diff --git a/zh-cn/native_sdk/media/media/native_avcodec_audiodecoder.h b/zh-cn/native_sdk/media/media/native_avcodec_audiodecoder.h new file mode 100644 index 0000000000000000000000000000000000000000..6e4ed9b1e0d32c881f70083f6c3823f76d2be83a --- /dev/null +++ b/zh-cn/native_sdk/media/media/native_avcodec_audiodecoder.h @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2021-2022 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 NATIVE_AVCODEC_AUDIODECODER_H +#define NATIVE_AVCODEC_AUDIODECODER_H + +#include +#include +#include "native_averrors.h" +#include "native_avformat.h" +#include "native_avmemory.h" +#include "native_avcodec_base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 通过mime类型创建一个音频解码器实例,大多数情况下推荐使用该接口。 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param mime mime类型描述字符串,参考{@link AVCODEC_MIME_TYPE} + * @return 返回一个指向AVCodec实例的指针 + * @since 9 + * @version 1.0 + */ +AVCodec* OH_AudioDecoder_CreateByMime(const char *mime); + +/** + * @brief 通过音频解码器名称创建一个音频解码器实例,使用这个接口的前提是必须清楚解码器准确的名称。 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param name 音频解码器名称 + * @return 返回一个指向AVCodec实例的指针 + * @since 9 + * @version 1.0 + */ +AVCodec* OH_AudioDecoder_CreateByName(const char *name); + +/** + * @brief 清空解码器内部资源,并销毁解码器实例 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioDecoder_Destroy(AVCodec *codec); + +/** + * @brief 设置异步回调函数,使得你的应用能够响应音频解码器产生的事件,该接口被调用必须是在Prepare被调用前 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param codec 指向AVCodec实例的指针 + * @param callback 一个包含所有回调函数的集合体,参考{@link AVCodecAsyncCallback} + * @param userData 用户特定数据 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioDecoder_SetCallback(AVCodec *codec, AVCodecAsyncCallback callback, void *userData); + +/** + * @brief 配置音频解码器,典型地,需要配置被解码音频轨道的描述信息,这些信息能够从容器中提取出来, + * 该接口被调用必须是在Prepare被调用前。 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param codec 指向AVCodec实例的指针 + * @param format 指向AVFormat的指针,用以给出待解码音频轨道的描述信息 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioDecoder_Configure(AVCodec *codec, AVFormat *format); + +/** + * @brief 准备解码器内部资源,调用该接口前必须先调用Configure接口。 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioDecoder_Prepare(AVCodec *codec); + +/** + * @brief 启动解码器,该接口必须在已经Prepare成功后调用。在被启动成功后,解码器将开始报告NeedInputData事件。 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioDecoder_Start(AVCodec *codec); + +/** + * @brief 停止解码器。在停止后可通过Start重新进入Started状态,但需要注意的是,若先前给解码器输入过 + * Codec-Specific-Data,则需要重新输入。 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioDecoder_Stop(AVCodec *codec); + +/** + * @brief 清空解码器内部缓存的输入输出数据。在该接口被调用后,所有先前通过异步回调报告的Buffer的索引都将 + * 失效,确保不要再访问这些索引对应的Buffers。 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioDecoder_Flush(AVCodec *codec); + +/** + * @brief 重置解码器。如需继续解码工作,需要重新调用Configure接口以配置该解码器实例。 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ + +AVErrCode OH_AudioDecoder_Reset(AVCodec *codec); + +/** + * @brief 获取该解码器输出数据的描述信息,具体参考{@link AVFormat}. 需要注意的是,返回值所指向 + * 的AVFormat实例的生命周期将会再下一次调用该接口时或者该AVCodec实例被销毁时失效。 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param codec 指向AVCodec实例的指针 + * @return 返回AVFormat句柄指针,生命周期随下一次GetOutputMediaDescription刷新,或伴随AVCodec销毁; + * @since 9 + * @version 1.0 + */ +AVFormat* OH_AudioDecoder_GetOutputDescription(AVCodec *codec); + +/** + * @brief 向解码器设置动态参数,注意:该接口仅能在解码器被启动后调用,同时错误的参数设置,可能会导致解码失败 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param codec 指向AVCodec实例的指针 + * @param format AVFormat句柄指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioDecoder_SetParameter(AVCodec *codec, AVFormat *format); + +/** + * @brief 将填充好数据的输入Buffer提交给音频解码器。{@link AVCodecOnNeedInputData}回调会报告可用的 + * 输入Buffer及对应的索引值。一旦指定索引的Buffer被提交给了音频解码器,直到再一次收到{@link AVCodecOnNeedInputData} + * 回调报告相同索引的Buffer可用前,该Buffer都不可以再次被访问。另外,对于部分解码器,要求在最开始给解码器输入 + * Codec-Specific-Data,用以初始化解码器的解码过程。 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param codec 指向AVCodec实例的指针 + * @param index 输入Buffer对应的索引值 + * @param attr 描述该Buffer内所包含数据的信息 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioDecoder_PushInputData(AVCodec *codec, uint32_t index, AVCodecBufferAttr attr); + +/** + * @brief 将处理结束的输出Buffer交还给解码器。 + * @syscap SystemCapability.Multimedia.Media.AudioDecoder + * @param codec 指向AVCodec实例的指针 + * @param index 输出Buffer对应的索引值 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioDecoder_FreeOutputData(AVCodec *codec, uint32_t index); + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_AVCODEC_AUDIODECODER_H \ No newline at end of file diff --git a/zh-cn/native_sdk/media/media/native_avcodec_audioencoder.h b/zh-cn/native_sdk/media/media/native_avcodec_audioencoder.h new file mode 100644 index 0000000000000000000000000000000000000000..2923804cc0b9d12c030b6d9f0d6ec0ee90105af7 --- /dev/null +++ b/zh-cn/native_sdk/media/media/native_avcodec_audioencoder.h @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2021-2022 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 NATIVE_AVCODEC_AUDIOENCODER_H +#define NATIVE_AVCODEC_AUDIOENCODER_H + +#include +#include +#include "native_averrors.h" +#include "native_avformat.h" +#include "native_avmemory.h" +#include "native_avcodec_base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 通过mime类型创建一个音频编码器实例,大多数情况下推荐使用该接口。 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param mime mime类型描述字符串,参考{@link AVCODEC_MIME_TYPE} + * @return 返回一个指向AVCodec实例的指针 + * @since 9 + * @version 1.0 + */ +AVCodec* OH_AudioEncoder_CreateByMime(const char *mime); + +/** + * @brief 通过音频编码器名称创建一个音频编码器实例,使用这个接口的前提是必须清楚编码器准确的名称。 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param name 音频编码器名称 + * @return 返回一个指向AVCodec实例的指针 + * @since 9 + * @version 1.0 + */ +AVCodec* OH_AudioEncoder_CreateByName(const char *name); + +/** + * @brief 清空编码器内部资源,并销毁编码器实例 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OHAudioEncoder_Destroy(AVCodec *codec); + +/** + * @brief 设置异步回调函数,使得你的应用能够响应音频编码器产生的事件,该接口被调用必须是在Prepare被调用前 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param codec 指向AVCodec实例的指针 + * @param callback 一个包含所有回调函数的集合体,参考{@link AVCodecAsyncCallback} + * @param userData 用户特定数据 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioEncoder_SetCallback(AVCodec *codec, AVCodecAsyncCallback callback, void *userData); + +/** + * @brief 配置音频编码器,典型地,需要配置被编码音频轨道的描述信息,该接口被调用必须是在Prepare被调用前。 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param codec 指向AVCodec实例的指针 + * @param format AVFormat句柄指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioEncoder_Configure(AVCodec *codec, AVFormat *format); + +/** + * @brief 准备编码器内部资源,调用该接口前必须先调用Configure接口。 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioEncoder_Prepare(AVCodec *codec); + +/** + * @brief 启动编码器,该接口必须在已经Prepare成功后调用。在被启动成功后,编码器将开始报告NeedInputData事件。 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioEncoder_Start(AVCodec *codec); + +/** + * @brief 停止编码器。在停止后可通过Start重新进入Started状态。 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioEncoder_Stop(AVCodec *codec); + +/** + * @brief 清空编码器内部缓存的输入输出数据。在该接口被调用后,所有先前通过异步回调报告的Buffer的索引都将 + * 失效,确保不要再访问这些索引对应的Buffers。 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioEncoder_Flush(AVCodec *codec); + +/** + * @brief 重置编码器。如需继续编码工作,需要重新调用Configure接口以配置该编码器实例。 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioEncoder_Reset(AVCodec *codec); + +/** + * @brief 获取该编码器输出数据的描述信息,具体参考{@link AVFormat}. 需要注意的是,返回值所指向 + * 的AVFormat实例的生命周期将会再下一次调用该接口时或者该AVCodec实例被销毁时失效。 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param codec 指向AVCodec实例的指针 + * @return 返回AVFormat句柄指针,生命周期随下一次GetOutputMediaDescription刷新,或伴随AVCodec销毁; + * @since 9 + * @version 1.0 + */ +AVFormat* OH_AudioEncoder_GetOutputDescription(AVCodec *codec); + +/** + * @brief 向编码器设置动态参数,注意:该接口仅能在编码器被启动后调用,同时错误的参数设置,可能会导致编码失败 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param codec 指向AVCodec实例的指针 + * @param format AVFormat句柄指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioEncoder_SetParameter(AVCodec *codec, AVFormat *format); + +/** + * @brief 将填充好数据的输入Buffer提交给音频编码器。{@link AVCodecOnNeedInputData}回调会报告可用的 + * 输入Buffer及对应的索引值。一旦指定索引的Buffer被提交给了音频编码器,直到再一次收到{@link AVCodecOnNeedInputData} + * 回调报告相同索引的Buffer可用前,该Buffer都不可以再次被访问。 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param codec 指向AVCodec实例的指针 + * @param index 输入Buffer对应的索引值 + * @param attr 描述该Buffer内所包含数据的信息 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioEncoder_PushInputData(AVCodec *codec, uint32_t index, AVCodecBufferAttr attr); + +/** + * @brief 将处理结束的输出Buffer交还给编码器。 + * @syscap SystemCapability.Multimedia.Media.AudioEncoder + * @param codec 指向AVCodec实例的指针 + * @param index 输出Buffer对应的索引值 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_AudioEncoder_FreeOutputData(AVCodec *codec, uint32_t index); + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_AVCODEC_AUDIOENCODER_H \ No newline at end of file diff --git a/zh-cn/native_sdk/media/media/native_avcodec_base.h b/zh-cn/native_sdk/media/media/native_avcodec_base.h new file mode 100644 index 0000000000000000000000000000000000000000..70b3667d667b4e2adbb876d983a7188350c691fe --- /dev/null +++ b/zh-cn/native_sdk/media/media/native_avcodec_base.h @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2021-2022 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 NATIVE_AVCODEC_BASE_H +#define NATIVE_AVCODEC_BASE_H + +#include +#include +#include "native_averrors.h" +#include "native_avformat.h" +#include "native_avmemory.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct NativeWindow NativeWindow; +typedef struct AVCodec AVCodec; + +/** + * @brief 枚举音视频编解码的MIME类型 + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 9 + * @version 1.0 + */ +extern const char* AVCODEC_MIME_TYPE_VIDEO_AVC; +extern const char* AVCODEC_MIME_TYPE_AUDIO_AAC; + +/** + * @brief 枚举AVCodec的Buffer标记的类别 + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 9 + * @version 1.0 + */ +typedef enum AVCodecBufferFlags { + AVCODEC_BUFFER_FLAGS_NONE = 0, + /* 表明该Buffer是End-of-Stream帧 */ + AVCODEC_BUFFER_FLAGS_EOS = 1 << 0, + /* 表明该Buffer内包含关键帧 */ + AVCODEC_BUFFER_FLAGS_SYNC_FRAME = 1 << 1, + /* 表明该Buffer内包含的数据仅仅为一帧的一部分 */ + AVCODEC_BUFFER_FLAGS_INCOMPLETE_FRAME = 1 << 2, + /* 表明该Buffer包含Codec-Specific-Data */ + AVCODEC_BUFFER_FLAGS_CODEC_DATA = 1 << 3, +} AVCodecBufferFlags; + +/** + * @brief 定义AVCodec的Buffer描述信息 + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 9 + * @version 1.0 + */ +typedef struct AVCodecBufferAttr { + /* 以微秒为单位表示的该Buffer的Presentation时间戳 */ + int64_t pts; + /* 以字节为单位表示的该Buffer内所包含数据的大小 */ + int32_t size; + /* 有效数据在该Buffer内的起始偏移量 */ + int32_t offset; + /* 该Buffer具有的标记, 也是多个{@link AVCodecBufferFlags}的组合. */ + uint32_t flags; +} AVCodecBufferAttr; + +/** + * @brief 当AVCodec实例运行发生错误时,该函数指针会被调用以报告具体错误信息。 + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @param codec AVCodec实例 + * @param errorCode 具体错误码 + * @param userData 用户特定数据 + * @since 9 + * @version 1.0 + */ +typedef void (* AVCodecOnError)(AVCodec *codec, int32_t errorCode, void *userData); + +/** + * @brief 当输出流发生变化时,该函数指针会被调用以报告新的流描述信息. + * 需要注意的时,AVFormat指针的生命周期仅维持在该函数指针被调用时上有效,禁止在调用结束后继续访问。 + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @param codec AVCodec实例 + * @param format 新的输出流描述信息 + * @param userData 用户特定数据 + * @since 9 + * @version 1.0 + */ +typedef void (* AVCodecOnStreamChanged)(AVCodec *codec, AVFormat *format, void *userData); + +/** + * @brief 当AVCodec运行过程中需要新的输入数据时,该函数指针会被调用,并携带一块可用的Buffer以供填入新的输入数据。 + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @param codec AVCodec实例 + * @param index 新的可用的输入Buffer对应的索引. + * @param data 新的可用的输入Buffer. + * @param userData 用户特定数据 + * @since 9 + * @version 1.0 + */ +typedef void (* AVCodecOnNeedInputData)(AVCodec *codec, uint32_t index, AVMemory *data, void *userData); + +/** + * @brief 当AVCodec运行过程中产生了新的输出数据时,该函数指针会被调用,并携带一块包含新输出数据的Buffer. + * 需要注意的是,AVCodecBufferAttr指针的生命周期仅维持在该函数指针被调用时有效,禁止调用结束后继续访问. + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @param codec AVCodec实例 + * @param index 新的输出Buffer对应的索引. + * @param data 包含新的输出数据的Buffer + * @param attr 新的输出Buffer的描述信息,具体参考{@link AVCodecBufferAttr} + * @param userData specified data + * @since 9 + * @version 1.0 + */ +typedef void (* AVCodecOnNewOutputData)(AVCodec *codec, uint32_t index, AVMemory *data, + AVCodecBufferAttr *attr, void *userData); + +/** + * @brief AVCodec所有的异步回调函数指针集合。注册一个该结构体实例给AVCodec实例,并处理通过该回调报告 + * 的信息,以确保AVCodec正常运转。 + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @param onError 监听AVCodec运行错误,参考{@link AVCodecOnError} + * @param onStreamChanged 监听编解码流信息,参考{@link AVCodecOnStreamChanged} + * @param onNeedInputData 监听编解码需要输入数据,参考{@link AVCodecOnNeedInputData} + * @param onNeedInputData 监听编解码产生输出数据,参考{@link onNeedInputData} + * @since 9 + * @version 1.0 + */ +typedef struct AVCodecAsyncCallback { + AVCodecOnError onError; + AVCodecOnStreamChanged onStreamChanged; + AVCodecOnNeedInputData onNeedInputData; + AVCodecOnNewOutputData onNeedOutputData; +} AVCodecAsyncCallback; + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_AVCODEC_BASE_H \ No newline at end of file diff --git a/zh-cn/native_sdk/media/media/native_avcodec_videodecoder.h b/zh-cn/native_sdk/media/media/native_avcodec_videodecoder.h new file mode 100644 index 0000000000000000000000000000000000000000..c79a4cc6f55da4a2acfd94f0f44da903d6534499 --- /dev/null +++ b/zh-cn/native_sdk/media/media/native_avcodec_videodecoder.h @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2021-2022 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 NATIVE_AVCODEC_VIDEODECODER_H +#define NATIVE_AVCODEC_VIDEODECODER_H + +#include +#include +#include "native_averrors.h" +#include "native_avformat.h" +#include "native_avmemory.h" +#include "native_avcodec_base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 通过mime类型创建一个视频解码器实例,大多数情况下推荐使用该接口。 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param mime mime类型描述字符串,参考{@link AVCODEC_MIME_TYPE} + * @return 返回一个指向AVCodec实例的指针 + * @since 9 + * @version 1.0 + */ +AVCodec* OH_VideoDecoder_CreateByMime(const char *mime); + +/** + * @brief 通过视频解码器名称创建一个视频解码器实例,使用这个接口的前提是必须清楚解码器准确的名称。 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param name 视频解码器名称 + * @return 返回一个指向AVCodec实例的指针 + * @since 9 + * @version 1.0 + */ +AVCodec* OH_VideoDecoder_CreateByName(const char *name); + +/** + * @brief 清空解码器内部资源,并销毁解码器实例 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_Destroy(AVCodec *codec); + +/** + * @brief 设置异步回调函数,使得你的应用能够响应视频解码器产生的事件,该接口被调用必须是在Prepare被调用前 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @param callback 一个包含所有回调函数的集合体,参考{@link AVCodecAsyncCallback} + * @param userData 用户特定数据 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_SetCallback(AVCodec *codec, AVCodecAsyncCallback callback, void *userData); + +/** + * @brief 指定输出Surface,以提供视频解码输出, 该接口被调用必须是在Prepare被调用前 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @param window 指向一个NativeWindow实例的指针,具体参考{@link NativeWindow} + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_SetSurface(AVCodec *codec, NativeWindow *window); + +/** + * @brief 配置视频解码器,典型地,需要配置被解码视频轨道的描述信息,这些信息能够从容器中提取出来, + * 该接口被调用必须是在Prepare被调用前。 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @param format 指向AVFormat的指针,用以给出待解码视频轨道的描述信息 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_Configure(AVCodec *codec, AVFormat *format); + +/** + * @brief 准备解码器内部资源,调用该接口前必须先调用Configure接口。 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_Prepare(AVCodec *codec); + +/** + * @brief 启动解码器,该接口必须在已经Prepare成功后调用。在被启动成功后,解码器将开始报告NeedInputData事件。 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_Start(AVCodec *codec); + +/** + * @brief 停止解码器。在停止后可通过Start重新进入Started状态,但需要注意的是,若先前给解码器输入过 + * Codec-Specific-Data,则需要重新输入。 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_Stop(AVCodec *codec); + +/** + * @brief 清空解码器内部缓存的输入输出数据。在该接口被调用后,所有先前通过异步回调报告的Buffer的索引都将 + * 失效,确保不要再访问这些索引对应的Buffers。 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_Flush(AVCodec *codec); + +/** + * @brief 重置解码器。如需继续解码工作,需要重新调用Configure接口以配置该解码器实例。 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_Reset(AVCodec *codec); + +/** + * @brief 获取该解码器输出数据的描述信息,具体参考{@link AVFormat}. 需要注意的是,返回值所指向 + * 的AVFormat实例的生命周期将会再下一次调用该接口时或者该AVCodec实例被销毁时失效。 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @return 返回AVFormat实例的指针 + * @since 9 + * @version 1.0 + */ +AVFormat* OH_VideoDecoder_GetOutputDescription(AVCodec *codec); + +/** + * @brief 向解码器设置动态参数,注意:该接口仅能在解码器被启动后调用,同时错误的参数设置,可能会导致解码失败 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @param format 指向AVFormat实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_SetParameter(AVCodec *codec, AVFormat *format); + +/** + * @brief 将填充好数据的输入Buffer提交给视频解码器。{@link AVCodecOnNeedInputData}回调会报告可用的 + * 输入Buffer及对应的索引值。一旦指定索引的Buffer被提交给了视频解码器,直到再一次收到{@link AVCodecOnNeedInputData} + * 回调报告相同索引的Buffer可用前,该Buffer都不可以再次被访问。另外,对于部分解码器,要求在最开始给解码器输入 + * Codec-Specific-Data,用以初始化解码器的解码过程,例如H264格式的PPS/SPS数据。 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @param index 输入Buffer对应的索引值 + * @param attr 描述该Buffer内所包含数据的信息 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_PushInputData(AVCodec *codec, uint32_t index, AVCodecBufferAttr attr); + +/** + * @brief 将处理结束的输出Buffer交还给解码器,并通知解码器完成将该Buffer内包含的解码后的数据在输出Surface上渲染。 + * 如果先前未配置输出Surface,调用该接口仅仅将指定索引对应的输出Buffer交还给解码器。 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @param index 输出Buffer对应的索引值 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_RenderOutputData(AVCodec *codec, uint32_t index); + +/** + * @brief 将处理结束的输出Buffer交还给解码器。 + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec 指向AVCodec实例的指针 + * @param index 输出Buffer对应的索引值 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoDecoder_FreeOutputData(AVCodec *codec, uint32_t index); + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_AVCODEC_VIDEODECODER_H \ No newline at end of file diff --git a/zh-cn/native_sdk/media/media/native_avcodec_videoencoder.h b/zh-cn/native_sdk/media/media/native_avcodec_videoencoder.h new file mode 100644 index 0000000000000000000000000000000000000000..af73d2ee17c8d4d1652a6576c00128262b0bd2c2 --- /dev/null +++ b/zh-cn/native_sdk/media/media/native_avcodec_videoencoder.h @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2021-2022 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 NATIVE_AVCODEC_VIDEOENCODER_H +#define NATIVE_AVCODEC_VIDEOENCODER_H + +#include +#include +#include "native_averrors.h" +#include "native_avformat.h" +#include "native_avmemory.h" +#include "native_avcodec_base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 通过mime类型创建一个视频编码器实例,大多数情况下推荐使用该接口。 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param mime mime类型描述字符串,参考{@link AVCODEC_MIME_TYPE} + * @return 返回一个指向AVCodec实例的指针 + * @since 9 + * @version 1.0 + */ +AVCodec* OH_VideoEncoder_CreateByMime(const char *mime); + +/** + * @brief 通过视频编码器名称创建一个视频编码器实例,使用这个接口的前提是必须清楚编码器准确的名称。 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param name 视频编码器名称 + * @return 返回一个指向AVCodec实例的指针 + * @since 9 + * @version 1.0 + */ +AVCodec* OH_VideoEncoder_CreateByName(const char *name); + +/** + * @brief 清空编码器内部资源,并销毁编码器实例 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoEncoder_Destroy(AVCodec *codec); + +/** + * @brief 设置异步回调函数,使得你的应用能够响应视频编码器产生的事件,该接口被调用必须是在Prepare被调用前 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @param callback 一个包含所有回调函数的集合体,参考{@link AVCodecAsyncCallback} + * @param userData 用户特定数据 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoEncoder_SetCallback(AVCodec *codec, AVCodecAsyncCallback callback, void *userData); + +/** + * @brief 配置视频编码器,典型地,需要配置被编码视频轨道的描述信息,该接口被调用必须是在Prepare被调用前。 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @param format 指向AVFormat的指针,用以给出待编码视频轨道的描述信息 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoEncoder_Configure(AVCodec *codec, AVFormat *format); + +/** + * @brief 准备编码器内部资源,调用该接口前必须先调用Configure接口。 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoEncoder_Prepare(AVCodec *codec); + +/** + * @brief 启动编码器,该接口必须在已经Prepare成功后调用。在被启动成功后,编码器将开始报告NeedInputData事件。 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoEncoder_Start(AVCodec *codec); + +/** + * @brief 停止编码器。在停止后可通过Start重新进入Started状态。 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoEncoder_Stop(AVCodec *codec); + +/** + * @brief 清空编码器内部缓存的输入输出数据。在该接口被调用后,所有先前通过异步回调报告的Buffer的索引都将 + * 失效,确保不要再访问这些索引对应的Buffers。 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoEncoder_Flush(AVCodec *codec); + +/** + * @brief 重置编码器。如需继续编码工作,需要重新调用Configure接口以配置该编码器实例。 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoEncoder_Reset(AVCodec *codec); + +/** + * @brief 获取该编码器输出数据的描述信息,具体参考{@link AVFormat}. 需要注意的是,返回值所指向 + * 的AVFormat实例的生命周期将会再下一次调用该接口时或者该AVCodec实例被销毁时失效。 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @return 返回AVFormat实例的指针 + * @since 9 + * @version 1.0 + */ +AVFormat* OH_VideoEncoder_GetOutputDescription(AVCodec *codec); + +/** + * @brief 向编码器设置动态参数,注意:该接口仅能在编码器被启动后调用,同时错误的参数设置,可能会导致编码失败 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @param format AVFormat句柄指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoEncoder_SetParameter(AVCodec *codec, AVFormat *format); + + +/** + * @brief 从视频编码器获取输入Surface, 该接口被调用必须是在Prepare被调用前。 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @param window 指向一个NativeWindow实例的指针,具体参考{@link NativeWindow} + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoEncoder_GetSurface(AVCodec *codec, NativeWindow **window); + +/** + * @brief 将处理结束的输出Buffer交还给编码器。 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @param index 输出Buffer对应的索引值 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoEncoder_FreeOutputData(AVCodec *codec, uint32_t index); + +/** + * @brief 通知视频编码器输入码流已结束。surface模式推荐使用该接口通知编码器码流结束, + * bytebuffer模式推荐使用OH_AVCODEC_VideoEncoderPushInputData接口通知编码器码流结束。 + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec 指向AVCodec实例的指针 + * @return 执行成功返回AV_ERR_OK,否则返回具体错误码,参考{@link AVErrCode} + * @since 9 + * @version 1.0 + */ +AVErrCode OH_VideoEncoder_NotifyEndOfStream(AVCodec *codec); + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_AVCODEC_VIDEOENCODER_H \ No newline at end of file diff --git a/zh-cn/native_sdk/media/media/native_averrors.h b/zh-cn/native_sdk/media/media/native_averrors.h new file mode 100644 index 0000000000000000000000000000000000000000..154f5bec025128bc68000d5c9caacd33b736631d --- /dev/null +++ b/zh-cn/native_sdk/media/media/native_averrors.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2021 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 NATIVE_AVERRORS_H +#define NATIVE_AVERRORS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief AV error code + * @syscap SystemCapability.Multimedia.Media.Core + * @since 9 + * @version 1.0 + */ +typedef enum AVErrCode { + /** + * the operation completed successfully. + */ + AV_ERR_OK = 0, + /** + * no memory. + */ + AV_ERR_NO_MEMORY = 1, + /** + * opertation not be permitted. + */ + AV_ERR_OPERATE_NOT_PERMIT = 2, + /** + * invalid argument. + */ + AV_ERR_INVALID_VAL = 3, + /** + * IO error. + */ + AV_ERR_IO = 4, + /** + * network timeout. + */ + AV_ERR_TIMEOUT = 5, + /** + * unknown error. + */ + AV_ERR_UNKNOWN = 6, + /** + * media service died. + */ + AV_ERR_SERVICE_DIED = 7, + /** + * the state is not support this operation. + */ + AV_ERR_INVALID_STATE = 8, + /** + * unsupport interface. + */ + AV_ERR_UNSUPPORT = 9, + /** + * extend err start. + */ + AV_ERR_EXTEND_START = 100, +} AVErrCode; + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_AVERRORS_H \ No newline at end of file diff --git a/zh-cn/native_sdk/media/media/native_avformat.h b/zh-cn/native_sdk/media/media/native_avformat.h new file mode 100644 index 0000000000000000000000000000000000000000..643846cb027b72664f3b91cf7f8f65105ac4e4d2 --- /dev/null +++ b/zh-cn/native_sdk/media/media/native_avformat.h @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2021-2022 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 NATIVE_AVFORMAT_H +#define NATIVE_AVFORMAT_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct AVFormat AVFormat; + +/** + * @brief Enumerates AVPixel Format. + * @syscap SystemCapability.Multimedia.Media.Core + * @since 9 + * @version 1.0 + */ +typedef enum AVPixelFormat { + /** + * yuv 420 planar. + */ + AV_PIXEL_FORMAT_YUVI420 = 1, + /** + * NV12. yuv 420 semiplanar. + */ + AV_PIXEL_FORMAT_NV12 = 2, + /** + * NV21. yvu 420 semiplanar. + */ + AV_PIXEL_FORMAT_NV21 = 3, + /** + * format from surface. + */ + AV_PIXEL_FORMAT_SURFACE_FORMAT = 4, +} AVPixelFormat; + +/** + * @brief 创建一个AVFormat句柄指针,用以读写数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @return 返回AVFormat实例的指针 + * @since 9 + * @version 1.0 + */ +struct AVFormat* OH_AVFormat_Create(void); + +/** + * @brief 销毁指定AVFormat句柄资源 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @return void + * @since 9 + * @version 1.0 + */ +void OH_AVFormat_Destroy(struct AVFormat *format); + +/** + * @brief 拷贝AVFormat句柄资源 + * @syscap SystemCapability.Multimedia.Media.Core + * @param to 接收数据的AVFormat句柄指针 + * @param from 被拷贝数据的AVFormat句柄指针 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_Copy(struct AVFormat *to, struct AVFormat *from); + +/** + * @brief 向AVFormat写入Int数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @param key 写入数据的键值 + * @param value 写入的数据 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_SetIntValue(struct AVFormat *format, const char *key, int32_t value); + +/** + * @brief 向AVFormat写入Long数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @param key 写入数据的键值 + * @param value 写入的数据 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_SetLongValue(struct AVFormat *format, const char *key, int64_t value); + +/** + * @brief 向AVFormat写入Float数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @param key 写入数据的键值 + * @param value 写入的数据 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_SetFloatValue(struct AVFormat *format, const char *key, float value); + +/** + * @brief 向AVFormat写入Double数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @param key 写入数据的键值 + * @param value 写入的数据 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_SetDoubleValue(struct AVFormat *format, const char *key, double value); + +/** + * @brief 向AVFormat写入String数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @param key 写入数据的键值 + * @param value 写入的数据 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_SetStringValue(struct AVFormat *format, const char *key, const char *value); + +/** + * @brief 向AVFormat写入一块指定长度的数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @param key 写入数据的键值 + * @param addr 写入的数据地址 + * @param size 写入的数据长度 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_SetBuffer(struct AVFormat *format, const char *key, const uint8_t *addr, size_t size); + +/** + * @brief 从AVFormat读取Int数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @param key 读取数据的键值 + * @param out 读取的数据 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_GetIntValue(struct AVFormat *format, const char *key, int32_t *out); + +/** + * @brief 从AVFormat读取Long数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @param key 读取数据的键值 + * @param out 读取的数据 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_GetLongValue(struct AVFormat *format, const char *key, int64_t *out); + +/** + * @brief 从AVFormat读取Float数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @param key 读取数据的键值 + * @param out 读取的数据 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_GetFloatValue(struct AVFormat *format, const char *key, float *out); + +/** + * @brief 从AVFormat读取Double数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @param key 读取数据的键值 + * @param out 读取的数据 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_GetDoubleValue(struct AVFormat *format, const char *key, double *out); + +/** + * @brief 从AVFormat读取Double数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @param key 读取数据的键值 + * @param out 读取的字符串指针,指向的数据生命周期伴随GetString更新,伴随Format销毁,如果调用者需要长期持有,必须进行内存拷贝 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_GetStringValue(struct AVFormat *format, const char *key, const char **out); + +/** + * @brief 从AVFormat读取一块指定长度的数据 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @param key 读写数据的键值 + * @param addr 生命周期是format持有,伴随Format销毁,如果调用者需要长期持有,必须进行内存拷贝 + * @param size 读写数据的长度 + * @return 返回值为TRUE表示成功,FALSE表示失败 + * @since 9 + * @version 1.0 + */ +bool OH_AVFormat_GetBuffer(struct AVFormat *format, const char *key, uint8_t **addr, size_t *size); + +/** + * @brief 以字符串的形式输出AVFormat所包含的信息。 + * @syscap SystemCapability.Multimedia.Media.Core + * @param format 指向AVFormat实例的指针 + * @return 返回由键值和数据组成的字符串 + * @since 9 + * @version 1.0 + */ +const char *OH_AVFormat_DumpInfo(struct AVFormat *format); + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_AVFORMAT_H \ No newline at end of file diff --git a/zh-cn/native_sdk/media/media/native_avmemory.h b/zh-cn/native_sdk/media/media/native_avmemory.h new file mode 100644 index 0000000000000000000000000000000000000000..68512642b44fff498b76e3a56b43736881973dfe --- /dev/null +++ b/zh-cn/native_sdk/media/media/native_avmemory.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021-2022 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 NATIVE_AVMEMORY_H +#define NATIVE_AVMEMORY_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct AVMemory AVMemory; + +/** + * @brief Get the memory's virtual address + * @syscap SystemCapability.Multimedia.Media.Core + * @param mem Encapsulate AVMemory structure instance pointer + * @return the memory's virtual address if the memory is valid, otherwise nullptr. + * @since 9 + * @version 1.0 + */ +uint8_t* OH_AVMemory_GetAddr(struct AVMemory *mem); + +/** + * @brief Get the memory's size + * @syscap SystemCapability.Multimedia.Media.Core + * @param mem Encapsulate AVMemory structure instance pointer + * @return the memory's size if the memory is valid, otherwise -1. + * @since 9 + * @version 1.0 + */ +int32_t OH_AVMemory_GetSize(struct AVMemory *mem); + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_AVMEMORY_H \ No newline at end of file