Skip to content

Commit

Permalink
SGPlayer: int -> NSUInteger, double -> Float64.
Browse files Browse the repository at this point in the history
  • Loading branch information
libobjc committed Jul 1, 2019
1 parent cc331a0 commit 1751306
Show file tree
Hide file tree
Showing 34 changed files with 141 additions and 156 deletions.
10 changes: 5 additions & 5 deletions SGPlayer/Classes/Core/SGCommon/SGDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@
#define SGPLAYER_EXTERN extern
#endif

typedef NS_ENUM(int, SGMediaType) {
typedef NS_ENUM(NSUInteger, SGMediaType) {
SGMediaTypeUnknown = 0,
SGMediaTypeAudio = 1,
SGMediaTypeVideo = 2,
SGMediaTypeSubtitle = 3,
};

typedef NS_ENUM(int, SGPlayerState) {
typedef NS_ENUM(NSUInteger, SGPlayerState) {
SGPlayerStateNone = 0,
SGPlayerStatePreparing = 1,
SGPlayerStateReady = 2,
SGPlayerStateFailed = 3,
};

typedef NS_OPTIONS(int, SGPlaybackState) {
typedef NS_OPTIONS(NSUInteger, SGPlaybackState) {
SGPlaybackStateNone = 0,
SGPlaybackStatePlaying = 1 << 0,
SGPlaybackStateSeeking = 1 << 1,
SGPlaybackStateFinished = 1 << 2,
};

typedef NS_ENUM(int, SGLoadingState) {
typedef NS_ENUM(NSUInteger, SGLoadingState) {
SGLoadingStateNone = 0,
SGLoadingStatePlaybale = 1,
SGLoadingStateStalled = 2,
SGLoadingStateFinished = 3,
};

typedef NS_OPTIONS(int, SGInfoAction) {
typedef NS_OPTIONS(NSUInteger, SGInfoAction) {
SGInfoActionNone = 0,
SGInfoActionTimeCached = 1 << 1,
SGInfoActionTimePlayback = 1 << 2,
Expand Down
51 changes: 18 additions & 33 deletions SGPlayer/Classes/Core/SGCommon/SGError.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,13 @@
/**
*
*/
typedef NS_ENUM(int, SGErrorCode) {
SGErrorCodeUnknown,
typedef NS_ENUM(NSUInteger, SGErrorCode) {
SGErrorCodeUnknown = 0,
SGErrorImmediateExitRequested,
SGErrorCodeNoValidFormat,
SGErrorCodeNoValidTrackToPlay,
SGErrorCodeFormatNotSeekable,
SGErrorCodePacketOutputCannotOpen,
SGErrorCodePacketOutputCannotClose,
SGErrorCodePacketOutputCannotPause,
SGErrorCodePacketOutputCannotResume,
SGErrorCodePacketOutputCannotSeek,
SGErrorCodePacketOutputCancelSeek,
SGErrorCodeURLDemuxerFunnelFinished,
SGErrorCodeConcatDemuxerNotFoundUnit,
SGErrorCodeConcatDemuxerUnitInvaildDuration,
SGErrorCodeMutilDemuxerEndOfFile,
SGErrorCodeDemuxerEndOfFile,
SGErrorCodeInvlidTime,
Expand All @@ -34,35 +26,28 @@ typedef NS_ENUM(int, SGErrorCode) {
/**
*
*/
typedef NS_ENUM(int, SGOperationCode) {
SGOperationCodeUnknown,
SGOperationCodeFormatCreate,
SGOperationCodeFormatOpenInput,
SGOperationCodeFormatFindStreamInfo,
SGOperationCodeFormatSeekFrame,
SGOperationCodeFormatReadFrame,
SGOperationCodeFormatGetSeekable,
SGOperationCodeCodecSetParametersToContext,
SGOperationCodeCodecOpen2,
SGOperationCodeAuidoSwrInit,
SGOperationCodeSessionOpen,
SGOperationCodePacketOutputOpen,
SGOperationCodePacketOutputClose,
SGOperationCodePacketOutputPause,
SGOperationCodePacketOutputResmue,
SGOperationCodePacketOutputSeek,
SGOperationCodeURLDemuxerFunnelNext,
SGOperationCodeURLDemuxerSeek,
SGOperationCodeMutilDemuxerNext,
SGOperationCodeSegmentDemuxerNext,
typedef NS_ENUM(NSUInteger, SGActionCode) {
SGActionCodeUnknown = 0,
SGActionCodeFormatCreate,
SGActionCodeFormatOpenInput,
SGActionCodeFormatFindStreamInfo,
SGActionCodeFormatSeekFrame,
SGActionCodeFormatReadFrame,
SGActionCodeFormatGetSeekable,
SGActionCodeCodecSetParametersToContext,
SGActionCodeCodecOpen2,
SGActionCodePacketOutputSeek,
SGActionCodeURLDemuxerFunnelNext,
SGActionCodeMutilDemuxerNext,
SGActionCodeSegmentDemuxerNext,
};

/**
*
*/
NSError * SGEGetError(int result, SGOperationCode operation);
NSError * SGGetFFError(int result, SGActionCode operation);

/**
*
*/
NSError * SGECreateError(int code, SGOperationCode operation);
NSError * SGCreateError(NSUInteger code, SGActionCode operation);
4 changes: 2 additions & 2 deletions SGPlayer/Classes/Core/SGCommon/SGError.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

static NSString * const SGErrorUserInfoKeyOperation = @"SGErrorUserInfoKeyOperation";

NSError * SGEGetError(int result, SGOperationCode operation)
NSError * SGGetFFError(int result, SGActionCode operation)
{
if (result >= 0) {
return nil;
Expand All @@ -28,7 +28,7 @@
return [NSError errorWithDomain:domain code:result userInfo:@{SGErrorUserInfoKeyOperation : @(operation)}];
}

NSError * SGECreateError(int code, SGOperationCode operation)
NSError * SGCreateError(NSUInteger code, SGActionCode operation)
{
return [NSError errorWithDomain:@"SGPlayer-Error-SGErrorCode" code:(NSInteger)code userInfo:@{SGErrorUserInfoKeyOperation : @(operation)}];
}
4 changes: 2 additions & 2 deletions SGPlayer/Classes/Core/SGDecoder/SGAudioDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ - (void)flush
}
[cd fillToDescriptor:self->_codecDescriptor];
switch (packet.codecDescriptor.type) {
case SGCodecType_Decode: {
case SGCodecTypeDecode: {
NSArray<SGFrame *> *objs = [self processPacket:packet];
for (SGFrame *obj in objs) {
[ret addObject:obj];
}
}
break;
case SGCodecType_Padding: {
case SGCodecTypePadding: {
SGAudioDescriptor *ad = self->_audioDescriptor;
if (ad == nil) {
ad = [[SGAudioDescriptor alloc] init];
Expand Down
4 changes: 2 additions & 2 deletions SGPlayer/Classes/Core/SGDecoder/SGCodecContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ - (AVCodecContext *)createCcodecContext
codecContext->opaque = (__bridge void *)self;

int result = avcodec_parameters_to_context(codecContext, self->_codecpar);
NSError *error = SGEGetError(result, SGOperationCodeCodecSetParametersToContext);
NSError *error = SGGetFFError(result, SGActionCodeCodecSetParametersToContext);
if (error) {
avcodec_free_context(&codecContext);
return nil;
Expand Down Expand Up @@ -145,7 +145,7 @@ - (AVCodecContext *)createCcodecContext
av_dict_free(&opts);
}

error = SGEGetError(result, SGOperationCodeCodecOpen2);
error = SGGetFFError(result, SGActionCodeCodecOpen2);
if (error) {
avcodec_free_context(&codecContext);
return nil;
Expand Down
12 changes: 6 additions & 6 deletions SGPlayer/Classes/Core/SGDecoder/SGDecodeLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
/**
*
*/
typedef NS_ENUM(int, SGDecodeLoopState) {
SGDecodeLoopStateNone,
SGDecodeLoopStateDecoding,
SGDecodeLoopStateStalled,
SGDecodeLoopStatePaused,
SGDecodeLoopStateClosed,
typedef NS_ENUM(NSUInteger, SGDecodeLoopState) {
SGDecodeLoopStateNone = 0,
SGDecodeLoopStateDecoding = 1,
SGDecodeLoopStateStalled = 2,
SGDecodeLoopStatePaused = 3,
SGDecodeLoopStateClosed = 4,
};

@interface SGDecodeLoop : NSObject
Expand Down
4 changes: 2 additions & 2 deletions SGPlayer/Classes/Core/SGDecoder/SGVideoDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ - (void)flush
}
[cd fillToDescriptor:self->_codecDescriptor];
switch (packet.codecDescriptor.type) {
case SGCodecType_Decode: {
case SGCodecTypeDecode: {
NSArray<SGFrame *> *objs = [self processPacket:packet];
for (SGFrame *obj in objs) {
[ret addObject:obj];
}
}
break;
case SGCodecType_Padding: {
case SGCodecTypePadding: {

}
break;
Expand Down
6 changes: 3 additions & 3 deletions SGPlayer/Classes/Core/SGDemuxer/SGDemuxerFunnel.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ - (NSError *)open
- (NSError *)seekToTime:(CMTime)time
{
if (!CMTIME_IS_NUMERIC(time)) {
return SGECreateError(SGErrorCodeInvlidTime, SGOperationCodeFormatSeekFrame);
return SGCreateError(SGErrorCodeInvlidTime, SGActionCodeFormatSeekFrame);
}
NSError *error = [self->_demuxable seekToTime:CMTimeSubtract(time, self->_timeLayout.start)];
if (error) {
Expand Down Expand Up @@ -122,7 +122,7 @@ - (NSError *)nextPacketInternal:(SGPacket **)packet
}
if (CMTimeCompare(pkt.timeStamp, CMTimeRangeGetEnd(self->_timeRange)) >= 0) {
[pkt unlock];
error = SGECreateError(SGErrorCodeURLDemuxerFunnelFinished, SGOperationCodeURLDemuxerFunnelNext);
error = SGCreateError(SGErrorCodeURLDemuxerFunnelFinished, SGActionCodeURLDemuxerFunnelNext);
break;
}
[pkt.codecDescriptor appendTimeLayout:self->_timeLayout];
Expand Down Expand Up @@ -150,7 +150,7 @@ - (NSError *)nextPacketInternalOvergop:(SGPacket **)packet
}
}
if (self->_flags.finished) {
error = SGECreateError(SGErrorCodeURLDemuxerFunnelFinished, SGOperationCodeURLDemuxerFunnelNext);
error = SGCreateError(SGErrorCodeURLDemuxerFunnelFinished, SGActionCodeURLDemuxerFunnelNext);
break;
}
error = [self->_demuxable nextPacket:&pkt];
Expand Down
4 changes: 2 additions & 2 deletions SGPlayer/Classes/Core/SGDemuxer/SGMutilDemuxer.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ - (NSError *)seekable
- (NSError *)seekToTime:(CMTime)time
{
if (!CMTIME_IS_NUMERIC(time)) {
return SGECreateError(SGErrorCodeInvlidTime, SGOperationCodeFormatSeekFrame);
return SGCreateError(SGErrorCodeInvlidTime, SGActionCodeFormatSeekFrame);
}
for (id<SGDemuxable> obj in self->_demuxables) {
NSError *error = [obj seekToTime:time];
Expand Down Expand Up @@ -148,7 +148,7 @@ - (NSError *)nextPacket:(SGPacket **)packet
}
}
if (!demuxable) {
return SGECreateError(SGErrorCodeMutilDemuxerEndOfFile, SGOperationCodeMutilDemuxerNext);
return SGCreateError(SGErrorCodeMutilDemuxerEndOfFile, SGActionCodeMutilDemuxerNext);
}
error = [demuxable nextPacket:packet];
if (error) {
Expand Down
6 changes: 3 additions & 3 deletions SGPlayer/Classes/Core/SGDemuxer/SGPaddingDemuxer.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (NSError *)seekable
- (NSError *)seekToTime:(CMTime)time
{
if (!CMTIME_IS_NUMERIC(time)) {
return SGECreateError(SGErrorCodeInvlidTime, SGOperationCodeFormatSeekFrame);
return SGCreateError(SGErrorCodeInvlidTime, SGActionCodeFormatSeekFrame);
}
time = CMTimeMaximum(time, kCMTimeZero);
time = CMTimeMinimum(time, self->_duration);
Expand All @@ -67,7 +67,7 @@ - (NSError *)seekToTime:(CMTime)time
- (NSError *)nextPacket:(SGPacket **)packet
{
if (CMTimeCompare(self->_lasttime, self->_duration) >= 0) {
return SGECreateError(SGErrorCodeDemuxerEndOfFile, SGOperationCodeFormatReadFrame);
return SGCreateError(SGErrorCodeDemuxerEndOfFile, SGActionCodeFormatReadFrame);
}
CMTime timeStamp = self->_lasttime;
CMTime duration = CMTimeSubtract(self->_duration, self->_lasttime);
Expand All @@ -77,7 +77,7 @@ - (NSError *)nextPacket:(SGPacket **)packet
pkt.core->dts = av_rescale(AV_TIME_BASE, timeStamp.value, timeStamp.timescale);
pkt.core->duration = av_rescale(AV_TIME_BASE, duration.value, duration.timescale);
SGCodecDescriptor *cd = [[SGCodecDescriptor alloc] init];
cd.type = SGCodecType_Padding;
cd.type = SGCodecTypePadding;
cd.timebase = AV_TIME_BASE_Q;
[pkt setCodecDescriptor:cd];
[pkt fill];
Expand Down
4 changes: 2 additions & 2 deletions SGPlayer/Classes/Core/SGDemuxer/SGSegmentDemuxer.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ - (NSError *)open
- (NSError *)seekToTime:(CMTime)time
{
if (!CMTIME_IS_NUMERIC(time)) {
return SGECreateError(SGErrorCodeInvlidTime, SGOperationCodeFormatSeekFrame);
return SGCreateError(SGErrorCodeInvlidTime, SGActionCodeFormatSeekFrame);
}
if (!self->_demuxable) {
return nil;
Expand All @@ -85,7 +85,7 @@ - (NSError *)seekToTime:(CMTime)time
- (NSError *)nextPacket:(SGPacket **)packet
{
if (!self->_demuxable) {
return SGECreateError(SGErrorCodeDemuxerEndOfFile, SGOperationCodeSegmentDemuxerNext);
return SGCreateError(SGErrorCodeDemuxerEndOfFile, SGActionCodeSegmentDemuxerNext);
}
NSError *error = [self->_demuxable nextPacket:packet];
if (error) {
Expand Down
2 changes: 1 addition & 1 deletion SGPlayer/Classes/Core/SGDemuxer/SGTrackDemuxer.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ - (NSError *)seekable
- (NSError *)seekToTime:(CMTime)time
{
if (!CMTIME_IS_NUMERIC(time)) {
return SGECreateError(SGErrorCodeInvlidTime, SGOperationCodeFormatSeekFrame);
return SGCreateError(SGErrorCodeInvlidTime, SGActionCodeFormatSeekFrame);
}
time = CMTimeMaximum(time, kCMTimeZero);
time = CMTimeMinimum(time, self->_duration);
Expand Down
20 changes: 10 additions & 10 deletions SGPlayer/Classes/Core/SGDemuxer/SGURLDemuxer.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ - (NSError *)seekable
if (self->_context->pb && self->_context->pb->seekable > 0) {
return nil;
}
return SGECreateError(SGErrorCodeFormatNotSeekable, SGOperationCodeFormatGetSeekable);
return SGCreateError(SGErrorCodeFormatNotSeekable, SGActionCodeFormatGetSeekable);
}
return SGECreateError(SGErrorCodeNoValidFormat, SGOperationCodeFormatGetSeekable);
return SGCreateError(SGErrorCodeNoValidFormat, SGActionCodeFormatGetSeekable);
}

- (NSError *)seekToTime:(CMTime)time
{
if (!CMTIME_IS_NUMERIC(time)) {
return SGECreateError(SGErrorCodeInvlidTime, SGOperationCodeFormatSeekFrame);
return SGCreateError(SGErrorCodeInvlidTime, SGActionCodeFormatSeekFrame);
}
NSError *error = [self seekable];
if (error) {
Expand All @@ -113,9 +113,9 @@ - (NSError *)seekToTime:(CMTime)time
if (ret >= 0) {
self->_basetime = time;
}
return SGEGetError(ret, SGOperationCodeFormatSeekFrame);
return SGGetFFError(ret, SGActionCodeFormatSeekFrame);
}
return SGECreateError(SGErrorCodeNoValidFormat, SGOperationCodeFormatSeekFrame);
return SGCreateError(SGErrorCodeNoValidFormat, SGActionCodeFormatSeekFrame);
}

- (NSError *)nextPacket:(SGPacket **)packet
Expand All @@ -136,9 +136,9 @@ - (NSError *)nextPacket:(SGPacket **)packet
[pkt fill];
*packet = pkt;
}
return SGEGetError(ret, SGOperationCodeFormatReadFrame);
return SGGetFFError(ret, SGActionCodeFormatReadFrame);
}
return SGECreateError(SGErrorCodeNoValidFormat, SGOperationCodeFormatReadFrame);
return SGCreateError(SGErrorCodeNoValidFormat, SGActionCodeFormatReadFrame);
}

#pragma mark - AVFormatContext
Expand All @@ -147,7 +147,7 @@ - (NSError *)nextPacket:(SGPacket **)packet
{
AVFormatContext *ctx = avformat_alloc_context();
if (!ctx) {
return SGECreateError(SGErrorCodeNoValidFormat, SGOperationCodeFormatCreate);
return SGCreateError(SGErrorCodeNoValidFormat, SGActionCodeFormatCreate);
}
ctx->interrupt_callback.callback = callback;
ctx->interrupt_callback.opaque = opaque;
Expand All @@ -161,15 +161,15 @@ - (NSError *)nextPacket:(SGPacket **)packet
if (opts) {
av_dict_free(&opts);
}
NSError *error = SGEGetError(success, SGOperationCodeFormatOpenInput);
NSError *error = SGGetFFError(success, SGActionCodeFormatOpenInput);
if (error) {
if (ctx) {
avformat_free_context(ctx);
}
return error;
}
success = avformat_find_stream_info(ctx, NULL);
error = SGEGetError(success, SGOperationCodeFormatFindStreamInfo);
error = SGGetFFError(success, SGActionCodeFormatFindStreamInfo);
if (error) {
if (ctx) {
avformat_close_input(&ctx);
Expand Down
4 changes: 2 additions & 2 deletions SGPlayer/Classes/Core/SGDescription/SGCodecDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#import "SGTrack.h"

typedef NS_ENUM(NSUInteger, SGCodecType) {
SGCodecType_Decode,
SGCodecType_Padding,
SGCodecTypeDecode = 0,
SGCodecTypePadding = 1,
};

@interface SGCodecDescriptor : NSObject <NSCopying>
Expand Down
2 changes: 1 addition & 1 deletion SGPlayer/Classes/Core/SGDescription/SGCodecDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ - (id)copyWithZone:(NSZone *)zone
- (instancetype)init
{
if (self = [super init]) {
self->_type = SGCodecType_Decode;
self->_type = SGCodecTypeDecode;
self->_scale = CMTimeMake(1, 1);
self->_timebase = AV_TIME_BASE_Q;
self->_timeRange = CMTimeRangeMake(kCMTimeNegativeInfinity,
Expand Down
Loading

0 comments on commit 1751306

Please sign in to comment.