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(); DraggingPlayerAgent()31 DraggingPlayerAgent() {}; 32 DraggingPlayerAgent(const DraggingPlayerAgent &) = delete; 33 DraggingPlayerAgent operator=(const DraggingPlayerAgent &) = delete; 34 ~DraggingPlayerAgent(); 35 Status Init(const shared_ptr<DemuxerFilter> &demuxer, const shared_ptr<DecoderSurfaceFilter> &decoder, 36 std::string playerId); 37 void ConsumeVideoFrame(const std::shared_ptr<AVBuffer> avBuffer, uint32_t bufferIndex); 38 bool IsVideoStreamDiscardable(const std::shared_ptr<AVBuffer> avBuffer); 39 void UpdateSeekPos(int64_t seekMs); 40 void StopDragging(int64_t seekCnt); 41 void Release(); 42 43 private: 44 static bool LoadSymbol(); 45 static void *LoadLibrary(); 46 static bool CheckSymbol(void *handler); 47 static mutex mtx_; 48 unique_ptr<OHOS::Media::Task> task_; 49 static void *handler_; 50 using CreateFunc = DraggingPlayer *(*)(); 51 using DestroyFunc = void (*)(DraggingPlayer *); 52 static CreateFunc createFunc_; 53 static DestroyFunc destroyFunc_; 54 DraggingPlayer *draggingPlayer_ {nullptr}; 55 shared_ptr<VideoStreamReadyCallback> videoStreamReadyCb_ {nullptr}; 56 shared_ptr<VideoFrameReadyCallback> videoFrameReadyCb_ {nullptr}; 57 shared_ptr<DemuxerFilter> demuxer_ {nullptr}; 58 shared_ptr<DecoderSurfaceFilter> decoder_ {nullptr}; 59 bool isReleased_ {false}; 60 atomic<int64_t> seekCnt_ {0}; 61 mutex draggingMutex_ {}; 62 std::string threadName_ {}; 63 }; 64 65 } // namespace Media 66 } // namespace OHOS 67 #endif // DRAGGING_PLAYER_AGENT_H