• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-2025 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 "media_sync_manager.h"
20 #include "common/status.h"
21 #include "buffer/avbuffer.h"
22 #include "meta/meta.h"
23 #include "osal/task/condition_variable.h"
24 #include "osal/task/mutex.h"
25 
26 #define BUFFER_FLAG_EOS 0x00000001
27 
28 namespace OHOS {
29 namespace Media {
30 namespace Pipeline {
31 class MediaSynchronousSink : public IMediaSynchronizer, public InterruptListener {
32 public:
MediaSynchronousSink()33     MediaSynchronousSink() {};
34     ~MediaSynchronousSink();
35     void WaitAllPrerolled(bool shouldWait) final;
36     int8_t GetPriority() final;
37 
38     void NotifyAllPrerolled() final;
39 
40     void OnInterrupted(bool isInterruptNeeded) override;
41 
42 protected:
43     virtual int64_t DoSyncWrite(const std::shared_ptr<OHOS::Media::AVBuffer>& buffer) = 0;
44 
45     virtual void ResetSyncInfo() = 0;
46 
47     void Init();
48     void WriteToPluginRefTimeSync(const std::shared_ptr<OHOS::Media::AVBuffer>& buffer);
49     void ResetPrerollReported();
50     void UpdateMediaTimeRange(const std::shared_ptr<Meta>& meta);
51 
52     int8_t syncerPriority_ {IMediaSynchronizer::NONE};
53     bool hasReportedPreroll_ {false};
54     std::atomic<bool> waitForPrerolled_ {false};
55     std::atomic<bool> isInterruptNeeded_ {false};
56     OHOS::Media::Mutex prerollMutex_ {};
57     OHOS::Media::ConditionVariable prerollCond_ {};
58     std::weak_ptr<IMediaSyncCenter> syncCenter_;
59 
60     int64_t waitPrerolledTimeout_ {0};
61 };
62 
63 class LagDetector {
64 public:
65     virtual void Reset() = 0;
66 
67     /**
68      * Calc all time delays
69      */
70     virtual bool CalcLag(std::shared_ptr<AVBuffer> buffer) = 0;
71 };
72 } // namespace Pipeline
73 } // namespace Media
74 } // namespace OHOS
75 
76 #endif // HISTREAMER_PIPELINE_MEDIA_SYNC_SINK_H
77