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_DEMO_COMMON_H 17 #define AVMUXER_DEMO_COMMON_H 18 19 #include <iostream> 20 #include <unistd.h> 21 #include <fcntl.h> 22 #include "avmuxer.h" 23 #include "nocopyable.h" 24 #include "native_avmuxer.h" 25 #include "avcodec_errors.h" 26 27 namespace OHOS { 28 namespace MediaAVCodec { 29 // only for demo 30 typedef struct AudioTrackParam { 31 const char* mimeType; 32 long long bitRate; 33 int sampleFormat; 34 int sampleRate; 35 int channels; 36 long long channelMask; 37 int samplePerFrame; 38 } AudioTrackParam; 39 40 typedef struct VideoTrackParam { 41 const char* mimeType; 42 long long bitRate; 43 int pixelFormat; 44 int width; 45 int height; 46 } VideoTrackParam; 47 48 class AVMuxerDemo : public NoCopyable { 49 public: 50 AVMuxerDemo() = default; 51 ~AVMuxerDemo() = default; 52 53 int32_t GetFdByMode(OH_AVOutputFormat format); 54 int32_t GetErrorFd(); 55 int32_t GetFdByName(OH_AVOutputFormat format, std::string fileName); 56 int32_t InnerGetFdByMode(Plugins::OutputFormat format); 57 int32_t InnerGetFdByName(Plugins::OutputFormat format, std::string fileName); 58 // native api 59 OH_AVMuxer* NativeCreate(int32_t fd, OH_AVOutputFormat format); 60 OH_AVErrCode NativeSetRotation(OH_AVMuxer* muxer, int32_t rotation); 61 OH_AVErrCode NativeAddTrack(OH_AVMuxer* muxer, int32_t* trackIndex, OH_AVFormat* trackFormat); 62 OH_AVErrCode NativeStart(OH_AVMuxer* muxer); 63 OH_AVErrCode NativeWriteSampleBuffer(OH_AVMuxer* muxer, uint32_t trackIndex, 64 OH_AVMemory* sample, OH_AVCodecBufferAttr info); 65 OH_AVErrCode NativeWriteSampleBuffer(OH_AVMuxer* muxer, uint32_t trackIndex, 66 OH_AVBuffer* sample); 67 OH_AVErrCode NativeStop(OH_AVMuxer* muxer); 68 OH_AVErrCode NativeDestroy(OH_AVMuxer* muxer); 69 70 // Inner api 71 int32_t InnerCreate(int32_t fd, Plugins::OutputFormat format); 72 int32_t InnerSetRotation(int32_t rotation); 73 int32_t InnerAddTrack(int32_t& trackIndex, std::shared_ptr<Meta> trackDesc); 74 int32_t InnerStart(); 75 int32_t InnerWriteSample(uint32_t trackIndex, std::shared_ptr<AVBuffer> sample); 76 int32_t InnerStop(); 77 int32_t InnerDestroy(); 78 private: 79 std::string filename = ""; 80 std::shared_ptr<AVMuxer> avmuxer_; 81 }; 82 } 83 } 84 #endif // AVMUXER_DEMO_COMMON_H