Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reattach videooutput on too many failures #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions MDVRLibrary/MDVRLibrary/MDVideoDataAdatperAVPlayerImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
@interface MDVideoDataAdatperAVPlayerImpl ()<AVPlayerItemOutputPullDelegate>
@property (nonatomic, strong) AVPlayerItemVideoOutput* output;
@property (nonatomic, strong) AVPlayerItem* playerItem;
@property (nonatomic) int failures;
@property (nonatomic) CMTime lastFailure;

@end

Expand Down Expand Up @@ -66,25 +68,37 @@ - (void) setup{
[self.playerItem addOutput:self.output];
}

- (void)teardown{
- (void)teardown {
if (self.playerItem != nil && self.output != nil) {
[self.playerItem removeOutput:self.output];
self.output = nil;
}
}

- (CVPixelBufferRef)copyPixelBuffer{
if (_failures == 10) {
if (self.output != nil) {
[self teardown];
[self setup];
_failures = 0;
}
}

if (self.output == nil) {
return nil;
}

CMTime currentTime = [self.playerItem currentTime];
if([self.output hasNewPixelBufferForItemTime:currentTime]){
_failures = 0;
return [self.output copyPixelBufferForItemTime:currentTime itemTimeForDisplay:nil];
} else {
if (_lastFailure.value != currentTime.value) {
_failures += 1;
_lastFailure = currentTime;
}
return nil;
}

}

- (void)dealloc{
Expand Down