• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 "transcoder_mock.h"
17 #include <sync_fence.h>
18 #include <cstdio>
19 #include <fstream>
20 #include <iostream>
21 #include <sstream>
22 #include <fcntl.h>
23 #include <unistd.h>
24 #include <sys/stat.h>
25 #include <sys/time.h>
26 #include <sys/types.h>
27 
28 using namespace std;
29 using namespace OHOS;
30 using namespace OHOS::Media;
31 using namespace testing::ext;
32 using namespace OHOS::Media::TranscoderTestParam;
33 
OnError(int32_t errorCode,const std::string & errorMsg)34 void TransCoderCallbackTest::OnError(int32_t errorCode, const std::string &errorMsg)
35 {
36     cout << "Error received, errorType:" << errorCode << " errorCode:" << errorMsg << endl;
37 }
38 
OnInfo(int32_t type,int32_t extra)39 void TransCoderCallbackTest::OnInfo(int32_t type, int32_t extra)
40 {
41     cout << "Info received, Infotype:" << type << " Infocode:" << extra << endl;
42 }
43 
CreateTranscoder()44 bool TranscoderMock::CreateTranscoder()
45 {
46     transcoder_ = TransCoderFactory::CreateTransCoder();
47     return transcoder_ != nullptr;
48 }
49 
SetOutputFormat(OutputFormatType format)50 int32_t TranscoderMock::SetOutputFormat(OutputFormatType format)
51 {
52     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
53     return transcoder_->SetOutputFormat(format);
54 }
55 
SetVideoEncoder(VideoCodecFormat encoder)56 int32_t TranscoderMock::SetVideoEncoder(VideoCodecFormat encoder)
57 {
58     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
59     return transcoder_->SetVideoEncoder(encoder);
60 }
61 
SetVideoEncodingBitRate(int32_t rate)62 int32_t TranscoderMock::SetVideoEncodingBitRate(int32_t rate)
63 {
64     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
65     return transcoder_->SetVideoEncodingBitRate(rate);
66 }
67 
SetVideoSize(int32_t videoFrameWidth,int32_t videoFrameHeight)68 int32_t TranscoderMock::SetVideoSize(int32_t videoFrameWidth, int32_t videoFrameHeight)
69 {
70     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
71     return transcoder_->SetVideoSize(videoFrameWidth, videoFrameHeight);
72 }
73 
SetAudioEncoder(AudioCodecFormat encoder)74 int32_t TranscoderMock::SetAudioEncoder(AudioCodecFormat encoder)
75 {
76     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
77     return transcoder_->SetAudioEncoder(encoder);
78 }
79 
SetAudioEncodingBitRate(int32_t bitRate)80 int32_t TranscoderMock::SetAudioEncodingBitRate(int32_t bitRate)
81 {
82     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
83     return transcoder_->SetAudioEncodingBitRate(bitRate);
84 }
85 
SetInputFile(int32_t fd,int64_t offset,int64_t size)86 int32_t TranscoderMock::SetInputFile(int32_t fd, int64_t offset, int64_t size)
87 {
88     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
89     return transcoder_->SetInputFile(fd, offset, size);
90 }
91 
SetOutputFile(int32_t fd)92 int32_t TranscoderMock::SetOutputFile(int32_t fd)
93 {
94     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
95     return transcoder_->SetOutputFile(fd);
96 }
97 
SetTransCoderCallback(const std::shared_ptr<TransCoderCallback> & callback)98 int32_t TranscoderMock::SetTransCoderCallback(const std::shared_ptr<TransCoderCallback> &callback)
99 {
100     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
101     return transcoder_->SetTransCoderCallback(callback);
102 }
103 
Prepare()104 int32_t TranscoderMock::Prepare()
105 {
106     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
107     return transcoder_->Prepare();
108 }
109 
Start()110 int32_t TranscoderMock::Start()
111 {
112     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
113     return transcoder_->Start();
114 }
115 
Pause()116 int32_t TranscoderMock::Pause()
117 {
118     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
119     if (!isExit_.load()) {
120         isExit_.store(true);
121     }
122     return transcoder_->Pause();
123 }
124 
Resume()125 int32_t TranscoderMock::Resume()
126 {
127     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
128     if (!isExit_.load()) {
129         isExit_.store(true);
130     }
131     return transcoder_->Resume();
132 }
133 
Cancel()134 int32_t TranscoderMock::Cancel()
135 {
136     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
137     if (!isExit_.load()) {
138         isExit_.store(true);
139     }
140     return transcoder_->Cancel();
141 }
142 
Release()143 int32_t TranscoderMock::Release()
144 {
145     UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr");
146     if (!isExit_.load()) {
147         isExit_.store(true);
148     }
149     return transcoder_->Release();
150 }