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 #include <memory>
17 #include "avmemory_inner_mock.h"
18 #include "native_averrors.h"
19 #include "demuxer_inner_mock.h"
20 
21 namespace OHOS {
22 namespace MediaAVCodec {
Destroy()23 int32_t DemuxerInnerMock::Destroy()
24 {
25     if (demuxer_ != nullptr) {
26         demuxer_ = nullptr;
27         return AV_ERR_OK;
28     }
29     return AV_ERR_UNKNOWN;
30 }
31 
SelectTrackByID(uint32_t trackIndex)32 int32_t DemuxerInnerMock::SelectTrackByID(uint32_t trackIndex)
33 {
34     if (demuxer_ != nullptr) {
35         return demuxer_->SelectTrackByID(trackIndex);
36     }
37     return AV_ERR_UNKNOWN;
38 }
39 
UnselectTrackByID(uint32_t trackIndex)40 int32_t DemuxerInnerMock::UnselectTrackByID(uint32_t trackIndex)
41 {
42     if (demuxer_ != nullptr) {
43         return demuxer_->UnselectTrackByID(trackIndex);
44     }
45     return AV_ERR_UNKNOWN;
46 }
47 
ReadSample(uint32_t trackIndex,std::shared_ptr<AVMemoryMock> sample,AVCodecBufferInfo * bufferInfo,uint32_t & flag,bool checkBufferInfo)48 int32_t DemuxerInnerMock::ReadSample(uint32_t trackIndex, std::shared_ptr<AVMemoryMock> sample,
49     AVCodecBufferInfo *bufferInfo, uint32_t &flag, bool checkBufferInfo)
50 {
51     (void)checkBufferInfo;
52     auto mem = std::static_pointer_cast<AVMemoryInnerMock>(sample);
53     std::shared_ptr<AVSharedMemory> sharedMem = (mem != nullptr) ? mem->GetAVMemory() : nullptr;
54     if (demuxer_ != nullptr) {
55         int32_t ret = demuxer_->ReadSample(trackIndex, sharedMem, *bufferInfo, flag);
56         return ret;
57     }
58     return AV_ERR_UNKNOWN;
59 }
60 
SeekToTime(int64_t mSeconds,SeekMode mode)61 int32_t DemuxerInnerMock::SeekToTime(int64_t mSeconds, SeekMode mode)
62 {
63     if (demuxer_ != nullptr) {
64         SeekMode seekMode = static_cast<SeekMode>(mode);
65         return demuxer_->SeekToTime(mSeconds, seekMode);
66     }
67     return AV_ERR_UNKNOWN;
68 }
69 
GetIndexByRelativePresentationTimeUs(const uint32_t trackIndex,const uint64_t relativePresentationTimeUs,uint32_t & index)70 int32_t DemuxerInnerMock::GetIndexByRelativePresentationTimeUs(const uint32_t trackIndex,
71     const uint64_t relativePresentationTimeUs, uint32_t &index)
72 {
73     if (demuxer_ != nullptr) {
74         return demuxer_->GetIndexByRelativePresentationTimeUs(trackIndex, relativePresentationTimeUs, index);
75     }
76     return AV_ERR_UNKNOWN;
77 }
78 
GetRelativePresentationTimeUsByIndex(uint32_t trackIndex,const uint32_t index,uint64_t & relativePresentationTimeUs)79 int32_t DemuxerInnerMock::GetRelativePresentationTimeUsByIndex(uint32_t trackIndex,
80     const uint32_t index, uint64_t &relativePresentationTimeUs)
81 
82 {
83     if (demuxer_ != nullptr) {
84         return demuxer_->GetRelativePresentationTimeUsByIndex(trackIndex, index, relativePresentationTimeUs);
85     }
86     return AV_ERR_UNKNOWN;
87 }
88 }
89 }