comparison deps/Platinum/Source/Devices/MediaRenderer/PltMediaController.cpp @ 0:3425707ddbf6

Initial import (hopefully this mercurial stuff works...)
author fraserofthenight
date Mon, 06 Jul 2009 08:06:28 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3425707ddbf6
1 /*****************************************************************
2 |
3 | Platinum - AV Media Controller (Media Renderer Control Point)
4 |
5 | Copyright (c) 2004-2008, Plutinosoft, LLC.
6 | All rights reserved.
7 | http://www.plutinosoft.com
8 |
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
13 |
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 |
21 | This program is distributed in the hope that it will be useful,
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | GNU General Public License for more details.
25 |
26 | You should have received a copy of the GNU General Public License
27 | along with this program; see the file LICENSE.txt. If not, write to
28 | the Free Software Foundation, Inc.,
29 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 | http://www.gnu.org/licenses/gpl-2.0.html
31 |
32 ****************************************************************/
33
34 /*----------------------------------------------------------------------
35 | includes
36 +---------------------------------------------------------------------*/
37 #include "Neptune.h"
38 #include "PltMediaController.h"
39 #include "PltDidl.h"
40 #include "PltDeviceData.h"
41 #include "PltXmlHelper.h"
42
43 NPT_SET_LOCAL_LOGGER("platinum.media.renderer.controller")
44
45 /*----------------------------------------------------------------------
46 | PLT_MediaController::PLT_MediaController
47 +---------------------------------------------------------------------*/
48 PLT_MediaController::PLT_MediaController(PLT_CtrlPointReference& ctrl_point,
49 PLT_MediaControllerDelegate* delegate /* = NULL */) :
50 m_CtrlPoint(ctrl_point),
51 m_Delegate(delegate)
52 {
53 m_CtrlPoint->AddListener(this);
54 }
55
56 /*----------------------------------------------------------------------
57 | PLT_MediaController::~PLT_MediaController
58 +---------------------------------------------------------------------*/
59 PLT_MediaController::~PLT_MediaController()
60 {
61 m_CtrlPoint->RemoveListener(this);
62 }
63
64 /*----------------------------------------------------------------------
65 | PLT_MediaController::OnDeviceAdded
66 +---------------------------------------------------------------------*/
67 NPT_Result
68 PLT_MediaController::OnDeviceAdded(PLT_DeviceDataReference& device)
69 {
70 PLT_DeviceDataReference data;
71 NPT_String uuid = device->GetUUID();
72 // is it a new device?
73 if (NPT_SUCCEEDED(NPT_ContainerFind(m_MediaRenderers, PLT_DeviceDataFinder(uuid), data))) {
74 NPT_LOG_FINE_1("Device (%s) is already in our list!", (const char*)uuid);
75 return NPT_FAILURE;
76 }
77
78 NPT_LOG_FINE("Device Found:");
79 device->ToLog(NPT_LOG_LEVEL_FINE);
80
81 // verify the device implements the function we need
82 PLT_Service* serviceAVT;
83 PLT_Service* serviceCMR;
84 NPT_String type;
85
86 type = "urn:schemas-upnp-org:service:AVTransport:1";
87 if (NPT_FAILED(device->FindServiceByType(type, serviceAVT))) {
88 NPT_LOG_FINE_1("Service %s not found", (const char*)type);
89 return NPT_FAILURE;
90 }
91
92 type = "urn:schemas-upnp-org:service:ConnectionManager:1";
93 if (NPT_FAILED(device->FindServiceByType(type, serviceCMR))) {
94 NPT_LOG_FINE_1("Service %s not found", (const char*)type);
95 return NPT_FAILURE;
96 }
97
98 m_MediaRenderers.Add(device);
99
100 if (m_Delegate && m_Delegate->OnMRAdded(device)) {
101 // subscribe to AVT eventing if delegate wants it
102 m_CtrlPoint->Subscribe(serviceAVT);
103 }
104
105 return NPT_SUCCESS;
106 }
107
108 /*----------------------------------------------------------------------
109 | PLT_MediaController::OnDeviceRemoved
110 +---------------------------------------------------------------------*/
111 NPT_Result
112 PLT_MediaController::OnDeviceRemoved(PLT_DeviceDataReference& device)
113 {
114 // only release if we have kept it around
115 PLT_DeviceDataReference data;
116 NPT_String uuid = device->GetUUID();
117 // is it a new device?
118 if (NPT_FAILED(NPT_ContainerFind(m_MediaRenderers, PLT_DeviceDataFinder(uuid), data))) {
119 NPT_LOG_FINE_1("Device (%s) not found in our list!", (const char*)uuid);
120 return NPT_FAILURE;
121 }
122
123 NPT_LOG_FINE("Device Removed:");
124 device->ToLog(NPT_LOG_LEVEL_FINE);
125
126 if (m_Delegate) {
127 m_Delegate->OnMRRemoved(device);
128 }
129
130 m_MediaRenderers.Remove(device);
131 return NPT_SUCCESS;
132 }
133
134 /*----------------------------------------------------------------------
135 | PLT_MediaController::FindActionDesc
136 +---------------------------------------------------------------------*/
137 NPT_Result
138 PLT_MediaController::FindActionDesc(PLT_DeviceDataReference& device,
139 const char* service_type,
140 const char* action_name,
141 PLT_ActionDesc*& action_desc)
142 {
143 // look for the service
144 PLT_Service* service;
145 if (NPT_FAILED(device->FindServiceByType(service_type, service))) {
146 NPT_LOG_FINE_1("Service %s not found", (const char*)service_type);
147 return NPT_FAILURE;
148 }
149
150 action_desc = service->FindActionDesc(action_name);
151 if (action_desc == NULL) {
152 NPT_LOG_FINE_1("Action %s not found in service", action_name);
153 return NPT_FAILURE;
154 }
155
156 return NPT_SUCCESS;
157 }
158
159 /*----------------------------------------------------------------------
160 | PLT_MediaController::CreateAction
161 +---------------------------------------------------------------------*/
162 NPT_Result
163 PLT_MediaController::CreateAction(PLT_DeviceDataReference& device,
164 const char* service_type,
165 const char* action_name,
166 PLT_ActionReference& action)
167 {
168 PLT_ActionDesc* action_desc;
169 NPT_CHECK_SEVERE(FindActionDesc(device, service_type, action_name, action_desc));
170 action = new PLT_Action(action_desc);
171 return NPT_SUCCESS;
172 }
173
174 /*----------------------------------------------------------------------
175 | PLT_MediaController::CallAVTransportAction
176 +---------------------------------------------------------------------*/
177 NPT_Result
178 PLT_MediaController::CallAVTransportAction(PLT_ActionReference& action,
179 NPT_UInt32 instance_id,
180 void* userdata)
181 {
182 // Set the object id
183 NPT_CHECK_SEVERE(action->SetArgumentValue("InstanceID",
184 NPT_String::FromInteger(instance_id)));
185
186 // set the arguments on the action, this will check the argument values
187 return m_CtrlPoint->InvokeAction(action, userdata);
188 }
189
190 /*----------------------------------------------------------------------
191 | PLT_MediaController::GetCurrentTransportActions
192 +---------------------------------------------------------------------*/
193 NPT_Result
194 PLT_MediaController::GetCurrentTransportActions(PLT_DeviceDataReference& device,
195 NPT_UInt32 instance_id,
196 void* userdata)
197 {
198 PLT_ActionReference action;
199 NPT_CHECK_SEVERE(CreateAction(device,
200 "urn:schemas-upnp-org:service:AVTransport:1",
201 "GetCurrentTransportActions",
202 action));
203 return CallAVTransportAction(action, instance_id, userdata);
204 }
205
206 /*----------------------------------------------------------------------
207 | PLT_MediaController::GetDeviceCapabilities
208 +---------------------------------------------------------------------*/
209 NPT_Result
210 PLT_MediaController::GetDeviceCapabilities(PLT_DeviceDataReference& device,
211 NPT_UInt32 instance_id,
212 void* userdata)
213 {
214 PLT_ActionReference action;
215 NPT_CHECK_SEVERE(CreateAction(device,
216 "urn:schemas-upnp-org:service:AVTransport:1",
217 "GetDeviceCapabilities",
218 action));
219 return CallAVTransportAction(action, instance_id, userdata);
220 }
221
222 /*----------------------------------------------------------------------
223 | PLT_MediaController::GetMediaInfo
224 +---------------------------------------------------------------------*/
225 NPT_Result
226 PLT_MediaController::GetMediaInfo(PLT_DeviceDataReference& device,
227 NPT_UInt32 instance_id,
228 void* userdata)
229 {
230 PLT_ActionReference action;
231 NPT_CHECK_SEVERE(CreateAction(device,
232 "urn:schemas-upnp-org:service:AVTransport:1",
233 "GetMediaInfo",
234 action));
235 return CallAVTransportAction(action, instance_id, userdata);
236 }
237
238 /*----------------------------------------------------------------------
239 | PLT_MediaController::GetPositionInfo
240 +---------------------------------------------------------------------*/
241 NPT_Result
242 PLT_MediaController::GetPositionInfo(PLT_DeviceDataReference& device,
243 NPT_UInt32 instance_id,
244 void* userdata)
245 {
246 PLT_ActionReference action;
247 NPT_CHECK_SEVERE(CreateAction(device,
248 "urn:schemas-upnp-org:service:AVTransport:1",
249 "GetPositionInfo",
250 action));
251 return CallAVTransportAction(action, instance_id, userdata);
252 }
253
254 /*----------------------------------------------------------------------
255 | PLT_MediaController::GetTransportInfo
256 +---------------------------------------------------------------------*/
257 NPT_Result
258 PLT_MediaController::GetTransportInfo(PLT_DeviceDataReference& device,
259 NPT_UInt32 instance_id,
260 void* userdata)
261 {
262 PLT_ActionReference action;
263 NPT_CHECK_SEVERE(CreateAction(device,
264 "urn:schemas-upnp-org:service:AVTransport:1",
265 "GetTransportInfo",
266 action));
267 return CallAVTransportAction(action, instance_id, userdata);
268 }
269
270 /*----------------------------------------------------------------------
271 | PLT_MediaController::GetTransportSettings
272 +---------------------------------------------------------------------*/
273 NPT_Result
274 PLT_MediaController::GetTransportSettings(PLT_DeviceDataReference& device,
275 NPT_UInt32 instance_id,
276 void* userdata)
277 {
278 PLT_ActionReference action;
279 NPT_CHECK_SEVERE(CreateAction(device,
280 "urn:schemas-upnp-org:service:AVTransport:1",
281 "GetTransportSettings",
282 action));
283 return CallAVTransportAction(action, instance_id, userdata);
284 }
285
286 /*----------------------------------------------------------------------
287 | PLT_MediaController::Next
288 +---------------------------------------------------------------------*/
289 NPT_Result
290 PLT_MediaController::Next(PLT_DeviceDataReference& device,
291 NPT_UInt32 instance_id,
292 void* userdata)
293 {
294 PLT_ActionReference action;
295 NPT_CHECK_SEVERE(CreateAction(device,
296 "urn:schemas-upnp-org:service:AVTransport:1",
297 "Next",
298 action));
299 return CallAVTransportAction(action, instance_id, userdata);
300 }
301
302 /*----------------------------------------------------------------------
303 | PLT_MediaController::Pause
304 +---------------------------------------------------------------------*/
305 NPT_Result
306 PLT_MediaController::Pause(PLT_DeviceDataReference& device,
307 NPT_UInt32 instance_id,
308 void* userdata)
309 {
310 PLT_ActionReference action;
311 NPT_CHECK_SEVERE(CreateAction(device,
312 "urn:schemas-upnp-org:service:AVTransport:1",
313 "Pause",
314 action));
315 return CallAVTransportAction(action, instance_id, userdata);
316 }
317
318 /*----------------------------------------------------------------------
319 | PLT_MediaController::Play
320 +---------------------------------------------------------------------*/
321 NPT_Result
322 PLT_MediaController::Play(PLT_DeviceDataReference& device,
323 NPT_UInt32 instance_id,
324 NPT_String speed,
325 void* userdata)
326 {
327 PLT_ActionReference action;
328 NPT_CHECK_SEVERE(CreateAction(device,
329 "urn:schemas-upnp-org:service:AVTransport:1",
330 "Play",
331 action));
332
333 // Set the speed
334 if (NPT_FAILED(action->SetArgumentValue("Speed", speed))) {
335 return NPT_ERROR_INVALID_PARAMETERS;
336 }
337
338 return CallAVTransportAction(action, instance_id, userdata);
339 }
340
341 /*----------------------------------------------------------------------
342 | PLT_MediaController::Previous
343 +---------------------------------------------------------------------*/
344 NPT_Result
345 PLT_MediaController::Previous(PLT_DeviceDataReference& device,
346 NPT_UInt32 instance_id,
347 void* userdata)
348 {
349 PLT_ActionReference action;
350 NPT_CHECK_SEVERE(CreateAction(device,
351 "urn:schemas-upnp-org:service:AVTransport:1",
352 "Previous",
353 action));
354 return CallAVTransportAction(action, instance_id, userdata);
355 }
356
357 /*----------------------------------------------------------------------
358 | PLT_MediaController::Seek
359 +---------------------------------------------------------------------*/
360 NPT_Result
361 PLT_MediaController::Seek(PLT_DeviceDataReference& device,
362 NPT_UInt32 instance_id,
363 NPT_String unit,
364 NPT_String target,
365 void* userdata)
366 {
367 PLT_ActionReference action;
368 NPT_CHECK_SEVERE(CreateAction(device,
369 "urn:schemas-upnp-org:service:AVTransport:1",
370 "Seek",
371 action));
372
373 // Set the unit
374 if (NPT_FAILED(action->SetArgumentValue("Unit", unit))) {
375 return NPT_ERROR_INVALID_PARAMETERS;
376 }
377
378 // Set the target
379 if (NPT_FAILED(action->SetArgumentValue("Target", target))) {
380 return NPT_ERROR_INVALID_PARAMETERS;
381 }
382
383 return CallAVTransportAction(action, instance_id, userdata);
384 }
385
386 /*----------------------------------------------------------------------
387 | PLT_MediaController::SetAVTransportURI
388 +---------------------------------------------------------------------*/
389 NPT_Result
390 PLT_MediaController::SetAVTransportURI(PLT_DeviceDataReference& device,
391 NPT_UInt32 instance_id,
392 const char* uri,
393 const char* metadata,
394 void* userdata)
395 {
396 PLT_ActionReference action;
397 NPT_CHECK_SEVERE(CreateAction(device,
398 "urn:schemas-upnp-org:service:AVTransport:1",
399 "SetAVTransportURI",
400 action));
401
402 // set the uri
403 if (NPT_FAILED(action->SetArgumentValue("CurrentURI", uri))) {
404 return NPT_ERROR_INVALID_PARAMETERS;
405 }
406
407 // set the uri metadata
408 if (NPT_FAILED(action->SetArgumentValue("CurrentURIMetaData", metadata))) {
409 return NPT_ERROR_INVALID_PARAMETERS;
410 }
411
412 return CallAVTransportAction(action, instance_id, userdata);
413 }
414
415 /*----------------------------------------------------------------------
416 | PLT_MediaController::SetPlayMode
417 +---------------------------------------------------------------------*/
418 NPT_Result
419 PLT_MediaController::SetPlayMode(PLT_DeviceDataReference& device,
420 NPT_UInt32 instance_id,
421 NPT_String new_play_mode,
422 void* userdata)
423 {
424 PLT_ActionReference action;
425 NPT_CHECK_SEVERE(CreateAction(device,
426 "urn:schemas-upnp-org:service:AVTransport:1",
427 "SetPlayMode",
428 action));
429
430 // set the New PlayMode
431 if (NPT_FAILED(action->SetArgumentValue("NewPlayMode", new_play_mode))) {
432 return NPT_ERROR_INVALID_PARAMETERS;
433 }
434
435 return CallAVTransportAction(action, instance_id, userdata);
436 }
437
438 /*----------------------------------------------------------------------
439 | PLT_MediaController::Stop
440 +---------------------------------------------------------------------*/
441 NPT_Result
442 PLT_MediaController::Stop(PLT_DeviceDataReference& device,
443 NPT_UInt32 instance_id,
444 void* userdata)
445 {
446 PLT_ActionReference action;
447 NPT_CHECK_SEVERE(CreateAction(device,
448 "urn:schemas-upnp-org:service:AVTransport:1",
449 "Stop",
450 action));
451 return CallAVTransportAction(action, instance_id, userdata);
452 }
453
454 /*----------------------------------------------------------------------
455 | PLT_MediaController::GetCurrentConnectionIDs
456 +---------------------------------------------------------------------*/
457 NPT_Result
458 PLT_MediaController::GetCurrentConnectionIDs(PLT_DeviceDataReference& device,
459 void* userdata)
460 {
461 PLT_ActionReference action;
462 NPT_CHECK_SEVERE(CreateAction(device,
463 "urn:schemas-upnp-org:service:ConnectionManager:1",
464 "GetCurrentConnectionIDs",
465 action));
466
467 // set the arguments on the action, this will check the argument values
468 if (NPT_FAILED(m_CtrlPoint->InvokeAction(action, userdata))) {
469 return NPT_ERROR_INVALID_PARAMETERS;
470 }
471
472 return NPT_SUCCESS;
473 }
474
475 /*----------------------------------------------------------------------
476 | PLT_MediaController::GetCurrentConnectionInfo
477 +---------------------------------------------------------------------*/
478 NPT_Result
479 PLT_MediaController::GetCurrentConnectionInfo(PLT_DeviceDataReference& device,
480 NPT_UInt32 connection_id,
481 void* userdata)
482 {
483 PLT_ActionReference action;
484 NPT_CHECK_SEVERE(CreateAction(device,
485 "urn:schemas-upnp-org:service:ConnectionManager:1",
486 "GetCurrentConnectionInfo",
487 action));
488
489 // set the New PlayMode
490 if (NPT_FAILED(action->SetArgumentValue("ConnectionID", NPT_String::FromInteger(connection_id)))) {
491 return NPT_ERROR_INVALID_PARAMETERS;
492 }
493
494 // set the arguments on the action, this will check the argument values
495 if (NPT_FAILED(m_CtrlPoint->InvokeAction(action, userdata))) {
496 return NPT_ERROR_INVALID_PARAMETERS;
497 }
498
499 return NPT_SUCCESS;
500 }
501
502 /*----------------------------------------------------------------------
503 | PLT_MediaController::GetProtocolInfo
504 +---------------------------------------------------------------------*/
505 NPT_Result
506 PLT_MediaController::GetProtocolInfo(PLT_DeviceDataReference& device,
507 void* userdata)
508 {
509 PLT_ActionReference action;
510 NPT_CHECK_SEVERE(CreateAction(device,
511 "urn:schemas-upnp-org:service:ConnectionManager:1",
512 "GetProtocolInfo",
513 action));
514
515 // set the arguments on the action, this will check the argument values
516 if (NPT_FAILED(m_CtrlPoint->InvokeAction(action, userdata))) {
517 return NPT_ERROR_INVALID_PARAMETERS;
518 }
519
520 return NPT_SUCCESS;
521 }
522
523 /*----------------------------------------------------------------------
524 | PLT_MediaController::OnActionResponse
525 +---------------------------------------------------------------------*/
526 NPT_Result
527 PLT_MediaController::OnActionResponse(NPT_Result res, PLT_ActionReference& action, void* userdata)
528 {
529 if (m_Delegate == NULL) return NPT_SUCCESS;
530
531 /* make sure device is a renderer we've previously found */
532 PLT_DeviceDataReference device;
533 NPT_String uuid = action->GetActionDesc()->GetService()->GetDevice()->GetUUID();
534 if (NPT_FAILED(NPT_ContainerFind(m_MediaRenderers, PLT_DeviceDataFinder(uuid), device))) {
535 NPT_LOG_FINE_1("Device (%s) not found in our list of renderers", (const char*)uuid);
536 res = NPT_FAILURE;
537 }
538
539 /* extract action name */
540 NPT_String actionName = action->GetActionDesc()->GetName();
541
542 /* AVTransport response ? */
543 if (actionName.Compare("GetCurrentTransportActions", true) == 0) {
544 return OnGetCurrentTransportActionsResponse(res, device, action, userdata);
545 }
546 else if (actionName.Compare("GetDeviceCapabilities", true) == 0) {
547 return OnGetDeviceCapabilitiesResponse(res, device, action, userdata);
548 }
549 else if (actionName.Compare("GetMediaInfo", true) == 0) {
550 return OnGetMediaInfoResponse(res, device, action, userdata);
551 }
552 else if (actionName.Compare("GetPositionInfo", true) == 0) {
553 return OnGetPositionInfoResponse(res, device, action, userdata);
554 }
555 else if (actionName.Compare("GetTransportInfo", true) == 0) {
556 return OnGetTransportInfoResponse(res, device, action, userdata);
557 }
558 else if (actionName.Compare("GetTransportSettings", true) == 0) {
559 return OnGetTransportSettingsResponse(res, device, action, userdata);
560 }
561 else if (actionName.Compare("Next", true) == 0) {
562 m_Delegate->OnNextResult(res, device, userdata);
563 }
564 else if (actionName.Compare("Pause", true) == 0) {
565 m_Delegate->OnPauseResult(res, device, userdata);
566 }
567 else if (actionName.Compare("Play", true) == 0) {
568 m_Delegate->OnPlayResult(res, device, userdata);
569 }
570 else if (actionName.Compare("Previous", true) == 0) {
571 m_Delegate->OnPreviousResult(res, device, userdata);
572 }
573 else if (actionName.Compare("Seek", true) == 0) {
574 m_Delegate->OnSeekResult(res, device, userdata);
575 }
576 else if (actionName.Compare("SetAVTransportURI", true) == 0) {
577 m_Delegate->OnSetAVTransportURIResult(res, device, userdata);
578 }
579 else if (actionName.Compare("SetPlayMode", true) == 0) {
580 m_Delegate->OnSetPlayModeResult(res, device, userdata);
581 }
582 else if (actionName.Compare("Stop", true) == 0) {
583 m_Delegate->OnStopResult(res, device, userdata);
584 }
585 else if (actionName.Compare("GetCurrentConnectionIDs", true) == 0) {
586 return OnGetCurrentConnectionIDsResponse(res, device, action, userdata);
587 }
588 else if (actionName.Compare("GetCurrentConnectionInfo", true) == 0) {
589 return OnGetCurrentConnectionInfoResponse(res, device, action, userdata);
590 }
591 else if (actionName.Compare("GetProtocolInfo", true) == 0) {
592 return OnGetProtocolInfoResponse(res, device, action, userdata);
593 }
594
595 return NPT_SUCCESS;
596 }
597
598 /*----------------------------------------------------------------------
599 | PLT_MediaController::OnGetCurrentTransportActionsResponse
600 +---------------------------------------------------------------------*/
601 NPT_Result
602 PLT_MediaController::OnGetCurrentTransportActionsResponse(NPT_Result res,
603 PLT_DeviceDataReference& device,
604 PLT_ActionReference& action,
605 void* userdata)
606 {
607 NPT_String actions;
608 PLT_StringList values;
609
610 if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
611 goto bad_action;
612 }
613
614 if (NPT_FAILED(action->GetArgumentValue("Actions", actions))) {
615 goto bad_action;
616 }
617
618 // parse the list of actions and return a list to listener
619 ParseCSV(actions, values);
620
621 m_Delegate->OnGetCurrentTransportActionsResult(NPT_SUCCESS, device, &values, userdata);
622 return NPT_SUCCESS;
623
624 bad_action:
625 m_Delegate->OnGetCurrentTransportActionsResult(NPT_FAILURE, device, NULL, userdata);
626 return NPT_FAILURE;
627 }
628
629 /*----------------------------------------------------------------------
630 | PLT_MediaController::OnGetDeviceCapabilitiesResponse
631 +---------------------------------------------------------------------*/
632 NPT_Result
633 PLT_MediaController::OnGetDeviceCapabilitiesResponse(NPT_Result res,
634 PLT_DeviceDataReference& device,
635 PLT_ActionReference& action,
636 void* userdata)
637 {
638 NPT_String value;
639 PLT_DeviceCapabilities capabilities;
640
641 if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
642 goto bad_action;
643 }
644
645 if (NPT_FAILED(action->GetArgumentValue("PlayMedia", value))) {
646 goto bad_action;
647 }
648 // parse the list of medias and return a list to listener
649 ParseCSV(value, capabilities.play_media);
650
651 if (NPT_FAILED(action->GetArgumentValue("RecMedia", value))) {
652 goto bad_action;
653 }
654 // parse the list of rec and return a list to listener
655 ParseCSV(value, capabilities.rec_media);
656
657 if (NPT_FAILED(action->GetArgumentValue("RecQualityModes", value))) {
658 goto bad_action;
659 }
660 // parse the list of modes and return a list to listener
661 ParseCSV(value, capabilities.rec_quality_modes);
662
663 m_Delegate->OnGetDeviceCapabilitiesResult(NPT_SUCCESS, device, &capabilities, userdata);
664 return NPT_SUCCESS;
665
666 bad_action:
667 m_Delegate->OnGetDeviceCapabilitiesResult(NPT_FAILURE, device, NULL, userdata);
668 return NPT_FAILURE;
669 }
670
671 /*----------------------------------------------------------------------
672 | PLT_MediaController::OnGetMediaInfoResponse
673 +---------------------------------------------------------------------*/
674 NPT_Result
675 PLT_MediaController::OnGetMediaInfoResponse(NPT_Result res,
676 PLT_DeviceDataReference& device,
677 PLT_ActionReference& action,
678 void* userdata)
679 {
680 NPT_String value;
681 PLT_MediaInfo info;
682
683 if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
684 goto bad_action;
685 }
686
687 if (NPT_FAILED(action->GetArgumentValue("NrTracks", info.num_tracks))) {
688 goto bad_action;
689 }
690 if (NPT_FAILED(action->GetArgumentValue("MediaDuration", value))) {
691 goto bad_action;
692 }
693 if (NPT_FAILED(PLT_Didl::ParseTimeStamp(value, info.media_duration))) {
694 goto bad_action;
695 }
696
697 if (NPT_FAILED(action->GetArgumentValue("CurrentURI", info.cur_uri))) {
698 goto bad_action;
699 }
700 if (NPT_FAILED(action->GetArgumentValue("CurrentURIMetaData", info.cur_metadata))) {
701 goto bad_action;
702 }
703 if (NPT_FAILED(action->GetArgumentValue("NextURI", info.next_uri))) {
704 goto bad_action;
705 }
706 if (NPT_FAILED(action->GetArgumentValue("NextURIMetaData", info.next_metadata))) {
707 goto bad_action;
708 }
709 if (NPT_FAILED(action->GetArgumentValue("PlayMedium", info.play_medium))) {
710 goto bad_action;
711 }
712 if (NPT_FAILED(action->GetArgumentValue("RecordMedium", info.rec_medium))) {
713 goto bad_action;
714 }
715 if (NPT_FAILED(action->GetArgumentValue("WriteStatus", info.write_status))) {
716 goto bad_action;
717 }
718
719 m_Delegate->OnGetMediaInfoResult(NPT_SUCCESS, device, &info, userdata);
720 return NPT_SUCCESS;
721
722 bad_action:
723 m_Delegate->OnGetMediaInfoResult(NPT_FAILURE, device, NULL, userdata);
724 return NPT_FAILURE;
725 }
726
727 /*----------------------------------------------------------------------
728 | PLT_MediaController::OnGetPositionInfoResponse
729 +---------------------------------------------------------------------*/
730 NPT_Result
731 PLT_MediaController::OnGetPositionInfoResponse(NPT_Result res,
732 PLT_DeviceDataReference& device,
733 PLT_ActionReference& action,
734 void* userdata)
735 {
736 NPT_String value;
737 PLT_PositionInfo info;
738
739 if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
740 goto bad_action;
741 }
742
743 if (NPT_FAILED(action->GetArgumentValue("Track", info.track))) {
744 goto bad_action;
745 }
746
747 if (NPT_FAILED(action->GetArgumentValue("TrackDuration", value))) {
748 goto bad_action;
749 }
750 if (NPT_FAILED(PLT_Didl::ParseTimeStamp(value, info.track_duration))) {
751 goto bad_action;
752 }
753
754 if (NPT_FAILED(action->GetArgumentValue("TrackMetaData", info.track_metadata))) {
755 goto bad_action;
756 }
757
758 if (NPT_FAILED(action->GetArgumentValue("TrackURI", info.track_uri))) {
759 goto bad_action;
760 }
761
762 if (NPT_FAILED(action->GetArgumentValue("RelTime", value))) {
763 goto bad_action;
764 }
765 if (NPT_FAILED(PLT_Didl::ParseTimeStamp(value, info.rel_time))) {
766 goto bad_action;
767 }
768
769 if (NPT_FAILED(action->GetArgumentValue("AbsTime", value))) {
770 goto bad_action;
771 }
772 if (NPT_FAILED(PLT_Didl::ParseTimeStamp(value, info.abs_time))) {
773 goto bad_action;
774 }
775
776 if (NPT_FAILED(action->GetArgumentValue("RelCount", info.rel_count))) {
777 goto bad_action;
778 }
779 if (NPT_FAILED(action->GetArgumentValue("AbsCount", info.abs_count))) {
780 goto bad_action;
781 }
782
783 m_Delegate->OnGetPositionInfoResult(NPT_SUCCESS, device, &info, userdata);
784 return NPT_SUCCESS;
785
786 bad_action:
787 m_Delegate->OnGetPositionInfoResult(NPT_FAILURE, device, NULL, userdata);
788 return NPT_FAILURE;
789 }
790
791 /*----------------------------------------------------------------------
792 | PLT_MediaController::OnGetTransportInfoResponse
793 +---------------------------------------------------------------------*/
794 NPT_Result
795 PLT_MediaController::OnGetTransportInfoResponse(NPT_Result res,
796 PLT_DeviceDataReference& device,
797 PLT_ActionReference& action,
798 void* userdata)
799 {
800 PLT_TransportInfo info;
801
802 if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
803 goto bad_action;
804 }
805
806 if (NPT_FAILED(action->GetArgumentValue("CurrentTransportState", info.cur_transport_state))) {
807 goto bad_action;
808 }
809 if (NPT_FAILED(action->GetArgumentValue("CurrentTransportStatus", info.cur_transport_status))) {
810 goto bad_action;
811 }
812 if (NPT_FAILED(action->GetArgumentValue("CurrentSpeed", info.cur_speed))) {
813 goto bad_action;
814 }
815
816 m_Delegate->OnGetTransportInfoResult(NPT_SUCCESS, device, &info, userdata);
817 return NPT_SUCCESS;
818
819 bad_action:
820 m_Delegate->OnGetTransportInfoResult(NPT_FAILURE, device, NULL, userdata);
821 return NPT_FAILURE;
822 }
823
824 /*----------------------------------------------------------------------
825 | PLT_MediaController::OnGetTransportSettingsResponse
826 +---------------------------------------------------------------------*/
827 NPT_Result
828 PLT_MediaController::OnGetTransportSettingsResponse(NPT_Result res,
829 PLT_DeviceDataReference& device,
830 PLT_ActionReference& action,
831 void* userdata)
832 {
833 PLT_TransportSettings settings;
834
835 if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
836 goto bad_action;
837 }
838
839 if (NPT_FAILED(action->GetArgumentValue("PlayMode", settings.play_mode))) {
840 goto bad_action;
841 }
842 if (NPT_FAILED(action->GetArgumentValue("RecQualityMode", settings.rec_quality_mode))) {
843 goto bad_action;
844 }
845
846 m_Delegate->OnGetTransportSettingsResult(NPT_SUCCESS, device, &settings, userdata);
847 return NPT_SUCCESS;
848
849 bad_action:
850 m_Delegate->OnGetTransportSettingsResult(NPT_FAILURE, device, NULL, userdata);
851 return NPT_FAILURE;
852 }
853
854 /*----------------------------------------------------------------------
855 | PLT_MediaController::OnGetCurrentConnectionIDsResponse
856 +---------------------------------------------------------------------*/
857 NPT_Result
858 PLT_MediaController::OnGetCurrentConnectionIDsResponse(NPT_Result res,
859 PLT_DeviceDataReference& device,
860 PLT_ActionReference& action,
861 void* userdata)
862 {
863 NPT_String value;
864 PLT_StringList IDs;
865
866 if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
867 goto bad_action;
868 }
869
870 if (NPT_FAILED(action->GetArgumentValue("ConnectionIDs", value))) {
871 goto bad_action;
872 }
873 // parse the list of medias and return a list to listener
874 ParseCSV(value, IDs);
875
876 m_Delegate->OnGetCurrentConnectionIDsResult(NPT_SUCCESS, device, &IDs, userdata);
877 return NPT_SUCCESS;
878
879 bad_action:
880 m_Delegate->OnGetCurrentConnectionIDsResult(NPT_FAILURE, device, NULL, userdata);
881 return NPT_FAILURE;
882 }
883
884 /*----------------------------------------------------------------------
885 | PLT_MediaController::OnGetCurrentConnectionInfoResponse
886 +---------------------------------------------------------------------*/
887 NPT_Result
888 PLT_MediaController::OnGetCurrentConnectionInfoResponse(NPT_Result res,
889 PLT_DeviceDataReference& device,
890 PLT_ActionReference& action,
891 void* userdata)
892 {
893 NPT_String value;
894 PLT_ConnectionInfo info;
895
896 if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
897 goto bad_action;
898 }
899
900 if (NPT_FAILED(action->GetArgumentValue("RcsID", info.rcs_id))) {
901 goto bad_action;
902 }
903 if (NPT_FAILED(action->GetArgumentValue("AVTransportID", info.avtransport_id))) {
904 goto bad_action;
905 }
906 if (NPT_FAILED(action->GetArgumentValue("ProtocolInfo", info.protocol_info))) {
907 goto bad_action;
908 }
909 if (NPT_FAILED(action->GetArgumentValue("PeerConnectionManager", info.peer_connection_mgr))) {
910 goto bad_action;
911 }
912 if (NPT_FAILED(action->GetArgumentValue("PeerConnectionID", info.peer_connection_id))) {
913 goto bad_action;
914 }
915 if (NPT_FAILED(action->GetArgumentValue("Direction", info.direction))) {
916 goto bad_action;
917 }
918 if (NPT_FAILED(action->GetArgumentValue("Status", info.status))) {
919 goto bad_action;
920 }
921 m_Delegate->OnGetCurrentConnectionInfoResult(NPT_SUCCESS, device, &info, userdata);
922 return NPT_SUCCESS;
923
924 bad_action:
925 m_Delegate->OnGetCurrentConnectionInfoResult(NPT_FAILURE, device, NULL, userdata);
926 return NPT_FAILURE;
927 }
928
929 /*----------------------------------------------------------------------
930 | PLT_MediaController::OnGetProtocolInfoResponse
931 +---------------------------------------------------------------------*/
932 NPT_Result
933 PLT_MediaController::OnGetProtocolInfoResponse(NPT_Result res,
934 PLT_DeviceDataReference& device,
935 PLT_ActionReference& action,
936 void* userdata)
937 {
938 NPT_String source_info, sink_info;
939 PLT_StringList sources, sinks;
940
941 if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
942 goto bad_action;
943 }
944
945 if (NPT_FAILED(action->GetArgumentValue("Source", source_info))) {
946 goto bad_action;
947 }
948 ParseCSV(source_info, sources);
949
950 if (NPT_FAILED(action->GetArgumentValue("Sink", sink_info))) {
951 goto bad_action;
952 }
953 ParseCSV(sink_info, sinks);
954
955 m_Delegate->OnGetProtocolInfoResult(NPT_SUCCESS, device, &sources, &sinks, userdata);
956 return NPT_SUCCESS;
957
958 bad_action:
959 m_Delegate->OnGetProtocolInfoResult(NPT_FAILURE, device, NULL, NULL, userdata);
960 return NPT_FAILURE;
961 }
962
963 /*----------------------------------------------------------------------
964 | PLT_MediaController::OnEventNotify
965 +---------------------------------------------------------------------*/
966 NPT_Result
967 PLT_MediaController::OnEventNotify(PLT_Service* service, NPT_List<PLT_StateVariable*>* vars)
968 {
969 if (!m_Delegate) return NPT_SUCCESS;
970
971 // parse LastChange var into smaller vars
972 PLT_StateVariable* lastChangeVar = NULL;
973 if (NPT_SUCCEEDED(NPT_ContainerFind(*vars, PLT_ListStateVariableNameFinder("LastChange"), lastChangeVar))) {
974 vars->Remove(lastChangeVar);
975 PLT_Service* var_service = lastChangeVar->GetService();
976 NPT_String text = lastChangeVar->GetValue();
977
978 NPT_XmlNode* xml = NULL;
979 NPT_XmlParser parser;
980 if (NPT_FAILED(parser.Parse(text, xml)) || !xml || !xml->AsElementNode()) {
981 delete xml;
982 return NPT_FAILURE;
983 }
984
985 NPT_XmlElementNode* node = xml->AsElementNode();
986 if (!node->GetTag().Compare("Event", true)) {
987 // look for the instance with attribute id = 0
988 NPT_XmlElementNode* instance = NULL;
989 for (NPT_Cardinal i=0; i<node->GetChildren().GetItemCount(); i++) {
990 NPT_XmlElementNode* child;
991 if (NPT_FAILED(PLT_XmlHelper::GetChild(node, child, i)))
992 continue;
993
994 if (!child->GetTag().Compare("InstanceID", true)) {
995 // extract the "val" attribute value
996 NPT_String value;
997 if (NPT_SUCCEEDED(PLT_XmlHelper::GetAttribute(child, "val", value)) &&
998 !value.Compare("0")) {
999 instance = child;
1000 break;
1001 }
1002 }
1003 }
1004
1005 // did we find an instance with id = 0 ?
1006 if (instance != NULL) {
1007 // all the children of the Instance node are state variables
1008 for (NPT_Cardinal j=0; j<instance->GetChildren().GetItemCount(); j++) {
1009 NPT_XmlElementNode* var_node;
1010 if (NPT_FAILED(PLT_XmlHelper::GetChild(instance, var_node, j)))
1011 continue;
1012
1013 // look for the state variable in this service
1014 const NPT_String* value = var_node->GetAttribute("val");
1015 PLT_StateVariable* var = var_service->FindStateVariable(var_node->GetTag());
1016 if (value != NULL && var != NULL) {
1017 // get the value and set the state variable
1018 // if it succeeded, add it to the list of vars we'll event
1019 if (NPT_SUCCEEDED(var->SetValue(*value))) {
1020 vars->Add(var);
1021 NPT_LOG_FINE_2("PLT_MediaController received var change for (%s): %s", (const char*)var->GetName(), (const char*)var->GetValue());
1022 }
1023 }
1024 }
1025 }
1026 }
1027 delete xml;
1028 }
1029
1030 if (vars->GetItemCount()) {
1031 m_Delegate->OnMRStateVariablesChanged(service, vars);
1032 }
1033
1034 return NPT_SUCCESS;
1035 }