1 /* 2 * Copyright (c) 2024 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 DRAGGING_PLAYER_AGENT_H 17 #define DRAGGING_PLAYER_AGENT_H 18 19 #include <atomic> 20 #include "dragging_player.h" 21 #include "common/status.h" 22 #include "osal/task/task.h" 23 24 namespace OHOS { 25 namespace Media { 26 using namespace std; 27 using namespace Pipeline; 28 class DraggingPlayerAgent : public std::enable_shared_from_this<DraggingPlayerAgent> { 29 public: 30 static shared_ptr<DraggingPlayerAgent> Create(); 31 static bool IsDraggingSupported(const shared_ptr<DemuxerFilter> &demuxer, 32 const shared_ptr<DecoderSurfaceFilter> &decoder); DraggingPlayerAgent()33 DraggingPlayerAgent() {}; 34 DraggingPlayerAgent(const DraggingPlayerAgent &) = delete; 35 DraggingPlayerAgent operator=(const DraggingPlayerAgent &) = delete; 36 ~DraggingPlayerAgent(); 37 Status Init(const shared_ptr<DemuxerFilter> &demuxer, const shared_ptr<DecoderSurfaceFilter> &decoder, 38 std::string playerId); 39 void ConsumeVideoFrame(const std::shared_ptr<AVBuffer> avBuffer, uint32_t bufferIndex); 40 bool IsVideoStreamDiscardable(const std::shared_ptr<AVBuffer> avBuffer); 41 void UpdateSeekPos(int64_t seekMs); 42 void StopDragging(int64_t seekCnt); 43 void Release(); 44 45 private: 46 static bool loaded_; 47 static bool LoadSymbol(); 48 static void *LoadLibrary(); 49 static bool CheckSymbol(void *handler); 50 static mutex mtx_; 51 unique_ptr<OHOS::Media::Task> task_; 52 static void *handler_; 53 using CreateFunc = DraggingPlayer *(*)(); 54 using DestroyFunc = void (*)(DraggingPlayer *); 55 using CheckSupportedFunc = bool (*) (DemuxerFilter *, DecoderSurfaceFilter *); 56 static CreateFunc createFunc_; 57 static DestroyFunc destroyFunc_; 58 static CheckSupportedFunc checkSupportedFunc_; 59 DraggingPlayer *draggingPlayer_ {nullptr}; 60 shared_ptr<VideoStreamReadyCallback> videoStreamReadyCb_ {nullptr}; 61 shared_ptr<VideoFrameReadyCallback> videoFrameReadyCb_ {nullptr}; 62 shared_ptr<DemuxerFilter> demuxer_ {nullptr}; 63 shared_ptr<DecoderSurfaceFilter> decoder_ {nullptr}; 64 bool isReleased_ {false}; 65 atomic<int64_t> seekCnt_ {0}; 66 mutex draggingMutex_ {}; 67 std::string threadName_ {}; 68 }; 69 70 } // namespace Media 71 } // namespace OHOS 72 #endif // DRAGGING_PLAYER_AGENT_H