1 /*
2 * Copyright (C) 2025 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 "avtranscoder_mock.h"
17
18 using namespace OHOS;
19 using namespace OHOS::Media;
20
21 static const int32_t INVALID_TYPE = -1;
22 static const int32_t TEST_EXTRA = 0;
23
CreateTransCoder()24 std::shared_ptr<TransCoder> TransCoderFactory::CreateTransCoder()
25 {
26 std::shared_ptr<MockAVTransCoder> transcoder = std::make_shared<MockAVTransCoder>();
27 return transcoder;
28 }
29
SetOutputFormat(OutputFormatType format)30 int32_t MockAVTransCoder::SetOutputFormat(OutputFormatType format)
31 {
32 return MSERR_OK;
33 }
34
SetVideoEncoder(VideoCodecFormat encoder)35 int32_t MockAVTransCoder::SetVideoEncoder(VideoCodecFormat encoder)
36 {
37 return MSERR_OK;
38 }
39
SetVideoEncodingBitRate(int32_t rate)40 int32_t MockAVTransCoder::SetVideoEncodingBitRate(int32_t rate)
41 {
42 return MSERR_OK;
43 }
44
SetVideoSize(int32_t videoFrameWidth,int32_t videoFrameHeight)45 int32_t MockAVTransCoder::SetVideoSize(int32_t videoFrameWidth, int32_t videoFrameHeight)
46 {
47 return MSERR_OK;
48 }
49
SetColorSpace(TranscoderColorSpace colorSpaceFormat)50 int32_t MockAVTransCoder::SetColorSpace(TranscoderColorSpace colorSpaceFormat)
51 {
52 return MSERR_OK;
53 }
54
SetEnableBFrame(bool enableBFrame)55 int32_t MockAVTransCoder::SetEnableBFrame(bool enableBFrame)
56 {
57 return MSERR_OK;
58 }
59
SetAudioEncoder(AudioCodecFormat encoder)60 int32_t MockAVTransCoder::SetAudioEncoder(AudioCodecFormat encoder)
61 {
62 return MSERR_OK;
63 }
64
SetAudioEncodingBitRate(int32_t bitRate)65 int32_t MockAVTransCoder::SetAudioEncodingBitRate(int32_t bitRate)
66 {
67 return MSERR_OK;
68 }
69
SetInputFile(int32_t fd,int64_t offset,int64_t size)70 int32_t MockAVTransCoder::SetInputFile(int32_t fd, int64_t offset, int64_t size)
71 {
72 if (fd < 0 && callback_ != nullptr) {
73 callback_->OnError(MSERR_SUPER_RESOLUTION_NOT_ENABLED, "mock");
74 return MSERR_INVALID_VAL;
75 }
76 return MSERR_OK;
77 }
78
SetOutputFile(int32_t fd)79 int32_t MockAVTransCoder::SetOutputFile(int32_t fd)
80 {
81 if (fd < 0 && callback_ != nullptr) {
82 callback_->OnError(MSERR_INVALID_OPERATION, "mock");
83 return MSERR_INVALID_VAL;
84 }
85 return MSERR_OK;
86 }
87
SetTransCoderCallback(const std::shared_ptr<TransCoderCallback> & callback)88 int32_t MockAVTransCoder::SetTransCoderCallback(const std::shared_ptr<TransCoderCallback> &callback)
89 {
90 callback_ = callback;
91 return MSERR_OK;
92 }
93
Prepare()94 int32_t MockAVTransCoder::Prepare()
95 {
96 if (callback_) {
97 callback_->OnInfo(TransCoderOnInfoType::INFO_TYPE_PROGRESS_UPDATE, TEST_EXTRA);
98 }
99 return MSERR_OK;
100 }
101
Start()102 int32_t MockAVTransCoder::Start()
103 {
104 if (callback_) {
105 callback_->OnInfo(TransCoderOnInfoType::INFO_TYPE_TRANSCODER_COMPLETED, TEST_EXTRA);
106 }
107 return MSERR_OK;
108 }
109
Pause()110 int32_t MockAVTransCoder::Pause()
111 {
112 if (callback_) {
113 callback_->OnInfo(INVALID_TYPE, TEST_EXTRA);
114 }
115 return MSERR_OK;
116 }
117
Resume()118 int32_t MockAVTransCoder::Resume()
119 {
120 return MSERR_OK;
121 }
122
Cancel()123 int32_t MockAVTransCoder::Cancel()
124 {
125 return MSERR_OK;
126 }
127
Release()128 int32_t MockAVTransCoder::Release()
129 {
130 return MSERR_OK;
131 }