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 AVDEMUXER_IMPL_H
17#define AVDEMUXER_IMPL_H
18
19#include <memory>
20#include "avdemuxer.h"
21#include "avsource.h"
22#include "nocopyable.h"
23#include "media_demuxer.h"
24
25namespace OHOS {
26namespace MediaAVCodec {
27using namespace Media;
28class AVDemuxerImpl : public AVDemuxer, public NoCopyable {
29public:
30    AVDemuxerImpl();
31    ~AVDemuxerImpl();
32
33    int32_t SelectTrackByID(uint32_t trackIndex) override;
34    int32_t UnselectTrackByID(uint32_t trackIndex) override;
35    int32_t ReadSample(uint32_t trackIndex, std::shared_ptr<AVSharedMemory> sample,
36        AVCodecBufferInfo &info, uint32_t &flag) override;
37    int32_t ReadSample(uint32_t trackIndex, std::shared_ptr<AVSharedMemory> sample,
38        AVCodecBufferInfo &info, AVCodecBufferFlag &flag) override;
39    int32_t ReadSampleBuffer(uint32_t trackIndex, std::shared_ptr<AVBuffer> sample) override;
40    int32_t SeekToTime(int64_t millisecond, const SeekMode mode) override;
41    int32_t SetCallback(const std::shared_ptr<AVDemuxerCallback> &callback) override;
42    int32_t GetMediaKeySystemInfo(std::multimap<std::string, std::vector<uint8_t>> &infos) override;
43    int32_t Init(std::shared_ptr<AVSource> source);
44    int32_t StartReferenceParser(int64_t startTimeMs) override;
45    int32_t GetFrameLayerInfo(std::shared_ptr<AVBuffer> videoSample, FrameLayerInfo &frameLayerInfo) override;
46    int32_t GetGopLayerInfo(uint32_t gopId, GopLayerInfo &gopLayerInfo) override;
47
48    int32_t GetIndexByRelativePresentationTimeUs(const uint32_t trackIndex,
49        const uint64_t relativePresentationTimeUs, uint32_t &index) override;
50    int32_t GetRelativePresentationTimeUsByIndex(const uint32_t trackIndex,
51        const uint32_t index, uint64_t &relativePresentationTimeUs) override;
52private:
53    std::shared_ptr<MediaDemuxer> mediaDemuxer_ = nullptr;
54    std::string sourceUri_;
55};
56} // namespace MediaAVCodec
57} // namespace OHOS
58#endif // AVDEMUXER_IMPL_H