Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeus64 committed Jan 11, 2018
1 parent 52bcd9b commit 70581af
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 58 deletions.
1 change: 1 addition & 0 deletions source/ALFmxInertialMovement.pas
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ TChoreographerFrameCallback = class(TJavaLocal, JChoreographer_FrameCallback
property OnStop: TNotifyEvent read FOnStop write FOnStop;
property DeadZone: Integer read FDeadZone write FDeadZone default ALDefaultDeadZone;
property mouseEventReceived: boolean read fmouseEventReceived; // used only internally
property TimerActive: boolean read FTimerActive;
published
property Interval: Word read FInterval write SetInterval default ALDefaultIntervalOfAni;
property DecelerationRate: Double read FDecelerationRate write FDecelerationRate stored DecelerationRateStored nodefault;
Expand Down
129 changes: 71 additions & 58 deletions source/ALVideoPlayer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -902,44 +902,44 @@ constructor TALAndroidVideoPlayer.Create;
fBitmap := TalTexture.Create(False);
ALInitializeEXTERNALOESTexture(fBitmap);

//-----
fVideoWidth := 0;
fVideoHeight := 0;
end);

//-----
FMediaPlayer := TJMediaPlayer.JavaClass.init;
//-----
fOnErrorEvent := nil;
FOnErrorListener := TALErrorListener.Create(Self);
FMediaPlayer.setOnErrorListener(FOnErrorListener);
//-----
fOnPreparedEvent := nil;
FOnPreparedListener := TALPreparedListener.Create(Self);
FMediaPlayer.setOnPreparedListener(FOnPreparedListener);
//-----
fonVideoSizeChangedEvent := nil;
fonVideoSizeChangedListener := TALVideoSizeChangedListener.Create(Self);
FMediaPlayer.setOnVideoSizeChangedListener(fonVideoSizeChangedListener);
//-----
fOnBufferingUpdateEvent := nil;
fOnBufferingUpdateListener := TALBufferingUpdateListener.Create(Self);
FMediaPlayer.setOnBufferingUpdateListener(fOnBufferingUpdateListener);
//-----
fOnCompletionEvent := nil;
fOnCompletionListener := TALCompletionListener.Create(Self);
FMediaPlayer.setOnCompletionListener(fOnCompletionListener);
//-----
fSurfaceTexture := TJSurfaceTexture.JavaClass.init(fBitmap.Handle);
//-----
fHandler := TJHandler.JavaClass.init(TJLooper.javaclass.getMainLooper());
//-----
fOnFrameAvailableEvent := nil;
FOnFrameAvailableListener := TALFrameAvailableListener.Create(Self);
fSurfaceTexture.setOnFrameAvailableListener(FOnFrameAvailableListener, fHandler);
//-----
FMediaPlayer.setSurface(TJSurface.JavaClass.init((fSurfaceTexture)));
//-----
fVideoWidth := 0;
fVideoHeight := 0;

end);
//-----
FMediaPlayer := TJMediaPlayer.JavaClass.init;
//-----
fOnErrorEvent := nil;
FOnErrorListener := TALErrorListener.Create(Self);
FMediaPlayer.setOnErrorListener(FOnErrorListener);
//-----
fOnPreparedEvent := nil;
FOnPreparedListener := TALPreparedListener.Create(Self);
FMediaPlayer.setOnPreparedListener(FOnPreparedListener);
//-----
fonVideoSizeChangedEvent := nil;
fonVideoSizeChangedListener := TALVideoSizeChangedListener.Create(Self);
FMediaPlayer.setOnVideoSizeChangedListener(fonVideoSizeChangedListener);
//-----
fOnBufferingUpdateEvent := nil;
fOnBufferingUpdateListener := TALBufferingUpdateListener.Create(Self);
FMediaPlayer.setOnBufferingUpdateListener(fOnBufferingUpdateListener);
//-----
fOnCompletionEvent := nil;
fOnCompletionListener := TALCompletionListener.Create(Self);
FMediaPlayer.setOnCompletionListener(fOnCompletionListener);
//-----
fSurfaceTexture := TJSurfaceTexture.JavaClass.init(fBitmap.Handle);
//-----
fHandler := TJHandler.JavaClass.init(TJLooper.javaclass.getMainLooper());
//-----
fOnFrameAvailableEvent := nil;
FOnFrameAvailableListener := TALFrameAvailableListener.Create(Self);
fSurfaceTexture.setOnFrameAvailableListener(FOnFrameAvailableListener, fHandler);
//-----
FMediaPlayer.setSurface(TJSurface.JavaClass.init((fSurfaceTexture)));

