1 /* 2 * Copyright (c) 2023-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HISTREAMER_PIPELINE_CORE_I_MEDIA_SYNC_CENTER_H 17 #define HISTREAMER_PIPELINE_CORE_I_MEDIA_SYNC_CENTER_H 18 19 #include "common/status.h" 20 21 namespace OHOS { 22 namespace Media { 23 namespace Pipeline { 24 /** 25 * @brief Pipeline clock supplier 26 */ 27 struct IMediaSynchronizer { 28 const static int8_t NONE = -1; 29 const static int8_t VIDEO_SINK = 0; 30 const static int8_t AUDIO_SINK = 2; 31 const static int8_t VIDEO_SRC = 4; 32 const static int8_t AUDIO_SRC = 6; 33 const static int8_t SUBTITLE_SINK = 8; 34 virtual ~IMediaSynchronizer() = default; 35 virtual int8_t GetPriority() = 0; 36 virtual void WaitAllPrerolled(bool shouldWait) = 0; 37 virtual void NotifyAllPrerolled() = 0; 38 }; 39 40 struct IMediaSyncCenter { 41 virtual Status Reset() = 0; 42 virtual void AddSynchronizer(IMediaSynchronizer* syncer) = 0; 43 44 virtual void RemoveSynchronizer(IMediaSynchronizer* syncer) = 0; 45 /** 46 * anchor a media time(pts) with real clock time. 47 * 48 * @param clockTime based on HST_TIME_BASE 49 * @param mediaTime media time based on HST_TIME_BASE 50 * @param maxMediaTime duration of resource 51 * @retval current frame Whether rendering is required 52 */ 53 virtual bool UpdateTimeAnchor(int64_t clockTime, int64_t delayTime, int64_t mediaTime, int64_t absMediaTime, 54 int64_t maxMediaTime, IMediaSynchronizer* supplier); 55 56 /** 57 * get media time currently 58 * @return media time now 59 */ 60 virtual int64_t GetMediaTimeNow() = 0; 61 62 /*** 63 * get clock time now 64 * @return return clock time based on HST_TIME_BASE 65 */ 66 virtual int64_t GetClockTimeNow() = 0; 67 68 /** 69 * Get clock time anchored with pts 70 * 71 * @param mediaTime target pts 72 * @return clock time anchored with pts 73 */ 74 virtual int64_t GetClockTime(int64_t mediaTime) = 0; 75 76 /** 77 * after IMediaSynchronizer has received the first frame, it should call this function to report the receiving of 78 * the first frame. 79 * 80 * @param supplier which report first frame 81 */ 82 virtual void ReportPrerolled(IMediaSynchronizer* supplier) = 0; 83 84 virtual void ReportEos(IMediaSynchronizer* supplier) = 0; 85 86 virtual void SetMediaTimeRangeStart(int64_t startMediaTime, int32_t trackId, IMediaSynchronizer* supplier) = 0; 87 88 virtual void SetMediaTimeRangeEnd(int64_t endMediaTime, int32_t trackId, IMediaSynchronizer* supplier) = 0; 89 90 virtual int64_t GetSeekTime() = 0; 91 92 virtual Status SetPlaybackRate(float rate) = 0; 93 94 virtual float GetPlaybackRate() = 0; 95 96 virtual void SetMediaStartPts(int64_t startPts) = 0; 97 98 virtual void ResetMediaStartPts() = 0; 99 100 virtual int64_t GetMediaStartPts() = 0; 101 102 virtual void SetLastAudioBufferDuration(int64_t durationUs) = 0; 103 }; 104 } // namespace Pipeline 105 } // namespace Media 106 } // namespace OHOS 107 #endif // HISTREAMER_PIPELINE_CORE_I_MEDIA_SYNC_CENTER_H 108