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 31 namespace OHOS { 32 namespace Media { 33 class AVMetadataHelperImpl : public IAVMetadataHelperEngine, 34 public std::enable_shared_from_this<AVMetadataHelperImpl>, 35 public NoCopyable { 36 public: 37 AVMetadataHelperImpl(); 38 ~AVMetadataHelperImpl(); 39 40 void OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode); 41 int32_t SetSource(const std::string &uri, int32_t usage) override; 42 int32_t SetSource(const std::shared_ptr<IMediaDataSource> &dataSrc) override; 43 std::string ResolveMetadata(int32_t key) override; 44 std::unordered_map<int32_t, std::string> ResolveMetadata() override; 45 std::shared_ptr<Meta> GetAVMetadata() override; 46 std::shared_ptr<AVSharedMemory> FetchFrameAtTime( 47 int64_t timeUs, int32_t option, const OutputConfiguration ¶m) override; 48 std::shared_ptr<AVBuffer> FetchFrameYuv( 49 int64_t timeUs, int32_t option, const OutputConfiguration ¶m) override; 50 std::shared_ptr<AVSharedMemory> FetchArtPicture() override; 51 int32_t GetTimeByFrameIndex(uint32_t index, uint64_t &time) override; 52 int32_t GetFrameIndexByTime(uint64_t time, uint32_t &index) override; 53 void SetInterruptState(bool isInterruptNeeded) override; 54 55 private: 56 std::shared_ptr<OHOS::Media::MediaDemuxer> mediaDemuxer_; 57 std::shared_ptr<AVMetaDataCollector> metadataCollector_; 58 std::shared_ptr<AVThumbnailGenerator> thumbnailGenerator_; 59 std::unordered_map<int32_t, std::string> collectedMeta_; 60 std::shared_ptr<AVSharedMemory> collectedArtPicture_; 61 std::shared_ptr<AVSharedMemoryBase> fetchedFrameAtTime_; 62 std::atomic_bool stopProcessing_{ false }; 63 64 Status SetSourceInternel(const std::string &uri); 65 Status SetSourceInternel(const std::shared_ptr<IMediaDataSource> &dataSrc); 66 Status InitMetadataCollector(); 67 Status InitThumbnailGenerator(); 68 69 void Reset(); 70 void Destroy(); 71 std::string groupId_; 72 std::atomic<bool> isInterruptNeeded_ = false; 73 }; 74 } // namespace Media 75 } // namespace OHOS 76 #endif // AVMETADATAHELPER_HST_IMPL_H