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