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 MEDIA_PIPELINE_VIDEO_SINK_H 17 #define MEDIA_PIPELINE_VIDEO_SINK_H 18 19 #include "osal/task/task.h" 20 #include "sink/media_synchronous_sink.h" 21 #include "buffer/avbuffer.h" 22 #include "common/status.h" 23 #include "meta/video_types.h" 24 #include "filter/filter.h" 25 26 namespace OHOS { 27 namespace Media { 28 namespace Pipeline { 29 class VideoSink : public MediaSynchronousSink { 30 public: 31 VideoSink(); 32 ~VideoSink(); 33 bool DoSyncWrite(const std::shared_ptr<OHOS::Media::AVBuffer>& buffer) override; // true and render 34 void ResetSyncInfo() override; 35 Status GetLatency(uint64_t& nanoSec); 36 bool CheckBufferLatenessMayWait(const std::shared_ptr<OHOS::Media::AVBuffer>& buffer); 37 void SetSyncCenter(std::shared_ptr<MediaSyncManager> syncCenter); 38 void SetEventReceiver(const std::shared_ptr<EventReceiver> &receiver); 39 void SetFirstPts(int64_t pts); 40 void SetSeekFlag(); 41 private: 42 int64_t refreshTime_ {0}; 43 bool isFirstFrame_ {true}; 44 uint32_t frameRate_ {0}; 45 int64_t lastTimeStamp_ {HST_TIME_NONE}; 46 int64_t lastBufferTime_ {HST_TIME_NONE}; 47 int64_t deltaTimeAccu_ {0}; 48 bool forceRenderNextFrame_ {false}; 49 VideoScaleType videoScaleType_ {VideoScaleType::VIDEO_SCALE_TYPE_FIT}; 50 51 void CalcFrameRate(); 52 std::shared_ptr<OHOS::Media::Task> frameRateTask_ {nullptr}; 53 std::atomic<uint64_t> renderFrameCnt_ {0}; 54 std::atomic<uint64_t> discardFrameCnt_ {0}; 55 std::shared_ptr<EventReceiver> eventReceiver_ {nullptr}; 56 int64_t firstPts_ {HST_TIME_NONE}; 57 int64_t fixDelay_ {0}; 58 bool seekFlag_{false}; 59 }; 60 } // namespace Pipeline 61 } // namespace Media 62 } // namespace OHOS 63 64 #endif // MEDIA_PIPELINE_VIDEO_SINK_FILTER_H