• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024-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 #ifndef TRANSCODER_MOCK_H
17 #define TRANSCODER_MOCK_H
18 #include <atomic>
19 #include <thread>
20 #include <string>
21 #include "gtest/gtest.h"
22 #include "media_errors.h"
23 #include "unittest_log.h"
24 #include "transcoder.h"
25 #include "surface.h"
26 #include "securec.h"
27 #include "nocopyable.h"
28 
29 namespace OHOS {
30 namespace Media {
31 namespace TranscoderTestParam {
32     constexpr uint32_t TRASCODER_AUDIO_ENCODING_BIT_RATE = 20000;
33     constexpr uint32_t TRASCODER_VIDEO_ENCODING_BIT_RATE = 30000;
34     constexpr int32_t TRANSCODER_BUFFER_WIDTH = 320;
35     constexpr int32_t TRANSCODER_BUFFER_HEIGHT = 240;
36     constexpr int32_t TRANSCODER_BUFFER_WIDTH_480p = 640;
37     constexpr int32_t TRANSCODER_BUFFER_HEIGHT_480p = 480;
38     constexpr int32_t ERROR_WRONG_STATE = -5;
39     constexpr uint64_t TRANSCODER_FILE_OFFSET = 37508084;
40     constexpr uint64_t TRANSCODER_FILE_SIZE = 2735029;
41     const std::string TRANSCODER_ROOT_SRC = "/data/test/media/transcoder_src/";
42     const std::string TRANSCODER_ROOT_DST = "/data/test/media/transcoder_dst/";
43 } // namespace TranscoderTestParam
44 class TranscoderMock {
45 public:
46     TranscoderMock() = default;
47     ~TranscoderMock() = default;
48     bool CreateTranscoder();
49     int32_t SetOutputFormat(OutputFormatType format);
50     int32_t SetVideoEncoder(VideoCodecFormat encoder);
51     int32_t SetVideoEncodingBitRate(int32_t rate);
52     int32_t SetVideoSize(int32_t videoFrameWidth, int32_t videoFrameHeight);
53     int32_t SetColorSpace(TranscoderColorSpace colorSpaceFormat);
54     int32_t SetEnableBFrame(bool enableBFrame);
55     int32_t SetAudioEncoder(AudioCodecFormat encoder);
56     int32_t SetAudioEncodingBitRate(int32_t bitRate);
57     int32_t SetInputFile(int32_t fd, int64_t offset, int64_t size);
58     int32_t SetOutputFile(int32_t fd);
59     int32_t SetTransCoderCallback(const std::shared_ptr<TransCoderCallback> &callback);
60     int32_t Prepare();
61     int32_t Start();
62     int32_t Pause();
63     int32_t Resume();
64     int32_t Cancel();
65     int32_t Release();
66 private:
67     std::shared_ptr<TransCoder> transcoder_ = nullptr;
68     std::atomic<bool> isExit_ { false };
69 };
70 
71 class TransCoderCallbackTest : public TransCoderCallback, public NoCopyable {
72 public:
~TransCoderCallbackTest()73     ~TransCoderCallbackTest() {}
74     void OnError(int32_t errorCode, const std::string &errorMsg) override;
75     void OnInfo(int32_t type, int32_t extra) override;
76 };
77 }
78 }
79 #endif