• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RECORDER_SERVICE_STUB_H
17 #define RECORDER_SERVICE_STUB_H
18 
19 #include <map>
20 #include <set>
21 #include "i_standard_recorder_service.h"
22 #include "i_standard_recorder_listener.h"
23 #include "media_death_recipient.h"
24 #include "recorder_server.h"
25 #include "nocopyable.h"
26 #include "monitor_server_object.h"
27 
28 namespace OHOS {
29 namespace Media {
30 class RecorderServiceStub : public IRemoteStub<IStandardRecorderService>,
31     public MonitorServerObject, public NoCopyable {
32 public:
33     static sptr<RecorderServiceStub> Create();
34     virtual ~RecorderServiceStub();
35 
36     int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
37     using RecorderStubFunc = int32_t(RecorderServiceStub::*)(MessageParcel &data, MessageParcel &reply);
38     int32_t SetListenerObject(const sptr<IRemoteObject> &object) override;
39     int32_t SetVideoSource(VideoSourceType source, int32_t &sourceId) override;
40     int32_t SetVideoEncoder(int32_t sourceId, VideoCodecFormat encoder) override;
41     int32_t SetVideoSize(int32_t sourceId, int32_t width, int32_t height) override;
42     int32_t SetVideoFrameRate(int32_t sourceId, int32_t frameRate) override;
43     int32_t SetVideoEncodingBitRate(int32_t sourceId, int32_t rate) override;
44     int32_t SetCaptureRate(int32_t sourceId, double fps) override;
45     sptr<OHOS::Surface> GetSurface(int32_t sourceId) override;
46     int32_t SetAudioSource(AudioSourceType source, int32_t &sourceId) override;
47     int32_t SetAudioEncoder(int32_t sourceId, AudioCodecFormat encoder) override;
48     int32_t SetAudioSampleRate(int32_t sourceId, int32_t rate) override;
49     int32_t SetAudioChannels(int32_t sourceId, int32_t num) override;
50     int32_t SetAudioEncodingBitRate(int32_t sourceId, int32_t bitRate) override;
51     int32_t SetDataSource(DataSourceType dataType, int32_t &sourceId) override;
52     int32_t SetMaxDuration(int32_t duration) override;
53     int32_t SetOutputFormat(OutputFormatType format) override;
54     int32_t SetOutputFile(int32_t fd) override;
55     int32_t SetNextOutputFile(int32_t fd) override;
56     int32_t SetMaxFileSize(int64_t size) override;
57     int32_t SetLocation(float latitude, float longitude) override;
58     int32_t SetOrientationHint(int32_t rotation) override;
59     int32_t Prepare() override;
60     int32_t Start() override;
61     int32_t Pause() override;
62     int32_t Resume() override;
63     int32_t Stop(bool block) override;
64     int32_t Reset() override;
65     int32_t Release() override;
66     int32_t SetFileSplitDuration(FileSplitType type, int64_t timestamp, uint32_t duration) override;
67     int32_t DestroyStub() override;
68     int32_t DumpInfo(int32_t fd);
69 
70     // MonitorServerObject override
71     int32_t DoIpcAbnormality() override;
72     int32_t DoIpcRecovery(bool fromMonitor) override;
73 
74 private:
75     RecorderServiceStub();
76     int32_t Init();
77     int32_t SetListenerObject(MessageParcel &data, MessageParcel &reply);
78     int32_t SetVideoSource(MessageParcel &data, MessageParcel &reply);
79     int32_t SetVideoEncoder(MessageParcel &data, MessageParcel &reply);
80     int32_t SetVideoSize(MessageParcel &data, MessageParcel &reply);
81     int32_t SetVideoFrameRate(MessageParcel &data, MessageParcel &reply);
82     int32_t SetVideoEncodingBitRate(MessageParcel &data, MessageParcel &reply);
83     int32_t SetCaptureRate(MessageParcel &data, MessageParcel &reply);
84     int32_t GetSurface(MessageParcel &data, MessageParcel &reply);
85     int32_t SetAudioSource(MessageParcel &data, MessageParcel &reply);
86     int32_t SetAudioEncoder(MessageParcel &data, MessageParcel &reply);
87     int32_t SetAudioSampleRate(MessageParcel &data, MessageParcel &reply);
88     int32_t SetAudioChannels(MessageParcel &data, MessageParcel &reply);
89     int32_t SetAudioEncodingBitRate(MessageParcel &data, MessageParcel &reply);
90     int32_t SetDataSource(MessageParcel &data, MessageParcel &reply);
91     int32_t SetMaxDuration(MessageParcel &data, MessageParcel &reply);
92     int32_t SetOutputFormat(MessageParcel &data, MessageParcel &reply);
93     int32_t SetOutputFile(MessageParcel &data, MessageParcel &reply);
94     int32_t SetNextOutputFile(MessageParcel &data, MessageParcel &reply);
95     int32_t SetMaxFileSize(MessageParcel &data, MessageParcel &reply);
96     int32_t SetLocation(MessageParcel &data, MessageParcel &reply);
97     int32_t SetOrientationHint(MessageParcel &data, MessageParcel &reply);
98     int32_t Prepare(MessageParcel &data, MessageParcel &reply);
99     int32_t Start(MessageParcel &data, MessageParcel &reply);
100     int32_t Pause(MessageParcel &data, MessageParcel &reply);
101     int32_t Resume(MessageParcel &data, MessageParcel &reply);
102     int32_t Stop(MessageParcel &data, MessageParcel &reply);
103     int32_t Reset(MessageParcel &data, MessageParcel &reply);
104     int32_t Release(MessageParcel &data, MessageParcel &reply);
105     int32_t SetFileSplitDuration(MessageParcel &data, MessageParcel &reply);
106     int32_t DestroyStub(MessageParcel &data, MessageParcel &reply);
107 
108     std::shared_ptr<IRecorderService> recorderServer_ = nullptr;
109     std::map<uint32_t, RecorderStubFunc> recFuncs_;
110     std::mutex mutex_;
111     int32_t pid_;
112     bool needAudioPermissionCheck = false;
113     const std::set<uint32_t> AUDIO_REQUEST = {SET_AUDIO_SOURCE, SET_AUDIO_ENCODER, SET_AUDIO_ENCODER,
114         SET_AUDIO_CHANNELS, SET_AUDIO_ENCODING_BIT_RATE};
115     const std::set<uint32_t> COMMON_REQUEST = {SET_LISTENER_OBJ, SET_DATA_SOURCE, SET_MAX_DURATION,
116         SET_OUTPUT_FORMAT, SET_OUTPUT_FILE, SET_NEXT_OUTPUT_FILE, SET_MAX_FILE_SIZE, SET_LOCATION, SET_ORIENTATION_HINT,
117         PREPARE, START, PAUSE, RESUME, STOP, RESET, RELEASE, SET_FILE_SPLIT_DURATION, DESTROY};
118 };
119 } // namespace Media
120 } // namespace OHOS
121 #endif // RECORDER_SERVICE_STUB_H
122