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