1 /*
2  * Copyright (c) 2022-2022 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 namespace OHOS {
19 namespace Media {
20 namespace Pipeline {
21 /**
22  * @brief Pipeline clock supplier
23  */
24 struct IMediaSynchronizer {
25     const static int8_t NONE = -1;
26     const static int8_t VIDEO_SINK = 0;
27     const static int8_t AUDIO_SINK = 2;
28     const static int8_t VIDEO_SRC = 4;
29     const static int8_t AUDIO_SRC = 6;
30     virtual ~IMediaSynchronizer() = default;
31     virtual int8_t GetPriority() = 0;
32     virtual std::string GetSynchronizerName() = 0;
33     virtual void WaitAllPrerolled(bool shouldWait) = 0;
34     virtual void NotifyAllPrerolled() = 0;
35 };
36 
37 struct IMediaSyncCenter {
38     virtual void AddSynchronizer(IMediaSynchronizer* syncer) = 0;
39 
40     virtual void RemoveSynchronizer(IMediaSynchronizer* syncer) = 0;
41     /**
42      * anchor a media time(pts) with real clock time.
43      *
44      * @param clockTime based on HST_TIME_BASE
45      * @param mediaTime media time based on HST_TIME_BASE
46      * @param supplier which report this time anchor
47      * @retval current frame Whether rendering is required
48      */
49     virtual bool UpdateTimeAnchor(int64_t clockTime, int64_t mediaTime, IMediaSynchronizer* supplier) = 0;
50 
51     /**
52      * get media time currently
53      * @return media time now
54      */
55     virtual int64_t GetMediaTimeNow() = 0;
56 
57     /***
58      * get clock time now
59      * @return return clock time based on HST_TIME_BASE
60      */
61     virtual int64_t GetClockTimeNow() = 0;
62 
63     /**
64      * Get clock time anchored with pts
65      *
66      * @param mediaTime target pts
67      * @return clock time anchored with pts
68      */
69     virtual int64_t GetClockTime(int64_t mediaTime) = 0;
70 
71     /**
72      * after IMediaSynchronizer has received the first frame, it should call this function to report the receiving of
73      * the first frame.
74      *
75      * @param supplier which report first frame
76      */
77     virtual void ReportPrerolled(IMediaSynchronizer* supplier) = 0;
78 
79     virtual void SetMediaTimeRangeStart(int64_t startMediaTime, int32_t trackId) = 0;
80 
81     virtual void SetMediaTimeRangeEnd(int64_t endMediaTime, int32_t trackId) = 0;
82 };
83 } // namespace Pipeline
84 } // namespace Media
85 } // namespace OHOS
86 #endif // HISTREAMER_PIPELINE_CORE_I_MEDIA_SYNC_CENTER_H
87