1da853ecaSopenharmony_ci/* 2da853ecaSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3da853ecaSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4da853ecaSopenharmony_ci * you may not use this file except in compliance with the License. 5da853ecaSopenharmony_ci * You may obtain a copy of the License at 6da853ecaSopenharmony_ci * 7da853ecaSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8da853ecaSopenharmony_ci * 9da853ecaSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10da853ecaSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11da853ecaSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12da853ecaSopenharmony_ci * See the License for the specific language governing permissions and 13da853ecaSopenharmony_ci * limitations under the License. 14da853ecaSopenharmony_ci */ 15da853ecaSopenharmony_ci 16da853ecaSopenharmony_ci#ifndef AVMUXER_DEMO_COMMON_H 17da853ecaSopenharmony_ci#define AVMUXER_DEMO_COMMON_H 18da853ecaSopenharmony_ci 19da853ecaSopenharmony_ci#include <iostream> 20da853ecaSopenharmony_ci#include <unistd.h> 21da853ecaSopenharmony_ci#include <fcntl.h> 22da853ecaSopenharmony_ci#include "avmuxer.h" 23da853ecaSopenharmony_ci#include "nocopyable.h" 24da853ecaSopenharmony_ci#include "native_avmuxer.h" 25da853ecaSopenharmony_ci#include "avcodec_errors.h" 26da853ecaSopenharmony_ci 27da853ecaSopenharmony_cinamespace OHOS { 28da853ecaSopenharmony_cinamespace MediaAVCodec { 29da853ecaSopenharmony_ci// only for demo 30da853ecaSopenharmony_citypedef struct AudioTrackParam { 31da853ecaSopenharmony_ci const char* mimeType; 32da853ecaSopenharmony_ci long long bitRate; 33da853ecaSopenharmony_ci int sampleFormat; 34da853ecaSopenharmony_ci int sampleRate; 35da853ecaSopenharmony_ci int channels; 36da853ecaSopenharmony_ci long long channelMask; 37da853ecaSopenharmony_ci int samplePerFrame; 38da853ecaSopenharmony_ci} AudioTrackParam; 39da853ecaSopenharmony_ci 40da853ecaSopenharmony_citypedef struct VideoTrackParam { 41da853ecaSopenharmony_ci const char* mimeType; 42da853ecaSopenharmony_ci long long bitRate; 43da853ecaSopenharmony_ci int pixelFormat; 44da853ecaSopenharmony_ci int width; 45da853ecaSopenharmony_ci int height; 46da853ecaSopenharmony_ci} VideoTrackParam; 47da853ecaSopenharmony_ci 48da853ecaSopenharmony_ciclass AVMuxerDemo : public NoCopyable { 49da853ecaSopenharmony_cipublic: 50da853ecaSopenharmony_ci AVMuxerDemo() = default; 51da853ecaSopenharmony_ci ~AVMuxerDemo() = default; 52da853ecaSopenharmony_ci 53da853ecaSopenharmony_ci int32_t GetFdByMode(OH_AVOutputFormat format); 54da853ecaSopenharmony_ci int32_t GetErrorFd(); 55da853ecaSopenharmony_ci int32_t GetFdByName(OH_AVOutputFormat format, std::string fileName); 56da853ecaSopenharmony_ci int32_t InnerGetFdByMode(Plugins::OutputFormat format); 57da853ecaSopenharmony_ci int32_t InnerGetFdByName(Plugins::OutputFormat format, std::string fileName); 58da853ecaSopenharmony_ci // native api 59da853ecaSopenharmony_ci OH_AVMuxer* NativeCreate(int32_t fd, OH_AVOutputFormat format); 60da853ecaSopenharmony_ci OH_AVErrCode NativeSetRotation(OH_AVMuxer* muxer, int32_t rotation); 61da853ecaSopenharmony_ci OH_AVErrCode NativeAddTrack(OH_AVMuxer* muxer, int32_t* trackIndex, OH_AVFormat* trackFormat); 62da853ecaSopenharmony_ci OH_AVErrCode NativeStart(OH_AVMuxer* muxer); 63da853ecaSopenharmony_ci OH_AVErrCode NativeWriteSampleBuffer(OH_AVMuxer* muxer, uint32_t trackIndex, 64da853ecaSopenharmony_ci OH_AVMemory* sample, OH_AVCodecBufferAttr info); 65da853ecaSopenharmony_ci OH_AVErrCode NativeWriteSampleBuffer(OH_AVMuxer* muxer, uint32_t trackIndex, 66da853ecaSopenharmony_ci OH_AVBuffer* sample); 67da853ecaSopenharmony_ci OH_AVErrCode NativeStop(OH_AVMuxer* muxer); 68da853ecaSopenharmony_ci OH_AVErrCode NativeDestroy(OH_AVMuxer* muxer); 69da853ecaSopenharmony_ci 70da853ecaSopenharmony_ci // Inner api 71da853ecaSopenharmony_ci int32_t InnerCreate(int32_t fd, Plugins::OutputFormat format); 72da853ecaSopenharmony_ci int32_t InnerSetRotation(int32_t rotation); 73da853ecaSopenharmony_ci int32_t InnerAddTrack(int32_t& trackIndex, std::shared_ptr<Meta> trackDesc); 74da853ecaSopenharmony_ci int32_t InnerStart(); 75da853ecaSopenharmony_ci int32_t InnerWriteSample(uint32_t trackIndex, std::shared_ptr<AVBuffer> sample); 76da853ecaSopenharmony_ci int32_t InnerStop(); 77da853ecaSopenharmony_ci int32_t InnerDestroy(); 78da853ecaSopenharmony_ciprivate: 79da853ecaSopenharmony_ci std::string filename = ""; 80da853ecaSopenharmony_ci std::shared_ptr<AVMuxer> avmuxer_; 81da853ecaSopenharmony_ci}; 82da853ecaSopenharmony_ci} 83da853ecaSopenharmony_ci} 84da853ecaSopenharmony_ci#endif // AVMUXER_DEMO_COMMON_H