1 /*
2 * Copyright (c) 2020 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 <cstdio>
17 #include "player_client.h"
18 #include "samgr_lite.h"
19 #include "surface.h"
20 #include "surface_impl.h"
21
OHOS_SystemInit(void)22 extern "C" void __attribute__((weak)) OHOS_SystemInit(void)
23 {
24 SAMGR_Bootstrap();
25 }
26
27 namespace OHOS {
28 namespace Media {
InitPlayerClient()29 bool Player::PlayerClient::InitPlayerClient()
30 {
31 OHOS_SystemInit();
32 if (proxy_ == nullptr) {
33 IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(SERVICE_NAME);
34 if (iUnknown == nullptr) {
35 MEDIA_ERR_LOG("iUnknown is NULL");
36 return false;
37 }
38 (void)iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&proxy_);
39 if (proxy_ == nullptr) {
40 MEDIA_ERR_LOG("QueryInterface failed");
41 return false;
42 }
43 }
44 return true;
45 }
46
Callback(void * owner,int code,IpcIo * reply)47 int Player::PlayerClient::Callback(void* owner, int code, IpcIo *reply)
48 {
49 if (code != 0) {
50 MEDIA_ERR_LOG("callback error, code = %d", code);
51 return -1;
52 }
53
54 if (owner == nullptr) {
55 return -1;
56 }
57 CallBackPara* para = (CallBackPara*)owner;
58 switch (para->funcId) {
59 case PLAYER_SERVER_SET_SOURCE: {
60 int32_t* ret = static_cast<int32_t*>(para->ret);
61 ReadInt32(reply, ret);
62 if ((*ret == 0) && (para->type == (int32_t)SourceType::SOURCE_TYPE_STREAM) && (para->data != nullptr)) {
63 Source* source = (Source*)para->data;
64 auto stream = source->GetSourceStream();
65 Surface* surface = SurfaceImpl::GenericSurfaceByIpcIo(*reply);
66 if (surface != nullptr) {
67 stream->SetSurface(surface);
68 } else {
69 MEDIA_ERR_LOG("Stream source GenericSurfaceByIpcIo failed");
70 }
71 }
72 break;
73 }
74 case PLAYER_SERVER_PREPARE: {
75 int32_t* ret = static_cast<int32_t*>(para->ret);
76 ReadInt32(reply, ret);
77 break;
78 }
79 case PLAYER_SERVER_PLAY: {
80 int32_t* ret = static_cast<int32_t*>(para->ret);
81 ReadInt32(reply, ret);
82 break;
83 }
84 case PLAYER_SERVER_IS_PLAYING: {
85 bool* ret = static_cast<bool*>(para->ret);
86 ReadBool(reply, ret);
87 break;
88 }
89 case PLAYER_SERVER_PAUSE: {
90 int32_t* ret = static_cast<int32_t*>(para->ret);
91 ReadInt32(reply, ret);
92 break;
93 }
94 case PLAYER_SERVER_STOP: {
95 int32_t* ret = static_cast<int32_t*>(para->ret);
96 ReadInt32(reply, ret);
97 break;
98 }
99 case PLAYER_SERVER_REWIND: {
100 int32_t* ret = static_cast<int32_t*>(para->ret);
101 ReadInt32(reply, ret);
102 break;
103 }
104 case PLAYER_SERVER_SET_VOLUME: {
105 int32_t* ret = static_cast<int32_t*>(para->ret);
106 ReadInt32(reply, ret);
107 break;
108 }
109 case PLAYER_SERVER_SET_VIDEO_SURFACE: {
110 int32_t* ret = static_cast<int32_t*>(para->ret);
111 ReadInt32(reply, ret);
112 break;
113 }
114 case PLAYER_SERVER_ENABLE_SINGLE_LOOPING: {
115 int32_t* ret = static_cast<int32_t*>(para->ret);
116 ReadInt32(reply, ret);
117 break;
118 }
119 case PLAYER_SERVER_IS_SINGLE_LOOPING: {
120 int32_t* ret = static_cast<int32_t*>(para->ret);
121 ReadInt32(reply, ret);
122 break;
123 }
124 case PLAYER_SERVER_GET_CURRENT_TIME: {
125 int32_t* ret = static_cast<int32_t*>(para->ret);
126 ReadInt32(reply, ret);
127 int64_t* data = static_cast<int64_t*>(para->data);
128 ReadInt64(reply, data);
129 break;
130 }
131 case PLAYER_SERVER_GET_DURATION: {
132 int32_t* ret = static_cast<int32_t*>(para->ret);
133 ReadInt32(reply, ret);
134 int64_t* data = static_cast<int64_t*>(para->data);
135 ReadInt64(reply, data);
136 break;
137 }
138 case PLAYER_SERVER_GET_VIDEO_WIDTH: {
139 int32_t* ret = static_cast<int32_t*>(para->ret);
140 ReadInt32(reply, ret);
141 int32_t* data = static_cast<int32_t*>(para->data);
142 ReadInt32(reply, data);
143 break;
144 }
145 case PLAYER_SERVER_GET_VIDEO_HEIGHT: {
146 int32_t* ret = static_cast<int32_t*>(para->ret);
147 ReadInt32(reply, ret);
148 int32_t* data = static_cast<int32_t*>(para->data);
149 ReadInt32(reply, data);
150 break;
151 }
152 case PLAYER_SERVER_RESET: {
153 int32_t* ret = static_cast<int32_t*>(para->ret);
154 ReadInt32(reply, ret);
155 break;
156 }
157 case PLAYER_SERVER_RELEASE: {
158 int32_t* ret = static_cast<int32_t*>(para->ret);
159 ReadInt32(reply, ret);
160 break;
161 }
162 case PLAYER_SERVER_SET_PLAYER_CALLBACK: {
163 break;
164 }
165 case PLAYER_SERVER_GET_STATE: {
166 int32_t *ret = static_cast<int32_t *>(para->ret);
167 ReadInt32(reply, ret);
168 int32_t *data = static_cast<int32_t *>(para->data);
169 ReadInt32(reply, data);
170 break;
171 }
172 case PLAYER_SERVER_SET_SPEED: {
173 int32_t *ret = static_cast<int32_t *>(para->ret);
174 ReadInt32(reply, ret);
175 break;
176 }
177 case PLAYER_SERVER_GET_SPEED: {
178 int32_t *ret = static_cast<int32_t *>(para->ret);
179 ReadInt32(reply, ret);
180 float *data = static_cast<float *>(para->data);
181 ReadFloat(reply, data);
182 break;
183 }
184 case PLAYER_SERVER_SET_AUDIO_STREAM_TYPE: {
185 int32_t *ret = static_cast<int32_t *>(para->ret);
186 ReadInt32(reply, ret);
187 break;
188 }
189 case PLAYER_SERVER_GET_AUDIO_STREAM_TYPE: {
190 int32_t *ret = static_cast<int32_t *>(para->ret);
191 ReadInt32(reply, ret);
192 int32_t *data = static_cast<int32_t *>(para->data);
193 ReadInt32(reply, data);
194 break;
195 }
196 case PLAYER_SERVER_SET_PARAMETER: {
197 int32_t *ret = static_cast<int32_t *>(para->ret);
198 ReadInt32(reply, ret);
199 break;
200 }
201 default:
202 break;
203 }
204 return 0;
205 }
206
SetSource(const Source & source)207 int32_t Player::PlayerClient::SetSource(const Source &source)
208 {
209 IpcIo io;
210 uint8_t tmpData[DEFAULT_IPC_SIZE];
211 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
212 int32_t sourceType = (int32_t)source.GetSourceType();
213 WriteInt32(&io, sourceType);
214 switch ((SourceType)sourceType) {
215 case SourceType::SOURCE_TYPE_URI: {
216 std::string uri = source.GetSourceUri();
217 const char* str = uri.c_str();
218 WriteString(&io, str);
219 break;
220 }
221 case SourceType::SOURCE_TYPE_FD:
222 MEDIA_ERR_LOG("unsupported now: SOURCE_TYPE_FD");
223 break;
224 case SourceType::SOURCE_TYPE_STREAM: {
225 break;
226 }
227 default:
228 break;
229 }
230 int32_t ans = -10;
231 CallBackPara para = {};
232 para.funcId = PLAYER_SERVER_SET_SOURCE;
233 para.ret = &ans;
234 para.type = sourceType;
235 para.data = (void *)&source;
236 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_SET_SOURCE, &io, ¶, Callback);
237 if (ret != 0) {
238 MEDIA_ERR_LOG("SetSource failed, ret=%u", ret);
239 }
240 return ans;
241 }
242
Prepare()243 int32_t Player::PlayerClient::Prepare()
244 {
245 IpcIo io;
246 uint8_t tmpData[DEFAULT_IPC_SIZE];
247 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
248 int32_t ans = -1;
249 CallBackPara para = {};
250 para.funcId = PLAYER_SERVER_PREPARE;
251 para.ret = &ans;
252 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_PREPARE, &io, ¶, Callback);
253 if (ret != 0) {
254 MEDIA_ERR_LOG("Prepare failed, ret=%u\n", ret);
255 }
256 return ans;
257 }
258
Play()259 int32_t Player::PlayerClient::Play()
260 {
261 IpcIo io;
262 uint8_t tmpData[DEFAULT_IPC_SIZE];
263 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
264 int32_t ans = -1;
265 CallBackPara para = {};
266 para.funcId = PLAYER_SERVER_PLAY;
267 para.ret = &ans;
268 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_PLAY, &io, ¶, Callback);
269 if (ret != 0) {
270 MEDIA_ERR_LOG("Play failed, ret=%u\n", ret);
271 }
272 return ans;
273 }
274
IsPlaying()275 bool Player::PlayerClient::IsPlaying()
276 {
277 IpcIo io;
278 uint8_t tmpData[DEFAULT_IPC_SIZE];
279 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
280 bool ans = false;
281 CallBackPara para = {};
282 para.funcId = PLAYER_SERVER_IS_PLAYING;
283 para.ret = &ans;
284 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_IS_PLAYING, &io, ¶, Callback);
285 if (ret != 0) {
286 MEDIA_ERR_LOG("IsPlaying failed, ret=%u\n", ret);
287 }
288 return ans;
289 }
290
Pause()291 int32_t Player::PlayerClient::Pause()
292 {
293 IpcIo io;
294 uint8_t tmpData[DEFAULT_IPC_SIZE];
295 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
296 int32_t ans = -1;
297 CallBackPara para = {};
298 para.funcId = PLAYER_SERVER_PAUSE;
299 para.ret = &ans;
300 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_PAUSE, &io, ¶, Callback);
301 if (ret != 0) {
302 MEDIA_ERR_LOG("Pause failed, ret=%u\n", ret);
303 }
304 return ans;
305 }
306
Stop()307 int32_t Player::PlayerClient::Stop()
308 {
309 IpcIo io;
310 uint8_t tmpData[DEFAULT_IPC_SIZE];
311 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
312 int32_t ans = -1;
313 CallBackPara para = {};
314 para.funcId = PLAYER_SERVER_STOP;
315 para.ret = &ans;
316 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_STOP, &io, ¶, Callback);
317 if (ret != 0) {
318 MEDIA_ERR_LOG("Stop failed, ret=%u\n", ret);
319 }
320 return ans;
321 }
Rewind(int64_t mSeconds,int32_t mode)322 int32_t Player::PlayerClient::Rewind(int64_t mSeconds, int32_t mode)
323 {
324 IpcIo io;
325 uint8_t tmpData[DEFAULT_IPC_SIZE];
326 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
327 WriteInt64(&io, mSeconds);
328 WriteInt32(&io, mode);
329 int32_t ans = -1;
330 CallBackPara para = {};
331 para.funcId = PLAYER_SERVER_REWIND;
332 para.ret = &ans;
333 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_REWIND, &io, ¶, Callback);
334 if (ret != 0) {
335 MEDIA_ERR_LOG("Rewind failed, ret=%u\n", ret);
336 }
337 return ans;
338 }
339
SetVolume(float leftVolume,float rightVolume)340 int32_t Player::PlayerClient::SetVolume(float leftVolume, float rightVolume)
341 {
342 IpcIo io;
343 uint8_t tmpData[DEFAULT_IPC_SIZE];
344 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
345 WriteRawData(&io, &leftVolume, sizeof(float));
346 WriteRawData(&io, &rightVolume, sizeof(float));
347 int32_t ans = -1;
348 CallBackPara para = {};
349 para.funcId = PLAYER_SERVER_SET_VOLUME;
350 para.ret = &ans;
351 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_SET_VOLUME, &io, ¶, Callback);
352 if (ret != 0) {
353 MEDIA_ERR_LOG("SetVolume failed, ret=%u\n", ret);
354 }
355 return ans;
356 }
357
SetSurface(Surface * surface)358 int32_t Player::PlayerClient::SetSurface(Surface *surface)
359 {
360 IpcIo io;
361 uint8_t tmpData[DEFAULT_IPC_SIZE];
362 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
363 std::string position_x = surface->GetUserData("region_position_x");
364 const char* str_x = position_x.c_str();
365 WriteString(&io, str_x);
366 std::string position_y = surface->GetUserData("region_position_y");
367 const char* str_y = position_y.c_str();
368 WriteString(&io, str_y);
369 std::string width = surface->GetUserData("region_width");
370 const char* str_width = width.c_str();
371 WriteString(&io, str_width);
372 std::string height = surface->GetUserData("region_height");
373 const char* str_height = height.c_str();
374 WriteString(&io, str_height);
375 int32_t ans = -1;
376 CallBackPara para = {};
377 para.funcId = PLAYER_SERVER_SET_VIDEO_SURFACE;
378 para.ret = &ans;
379 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_SET_VIDEO_SURFACE, &io, ¶, Callback);
380 if (ret != 0) {
381 MEDIA_ERR_LOG("SetSurface failed, ret=%u\n", ret);
382 }
383 return ans;
384 }
385
SetLoop(bool loop)386 int32_t Player::PlayerClient::SetLoop(bool loop)
387 {
388 IpcIo io;
389 uint8_t tmpData[DEFAULT_IPC_SIZE];
390 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
391 WriteBool(&io, loop);
392 int32_t ans = -1;
393 CallBackPara para = {};
394 para.funcId = PLAYER_SERVER_ENABLE_SINGLE_LOOPING;
395 para.ret = &ans;
396 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_ENABLE_SINGLE_LOOPING, &io, ¶, Callback);
397 if (ret != 0) {
398 MEDIA_ERR_LOG("SetLoop failed, ret=%u\n", ret);
399 }
400 return ans;
401 }
402
IsSingleLooping()403 bool Player::PlayerClient::IsSingleLooping()
404 {
405 IpcIo io;
406 uint8_t tmpData[DEFAULT_IPC_SIZE];
407 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
408 bool ans = false;
409 CallBackPara para = {};
410 para.funcId = PLAYER_SERVER_IS_SINGLE_LOOPING;
411 para.ret = &ans;
412 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_IS_SINGLE_LOOPING, &io, ¶, Callback);
413 if (ret != 0) {
414 MEDIA_ERR_LOG("IsSingleLooping failed, ret=%u\n", ret);
415 }
416 return ans;
417 }
418
GetCurrentPosition(int64_t & time) const419 int32_t Player::PlayerClient::GetCurrentPosition(int64_t &time) const
420 {
421 IpcIo io;
422 uint8_t tmpData[DEFAULT_IPC_SIZE];
423 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
424 int32_t ans = -1;
425
426 CallBackPara para = {};
427 para.funcId = PLAYER_SERVER_GET_CURRENT_TIME;
428 para.ret = &ans;
429 para.data = &time;
430 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_GET_CURRENT_TIME, &io, ¶, Callback);
431 if (ret != 0) {
432 MEDIA_ERR_LOG("GetCurrentPosition failed, ret=%u\n", ret);
433 }
434 return ans;
435 }
436
GetDuration(int64_t & duration) const437 int32_t Player::PlayerClient::GetDuration(int64_t &duration) const
438 {
439 IpcIo io;
440 uint8_t tmpData[DEFAULT_IPC_SIZE];
441 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
442 int32_t ans = -1;
443 CallBackPara para = {};
444 para.funcId = PLAYER_SERVER_GET_DURATION;
445 para.ret = &ans;
446 para.data = &duration;
447 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_GET_DURATION, &io, ¶, Callback);
448 if (ret != 0) {
449 MEDIA_ERR_LOG("GetDuration failed, ret=%u\n", ret);
450 }
451 return ans;
452 }
GetVideoWidth(int32_t & videoWidth)453 int32_t Player::PlayerClient::GetVideoWidth(int32_t &videoWidth)
454 {
455 IpcIo io;
456 uint8_t tmpData[DEFAULT_IPC_SIZE];
457 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
458 int32_t ans = -1;
459 CallBackPara para = {};
460 para.funcId = PLAYER_SERVER_GET_VIDEO_WIDTH;
461 para.ret = &ans;
462 para.data = &videoWidth;
463 int32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_GET_VIDEO_WIDTH, &io, ¶, Callback);
464 if (ret != 0) {
465 MEDIA_ERR_LOG("GetVideoWidth failed, ret=%d\n", ret);
466 }
467 return ans;
468 }
469
GetVideoHeight(int32_t & videoHeight)470 int32_t Player::PlayerClient::GetVideoHeight(int32_t &videoHeight)
471 {
472 IpcIo io;
473 uint8_t tmpData[DEFAULT_IPC_SIZE];
474 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
475 int32_t ans = -1;
476 CallBackPara para = {};
477 para.funcId = PLAYER_SERVER_GET_VIDEO_HEIGHT;
478 para.ret = &ans;
479 para.data = &videoHeight;
480 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_GET_VIDEO_HEIGHT, &io, ¶, Callback);
481 if (ret != 0) {
482 MEDIA_ERR_LOG("GetVideoHeight failed, ret=%u\n", ret);
483 }
484 return ans;
485 }
486
Reset()487 int32_t Player::PlayerClient::Reset()
488 {
489 IpcIo io;
490 uint8_t tmpData[DEFAULT_IPC_SIZE];
491 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
492 int32_t ans = -1;
493 CallBackPara para = {};
494 para.funcId = PLAYER_SERVER_RESET;
495 para.ret = &ans;
496 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_RESET, &io, ¶, Callback);
497 if (ret != 0) {
498 MEDIA_ERR_LOG("Reset failed, ret=%u\n", ret);
499 }
500 return ans;
501 }
502
Release()503 int32_t Player::PlayerClient::Release()
504 {
505 if (sid_ != nullptr) {
506 delete sid_;
507 sid_ = nullptr;
508 }
509 IpcIo io;
510 uint8_t tmpData[DEFAULT_IPC_SIZE];
511 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
512 int32_t ans = -1;
513 CallBackPara para = {};
514 para.funcId = PLAYER_SERVER_RELEASE;
515 para.ret = &ans;
516 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_RELEASE, &io, ¶, Callback);
517 if (ret != 0) {
518 MEDIA_ERR_LOG("Release failed, ret=%u\n", ret);
519 }
520 return ans;
521 }
522
PlayerCommonCallback(uint32_t code,IpcIo * data,IpcIo * reply,MessageOption option)523 int32_t Player::PlayerClient::PlayerCommonCallback(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option)
524 {
525 auto playerCallback = static_cast<PlayerCallback *>(option.args);
526 if (playerCallback == nullptr) {
527 MEDIA_ERR_LOG("call back error, playerCallback is null");
528 return -1;
529 }
530 MEDIA_INFO_LOG("PlayerCommonCallback, funcId=%d", code);
531 switch (code) {
532 case ON_PLAYBACK_COMPLETE: {
533 playerCallback->OnPlaybackComplete();
534 break;
535 }
536 case ON_ERROR: {
537 int32_t errorType;
538 ReadInt32(data, &errorType);
539 int32_t errorCode;
540 ReadInt32(data, &errorCode);
541 playerCallback->OnError(errorType, errorCode);
542 break;
543 }
544 case ON_INFO: {
545 int32_t type;
546 ReadInt32(data, &type);
547 int32_t extra;
548 ReadInt32(data, &extra);
549 playerCallback->OnInfo(type, extra);
550 break;
551 }
552 case ON_VIDEO_SIZE_CHANGED: {
553 int32_t width;
554 ReadInt32(data, &width);
555 int32_t height;
556 ReadInt32(data, &height);
557 playerCallback->OnVideoSizeChanged(width, height);
558 break;
559 }
560 case ON_REWIND_TO_COMPLETE: {
561 playerCallback->OnRewindToComplete();
562 break;
563 }
564 default: {
565 MEDIA_ERR_LOG("unsupported funId\n");
566 break;
567 }
568 }
569 return 0;
570 }
571
SetPlayerCallback(const std::shared_ptr<PlayerCallback> & cb)572 void Player::PlayerClient::SetPlayerCallback(const std::shared_ptr<PlayerCallback> &cb)
573 {
574 MEDIA_INFO_LOG("PlayerClient::SetPlayerCallback\n");
575 if (sid_ == nullptr) {
576 sid_ = new SvcIdentity();
577 }
578 objectStub_.func = PlayerCommonCallback;
579 objectStub_.args = (void*)cb.get();
580 objectStub_.isRemote = false;
581 sid_->handle = IPC_INVALID_HANDLE;
582 sid_->token = SERVICE_TYPE_ANONYMOUS;
583 sid_->cookie = reinterpret_cast<uintptr_t>(&objectStub_);
584 IpcIo io;
585 uint8_t tmpData[DEFAULT_IPC_SIZE];
586 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 1);
587 bool writeRemote = WriteRemoteObject(&io, sid_);
588 if (!writeRemote) {
589 return;
590 }
591 CallBackPara para = {};
592 para.funcId = PLAYER_SERVER_SET_PLAYER_CALLBACK;
593 uint32_t ans = proxy_->Invoke(proxy_, PLAYER_SERVER_SET_PLAYER_CALLBACK, &io, ¶, Callback);
594 if (ans != 0) {
595 MEDIA_ERR_LOG("SetPlayerCallback : Invoke failed, ret=%u\n", ans);
596 }
597 }
598
GetPlayerState(int32_t & state) const599 int32_t Player::PlayerClient::GetPlayerState(int32_t &state) const
600 {
601 IpcIo io;
602 uint8_t tmpData[DEFAULT_IPC_SIZE];
603 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
604 int32_t ans = -1;
605 CallBackPara para = {};
606 para.funcId = PLAYER_SERVER_GET_STATE;
607 para.ret = &ans;
608 para.data = &state;
609 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_GET_STATE, &io, ¶, Callback);
610 if (ret != 0) {
611 MEDIA_ERR_LOG("GetPlayerState failed, ret=%u\n", ret);
612 }
613 return ans;
614 }
615
SetPlaybackSpeed(float speed)616 int32_t Player::PlayerClient::SetPlaybackSpeed(float speed)
617 {
618 IpcIo io;
619 uint8_t tmpData[DEFAULT_IPC_SIZE];
620 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
621 WriteFloat(&io, speed);
622 int32_t ans = -1;
623 CallBackPara para = {};
624 para.funcId = PLAYER_SERVER_SET_SPEED;
625 para.ret = &ans;
626 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_SET_SPEED, &io, ¶, Callback);
627 if (ret != 0) {
628 MEDIA_ERR_LOG("SetPlaybackSpeed failed, ret=%u\n", ret);
629 }
630 return ans;
631 }
632
GetPlaybackSpeed(float & speed)633 int32_t Player::PlayerClient::GetPlaybackSpeed(float &speed)
634 {
635 IpcIo io;
636 uint8_t tmpData[DEFAULT_IPC_SIZE];
637 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
638 int32_t ans = -1;
639 CallBackPara para = {};
640 para.funcId = PLAYER_SERVER_GET_SPEED;
641 para.ret = &ans;
642 para.data = &speed;
643 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_GET_SPEED, &io, ¶, Callback);
644 if (ret != 0) {
645 MEDIA_ERR_LOG("GetPlaybackSpeed failed, ret=%u\n", ret);
646 }
647 return ans;
648 }
649
SetParameter(const Format & params)650 int32_t Player::PlayerClient::SetParameter(const Format ¶ms)
651 {
652 IpcIo io;
653 uint8_t tmpData[DEFAULT_IPC_SIZE];
654 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
655
656 std::map<std::string, FormatData *> formatParam = params.GetFormatMap();
657 WriteInt32(&io, formatParam.size()); /* count */
658
659 std::map<std::string, FormatData *> ::iterator iter;
660 for (iter = formatParam.begin(); iter != formatParam.end(); iter++) {
661 WriteString(&io, iter->first.c_str()); /* key */
662 FormatData *data = iter->second;
663 FormatDataType type = data->GetType();
664 WriteInt32(&io, (int32_t)type); /* type */
665
666 /* value */
667 if (type == FORMAT_TYPE_INT32) {
668 int32_t value;
669 data->GetInt32Value(value);
670 WriteInt32(&io, value);
671 } else if (type == FORMAT_TYPE_INT64) {
672 int64_t value;
673 data->GetInt64Value(value);
674 WriteInt64(&io, value);
675 } else if (type == FORMAT_TYPE_FLOAT) {
676 float value;
677 data->GetFloatValue(value);
678 WriteFloat(&io, value);
679 } else if (type == FORMAT_TYPE_DOUBLE) {
680 double value;
681 data->GetDoubleValue(value);
682 WriteDouble(&io, value);
683 } else if (type == FORMAT_TYPE_STRING) {
684 std::string value;
685 data->GetStringValue(value);
686 WriteString(&io, value.c_str());
687 } else {
688 MEDIA_ERR_LOG("SetParameter failed, type:%d\n", type);
689 return -1;
690 }
691 }
692
693 int32_t ans = -1;
694 CallBackPara para = {};
695 para.funcId = PLAYER_SERVER_SET_PARAMETER;
696 para.ret = &ans;
697 int32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_SET_PARAMETER, &io, ¶, Callback);
698 if (ret != 0) {
699 MEDIA_ERR_LOG("PlayerClient::SetParameter failed, ret=%d\n", ret);
700 }
701 return ans;
702 }
703
SetAudioStreamType(int32_t type)704 int32_t Player::PlayerClient::SetAudioStreamType(int32_t type)
705 {
706 IpcIo io;
707 uint8_t tmpData[DEFAULT_IPC_SIZE];
708 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
709 WriteInt32(&io, type);
710 int32_t ans = -1;
711 CallBackPara para = {};
712 para.funcId = PLAYER_SERVER_SET_AUDIO_STREAM_TYPE;
713 para.ret = &ans;
714 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_SET_AUDIO_STREAM_TYPE, &io, ¶, Callback);
715 if (ret != 0) {
716 MEDIA_ERR_LOG("SetPlaybackSpeed failed, ret=%u\n", ret);
717 }
718 return ans;
719 }
720
GetAudioStreamType(int32_t & type)721 void Player::PlayerClient::GetAudioStreamType(int32_t &type)
722 {
723 IpcIo io;
724 uint8_t tmpData[DEFAULT_IPC_SIZE];
725 IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
726 int32_t ans = -1;
727 CallBackPara para = {};
728 para.funcId = PLAYER_SERVER_GET_AUDIO_STREAM_TYPE;
729 para.ret = &ans;
730 para.data = &type;
731 uint32_t ret = proxy_->Invoke(proxy_, PLAYER_SERVER_GET_AUDIO_STREAM_TYPE, &io, ¶, Callback);
732 if (ret != 0) {
733 MEDIA_ERR_LOG("GetPlaybackSpeed failed, ret=%u\n", ret);
734 }
735 }
736 }
737 }
738