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 DEMUXER_MOCK_H
17 #define DEMUXER_MOCK_H
18 
19 #include <cinttypes>
20 #include <string>
21 #include <memory>
22 #include "nocopyable.h"
23 #include "avformat_mock.h"
24 #include "avsource_mock.h"
25 #include "common_mock.h"
26 #include "av_common.h"
27 #include "avcodec_common.h"
28 
29 namespace OHOS {
30 namespace MediaAVCodec {
31 class DemuxerMock : public NoCopyable {
32 public:
33     virtual ~DemuxerMock() = default;
34 
35     virtual int32_t Destroy() = 0;
36     virtual int32_t SelectTrackByID(uint32_t trackIndex) = 0;
37     virtual int32_t UnselectTrackByID(uint32_t trackIndex) = 0;
38     virtual int32_t ReadSample(uint32_t trackIndex, std::shared_ptr<AVMemoryMock> sample,
39         AVCodecBufferInfo *bufferInfo, uint32_t &flag, bool checkBufferInfo = false) = 0;
40     virtual int32_t SeekToTime(int64_t mSeconds, Media::SeekMode mode) = 0;
SetMediaKeySystemInfoCallback(bool isNull)41     virtual int32_t SetMediaKeySystemInfoCallback(bool isNull)
42     {
43         return AV_ERR_OK;
44     }
SetDemuxerMediaKeySystemInfoCallback(bool isNull)45     virtual int32_t SetDemuxerMediaKeySystemInfoCallback(bool isNull)
46     {
47         return AV_ERR_OK;
48     }
GetMediaKeySystemInfo()49     virtual int32_t GetMediaKeySystemInfo()
50     {
51         return AV_ERR_OK;
52     }
53     virtual int32_t GetIndexByRelativePresentationTimeUs(const uint32_t trackIndex,
54         const uint64_t relativePresentationTimeUs, uint32_t &index) = 0;
55     virtual int32_t GetRelativePresentationTimeUsByIndex(const uint32_t trackIndex,
56         const uint32_t index, uint64_t &relativePresentationTimeUs) = 0;
57 };
58 
59 class __attribute__((visibility("default"))) AVDemuxerMockFactory {
60 public:
61     static std::shared_ptr<DemuxerMock> CreateDemuxer(std::shared_ptr<AVSourceMock> source);
62 private:
63     AVDemuxerMockFactory() = delete;
64     ~AVDemuxerMockFactory() = delete;
65 };
66 }  // namespace MediaAVCodec
67 }  // namespace OHOS
68 #endif // DEMUXER_MOCK_H