1 /* 2 * Copyright (c) 2024-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_VIDEO_MUXER_H 17 #define AVCODEC_AUDIO_VIDEO_MUXER_H 18 19 #include "native_avmuxer.h" 20 #include "native_avcodec_base.h" 21 #include "native_avformat.h" 22 #include "native_avbuffer.h" 23 #include <atomic> 24 #include <cstdint> 25 #include <memory> 26 #include <refbase.h> 27 #include "avmuxer.h" 28 #include "media_description.h" 29 #include "photo_asset_interface.h" 30 #include "av_codec_proxy.h" 31 32 namespace OHOS { 33 namespace CameraStandard { 34 const std::string STAGE_VIDEO_ENCODER_PARAM_VALUE = "video_encode_bitrate_mode=SQR:bitrate="; 35 const std::string STAGE_ENCODER_PARAM_KEY = "com.openharmony.encParam"; 36 enum TrackType { 37 AUDIO_TRACK = 0, 38 VIDEO_TRACK, 39 META_TRACK 40 }; 41 using namespace MediaAVCodec; 42 class AudioVideoMuxer : public RefBase { 43 public: 44 explicit AudioVideoMuxer(); 45 ~AudioVideoMuxer(); 46 47 int32_t Create(OH_AVOutputFormat format, std::shared_ptr<PhotoAssetIntf> photoAssetProxy); 48 int32_t AddTrack(int &trackId, std::shared_ptr<Format> format, TrackType type); 49 int32_t Start(); 50 int32_t WriteSampleBuffer(std::shared_ptr<OHOS::Media::AVBuffer> sample, TrackType type); 51 int32_t Stop(); 52 int32_t Release(); 53 int32_t SetRotation(int32_t rotation); 54 int32_t SetCoverTime(float timems); 55 int32_t SetStartTime(float timems); 56 int32_t SetTimedMetadata(); 57 int32_t GetVideoFd(); 58 std::shared_ptr<PhotoAssetIntf> GetPhotoAssetProxy(); 59 std::atomic<int32_t> releaseSignal_ = 2; 60 int32_t SetSqr(int32_t bitrate); 61 62 private: 63 std::shared_ptr<AVCodecIntf> avCodecProxy_ = nullptr; 64 int32_t fd_ = -1; 65 std::shared_ptr<PhotoAssetIntf> photoAssetProxy_ = nullptr; 66 int audioTrackId_ = -1; 67 int videoTrackId_ = -1; 68 int metaTrackId_ = -1; 69 }; 70 } // CameraStandard 71 } // OHOS 72 #endif // AVCODEC_SAMPLE_VIDEO_ENCODER_H