• 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 
17 #ifndef MEDIA_AVCODEC_AVDEMUXER_H
18 #define MEDIA_AVCODEC_AVDEMUXER_H
19 
20 #include <memory>
21 #include "avcodec_common.h"
22 #include "buffer/avbuffer.h"
23 #include "buffer/avsharedmemory.h"
24 #include "avsource.h"
25 #include "meta/media_types.h"
26 
27 namespace OHOS {
28 namespace MediaAVCodec {
29 using namespace Media;
30 class AVDemuxer {
31 public:
32     ~AVDemuxer() = default;
33 
34     /**
35      * @brief Select the sourceTrack by track index.
36      * This function can only by called before {@link ReadSample}.
37      * @param trackIndex The track index for being selected.
38      * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise.
39      * @since 4.0
40      */
41     virtual int32_t SelectTrackByID(uint32_t trackIndex) = 0;
42 
43     /**
44      * @brief Unselect the sourceTrack by track index.
45      * This function can only by called before {@link ReadSample}.
46      * @param trackIndex The track index for being unselected.
47      * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise.
48      * @since 4.0
49      */
50     virtual int32_t UnselectTrackByID(uint32_t trackIndex) = 0;
51 
52     /**
53      * @brief Retrieve the sample in selected tracks and store it in buffer, and store buffer's info to attr.
54      * @param trackIndex Get the sampleBuffer from this track.
55      * @param sample The AVSharedMemory handle pointer to get buffer data.
56      * @param info The CodecBufferAttr handle pointer to get buffer info.
57      * @param flag The buffer flags.
58      * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise.
59      * @since 4.0
60      */
61     virtual int32_t ReadSample(uint32_t trackIndex, std::shared_ptr<AVSharedMemory> sample,
62         AVCodecBufferInfo &info, uint32_t &flag) = 0;
63 
64     /**
65      * @brief Retrieve the sample in selected tracks and store it in buffer, and store buffer's info to attr.
66      * @param trackIndex Get the sampleBuffer from this track.
67      * @param sample The AVSharedMemory handle pointer to get buffer data.
68      * @param info The CodecBufferAttr handle pointer to get buffer info.
69      * @param flag The buffer flags.
70      * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise.
71      * @since 4.0
72      */
73     virtual int32_t ReadSample(uint32_t trackIndex, std::shared_ptr<AVSharedMemory> sample,
74         AVCodecBufferInfo &info, AVCodecBufferFlag &flag) = 0;
75 
76      /**
77      * @brief Retrieve the sample in selected tracks and store it in buffer, and store buffer's info to attr.
78      * @param trackIndex Get the sampleBuffer from this track.
79      * @param sample The AVBuffer handle pointer to get buffer data.
80      * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise.
81      * @since 4.1
82      */
83     virtual int32_t ReadSampleBuffer(uint32_t trackIndex, std::shared_ptr<AVBuffer> sample) = 0;
84 
85     /**
86      * @brief All selected tracks seek near to the requested time according to the seek mode.
87      * @param millisecond The timestamp for seeking which is the position relative to the beginning of the file.
88      * @param mode The mode for seeking. Value. For details, see {@link SeekMode}.
89      * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise.
90      * @since 4.0
91      */
92     virtual int32_t SeekToTime(int64_t millisecond, SeekMode mode) = 0;
93 
94     /**
95      * @brief Registers a demuxer listener.
96      *
97      * @param callback Indicates the demuxer listener to register. For details, see {@link AVDemuxerCallback}.
98      * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise.
99      * @since 4.1
100      * @version 4.1
101      */
102     virtual int32_t SetCallback(const std::shared_ptr<AVDemuxerCallback> &callback) = 0;
103 
104     virtual int32_t GetMediaKeySystemInfo(std::multimap<std::string, std::vector<uint8_t>> &infos) = 0;
105 };
106 
107 class __attribute__((visibility("default"))) AVDemuxerFactory {
108 public:
109 #ifdef UNSUPPORT_DEMUXER
CreateWithSource(std::shared_ptr<AVSource> source)110     static std::shared_ptr<AVDemuxer> CreateWithSource(std::shared_ptr<AVSource> source)
111     {
112         return nullptr;
113     }
114 #else
115     /**
116      * @brief Instantiate the preferred demuxer of the given source instance.
117      * @param sourceAddr The address for source instance.
118      * @return Returns the preferred demuxer.
119      * @since 4.0
120      */
121     static std::shared_ptr<AVDemuxer> CreateWithSource(std::shared_ptr<AVSource> source);
122 #endif
123 private:
124     AVDemuxerFactory() = default;
125     ~AVDemuxerFactory() = default;
126 };
127 } // namespace MediaAVCodec
128 } // namespace OHOS
129 #endif // MEDIA_AVCODEC_AVDEMUXER_H
130