From d02f881d389c27f8e300e81d77fec70b1afbe9b1 Mon Sep 17 00:00:00 2001 From: skufly Date: Tue, 28 Apr 2020 18:26:03 +0800 Subject: [PATCH] feat(iOS): add interface to sync player --- platform/Apple/source/CicadaDef.h | 24 ++++++++++++++ platform/Apple/source/CicadaPlayer.h | 31 +++++++++++++++++ platform/Apple/source/CicadaPlayer.mm | 48 +++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) diff --git a/platform/Apple/source/CicadaDef.h b/platform/Apple/source/CicadaDef.h index 050985212..63f98e9f7 100644 --- a/platform/Apple/source/CicadaDef.h +++ b/platform/Apple/source/CicadaDef.h @@ -166,6 +166,30 @@ typedef enum CicadaOption: NSUInteger { CICADA_OPTION_RENDER_FPS = 0, } CicadaOption; +typedef enum CicadaPlaybackType: NSUInteger { + /** + * @brief 播放音视频,默认值 + */ + /**** + * @brief play video & audio, default + */ + CicadaPlaybackTypeALL = 0, + /** + * @brief 播放视频 + */ + /**** + * @brief play video + */ + CicadaPlaybackTypeVideo = 1, + /** + * @brief 播放音频 + */ + /**** + * @brief play audio + */ + CicadaPlaybackTypeAudio = 2, +} CicadaPlaybackType; + /** @brief CicadaErrorModel为播放错误信息描述 */ diff --git a/platform/Apple/source/CicadaPlayer.h b/platform/Apple/source/CicadaPlayer.h index 41f5ed585..1b3263bea 100644 --- a/platform/Apple/source/CicadaPlayer.h +++ b/platform/Apple/source/CicadaPlayer.h @@ -285,6 +285,37 @@ OBJC_EXPORT */ -(void) setDefaultBandWidth:(int)bandWidth; +/** + @brief 设置所需的播放内容。 + @param CicadaPlaybackType 指定播放音频或视频。 + */ +/**** + @brief Set the playback track. + @param CicadaPlaybackType The specified track to playback. + */ +-(void) setPlaybackType:(CicadaPlaybackType)type; + +/** + @brief 获取当前播放的pts。 + @return 当前播放的pts。 + */ +/**** + @brief Get playing pts. + @return Playing pts. + */ +-(int64_t) getPlayingPts; + + +/** + @brief 设置参考时间钟。 + @param referClock 参考时间钟。 + */ +/**** + @brief Set the refer clock + @param referClock The refer clock + */ +-(void) SetClockRefer:(int64_t (^)(void))referClock; + /** * @brief 获取播放器的参数 * diff --git a/platform/Apple/source/CicadaPlayer.mm b/platform/Apple/source/CicadaPlayer.mm index 6e8d5bcbd..72a1285fb 100644 --- a/platform/Apple/source/CicadaPlayer.mm +++ b/platform/Apple/source/CicadaPlayer.mm @@ -49,6 +49,8 @@ static void CicadaPlayer_log_print(void *userData, int prio, const char *buf) } } +typedef int64_t(^CicadaReferClockFun) (); + @interface CicadaPlayer () { CicadaPlayerView* mView; @@ -64,6 +66,7 @@ @interface CicadaPlayer () @property(nonatomic,assign) CicadaStatus mCurrentStatus; @property(nonatomic, strong) NSString *traceId; @property(nonatomic, strong) CicadaThumbnail* thumbnail; +@property(nonatomic, strong) CicadaReferClockFun referClock; @end @implementation CicadaPlayer @@ -73,6 +76,7 @@ @implementation CicadaPlayer @synthesize currentPosition = _currentPosition; @synthesize bufferedPosition = _bufferedPosition; @synthesize duration = _duration; +@synthesize referClock = _referClock; - (void)resetProperty { @@ -843,6 +847,50 @@ - (void) setDelegate:(id)theDelegate } } +-(void) setPlaybackType:(CicadaPlaybackType)type +{ + if (self.player) { + uint64_t flags = 0; + switch (type) { + case CicadaPlaybackTypeVideo: + flags = (1 << CICADA_TRACK_VIDEO); + break; + case CicadaPlaybackTypeAudio: + flags = (1 << CICADA_TRACK_AUDIO); + break; + default: + flags = (1 << CICADA_TRACK_VIDEO) | (1 << CICADA_TRACK_AUDIO); + break; + } + self.player->SetStreamTypeFlags(flags); + } +} + +-(int64_t) getPlayingPts +{ + if (self.player) { + self.player->GetMasterClockPts(); + } + return 0; +} + +int64_t CicadaClockRefer(void *arg) +{ + CicadaPlayer *player = (__bridge CicadaPlayer *)arg; + if (player.referClock) { + return player.referClock(); + } + return -1; +} + +-(void) SetClockRefer:(int64_t (^)(void))referClock +{ + if (self.player) { + self.player->SetClockRefer(CicadaClockRefer, (__bridge void*)self); + } + self.referClock = referClock; +} + -(NSString *) getOption:(CicadaOption)key { if (nullptr == self.player) {