Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
KWANG HYOUN KIM committed Aug 23, 2019
2 parents 37e576a + 5132592 commit ffe033a
Show file tree
Hide file tree
Showing 16 changed files with 729 additions and 173 deletions.
28 changes: 22 additions & 6 deletions DLGPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
23DC295021B810B50012243A /* DLGPlayerFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 23DC293121B810B50012243A /* DLGPlayerFrame.m */; };
23DC295121B810B50012243A /* DLGPlayerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 23DC293321B810B50012243A /* DLGPlayerView.m */; };
23DC295521B810B50012243A /* DLGPlayerUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 23DC293821B810B50012243A /* DLGPlayerUtils.m */; };
23E013A6230E7B5D00B9BB0E /* Shader.metal in Sources */ = {isa = PBXBuildFile; fileRef = 23E013A5230E7B5B00B9BB0E /* Shader.metal */; };
23E013AA230E7B6B00B9BB0E /* DLGPlayerVideoFrameView.h in Headers */ = {isa = PBXBuildFile; fileRef = 23E013A7230E7B6B00B9BB0E /* DLGPlayerVideoFrameView.h */; };
23E013AB230E7B6B00B9BB0E /* MetalPlayerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 23E013A8230E7B6B00B9BB0E /* MetalPlayerView.h */; };
23E013AC230E7B6B00B9BB0E /* MetalPlayerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 23E013A9230E7B6B00B9BB0E /* MetalPlayerView.m */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -120,6 +124,10 @@
23DC296E21B8147A0012243A /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; };
23DC297021B814830012243A /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
23DC297221B8148B0012243A /* libiconv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libiconv.tbd; path = usr/lib/libiconv.tbd; sourceTree = SDKROOT; };
23E013A5230E7B5B00B9BB0E /* Shader.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shader.metal; sourceTree = "<group>"; };
23E013A7230E7B6B00B9BB0E /* DLGPlayerVideoFrameView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DLGPlayerVideoFrameView.h; sourceTree = "<group>"; };
23E013A8230E7B6B00B9BB0E /* MetalPlayerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MetalPlayerView.h; sourceTree = "<group>"; };
23E013A9230E7B6B00B9BB0E /* MetalPlayerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MetalPlayerView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -215,32 +223,36 @@
23DC292321B810B50012243A /* DLGPlayerRGBFragmentShader.glsl */,
23DC292521B810B50012243A /* DLGPlayerRotationVertexShader.glsl */,
23DC292621B810B50012243A /* DLGPlayerVertexShader.glsl */,
23E013A5230E7B5B00B9BB0E /* Shader.metal */,
);
path = resource;
sourceTree = "<group>";
};
23DC292721B810B50012243A /* frame */ = {
isa = PBXGroup;
children = (
23DC292821B810B50012243A /* DLGPlayerVideoYUVFrame.h */,
23DC292921B810B50012243A /* DLGPlayerVideoFrame.h */,
23DC292A21B810B50012243A /* DLGPlayerVideoRGBFrame.m */,
23DC293021B810B50012243A /* DLGPlayerAudioFrame.h */,
23DC292B21B810B50012243A /* DLGPlayerAudioFrame.m */,
23DC292C21B810B50012243A /* DLGPlayerFrame.h */,
23DC292D21B810B50012243A /* DLGPlayerVideoRGBFrame.h */,
23DC293121B810B50012243A /* DLGPlayerFrame.m */,
23DC292921B810B50012243A /* DLGPlayerVideoFrame.h */,
23DC292E21B810B50012243A /* DLGPlayerVideoFrame.m */,
23DC292D21B810B50012243A /* DLGPlayerVideoRGBFrame.h */,
23DC292A21B810B50012243A /* DLGPlayerVideoRGBFrame.m */,
23DC292821B810B50012243A /* DLGPlayerVideoYUVFrame.h */,
23DC292F21B810B50012243A /* DLGPlayerVideoYUVFrame.m */,
23DC293021B810B50012243A /* DLGPlayerAudioFrame.h */,
23DC293121B810B50012243A /* DLGPlayerFrame.m */,
);
path = frame;
sourceTree = "<group>";
};
23DC293221B810B50012243A /* view */ = {
isa = PBXGroup;
children = (
23E013A7230E7B6B00B9BB0E /* DLGPlayerVideoFrameView.h */,
23DC293421B810B50012243A /* DLGPlayerView.h */,
23DC293321B810B50012243A /* DLGPlayerView.m */,
23E013A8230E7B6B00B9BB0E /* MetalPlayerView.h */,
23E013A9230E7B6B00B9BB0E /* MetalPlayerView.m */,
);
path = view;
sourceTree = "<group>";
Expand Down Expand Up @@ -282,6 +294,7 @@
files = (
23DC293E21B810B50012243A /* DLGPlayer.h in Headers */,
237758B421CA5658000B6B7F /* DLGPlayerControlStatus.h in Headers */,
23E013AB230E7B6B00B9BB0E /* MetalPlayerView.h in Headers */,
235409BA21BA05B500533B9B /* DLGPlayerFrame.h in Headers */,
235409BC21BA05B500533B9B /* DLGPlayerAudioFrame.h in Headers */,
235409B921BA05B500533B9B /* DLGPlayerVideoFrame.h in Headers */,
Expand All @@ -291,6 +304,7 @@
235409BD21BA05BC00533B9B /* DLGPlayerView.h in Headers */,
235409B621BA05A900533B9B /* DLGPlayerDef.h in Headers */,
235409B721BA05A900533B9B /* DLGPlayerUtils.h in Headers */,
23E013AA230E7B6B00B9BB0E /* DLGPlayerVideoFrameView.h in Headers */,
235409C621BA177A00533B9B /* DLGSimplePlayerViewController.h in Headers */,
235409BB21BA05B500533B9B /* DLGPlayerVideoRGBFrame.h in Headers */,
23DC293921B810B50012243A /* DLGPlayerViewController.h in Headers */,
Expand Down Expand Up @@ -446,10 +460,12 @@
23DC295521B810B50012243A /* DLGPlayerUtils.m in Sources */,
237758B521CA5658000B6B7F /* DLGPlayerControlStatus.m in Sources */,
23DC295021B810B50012243A /* DLGPlayerFrame.m in Sources */,
23E013AC230E7B6B00B9BB0E /* MetalPlayerView.m in Sources */,
23DC294A21B810B50012243A /* DLGPlayerAudioFrame.m in Sources */,
23DC294E21B810B50012243A /* DLGPlayerVideoYUVFrame.m in Sources */,
23DC295121B810B50012243A /* DLGPlayerView.m in Sources */,
23DC293F21B810B50012243A /* DLGPlayerViewController.m in Sources */,
23E013A6230E7B5D00B9BB0E /* Shader.metal in Sources */,
23DC294921B810B50012243A /* DLGPlayerVideoRGBFrame.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
1 change: 0 additions & 1 deletion DLGPlayer/DLGPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#import "DLGPlayerVideoFrame.h"
#import "DLGPlayerVideoRGBFrame.h"
#import "DLGPlayerVideoYUVFrame.h"
#import "DLGPlayerView.h"
#import "DLGPlayerViewController.h"
#import "DLGPlayerUtils.h"
#import "DLGPlayerControlStatus.h"
Expand Down
146 changes: 95 additions & 51 deletions DLGPlayer/DLGPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
#import "DLGPlayerFrame.h"
#import "DLGPlayerVideoFrame.h"
#import "DLGPlayerAudioFrame.h"
#import "DLGPlayerVideoFrameView.h"
#import "MetalPlayerView.h"

@interface DLGPlayer ()

@property (nonatomic, strong) DLGPlayerView *view;
@property (nonatomic, readonly) BOOL isAvilableMetal;
@property (nonatomic, strong) id<DLGPlayerVideoFrameView> view;
@property (nonatomic, strong) DLGPlayerDecoder *decoder;
@property (nonatomic, strong) DLGPlayerAudioManager *audio;

Expand All @@ -40,9 +43,10 @@ @interface DLGPlayer ()
@property (nonatomic, strong) dispatch_semaphore_t vFramesLock;
@property (nonatomic, strong) dispatch_semaphore_t aFramesLock;
@property (nonatomic, strong) dispatch_queue_t renderingQueue;
@property (nonatomic, strong) dispatch_queue_t processingQueue;
@end

static dispatch_queue_t processingQueue;
static dispatch_queue_t processingQueueStatic;

@implementation DLGPlayer

Expand Down Expand Up @@ -91,14 +95,21 @@ - (void)initVars {
_vFramesLock = dispatch_semaphore_create(1);
_renderingQueue = dispatch_queue_create([[NSString stringWithFormat:@"DLGPlayer.renderingQueue::%zd", self.hash] UTF8String], DISPATCH_QUEUE_SERIAL);

if (!processingQueue) {
processingQueue = dispatch_queue_create("DLGPlayer.processingQueue", DISPATCH_QUEUE_SERIAL);
if (self.isAvilableMetal) {
_processingQueue = dispatch_queue_create([[NSString stringWithFormat:@"DLGPlayer.processingQueue::%zd", self.hash] UTF8String], DISPATCH_QUEUE_SERIAL);
} else if (!processingQueueStatic) {
processingQueueStatic = dispatch_queue_create("DLGPlayer.processingQueue", DISPATCH_QUEUE_SERIAL);
}
}

- (void)initView {
DLGPlayerView *v = [[DLGPlayerView alloc] init];
self.view = v;
if (self.isAvilableMetal) {
if (@available(iOS 9.0, *)) {
_view = [MetalPlayerView new];
}
} else {
_view = [DLGPlayerView new];
}
}

- (void)initDecoder {
Expand Down Expand Up @@ -126,10 +137,18 @@ - (void)clearVars {
self.opening = NO;
}

- (dispatch_queue_t)processingQueue {
if (self.isAvilableMetal) {
return _processingQueue;
} else {
return processingQueueStatic;
}
}

- (void)open:(NSString *)url {
__weak typeof(self)weakSelf = self;

dispatch_async(processingQueue, ^{
dispatch_async(self.processingQueue, ^{
__strong typeof(weakSelf)strongSelf = weakSelf;

if (!strongSelf || strongSelf.opening || strongSelf.closing) {
Expand All @@ -138,37 +157,45 @@ - (void)open:(NSString *)url {

strongSelf.opening = YES;

NSError *error = nil;
if ([strongSelf.audio open:&error]) {
strongSelf.decoder.audioChannels = [weakSelf.audio channels];
strongSelf.decoder.audioSampleRate = [weakSelf.audio sampleRate];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf handleError:error];
});
}

if (![strongSelf.decoder open:url error:&error]) {
strongSelf.opening = NO;
@autoreleasepool {
NSError *error = nil;
if ([strongSelf.audio open:&error]) {
strongSelf.decoder.audioChannels = [weakSelf.audio channels];
strongSelf.decoder.audioSampleRate = [weakSelf.audio sampleRate];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf handleError:error];
});
}

dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf handleError:error];
});
return;
if (![strongSelf.decoder open:url error:&error]) {
strongSelf.opening = NO;

dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf handleError:error];
});
return;
}
}

dispatch_async(dispatch_get_main_queue(), ^{
if (!strongSelf.opening || strongSelf.closing) {
return;
}

[strongSelf.view setCurrentEAGLContext];
if ([strongSelf.view isKindOfClass:[DLGPlayerView class]]) {
DLGPlayerView *view = (DLGPlayerView *) strongSelf.view;
[view setCurrentEAGLContext];
}

strongSelf.view.isYUV = [strongSelf.decoder isYUV];
strongSelf.view.keepLastFrame = [strongSelf.decoder hasPicture] && ![strongSelf.decoder hasVideo];
strongSelf.view.rotation = strongSelf.decoder.rotation;
strongSelf.view.contentSize = CGSizeMake([strongSelf.decoder videoWidth], [strongSelf.decoder videoHeight]);
strongSelf.view.contentMode = UIViewContentModeScaleAspectFit;

if ([strongSelf.view isKindOfClass:[UIView class]]) {
((UIView *) strongSelf.view).contentMode = UIViewContentModeScaleAspectFit;
}

strongSelf.duration = strongSelf.decoder.duration;
strongSelf.metadata = strongSelf.decoder.metadata;
Expand Down Expand Up @@ -196,7 +223,7 @@ - (void)close {

[self pause];

dispatch_async(processingQueue, ^{
dispatch_async(self.processingQueue, ^{
__strong typeof(self)strongSelf = weakSelf;

if (!strongSelf || strongSelf.closing) {
Expand All @@ -209,30 +236,32 @@ - (void)close {
[strongSelf.decoder close];
[strongSelf.view clear];

NSArray<NSError *> *errors = nil;

if ([strongSelf.audio close:&errors]) {
[strongSelf clearVars];

dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:DLGPlayerNotificationClosed object:strongSelf];
});
} else {
[strongSelf clearVars];
@autoreleasepool {
NSArray<NSError *> *errors = nil;

dispatch_async(dispatch_get_main_queue(), ^{
for (NSError *error in errors) {
[strongSelf handleError:error];
}
});
if ([strongSelf.audio close:&errors]) {
[strongSelf clearVars];

dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:DLGPlayerNotificationClosed object:strongSelf];
});
} else {
[strongSelf clearVars];

dispatch_async(dispatch_get_main_queue(), ^{
for (NSError *error in errors) {
[strongSelf handleError:error];
}
});
}
}
});
}

- (void)play {
__weak typeof(self)weakSelf = self;

dispatch_async(processingQueue, ^{
dispatch_async(self.processingQueue, ^{
__strong typeof(weakSelf)strongSelf = weakSelf;

if (!strongSelf || !strongSelf.opened || strongSelf.playing || strongSelf.closing) {
Expand All @@ -244,10 +273,12 @@ - (void)play {
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf render];

NSError *error = nil;

if (![strongSelf.audio play:&error]) {
[strongSelf handleError:error];
@autoreleasepool {
NSError *error = nil;

if (![strongSelf.audio play:&error]) {
[strongSelf handleError:error];
}
}
});

Expand All @@ -258,9 +289,11 @@ - (void)play {
- (void)pause {
self.playing = NO;

NSError *error = nil;
if (![self.audio pause:&error]) {
[self handleError:error];
@autoreleasepool {
NSError *error = nil;
if (![self.audio pause:&error]) {
[self handleError:error];
}
}
}

Expand Down Expand Up @@ -446,7 +479,7 @@ - (void)render {
if (self.decoder.hasPicture && self.vframes.count > 0) {
DLGPlayerVideoFrame *frame = self.vframes[0];
frame.brightness = _brightness;
self.view.contentSize = CGSizeMake(frame.width, frame.height);
_view.contentSize = CGSizeMake(frame.width, frame.height);
[self.vframes removeObjectAtIndex:0];
[self renderView:frame];
}
Expand Down Expand Up @@ -600,7 +633,7 @@ - (void)readAudioFrame:(float *)data frames:(UInt32)frames channels:(UInt32)chan
}

- (UIView *)playerView {
return self.view;
return (UIView *) _view;
}

- (void)setPosition:(double)position {
Expand All @@ -612,6 +645,17 @@ - (double)position {
return self.mediaPosition;
}

- (BOOL)isAvilableMetal {
#if TARGET_IPHONE_SIMULATOR
return NO;
#else
if (@available(iOS 9.0, *)) {
return YES;
}
return NO;
#endif
}

#pragma mark - Handle Error
- (void)handleError:(NSError *)error {
if (error == nil) {
Expand Down
6 changes: 5 additions & 1 deletion DLGPlayer/frame/DLGPlayerVideoFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "DLGPlayerFrame.h"
#import <OpenGLES/ES2/gl.h>
@import MetalKit;

typedef enum : NSUInteger {
kDLGPlayerVideoFrameTypeNone,
Expand All @@ -17,11 +18,14 @@ typedef enum : NSUInteger {

@interface DLGPlayerVideoFrame : DLGPlayerFrame

@property (nonatomic, readonly) BOOL prepared;
@property (nonatomic) DLGPlayerVideoFrameType videoType;
@property (nonatomic) int width;
@property (nonatomic) int height;
@property (nonatomic) float brightness;

- (BOOL)prepareRender:(GLuint)program;
- (BOOL)prepareProgram:(GLuint)program;
- (BOOL)prepareDevice:(id<MTLDevice>)device;
- (BOOL)render:(id<MTLComputeCommandEncoder>)encoder;

@end
Loading

0 comments on commit ffe033a

Please sign in to comment.