• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #ifndef AVMUXER_DEMO_BASE
16 #define AVMUXER_DEMO_BASE
17 
18 #include <string>
19 #include "av_common.h"
20 #include "avcodec_common.h"
21 #include "avsharedmemorybase.h"
22 #include "media_description.h"
23 #include "avmuxer_demo_common.h"
24 namespace OHOS {
25 namespace MediaAVCodec {
26 class AVMuxerDemoBase {
27 public:
28     AVMuxerDemoBase();
29     virtual ~AVMuxerDemoBase() = default;
30     void RunCase();
31     void RunMultiThreadCase();
32 
33 protected:
34     virtual void DoRunMuxer() = 0;
35     virtual void DoRunMultiThreadCase()= 0;
36     virtual int DoWriteSample(uint32_t trackIndex, std::shared_ptr<AVSharedMemory> sample,
37         AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0;
38     virtual int DoAddTrack(int32_t &trackIndex, MediaDescription &trackDesc) = 0;
39     int AddVideoTrack(const VideoTrackParam *param);
40     int AddAudioTrack(const AudioTrackParam *param);
41     int AddCoverTrack(const VideoTrackParam *param);
42     void WriteTrackSample();
43     void WriteAvTrackSample();
44     void WriteSingleTrackSample(uint32_t trackId, std::shared_ptr<std::ifstream> file);
45     void WriteCoverSample();
46     void SelectFormatMode();
47     void SelectAudioVideoMode();
48     void SelectCoverMode();
49     int SelectMode();
50     int SelectModeAndOpenFile();
51     bool ReadSampleDataInfo(std::shared_ptr<std::ifstream> file, std::shared_ptr<AVSharedMemoryBase> &buffer,
52         AVCodecBufferInfo &info, AVCodecBufferFlag &flag);
53     void Reset();
54     static void MulThdWriteTrackSample(AVMuxerDemoBase *muxerBase, uint32_t trackId,
55         std::shared_ptr<std::ifstream> file);
56 
57     const static AudioTrackParam *audioParams_;
58     const static VideoTrackParam *videoParams_;
59     const static VideoTrackParam *coverParams_;
60     static std::string videoType_;
61     static std::string audioType_;
62     static std::string coverType_;
63     static std::string format_;
64     static OutputFormat outputFormat_;
65     static bool hasSetMode_;
66 
67     int32_t videoTrackId_ {-1};
68     int32_t audioTrackId_ {-1};
69     int32_t coverTrackId_ {-1};
70     std::shared_ptr<std::ifstream> audioFile_ {nullptr};
71     std::shared_ptr<std::ifstream> videoFile_ {nullptr};
72     std::shared_ptr<std::ifstream> coverFile_ {nullptr};
73     int32_t outFd_ {-1};
74     int64_t audioPts_ {0};
75     int64_t videoPts_ {0};
76 };
77 } // MediaAVCodec
78 } // OHOS
79 #endif