/* * Copyright (c) 2024-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SEEK_AGENT_H #define SEEK_AGENT_H #include #include #include "common/status.h" #include "avbuffer_queue_define.h" #include "osal/task/condition_variable.h" #include "osal/task/mutex.h" #include "iremote_stub.h" #include "demuxer_filter.h" namespace OHOS { namespace Media { class HiPlayerImpl; class SeekAgent : public std::enable_shared_from_this { public: explicit SeekAgent(std::shared_ptr demuxer, int64_t startPts = 0); ~SeekAgent(); Status Seek(int64_t seekPos, bool &timeout); Status OnAudioBufferFilled(std::shared_ptr& buffer, sptr producer, int32_t trackId); Status OnVideoBufferFilled(std::shared_ptr& buffer, sptr producer, int32_t trackId); Status AlignAudioPosition(int64_t audioPosition); void SetInterruptState(bool isNeed); private: Status SetBufferFilledListener(); Status RemoveBufferFilledListener(); Status GetAllTrackInfo(uint32_t &videoTrackId, std::vector &audioTrackIds); bool GetAudioTrackId(uint32_t &audioTrackId); std::shared_ptr demuxer_; Mutex targetArrivedLock_; ConditionVariable targetArrivedCond_; bool isAudioTargetArrived_{true}; bool isVideoTargetArrived_{true}; int64_t seekTargetPts_{-1}; int64_t mediaStartPts_{0}; bool isInterrputNeeded_{false}; std::atomic isSeeking_{false}; std::map> producerMap_; std::map> listenerMap_; static constexpr uint32_t WAIT_MAX_MS = 4000; static constexpr uint32_t MS_TO_US = 1000; }; class AudioBufferFilledListener : public IRemoteStub { public: AudioBufferFilledListener(std::shared_ptr seekAgent, sptr producer, int32_t trackId); ~AudioBufferFilledListener() = default; void OnBufferFilled(std::shared_ptr& buffer); private: std::weak_ptr seekAgent_; sptr producer_; int32_t trackId_; }; class VideoBufferFilledListener : public IRemoteStub { public: VideoBufferFilledListener(std::shared_ptr seekAgent, sptr producer, int32_t trackId); ~VideoBufferFilledListener() = default; void OnBufferFilled(std::shared_ptr& buffer); private: std::weak_ptr seekAgent_; sptr producer_; int32_t trackId_; }; } // namespace Media } // namespace OHOS #endif // SEEK_AGENT_H