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