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 16da853ecaSopenharmony_ci#ifndef NATIVE_AVSOURCE_H 17da853ecaSopenharmony_ci#define NATIVE_AVSOURCE_H 18da853ecaSopenharmony_ci 19da853ecaSopenharmony_ci#include <stdint.h> 20da853ecaSopenharmony_ci#include "native_avcodec_base.h" 21da853ecaSopenharmony_ci#include "native_averrors.h" 22da853ecaSopenharmony_ci#include "native_avformat.h" 23da853ecaSopenharmony_ci 24da853ecaSopenharmony_ci#ifdef __cplusplus 25da853ecaSopenharmony_ciextern "C" { 26da853ecaSopenharmony_ci#endif 27da853ecaSopenharmony_ci 28da853ecaSopenharmony_citypedef struct OH_AVSource OH_AVSource; 29da853ecaSopenharmony_ci 30da853ecaSopenharmony_ci/** 31da853ecaSopenharmony_ci * @brief Creates an OH_AVSource instance that models the media with data source. 32da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Spliter 33da853ecaSopenharmony_ci * @param dataSource User customized media resource. 34da853ecaSopenharmony_ci * @return Returns a pointer to an OH_AVSource instance if the execution is successful, otherwise returns nullptr. 35da853ecaSopenharmony_ci * Possible failure causes: 36da853ecaSopenharmony_ci * 1. dataSource is nullptr. 37da853ecaSopenharmony_ci * 2. dataSource->size == 0. 38da853ecaSopenharmony_ci * 3. set data source failed. 39da853ecaSopenharmony_ci * 4. out of memory. 40da853ecaSopenharmony_ci * 5. demuxer engine is nullptr. 41da853ecaSopenharmony_ci * @since 12 42da853ecaSopenharmony_ci*/ 43da853ecaSopenharmony_ciOH_AVSource *OH_AVSource_CreateWithDataSource(OH_AVDataSource *dataSource); 44da853ecaSopenharmony_ci 45da853ecaSopenharmony_ci/** 46da853ecaSopenharmony_ci * @brief Creates an OH_AVSource instance that models the media at the URI. 47da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Spliter 48da853ecaSopenharmony_ci * @param uri An URI for a remote media resource. 49da853ecaSopenharmony_ci * @return Returns a pointer to an OH_AVSource instance if the execution is successful, otherwise returns nullptr. 50da853ecaSopenharmony_ci * Possible failure causes: 51da853ecaSopenharmony_ci * 1. network anomaly. 52da853ecaSopenharmony_ci * 2. resource is invalid. 53da853ecaSopenharmony_ci * 3. file format is not supported. 54da853ecaSopenharmony_ci * @since 10 55da853ecaSopenharmony_ci*/ 56da853ecaSopenharmony_ciOH_AVSource *OH_AVSource_CreateWithURI(char *uri); 57da853ecaSopenharmony_ci 58da853ecaSopenharmony_ci/** 59da853ecaSopenharmony_ci * @brief Creates an OH_AVSource instance that models the media at the FileDescriptor. 60da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Spliter 61da853ecaSopenharmony_ci * @param fd The fileDescriptor of data source. 62da853ecaSopenharmony_ci * @param offset The offset into the file to start reading. 63da853ecaSopenharmony_ci * @param size The file size in bytes. 64da853ecaSopenharmony_ci * @return Returns a pointer to an OH_AVSource instance if the execution is successful, otherwise returns nullptr. 65da853ecaSopenharmony_ci * Possible failure causes: 66da853ecaSopenharmony_ci * 1. fd is invalid. 67da853ecaSopenharmony_ci * 2. offset is not start pos of resource. 68da853ecaSopenharmony_ci * 3. size error. 69da853ecaSopenharmony_ci * 4. resource is invalid. 70da853ecaSopenharmony_ci * 5. file format is not supported. 71da853ecaSopenharmony_ci * @since 10 72da853ecaSopenharmony_ci*/ 73da853ecaSopenharmony_ciOH_AVSource *OH_AVSource_CreateWithFD(int32_t fd, int64_t offset, int64_t size); 74da853ecaSopenharmony_ci 75da853ecaSopenharmony_ci/** 76da853ecaSopenharmony_ci * @brief Destroy the OH_AVSource instance and free the internal resources. 77da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Spliter 78da853ecaSopenharmony_ci * @param source Pointer to an OH_AVSource instance. 79da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful, 80da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 81da853ecaSopenharmony_ci * {@link AV_ERR_INVALID_VAL} source is invalid. 82da853ecaSopenharmony_ci * @since 10 83da853ecaSopenharmony_ci*/ 84da853ecaSopenharmony_ciOH_AVErrCode OH_AVSource_Destroy(OH_AVSource *source); 85da853ecaSopenharmony_ci 86da853ecaSopenharmony_ci/** 87da853ecaSopenharmony_ci * @brief Get the format info of source. 88da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Spliter 89da853ecaSopenharmony_ci * @param source Pointer to an OH_AVSource instance. 90da853ecaSopenharmony_ci * @return Returns the source's format info if the execution is successful, otherwise returns nullptr. 91da853ecaSopenharmony_ci * Possible failure causes: 92da853ecaSopenharmony_ci * 1. source is invalid. 93da853ecaSopenharmony_ci * @since 10 94da853ecaSopenharmony_ci*/ 95da853ecaSopenharmony_ciOH_AVFormat *OH_AVSource_GetSourceFormat(OH_AVSource *source); 96da853ecaSopenharmony_ci 97da853ecaSopenharmony_ci/** 98da853ecaSopenharmony_ci * @brief Get the format info of track. 99da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Spliter 100da853ecaSopenharmony_ci * @param source Pointer to an OH_AVSource instance. 101da853ecaSopenharmony_ci * @param trackIndex The track index to get format. 102da853ecaSopenharmony_ci * @return Returns the track's format info if the execution is successful, otherwise returns nullptr. 103da853ecaSopenharmony_ci * Possible failure causes: 104da853ecaSopenharmony_ci * 1. source is invalid. 105da853ecaSopenharmony_ci * 2. trackIndex is out of range. 106da853ecaSopenharmony_ci * @since 10 107da853ecaSopenharmony_ci*/ 108da853ecaSopenharmony_ciOH_AVFormat *OH_AVSource_GetTrackFormat(OH_AVSource *source, uint32_t trackIndex); 109da853ecaSopenharmony_ci 110da853ecaSopenharmony_ci#ifdef __cplusplus 111da853ecaSopenharmony_ci} 112da853ecaSopenharmony_ci#endif 113da853ecaSopenharmony_ci 114da853ecaSopenharmony_ci#endif // NATIVE_AVSOURCE_H