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_MEDIA_SYNC_SINK_H
17 #define HISTREAMER_PIPELINE_MEDIA_SYNC_SINK_H
18 #include <functional>
19 #include "pipeline/core/filter_base.h"
20 #include "pipeline/core/media_sync_manager.h"
21 
22 namespace OHOS {
23 namespace Media {
24 namespace Pipeline {
25 class MediaSynchronousSink : public FilterBase, public IMediaSynchronizer {
26 public:
MediaSynchronousSink(const std::string & name)27     explicit MediaSynchronousSink(const std::string& name) : FilterBase(name) {}
28     ~MediaSynchronousSink() override;
29     void WaitAllPrerolled(bool shouldWait) final;
30     int8_t GetPriority() final;
31 
32     void NotifyAllPrerolled() final;
33 
34     void Init(EventReceiver *receiver, FilterCallback *callback) override;
35 
GetSynchronizerName()36     std::string GetSynchronizerName() override
37     {
38         return name_;
39     }
40 protected:
41     virtual ErrorCode DoSyncWrite(const AVBufferPtr& buffer) = 0;
42     virtual ErrorCode WriteToPluginRefTimeSync(const AVBufferPtr& buffer);
43     virtual void ResetSyncInfo() = 0;
44 
45     void ResetPrerollReported();
46     void UpdateMediaTimeRange(const Plugin::Meta& meta);
47 
48     int8_t syncerPriority_ {IMediaSynchronizer::NONE};
49     bool hasReportedPreroll_ {false};
50     std::atomic<bool> waitForPrerolled_ {false};
51     OSAL::Mutex prerollMutex_ {};
52     OSAL::ConditionVariable prerollCond_ {};
53 
54     int64_t waitPrerolledTimeout_ {0};
55 };
56 } // namespace Pipeline
57 } // namespace Media
58 } // namespace OHOS
59 
60 #endif // HISTREAMER_PIPELINE_MEDIA_SYNC_SINK_H
61