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