• 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 MEDIA_CODEC_DECODER_ADAPTER_H
17 #define MEDIA_CODEC_DECODER_ADAPTER_H
18 
19 #include <condition_variable>
20 #include <cstdint>
21 #include <memory>
22 #include <mutex>
23 #include <queue>
24 #include <string>
25 
26 #include "graphic_adapter.h"
27 #include "media_codec_adapter.h"
28 #include "audio_cenc_info_adapter.h"
29 
30 namespace OHOS::NWeb {
31 
32 enum class DecoderAdapterCode : int32_t { DECODER_OK = 0, DECODER_ERROR = 1, DECODER_RETRY = 2 };
33 
34 class DecoderFormatAdapter {
35 public:
36     DecoderFormatAdapter() = default;
37 
38     virtual ~DecoderFormatAdapter() = default;
39 
40     virtual int32_t GetWidth() = 0;
41 
42     virtual int32_t GetHeight() = 0;
43 
44     virtual double GetFrameRate() = 0;
45 
46     virtual void SetWidth(int32_t width) = 0;
47 
48     virtual void SetHeight(int32_t height) = 0;
49 
50     virtual void SetFrameRate(double frameRate) = 0;
51 };
52 
53 class DecoderCallbackAdapter {
54 public:
55     DecoderCallbackAdapter() = default;
56 
57     virtual ~DecoderCallbackAdapter() = default;
58 
59     virtual void OnError(ErrorType errorType, int32_t errorCode) = 0;
60 
61     virtual void OnStreamChanged(int32_t width, int32_t height, double frameRate) = 0;
62 
63     virtual void OnNeedInputData(uint32_t index, std::shared_ptr<OhosBufferAdapter> buffer) = 0;
64 
65     virtual void OnNeedOutputData(uint32_t index, std::shared_ptr<BufferInfoAdapter> info, BufferFlag flag) = 0;
66 };
67 
68 class MediaCodecDecoderAdapter {
69 public:
70     MediaCodecDecoderAdapter() = default;
71 
72     virtual ~MediaCodecDecoderAdapter() = default;
73 
74     virtual DecoderAdapterCode CreateVideoDecoderByMime(const std::string& mimetype) = 0;
75 
76     virtual DecoderAdapterCode CreateVideoDecoderByName(const std::string& name) = 0;
77 
78     virtual DecoderAdapterCode ConfigureDecoder(const std::shared_ptr<DecoderFormatAdapter> format) = 0;
79 
80     virtual DecoderAdapterCode SetParameterDecoder(const std::shared_ptr<DecoderFormatAdapter> format) = 0;
81 
82     virtual DecoderAdapterCode SetOutputSurface(void* window) = 0;
83 
84     virtual DecoderAdapterCode PrepareDecoder() = 0;
85 
86     virtual DecoderAdapterCode StartDecoder() = 0;
87 
88     virtual DecoderAdapterCode StopDecoder() = 0;
89 
90     virtual DecoderAdapterCode FlushDecoder() = 0;
91 
92     virtual DecoderAdapterCode ResetDecoder() = 0;
93 
94     virtual DecoderAdapterCode ReleaseDecoder() = 0;
95 
96     virtual DecoderAdapterCode QueueInputBufferDec(
97         uint32_t index, int64_t presentationTimeUs, int32_t size, int32_t offset, BufferFlag flag) = 0;
98 
99     virtual DecoderAdapterCode GetOutputFormatDec(std::shared_ptr<DecoderFormatAdapter> format) = 0;
100 
101     virtual DecoderAdapterCode ReleaseOutputBufferDec(uint32_t index, bool isRender) = 0;
102 
103     virtual DecoderAdapterCode SetCallbackDec(const std::shared_ptr<DecoderCallbackAdapter> callback) = 0;
104 
105     virtual DecoderAdapterCode SetDecryptionConfig(void *session, bool isSecure) = 0;
106 
107     virtual DecoderAdapterCode SetAVCencInfo(uint32_t index, const std::shared_ptr<AudioCencInfoAdapter> cencInfo) = 0;
108 };
109 
110 } // namespace OHOS::NWeb
111 
112 #endif // MEDIA_CODEC_DECODER_ADAPTER_H
113