/* * Copyright (c) 2025-2025 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 SEI_PARSER_HELPER_H #define SEI_PARSER_HELPER_H #include #include #include "surface_type.h" #include "filter/filter.h" #include "buffer/avbuffer_queue.h" #include "media_sync_manager.h" #include "osal/task/autospinlock.h" namespace OHOS { namespace Media { class SeiParserHelper; struct SeiPayloadInfo; struct SeiPayloadInfoGroup; using HelperConstructFunc = std::function()>; class SeiParserHelper { public: virtual ~SeiParserHelper() = default; Status ParseSeiPayload(const std::shared_ptr &buffer, std::shared_ptr &group); void SetPayloadTypeVec(const std::vector &vector); protected: SeiParserHelper() = default; private: static int32_t GetSeiTypeOrSize(uint8_t *&bodyPtr, const uint8_t *const maxPtr); static Status FillTargetBuffer(const std::shared_ptr buffer, uint8_t *&payloadPtr, const uint8_t *const maxPtr, const int32_t payloadSize); virtual bool IsSeiNalu(uint8_t *&headerPtr) = 0; bool FindNextSeiNaluPos(uint8_t *&startPtr, const uint8_t *const maxPtr); Status ParseSeiRbsp( uint8_t *&bodyPtr, const uint8_t *const maxPtr, const std::shared_ptr &group); static uint32_t GetNaluStartSeq(); std::vector payloadTypeVec_{}; SpinLock spinLock_; }; class AvcSeiParserHelper : public SeiParserHelper { public: AvcSeiParserHelper() = default; private: bool IsSeiNalu(uint8_t *&headerPtr) override; }; class HevcSeiParserHelper : public SeiParserHelper { public: HevcSeiParserHelper() = default; private: bool IsSeiNalu(uint8_t *&headerPtr) override; }; class SeiParserHelperFactory { public: static std::shared_ptr CreateHelper(const std::string &mimeType); private: static const std::map HELPER_CONSTRUCTOR_MAP; }; struct SeiPayloadInfo { int32_t payloadType; std::shared_ptr payload; }; struct SeiPayloadInfoGroup { int64_t playbackPosition = 0; std::vector vec; }; class SeiParserListener : public IBrokerListener { public: explicit SeiParserListener(const std::string &mimeType, sptr producer, std::shared_ptr eventReceiver, bool isFlowLimited); sptr AsObject() override { return nullptr; } void OnBufferFilled(std::shared_ptr &avBuffer) override; void SetPayloadTypeVec(const std::vector &vector); void OnInterrupted(bool isInterruptNeeded); void SetSyncCenter(std::shared_ptr syncCenter) { syncCenter_ = syncCenter; } Status SetSeiMessageCbStatus(bool status, const std::vector &payloadTypes); private: void FlowLimit(const std::shared_ptr &avBuffer); sptr producer_{}; std::shared_ptr seiParserHelper_{}; std::shared_ptr eventReceiver_{}; bool isFlowLimited_ { false }; std::atomic isInterruptNeeded_ { false }; std::mutex mutex_ {}; std::condition_variable cond_ {}; std::shared_ptr syncCenter_; int64_t startPts_ = 0; std::vector payloadTypes_{}; }; } // namespace Media } // namespace OHOS #endif // SEI_PARSER_HELPER_H