Mercurial > projects > hoofbaby
comparison deps/Platinum/Source/Devices/MediaRenderer/PltMediaRenderer.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 Renderer Device | |
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 "PltMediaRenderer.h" | |
39 #include "PltService.h" | |
40 | |
41 NPT_SET_LOCAL_LOGGER("platinum.media.renderer") | |
42 | |
43 /*---------------------------------------------------------------------- | |
44 | external references | |
45 +---------------------------------------------------------------------*/ | |
46 extern NPT_UInt8 RDR_ConnectionManagerSCPD[]; | |
47 extern NPT_UInt8 RDR_AVTransportSCPD[]; | |
48 extern NPT_UInt8 RDR_RenderingControlSCPD[]; | |
49 | |
50 /*---------------------------------------------------------------------- | |
51 | PLT_MediaRenderer::PLT_MediaRenderer | |
52 +---------------------------------------------------------------------*/ | |
53 PLT_MediaRenderer::PLT_MediaRenderer(const char* friendly_name, | |
54 bool show_ip /* = false */, | |
55 const char* uuid /* = NULL */, | |
56 unsigned int port /* = 0 */, | |
57 bool port_rebind /* = false */) : | |
58 PLT_DeviceHost("/", uuid, "urn:schemas-upnp-org:device:MediaRenderer:1", friendly_name, show_ip, port, port_rebind) | |
59 { | |
60 } | |
61 | |
62 /*---------------------------------------------------------------------- | |
63 | PLT_MediaRenderer::~PLT_MediaRenderer | |
64 +---------------------------------------------------------------------*/ | |
65 PLT_MediaRenderer::~PLT_MediaRenderer() | |
66 { | |
67 } | |
68 | |
69 /*---------------------------------------------------------------------- | |
70 | PLT_MediaRenderer::SetupServices | |
71 +---------------------------------------------------------------------*/ | |
72 NPT_Result | |
73 PLT_MediaRenderer::SetupServices(PLT_DeviceData& data) | |
74 { | |
75 PLT_Service* service; | |
76 | |
77 { | |
78 /* AVTransport */ | |
79 service = new PLT_Service( | |
80 &data, | |
81 "urn:schemas-upnp-org:service:AVTransport:1", | |
82 "urn:upnp-org:serviceId:AVT_1-0", | |
83 "urn:schemas-upnp-org:metadata-1-0/AVT/"); | |
84 NPT_CHECK_FATAL(service->SetSCPDXML((const char*) RDR_AVTransportSCPD)); | |
85 NPT_CHECK_FATAL(service->InitURLs("AVTransport", data.GetUUID())); | |
86 NPT_CHECK_FATAL(data.AddService(service)); | |
87 | |
88 service->SetStateVariableRate("LastChange", NPT_TimeInterval(0.2f)); | |
89 service->SetStateVariable("A_ARG_TYPE_InstanceID", "0"); | |
90 | |
91 // GetCurrentTransportActions | |
92 service->SetStateVariable("CurrentTransportActions", "Play,Pause,Stop,Seek,Next,Previous"); | |
93 | |
94 // GetDeviceCapabilities | |
95 service->SetStateVariable("PossiblePlaybackStorageMedia", "NONE,NETWORK"); | |
96 service->SetStateVariable("PossibleRecordStorageMedia", "NOT_IMPLEMENTED"); | |
97 service->SetStateVariable("PossibleRecordQualityModes", "NOT_IMPLEMENTED"); | |
98 | |
99 // GetMediaInfo | |
100 service->SetStateVariable("NumberOfTracks", "0"); | |
101 service->SetStateVariable("CurrentMediaDuration", "00:00:00");; | |
102 service->SetStateVariable("AVTransportURI", ""); | |
103 service->SetStateVariable("AVTransportURIMetadata", "");; | |
104 service->SetStateVariable("NextAVTransportURI", "NOT_IMPLEMENTED"); | |
105 service->SetStateVariable("NextAVTransportURIMetadata", "NOT_IMPLEMENTED"); | |
106 service->SetStateVariable("PlaybackStorageMedium", "NONE"); | |
107 service->SetStateVariable("RecordStorageMedium", "NOT_IMPLEMENTED"); | |
108 service->SetStateVariable("RecordMediumWriteStatus", "NOT_IMPLEMENTED"); | |
109 | |
110 // GetPositionInfo | |
111 service->SetStateVariable("CurrentTrack", "0"); | |
112 service->SetStateVariable("CurrentTrackDuration", "00:00:00"); | |
113 service->SetStateVariable("CurrentTrackMetadata", ""); | |
114 service->SetStateVariable("CurrentTrackURI", ""); | |
115 service->SetStateVariable("RelativeTimePosition", "00:00:00"); | |
116 service->SetStateVariable("AbsoluteTimePosition", "00:00:00"); | |
117 service->SetStateVariable("RelativeCounterPosition", "2147483647"); // means NOT_IMPLEMENTED | |
118 service->SetStateVariable("AbsoluteCounterPosition", "2147483647"); // means NOT_IMPLEMENTED | |
119 | |
120 // disable indirect eventing for certain state variables | |
121 PLT_StateVariable* var; | |
122 var = service->FindStateVariable("RelativeTimePosition"); | |
123 if (var) var->DisableIndirectEventing(); | |
124 var = service->FindStateVariable("AbsoluteTimePosition"); | |
125 if (var) var->DisableIndirectEventing(); | |
126 var = service->FindStateVariable("RelativeCounterPosition"); | |
127 if (var) var->DisableIndirectEventing(); | |
128 var = service->FindStateVariable("AbsoluteCounterPosition"); | |
129 if (var) var->DisableIndirectEventing(); | |
130 | |
131 // GetTransportInfo | |
132 service->SetStateVariable("TransportState", "NO_MEDIA_PRESENT"); | |
133 service->SetStateVariable("TransportStatus", "OK"); | |
134 service->SetStateVariable("TransportPlaySpeed", "1"); | |
135 | |
136 // GetTransportSettings | |
137 service->SetStateVariable("CurrentPlayMode", "NORMAL"); | |
138 service->SetStateVariable("CurrentRecordQualityMode", "NOT_IMPLEMENTED"); | |
139 } | |
140 | |
141 { | |
142 /* ConnectionManager */ | |
143 service = new PLT_Service( | |
144 &data, | |
145 "urn:schemas-upnp-org:service:ConnectionManager:1", | |
146 "urn:upnp-org:serviceId:CMGR_1-0"); | |
147 NPT_CHECK_FATAL(service->SetSCPDXML((const char*) RDR_ConnectionManagerSCPD)); | |
148 NPT_CHECK_FATAL(service->InitURLs("ConnectionManager", data.GetUUID())); | |
149 NPT_CHECK_FATAL(data.AddService(service)); | |
150 | |
151 service->SetStateVariable("CurrentConnectionIDs", "0"); | |
152 | |
153 // put all supported mime types here instead | |
154 service->SetStateVariable("SinkProtocolInfo", "http-get:*:*:*"); | |
155 service->SetStateVariable("SourceProtocolInfo", ""); | |
156 } | |
157 | |
158 { | |
159 /* RenderingControl */ | |
160 service = new PLT_Service( | |
161 &data, | |
162 "urn:schemas-upnp-org:service:RenderingControl:1", | |
163 "urn:upnp-org:serviceId:RCS_1-0", | |
164 "urn:schemas-upnp-org:metadata-1-0/RCS/"); | |
165 NPT_CHECK_FATAL(service->SetSCPDXML((const char*) RDR_RenderingControlSCPD)); | |
166 NPT_CHECK_FATAL(service->InitURLs("RenderingControl", data.GetUUID())); | |
167 NPT_CHECK_FATAL(data.AddService(service)); | |
168 | |
169 service->SetStateVariableRate("LastChange", NPT_TimeInterval(0.2f)); | |
170 | |
171 service->SetStateVariable("Mute", "0"); | |
172 service->SetStateVariable("Volume", "100"); | |
173 } | |
174 | |
175 return NPT_SUCCESS; | |
176 } | |
177 | |
178 /*---------------------------------------------------------------------- | |
179 | PLT_MediaRenderer::OnAction | |
180 +---------------------------------------------------------------------*/ | |
181 NPT_Result | |
182 PLT_MediaRenderer::OnAction(PLT_ActionReference& action, | |
183 const PLT_HttpRequestContext& context) | |
184 { | |
185 NPT_COMPILER_UNUSED(context); | |
186 | |
187 /* parse the action name */ | |
188 NPT_String name = action->GetActionDesc()->GetName(); | |
189 | |
190 /* Is it a ConnectionManager Service Action ? */ | |
191 if (name.Compare("GetCurrentConnectionIDs", true) == 0) { | |
192 if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) { | |
193 return NPT_FAILURE; | |
194 } | |
195 return NPT_SUCCESS; | |
196 } | |
197 if (name.Compare("GetProtocolInfo", true) == 0) { | |
198 if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) { | |
199 return NPT_FAILURE; | |
200 } | |
201 return NPT_SUCCESS; | |
202 } | |
203 if (name.Compare("GetCurrentConnectionInfo", true) == 0) { | |
204 return OnGetCurrentConnectionInfo(action); | |
205 } | |
206 | |
207 /* Is it a AVTransport Service Action ? */ | |
208 | |
209 // since all actions take an instance ID and we only support 1 instance | |
210 // verify that the Instance ID is 0 and return an error here now if not | |
211 NPT_String serviceType = action->GetActionDesc()->GetService()->GetServiceType(); | |
212 if (serviceType.Compare("urn:schemas-upnp-org:service:AVTransport:1", true) == 0) { | |
213 if (NPT_FAILED(action->VerifyArgumentValue("InstanceID", "0"))) { | |
214 action->SetError(802,"Not valid InstanceID."); | |
215 return NPT_FAILURE; | |
216 } | |
217 } | |
218 | |
219 if (name.Compare("GetCurrentTransportActions", true) == 0) { | |
220 if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) { | |
221 return NPT_FAILURE; | |
222 } | |
223 return NPT_SUCCESS; | |
224 } | |
225 if (name.Compare("GetDeviceCapabilities", true) == 0) { | |
226 if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) { | |
227 return NPT_FAILURE; | |
228 } | |
229 return NPT_SUCCESS; | |
230 } | |
231 if (name.Compare("GetMediaInfo", true) == 0) { | |
232 if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) { | |
233 return NPT_FAILURE; | |
234 } | |
235 return NPT_SUCCESS; | |
236 } | |
237 if (name.Compare("GetPositionInfo", true) == 0) { | |
238 if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) { | |
239 return NPT_FAILURE; | |
240 } | |
241 return NPT_SUCCESS; | |
242 } | |
243 if (name.Compare("GetTransportInfo", true) == 0) { | |
244 if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) { | |
245 return NPT_FAILURE; | |
246 } | |
247 return NPT_SUCCESS; | |
248 } | |
249 if (name.Compare("GetTransportSettings", true) == 0) { | |
250 if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) { | |
251 return NPT_FAILURE; | |
252 } | |
253 return NPT_SUCCESS; | |
254 } | |
255 if (name.Compare("Next", true) == 0) { | |
256 return OnNext(action); | |
257 } | |
258 if (name.Compare("Pause", true) == 0) { | |
259 return OnPause(action); | |
260 } | |
261 if (name.Compare("Play", true) == 0) { | |
262 return OnPlay(action); | |
263 } | |
264 if (name.Compare("Previous", true) == 0) { | |
265 return OnPrevious(action); | |
266 } | |
267 if (name.Compare("Seek", true) == 0) { | |
268 return OnSeek(action); | |
269 } | |
270 if (name.Compare("Stop", true) == 0) { | |
271 return OnStop(action); | |
272 } | |
273 if (name.Compare("SetAVTransportURI", true) == 0) { | |
274 return OnSetAVTransportURI(action); | |
275 } | |
276 if (name.Compare("SetPlayMode", true) == 0) { | |
277 return OnSetPlayMode(action); | |
278 } | |
279 | |
280 /* Is it a RendererControl Service Action ? */ | |
281 if (serviceType.Compare("urn:schemas-upnp-org:service:RenderingControl:1", true) == 0) { | |
282 /* we only support master channel */ | |
283 if (NPT_FAILED(action->VerifyArgumentValue("Channel", "Master"))) { | |
284 action->SetError(402,"Invalid Args."); | |
285 return NPT_FAILURE; | |
286 } | |
287 } | |
288 | |
289 if (name.Compare("GetVolume", true) == 0) { | |
290 NPT_CHECK_SEVERE(action->SetArgumentsOutFromStateVariable()); | |
291 return NPT_SUCCESS; | |
292 } | |
293 | |
294 if (name.Compare("GetMute", true) == 0) { | |
295 NPT_CHECK_SEVERE(action->SetArgumentsOutFromStateVariable()); | |
296 return NPT_SUCCESS; | |
297 } | |
298 | |
299 if (name.Compare("SetVolume", true) == 0) { | |
300 return OnSetVolume(action); | |
301 } | |
302 | |
303 if (name.Compare("SetMute", true) == 0) { | |
304 return OnSetMute(action); | |
305 } | |
306 | |
307 action->SetError(401,"No Such Action."); | |
308 return NPT_FAILURE; | |
309 } | |
310 | |
311 /*---------------------------------------------------------------------- | |
312 | PLT_MediaRenderer::OnGetCurrentConnectionInfo | |
313 +---------------------------------------------------------------------*/ | |
314 NPT_Result | |
315 PLT_MediaRenderer::OnGetCurrentConnectionInfo(PLT_ActionReference& action) | |
316 { | |
317 if (NPT_FAILED(action->VerifyArgumentValue("ConnectionID", "0"))) { | |
318 action->SetError(706,"No Such Connection."); | |
319 return NPT_FAILURE; | |
320 } | |
321 | |
322 if (NPT_FAILED(action->SetArgumentValue("RcsID", "0"))){ | |
323 return NPT_FAILURE; | |
324 } | |
325 if (NPT_FAILED(action->SetArgumentValue("AVTransportID", "0"))) { | |
326 return NPT_FAILURE; | |
327 } | |
328 if (NPT_FAILED(action->SetArgumentValue("ProtocolInfo", "http-get:*:*:*"))) { | |
329 return NPT_FAILURE; | |
330 } | |
331 if (NPT_FAILED(action->SetArgumentValue("PeerConnectionManager", "/"))) { | |
332 return NPT_FAILURE; | |
333 } | |
334 if (NPT_FAILED(action->SetArgumentValue("PeerConnectionID", "-1"))) { | |
335 return NPT_FAILURE; | |
336 } | |
337 if (NPT_FAILED(action->SetArgumentValue("Direction", "Input"))) { | |
338 return NPT_FAILURE; | |
339 } | |
340 if (NPT_FAILED(action->SetArgumentValue("Status", "Unknown"))) { | |
341 return NPT_FAILURE; | |
342 } | |
343 | |
344 return NPT_SUCCESS; | |
345 } | |
346 | |
347 /*---------------------------------------------------------------------- | |
348 | PLT_MediaRenderer::OnNext | |
349 +---------------------------------------------------------------------*/ | |
350 NPT_Result | |
351 PLT_MediaRenderer::OnNext(PLT_ActionReference& /* action */) | |
352 { | |
353 return NPT_SUCCESS; | |
354 } | |
355 | |
356 /*---------------------------------------------------------------------- | |
357 | PLT_MediaRenderer::OnPause | |
358 +---------------------------------------------------------------------*/ | |
359 NPT_Result | |
360 PLT_MediaRenderer::OnPause(PLT_ActionReference& /* action */) | |
361 { | |
362 return NPT_SUCCESS; | |
363 } | |
364 | |
365 /*---------------------------------------------------------------------- | |
366 | PLT_MediaRenderer::OnPlay | |
367 +---------------------------------------------------------------------*/ | |
368 NPT_Result | |
369 PLT_MediaRenderer::OnPlay(PLT_ActionReference& /* action */) | |
370 { | |
371 return NPT_SUCCESS; | |
372 } | |
373 | |
374 /*---------------------------------------------------------------------- | |
375 | PLT_MediaRenderer::OnPrevious | |
376 +---------------------------------------------------------------------*/ | |
377 NPT_Result | |
378 PLT_MediaRenderer::OnPrevious(PLT_ActionReference& /* action */) | |
379 { | |
380 return NPT_SUCCESS; | |
381 } | |
382 | |
383 /*---------------------------------------------------------------------- | |
384 | PLT_MediaRenderer::OnSeek | |
385 +---------------------------------------------------------------------*/ | |
386 NPT_Result | |
387 PLT_MediaRenderer::OnSeek(PLT_ActionReference& /* action */) | |
388 { | |
389 return NPT_SUCCESS; | |
390 } | |
391 | |
392 /*---------------------------------------------------------------------- | |
393 | PLT_MediaRenderer::OnStop | |
394 +---------------------------------------------------------------------*/ | |
395 NPT_Result | |
396 PLT_MediaRenderer::OnStop(PLT_ActionReference& /* action */) | |
397 { | |
398 return NPT_SUCCESS; | |
399 } | |
400 | |
401 /*---------------------------------------------------------------------- | |
402 | PLT_MediaRenderer::OnSetAVTransportURI | |
403 +---------------------------------------------------------------------*/ | |
404 NPT_Result | |
405 PLT_MediaRenderer::OnSetAVTransportURI(PLT_ActionReference& /* action */) | |
406 { | |
407 return NPT_SUCCESS; | |
408 } | |
409 | |
410 /*---------------------------------------------------------------------- | |
411 | PLT_MediaRenderer::OnSetPlayMode | |
412 +---------------------------------------------------------------------*/ | |
413 NPT_Result | |
414 PLT_MediaRenderer::OnSetPlayMode(PLT_ActionReference& /* action */) | |
415 { | |
416 return NPT_SUCCESS; | |
417 } | |
418 | |
419 /*---------------------------------------------------------------------- | |
420 | PLT_MediaRenderer::OnSetVolume | |
421 +---------------------------------------------------------------------*/ | |
422 NPT_Result | |
423 PLT_MediaRenderer::OnSetVolume(PLT_ActionReference& /* action */) | |
424 { | |
425 return NPT_SUCCESS; | |
426 } | |
427 | |
428 /*---------------------------------------------------------------------- | |
429 | PLT_MediaRenderer::OnSetMute | |
430 +---------------------------------------------------------------------*/ | |
431 NPT_Result | |
432 PLT_MediaRenderer::OnSetMute(PLT_ActionReference& /* action */) | |
433 { | |
434 return NPT_SUCCESS; | |
435 } |