1 /* 2 * Copyright (C) 2024 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 AVCODEC_AUDIO_AVBUFFER_MUXER_DEMO_H 17 #define AVCODEC_AUDIO_AVBUFFER_MUXER_DEMO_H 18 19 #include <unistd.h> 20 #include <fcntl.h> 21 #include "avmuxer.h" 22 #include "nocopyable.h" 23 #include "avcodec_errors.h" 24 #include "native_avmuxer.h" 25 #include "native_avcodec_base.h" 26 #include "common/native_mfmagic.h" 27 28 namespace OHOS { 29 namespace MediaAVCodec { 30 namespace AudioBufferDemo { 31 32 enum class AudioMuxerFormatType : int32_t { 33 TYPE_AAC = 0, 34 TYPE_H264 = 1, 35 TYPE_H265 = 2, 36 TYPE_MPEG4 = 3, 37 TYPE_HDR = 4, 38 TYPE_JPG = 5, 39 TYPE_AMRNB = 6, 40 TYPE_AMRWB = 7, 41 TYPE_MPEG3 = 8, 42 TYPE_FLAC = 9, 43 TYPE_MAX = 20, 44 }; 45 46 typedef struct AudioTrackParam { 47 const char* mimeType; 48 int32_t sampleRate; 49 int32_t channels; 50 int32_t frameSize; 51 int32_t width; 52 int32_t height; 53 double frameRate; 54 int32_t videoDelay; 55 int32_t colorPrimaries; 56 int32_t colorTransfer; 57 int32_t colorMatrixCoeff; 58 int32_t colorRange; 59 int32_t isHdrVivid; 60 bool isNeedCover; 61 bool isNeedVideo; 62 } AudioTrackParam; 63 64 class AVMuxerDemo : public NoCopyable { 65 public: 66 AVMuxerDemo(); 67 ~AVMuxerDemo(); 68 69 bool InitFile(const std::string& inputFile); 70 bool RunCase(const uint8_t *data, size_t size); 71 72 int32_t AddTrack(OH_AVMuxer* muxer, int32_t& trackIndex, AudioTrackParam param); 73 int32_t AddCoverTrack(OH_AVMuxer* muxer, int32_t& trackId, AudioTrackParam param); 74 75 AudioTrackParam InitFormatParam(AudioMuxerFormatType type); 76 OH_AVMuxer* Create(); 77 int32_t Start(); 78 int32_t Stop(); 79 int32_t Destroy(); 80 81 int32_t SetRotation(OH_AVMuxer* muxer, int32_t rotation); 82 83 void WriteTrackCover(OH_AVMuxer *muxer, int32_t trackIndex); 84 void WriteSingleTrackSampleAVBuffer(OH_AVMuxer *muxer, int32_t trackIndex); 85 bool UpdateWriteBufferInfoAVBuffer(OH_AVBuffer **buffer, OH_AVCodecBufferAttr *info); 86 87 private: 88 OH_AVMuxer *avmuxer_ = {nullptr}; 89 OH_AVBuffer *avbuffer = {nullptr}; 90 int32_t outputFd_ = {-1}; 91 size_t inputdatasize_ = 0; 92 std::string inputdata_; 93 std::string output_path_; 94 OH_AVOutputFormat output_format_; 95 AudioMuxerFormatType audioType_; 96 }; 97 } // namespace AudioBufferDemo 98 } // namespace MediaAVCodec 99 } // namespace OHOS 100 #endif // AVCODEC_AUDIO_AVBUFFER_MUXER_DEMO_H 101