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 AVMETA_FRAME_CONVERTER_H 17 #define AVMETA_FRAME_CONVERTER_H 18 19 #include <mutex> 20 #include <condition_variable> 21 #include <gst/gst.h> 22 #include "i_avmetadatahelper_service.h" 23 #include "buffer/avsharedmemory.h" 24 #include "inner_msg_define.h" 25 #include "gst_mem_sink.h" 26 #include "gst_msg_processor.h" 27 #include "nocopyable.h" 28 29 namespace OHOS { 30 namespace Media { 31 class AVMetaFrameConverter : public NoCopyable { 32 public: 33 AVMetaFrameConverter(); 34 ~AVMetaFrameConverter(); 35 36 int32_t Init(const OutputConfiguration &config); 37 std::shared_ptr<AVSharedMemory> Convert(GstCaps &inCaps, GstBuffer &inBuf); 38 39 private: 40 int32_t SetupConvPipeline(); 41 int32_t SetupConvSrc(); 42 int32_t SetupConvSink(const OutputConfiguration &outConfig); 43 int32_t SetupMsgProcessor(); 44 void UninstallPipeline(); 45 int32_t ChangeState(GstState targetState); 46 int32_t PrepareConvert(GstCaps &inCaps); 47 std::shared_ptr<AVSharedMemory> GetConvertResult(); 48 int32_t Reset(); 49 void OnNotifyMessage(const InnerMessage &msg); 50 static GstFlowReturn OnNotifyNewSample(GstMemSink *elem, GstBuffer *sample, gpointer userData); 51 52 OutputConfiguration outConfig_; 53 GstPipeline *pipeline_ = nullptr; 54 GstElement *vidShMemSink_ = nullptr; 55 GstElement *appSrc_ = nullptr; 56 std::unique_ptr<GstMsgProcessor> msgProcessor_; 57 GstState currState_ = GST_STATE_NULL; 58 GstCaps *lastCaps_ = nullptr; 59 GstBuffer *lastResult_ = nullptr; 60 std::mutex mutex_; 61 std::condition_variable cond_; 62 bool startConverting_ = false; 63 std::vector<GstBuffer *> allResults_; 64 }; 65 } // namespace Media 66 } // namespace OHOS 67 #endif // AVMETA_FRAME_CONVERTER_H 68