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