end;

Expand Down Expand Up @@ -1535,16 +1535,16 @@ destructor TALIOSVideoPlayer.Destroy;
ALLog('TALIOSVideoPlayer.Destroy', 'ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.verbose);
{$ENDIF}

//-----
if FFrameRefreshTimer <> nil then begin
FFrameRefreshTimer.Enabled := False;
alFreeAndNil(FFrameRefreshTimer);
end;

//-----
TThread.Synchronize(nil,
procedure
begin

if FFrameRefreshTimer <> nil then begin
FFrameRefreshTimer.Enabled := False;
alFreeAndNil(FFrameRefreshTimer);
end;
//-----
if FNotificationsDelegate <> nil then begin
TNSNotificationCenter.Wrap(TNSNotificationCenter.OCClass.defaultCenter).removeObserver(FNotificationsDelegate.GetObjectID);
AlFreeAndNil(FNotificationsDelegate);
Expand Down Expand Up @@ -1574,6 +1574,7 @@ destructor TALIOSVideoPlayer.Destroy;
CFrelease(pointer(fvideoTextureCacheRef));
fvideoTextureCacheRef := 0;
end;

end);

//-----
Expand Down Expand Up @@ -1851,13 +1852,18 @@ procedure TALIOSVideoPlayer.setDataSource(Const aDataSource: String);
nil); // context: Arbitrary data that is passed to observer in observeValue(forKeyPath:of:change:context:).

//-----
//if you call setDataSource from a background thread then you are responsible
//to handle from this background thread the function doOnFrameRefresh
//this because part of this function (doOnFrameRefresh) could be more efficient
//to run directly from the background thread instead of the main UI thread used by TTimer
if TThread.Current.ThreadID = MainThreadID then begin
FFrameRefreshTimer := TTimer.Create(nil);
FFrameRefreshTimer.Interval := _FrameRefreshInterval; // equivalent to a fps of 30
FFrameRefreshTimer.OnTimer := doOnFrameRefresh;
FFrameRefreshTimer.Enabled := False;
end;

