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 "avmuxer.h" 19 #include "avmuxer_demo_common.h" 20 21 namespace OHOS { 22 namespace MediaAVCodec { 23 class AVMuxerDemoBase { 24 public: 25 AVMuxerDemoBase(); 26 virtual ~AVMuxerDemoBase() = default; 27 void RunCase(); 28 void RunMultiThreadCase(); 29 std::string GetOutputFileName(std::string header); 30 31 protected: 32 virtual void DoRunMuxer() = 0; 33 virtual void DoRunMultiThreadCase()= 0; 34 virtual int DoWriteSample(uint32_t trackIndex, std::shared_ptr<AVBuffer> sample) = 0; 35 virtual int DoAddTrack(int32_t &trackIndex, std::shared_ptr<Meta> trackDesc) = 0; DoGetInputBufferQueue(uint32_t trackIndex)36 virtual sptr<AVBufferQueueProducer> DoGetInputBufferQueue(uint32_t trackIndex) { return nullptr; }; 37 int AddVideoTrack(const VideoTrackParam *param); 38 int AddAudioTrack(const AudioTrackParam *param); 39 int AddCoverTrack(const VideoTrackParam *param); 40 void WriteTrackSample(); 41 void WriteAvTrackSample(); 42 void WriteSingleTrackSample(uint32_t trackId, std::shared_ptr<std::ifstream> file); 43 void WriteCoverSample(); 44 void WriteTrackSampleByBufferQueue(); 45 void WriteAvTrackSampleByBufferQueue(); 46 void WriteSingleTrackSampleByBufferQueue(sptr<AVBufferQueueProducer> bufferQueue, 47 std::shared_ptr<std::ifstream> file); 48 void SelectFormatMode(); 49 void SelectAudioMode(); 50 void SelectVideoMode(); 51 void SelectCoverMode(); 52 int SelectMode(); 53 int SelectModeAndOpenFile(); 54 bool ReadSampleDataInfo(std::shared_ptr<std::ifstream> file, std::shared_ptr<AVBuffer> &buffer); 55 bool ReadSampleDataInfoByBufferQueue(std::shared_ptr<std::ifstream> file, std::shared_ptr<AVBuffer> &buffer, 56 sptr<AVBufferQueueProducer> bufferQueue); 57 void Reset(); 58 static void MulThdWriteTrackSample(AVMuxerDemoBase *muxerBase, uint32_t trackId, 59 std::shared_ptr<std::ifstream> file); 60 static void MulThdWriteTrackSampleByBufferQueue(AVMuxerDemoBase *muxerBase, 61 sptr<AVBufferQueueProducer> bufferQueue, std::shared_ptr<std::ifstream> file); 62 63 const static AudioTrackParam *audioParams_; 64 const static VideoTrackParam *videoParams_; 65 const static VideoTrackParam *coverParams_; 66 static std::string videoType_; 67 static std::string audioType_; 68 static std::string coverType_; 69 static std::string format_; 70 static Plugins::OutputFormat outputFormat_; 71 static bool hasSetMode_; 72 73 int32_t videoTrackId_ {-1}; 74 int32_t audioTrackId_ {-1}; 75 int32_t coverTrackId_ {-1}; 76 sptr<AVBufferQueueProducer> videoBufferQueue_ {nullptr}; 77 sptr<AVBufferQueueProducer> audioBufferQueue_ {nullptr}; 78 sptr<AVBufferQueueProducer> coverBufferQueue_ {nullptr}; 79 std::shared_ptr<std::ifstream> audioFile_ {nullptr}; 80 std::shared_ptr<std::ifstream> videoFile_ {nullptr}; 81 std::shared_ptr<std::ifstream> coverFile_ {nullptr}; 82 int32_t outFd_ {-1}; 83 int64_t audioPts_ {0}; 84 int64_t videoPts_ {0}; 85 }; 86 } // MediaAVCodec 87 } // OHOS 88 #endif