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