• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-2023 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  * Description: supply stream player implement proxy realization.
15  * Author: huangchanggui
16  * Create: 2023-01-12
17  */
18 
19 #include "stream_player_impl_proxy.h"
20 #include "cast_engine_common_helper.h"
21 #include "cast_engine_errors.h"
22 #include "cast_engine_log.h"
23 
24 namespace OHOS {
25 namespace CastEngine {
26 namespace CastEngineClient {
27 DEFINE_CAST_ENGINE_LABEL("Cast-Client-StreamPlayer");
28 
~StreamPlayerImplProxy()29 StreamPlayerImplProxy::~StreamPlayerImplProxy()
30 {
31     CLOGD("destructor in");
32 }
33 
RegisterListener(sptr<IStreamPlayerListenerImpl> listener)34 int32_t StreamPlayerImplProxy::RegisterListener(sptr<IStreamPlayerListenerImpl> listener)
35 {
36     MessageParcel data;
37     MessageParcel reply;
38     MessageOption option;
39 
40     if (!data.WriteInterfaceToken(GetDescriptor())) {
41         CLOGE("Failed to write the interface token");
42         return CAST_ENGINE_ERROR;
43     }
44     if (!data.WriteRemoteObject(listener->AsObject())) {
45         CLOGE("Failed to write stream player listener");
46         return CAST_ENGINE_ERROR;
47     }
48     if (Remote()->SendRequest(REGISTER_LISTENER, data, reply, option) != ERR_NONE) {
49         CLOGE("Failed to send ipc request when registering listener");
50         return CAST_ENGINE_ERROR;
51     }
52 
53     return reply.ReadInt32();
54 }
55 
UnregisterListener()56 int32_t StreamPlayerImplProxy::UnregisterListener()
57 {
58     MessageParcel data;
59     MessageParcel reply;
60     MessageOption option;
61 
62     if (!data.WriteInterfaceToken(GetDescriptor())) {
63         CLOGE("Failed to write the interface token");
64         return CAST_ENGINE_ERROR;
65     }
66     if (Remote()->SendRequest(UNREGISTER_LISTENER, data, reply, option) != ERR_NONE) {
67         CLOGE("Failed to send ipc request when unregistering listener");
68         return CAST_ENGINE_ERROR;
69     }
70 
71     return reply.ReadInt32();
72 }
73 
SetSurface(sptr<IBufferProducer> producer)74 int32_t StreamPlayerImplProxy::SetSurface(sptr<IBufferProducer> producer)
75 {
76     MessageParcel data;
77     MessageParcel reply;
78     MessageOption option;
79 
80     if (!data.WriteInterfaceToken(GetDescriptor())) {
81         CLOGE("Failed to write the interface token");
82         return CAST_ENGINE_ERROR;
83     }
84     if (!data.WriteRemoteObject(producer->AsObject())) {
85         CLOGE("Failed to write surface producer");
86         return CAST_ENGINE_ERROR;
87     }
88 
89     int32_t ret = Remote()->SendRequest(SET_SURFACE, data, reply, option);
90     if (ret == ERR_INVALID_DATA) {
91         CLOGE("Invalid parameter when setting surface");
92         return ERR_INVALID_PARAM;
93     } else if (ret != ERR_NONE) {
94         CLOGE("Failed to send ipc request when setting surface");
95         return CAST_ENGINE_ERROR;
96     }
97 
98     return reply.ReadInt32();
99 }
100 
Load(const MediaInfo & mediaInfo)101 int32_t StreamPlayerImplProxy::Load(const MediaInfo &mediaInfo)
102 {
103     MessageParcel data;
104     MessageParcel reply;
105     MessageOption option;
106 
107     if (!data.WriteInterfaceToken(GetDescriptor())) {
108         CLOGE("Failed to write the interface token");
109         return CAST_ENGINE_ERROR;
110     }
111     if (!WriteMediaInfo(data, mediaInfo)) {
112         CLOGE("Failed to write the mediaInfo");
113         return CAST_ENGINE_ERROR;
114     }
115 
116     int32_t ret = Remote()->SendRequest(LOAD, data, reply, option);
117     if (ret == ERR_INVALID_DATA) {
118         CLOGE("Invalid parameter when load");
119         return ERR_INVALID_PARAM;
120     } else if (ret != ERR_NONE) {
121         CLOGE("Failed to send ipc request when load");
122         return CAST_ENGINE_ERROR;
123     }
124 
125     return reply.ReadInt32();
126 }
127 
Play(const MediaInfo & mediaInfo)128 int32_t StreamPlayerImplProxy::Play(const MediaInfo &mediaInfo)
129 {
130     MessageParcel data;
131     MessageParcel reply;
132     MessageOption option;
133 
134     if (!data.WriteInterfaceToken(GetDescriptor())) {
135         CLOGE("Failed to write the interface token");
136         return CAST_ENGINE_ERROR;
137     }
138     if (!WriteMediaInfo(data, mediaInfo)) {
139         CLOGE("Failed to write the mediaInfo");
140         return CAST_ENGINE_ERROR;
141     }
142 
143     int32_t ret = Remote()->SendRequest(START, data, reply, option);
144     if (ret == ERR_INVALID_DATA) {
145         CLOGE("Invalid parameter when play");
146         return ERR_INVALID_PARAM;
147     } else if (ret != ERR_NONE) {
148         CLOGE("Failed to send ipc request when play");
149         return CAST_ENGINE_ERROR;
150     }
151 
152     return reply.ReadInt32();
153 }
154 
Play(int index)155 int32_t StreamPlayerImplProxy::Play(int index)
156 {
157     MessageParcel data;
158     MessageParcel reply;
159     MessageOption option;
160 
161     if (!data.WriteInterfaceToken(GetDescriptor())) {
162         CLOGE("Failed to write the interface token");
163         return CAST_ENGINE_ERROR;
164     }
165     if (!data.WriteInt32(index)) {
166         CLOGE("Failed to write the index");
167         return CAST_ENGINE_ERROR;
168     }
169     if (Remote()->SendRequest(PLAY_INDEX, data, reply, option) != ERR_NONE) {
170         CLOGE("Failed to send ipc request when play");
171         return CAST_ENGINE_ERROR;
172     }
173 
174     return reply.ReadInt32();
175 }
176 
Pause()177 int32_t StreamPlayerImplProxy::Pause()
178 {
179     MessageParcel data;
180     MessageParcel reply;
181     MessageOption option;
182 
183     if (!data.WriteInterfaceToken(GetDescriptor())) {
184         CLOGE("Failed to write the interface token");
185         return CAST_ENGINE_ERROR;
186     }
187     if (Remote()->SendRequest(PAUSE, data, reply, option) != ERR_NONE) {
188         CLOGE("Failed to send ipc request when pause");
189         return CAST_ENGINE_ERROR;
190     }
191 
192     return reply.ReadInt32();
193 }
194 
Play()195 int32_t StreamPlayerImplProxy::Play()
196 {
197     MessageParcel data;
198     MessageParcel reply;
199     MessageOption option;
200 
201     if (!data.WriteInterfaceToken(GetDescriptor())) {
202         CLOGE("Failed to write the interface token");
203         return CAST_ENGINE_ERROR;
204     }
205     if (Remote()->SendRequest(PLAY, data, reply, option) != ERR_NONE) {
206         CLOGE("Failed to send ipc request when resume");
207         return CAST_ENGINE_ERROR;
208     }
209 
210     return reply.ReadInt32();
211 }
212 
Stop()213 int32_t StreamPlayerImplProxy::Stop()
214 {
215     MessageParcel data;
216     MessageParcel reply;
217     MessageOption option;
218 
219     if (!data.WriteInterfaceToken(GetDescriptor())) {
220         CLOGE("Failed to write the interface token");
221         return CAST_ENGINE_ERROR;
222     }
223     if (Remote()->SendRequest(STOP, data, reply, option) != ERR_NONE) {
224         CLOGE("Failed to send ipc request when stop");
225         return CAST_ENGINE_ERROR;
226     }
227 
228     return reply.ReadInt32();
229 }
230 
Next()231 int32_t StreamPlayerImplProxy::Next()
232 {
233     MessageParcel data;
234     MessageParcel reply;
235     MessageOption option;
236 
237     if (!data.WriteInterfaceToken(GetDescriptor())) {
238         CLOGE("Failed to write the interface token");
239         return CAST_ENGINE_ERROR;
240     }
241     if (Remote()->SendRequest(NEXT, data, reply, option) != ERR_NONE) {
242         CLOGE("Failed to send ipc request when stop");
243         return CAST_ENGINE_ERROR;
244     }
245 
246     return reply.ReadInt32();
247 }
248 
Previous()249 int32_t StreamPlayerImplProxy::Previous()
250 {
251     MessageParcel data;
252     MessageParcel reply;
253     MessageOption option;
254 
255     if (!data.WriteInterfaceToken(GetDescriptor())) {
256         CLOGE("Failed to write the interface token");
257         return CAST_ENGINE_ERROR;
258     }
259     if (Remote()->SendRequest(PREVIOUS, data, reply, option) != ERR_NONE) {
260         CLOGE("Failed to send ipc request when stop");
261         return CAST_ENGINE_ERROR;
262     }
263 
264     return reply.ReadInt32();
265 }
266 
Seek(int position)267 int32_t StreamPlayerImplProxy::Seek(int position)
268 {
269     MessageParcel data;
270     MessageParcel reply;
271     MessageOption option;
272 
273     if (!data.WriteInterfaceToken(GetDescriptor())) {
274         CLOGE("Failed to write the interface token");
275         return CAST_ENGINE_ERROR;
276     }
277     if (!data.WriteInt32(position)) {
278         CLOGE("Failed to write the position");
279         return CAST_ENGINE_ERROR;
280     }
281     if (Remote()->SendRequest(SEEK, data, reply, option) != ERR_NONE) {
282         CLOGE("Failed to send ipc request when seek");
283         return CAST_ENGINE_ERROR;
284     }
285 
286     return reply.ReadInt32();
287 }
288 
FastForward(int delta)289 int32_t StreamPlayerImplProxy::FastForward(int delta)
290 {
291     MessageParcel data;
292     MessageParcel reply;
293     MessageOption option;
294 
295     if (!data.WriteInterfaceToken(GetDescriptor())) {
296         CLOGE("Failed to write the interface token");
297         return CAST_ENGINE_ERROR;
298     }
299     if (!data.WriteInt32(delta)) {
300         CLOGE("Failed to write the delta");
301         return CAST_ENGINE_ERROR;
302     }
303     if (Remote()->SendRequest(FAST_FORWARD, data, reply, option) != ERR_NONE) {
304         CLOGE("Failed to send ipc request when fastForward");
305         return CAST_ENGINE_ERROR;
306     }
307 
308     return reply.ReadInt32();
309 }
310 
FastRewind(int delta)311 int32_t StreamPlayerImplProxy::FastRewind(int delta)
312 {
313     MessageParcel data;
314     MessageParcel reply;
315     MessageOption option;
316 
317     if (!data.WriteInterfaceToken(GetDescriptor())) {
318         CLOGE("Failed to write the interface token");
319         return CAST_ENGINE_ERROR;
320     }
321     if (!data.WriteInt32(delta)) {
322         CLOGE("Failed to write the delta");
323         return CAST_ENGINE_ERROR;
324     }
325     if (Remote()->SendRequest(FAST_REWIND, data, reply, option) != ERR_NONE) {
326         CLOGE("Failed to send ipc request when fastRewind");
327         return CAST_ENGINE_ERROR;
328     }
329 
330     return reply.ReadInt32();
331 }
332 
SetVolume(int volume)333 int32_t StreamPlayerImplProxy::SetVolume(int volume)
334 {
335     MessageParcel data;
336     MessageParcel reply;
337     MessageOption option;
338 
339     if (!data.WriteInterfaceToken(GetDescriptor())) {
340         CLOGE("Failed to write the interface token");
341         return CAST_ENGINE_ERROR;
342     }
343     if (!data.WriteInt32(volume)) {
344         CLOGE("Failed to write the volume");
345         return CAST_ENGINE_ERROR;
346     }
347     if (Remote()->SendRequest(SET_VOLUME, data, reply, option) != ERR_NONE) {
348         CLOGE("Failed to send ipc request when set volume");
349         return CAST_ENGINE_ERROR;
350     }
351 
352     return reply.ReadInt32();
353 }
354 
SetMute(bool mute)355 int32_t StreamPlayerImplProxy::SetMute(bool mute)
356 {
357     MessageParcel data;
358     MessageParcel reply;
359     MessageOption option;
360 
361     if (!data.WriteInterfaceToken(GetDescriptor())) {
362         CLOGE("Failed to write the interface token");
363         return CAST_ENGINE_ERROR;
364     }
365     if (!data.WriteBool(mute)) {
366         CLOGE("Failed to write the mute");
367         return CAST_ENGINE_ERROR;
368     }
369     if (Remote()->SendRequest(SET_MUTE, data, reply, option) != ERR_NONE) {
370         CLOGE("Failed to send ipc request when set mute");
371         return CAST_ENGINE_ERROR;
372     }
373 
374     return reply.ReadInt32();
375 }
376 
SetLoopMode(const LoopMode mode)377 int32_t StreamPlayerImplProxy::SetLoopMode(const LoopMode mode)
378 {
379     MessageParcel data;
380     MessageParcel reply;
381     MessageOption option;
382 
383     if (!data.WriteInterfaceToken(GetDescriptor())) {
384         CLOGE("Failed to write the interface token");
385         return CAST_ENGINE_ERROR;
386     }
387     if (!data.WriteInt32(static_cast<int32_t>(mode))) {
388         CLOGE("Failed to write the mode");
389         return CAST_ENGINE_ERROR;
390     }
391     if (Remote()->SendRequest(SET_LOOP_MODE, data, reply, option) != ERR_NONE) {
392         CLOGE("Failed to send ipc request when set volume");
393         return CAST_ENGINE_ERROR;
394     }
395 
396     return reply.ReadInt32();
397 }
398 
SetAvailableCapability(const StreamCapability & streamCapability)399 int32_t StreamPlayerImplProxy::SetAvailableCapability(const StreamCapability &streamCapability)
400 {
401     MessageParcel data;
402     MessageParcel reply;
403     MessageOption option;
404 
405     if (!data.WriteInterfaceToken(GetDescriptor())) {
406         CLOGE("Failed to write the interface token");
407         return CAST_ENGINE_ERROR;
408     }
409     if (!WriteStreamCapability(data, streamCapability)) {
410         CLOGE("Failed to write the modeScope");
411         return CAST_ENGINE_ERROR;
412     }
413     if (Remote()->SendRequest(SET_AVAILABLE_CAPABILITY, data, reply, option) != ERR_NONE) {
414         CLOGE("Failed to send ipc request when set available capability");
415         return CAST_ENGINE_ERROR;
416     }
417 
418     return reply.ReadInt32();
419 }
420 
SetSpeed(const PlaybackSpeed speed)421 int32_t StreamPlayerImplProxy::SetSpeed(const PlaybackSpeed speed)
422 {
423     MessageParcel data;
424     MessageParcel reply;
425     MessageOption option;
426 
427     if (!data.WriteInterfaceToken(GetDescriptor())) {
428         CLOGE("Failed to write the interface token");
429         return CAST_ENGINE_ERROR;
430     }
431     if (!data.WriteInt32(static_cast<int32_t>(speed))) {
432         CLOGE("Failed to write the position");
433         return CAST_ENGINE_ERROR;
434     }
435     if (Remote()->SendRequest(SET_SPEED, data, reply, option) != ERR_NONE) {
436         CLOGE("Failed to send ipc request when set volume");
437         return CAST_ENGINE_ERROR;
438     }
439 
440     return reply.ReadInt32();
441 }
442 
GetPlayerStatus(PlayerStates & playerStates)443 int32_t StreamPlayerImplProxy::GetPlayerStatus(PlayerStates &playerStates)
444 {
445     MessageParcel data;
446     MessageParcel reply;
447     MessageOption option;
448 
449     playerStates = PlayerStates::PLAYER_STATE_ERROR;
450     if (!data.WriteInterfaceToken(GetDescriptor())) {
451         CLOGE("Failed to write the interface token");
452         return CAST_ENGINE_ERROR;
453     }
454     if (Remote()->SendRequest(GET_PLAYER_STATUS, data, reply, option) != ERR_NONE) {
455         CLOGE("Failed to send ipc request when get player status");
456         return CAST_ENGINE_ERROR;
457     }
458 
459     int32_t errorCode = reply.ReadInt32();
460     CHECK_AND_RETURN_RET_LOG(errorCode != CAST_ENGINE_SUCCESS, errorCode, "CastEngine Errors");
461     playerStates = static_cast<PlayerStates>(reply.ReadInt32());
462 
463     return errorCode;
464 }
465 
GetPosition(int & position)466 int32_t StreamPlayerImplProxy::GetPosition(int &position)
467 {
468     MessageParcel data;
469     MessageParcel reply;
470     MessageOption option;
471 
472     if (!data.WriteInterfaceToken(GetDescriptor())) {
473         CLOGE("Failed to write the interface token");
474         return CAST_ENGINE_ERROR;
475     }
476     if (Remote()->SendRequest(GET_POSITION, data, reply, option) != ERR_NONE) {
477         CLOGE("Failed to send ipc request when get position");
478         return CAST_ENGINE_ERROR;
479     }
480 
481     int32_t errorCode = reply.ReadInt32();
482     CHECK_AND_RETURN_RET_LOG(errorCode != CAST_ENGINE_SUCCESS, errorCode, "CastEngine Errors");
483     position = reply.ReadInt32();
484 
485     return errorCode;
486 }
487 
GetDuration(int & duration)488 int32_t StreamPlayerImplProxy::GetDuration(int &duration)
489 {
490     MessageParcel data;
491     MessageParcel reply;
492     MessageOption option;
493 
494     if (!data.WriteInterfaceToken(GetDescriptor())) {
495         CLOGE("Failed to write the interface token");
496         return CAST_ENGINE_ERROR;
497     }
498     if (Remote()->SendRequest(GET_DURATION, data, reply, option) != ERR_NONE) {
499         CLOGE("Failed to send ipc request when get duration");
500         return CAST_ENGINE_ERROR;
501     }
502 
503     int32_t errorCode = reply.ReadInt32();
504     CHECK_AND_RETURN_RET_LOG(errorCode != CAST_ENGINE_SUCCESS, errorCode, "CastEngine Errors");
505     duration = reply.ReadInt32();
506 
507     return errorCode;
508 }
509 
GetVolume(int & volume,int & maxVolume)510 int32_t StreamPlayerImplProxy::GetVolume(int &volume, int &maxVolume)
511 {
512     MessageParcel data;
513     MessageParcel reply;
514     MessageOption option;
515 
516     if (!data.WriteInterfaceToken(GetDescriptor())) {
517         CLOGE("Failed to write the interface token");
518         return CAST_ENGINE_ERROR;
519     }
520     if (Remote()->SendRequest(GET_VOLUME, data, reply, option) != ERR_NONE) {
521         CLOGE("Failed to send ipc request when get duration");
522         return CAST_ENGINE_ERROR;
523     }
524 
525     int32_t errorCode = reply.ReadInt32();
526     CHECK_AND_RETURN_RET_LOG(errorCode != CAST_ENGINE_SUCCESS, errorCode, "CastEngine Errors");
527     volume = reply.ReadInt32();
528     maxVolume = reply.ReadInt32();
529 
530     return errorCode;
531 }
532 
GetMute(bool & mute)533 int32_t StreamPlayerImplProxy::GetMute(bool &mute)
534 {
535     MessageParcel data;
536     MessageParcel reply;
537     MessageOption option;
538 
539     if (!data.WriteInterfaceToken(GetDescriptor())) {
540         CLOGE("Failed to write the interface token");
541         return CAST_ENGINE_ERROR;
542     }
543     if (Remote()->SendRequest(GET_MUTE, data, reply, option) != ERR_NONE) {
544         CLOGE("Failed to send ipc request when query is mute");
545         return CAST_ENGINE_ERROR;
546     }
547 
548     int32_t errorCode = reply.ReadInt32();
549     CHECK_AND_RETURN_RET_LOG(errorCode != CAST_ENGINE_SUCCESS, errorCode, "CastEngine Errors");
550     mute = reply.ReadBool();
551 
552     return errorCode;
553 }
554 
GetLoopMode(LoopMode & loopMode)555 int32_t StreamPlayerImplProxy::GetLoopMode(LoopMode &loopMode)
556 {
557     MessageParcel data;
558     MessageParcel reply;
559     MessageOption option;
560 
561     loopMode = LoopMode::LOOP_MODE_LIST;
562     if (!data.WriteInterfaceToken(GetDescriptor())) {
563         CLOGE("Failed to write the interface token");
564         return CAST_ENGINE_ERROR;
565     }
566     if (Remote()->SendRequest(GET_LOOP_MODE, data, reply, option) != ERR_NONE) {
567         CLOGE("Failed to send ipc request when get duration");
568         return CAST_ENGINE_ERROR;
569     }
570 
571     int32_t errorCode = reply.ReadInt32();
572     CHECK_AND_RETURN_RET_LOG(errorCode != CAST_ENGINE_SUCCESS, errorCode, "CastEngine Errors");
573     loopMode = static_cast<LoopMode>(reply.ReadInt32());
574 
575     return errorCode;
576 }
577 
GetAvailableCapability(StreamCapability & streamCapability)578 int32_t StreamPlayerImplProxy::GetAvailableCapability(StreamCapability &streamCapability)
579 {
580     MessageParcel data;
581     MessageParcel reply;
582     MessageOption option;
583 
584     if (!data.WriteInterfaceToken(GetDescriptor())) {
585         CLOGE("Failed to write the interface token");
586         return CAST_ENGINE_ERROR;
587     }
588     if (Remote()->SendRequest(GET_AVAILABLE_CAPABILITY, data, reply, option) != ERR_NONE) {
589         CLOGE("Failed to send ipc request when get available capability");
590         return CAST_ENGINE_ERROR;
591     }
592 
593     int32_t errorCode = reply.ReadInt32();
594     CHECK_AND_RETURN_RET_LOG(errorCode != CAST_ENGINE_SUCCESS, errorCode, "CastEngine Errors");
595     streamCapability = ReadStreamCapability(reply);
596 
597     return errorCode;
598 }
599 
GetPlaySpeed(PlaybackSpeed & playbackSpeed)600 int32_t StreamPlayerImplProxy::GetPlaySpeed(PlaybackSpeed &playbackSpeed)
601 {
602     MessageParcel data;
603     MessageParcel reply;
604     MessageOption option;
605 
606     playbackSpeed = PlaybackSpeed::SPEED_FORWARD_1_00_X;
607     if (!data.WriteInterfaceToken(GetDescriptor())) {
608         CLOGE("Failed to write the interface token");
609         return CAST_ENGINE_ERROR;
610     }
611     if (Remote()->SendRequest(GET_PLAY_SPEED, data, reply, option) != ERR_NONE) {
612         CLOGE("Failed to send ipc request when get duration");
613         return CAST_ENGINE_ERROR;
614     }
615 
616     int32_t errorCode = reply.ReadInt32();
617     CHECK_AND_RETURN_RET_LOG(errorCode != CAST_ENGINE_SUCCESS, errorCode, "CastEngine Errors");
618     playbackSpeed = static_cast<PlaybackSpeed>(reply.ReadInt32());
619 
620     return errorCode;
621 }
622 
GetMediaInfoHolder(MediaInfoHolder & mediaInfoHolder)623 int32_t StreamPlayerImplProxy::GetMediaInfoHolder(MediaInfoHolder &mediaInfoHolder)
624 {
625     MessageParcel data;
626     MessageParcel reply;
627     MessageOption option;
628 
629     if (!data.WriteInterfaceToken(GetDescriptor())) {
630         CLOGE("Failed to write the interface token");
631         return CAST_ENGINE_ERROR;
632     }
633     if (Remote()->SendRequest(GET_MEDIA_INFO_HOLDER, data, reply, option) != ERR_NONE) {
634         CLOGE("Failed to send ipc request when get duration");
635         return CAST_ENGINE_ERROR;
636     }
637 
638     int32_t errorCode = reply.ReadInt32();
639     CHECK_AND_RETURN_RET_LOG(errorCode != CAST_ENGINE_SUCCESS, errorCode, "CastEngine Errors");
640     auto mediaInfos = ReadMediaInfoHolder(reply);
641     if (mediaInfos == nullptr) {
642         CLOGE("GetMediaInfoHolder, mediaInfoHolder is null");
643         return CAST_ENGINE_ERROR;
644     }
645     mediaInfoHolder = *mediaInfos;
646 
647     return errorCode;
648 }
649 
ProvideKeyResponse(const std::string & mediaId,const std::vector<uint8_t> & response)650 int32_t StreamPlayerImplProxy::ProvideKeyResponse(const std::string &mediaId, const std::vector<uint8_t> &response)
651 {
652     MessageParcel data;
653     MessageParcel reply;
654     MessageOption option;
655     auto len = response.size();
656     if (len > data.GetDataCapacity()) {
657         CLOGD("ProvideKeyResponse SetDataCapacity totalSize: %zu", len);
658 
659         data.SetMaxCapacity(len + len);
660         data.SetDataCapacity(len);
661     }
662 
663     if (!data.WriteInterfaceToken(GetDescriptor())) {
664         CLOGE("Failed to write the interface token");
665         return CAST_ENGINE_ERROR;
666     }
667 
668     if (!data.WriteString(mediaId)) {
669         CLOGE("Failed to write mediaId");
670         return CAST_ENGINE_ERROR;
671     }
672 
673     if (!data.WriteInt32(response.size())) {
674         CLOGE("StreamPlayerImplProxy ProvideKeyResponse Write response size failed");
675         return IPC_PROXY_ERR;
676     }
677 
678     if (len != 0) {
679         if (!data.WriteBuffer(response.data(), len)) {
680             CLOGE("StreamPlayerImplProxy ProvideKeyResponse write response failed");
681             return IPC_PROXY_ERR;
682         }
683     }
684 
685     if (Remote()->SendRequest(PROVIDE_KEY_RESPONSE, data, reply, option) != ERR_NONE) {
686         CLOGE("Failed to send ipc request when provide key response");
687         return CAST_ENGINE_ERROR;
688     }
689 
690     int32_t errorCode = reply.ReadInt32();
691     CHECK_AND_RETURN_RET_LOG(errorCode != CAST_ENGINE_SUCCESS, errorCode, "CastEngine Errors");
692     return errorCode;
693 }
694 
Release()695 int32_t StreamPlayerImplProxy::Release()
696 {
697     MessageParcel data;
698     MessageParcel reply;
699     MessageOption option;
700 
701     if (!data.WriteInterfaceToken(GetDescriptor())) {
702         CLOGE("Failed to write the interface token");
703         return CAST_ENGINE_ERROR;
704     }
705     if (Remote()->SendRequest(RELEASE, data, reply, option) != ERR_NONE) {
706         CLOGE("Failed to send ipc request when Releasing stream player");
707         return CAST_ENGINE_ERROR;
708     }
709 
710     return reply.ReadInt32();
711 }
712 } // namespace CastEngineClient
713 } // namespace CastEngine
714 } // namespace OHOS
715