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 int32_t SetSourceInternel(const std::string &uri, int32_t usage); 46 int32_t InitConverter(const OutputConfiguration &config); 47 int32_t PrepareInternel(bool async); 48 int32_t FetchFrameInternel(int64_t timeUsOrIndex, int32_t option, int32_t numFrames, 49 const OutputConfiguration ¶m, std::vector<std::shared_ptr<AVSharedMemory>> &outFrames); 50 int32_t ExtractMetadata(); 51 void OnNotifyElemSetup(GstElement &elem); 52 void Reset(); 53 54 std::shared_ptr<IPlayBinCtrler> playBinCtrler_; 55 std::shared_ptr<PlayBinSinkProvider> sinkProvider_; 56 std::unique_ptr<AVMetaFrameExtractor> frameExtractor_; 57 std::unique_ptr<AVMetaMetaCollector> metaCollector_; 58 std::unordered_map<int32_t, std::string> collectedMeta_; 59 bool hasCollectMeta_ = false; 60 int32_t usage_ = AVMetadataUsage::AV_META_USAGE_PIXEL_MAP; 61 62 std::mutex mutex_; 63 std::condition_variable cond_; 64 bool errHappened_ = false; 65 int32_t status_ = PLAYBIN_STATE_IDLE; 66 bool firstFetch_ = true; 67 }; 68 } // namespace Media 69 } // namespace OHOS 70 #endif // AVMETADATAHELPER_ENGINE_GST_IMPL_H