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 "avformat_capi_mock.h"
18 #include "avsource_capi_mock.h"
19 
20 namespace OHOS {
21 namespace MediaAVCodec {
Destroy()22 int32_t AVSourceCapiMock::Destroy()
23 {
24     if (source_ != nullptr) {
25         int32_t ret = OH_AVSource_Destroy(source_);
26         source_ = nullptr;
27         return ret;
28     }
29     return AV_ERR_UNKNOWN;
30 }
31 
GetSourceFormat()32 std::shared_ptr<FormatMock> AVSourceCapiMock::GetSourceFormat()
33 {
34     if (source_ != nullptr) {
35         OH_AVFormat *format = OH_AVSource_GetSourceFormat(source_);
36         if (format != nullptr) {
37             return std::make_shared<AVFormatCapiMock>(format);
38         }
39         return nullptr;
40     }
41     return nullptr;
42 }
43 
GetTrackFormat(uint32_t trackIndex)44 std::shared_ptr<FormatMock> AVSourceCapiMock::GetTrackFormat(uint32_t trackIndex)
45 {
46     if (source_ != nullptr) {
47         OH_AVFormat *format = OH_AVSource_GetTrackFormat(source_, trackIndex);
48         if (format != nullptr) {
49             return std::make_shared<AVFormatCapiMock>(format);
50         }
51         return nullptr;
52     }
53     return nullptr;
54 }
55 
GetUserData()56 std::shared_ptr<FormatMock> AVSourceCapiMock::GetUserData()
57 {
58     return nullptr;
59 }
60 
GetAVSource()61 OH_AVSource* AVSourceCapiMock::GetAVSource()
62 {
63     return source_;
64 }
65 } // namespace MediaAVCodec
66 } // namespace OHOS