1 /*
2  * Copyright (C) 2024 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 TRANSCODER_SERVICE_STUB_H
17 #define TRANSCODER_SERVICE_STUB_H
18 
19 #include <map>
20 #include <set>
21 #include "i_standard_transcoder_service.h"
22 #include "i_standard_transcoder_listener.h"
23 #include "media_death_recipient.h"
24 #include "transcoder_server.h"
25 #include "nocopyable.h"
26 #include "monitor_server_object.h"
27 
28 namespace OHOS {
29 namespace Media {
30 class TransCoderServiceStub : public IRemoteStub<IStandardTransCoderService>,
31     public MonitorServerObject, public NoCopyable {
32 public:
33     static sptr<TransCoderServiceStub> Create();
34     virtual ~TransCoderServiceStub();
35 
36     int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
37     using TransCoderStubFunc = int32_t(TransCoderServiceStub::*)(MessageParcel &data, MessageParcel &reply);
38     int32_t SetListenerObject(const sptr<IRemoteObject> &object) override;
39     int32_t SetVideoEncoder(VideoCodecFormat encoder) override;
40     int32_t SetVideoSize(int32_t width, int32_t height) override;
41     int32_t SetVideoEncodingBitRate(int32_t rate) override;
42     int32_t SetAudioEncoder(AudioCodecFormat encoder) override;
43     int32_t SetAudioEncodingBitRate(int32_t bitRate) override;
44     int32_t SetOutputFormat(OutputFormatType format) override;
45     int32_t SetInputFile(int32_t fd, int64_t offset, int64_t size) override;
46     int32_t SetOutputFile(int32_t fd) override;
47     int32_t Prepare() override;
48     int32_t Start() override;
49     int32_t Pause() override;
50     int32_t Resume() override;
51     int32_t Cancel() override;
52     int32_t Release() override;
53     int32_t DumpInfo(int32_t fd);
54     int32_t DestroyStub() override;
55 
56     // MonitorServerObject override
57     int32_t DoIpcAbnormality() override;
58     int32_t DoIpcRecovery(bool fromMonitor) override;
59 
60 private:
61     TransCoderServiceStub();
62     int32_t Init();
63     int32_t SetListenerObject(MessageParcel &data, MessageParcel &reply);
64     int32_t SetVideoEncoder(MessageParcel &data, MessageParcel &reply);
65     int32_t SetVideoSize(MessageParcel &data, MessageParcel &reply);
66     int32_t SetVideoEncodingBitRate(MessageParcel &data, MessageParcel &reply);
67     int32_t SetAudioEncoder(MessageParcel &data, MessageParcel &reply);
68     int32_t SetAudioEncodingBitRate(MessageParcel &data, MessageParcel &reply);
69     int32_t SetOutputFormat(MessageParcel &data, MessageParcel &reply);
70     int32_t SetInputFileUrl(MessageParcel &data, MessageParcel &reply);
71     int32_t SetInputFileFd(MessageParcel &data, MessageParcel &reply);
72     int32_t SetOutputFile(MessageParcel &data, MessageParcel &reply);
73     int32_t Prepare(MessageParcel &data, MessageParcel &reply);
74     int32_t Start(MessageParcel &data, MessageParcel &reply);
75     int32_t Pause(MessageParcel &data, MessageParcel &reply);
76     int32_t Resume(MessageParcel &data, MessageParcel &reply);
77     int32_t Cancel(MessageParcel &data, MessageParcel &reply);
78     int32_t Release(MessageParcel &data, MessageParcel &reply);
79     int32_t DestroyStub(MessageParcel &data, MessageParcel &reply);
80 
81     std::shared_ptr<ITransCoderService> transCoderServer_ = nullptr;
82     std::map<uint32_t, TransCoderStubFunc> recFuncs_;
83     std::mutex mutex_;
84     int32_t pid_ = -1;
85 };
86 } // namespace Media
87 } // namespace OHOS
88 #endif // TRANSCODER_SERVICE_STUB_H
89