Skip to content

Commit

Permalink
SGVideoRenderer: Add timing info callback.
Browse files Browse the repository at this point in the history
  • Loading branch information
libobjc committed Nov 18, 2019
1 parent 472d6cd commit 730d29e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ @interface SGVideoRenderer () <MTKViewDelegate>
NSUInteger framesFetched;
NSUInteger framesDisplayed;
NSTimeInterval currentFrameEndTime;
NSTimeInterval currentFrameBeginTime;
} _flags;
SGCapacity _capacity;
}
Expand Down Expand Up @@ -198,6 +199,8 @@ - (BOOL)close
self->_flags.hasNewFrame = NO;
self->_flags.framesFetched = 0;
self->_flags.framesDisplayed = 0;
self->_flags.currentFrameEndTime = 0;
self->_flags.currentFrameBeginTime = 0;
self->_capacity = SGCapacityCreate();
return ^{b1();};
}, ^BOOL(SGBlock block) {
Expand Down Expand Up @@ -252,6 +255,8 @@ - (BOOL)flush
self->_flags.hasNewFrame = NO;
self->_flags.framesFetched = 0;
self->_flags.framesDisplayed = 0;
self->_flags.currentFrameEndTime = 0;
self->_flags.currentFrameBeginTime = 0;
return nil;
}, ^BOOL(SGBlock block) {
self->_metalView.paused = NO;
Expand Down Expand Up @@ -326,6 +331,7 @@ - (void)fetchTimerHandler
self->_currentFrame = newFrame;
self->_flags.hasNewFrame = YES;
self->_flags.framesFetched += 1;
self->_flags.currentFrameBeginTime = currentMediaTime;
self->_flags.currentFrameEndTime = currentMediaTime + CMTimeGetSeconds(duration);
if (self->_frameOutput) {
[newFrame lock];
Expand All @@ -338,7 +344,12 @@ - (void)fetchTimerHandler
[self->_clock setVideoTime:time];
};
} else if (currentMediaTime < self->_flags.currentFrameEndTime) {
CMTime time = self->_currentFrame.timeStamp;
time = CMTimeAdd(time, SGCMTimeMakeWithSeconds(currentMediaTime - self->_flags.currentFrameBeginTime));
capacity.duration = SGCMTimeMakeWithSeconds(self->_flags.currentFrameEndTime - currentMediaTime);
b2 = ^{
[self->_clock setVideoTime:time];
};
}
if (!SGCapacityIsEqual(self->_capacity, capacity)) {
self->_capacity = capacity;
Expand Down

0 comments on commit 730d29e

Please sign in to comment.