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 #include "recorder_service_stub.h"
17 #include <unistd.h>
18 #include "recorder_listener_proxy.h"
19 #include "media_server_manager.h"
20 #include "media_log.h"
21 #include "media_errors.h"
22 #include "ipc_skeleton.h"
23 #include "media_permission.h"
24 #include "accesstoken_kit.h"
25 #include "media_dfx.h"
26
27 namespace {
28 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_RECORDER, "RecorderServiceStub"};
29 }
30
31 namespace OHOS {
32 namespace Media {
Create()33 sptr<RecorderServiceStub> RecorderServiceStub::Create()
34 {
35 sptr<RecorderServiceStub> recorderStub = new(std::nothrow) RecorderServiceStub();
36 CHECK_AND_RETURN_RET_LOG(recorderStub != nullptr, nullptr, "failed to new RecorderServiceStub");
37
38 int32_t ret = recorderStub->Init();
39 CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, nullptr, "failed to recorder stub init");
40 StatisticEventWriteBundleName("create", "RecorderServiceStub");
41 return recorderStub;
42 }
43
RecorderServiceStub()44 RecorderServiceStub::RecorderServiceStub()
45 {
46 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
47 }
48
~RecorderServiceStub()49 RecorderServiceStub::~RecorderServiceStub()
50 {
51 (void)CancellationMonitor(pid_);
52 needAudioPermissionCheck = false;
53 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
54 }
55
Init()56 int32_t RecorderServiceStub::Init()
57 {
58 recorderServer_ = RecorderServer::Create();
59 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "failed to create RecorderServer");
60 FillRecFuncPart1();
61 FillRecFuncPart2();
62 pid_ = IPCSkeleton::GetCallingPid();
63 (void)RegisterMonitor(pid_);
64 return MSERR_OK;
65 }
66
FillRecFuncPart1()67 void RecorderServiceStub::FillRecFuncPart1()
68 {
69 recFuncs_[SET_LISTENER_OBJ] =
70 [this](MessageParcel &data, MessageParcel &reply) { return SetListenerObject(data, reply); };
71 recFuncs_[SET_VIDEO_SOURCE] =
72 [this](MessageParcel &data, MessageParcel &reply) { return SetVideoSource(data, reply); };
73 recFuncs_[SET_VIDEO_ENCODER] =
74 [this](MessageParcel &data, MessageParcel &reply) { return SetVideoEncoder(data, reply); };
75 recFuncs_[SET_VIDEO_SIZE] =
76 [this](MessageParcel &data, MessageParcel &reply) { return SetVideoSize(data, reply); };
77 recFuncs_[SET_VIDEO_FARAME_RATE] =
78 [this](MessageParcel &data, MessageParcel &reply) { return SetVideoFrameRate(data, reply); };
79 recFuncs_[SET_VIDEO_ENCODING_BIT_RATE] =
80 [this](MessageParcel &data, MessageParcel &reply) { return SetVideoEncodingBitRate(data, reply); };
81 recFuncs_[GET_SURFACE] =
82 [this](MessageParcel &data, MessageParcel &reply) { return GetSurface(data, reply); };
83 recFuncs_[SET_AUDIO_SOURCE] =
84 [this](MessageParcel &data, MessageParcel &reply) { return SetAudioSource(data, reply); };
85 recFuncs_[SET_AUDIO_ENCODER] =
86 [this](MessageParcel &data, MessageParcel &reply) { return SetAudioEncoder(data, reply); };
87 recFuncs_[SET_AUDIO_SAMPLE_RATE] =
88 [this](MessageParcel &data, MessageParcel &reply) { return SetAudioSampleRate(data, reply); };
89 recFuncs_[SET_AUDIO_CHANNELS] =
90 [this](MessageParcel &data, MessageParcel &reply) { return SetAudioChannels(data, reply); };
91 recFuncs_[SET_AUDIO_ENCODING_BIT_RATE] =
92 [this](MessageParcel &data, MessageParcel &reply) { return SetAudioEncodingBitRate(data, reply); };
93 recFuncs_[SET_DATA_SOURCE] =
94 [this](MessageParcel &data, MessageParcel &reply) { return SetDataSource(data, reply); };
95 recFuncs_[SET_MAX_DURATION] =
96 [this](MessageParcel &data, MessageParcel &reply) { return SetMaxDuration(data, reply); };
97 recFuncs_[SET_OUTPUT_FORMAT] =
98 [this](MessageParcel &data, MessageParcel &reply) { return SetOutputFormat(data, reply); };
99 recFuncs_[SET_OUTPUT_FILE] =
100 [this](MessageParcel &data, MessageParcel &reply) { return SetOutputFile(data, reply); };
101 recFuncs_[SET_FILE_GENERATION_MODE] =
102 [this](MessageParcel &data, MessageParcel &reply) { return SetFileGenerationMode(data, reply); };
103 recFuncs_[SET_LOCATION] =
104 [this](MessageParcel &data, MessageParcel &reply) { return SetLocation(data, reply); };
105 recFuncs_[SET_ORIENTATION_HINT] =
106 [this](MessageParcel &data, MessageParcel &reply) { return SetOrientationHint(data, reply); };
107 recFuncs_[SET_USER_CUSTOM_INFO] =
108 [this](MessageParcel &data, MessageParcel &reply) { return SetUserCustomInfo(data, reply); };
109 recFuncs_[SET_GENRE] =
110 [this](MessageParcel &data, MessageParcel &reply) { return SetGenre(data, reply); };
111 recFuncs_[PREPARE] =
112 [this](MessageParcel &data, MessageParcel &reply) { return Prepare(data, reply); };
113 }
114
FillRecFuncPart2()115 void RecorderServiceStub::FillRecFuncPart2()
116 {
117 recFuncs_[START] =
118 [this](MessageParcel &data, MessageParcel &reply) { return Start(data, reply); };
119 recFuncs_[PAUSE] =
120 [this](MessageParcel &data, MessageParcel &reply) { return Pause(data, reply); };
121 recFuncs_[RESUME] =
122 [this](MessageParcel &data, MessageParcel &reply) { return Resume(data, reply); };
123 recFuncs_[STOP] =
124 [this](MessageParcel &data, MessageParcel &reply) { return Stop(data, reply); };
125 recFuncs_[RESET] =
126 [this](MessageParcel &data, MessageParcel &reply) { return Reset(data, reply); };
127 recFuncs_[RELEASE] =
128 [this](MessageParcel &data, MessageParcel &reply) { return Release(data, reply); };
129 recFuncs_[DESTROY] =
130 [this](MessageParcel &data, MessageParcel &reply) { return DestroyStub(data, reply); };
131 recFuncs_[GET_AV_RECORDER_CONFIG] =
132 [this](MessageParcel &data, MessageParcel &reply) { return GetAVRecorderConfig(data, reply); };
133 recFuncs_[GET_LOCATION] =
134 [this](MessageParcel &data, MessageParcel &reply) { return GetLocation(data, reply); };
135 recFuncs_[SET_VIDEO_IS_HDR] =
136 [this](MessageParcel &data, MessageParcel &reply) { return SetVideoIsHdr(data, reply); };
137 recFuncs_[SET_VIDEO_ENABLE_TEMPORAL_SCALE] =
138 [this](MessageParcel &data, MessageParcel &reply) { return SetVideoEnableTemporalScale(data, reply); };
139 recFuncs_[GET_AUDIO_CAPTURER_CHANGE_INFO] =
140 [this](MessageParcel &data, MessageParcel &reply) { return GetCurrentCapturerChangeInfo(data, reply); };
141 recFuncs_[GET_AVAILABLE_ENCODER] =
142 [this](MessageParcel &data, MessageParcel &reply) { return GetAvailableEncoder(data, reply); };
143 recFuncs_[GET_MAX_AMPLITUDE] =
144 [this](MessageParcel &data, MessageParcel &reply) { return GetMaxAmplitude(data, reply); };
145 recFuncs_[SET_META_CONFIGS] =
146 [this](MessageParcel &data, MessageParcel &reply) { return SetMetaConfigs(data, reply); };
147 recFuncs_[SET_META_SOURCE] =
148 [this](MessageParcel &data, MessageParcel &reply) { return SetMetaSource(data, reply); };
149 recFuncs_[SET_META_MIME_TYPE] =
150 [this](MessageParcel &data, MessageParcel &reply) { return SetMetaMimeType(data, reply); };
151 recFuncs_[SET_META_TIMED_KEY] =
152 [this](MessageParcel &data, MessageParcel &reply) { return SetMetaTimedKey(data, reply); };
153 recFuncs_[SET_META_TRACK_SRC_MIME_TYPE] =
154 [this](MessageParcel &data, MessageParcel &reply) { return SetMetaSourceTrackMime(data, reply); };
155 recFuncs_[GET_META_SURFACE] =
156 [this](MessageParcel &data, MessageParcel &reply) { return GetMetaSurface(data, reply); };
157 recFuncs_[IS_WATERMARK_SUPPORTED] =
158 [this](MessageParcel &data, MessageParcel &reply) { return IsWatermarkSupported(data, reply); };
159 recFuncs_[SET_WATERMARK] =
160 [this](MessageParcel &data, MessageParcel &reply) { return SetWatermark(data, reply); };
161 }
162
DestroyStub()163 int32_t RecorderServiceStub::DestroyStub()
164 {
165 recorderServer_ = nullptr;
166 MediaServerManager::GetInstance().DestroyStubObject(MediaServerManager::RECORDER, AsObject());
167 return MSERR_OK;
168 }
169
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)170 int RecorderServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
171 MessageOption &option)
172 {
173 MEDIA_LOGI("Stub: OnRemoteRequest of code: %{public}d is received", code);
174 int32_t permissionResult;
175
176 auto remoteDescriptor = data.ReadInterfaceToken();
177 CHECK_AND_RETURN_RET_LOG(RecorderServiceStub::GetDescriptor() == remoteDescriptor,
178 MSERR_INVALID_OPERATION, "Invalid descriptor");
179
180 {
181 if (code == SET_AUDIO_SOURCE) {
182 std::lock_guard<std::mutex> lock(stmutex_);
183 int32_t type = data.ReadInt32();
184 CHECK_AND_RETURN_RET_LOG(audioSourceType_ == AUDIO_SOURCE_INVALID,
185 MSERR_EXT_API9_OPERATE_NOT_PERMIT, "unsupport parameter or repeated operation");
186 audioSourceType_ = static_cast<AudioSourceType>(type);
187 }
188 }
189
190 if (AUDIO_REQUEST.count(code) != 0) {
191 permissionResult = CheckPermission();
192 needAudioPermissionCheck = true;
193 } else if (COMMON_REQUEST.count(code) != 0) {
194 if (needAudioPermissionCheck) {
195 permissionResult = CheckPermission();
196 } else {
197 // none audio request no need to check permission in recorder server
198 permissionResult = Security::AccessToken::PERMISSION_GRANTED;
199 }
200 } else {
201 // none audio request no need to check permission in recorder server
202 permissionResult = Security::AccessToken::PERMISSION_GRANTED;
203 }
204 CHECK_AND_RETURN_RET_LOG(permissionResult == Security::AccessToken::PERMISSION_GRANTED,
205 MSERR_EXT_API9_PERMISSION_DENIED, "user do not have the correct permission");
206
207 auto itFunc = recFuncs_.find(code);
208 if (itFunc != recFuncs_.end()) {
209 auto memberFunc = itFunc->second;
210 if (memberFunc != nullptr) {
211 std::lock_guard<std::mutex> lock(mutex_);
212 (void)IpcRecovery(false);
213 int32_t ret = memberFunc(data, reply);
214 if (ret != MSERR_OK) {
215 MEDIA_LOGE("calling memberFunc is failed.");
216 }
217 if (AUDIO_REQUEST.count(code) != 0 && ret != MSERR_OK) {
218 MEDIA_LOGE("audio memberFunc failed, reset permission check.");
219 }
220 return MSERR_OK;
221 }
222 }
223 MEDIA_LOGW("RecorderServiceStub: no member func supporting, applying default process");
224
225 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
226 }
227
SetListenerObject(const sptr<IRemoteObject> & object)228 int32_t RecorderServiceStub::SetListenerObject(const sptr<IRemoteObject> &object)
229 {
230 CHECK_AND_RETURN_RET_LOG(object != nullptr, MSERR_NO_MEMORY, "set listener object is nullptr");
231
232 sptr<IStandardRecorderListener> listener = iface_cast<IStandardRecorderListener>(object);
233 CHECK_AND_RETURN_RET_LOG(listener != nullptr, MSERR_NO_MEMORY, "failed to convert IStandardRecorderListener");
234
235 std::shared_ptr<RecorderCallback> callback = std::make_shared<RecorderListenerCallback>(listener);
236 CHECK_AND_RETURN_RET_LOG(callback != nullptr, MSERR_NO_MEMORY, "failed to new RecorderListenerCallback");
237
238 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
239 (void)recorderServer_->SetRecorderCallback(callback);
240 return MSERR_OK;
241 }
242
SetVideoSource(VideoSourceType source,int32_t & sourceId)243 int32_t RecorderServiceStub::SetVideoSource(VideoSourceType source, int32_t &sourceId)
244 {
245 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
246 return recorderServer_->SetVideoSource(source, sourceId);
247 }
248
SetVideoEncoder(int32_t sourceId,VideoCodecFormat encoder)249 int32_t RecorderServiceStub::SetVideoEncoder(int32_t sourceId, VideoCodecFormat encoder)
250 {
251 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
252 return recorderServer_->SetVideoEncoder(sourceId, encoder);
253 }
254
SetVideoSize(int32_t sourceId,int32_t width,int32_t height)255 int32_t RecorderServiceStub::SetVideoSize(int32_t sourceId, int32_t width, int32_t height)
256 {
257 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
258 return recorderServer_->SetVideoSize(sourceId, width, height);
259 }
260
SetVideoFrameRate(int32_t sourceId,int32_t frameRate)261 int32_t RecorderServiceStub::SetVideoFrameRate(int32_t sourceId, int32_t frameRate)
262 {
263 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
264 return recorderServer_->SetVideoFrameRate(sourceId, frameRate);
265 }
266
SetVideoEncodingBitRate(int32_t sourceId,int32_t rate)267 int32_t RecorderServiceStub::SetVideoEncodingBitRate(int32_t sourceId, int32_t rate)
268 {
269 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
270 return recorderServer_->SetVideoEncodingBitRate(sourceId, rate);
271 }
272
SetVideoIsHdr(int32_t sourceId,bool isHdr)273 int32_t RecorderServiceStub::SetVideoIsHdr(int32_t sourceId, bool isHdr)
274 {
275 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
276 return recorderServer_->SetVideoIsHdr(sourceId, isHdr);
277 }
278
SetVideoEnableTemporalScale(int32_t sourceId,bool enableTemporalScale)279 int32_t RecorderServiceStub::SetVideoEnableTemporalScale(int32_t sourceId, bool enableTemporalScale)
280 {
281 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
282 return recorderServer_->SetVideoEnableTemporalScale(sourceId, enableTemporalScale);
283 }
284
SetMetaConfigs(int32_t sourceId)285 int32_t RecorderServiceStub::SetMetaConfigs(int32_t sourceId)
286 {
287 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
288 return recorderServer_->SetMetaConfigs(sourceId);
289 }
290
SetMetaSource(MetaSourceType source,int32_t & sourceId)291 int32_t RecorderServiceStub::SetMetaSource(MetaSourceType source, int32_t &sourceId)
292 {
293 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
294 return recorderServer_->SetMetaSource(source, sourceId);
295 }
296
SetMetaMimeType(int32_t sourceId,const std::string_view & type)297 int32_t RecorderServiceStub::SetMetaMimeType(int32_t sourceId, const std::string_view &type)
298 {
299 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
300 return recorderServer_->SetMetaMimeType(sourceId, type);
301 }
302
SetMetaTimedKey(int32_t sourceId,const std::string_view & timedKey)303 int32_t RecorderServiceStub::SetMetaTimedKey(int32_t sourceId, const std::string_view &timedKey)
304 {
305 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
306 return recorderServer_->SetMetaTimedKey(sourceId, timedKey);
307 }
308
SetMetaSourceTrackMime(int32_t sourceId,const std::string_view & srcTrackMime)309 int32_t RecorderServiceStub::SetMetaSourceTrackMime(int32_t sourceId, const std::string_view &srcTrackMime)
310 {
311 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
312 return recorderServer_->SetMetaSourceTrackMime(sourceId, srcTrackMime);
313 }
314
GetSurface(int32_t sourceId)315 sptr<OHOS::Surface> RecorderServiceStub::GetSurface(int32_t sourceId)
316 {
317 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, nullptr, "recorder server is nullptr");
318 return recorderServer_->GetSurface(sourceId);
319 }
320
GetMetaSurface(int32_t sourceId)321 sptr<OHOS::Surface> RecorderServiceStub::GetMetaSurface(int32_t sourceId)
322 {
323 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, nullptr, "recorder server is nullptr");
324 return recorderServer_->GetMetaSurface(sourceId);
325 }
326
SetAudioSource(AudioSourceType source,int32_t & sourceId)327 int32_t RecorderServiceStub::SetAudioSource(AudioSourceType source, int32_t &sourceId)
328 {
329 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
330 return recorderServer_->SetAudioSource(source, sourceId);
331 }
332
SetAudioEncoder(int32_t sourceId,AudioCodecFormat encoder)333 int32_t RecorderServiceStub::SetAudioEncoder(int32_t sourceId, AudioCodecFormat encoder)
334 {
335 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
336 return recorderServer_->SetAudioEncoder(sourceId, encoder);
337 }
338
SetAudioSampleRate(int32_t sourceId,int32_t rate)339 int32_t RecorderServiceStub::SetAudioSampleRate(int32_t sourceId, int32_t rate)
340 {
341 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
342 return recorderServer_->SetAudioSampleRate(sourceId, rate);
343 }
344
SetAudioChannels(int32_t sourceId,int32_t num)345 int32_t RecorderServiceStub::SetAudioChannels(int32_t sourceId, int32_t num)
346 {
347 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
348 return recorderServer_->SetAudioChannels(sourceId, num);
349 }
350
SetAudioEncodingBitRate(int32_t sourceId,int32_t bitRate)351 int32_t RecorderServiceStub::SetAudioEncodingBitRate(int32_t sourceId, int32_t bitRate)
352 {
353 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
354 return recorderServer_->SetAudioEncodingBitRate(sourceId, bitRate);
355 }
356
SetDataSource(DataSourceType dataType,int32_t & sourceId)357 int32_t RecorderServiceStub::SetDataSource(DataSourceType dataType, int32_t &sourceId)
358 {
359 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
360 return recorderServer_->SetDataSource(dataType, sourceId);
361 }
362
SetUserCustomInfo(Meta & userCustomInfo)363 int32_t RecorderServiceStub::SetUserCustomInfo(Meta &userCustomInfo)
364 {
365 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
366 return recorderServer_->SetUserCustomInfo(userCustomInfo);
367 }
368
SetGenre(std::string & genre)369 int32_t RecorderServiceStub::SetGenre(std::string &genre)
370 {
371 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
372 return recorderServer_->SetGenre(genre);
373 }
374
SetMaxDuration(int32_t duration)375 int32_t RecorderServiceStub::SetMaxDuration(int32_t duration)
376 {
377 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
378 return recorderServer_->SetMaxDuration(duration);
379 }
380
SetOutputFormat(OutputFormatType format)381 int32_t RecorderServiceStub::SetOutputFormat(OutputFormatType format)
382 {
383 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
384 return recorderServer_->SetOutputFormat(format);
385 }
386
SetOutputFile(int32_t fd)387 int32_t RecorderServiceStub::SetOutputFile(int32_t fd)
388 {
389 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
390 return recorderServer_->SetOutputFile(fd);
391 }
392
SetFileGenerationMode(FileGenerationMode mode)393 int32_t RecorderServiceStub::SetFileGenerationMode(FileGenerationMode mode)
394 {
395 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
396 return recorderServer_->SetFileGenerationMode(mode);
397 }
398
SetLocation(float latitude,float longitude)399 int32_t RecorderServiceStub::SetLocation(float latitude, float longitude)
400 {
401 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
402 recorderServer_->SetLocation(latitude, longitude);
403 return MSERR_OK;
404 }
405
SetOrientationHint(int32_t rotation)406 int32_t RecorderServiceStub::SetOrientationHint(int32_t rotation)
407 {
408 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
409 recorderServer_->SetOrientationHint(rotation);
410 return MSERR_OK;
411 }
412
Prepare()413 int32_t RecorderServiceStub::Prepare()
414 {
415 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
416 return recorderServer_->Prepare();
417 }
418
Start()419 int32_t RecorderServiceStub::Start()
420 {
421 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
422 return recorderServer_->Start();
423 }
424
Pause()425 int32_t RecorderServiceStub::Pause()
426 {
427 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
428 return recorderServer_->Pause();
429 }
430
Resume()431 int32_t RecorderServiceStub::Resume()
432 {
433 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
434 return recorderServer_->Resume();
435 }
436
Stop(bool block)437 int32_t RecorderServiceStub::Stop(bool block)
438 {
439 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
440 return recorderServer_->Stop(block);
441 }
442
Reset()443 int32_t RecorderServiceStub::Reset()
444 {
445 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
446 return recorderServer_->Reset();
447 }
448
Release()449 int32_t RecorderServiceStub::Release()
450 {
451 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
452 return recorderServer_->Release();
453 }
454
DumpInfo(int32_t fd)455 int32_t RecorderServiceStub::DumpInfo(int32_t fd)
456 {
457 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
458 return std::static_pointer_cast<RecorderServer>(recorderServer_)->DumpInfo(fd);
459 }
460
GetAVRecorderConfig(ConfigMap & configMap)461 int32_t RecorderServiceStub::GetAVRecorderConfig(ConfigMap &configMap)
462 {
463 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
464 return recorderServer_->GetAVRecorderConfig(configMap);
465 }
466
GetLocation(Location & location)467 int32_t RecorderServiceStub::GetLocation(Location &location)
468 {
469 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
470 return recorderServer_->GetLocation(location);
471 }
472
GetCurrentCapturerChangeInfo(AudioRecorderChangeInfo & changeInfo)473 int32_t RecorderServiceStub::GetCurrentCapturerChangeInfo(AudioRecorderChangeInfo &changeInfo)
474 {
475 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
476 return recorderServer_->GetCurrentCapturerChangeInfo(changeInfo);
477 }
478
GetAvailableEncoder(std::vector<EncoderCapabilityData> & encoderInfo)479 int32_t RecorderServiceStub::GetAvailableEncoder(std::vector<EncoderCapabilityData> &encoderInfo)
480 {
481 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
482 return recorderServer_->GetAvailableEncoder(encoderInfo);
483 }
484
GetMaxAmplitude()485 int32_t RecorderServiceStub::GetMaxAmplitude()
486 {
487 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
488 return recorderServer_->GetMaxAmplitude();
489 }
490
IsWatermarkSupported(bool & isWatermarkSupported)491 int32_t RecorderServiceStub::IsWatermarkSupported(bool &isWatermarkSupported)
492 {
493 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
494 return recorderServer_->IsWatermarkSupported(isWatermarkSupported);
495 }
496
SetWatermark(std::shared_ptr<AVBuffer> & waterMarkBuffer)497 int32_t RecorderServiceStub::SetWatermark(std::shared_ptr<AVBuffer> &waterMarkBuffer)
498 {
499 CHECK_AND_RETURN_RET_LOG(recorderServer_ != nullptr, MSERR_NO_MEMORY, "recorder server is nullptr");
500 return recorderServer_->SetWatermark(waterMarkBuffer);
501 }
502
DoIpcAbnormality()503 int32_t RecorderServiceStub::DoIpcAbnormality()
504 {
505 MEDIA_LOGI("Enter DoIpcAbnormality.");
506 SetIpcAlarmedFlag();
507 return MSERR_OK;
508 }
509
DoIpcRecovery(bool fromMonitor)510 int32_t RecorderServiceStub::DoIpcRecovery(bool fromMonitor)
511 {
512 MEDIA_LOGI("Enter DoIpcRecovery %{public}d.", fromMonitor);
513 UnSetIpcAlarmedFlag();
514 return MSERR_OK;
515 }
516
SetListenerObject(MessageParcel & data,MessageParcel & reply)517 int32_t RecorderServiceStub::SetListenerObject(MessageParcel &data, MessageParcel &reply)
518 {
519 sptr<IRemoteObject> object = data.ReadRemoteObject();
520 reply.WriteInt32(SetListenerObject(object));
521 return MSERR_OK;
522 }
523
SetVideoSource(MessageParcel & data,MessageParcel & reply)524 int32_t RecorderServiceStub::SetVideoSource(MessageParcel &data, MessageParcel &reply)
525 {
526 int32_t source = data.ReadInt32();
527 VideoSourceType sourceType = static_cast<VideoSourceType>(source);
528 int32_t sourceId = 0;
529 int32_t ret = SetVideoSource(sourceType, sourceId);
530 reply.WriteInt32(sourceId);
531 reply.WriteInt32(ret);
532 return MSERR_OK;
533 }
534
SetVideoEncoder(MessageParcel & data,MessageParcel & reply)535 int32_t RecorderServiceStub::SetVideoEncoder(MessageParcel &data, MessageParcel &reply)
536 {
537 int32_t sourceId = data.ReadInt32();
538 int32_t encoder = data.ReadInt32();
539 VideoCodecFormat codecFormat = static_cast<VideoCodecFormat>(encoder);
540 reply.WriteInt32(SetVideoEncoder(sourceId, codecFormat));
541 return MSERR_OK;
542 }
543
SetVideoSize(MessageParcel & data,MessageParcel & reply)544 int32_t RecorderServiceStub::SetVideoSize(MessageParcel &data, MessageParcel &reply)
545 {
546 int32_t sourceId = data.ReadInt32();
547 int32_t width = data.ReadInt32();
548 int32_t height = data.ReadInt32();
549 reply.WriteInt32(SetVideoSize(sourceId, width, height));
550 return MSERR_OK;
551 }
552
SetVideoFrameRate(MessageParcel & data,MessageParcel & reply)553 int32_t RecorderServiceStub::SetVideoFrameRate(MessageParcel &data, MessageParcel &reply)
554 {
555 int32_t sourceId = data.ReadInt32();
556 int32_t frameRate = data.ReadInt32();
557 reply.WriteInt32(SetVideoFrameRate(sourceId, frameRate));
558 return MSERR_OK;
559 }
560
SetVideoEncodingBitRate(MessageParcel & data,MessageParcel & reply)561 int32_t RecorderServiceStub::SetVideoEncodingBitRate(MessageParcel &data, MessageParcel &reply)
562 {
563 int32_t sourceId = data.ReadInt32();
564 int32_t rate = data.ReadInt32();
565 reply.WriteInt32(SetVideoEncodingBitRate(sourceId, rate));
566 return MSERR_OK;
567 }
568
SetVideoIsHdr(MessageParcel & data,MessageParcel & reply)569 int32_t RecorderServiceStub::SetVideoIsHdr(MessageParcel &data, MessageParcel &reply)
570 {
571 int32_t sourceId = data.ReadInt32();
572 bool isHdr = data.ReadBool();
573 reply.WriteInt32(SetVideoIsHdr(sourceId, isHdr));
574 return MSERR_OK;
575 }
576
SetVideoEnableTemporalScale(MessageParcel & data,MessageParcel & reply)577 int32_t RecorderServiceStub::SetVideoEnableTemporalScale(MessageParcel &data, MessageParcel &reply)
578 {
579 int32_t sourceId = data.ReadInt32();
580 bool enableTemporalScale = data.ReadBool();
581 reply.WriteInt32(SetVideoEnableTemporalScale(sourceId, enableTemporalScale));
582 return MSERR_OK;
583 }
584
SetMetaConfigs(MessageParcel & data,MessageParcel & reply)585 int32_t RecorderServiceStub::SetMetaConfigs(MessageParcel &data, MessageParcel &reply)
586 {
587 int32_t sourceId = data.ReadInt32();
588 int32_t ret = SetMetaConfigs(sourceId);
589 reply.WriteInt32(ret);
590 return MSERR_OK;
591 }
592
SetMetaSource(MessageParcel & data,MessageParcel & reply)593 int32_t RecorderServiceStub::SetMetaSource(MessageParcel &data, MessageParcel &reply)
594 {
595 int32_t source = data.ReadInt32();
596 MetaSourceType sourceType = static_cast<MetaSourceType>(source);
597 int32_t sourceId = 0;
598 int32_t ret = SetMetaSource(sourceType, sourceId);
599 reply.WriteInt32(sourceId);
600 reply.WriteInt32(ret);
601 return MSERR_OK;
602 }
603
SetMetaMimeType(MessageParcel & data,MessageParcel & reply)604 int32_t RecorderServiceStub::SetMetaMimeType(MessageParcel &data, MessageParcel &reply)
605 {
606 int32_t sourceId = data.ReadInt32();
607 const char *mimetypeStr = data.ReadCString();
608 CHECK_AND_RETURN_RET_LOG(mimetypeStr != nullptr, MSERR_INVALID_OPERATION,
609 "data.ReadCString() is nullptr");
610 std::string_view mimetype(mimetypeStr);
611 reply.WriteInt32(SetMetaMimeType(sourceId, mimetype));
612 return MSERR_OK;
613 }
614
SetMetaTimedKey(MessageParcel & data,MessageParcel & reply)615 int32_t RecorderServiceStub::SetMetaTimedKey(MessageParcel &data, MessageParcel &reply)
616 {
617 int32_t sourceId = data.ReadInt32();
618 const char *mimetypeStr = data.ReadCString();
619 CHECK_AND_RETURN_RET_LOG(mimetypeStr != nullptr, MSERR_INVALID_OPERATION,
620 "data.ReadCString() is nullptr");
621 std::string_view timedKey(mimetypeStr);
622 reply.WriteInt32(SetMetaTimedKey(sourceId, timedKey));
623 return MSERR_OK;
624 }
625
SetMetaSourceTrackMime(MessageParcel & data,MessageParcel & reply)626 int32_t RecorderServiceStub::SetMetaSourceTrackMime(MessageParcel &data, MessageParcel &reply)
627 {
628 int32_t sourceId = data.ReadInt32();
629 const char *mimetypeStr = data.ReadCString();
630 CHECK_AND_RETURN_RET_LOG(mimetypeStr != nullptr, MSERR_INVALID_OPERATION,
631 "data.ReadCString() is nullptr");
632 std::string_view srcTrackMime(mimetypeStr);
633 reply.WriteInt32(SetMetaSourceTrackMime(sourceId, srcTrackMime));
634 return MSERR_OK;
635 }
636
GetSurface(MessageParcel & data,MessageParcel & reply)637 int32_t RecorderServiceStub::GetSurface(MessageParcel &data, MessageParcel &reply)
638 {
639 int32_t sourceId = data.ReadInt32();
640 sptr<OHOS::Surface> surface = GetSurface(sourceId);
641 if (surface != nullptr && surface->GetProducer() != nullptr) {
642 sptr<IRemoteObject> object = surface->GetProducer()->AsObject();
643 (void)reply.WriteRemoteObject(object);
644 }
645 return MSERR_OK;
646 }
647
GetMetaSurface(MessageParcel & data,MessageParcel & reply)648 int32_t RecorderServiceStub::GetMetaSurface(MessageParcel &data, MessageParcel &reply)
649 {
650 int32_t sourceId = data.ReadInt32();
651 sptr<OHOS::Surface> surface = GetMetaSurface(sourceId);
652 if (surface != nullptr && surface->GetProducer() != nullptr) {
653 sptr<IRemoteObject> object = surface->GetProducer()->AsObject();
654 (void)reply.WriteRemoteObject(object);
655 }
656 return MSERR_OK;
657 }
658
SetAudioSource(MessageParcel & data,MessageParcel & reply)659 int32_t RecorderServiceStub::SetAudioSource(MessageParcel &data, MessageParcel &reply)
660 {
661 int32_t sourceId = 0;
662 int32_t ret = SetAudioSource(audioSourceType_, sourceId);
663 reply.WriteInt32(sourceId);
664 reply.WriteInt32(ret);
665 return MSERR_OK;
666 }
667
SetAudioEncoder(MessageParcel & data,MessageParcel & reply)668 int32_t RecorderServiceStub::SetAudioEncoder(MessageParcel &data, MessageParcel &reply)
669 {
670 int32_t sourceId = data.ReadInt32();
671 int32_t format = data.ReadInt32();
672 AudioCodecFormat encoderFormat = static_cast<AudioCodecFormat>(format);
673 reply.WriteInt32(SetAudioEncoder(sourceId, encoderFormat));
674 return MSERR_OK;
675 }
676
SetAudioSampleRate(MessageParcel & data,MessageParcel & reply)677 int32_t RecorderServiceStub::SetAudioSampleRate(MessageParcel &data, MessageParcel &reply)
678 {
679 int32_t sourceId = data.ReadInt32();
680 int32_t rate = data.ReadInt32();
681 reply.WriteInt32(SetAudioSampleRate(sourceId, rate));
682 return MSERR_OK;
683 }
684
SetAudioChannels(MessageParcel & data,MessageParcel & reply)685 int32_t RecorderServiceStub::SetAudioChannels(MessageParcel &data, MessageParcel &reply)
686 {
687 int32_t sourceId = data.ReadInt32();
688 int32_t num = data.ReadInt32();
689 reply.WriteInt32(SetAudioChannels(sourceId, num));
690 return MSERR_OK;
691 }
692
SetAudioEncodingBitRate(MessageParcel & data,MessageParcel & reply)693 int32_t RecorderServiceStub::SetAudioEncodingBitRate(MessageParcel &data, MessageParcel &reply)
694 {
695 int32_t sourceId = data.ReadInt32();
696 int32_t bitRate = data.ReadInt32();
697 reply.WriteInt32(SetAudioEncodingBitRate(sourceId, bitRate));
698 return MSERR_OK;
699 }
700
SetDataSource(MessageParcel & data,MessageParcel & reply)701 int32_t RecorderServiceStub::SetDataSource(MessageParcel &data, MessageParcel &reply)
702 {
703 int32_t type = data.ReadInt32();
704 int32_t sourceId = 0;
705 DataSourceType dataType = static_cast<DataSourceType>(type);
706 int32_t ret = SetDataSource(dataType, sourceId);
707 reply.WriteInt32(sourceId);
708 reply.WriteInt32(ret);
709 return MSERR_OK;
710 }
711
SetMaxDuration(MessageParcel & data,MessageParcel & reply)712 int32_t RecorderServiceStub::SetMaxDuration(MessageParcel &data, MessageParcel &reply)
713 {
714 int32_t duration = data.ReadInt32();
715 reply.WriteInt32(SetMaxDuration(duration));
716 return MSERR_OK;
717 }
718
SetOutputFormat(MessageParcel & data,MessageParcel & reply)719 int32_t RecorderServiceStub::SetOutputFormat(MessageParcel &data, MessageParcel &reply)
720 {
721 int32_t type = data.ReadInt32();
722 OutputFormatType formatType = static_cast<OutputFormatType>(type);
723 reply.WriteInt32(SetOutputFormat(formatType));
724 return MSERR_OK;
725 }
726
SetOutputFile(MessageParcel & data,MessageParcel & reply)727 int32_t RecorderServiceStub::SetOutputFile(MessageParcel &data, MessageParcel &reply)
728 {
729 int32_t fd = data.ReadFileDescriptor();
730 reply.WriteInt32(SetOutputFile(fd));
731 (void)::close(fd);
732 return MSERR_OK;
733 }
734
SetFileGenerationMode(MessageParcel & data,MessageParcel & reply)735 int32_t RecorderServiceStub::SetFileGenerationMode(MessageParcel &data, MessageParcel &reply)
736 {
737 int32_t mode = data.ReadInt32();
738 reply.WriteInt32(SetFileGenerationMode(static_cast<FileGenerationMode>(mode)));
739 return MSERR_OK;
740 }
741
SetLocation(MessageParcel & data,MessageParcel & reply)742 int32_t RecorderServiceStub::SetLocation(MessageParcel &data, MessageParcel &reply)
743 {
744 (void)reply;
745 float latitude = data.ReadFloat();
746 float longitude = data.ReadFloat();
747 SetLocation(latitude, longitude);
748 return MSERR_OK;
749 }
750
SetOrientationHint(MessageParcel & data,MessageParcel & reply)751 int32_t RecorderServiceStub::SetOrientationHint(MessageParcel &data, MessageParcel &reply)
752 {
753 (void)reply;
754 int32_t rotation = data.ReadInt32();
755 return SetOrientationHint(rotation);
756 }
757
SetUserCustomInfo(MessageParcel & data,MessageParcel & reply)758 int32_t RecorderServiceStub::SetUserCustomInfo(MessageParcel &data, MessageParcel &reply)
759 {
760 (void)reply;
761 Meta userCustomInfo;
762 bool ret = userCustomInfo.FromParcel(data);
763 if (!ret) {
764 MEDIA_LOGE("userCustomInfo FromParcel failed");
765 }
766 reply.WriteInt32(SetUserCustomInfo(userCustomInfo));
767 return MSERR_OK;
768 }
769
SetGenre(MessageParcel & data,MessageParcel & reply)770 int32_t RecorderServiceStub::SetGenre(MessageParcel &data, MessageParcel &reply)
771 {
772 (void)reply;
773 std::string genre = data.ReadString();
774 reply.WriteInt32(SetGenre(genre));
775 return MSERR_OK;
776 }
777
Prepare(MessageParcel & data,MessageParcel & reply)778 int32_t RecorderServiceStub::Prepare(MessageParcel &data, MessageParcel &reply)
779 {
780 (void)data;
781 reply.WriteInt32(Prepare());
782 return MSERR_OK;
783 }
784
Start(MessageParcel & data,MessageParcel & reply)785 int32_t RecorderServiceStub::Start(MessageParcel &data, MessageParcel &reply)
786 {
787 (void)data;
788 reply.WriteInt32(Start());
789 return MSERR_OK;
790 }
791
Pause(MessageParcel & data,MessageParcel & reply)792 int32_t RecorderServiceStub::Pause(MessageParcel &data, MessageParcel &reply)
793 {
794 (void)data;
795 reply.WriteInt32(Pause());
796 return MSERR_OK;
797 }
798
Resume(MessageParcel & data,MessageParcel & reply)799 int32_t RecorderServiceStub::Resume(MessageParcel &data, MessageParcel &reply)
800 {
801 (void)data;
802 reply.WriteInt32(Resume());
803 return MSERR_OK;
804 }
805
Stop(MessageParcel & data,MessageParcel & reply)806 int32_t RecorderServiceStub::Stop(MessageParcel &data, MessageParcel &reply)
807 {
808 bool block = data.ReadBool();
809 reply.WriteInt32(Stop(block));
810 audioSourceType_ = AUDIO_SOURCE_INVALID;
811 return MSERR_OK;
812 }
813
Reset(MessageParcel & data,MessageParcel & reply)814 int32_t RecorderServiceStub::Reset(MessageParcel &data, MessageParcel &reply)
815 {
816 (void)data;
817 reply.WriteInt32(Reset());
818 needAudioPermissionCheck = false;
819 audioSourceType_ = AUDIO_SOURCE_INVALID;
820 return MSERR_OK;
821 }
822
Release(MessageParcel & data,MessageParcel & reply)823 int32_t RecorderServiceStub::Release(MessageParcel &data, MessageParcel &reply)
824 {
825 (void)data;
826 reply.WriteInt32(Release());
827 needAudioPermissionCheck = false;
828 audioSourceType_ = AUDIO_SOURCE_INVALID;
829 return MSERR_OK;
830 }
831
DestroyStub(MessageParcel & data,MessageParcel & reply)832 int32_t RecorderServiceStub::DestroyStub(MessageParcel &data, MessageParcel &reply)
833 {
834 (void)data;
835 reply.WriteInt32(DestroyStub());
836 needAudioPermissionCheck = false;
837 audioSourceType_ = AUDIO_SOURCE_INVALID;
838 return MSERR_OK;
839 }
840
GetAVRecorderConfig(MessageParcel & data,MessageParcel & reply)841 int32_t RecorderServiceStub::GetAVRecorderConfig(MessageParcel &data, MessageParcel &reply)
842 {
843 ConfigMap configMap;
844 GetAVRecorderConfig(configMap);
845
846 (void)reply.WriteInt32(configMap["audioBitrate"]);
847 (void)reply.WriteInt32(configMap["audioChannels"]);
848 (void)reply.WriteInt32(configMap["audioCodec"]);
849 (void)reply.WriteInt32(configMap["audioSampleRate"]);
850 (void)reply.WriteInt32(configMap["fileFormat"]);
851 (void)reply.WriteInt32(configMap["videoBitrate"]);
852 (void)reply.WriteInt32(configMap["videoCodec"]);
853 (void)reply.WriteInt32(configMap["videoFrameHeight"]);
854 (void)reply.WriteInt32(configMap["videoFrameWidth"]);
855 (void)reply.WriteInt32(configMap["videoFrameRate"]);
856 (void)reply.WriteInt32(configMap["audioSourceType"]);
857 (void)reply.WriteInt32(configMap["videoSourceType"]);
858 (void)reply.WriteInt32(configMap["url"]);
859 (void)reply.WriteInt32(configMap["rotation"]);
860 (void)reply.WriteInt32(configMap["withVideo"]);
861 (void)reply.WriteInt32(configMap["withAudio"]);
862 (void)reply.WriteInt32(configMap["withLocation"]);
863
864 return MSERR_OK;
865 }
866
GetLocation(MessageParcel & data,MessageParcel & reply)867 int32_t RecorderServiceStub::GetLocation(MessageParcel &data, MessageParcel &reply)
868 {
869 Location location;
870 GetLocation(location);
871 (void)reply.WriteFloat(location.latitude);
872 (void)reply.WriteFloat(location.longitude);
873 return MSERR_OK;
874 }
875
CheckPermission()876 int32_t RecorderServiceStub::CheckPermission()
877 {
878 Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID();
879
880 switch (audioSourceType_) {
881 case AUDIO_SOURCE_VOICE_CALL:
882 return Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller,
883 "ohos.permission.RECORD_VOICE_CALL");
884 case AUDIO_MIC:
885 case AUDIO_SOURCE_DEFAULT:
886 case AUDIO_SOURCE_VOICE_RECOGNITION:
887 case AUDIO_SOURCE_VOICE_COMMUNICATION:
888 case AUDIO_SOURCE_VOICE_MESSAGE:
889 case AUDIO_SOURCE_CAMCORDER:
890 return Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller,
891 "ohos.permission.MICROPHONE");
892 case AUDIO_INNER:
893 MEDIA_LOGE("not supported audio source. Permission denied");
894 return Security::AccessToken::PERMISSION_DENIED;
895 default:
896 return Security::AccessToken::PERMISSION_GRANTED;
897 }
898 }
899
GetCurrentCapturerChangeInfo(MessageParcel & data,MessageParcel & reply)900 int32_t RecorderServiceStub::GetCurrentCapturerChangeInfo(MessageParcel &data, MessageParcel &reply)
901 {
902 AudioRecorderChangeInfo changeInfo;
903 int32_t ret = GetCurrentCapturerChangeInfo(changeInfo);
904 changeInfo.Marshalling(reply);
905
906 reply.WriteInt32(ret);
907 return MSERR_OK;
908 }
909
GetAvailableEncoder(MessageParcel & data,MessageParcel & reply)910 int32_t RecorderServiceStub::GetAvailableEncoder(MessageParcel &data, MessageParcel &reply)
911 {
912 (void)data;
913 std::vector<EncoderCapabilityData> encoderInfo;
914 int32_t ret = GetAvailableEncoder(encoderInfo);
915 reply.WriteInt32(static_cast<int32_t>(encoderInfo.size()));
916 for (auto iter = encoderInfo.begin(); iter != encoderInfo.end(); iter++) {
917 iter->Marshalling(reply);
918 }
919 reply.WriteInt32(ret);
920
921 return MSERR_OK;
922 }
923
GetMaxAmplitude(MessageParcel & data,MessageParcel & reply)924 int32_t RecorderServiceStub::GetMaxAmplitude(MessageParcel &data, MessageParcel &reply)
925 {
926 (void)data;
927 reply.WriteInt32(GetMaxAmplitude());
928
929 return MSERR_OK;
930 }
931
IsWatermarkSupported(MessageParcel & data,MessageParcel & reply)932 int32_t RecorderServiceStub::IsWatermarkSupported(MessageParcel &data, MessageParcel &reply)
933 {
934 (void)data;
935 bool isWatermarkSupported = false;
936 int32_t ret = IsWatermarkSupported(isWatermarkSupported);
937 CHECK_AND_RETURN_RET_LOG(reply.WriteBool(isWatermarkSupported), MSERR_INVALID_OPERATION, "reply write failed");
938 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), MSERR_INVALID_OPERATION, "reply write failed");
939 return MSERR_OK;
940 }
SetWatermark(MessageParcel & data,MessageParcel & reply)941 int32_t RecorderServiceStub::SetWatermark(MessageParcel &data, MessageParcel &reply)
942 {
943 std::shared_ptr<AVBuffer> buffer = AVBuffer::CreateAVBuffer();
944 CHECK_AND_RETURN_RET_LOG(buffer != nullptr, MSERR_NO_MEMORY, "create AVBuffer failed");
945 CHECK_AND_RETURN_RET_LOG(buffer->ReadFromMessageParcel(data), MSERR_INVALID_OPERATION, "read buffer failed");
946 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SetWatermark(buffer)), MSERR_INVALID_OPERATION, "reply write failed");
947 return MSERR_OK;
948 }
949 } // namespace Media
950 } // namespace OHOS
951