1da853ecaSopenharmony_ci/* 2da853ecaSopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd. 3da853ecaSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4da853ecaSopenharmony_ci * you may not use this file except in compliance with the License. 5da853ecaSopenharmony_ci * You may obtain a copy of the License at 6da853ecaSopenharmony_ci * 7da853ecaSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8da853ecaSopenharmony_ci * 9da853ecaSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10da853ecaSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11da853ecaSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12da853ecaSopenharmony_ci * See the License for the specific language governing permissions and 13da853ecaSopenharmony_ci * limitations under the License. 14da853ecaSopenharmony_ci */ 15da853ecaSopenharmony_ci#ifndef MEDIA_AVCODEC_COMMOM_H 16da853ecaSopenharmony_ci#define MEDIA_AVCODEC_COMMOM_H 17da853ecaSopenharmony_ci 18da853ecaSopenharmony_ci#include <string> 19da853ecaSopenharmony_ci#include <vector> 20da853ecaSopenharmony_ci#include <map> 21da853ecaSopenharmony_ci#include "av_common.h" 22da853ecaSopenharmony_ci#include "buffer/avbuffer.h" 23da853ecaSopenharmony_ci#include "meta/format.h" 24da853ecaSopenharmony_ci 25da853ecaSopenharmony_cinamespace OHOS { 26da853ecaSopenharmony_cinamespace MediaAVCodec { 27da853ecaSopenharmony_ciusing AVBuffer = OHOS::Media::AVBuffer; 28da853ecaSopenharmony_ciusing AVSharedMemory = OHOS::Media::AVSharedMemory; 29da853ecaSopenharmony_ciusing Format = OHOS::Media::Format; 30da853ecaSopenharmony_ci/** 31da853ecaSopenharmony_ci * @brief Error type of AVCodec 32da853ecaSopenharmony_ci * 33da853ecaSopenharmony_ci * @since 3.1 34da853ecaSopenharmony_ci * @version 3.1 35da853ecaSopenharmony_ci */ 36da853ecaSopenharmony_cienum AVCodecErrorType : int32_t { 37da853ecaSopenharmony_ci /* internal errors, error code passed by the errorCode, and definition see "AVCodecServiceErrCode" */ 38da853ecaSopenharmony_ci AVCODEC_ERROR_INTERNAL, 39da853ecaSopenharmony_ci /* extend error start. The extension error code agreed upon by the plug-in and 40da853ecaSopenharmony_ci the application will be transparently transmitted by the service. */ 41da853ecaSopenharmony_ci AVCODEC_ERROR_DECRYTION_FAILED, 42da853ecaSopenharmony_ci AVCODEC_ERROR_EXTEND_START = 0X10000, 43da853ecaSopenharmony_ci}; 44da853ecaSopenharmony_ci 45da853ecaSopenharmony_cienum class API_VERSION : int32_t { 46da853ecaSopenharmony_ci API_VERSION_10 = 10, 47da853ecaSopenharmony_ci API_VERSION_11 = 11 48da853ecaSopenharmony_ci}; 49da853ecaSopenharmony_ci 50da853ecaSopenharmony_ci/** 51da853ecaSopenharmony_ci * @brief Flag of AVCodecBuffer. 52da853ecaSopenharmony_ci * 53da853ecaSopenharmony_ci * @since 3.1 54da853ecaSopenharmony_ci */ 55da853ecaSopenharmony_cienum AVCodecBufferFlag : uint32_t { 56da853ecaSopenharmony_ci AVCODEC_BUFFER_FLAG_NONE = 0, 57da853ecaSopenharmony_ci /** This signals the end of stream. */ 58da853ecaSopenharmony_ci AVCODEC_BUFFER_FLAG_EOS = 1 << 0, 59da853ecaSopenharmony_ci /** This indicates that the buffer contains the data for a sync frame. */ 60da853ecaSopenharmony_ci AVCODEC_BUFFER_FLAG_SYNC_FRAME = 1 << 1, 61da853ecaSopenharmony_ci /** This indicates that the buffer only contains part of a frame. */ 62da853ecaSopenharmony_ci AVCODEC_BUFFER_FLAG_PARTIAL_FRAME = 1 << 2, 63da853ecaSopenharmony_ci /** This indicated that the buffer contains codec specific data. */ 64da853ecaSopenharmony_ci AVCODEC_BUFFER_FLAG_CODEC_DATA = 1 << 3, 65da853ecaSopenharmony_ci /** Flag is used to discard packets which are required to maintain valid decoder state but are not required 66da853ecaSopenharmony_ci * for output and should be dropped after decoding. 67da853ecaSopenharmony_ci * @since 12 68da853ecaSopenharmony_ci */ 69da853ecaSopenharmony_ci AVCODEC_BUFFER_FLAG_DISCARD = 1 << 4, 70da853ecaSopenharmony_ci /** Flag is used to indicate packets that contain frames that can be discarded by the decoder, 71da853ecaSopenharmony_ci * I.e. Non-reference frames. 72da853ecaSopenharmony_ci * @since 12 73da853ecaSopenharmony_ci */ 74da853ecaSopenharmony_ci AVCODEC_BUFFER_FLAG_DISPOSABLE = 1 << 5, 75da853ecaSopenharmony_ci /** Indicates that the frame is an extended discardable frame. It is not on the main reference path and 76da853ecaSopenharmony_ci * is referenced only by discardable frames or extended discardable frames. When subsequent frames on the branch 77da853ecaSopenharmony_ci * reference path are discarded by decoder, the frame can be further discarded. 78da853ecaSopenharmony_ci * @since 12 79da853ecaSopenharmony_ci */ 80da853ecaSopenharmony_ci AVCODEC_BUFFER_FLAG_DISPOSABLE_EXT = 1 << 6, 81da853ecaSopenharmony_ci}; 82da853ecaSopenharmony_ci 83da853ecaSopenharmony_cistruct AVCodecBufferInfo { 84da853ecaSopenharmony_ci /* The presentation timestamp in microseconds for the buffer */ 85da853ecaSopenharmony_ci int64_t presentationTimeUs = 0; 86da853ecaSopenharmony_ci /* The amount of data (in bytes) in the buffer */ 87da853ecaSopenharmony_ci int32_t size = 0; 88da853ecaSopenharmony_ci /* The start-offset of the data in the buffer */ 89da853ecaSopenharmony_ci int32_t offset = 0; 90da853ecaSopenharmony_ci}; 91da853ecaSopenharmony_ci 92da853ecaSopenharmony_ciclass AVCodecCallback { 93da853ecaSopenharmony_cipublic: 94da853ecaSopenharmony_ci virtual ~AVCodecCallback() = default; 95da853ecaSopenharmony_ci /** 96da853ecaSopenharmony_ci * Called when an error occurred. 97da853ecaSopenharmony_ci * 98da853ecaSopenharmony_ci * @param errorType Error type. For details, see {@link AVCodecErrorType}. 99da853ecaSopenharmony_ci * @param errorCode Error code. 100da853ecaSopenharmony_ci * @since 3.1 101da853ecaSopenharmony_ci * @version 3.1 102da853ecaSopenharmony_ci */ 103da853ecaSopenharmony_ci virtual void OnError(AVCodecErrorType errorType, int32_t errorCode) = 0; 104da853ecaSopenharmony_ci 105da853ecaSopenharmony_ci /** 106da853ecaSopenharmony_ci * Called when the output format has changed. 107da853ecaSopenharmony_ci * 108da853ecaSopenharmony_ci * @param format The new output format. 109da853ecaSopenharmony_ci * @since 3.1 110da853ecaSopenharmony_ci * @version 3.1 111da853ecaSopenharmony_ci */ 112da853ecaSopenharmony_ci virtual void OnOutputFormatChanged(const Format &format) = 0; 113da853ecaSopenharmony_ci 114da853ecaSopenharmony_ci /** 115da853ecaSopenharmony_ci * Called when an input buffer becomes available. 116da853ecaSopenharmony_ci * 117da853ecaSopenharmony_ci * @param index The index of the available input buffer. 118da853ecaSopenharmony_ci * @param buffer A {@link AVSharedMemory} object for a input buffer index that contains the data. 119da853ecaSopenharmony_ci * @since 3.1 120da853ecaSopenharmony_ci * @version 4.0 121da853ecaSopenharmony_ci */ 122da853ecaSopenharmony_ci virtual void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVSharedMemory> buffer) = 0; 123da853ecaSopenharmony_ci 124da853ecaSopenharmony_ci /** 125da853ecaSopenharmony_ci * Called when an output buffer becomes available. 126da853ecaSopenharmony_ci * 127da853ecaSopenharmony_ci * @param index The index of the available output buffer. 128da853ecaSopenharmony_ci * @param info The info of the available output buffer. For details, see {@link AVCodecBufferInfo} 129da853ecaSopenharmony_ci * @param flag The flag of the available output buffer. For details, see {@link AVCodecBufferFlag} 130da853ecaSopenharmony_ci * @param buffer A {@link AVSharedMemory} object for a output buffer index that contains the data. 131da853ecaSopenharmony_ci * @since 3.1 132da853ecaSopenharmony_ci * @version 4.0 133da853ecaSopenharmony_ci */ 134da853ecaSopenharmony_ci virtual void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag, 135da853ecaSopenharmony_ci std::shared_ptr<AVSharedMemory> buffer) = 0; 136da853ecaSopenharmony_ci}; 137da853ecaSopenharmony_ci 138da853ecaSopenharmony_ciclass AVDemuxerCallback { 139da853ecaSopenharmony_cipublic: 140da853ecaSopenharmony_ci virtual ~AVDemuxerCallback() = default; 141da853ecaSopenharmony_ci 142da853ecaSopenharmony_ci /** 143da853ecaSopenharmony_ci * Called when an drm info updated. 144da853ecaSopenharmony_ci * 145da853ecaSopenharmony_ci * @param drmInfo Drm Info. 146da853ecaSopenharmony_ci * @since 4.1 147da853ecaSopenharmony_ci * @version 4.1 148da853ecaSopenharmony_ci */ 149da853ecaSopenharmony_ci virtual void OnDrmInfoChanged(const std::multimap<std::string, std::vector<uint8_t>> &drmInfo) = 0; 150da853ecaSopenharmony_ci}; 151da853ecaSopenharmony_ci 152da853ecaSopenharmony_ciclass MediaCodecCallback { 153da853ecaSopenharmony_cipublic: 154da853ecaSopenharmony_ci virtual ~MediaCodecCallback() = default; 155da853ecaSopenharmony_ci /** 156da853ecaSopenharmony_ci * Called when an error occurred. 157da853ecaSopenharmony_ci * 158da853ecaSopenharmony_ci * @param errorType Error type. For details, see {@link AVCodecErrorType}. 159da853ecaSopenharmony_ci * @param errorCode Error code. 160da853ecaSopenharmony_ci * @since 4.1 161da853ecaSopenharmony_ci */ 162da853ecaSopenharmony_ci virtual void OnError(AVCodecErrorType errorType, int32_t errorCode) = 0; 163da853ecaSopenharmony_ci 164da853ecaSopenharmony_ci /** 165da853ecaSopenharmony_ci * Called when the output format has changed. 166da853ecaSopenharmony_ci * 167da853ecaSopenharmony_ci * @param format The new output format. 168da853ecaSopenharmony_ci * @since 4.1 169da853ecaSopenharmony_ci */ 170da853ecaSopenharmony_ci virtual void OnOutputFormatChanged(const Format &format) = 0; 171da853ecaSopenharmony_ci 172da853ecaSopenharmony_ci /** 173da853ecaSopenharmony_ci * Called when an input buffer becomes available. 174da853ecaSopenharmony_ci * 175da853ecaSopenharmony_ci * @param index The index of the available input buffer. 176da853ecaSopenharmony_ci * @param buffer A {@link AVBuffer} object for a input buffer index that contains the data. 177da853ecaSopenharmony_ci * @since 4.1 178da853ecaSopenharmony_ci */ 179da853ecaSopenharmony_ci virtual void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) = 0; 180da853ecaSopenharmony_ci 181da853ecaSopenharmony_ci /** 182da853ecaSopenharmony_ci * Called when an output buffer becomes available. 183da853ecaSopenharmony_ci * 184da853ecaSopenharmony_ci * @param index The index of the available output buffer. 185da853ecaSopenharmony_ci * @param buffer A {@link AVBuffer} object for a output buffer index that contains the data. 186da853ecaSopenharmony_ci * @since 4.1 187da853ecaSopenharmony_ci */ 188da853ecaSopenharmony_ci virtual void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) = 0; 189da853ecaSopenharmony_ci}; 190da853ecaSopenharmony_ci 191da853ecaSopenharmony_ciclass MediaCodecParameterCallback { 192da853ecaSopenharmony_cipublic: 193da853ecaSopenharmony_ci virtual ~MediaCodecParameterCallback() = default; 194da853ecaSopenharmony_ci /** 195da853ecaSopenharmony_ci * Called when an input parameter becomes available. 196da853ecaSopenharmony_ci * 197da853ecaSopenharmony_ci * @param index The index of the available input parameter. 198da853ecaSopenharmony_ci * @param parameter A {@link Format} object containing the corresponding index input parameter. 199da853ecaSopenharmony_ci * @since 5.0 200da853ecaSopenharmony_ci */ 201da853ecaSopenharmony_ci virtual void OnInputParameterAvailable(uint32_t index, std::shared_ptr<Format> parameter) = 0; 202da853ecaSopenharmony_ci}; 203da853ecaSopenharmony_ci 204da853ecaSopenharmony_ciclass MediaCodecParameterWithAttrCallback { 205da853ecaSopenharmony_cipublic: 206da853ecaSopenharmony_ci virtual ~MediaCodecParameterWithAttrCallback() = default; 207da853ecaSopenharmony_ci /** 208da853ecaSopenharmony_ci * Called when an input parameter with attribute becomes available. 209da853ecaSopenharmony_ci * 210da853ecaSopenharmony_ci * @param index The index of the available input parameter. 211da853ecaSopenharmony_ci * @param parameter A {@link Format} object containing the corresponding index input parameter. 212da853ecaSopenharmony_ci * @param attribute A read only {@link Format} object containing the corresponding index input attribute. 213da853ecaSopenharmony_ci * @since 5.0 214da853ecaSopenharmony_ci */ 215da853ecaSopenharmony_ci virtual void OnInputParameterWithAttrAvailable(uint32_t index, std::shared_ptr<Format> attribute, 216da853ecaSopenharmony_ci std::shared_ptr<Format> parameter) = 0; 217da853ecaSopenharmony_ci}; 218da853ecaSopenharmony_ci 219da853ecaSopenharmony_ciclass SurfaceBufferExtratDataKey { 220da853ecaSopenharmony_cipublic: 221da853ecaSopenharmony_ci /** 222da853ecaSopenharmony_ci * Key for timeStamp in surface's extraData, value type is int64 223da853ecaSopenharmony_ci */ 224da853ecaSopenharmony_ci static constexpr std::string_view ED_KEY_TIME_STAMP = "timeStamp"; 225da853ecaSopenharmony_ci 226da853ecaSopenharmony_ci /** 227da853ecaSopenharmony_ci * Key for endOfStream in surface's extraData, value type is bool 228da853ecaSopenharmony_ci */ 229da853ecaSopenharmony_ci static constexpr std::string_view ED_KEY_END_OF_STREAM = "endOfStream"; 230da853ecaSopenharmony_ci 231da853ecaSopenharmony_ciprivate: 232da853ecaSopenharmony_ci SurfaceBufferExtratDataKey() = delete; 233da853ecaSopenharmony_ci ~SurfaceBufferExtratDataKey() = delete; 234da853ecaSopenharmony_ci}; 235da853ecaSopenharmony_ci 236da853ecaSopenharmony_ciclass AVSourceFormat { 237da853ecaSopenharmony_cipublic: 238da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_TITLE = "title"; // string, title 239da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_ARTIST = "artist"; // string, artist 240da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_ALBUM = "album"; // string, album 241da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_ALBUM_ARTIST = "album_artist"; // string, album artist 242da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_DATE = "date"; // string, media date, 243da853ecaSopenharmony_ci // format: YYYY-MM-DD 244da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_COMMENT = "comment"; // string, comment 245da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_GENRE = "genre"; // string, genre 246da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_COPYRIGHT = "copyright"; // string, copyright 247da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_LANGUAGE = "language"; // string, language 248da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_DESCRIPTION = "description"; // string, description 249da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_LYRICS = "lyrics"; // string, cyrics 250da853ecaSopenharmony_ci 251da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_FILE_TYPE = "file_type"; // string, type 252da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_HAS_VIDEO = "has_video"; // bool, contain video tracks 253da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_HAS_AUDIO = "has_audio"; // bool, contain audio tracks 254da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_HAS_TIMEDMETA = "has_timed_meta"; // bool, contain timed metadata tracks 255da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_HAS_SUBTITLE = "has_subtitle"; // bool, contain subtitle tracks 256da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_AUTHOR = "author"; // string, autbor 257da853ecaSopenharmony_ci static constexpr std::string_view SOURCE_COMPOSER = "composer"; // string, composer 258da853ecaSopenharmony_ciprivate: 259da853ecaSopenharmony_ci AVSourceFormat() = delete; 260da853ecaSopenharmony_ci ~AVSourceFormat() = delete; 261da853ecaSopenharmony_ci}; 262da853ecaSopenharmony_ci 263da853ecaSopenharmony_cienum VideoBitStreamFormat { 264da853ecaSopenharmony_ci UNKNOWN = 0, 265da853ecaSopenharmony_ci AVCC, 266da853ecaSopenharmony_ci HVCC, 267da853ecaSopenharmony_ci ANNEXB 268da853ecaSopenharmony_ci}; 269da853ecaSopenharmony_ci 270da853ecaSopenharmony_cistruct CUVVConfigBox { 271da853ecaSopenharmony_ci uint16_t cuva_version_map; 272da853ecaSopenharmony_ci uint16_t terminal_provide_code; 273da853ecaSopenharmony_ci uint16_t terminal_provide_oriented_code; 274da853ecaSopenharmony_ci}; 275da853ecaSopenharmony_ci} // namespace MediaAVCodec 276da853ecaSopenharmony_ci} // namespace OHOS 277da853ecaSopenharmony_ci#endif // MEDIA_AVCODEC_COMMOM_H 278