• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024-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 
16 #ifndef TRANSCODER_PARAM_H
17 #define TRANSCODER_PARAM_H
18 
19 #include <cstdint>
20 #include <string>
21 #include "transcoder.h"
22 
23 namespace OHOS {
24 namespace Media {
25 
26 enum TransCoderPublicParamType : uint32_t {
27     // video begin
28     VIDEO_PUBLIC_PARAM_BEGIN,
29     VIDEO_ENC_FMT,
30     VIDEO_RECTANGLE,
31     VIDEO_BITRATE,
32     COLOR_SPACE_FMT,
33     VIDEO_PUBLIC_PARAM_END,
34     VIDEO_ENABLE_B_FRAME_ENCODING,
35     // audio begin
36     AUDIO_PUBLIC_PARAM_BEGIN,
37     AUDIO_ENC_FMT,
38     AUDIO_BITRATE,
39     AUDIO_PUBIC_PARAM_END,
40     // input begin,
41     INPUT_PATH,
42     INPUT_URL,
43     INPUT_FD,
44     // output begin,
45     OUTPUT_PATH,
46     OUTPUT_FD,
47 };
48 
49 /*
50  * TransCoder parameter base structure, inherite to it to extend the new parameter.
51  */
52 struct TransCoderParam {
TransCoderParamTransCoderParam53     explicit TransCoderParam(uint32_t t) : type(t) {}
54     TransCoderParam() = delete;
55     virtual ~TransCoderParam() = default;
56     uint32_t type;
57 };
58 
59 struct VideoEnc : public TransCoderParam {
VideoEncVideoEnc60     explicit VideoEnc(VideoCodecFormat fmt) : TransCoderParam(TransCoderPublicParamType::VIDEO_ENC_FMT), encFmt(fmt) {}
61     VideoCodecFormat encFmt;
62 };
63 
64 struct VideoRectangle : public TransCoderParam {
VideoRectangleVideoRectangle65     VideoRectangle(int32_t w, int32_t h) : TransCoderParam(TransCoderPublicParamType::VIDEO_RECTANGLE),
66         width(w), height(h) {}
67     int32_t width;
68     int32_t height;
69 };
70 
71 struct VideoBitRate : public TransCoderParam {
VideoBitRateVideoBitRate72     explicit VideoBitRate(int32_t br) : TransCoderParam(TransCoderPublicParamType::VIDEO_BITRATE), bitRate(br) {}
73     int32_t bitRate;
74 };
75 
76 struct VideoColorSpace : public TransCoderParam {
VideoColorSpaceVideoColorSpace77     explicit VideoColorSpace(TranscoderColorSpace fmt) : TransCoderParam(TransCoderPublicParamType::COLOR_SPACE_FMT),
78         colorSpaceFmt(fmt) {}
79     TranscoderColorSpace colorSpaceFmt;
80 };
81 
82 struct VideoEnableBFrameEncoding : public TransCoderParam {
VideoEnableBFrameEncodingVideoEnableBFrameEncoding83     explicit VideoEnableBFrameEncoding(bool enableBFrame) : TransCoderParam(
84         TransCoderPublicParamType::VIDEO_ENABLE_B_FRAME_ENCODING), enableBFrame(enableBFrame) {}
85     bool enableBFrame;
86 };
87 
88 struct AudioEnc : public TransCoderParam {
AudioEncAudioEnc89     explicit AudioEnc(AudioCodecFormat fmt) : TransCoderParam(TransCoderPublicParamType::AUDIO_ENC_FMT), encFmt(fmt) {}
90     AudioCodecFormat encFmt;
91 };
92 
93 struct AudioBitRate : public TransCoderParam {
AudioBitRateAudioBitRate94     explicit AudioBitRate(int32_t br) : TransCoderParam(TransCoderPublicParamType::AUDIO_BITRATE), bitRate(br) {}
95     int32_t bitRate;
96 };
97 
98 struct InputFilePath : public TransCoderParam {
InputFilePathInputFilePath99     explicit InputFilePath(const std::string &filePath) : TransCoderParam(TransCoderPublicParamType::INPUT_PATH),
100         path(filePath) {}
101     std::string path;
102 };
103 
104 struct InputUrl : public TransCoderParam {
InputUrlInputUrl105     explicit InputUrl(std::string inputUrl) : TransCoderParam(TransCoderPublicParamType::INPUT_URL), url(inputUrl) {}
106     std::string url;
107 };
108 
109 struct InputFd : public TransCoderParam {
InputFdInputFd110     explicit InputFd(int32_t inputFd, int64_t inputOffset, int64_t inputSize)
111         : TransCoderParam(TransCoderPublicParamType::INPUT_FD), fd(inputFd), offset(inputOffset), size(inputSize) {}
112     int32_t fd;
113     int64_t offset;
114     int64_t size;
115 };
116 
117 struct OutputFilePath : public TransCoderParam {
OutputFilePathOutputFilePath118     explicit OutputFilePath(const std::string &filePath)
119         : TransCoderParam(TransCoderPublicParamType::OUTPUT_PATH), path(filePath) {}
120     std::string path;
121 };
122 
123 struct OutputFd : public TransCoderParam {
OutputFdOutputFd124     explicit OutputFd(int32_t outFd) : TransCoderParam(TransCoderPublicParamType::OUTPUT_FD), fd(outFd) {}
125     int32_t fd;
126 };
127 } // namespace Media
128 } // namespace OHOS
129 #endif
130