1 /* 2 * Copyright (C) 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 AVMETADATAHELPER_HST_IMPL_H 17 #define AVMETADATAHELPER_HST_IMPL_H 18 19 #include <condition_variable> 20 #include <mutex> 21 22 #include "avmetadata_collector.h" 23 #include "av_thumbnail_generator.h" 24 #include "buffer/avsharedmemorybase.h" 25 #include "common/status.h" 26 #include "i_avmetadatahelper_engine.h" 27 #include "i_avmetadatahelper_service.h" 28 #include "media_demuxer.h" 29 #include "nocopyable.h" 30 #include "interrupt_monitor.h" 31 32 namespace OHOS { 33 namespace Media { 34 class TimeAndIndexConversion; 35 class AVMetadataHelperImpl : public IAVMetadataHelperEngine, 36 public std::enable_shared_from_this<AVMetadataHelperImpl>, 37 public NoCopyable { 38 public: 39 AVMetadataHelperImpl(); 40 ~AVMetadataHelperImpl(); 41 42 void OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode); 43 int32_t SetSource(const std::string &uri, int32_t usage) override; 44 int32_t SetSource(const std::shared_ptr<IMediaDataSource> &dataSrc) override; 45 std::string ResolveMetadata(int32_t key) override; 46 std::unordered_map<int32_t, std::string> ResolveMetadata() override; 47 std::shared_ptr<Meta> GetAVMetadata() override; 48 std::shared_ptr<AVSharedMemory> FetchFrameAtTime( 49 int64_t timeUs, int32_t option, const OutputConfiguration ¶m) override; 50 std::shared_ptr<AVBuffer> FetchFrameYuv( 51 int64_t timeUs, int32_t option, const OutputConfiguration ¶m) override; 52 std::shared_ptr<AVSharedMemory> FetchArtPicture() override; 53 int32_t GetTimeByFrameIndex(uint32_t index, uint64_t &time) override; 54 int32_t GetFrameIndexByTime(uint64_t time, uint32_t &index) override; 55 void SetInterruptState(bool isInterruptNeeded) override; 56 57 private: 58 std::shared_ptr<OHOS::Media::MediaDemuxer> mediaDemuxer_; 59 std::shared_ptr<AVMetaDataCollector> metadataCollector_; 60 std::shared_ptr<AVThumbnailGenerator> thumbnailGenerator_; 61 std::unordered_map<int32_t, std::string> collectedMeta_; 62 std::shared_ptr<AVSharedMemory> collectedArtPicture_; 63 std::shared_ptr<AVSharedMemoryBase> fetchedFrameAtTime_; 64 std::shared_ptr<OHOS::Media::TimeAndIndexConversion> conversion_ { nullptr }; 65 std::shared_ptr<InterruptMonitor> interruptMonitor_ {nullptr}; 66 std::atomic_bool stopProcessing_{ false }; 67 std::atomic_bool isForFrameConvert_{ false }; 68 69 Status SetSourceInternel(const std::string &uri, bool isForFrameConvert); 70 Status SetSourceInternel(const std::shared_ptr<IMediaDataSource> &dataSrc); 71 Status SetSourceForFrameConvert(const std::string &uri); 72 Status InitMetadataCollector(); 73 Status InitThumbnailGenerator(); 74 int32_t GetTimeForFrameConvert(uint32_t index, uint64_t &time); 75 int32_t GetIndexForFrameConvert(uint64_t time, uint32_t &index); 76 77 void Reset(); 78 void Destroy(); 79 std::string groupId_; 80 std::atomic<bool> isInterruptNeeded_ = false; 81 }; 82 } // namespace Media 83 } // namespace OHOS 84 #endif // AVMETADATAHELPER_HST_IMPL_H