• 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 
16 #ifndef AVCODEC_SAMPLE_INFO_H
17 #define AVCODEC_SAMPLE_INFO_H
18 
19 #include <cstdint>
20 #include <multimedia/player_framework/native_avcodec_videoencoder.h>
21 #include <string>
22 #include <condition_variable>
23 #include <queue>
24 #include <native_buffer/native_buffer.h>
25 #include "multimedia/player_framework/native_avcodec_base.h"
26 #include "multimedia/player_framework/native_avbuffer.h"
27 
28 constexpr int32_t BITRATE_10M = 10 * 1024 * 1024; // 10Mbps
29 constexpr int32_t BITRATE_20M = 20 * 1024 * 1024; // 20Mbps
30 constexpr int32_t BITRATE_30M = 30 * 1024 * 1024; // 30Mbps
31 
32 struct SampleInfo {
33     int32_t inputFd = -1;
34     int32_t outputFd = -1;
35     int64_t inputFileOffset = 0;
36     int64_t inputFileSize = 0;
37     std::string inputFilePath;
38     std::string videoCodecMime = "";
39     std::string audioCodecMime = "";
40     int32_t videoWidth = 0;
41     int32_t videoHeight = 0;
42     int32_t videoRotation = 0;
43 
44     double frameRate = 0.0;
45     int64_t bitrate = 10 * 1024 * 1024; // 10Mbps;
46     int64_t frameInterval = 0;
47     OH_AVPixelFormat pixelFormat = AV_PIXEL_FORMAT_NV12;
48     uint32_t bitrateMode = CBR;
49     int32_t iFrameInterval = 100;
50     int32_t rangFlag = 1;
51 
52     int32_t audioSampleForamt = 0;
53     int32_t audioSampleRate = 0;
54     int32_t audioChannelCount = 0;
55     int64_t audioChannelLayout = 0;
56 
57     int32_t isHDRVivid = 0;
58     int32_t hevcProfile = HEVC_PROFILE_MAIN;
59     OH_ColorPrimary primary = COLOR_PRIMARY_BT2020;
60     OH_TransferCharacteristic transfer = TRANSFER_CHARACTERISTIC_PQ;
61     OH_MatrixCoefficient matrix = MATRIX_COEFFICIENT_BT2020_CL;
62 
63     OHNativeWindow *window = nullptr;
64 
65     void (*playDoneCallback)(void *context) = nullptr;
66     void *playDoneCallbackData = nullptr;
67     uint8_t codecConfig[1024];
68     size_t codecConfigLen = 0;
69     int32_t aacAdts = -1;
70 };
71 
72 struct CodecBufferInfo {
73     uint32_t bufferIndex = 0;
74     uintptr_t *buffer = nullptr;
75     uint8_t *bufferAddr = nullptr;
76     OH_AVCodecBufferAttr attr = {0, 0, 0, AVCODEC_BUFFER_FLAGS_NONE};
77 
CodecBufferInfoCodecBufferInfo78     explicit CodecBufferInfo(uint8_t *addr) : bufferAddr(addr){};
CodecBufferInfoCodecBufferInfo79     CodecBufferInfo(uint8_t *addr, int32_t bufferSize)
80         : bufferAddr(addr), attr({0, bufferSize, 0, AVCODEC_BUFFER_FLAGS_NONE}){};
CodecBufferInfoCodecBufferInfo81     CodecBufferInfo(uint32_t argBufferIndex, OH_AVBuffer *argBuffer)
82         : bufferIndex(argBufferIndex), buffer(reinterpret_cast<uintptr_t *>(argBuffer))
83     {
84         OH_AVBuffer_GetBufferAttr(argBuffer, &attr);
85     };
86 };
87 
88 struct CodecUserData {
89 public:
90     SampleInfo *sampleInfo = nullptr;
91 
92     uint32_t inputFrameCount = 0;
93     std::mutex inputMutex;
94     std::condition_variable inputCond;
95     std::queue<CodecBufferInfo> inputBufferInfoQueue;
96 
97     uint32_t outputFrameCount = 0;
98     std::mutex outputMutex;
99     std::condition_variable outputCond;
100     std::mutex renderMutex;
101     std::condition_variable renderCond;
102     std::queue<CodecBufferInfo> outputBufferInfoQueue;
103 
104     std::queue<unsigned char> renderQueue;
105 
106     int64_t speed = 1.0f;
107     int64_t frameWrittenForSpeed = 0;
108     int64_t endPosAudioBufferPts = 0;
109     int64_t currentPosAudioBufferPts = 0;
110 };
111 
112 #endif // AVCODEC_SAMPLE_INFO_H