• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
24 extern "C" {
25 #endif
26 
27 typedef struct OH_AVDemuxer OH_AVDemuxer;
28 typedef struct DRM_MediaKeySystemInfo DRM_MediaKeySystemInfo;
29 
30 typedef void (*DRM_MediaKeySystemInfoCallback)(DRM_MediaKeySystemInfo* mediaKeySystemInfo);
31 
32 /**
33  * @brief Creates an OH_AVDemuxer instance for getting samples from source.
34  * Free the resources of the instance by calling OH_AVDemuxer_Destroy.
35  * @syscap SystemCapability.Multimedia.Media.Spliter
36  * @param source Pointer to an OH_AVSource instance.
37  * @return Returns a pointer to an OH_AVDemuxer instance
38  * @since 10
39 */
40 OH_AVDemuxer *OH_AVDemuxer_CreateWithSource(OH_AVSource *source);
41 
42 /**
43  * @brief Destroy the OH_AVDemuxer instance and free the internal resources.
44  * The same instance can only be destroyed once. The destroyed instance
45  * should not be used before it is created again. It is recommended setting
46  * the instance pointer to NULL right after the instance is destroyed successfully.
47  * @syscap SystemCapability.Multimedia.Media.Spliter
48  * @param demuxer Pointer to an OH_AVDemuxer instance.
49  * @return Returns AV_ERR_OK if the execution is successful,
50  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
51  * @since 10
52 */
53 OH_AVErrCode OH_AVDemuxer_Destroy(OH_AVDemuxer *demuxer);
54 
55 /**
56  * @brief The specified track is selected and the demuxer will read samples from
57  * this track. Multiple tracks are selected by calling this interface multiple times
58  * with different track indexes. Only the selected tracks are valid when calling
59  * OH_AVDemuxer_ReadSample to read samples. The interface returns AV_ERR_OK and the
60  * track is selected only once if the same track is selected multiple times.
61  * @syscap SystemCapability.Multimedia.Media.Spliter
62  * @param demuxer Pointer to an OH_AVDemuxer instance.
63  * @param trackIndex The index of the selected track.
64  * @return Returns AV_ERR_OK if the execution is successful,
65  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
66  * @since 10
67 */
68 OH_AVErrCode OH_AVDemuxer_SelectTrackByID(OH_AVDemuxer *demuxer, uint32_t trackIndex);
69 
70 /**
71  * @brief The specified selected track is unselected. The unselected track's sample
72  * can not be read from demuxer. Multiple selected tracks are unselected by calling
73  * this interface multiple times with different track indexes. The interface returns
74  * AV_ERR_OK and the track is unselected only once if the same track is unselected
75  * multiple times.
76  * @syscap SystemCapability.Multimedia.Media.Spliter
77  * @param demuxer Pointer to an OH_AVDemuxer instance.
78  * @param trackIndex The index of the unselected track.
79  * @return Returns AV_ERR_OK if the execution is successful,
80  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
81  * @since 10
82 */
83 OH_AVErrCode OH_AVDemuxer_UnselectTrackByID(OH_AVDemuxer *demuxer, uint32_t trackIndex);
84 
85 /**
86  * @brief Get the current encoded sample and sample-related information from the specified
87  * track. The track index must be selected before reading sample. The demuxer will advance
88  * automatically after calling this interface.
89  * @syscap SystemCapability.Multimedia.Media.Spliter
90  * @param demuxer Pointer to an OH_AVDemuxer instance.
91  * @param trackIndex The index of the track from which read an encoded sample.
92  * @param sample The OH_AVMemory handle pointer to the buffer storing the sample data.
93  * @param info The OH_AVCodecBufferAttr handle pointer to the buffer storing sample information.
94  * @return Returns AV_ERR_OK if the execution is successful,
95  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
96  * @deprecated since 11
97  * @useinstead OH_AVDemuxer_ReadSampleBuffer
98  * @since 10
99 */
100 OH_AVErrCode OH_AVDemuxer_ReadSample(OH_AVDemuxer *demuxer, uint32_t trackIndex,
101     OH_AVMemory *sample, OH_AVCodecBufferAttr *info);
102 
103 /**
104  * @brief Get the current encoded sample and sample-related information from the specified
105  * track. The track index must be selected before reading sample. The demuxer will advance
106  * automatically after calling this interface.
107  * @syscap SystemCapability.Multimedia.Media.Spliter
108  * @param demuxer Pointer to an OH_AVDemuxer instance.
109  * @param trackIndex The index of the track from which read an encoded sample.
110  * @param sample The OH_AVBuffer handle pointer to the buffer storing the sample data and corresponding attribute.
111  * @return Returns AV_ERR_OK if the execution is successful,
112  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
113  * @since 11
114 */
115 OH_AVErrCode OH_AVDemuxer_ReadSampleBuffer(OH_AVDemuxer *demuxer, uint32_t trackIndex,
116     OH_AVBuffer *sample);
117 
118 /**
119  * @brief All selected tracks seek near to the requested time according to the seek mode.
120  * @syscap SystemCapability.Multimedia.Media.Spliter
121  * @param demuxer Pointer to an OH_AVDemuxer instance.
122  * @param millisecond The millisecond for seeking, the timestamp is the position of
123  * the file relative to the start of the file.
124  * @param mode The mode for seeking. See {@link OH_AVSeekMode}.
125  * @return Returns AV_ERR_OK if the execution is successful,
126  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
127  * @since 10
128 */
129 OH_AVErrCode OH_AVDemuxer_SeekToTime(OH_AVDemuxer *demuxer, int64_t millisecond, OH_AVSeekMode mode);
130 
131 /**
132  * @brief Method to set player media key system info callback.
133  * @syscap SystemCapability.Multimedia.Media.Spliter
134  * @param demuxer Pointer to an OH_AVDemuxer instance
135  * @param callback object pointer.
136  * @return Returns {@link AV_ERR_OK} if the drm info callback is set; returns an error code defined
137  * in {@link native_averrors.h} otherwise.
138  * @since 11
139  * @version 1.0
140  */
141 OH_AVErrCode OH_AVDemuxer_SetMediaKeySystemInfoCallback(OH_AVDemuxer *demuxer,
142     DRM_MediaKeySystemInfoCallback callback);
143 
144 /**
145  * @brief Obtains media key system info to create media key session.
146  * @syscap SystemCapability.Multimedia.Media.Spliter
147  * @param demuxer Pointer to an OH_AVDemuxer instance
148  * @param mediaKeySystemInfo Indicates the media key systemInfo info which ram space allocated
149  * by callee and released by caller.
150  * @return Returns {@link AV_ERR_OK} if the current position is get; returns an error code defined
151  * in {@link native_averrors.h} otherwise.
152  * @since 11
153  * @version 1.0
154  */
155 OH_AVErrCode OH_AVDemuxer_GetMediaKeySystemInfo(OH_AVDemuxer *demuxer, DRM_MediaKeySystemInfo *mediaKeySystemInfo);
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif // NATIVE_AVDEMUXER_H
162