• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 AV_CODEC_INTERFACE_H
16 #define AV_CODEC_INTERFACE_H
17 #include "avcodec_video_encoder.h"
18 #include "avmuxer.h"
19 #include "avdemuxer.h"
20 #include "avsource.h"
21 
22 /**
23  * @brief Internal usage only, for camera framework interacts with av_codec related interfaces.
24  * @since 12
25  */
26 namespace OHOS::CameraStandard {
27 using AVMuxer = OHOS::MediaAVCodec::AVMuxer;
28 using AVCodecVideoEncoder = OHOS::MediaAVCodec::AVCodecVideoEncoder;
29 using AVMuxerFactory = OHOS::MediaAVCodec::AVMuxerFactory;
30 using VideoEncoderFactory = OHOS::MediaAVCodec::VideoEncoderFactory;
31 using Meta = OHOS::MediaAVCodec::Meta;
32 using AVBuffer = OHOS::MediaAVCodec::AVBuffer;
33 using AVCodecBufferInfo = OHOS::MediaAVCodec::AVCodecBufferInfo;
34 using AVCodecBufferFlag = OHOS::MediaAVCodec::AVCodecBufferFlag;
35 using Format = OHOS::Media::Format;
36 using MediaCodecCallback = OHOS::MediaAVCodec::MediaCodecCallback;
37 using AVSource = OHOS::MediaAVCodec::AVSource;
38 using SeekMode = OHOS::Media::Plugins::SeekMode;
39 using OutputFormat = OHOS::Media::Plugins::OutputFormat;
40 using AVSourceFactory = OHOS::MediaAVCodec::AVSourceFactory;
41 using AVDemuxer = OHOS::MediaAVCodec::AVDemuxer;
42 using AVDemuxerFactory = OHOS::MediaAVCodec::AVDemuxerFactory;
43 const int32_t AV_ERR_OK = 0;
44 const int32_t AV_ERR_INVALID_VAL = -1;
45 const int32_t AV_ERR_FAILED = -2;
46 class AVCodecIntf {
47 public:
48     virtual ~AVCodecIntf() = default;
49     virtual int32_t CreateAVMuxer(int32_t fd, OutputFormat format) = 0;
50     virtual int32_t CreateAVCodecVideoEncoder(const std::string& codecMime) = 0;
51     virtual int32_t AVMuxerSetParameter(const std::shared_ptr<Meta>& param) = 0;
52     virtual int32_t AVMuxerSetUserMeta(const std::shared_ptr<Meta>& userMeta) = 0;
53     virtual int32_t AVMuxerAddTrack(int32_t& trackIndex, const std::shared_ptr<Meta>& trackDesc) = 0;
54     virtual int32_t AVMuxerStart() = 0;
55     virtual int32_t AVMuxerWriteSample(uint32_t trackIndex, const std::shared_ptr<AVBuffer>& sample) = 0;
56     virtual int32_t AVMuxerStop() = 0;
57     virtual int32_t AVCodecVideoEncoderPrepare() = 0;
58     virtual int32_t AVCodecVideoEncoderStart() = 0;
59     virtual int32_t AVCodecVideoEncoderStop() = 0;
60     virtual int32_t AVCodecVideoEncoderRelease() = 0;
61     virtual bool IsVideoEncoderExisted() = 0;
62     virtual sptr<Surface> CreateInputSurface() = 0;
63     virtual int32_t QueueInputBuffer(uint32_t index) = 0;
64     virtual int32_t AVCodecVideoEncoderNotifyEos() = 0;
65     virtual int32_t ReleaseOutputBuffer(uint32_t index) = 0;
66     virtual int32_t AVCodecVideoEncoderSetParameter(const Format& format) = 0;
67     virtual int32_t AVCodecVideoEncoderSetCallback(const std::shared_ptr<MediaCodecCallback>& callback) = 0;
68     virtual int32_t AVCodecVideoEncoderConfigure(const Format& format) = 0;
69     virtual void CreateAVSource(int32_t fd, int64_t offset, int64_t size) = 0;
70     virtual int32_t AVSourceGetSourceFormat(Format& format) = 0;
71     virtual int32_t AVSourceGetUserMeta(Format& format) = 0;
72     virtual int32_t AVSourceGetTrackFormat(Format& format, uint32_t trackIndex) = 0;
73     virtual void CreateAVDemuxer(std::shared_ptr<AVSource> source) = 0;
74     virtual int32_t ReadSampleBuffer(uint32_t trackIndex, std::shared_ptr<AVBuffer> sample) = 0;
75     virtual int32_t AVDemuxerSeekToTime(int64_t millisecond, SeekMode mode) = 0;
76     virtual int32_t AVDemuxerSelectTrackByID(uint32_t trackIndex) = 0;
77 };
78 }  // namespace OHOS::CameraStandard
79 #endif //AV_CODEC_INTERFACE_H