1/* 2 * Copyright (C) 2023 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 NATIVE_AVDEMUXER_H 17#define NATIVE_AVDEMUXER_H 18 19#include <stdint.h> 20#include "native_avcodec_base.h" 21#include "native_avsource.h" 22 23#ifdef __cplusplus 24extern "C" { 25#endif 26 27typedef struct OH_AVDemuxer OH_AVDemuxer; 28typedef struct DRM_MediaKeySystemInfo DRM_MediaKeySystemInfo; 29typedef void (*DRM_MediaKeySystemInfoCallback)(DRM_MediaKeySystemInfo* mediaKeySystemInfo); 30 31/** 32 * @brief Call back will be invoked when updating DRM information. 33 * @param demuxer Player OH_AVDemuxer. 34 * @param mediaKeySystemInfo DRM information. 35 * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. 36 * @since 12 37 * @version 1.0 38 */ 39typedef void (*Demuxer_MediaKeySystemInfoCallback)(OH_AVDemuxer *demuxer, DRM_MediaKeySystemInfo *mediaKeySystemInfo); 40 41/** 42 * @brief Creates an OH_AVDemuxer instance for getting samples from source. 43 * Free the resources of the instance by calling OH_AVDemuxer_Destroy. 44 * @syscap SystemCapability.Multimedia.Media.Spliter 45 * @param source Pointer to an OH_AVSource instance. 46 * @return Returns a pointer to an OH_AVDemuxer instance if the execution is successful, otherwise returns nullptr. 47 * Possible failure causes: 48 * 1. source is invalid. 49 * @since 10 50*/ 51OH_AVDemuxer *OH_AVDemuxer_CreateWithSource(OH_AVSource *source); 52 53/** 54 * @brief Destroy the OH_AVDemuxer instance and free the internal resources. 55 * The same instance can only be destroyed once. The destroyed instance 56 * should not be used before it is created again. It is recommended setting 57 * the instance pointer to NULL right after the instance is destroyed successfully. 58 * @syscap SystemCapability.Multimedia.Media.Spliter 59 * @param demuxer Pointer to an OH_AVDemuxer instance. 60 * @return Returns AV_ERR_OK if the execution is successful, 61 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 62 * {@link AV_ERR_INVALID_VAL} demuxer is invalid. 63 * @since 10 64*/ 65OH_AVErrCode OH_AVDemuxer_Destroy(OH_AVDemuxer *demuxer); 66 67/** 68 * @brief The specified track is selected and the demuxer will read samples from 69 * this track. Multiple tracks are selected by calling this interface multiple times 70 * with different track indexes. Only the selected tracks are valid when calling 71 * OH_AVDemuxer_ReadSample to read samples. The interface returns AV_ERR_OK and the 72 * track is selected only once if the same track is selected multiple times. 73 * @syscap SystemCapability.Multimedia.Media.Spliter 74 * @param demuxer Pointer to an OH_AVDemuxer instance. 75 * @param trackIndex The index of the selected track. 76 * @return Returns AV_ERR_OK if the execution is successful, 77 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 78 * {@link AV_ERR_INVALID_VAL} demuxer is invalid, demuxer is not properly initialized, 79 * trackIndex is out of range, track is not supported to be read. 80 * @since 10 81*/ 82OH_AVErrCode OH_AVDemuxer_SelectTrackByID(OH_AVDemuxer *demuxer, uint32_t trackIndex); 83 84/** 85 * @brief The specified selected track is unselected. The unselected track's sample 86 * can not be read from demuxer. Multiple selected tracks are unselected by calling 87 * this interface multiple times with different track indexes. The interface returns 88 * AV_ERR_OK and the track is unselected only once if the same track is unselected 89 * multiple times. 90 * @syscap SystemCapability.Multimedia.Media.Spliter 91 * @param demuxer Pointer to an OH_AVDemuxer instance. 92 * @param trackIndex The index of the unselected track. 93 * @return Returns AV_ERR_OK if the execution is successful, 94 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 95 * {@link AV_ERR_INVALID_VAL} demuxer is invalid, demuxer is not properly initialized. 96 * @since 10 97*/ 98OH_AVErrCode OH_AVDemuxer_UnselectTrackByID(OH_AVDemuxer *demuxer, uint32_t trackIndex); 99 100/** 101 * @brief Get the current encoded sample and sample-related information from the specified 102 * track. The track index must be selected before reading sample. The demuxer will advance 103 * automatically after calling this interface. 104 * @syscap SystemCapability.Multimedia.Media.Spliter 105 * @param demuxer Pointer to an OH_AVDemuxer instance. 106 * @param trackIndex The index of the track from which read an encoded sample. 107 * @param sample The OH_AVMemory handle pointer to the buffer storing the sample data. 108 * @param info The OH_AVCodecBufferAttr handle pointer to the buffer storing sample information. 109 * @return Returns AV_ERR_OK if the execution is successful, 110 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 111 * {@link AV_ERR_INVALID_VAL} demuxer is invalid, demuxer is not properly initialized, sample is invalid, 112 * trackIndex is out of range. 113 * {@link AV_ERR_OPERATE_NOT_PERMIT} trackIndex has not been selected. 114 * {@link AV_ERR_NO_MEMORY} capability of sample is not enough to store all frame data. 115 * {@link AV_ERR_UNKNOWN} failed to read or parse frame from file. 116 * @deprecated since 11 117 * @useinstead OH_AVDemuxer_ReadSampleBuffer 118 * @since 10 119*/ 120OH_AVErrCode OH_AVDemuxer_ReadSample(OH_AVDemuxer *demuxer, uint32_t trackIndex, 121 OH_AVMemory *sample, OH_AVCodecBufferAttr *info); 122 123/** 124 * @brief Get the current encoded sample and sample-related information from the specified 125 * track. The track index must be selected before reading sample. The demuxer will advance 126 * automatically after calling this interface. 127 * @syscap SystemCapability.Multimedia.Media.Spliter 128 * @param demuxer Pointer to an OH_AVDemuxer instance. 129 * @param trackIndex The index of the track from which read an encoded sample. 130 * @param sample The OH_AVBuffer handle pointer to the buffer storing the sample data and corresponding attribute. 131 * @return Returns AV_ERR_OK if the execution is successful, 132 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 133 * {@link AV_ERR_INVALID_VAL} demuxer is invalid, demuxer is not properly initialized, sample is invalid, 134 * trackIndex is out of range. 135 * {@link AV_ERR_OPERATE_NOT_PERMIT} trackIndex has not been selected. 136 * {@link AV_ERR_NO_MEMORY} capability of sample is not enough to store frame data. 137 * {@link AV_ERR_UNKNOWN} failed to read or parse frame from file. 138 * @since 11 139*/ 140OH_AVErrCode OH_AVDemuxer_ReadSampleBuffer(OH_AVDemuxer *demuxer, uint32_t trackIndex, 141 OH_AVBuffer *sample); 142 143/** 144 * @brief All selected tracks seek near to the requested time according to the seek mode. 145 * @syscap SystemCapability.Multimedia.Media.Spliter 146 * @param demuxer Pointer to an OH_AVDemuxer instance. 147 * @param millisecond The millisecond for seeking, the timestamp is the position of 148 * the file relative to the start of the file. 149 * @param mode The mode for seeking. See {@link OH_AVSeekMode}. 150 * @return Returns AV_ERR_OK if the execution is successful, 151 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 152 * {@link AV_ERR_INVALID_VAL} demuxer is invalid, demuxer is not properly initialized, 153 * millisecond is out of range. 154 * {@link AV_ERR_OPERATE_NOT_PERMIT} trackIndex has not been selected, resource is unseekable. 155 * {@link AV_ERR_UNKNOWN} failed to seek. 156 * @since 10 157*/ 158OH_AVErrCode OH_AVDemuxer_SeekToTime(OH_AVDemuxer *demuxer, int64_t millisecond, OH_AVSeekMode mode); 159 160/** 161 * @brief Method to set player media key system info callback. 162 * @syscap SystemCapability.Multimedia.Media.Spliter 163 * @param demuxer Pointer to an OH_AVDemuxer instance 164 * @param callback object pointer. 165 * @return {@link AV_ERR_OK} 0 - Success 166 * {@link AV_ERR_OPERATE_NOT_PERMIT} 2 - If the demuxer engine is not inited or init failed. 167 * {@link AV_ERR_INVALID_VAL} 3 - If the demuxer instance is nullptr or invalid. 168 * @since 11 169 * @version 1.0 170 */ 171OH_AVErrCode OH_AVDemuxer_SetMediaKeySystemInfoCallback(OH_AVDemuxer *demuxer, 172 DRM_MediaKeySystemInfoCallback callback); 173 174/** 175 * @brief Method to set player media key system info callback. 176 * @syscap SystemCapability.Multimedia.Media.Spliter 177 * @param demuxer Pointer to an OH_AVDemuxer instance 178 * @param callback object pointer. 179 * @return {@link AV_ERR_OK} 0 - Success 180 * {@link AV_ERR_OPERATE_NOT_PERMIT} 2 - If the demuxer engine is not inited or init failed. 181 * {@link AV_ERR_INVALID_VAL} 3 - If the demuxer instance is nullptr or invalid. 182 * @since 12 183 * @version 1.0 184 */ 185OH_AVErrCode OH_AVDemuxer_SetDemuxerMediaKeySystemInfoCallback(OH_AVDemuxer *demuxer, 186 Demuxer_MediaKeySystemInfoCallback callback); 187 188/** 189 * @brief Obtains media key system info to create media key session. 190 * @syscap SystemCapability.Multimedia.Media.Spliter 191 * @param demuxer Pointer to an OH_AVDemuxer instance 192 * @param mediaKeySystemInfo Indicates the media key system info which ram space allocated by callee and 193 * released by caller. 194 * @return {@link AV_ERR_OK} 0 - Success 195 * {@link AV_ERR_OPERATE_NOT_PERMIT} 2 - If the demuxer engine is not inited or init failed. 196 * {@link AV_ERR_INVALID_VAL} 3 - If the demuxer instance is nullptr or invalid 197 * or the mediaKeySystemInfo is nullptr. 198 * @since 11 199 * @version 1.0 200 */ 201OH_AVErrCode OH_AVDemuxer_GetMediaKeySystemInfo(OH_AVDemuxer *demuxer, DRM_MediaKeySystemInfo *mediaKeySystemInfo); 202 203#ifdef __cplusplus 204} 205#endif 206 207#endif // NATIVE_AVDEMUXER_H 208