• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef VIDEO_DEC_INNER_MOCK_H
17 #define VIDEO_DEC_INNER_MOCK_H
18 
19 #include "vcodec_mock.h"
20 #include "avcodec_common.h"
21 #include "avcodec_video_decoder.h"
22 
23 namespace OHOS {
24 namespace MediaAVCodec {
25 class VideoDecInnerMock : public VideoDecMock {
26 public:
VideoDecInnerMock(std::shared_ptr<AVCodecVideoDecoder> videoDec)27     explicit VideoDecInnerMock(std::shared_ptr<AVCodecVideoDecoder> videoDec) : videoDec_(videoDec) {}
28     ~VideoDecInnerMock() = default;
29     int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) override;
30     int32_t SetOutputSurface(std::shared_ptr<SurfaceMock> surface) override;
31     int32_t Configure(std::shared_ptr<FormatMock> format) override;
32     int32_t Start() override;
33     int32_t Stop() override;
34     int32_t Flush() override;
35     int32_t Reset() override;
36     int32_t Release() override;
37     std::shared_ptr<FormatMock> GetOutputDescription() override;
38     int32_t SetParameter(std::shared_ptr<FormatMock> format) override;
39     int32_t PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr) override;
40     int32_t RenderOutputData(uint32_t index) override;
41     int32_t FreeOutputData(uint32_t index) override;
42     bool IsValid() override;
43 
44 private:
45     std::shared_ptr<AVCodecVideoDecoder> videoDec_ = nullptr;
46 };
47 
48 class VideoDecCallbackMock : public AVCodecCallback {
49 public:
50     VideoDecCallbackMock(std::shared_ptr<AVCodecCallbackMock> cb, std::weak_ptr<AVCodecVideoDecoder> vd);
51     ~VideoDecCallbackMock() = default;
52     void OnError(AVCodecErrorType errorType, int32_t errorCode) override;
53     void OnOutputFormatChanged(const Format &format) override;
54     void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVSharedMemory> buffer) override;
55     void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag,
56                                  std::shared_ptr<AVSharedMemory> buffer) override;
57 
58 private:
59     std::shared_ptr<AVCodecCallbackMock> mockCb_ = nullptr;
60     std::weak_ptr<AVCodecVideoDecoder> videoDec_;
61 };
62 } // namespace MediaAVCodec
63 } // namespace OHOS
64 #endif // VIDEO_DEC_INNER_MOCK_H