• 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 };
68 
69 struct CodecBufferInfo {
70     uint32_t bufferIndex = 0;
71     uintptr_t *buffer = nullptr;
72     uint8_t *bufferAddr = nullptr;
73     OH_AVCodecBufferAttr attr = {0, 0, 0, AVCODEC_BUFFER_FLAGS_NONE};
74 
CodecBufferInfoCodecBufferInfo75     explicit CodecBufferInfo(uint8_t *addr) : bufferAddr(addr){};
CodecBufferInfoCodecBufferInfo76     CodecBufferInfo(uint8_t *addr, int32_t bufferSize)
77         : bufferAddr(addr), attr({0, bufferSize, 0, AVCODEC_BUFFER_FLAGS_NONE}){};
CodecBufferInfoCodecBufferInfo78     CodecBufferInfo(uint32_t argBufferIndex, OH_AVBuffer *argBuffer)
79         : bufferIndex(argBufferIndex), buffer(reinterpret_cast<uintptr_t *>(argBuffer))
80     {
81         OH_AVBuffer_GetBufferAttr(argBuffer, &attr);
82     };
83 };
84 
85 struct CodecUserData {
86 public:
87     SampleInfo *sampleInfo = nullptr;
88 
89     uint32_t inputFrameCount = 0;
90     std::mutex inputMutex;
91     std::condition_variable inputCond;
92     std::queue<CodecBufferInfo> inputBufferInfoQueue;
93 
94     uint32_t outputFrameCount = 0;
95     std::mutex outputMutex;
96     std::condition_variable outputCond;
97     std::mutex renderMutex;
98     std::condition_variable renderCond;
99     std::queue<CodecBufferInfo> outputBufferInfoQueue;
100 
101     std::queue<unsigned char> renderQueue;
102 
103     int64_t speed = 1.0f;
104     int64_t frameWrittenForSpeed = 0;
105     int64_t endPosAudioBufferPts = 0;
106     int64_t currentPosAudioBufferPts = 0;
107 };
108 
109 #endif // AVCODEC_SAMPLE_INFO_H