Skip to content

Commit

Permalink
SGDmuxable: Track infos.
Browse files Browse the repository at this point in the history
  • Loading branch information
libobjc committed Oct 29, 2019
1 parent 5e07d85 commit 5f88b86
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 3 deletions.
7 changes: 7 additions & 0 deletions SGPlayer/Classes/Core/SGAsset/SGMutableTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@

@interface SGMutableTrack : SGTrack

/*!
@property subTracks
@abstract
Indicates the sub tracks.
*/
@property (nonatomic, copy, readonly) NSArray<SGTrack *> *subTracks;

/*!
@property segments
@abstract
Expand Down
15 changes: 13 additions & 2 deletions SGPlayer/Classes/Core/SGAsset/SGMutableTrack.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -34,9 +35,19 @@ - (instancetype)initWithType:(SGMediaType)type index:(NSInteger)index
return self;
}

- (NSArray<SGSegment *> *)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
Expand Down
20 changes: 20 additions & 0 deletions SGPlayer/Classes/Core/SGAsset/SGTrack+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//

#import "SGTrack.h"
#import "SGMutableTrack.h"
#import "avformat.h"

@interface SGTrack ()

Expand All @@ -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<SGTrack *> *subTracks;

@end
7 changes: 7 additions & 0 deletions SGPlayer/Classes/Core/SGAsset/SGTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions SGPlayer/Classes/Core/SGAsset/SGTrack.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -28,4 +29,9 @@ - (instancetype)initWithType:(SGMediaType)type index:(NSInteger)index
return self;
}

- (void *)coreptr
{
return self->_core;
}

@end
2 changes: 1 addition & 1 deletion SGPlayer/Classes/Core/SGData/SGFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static int const SGFramePlaneCount = 8;
/**
*
*/
@property (nonatomic, readonly) void * coreptr;
@property (nonatomic, readonly) void *coreptr;

/**
*
Expand Down
6 changes: 6 additions & 0 deletions SGPlayer/Classes/Core/SGDemuxer/SGTrackDemuxer.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "SGTrackDemuxer.h"
#import "SGTrack+Internal.h"
#import "SGPacket+Internal.h"
#import "SGSegment+Internal.h"
#import "SGError.h"
Expand Down Expand Up @@ -70,6 +71,7 @@ - (SGDemuxerOptions *)options
- (NSError *)open
{
CMTime basetime = kCMTimeZero;
NSMutableArray<SGTrack *> *subTracks = [NSMutableArray array];
for (SGSegment *obj in self->_track.segments) {
SGTimeLayout *layout = [[SGTimeLayout alloc] initWithOffset:basetime];
id<SGDemuxable> demuxer = [obj newDemuxable];
Expand All @@ -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];
Expand Down
1 change: 1 addition & 0 deletions SGPlayer/Classes/Core/SGDemuxer/SGURLDemuxer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 5f88b86

Please sign in to comment.