• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 AVMUXER_ENGINE_GST_IMPL_H
17 #define AVMUXER_ENGINE_GST_IMPL_H
18 
19 #include <set>
20 #include <map>
21 #include <tuple>
22 #include "nocopyable.h"
23 #include "i_avmuxer_engine.h"
24 #include "gst_msg_processor.h"
25 #include "gst_shmem_wrap_allocator.h"
26 #include "avmuxer_util.h"
27 
28 namespace OHOS {
29 namespace Media {
30 class AVMuxerEngineGstImpl :
31     public IAVMuxerEngine,
32     public std::enable_shared_from_this<AVMuxerEngineGstImpl>,
33     public NoCopyable {
34 public:
35     AVMuxerEngineGstImpl();
36     ~AVMuxerEngineGstImpl();
37 
38     std::vector<std::string> GetAVMuxerFormatList() override;
39     int32_t Init() override;
40     int32_t SetOutput(int32_t fd, const std::string &format) override;
41     int32_t SetLocation(float latitude, float longitude) override;
42     int32_t SetRotation(int32_t rotation) override;
43     int32_t AddTrack(const MediaDescription &trackDesc, int32_t &trackId) override;
44     int32_t Start() override;
45     int32_t WriteTrackSample(std::shared_ptr<AVSharedMemory> sampleData, const TrackSampleInfo &sampleInfo) override;
46     int32_t Stop() override;
47 private:
48     void SetParse(const std::string &mimeType);
49     int32_t WriteData(std::shared_ptr<AVSharedMemory> sampleData, const TrackSampleInfo &sampleInfo, GstElement *src);
50     int32_t SetupMsgProcessor();
51     void OnNotifyMessage(const InnerMessage &msg);
52     void Clear();
53 
54     GstElement *muxBin_ = nullptr;
55     std::map<int32_t, TrackInfo> trackInfo_;
56     std::mutex mutex_;
57     std::condition_variable cond_;
58     bool endFlag_ = false;
59     bool errHappened_ = false;
60     std::unique_ptr<GstMsgProcessor> msgProcessor_;
61     uint32_t videoTrackNum_ = 0;
62     uint32_t audioTrackNum_ = 0;
63     std::string format_;
64     bool isPlay_ = false;
65     GstShMemWrapAllocator *allocator_;
66 };
67 }  // namespace Media
68 }  // namespace OHOS
69 #endif // AVMUXER_ENGINE_GST_IMPL_H