From 5f88b862ca2f882a0a5492942808341d5f77d94c Mon Sep 17 00:00:00 2001 From: Single Date: Tue, 29 Oct 2019 11:28:03 +0800 Subject: [PATCH] SGDmuxable: Track infos. --- .../Classes/Core/SGAsset/SGMutableTrack.h | 7 +++++++ .../Classes/Core/SGAsset/SGMutableTrack.m | 15 ++++++++++++-- .../Classes/Core/SGAsset/SGTrack+Internal.h | 20 +++++++++++++++++++ SGPlayer/Classes/Core/SGAsset/SGTrack.h | 7 +++++++ SGPlayer/Classes/Core/SGAsset/SGTrack.m | 6 ++++++ SGPlayer/Classes/Core/SGData/SGFrame.h | 2 +- .../Classes/Core/SGDemuxer/SGTrackDemuxer.m | 6 ++++++ .../Classes/Core/SGDemuxer/SGURLDemuxer.m | 1 + 8 files changed, 61 insertions(+), 3 deletions(-) diff --git a/SGPlayer/Classes/Core/SGAsset/SGMutableTrack.h b/SGPlayer/Classes/Core/SGAsset/SGMutableTrack.h index efbddcb6..b9e61c4f 100644 --- a/SGPlayer/Classes/Core/SGAsset/SGMutableTrack.h +++ b/SGPlayer/Classes/Core/SGAsset/SGMutableTrack.h @@ -12,6 +12,13 @@ @interface SGMutableTrack : SGTrack +/*! + @property subTracks + @abstract + Indicates the sub tracks. + */ +@property (nonatomic, copy, readonly) NSArray *subTracks; + /*! @property segments @abstract diff --git a/SGPlayer/Classes/Core/SGAsset/SGMutableTrack.m b/SGPlayer/Classes/Core/SGAsset/SGMutableTrack.m index 6344d586..e2071ca7 100644 --- a/SGPlayer/Classes/Core/SGAsset/SGMutableTrack.m +++ b/SGPlayer/Classes/Core/SGAsset/SGMutableTrack.m @@ -23,6 +23,7 @@ - (id)copyWithZone:(NSZone *)zone { SGMutableTrack *obj = [super copyWithZone:zone]; obj->_segments = [self->_segments mutableCopy]; + obj->_subTracks = [self->_subTracks copy]; return obj; } @@ -34,9 +35,19 @@ - (instancetype)initWithType:(SGMediaType)type index:(NSInteger)index return self; } -- (NSArray *)segments +- (void *)coreptr { - return [self->_segments copy]; + void *ret = [super coreptr]; + if (ret) { + return ret; + } + for (SGTrack *obj in self->_subTracks) { + if (obj.coreptr) { + ret = obj.coreptr; + break; + } + } + return ret; } - (BOOL)appendSegment:(SGSegment *)segment diff --git a/SGPlayer/Classes/Core/SGAsset/SGTrack+Internal.h b/SGPlayer/Classes/Core/SGAsset/SGTrack+Internal.h index 08535ac2..2be125ef 100644 --- a/SGPlayer/Classes/Core/SGAsset/SGTrack+Internal.h +++ b/SGPlayer/Classes/Core/SGAsset/SGTrack+Internal.h @@ -7,6 +7,8 @@ // #import "SGTrack.h" +#import "SGMutableTrack.h" +#import "avformat.h" @interface SGTrack () @@ -17,4 +19,22 @@ */ - (instancetype)initWithType:(SGMediaType)type index:(NSInteger)index; +/*! + @property core + @abstract + Indicates the pointer to the AVStream. +*/ +@property (nonatomic) AVStream *core; + +@end + +@interface SGMutableTrack () + +/*! + @property subTracks + @abstract + Indicates the sub tracks. + */ +@property (nonatomic, copy) NSArray *subTracks; + @end diff --git a/SGPlayer/Classes/Core/SGAsset/SGTrack.h b/SGPlayer/Classes/Core/SGAsset/SGTrack.h index 5f4a2918..9bf6117f 100644 --- a/SGPlayer/Classes/Core/SGAsset/SGTrack.h +++ b/SGPlayer/Classes/Core/SGAsset/SGTrack.h @@ -14,6 +14,13 @@ + (instancetype)new NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE; +/*! + @property coreptr + @abstract + Indicates the pointer to the AVStream. + */ +@property (nonatomic, readonly) void *coreptr; + /*! @property type @abstract diff --git a/SGPlayer/Classes/Core/SGAsset/SGTrack.m b/SGPlayer/Classes/Core/SGAsset/SGTrack.m index 9f3c38f7..0797ba60 100644 --- a/SGPlayer/Classes/Core/SGAsset/SGTrack.m +++ b/SGPlayer/Classes/Core/SGAsset/SGTrack.m @@ -16,6 +16,7 @@ - (id)copyWithZone:(NSZone *)zone SGTrack *obj = [[self.class alloc] init]; obj->_type = self->_type; obj->_index = self->_index; + obj->_core = self->_core; return obj; } @@ -28,4 +29,9 @@ - (instancetype)initWithType:(SGMediaType)type index:(NSInteger)index return self; } +- (void *)coreptr +{ + return self->_core; +} + @end diff --git a/SGPlayer/Classes/Core/SGData/SGFrame.h b/SGPlayer/Classes/Core/SGData/SGFrame.h index b5eb4f6d..742a5d00 100644 --- a/SGPlayer/Classes/Core/SGData/SGFrame.h +++ b/SGPlayer/Classes/Core/SGData/SGFrame.h @@ -17,7 +17,7 @@ static int const SGFramePlaneCount = 8; /** * */ -@property (nonatomic, readonly) void * coreptr; +@property (nonatomic, readonly) void *coreptr; /** * diff --git a/SGPlayer/Classes/Core/SGDemuxer/SGTrackDemuxer.m b/SGPlayer/Classes/Core/SGDemuxer/SGTrackDemuxer.m index 9d4df680..177465fe 100644 --- a/SGPlayer/Classes/Core/SGDemuxer/SGTrackDemuxer.m +++ b/SGPlayer/Classes/Core/SGDemuxer/SGTrackDemuxer.m @@ -7,6 +7,7 @@ // #import "SGTrackDemuxer.h" +#import "SGTrack+Internal.h" #import "SGPacket+Internal.h" #import "SGSegment+Internal.h" #import "SGError.h" @@ -70,6 +71,7 @@ - (SGDemuxerOptions *)options - (NSError *)open { CMTime basetime = kCMTimeZero; + NSMutableArray *subTracks = [NSMutableArray array]; for (SGSegment *obj in self->_track.segments) { SGTimeLayout *layout = [[SGTimeLayout alloc] initWithOffset:basetime]; id demuxer = [obj newDemuxable]; @@ -83,8 +85,12 @@ - (NSError *)open NSAssert(!demuxer.tracks.firstObject || demuxer.tracks.firstObject.type == self->_track.type, @"Invaild mediaType."); basetime = CMTimeAdd(basetime, demuxer.duration); + if (demuxer.tracks.firstObject) { + [subTracks addObject:demuxer.tracks.firstObject]; + } } self->_duration = basetime; + self->_track.subTracks = subTracks; self->_currentLayout = self->_layouts.firstObject; self->_currentDemuxer = self->_demuxers.firstObject; [self->_currentDemuxer seekToTime:kCMTimeZero]; diff --git a/SGPlayer/Classes/Core/SGDemuxer/SGURLDemuxer.m b/SGPlayer/Classes/Core/SGDemuxer/SGURLDemuxer.m index 7f4d098e..049d087d 100644 --- a/SGPlayer/Classes/Core/SGDemuxer/SGURLDemuxer.m +++ b/SGPlayer/Classes/Core/SGDemuxer/SGURLDemuxer.m @@ -72,6 +72,7 @@ - (NSError *)open type = SGMediaTypeUnknown; } SGTrack *obj = [[SGTrack alloc] initWithType:type index:i]; + obj.core = stream; [tracks addObject:obj]; } self->_tracks = [tracks copy];