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