1 /* 2 * Copyright (C) 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_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 { 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 protected: 41 virtual int64_t DoSyncWrite(const std::shared_ptr<OHOS::Media::AVBuffer>& buffer) = 0; 42 43 virtual void ResetSyncInfo() = 0; 44 45 void Init(); 46 void WriteToPluginRefTimeSync(const std::shared_ptr<OHOS::Media::AVBuffer>& buffer); 47 void ResetPrerollReported(); 48 void UpdateMediaTimeRange(const std::shared_ptr<Meta>& meta); 49 50 int8_t syncerPriority_ {IMediaSynchronizer::NONE}; 51 bool hasReportedPreroll_ {false}; 52 std::atomic<bool> waitForPrerolled_ {false}; 53 OHOS::Media::Mutex prerollMutex_ {}; 54 OHOS::Media::ConditionVariable prerollCond_ {}; 55 std::weak_ptr<IMediaSyncCenter> syncCenter_; 56 57 int64_t waitPrerolledTimeout_ {0}; 58 }; 59 60 class LagDetector { 61 public: 62 virtual void Reset() = 0; 63 64 /** 65 * Calc all time delays 66 */ 67 virtual bool CalcLag(std::shared_ptr<AVBuffer> buffer) = 0; 68 }; 69 } // namespace Pipeline 70 } // namespace Media 71 } // namespace OHOS 72 73 #endif // HISTREAMER_PIPELINE_MEDIA_SYNC_SINK_H 74