* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MEDIA_AVCODEC_COMMOM_H
#define MEDIA_AVCODEC_COMMOM_H
#include <memory>
#include <string>
#include <vector>
#include <map>
#include "av_common.h"
#include "buffer/avbuffer.h"
#include "meta/format.h"
namespace OHOS {
namespace MediaAVCodec {
using AVBuffer = OHOS::Media::AVBuffer;
using AVSharedMemory = OHOS::Media::AVSharedMemory;
using Format = OHOS::Media::Format;
* @brief Error type of AVCodec
*
* @since 3.1
* @version 3.1
*/
enum AVCodecErrorType : int32_t {
AVCODEC_ERROR_INTERNAL,
the application will be transparently transmitted by the service. */
AVCODEC_ERROR_DECRYTION_FAILED,
AVCODEC_ERROR_FRAMEWORK_FAILED,
AVCODEC_ERROR_EXTEND_START = 0X10000,
};
enum class API_VERSION : int32_t {
API_VERSION_10 = 10,
API_VERSION_11 = 11
};
* @brief Flag of AVCodecBuffer.
*
* @since 3.1
*/
enum AVCodecBufferFlag : uint32_t {
AVCODEC_BUFFER_FLAG_NONE = 0,
AVCODEC_BUFFER_FLAG_EOS = 1 << 0,
AVCODEC_BUFFER_FLAG_SYNC_FRAME = 1 << 1,
AVCODEC_BUFFER_FLAG_PARTIAL_FRAME = 1 << 2,
AVCODEC_BUFFER_FLAG_CODEC_DATA = 1 << 3,
* for output and should be dropped after decoding.
* @since 12
*/
AVCODEC_BUFFER_FLAG_DISCARD = 1 << 4,
* I.e. Non-reference frames.
* @since 12
*/
AVCODEC_BUFFER_FLAG_DISPOSABLE = 1 << 5,
* is referenced only by discardable frames or extended discardable frames. When subsequent frames on the branch
* reference path are discarded by decoder, the frame can be further discarded.
* @since 12
*/
AVCODEC_BUFFER_FLAG_DISPOSABLE_EXT = 1 << 6,
AVCODEC_BUFFER_FLAG_MUL_FRAME = 1 << 7,
};
struct AVCodecBufferInfo {
int64_t presentationTimeUs = 0;
int32_t size = 0;
int32_t offset = 0;
};
class AVCodecCallback {
public:
virtual ~AVCodecCallback() = default;
* Called when an error occurred.
*
* @param errorType Error type. For details, see {@link AVCodecErrorType}.
* @param errorCode Error code.
* @since 3.1
* @version 3.1
*/
virtual void OnError(AVCodecErrorType errorType, int32_t errorCode) = 0;
* Called when the output format has changed.
*
* @param format The new output format.
* @since 3.1
* @version 3.1
*/
virtual void OnOutputFormatChanged(const Format &format) = 0;
* Called when an input buffer becomes available.
*
* @param index The index of the available input buffer.
* @param buffer A {@link AVSharedMemory} object for a input buffer index that contains the data.
* @since 3.1
* @version 4.0
*/
virtual void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVSharedMemory> buffer) = 0;
* Called when an output buffer becomes available.
*
* @param index The index of the available output buffer.
* @param info The info of the available output buffer. For details, see {@link AVCodecBufferInfo}
* @param flag The flag of the available output buffer. For details, see {@link AVCodecBufferFlag}
* @param buffer A {@link AVSharedMemory} object for a output buffer index that contains the data.
* @since 3.1
* @version 4.0
*/
virtual void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag,
std::shared_ptr<AVSharedMemory> buffer) = 0;
};
* @brief Timed metadata structure for interstitial event reporting.
* Carries parsed interstitial event data from HLS #EXT-X-DATERANGE or DASH EventStream/Event.
* @since 7.0
* @version 1.0
*/
struct AVTimedMetaData {
std::string id;
std::string classify;
int64_t start{0};
int64_t duration{0};
std::map<std::string, std::string> contents;
};
struct AVAdsChangeEvent {
int32_t type{0};
std::string eventId;
int64_t startMs{-1};
int64_t durationMs{-1};
int32_t reason{0};
};
class AVDemuxerCallback {
public:
virtual ~AVDemuxerCallback() = default;
* Called when an drm info updated.
*
* @param drmInfo Drm Info.
* @since 4.1
* @version 4.1
*/
virtual void OnDrmInfoChanged(const std::multimap<std::string, std::vector<uint8_t>> &drmInfo) = 0;
};
class MediaCodecCallback {
public:
virtual ~MediaCodecCallback() = default;
* Called when an error occurred.
*
* @param errorType Error type. For details, see {@link AVCodecErrorType}.
* @param errorCode Error code.
* @since 4.1
*/
virtual void OnError(AVCodecErrorType errorType, int32_t errorCode) = 0;
* Called when the output format has changed.
*
* @param format The new output format.
* @since 4.1
*/
virtual void OnOutputFormatChanged(const Format &format) = 0;
* Called when an input buffer becomes available.
*
* @param index The index of the available input buffer.
* @param buffer A {@link AVBuffer} object for a input buffer index that contains the data.
* @since 4.1
*/
virtual void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) = 0;
* Called when an output buffer becomes available.
*
* @param index The index of the available output buffer.
* @param buffer A {@link AVBuffer} object for a output buffer index that contains the data.
* @since 4.1
*/
virtual void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) = 0;
virtual void OnOutputBufferBinded(std::map<uint32_t, sptr<SurfaceBuffer>> &bufferMap)
{
(void)bufferMap;
}
virtual void OnOutputBufferUnbinded()
{
}
virtual void OnXperfEvent(int eventType, const std::string& msg)
{
(void) eventType;
(void) msg;
}
};
class MediaCodecParameterCallback {
public:
virtual ~MediaCodecParameterCallback() = default;
* Called when an input parameter becomes available.
*
* @param index The index of the available input parameter.
* @param parameter A {@link Format} object containing the corresponding index input parameter.
* @since 5.0
*/
virtual void OnInputParameterAvailable(uint32_t index, std::shared_ptr<Format> parameter) = 0;
};
class MediaCodecParameterWithAttrCallback {
public:
virtual ~MediaCodecParameterWithAttrCallback() = default;
* Called when an input parameter with attribute becomes available.
*
* @param index The index of the available input parameter.
* @param parameter A {@link Format} object containing the corresponding index input parameter.
* @param attribute A read only {@link Format} object containing the corresponding index input attribute.
* @since 5.0
*/
virtual void OnInputParameterWithAttrAvailable(uint32_t index, std::shared_ptr<Format> attribute,
std::shared_ptr<Format> parameter) = 0;
};
class SurfaceBufferExtratDataKey {
public:
* Key for timeStamp in surface's extraData, value type is int64
*/
static constexpr std::string_view ED_KEY_TIME_STAMP = "timeStamp";
* Key for endOfStream in surface's extraData, value type is bool
*/
static constexpr std::string_view ED_KEY_END_OF_STREAM = "endOfStream";
private:
SurfaceBufferExtratDataKey() = delete;
~SurfaceBufferExtratDataKey() = delete;
};
class AVSourceFormat {
public:
static constexpr std::string_view SOURCE_TITLE = "title";
static constexpr std::string_view SOURCE_ARTIST = "artist";
static constexpr std::string_view SOURCE_ALBUM = "album";
static constexpr std::string_view SOURCE_ALBUM_ARTIST = "album_artist";
static constexpr std::string_view SOURCE_DATE = "date";
static constexpr std::string_view SOURCE_COMMENT = "comment";
static constexpr std::string_view SOURCE_GENRE = "genre";
static constexpr std::string_view SOURCE_COPYRIGHT = "copyright";
static constexpr std::string_view SOURCE_LANGUAGE = "language";
static constexpr std::string_view SOURCE_DESCRIPTION = "description";
static constexpr std::string_view SOURCE_LYRICS = "lyrics";
static constexpr std::string_view SOURCE_FILE_TYPE = "file_type";
static constexpr std::string_view SOURCE_HAS_VIDEO = "has_video";
static constexpr std::string_view SOURCE_HAS_AUDIO = "has_audio";
static constexpr std::string_view SOURCE_HAS_TIMEDMETA = "has_timed_meta";
static constexpr std::string_view SOURCE_HAS_SUBTITLE = "has_subtitle";
static constexpr std::string_view SOURCE_AUTHOR = "author";
static constexpr std::string_view SOURCE_COMPOSER = "composer";
private:
AVSourceFormat() = delete;
~AVSourceFormat() = delete;
};
enum VideoBitStreamFormat {
UNKNOWN = 0,
AVCC,
HVCC,
ANNEXB
};
struct CUVVConfigBox {
uint16_t cuva_version_map;
uint16_t terminal_provide_code;
uint16_t terminal_provide_oriented_code;
};
}
}
#endif