1 /* 2 * Copyright (C) 2021 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 AVCODEC_SERVICE_STUB_H 17 #define AVCODEC_SERVICE_STUB_H 18 19 #include <map> 20 #include "i_standard_avcodec_listener.h" 21 #include "i_standard_avcodec_service.h" 22 #include "avcodec_server.h" 23 #include "media_death_recipient.h" 24 #include "nocopyable.h" 25 26 namespace OHOS { 27 namespace Media { 28 class AVCodecServiceStub : public IRemoteStub<IStandardAVCodecService>, public NoCopyable { 29 public: 30 static sptr<AVCodecServiceStub> Create(); 31 virtual ~AVCodecServiceStub(); 32 33 int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 34 using AVCodecStubFunc = int32_t(AVCodecServiceStub::*)(MessageParcel &data, MessageParcel &reply); 35 int32_t SetListenerObject(const sptr<IRemoteObject> &object) override; 36 int32_t InitParameter(AVCodecType type, bool isMimeType, const std::string &name) override; 37 int32_t Configure(const Format &format) override; 38 int32_t Prepare() override; 39 int32_t Start() override; 40 int32_t Stop() override; 41 int32_t Flush() override; 42 int32_t Reset() override; 43 int32_t Release() override; 44 sptr<OHOS::Surface> CreateInputSurface() override; 45 int32_t SetOutputSurface(sptr<OHOS::Surface> surface) override; 46 std::shared_ptr<AVSharedMemory> GetInputBuffer(uint32_t index) override; 47 int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override; 48 std::shared_ptr<AVSharedMemory> GetOutputBuffer(uint32_t index) override; 49 int32_t GetOutputFormat(Format &format) override; 50 std::shared_ptr<AudioCaps> GetAudioCaps() override; 51 std::shared_ptr<VideoCaps> GetVideoCaps() override; 52 int32_t ReleaseOutputBuffer(uint32_t index, bool render) override; 53 int32_t SetParameter(const Format &format) override; 54 int32_t DestroyStub() override; 55 56 private: 57 AVCodecServiceStub(); 58 int32_t Init(); 59 int32_t SetListenerObject(MessageParcel &data, MessageParcel &reply); 60 int32_t InitParameter(MessageParcel &data, MessageParcel &reply); 61 int32_t Configure(MessageParcel &data, MessageParcel &reply); 62 int32_t Prepare(MessageParcel &data, MessageParcel &reply); 63 int32_t Start(MessageParcel &data, MessageParcel &reply); 64 int32_t Stop(MessageParcel &data, MessageParcel &reply); 65 int32_t Flush(MessageParcel &data, MessageParcel &reply); 66 int32_t Reset(MessageParcel &data, MessageParcel &reply); 67 int32_t Release(MessageParcel &data, MessageParcel &reply); 68 int32_t CreateInputSurface(MessageParcel &data, MessageParcel &reply); 69 int32_t SetOutputSurface(MessageParcel &data, MessageParcel &reply); 70 int32_t GetInputBuffer(MessageParcel &data, MessageParcel &reply); 71 int32_t QueueInputBuffer(MessageParcel &data, MessageParcel &reply); 72 int32_t GetOutputBuffer(MessageParcel &data, MessageParcel &reply); 73 int32_t GetOutputFormat(MessageParcel &data, MessageParcel &reply); 74 int32_t GetAudioCaps(MessageParcel &data, MessageParcel &reply); 75 int32_t GetVideoCaps(MessageParcel &data, MessageParcel &reply); 76 int32_t ReleaseOutputBuffer(MessageParcel &data, MessageParcel &reply); 77 int32_t SetParameter(MessageParcel &data, MessageParcel &reply); 78 int32_t DestroyStub(MessageParcel &data, MessageParcel &reply); 79 80 std::shared_ptr<IAVCodecService> codecServer_ = nullptr; 81 std::map<uint32_t, AVCodecStubFunc> recFuncs_; 82 std::mutex mutex_; 83 84 class AVCodecBufferCache; 85 std::unique_ptr<AVCodecBufferCache> inputBufferCache_; 86 std::unique_ptr<AVCodecBufferCache> outputBufferCache_; 87 }; 88 } // namespace Media 89 } // namespace OHOS 90 #endif // AVCODEC_SERVICE_STUB_H 91