1 /* 2 * Copyright (C) 2021 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_ENGINE_GST_IMPL_H 17 #define AVMETADATAHELPER_ENGINE_GST_IMPL_H 18 19 #include <mutex> 20 #include <condition_variable> 21 #include "nocopyable.h" 22 #include "i_avmetadatahelper_engine.h" 23 #include "i_playbin_ctrler.h" 24 #include "gst_utils.h" 25 26 namespace OHOS { 27 namespace Media { 28 class AVMetaMetaCollector; 29 class AVMetaFrameExtractor; 30 31 class AVMetadataHelperEngineGstImpl : public IAVMetadataHelperEngine, public NoCopyable { 32 public: 33 AVMetadataHelperEngineGstImpl(); 34 ~AVMetadataHelperEngineGstImpl(); 35 36 int32_t SetSource(const std::string &uri, int32_t usage) override; 37 std::string ResolveMetadata(int32_t key) override; 38 std::unordered_map<int32_t, std::string> ResolveMetadata() override; 39 std::shared_ptr<AVSharedMemory> FetchFrameAtTime( 40 int64_t timeUs, int32_t option, const OutputConfiguration ¶m) override; 41 std::shared_ptr<AVSharedMemory> FetchArtPicture() override; 42 43 private: 44 void OnNotifyMessage(const PlayBinMessage &msg); 45 GValueArray *OnNotifyAutoPlugSort(GValueArray &factories); 46 int32_t SetSourceInternel(const std::string &uri, int32_t usage); 47 int32_t InitConverter(const OutputConfiguration &config); 48 int32_t PrepareInternel(bool async); 49 int32_t FetchFrameInternel(int64_t timeUsOrIndex, int32_t option, int32_t numFrames, 50 const OutputConfiguration ¶m, std::vector<std::shared_ptr<AVSharedMemory>> &outFrames); 51 int32_t ExtractMetadata(); 52 void OnNotifyElemSetup(GstElement &elem); 53 void OnNotifyElemUnSetup(GstElement &elem); 54 const std::string &GetStatusDescription(OHOS::Media::PlayBinState status); 55 void Reset(); 56 57 std::shared_ptr<IPlayBinCtrler> playBinCtrler_; 58 std::shared_ptr<PlayBinSinkProvider> sinkProvider_; 59 std::unique_ptr<AVMetaFrameExtractor> frameExtractor_; 60 std::unique_ptr<AVMetaMetaCollector> metaCollector_; 61 std::unordered_map<int32_t, std::string> collectedMeta_; 62 bool hasCollectMeta_ = false; 63 int32_t usage_ = AVMetadataUsage::AV_META_USAGE_PIXEL_MAP; 64 65 std::mutex mutex_; 66 std::condition_variable cond_; 67 bool errHappened_ = false; 68 int32_t status_ = PLAYBIN_STATE_IDLE; 69 bool firstFetch_ = true; 70 bool asyncDone_ = false; 71 }; 72 } // namespace Media 73 } // namespace OHOS 74 #endif // AVMETADATAHELPER_ENGINE_GST_IMPL_H