//-----
TThread.Synchronize(nil,
procedure
begin
Expand Down Expand Up @@ -1891,7 +1897,9 @@ procedure TALIOSVideoPlayer.setDataSource(Const aDataSource: String);
fState := vpsInitialized;

{$IFDEF DEBUG}
ALLog('TALIOSVideoPlayer.setDataSource', 'FPlayer.status: ' + alinttostrU(FPlayer.status) + ' - FPlayerItem.status: ' + alinttostrU(FPlayerItem.status), TalLogType.VERBOSE);
ALLog('TALIOSVideoPlayer.setDataSource', 'FPlayer.status: ' + alinttostrU(FPlayer.status) +
' - FPlayerItem.status: ' + alinttostrU(FPlayerItem.status) +
' - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.VERBOSE);
{$ENDIF}

end;
Expand Down Expand Up @@ -1990,16 +1998,16 @@ procedure TALIOSVideoPlayer.doOnFrameRefresh(Sender: TObject);
// The texture cache automatically flushes currently unused resources when you call the
// CVOpenGLESTextureCacheCreateTextureFromImage function
if CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, // allocator: The CFAllocator to use for allocating the texture object. This parameter can be NULL.
fvideoTextureCacheRef, // textureCache: The texture cache object that will manage the texture.
aPixelBuffer, // sourceImage: The CVImageBuffer that you want to create a texture from.
nil, // textureAttributes: A CFDictionary containing the attributes to be used for creating the CVOpenGLESTexture objects. This parameter can be NULL.
GL_TEXTURE_2D, // target: The target texture. GL_TEXTURE_2D and GL_RENDERBUFFER are the only targets currently supported.
GL_RGBA, // internalFormat: The number of color components in the texture. Examples are GL_RGBA, GL_LUMINANCE, GL_RGBA8_OES, GL_RED, and GL_RG.
aWidth, // width: The width of the texture image.
aHeight, // height The height of the texture image.
GL_BGRA_EXT, // format: The format of the pixel data. Examples are GL_RGBA and GL_LUMINANCE.
GL_UNSIGNED_BYTE, // type: The data type of the pixel data. One example is GL_UNSIGNED_BYTE.
0, // planeIndex: The plane of the CVImageBuffer to map bind. Ignored for non-planar CVImageBuffers.
fvideoTextureCacheRef, // textureCache: The texture cache object that will manage the texture.
aPixelBuffer, // sourceImage: The CVImageBuffer that you want to create a texture from.
nil, // textureAttributes: A CFDictionary containing the attributes to be used for creating the CVOpenGLESTexture objects. This parameter can be NULL.
GL_TEXTURE_2D, // target: The target texture. GL_TEXTURE_2D and GL_RENDERBUFFER are the only targets currently supported.
GL_RGBA, // internalFormat: The number of color components in the texture. Examples are GL_RGBA, GL_LUMINANCE, GL_RGBA8_OES, GL_RED, and GL_RG.
aWidth, // width: The width of the texture image.
aHeight, // height The height of the texture image.
GL_BGRA_EXT, // format: The format of the pixel data. Examples are GL_RGBA and GL_LUMINANCE.
GL_UNSIGNED_BYTE, // type: The data type of the pixel data. One example is GL_UNSIGNED_BYTE.
0, // planeIndex: The plane of the CVImageBuffer to map bind. Ignored for non-planar CVImageBuffers.
@fTextureRef) <> kCVReturnSuccess then begin // textureOut: A pointer to a CVOpenGLESTexture where the newly created texture object will be placed.
{$IFDEF DEBUG}
ALLog('TALIOSVideoPlayer.FrameRefreshOnTimer', 'CVOpenGLESTextureCacheCreateTextureFromImage failed!', TalLogType.Error);
Expand Down Expand Up @@ -2063,15 +2071,17 @@ procedure TALIOSVideoPlayer.doOnFrameRefresh(Sender: TObject);
aStopWatch1.Stop;
fFrameRefreshCounter := 0;
ALLog('TALIOSVideoPlayer.FrameRefreshOnTimer', 'Total TimeTaken: ' + ALFormatFloatU('0.00', aStopWatch1.Elapsed.TotalMilliseconds, AlDefaultFormatSettingsU) +
' - Synchronize TimeTaken: ' + ALFormatFloatU('0.00', aStopWatch2.Elapsed.TotalMilliseconds, AlDefaultFormatSettingsU), TalLogType.VERBOSE);
' - Synchronize TimeTaken: ' + ALFormatFloatU('0.00', aStopWatch2.Elapsed.TotalMilliseconds, AlDefaultFormatSettingsU) +
' - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.VERBOSE);
end;
{$ENDIF}

end
else begin

{$IFDEF DEBUG}
ALLog('TALIOSVideoPlayer.FrameRefreshOnTimer', 'hasNewPixelBufferForItemTime:NO', TalLogType.VERBOSE);
ALLog('TALIOSVideoPlayer.FrameRefreshOnTimer', 'hasNewPixelBufferForItemTime:NO' +
' - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.VERBOSE);
{$ENDIF}

//sometime we continusly receive hasNewPixelBufferForItemTime:NO
Expand All @@ -2094,7 +2104,8 @@ procedure TALIOSVideoPlayer.doOnFrameRefresh(Sender: TObject);
{$IFDEF DEBUG}
ALLog('TALIOSVideoPlayer.FrameRefreshOnTimer', 'hasNewPixelBufferForItemTime:NO '+
'- Pause and Restart '+
'- currentTime: ' + alinttostrU(fPlayer.currentTime.value), TalLogType.VERBOSE);
' - currentTime: ' + alinttostrU(fPlayer.currentTime.value) +
' - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.VERBOSE);
{$ENDIF}
fPlayer.pause;
fPlayer.play;
Expand Down Expand Up @@ -2134,7 +2145,8 @@ procedure TALIOSVideoPlayer.doOnReady;
then begin

{$IFDEF DEBUG}
ALLog('TALIOSVideoPlayer.doOnReady', 'Ready', TalLogType.VERBOSE);
ALLog('TALIOSVideoPlayer.doOnReady', 'Ready' +
' - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.VERBOSE);
{$ENDIF}

//i need to do this here because of bug like :
Expand Down Expand Up @@ -2169,7 +2181,8 @@ procedure TALIOSVideoPlayer.doOnReady;
(FPlayerItem.status = AVPlayerItemStatusFailed) then begin

{$IFDEF DEBUG}
ALLog('TALIOSVideoPlayer.doOnReady', 'Failed', TalLogType.Error);
ALLog('TALIOSVideoPlayer.doOnReady', 'Failed' +
' - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.VERBOSE);
{$ENDIF}

//fire the fOnErrorEvent
Expand Down

0 comments on commit 70581af

Please sign in to comment.