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 CODEC_SERVICE_STUB_H 17 #define CODEC_SERVICE_STUB_H 18 19 #include <map> 20 #include <shared_mutex> 21 #include "avcodec_death_recipient.h" 22 #include "codec_server.h" 23 #include "i_standard_codec_listener.h" 24 #include "i_standard_codec_service.h" 25 #include "nocopyable.h" 26 27 namespace OHOS { 28 namespace MediaAVCodec { 29 class CodecServiceStub : public IRemoteStub<IStandardCodecService>, public NoCopyable { 30 public: 31 static sptr<CodecServiceStub> Create(); 32 virtual ~CodecServiceStub(); 33 34 int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 35 int32_t SetListenerObject(const sptr<IRemoteObject> &object) override; 36 37 int32_t Init(AVCodecType type, bool isMimeType, const std::string &name, Meta &callerInfo) override; 38 int32_t Configure(const Format &format) override; 39 int32_t Prepare() override; 40 int32_t Start() override; 41 int32_t Stop() override; 42 int32_t Flush() override; 43 int32_t Reset() override; 44 int32_t Release() override; 45 int32_t NotifyEos() override; 46 sptr<Surface> CreateInputSurface() override; 47 int32_t SetOutputSurface(sptr<Surface> surface) override; 48 int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override; 49 int32_t QueueInputBuffer(uint32_t index) override; 50 int32_t QueueInputParameter(uint32_t index) override; 51 int32_t GetOutputFormat(Format &format) override; 52 int32_t ReleaseOutputBuffer(uint32_t index, bool render) override; 53 int32_t RenderOutputBufferAtTime(uint32_t index, int64_t renderTimestampNs) override; 54 int32_t SetParameter(const Format &format) override; 55 int32_t GetInputFormat(Format &format) override; 56 57 int32_t DestroyStub() override; 58 #ifdef SUPPORT_DRM 59 int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession, 60 const bool svpFlag) override; 61 #endif 62 int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override; 63 int32_t SetCustomBuffer(std::shared_ptr<AVBuffer> buffer) override; 64 65 private: 66 CodecServiceStub(); 67 int32_t InitStub(); 68 int32_t SetListenerObject(MessageParcel &data, MessageParcel &reply); 69 int32_t Init(MessageParcel &data, MessageParcel &reply); 70 int32_t Configure(MessageParcel &data, MessageParcel &reply); 71 int32_t Prepare(MessageParcel &data, MessageParcel &reply); 72 int32_t Start(MessageParcel &data, MessageParcel &reply); 73 int32_t Stop(MessageParcel &data, MessageParcel &reply); 74 int32_t Flush(MessageParcel &data, MessageParcel &reply); 75 int32_t Reset(MessageParcel &data, MessageParcel &reply); 76 int32_t Release(MessageParcel &data, MessageParcel &reply); 77 int32_t NotifyEos(MessageParcel &data, MessageParcel &reply); 78 int32_t CreateInputSurface(MessageParcel &data, MessageParcel &reply); 79 int32_t SetOutputSurface(MessageParcel &data, MessageParcel &reply); 80 int32_t QueueInputBuffer(MessageParcel &data, MessageParcel &reply); 81 int32_t GetOutputFormat(MessageParcel &data, MessageParcel &reply); 82 int32_t ReleaseOutputBuffer(MessageParcel &data, MessageParcel &reply); 83 int32_t RenderOutputBufferAtTime(MessageParcel &data, MessageParcel &reply); 84 int32_t SetParameter(MessageParcel &data, MessageParcel &reply); 85 int32_t GetInputFormat(MessageParcel &data, MessageParcel &reply); 86 int32_t DestroyStub(MessageParcel &data, MessageParcel &reply); 87 #ifdef SUPPORT_DRM 88 int32_t SetDecryptConfig(MessageParcel &data, MessageParcel &reply); 89 #endif 90 int32_t SetCustomBuffer(MessageParcel &data, MessageParcel &reply); 91 int32_t InnerRelease(); 92 93 std::shared_ptr<ICodecService> codecServer_ = nullptr; 94 std::shared_mutex mutex_; 95 sptr<IStandardCodecListener> listener_ = nullptr; 96 }; 97 } // namespace MediaAVCodec 98 } // namespace OHOS 99 #endif // CODEC_SERVICE_STUB_H 100