1 /*
2  *			GPAC - Multimedia Framework C SDK
3  *
4  *			Authors: Jean Le Feuvre
5  *			Copyright (c) Telecom ParisTech 2009-2012
6  *			All rights reserved
7  *
8  *  This file is part of GPAC / Platinum UPnP module
9  *
10  *  GPAC is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU Lesser General Public License as published by
12  *  the Free Software Foundation; either version 2, or (at your option)
13  *  any later version.
14  *
15  *  GPAC is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU Lesser General Public License for more details.
19  *
20  *  You should have received a copy of the GNU Lesser General Public
21  *  License along with this library; see the file COPYING.  If not, write to
22  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  *
25  *	----------------------------------------------------------------------------------
26  *		PLATINUM IS LICENSED UNDER GPL or commercial agreement - cf platinum license
27  *	----------------------------------------------------------------------------------
28  *
29  */
30 
31 
32 #ifndef _GPAC_PLATINUM_H_
33 #define _GPAC_PLATINUM_H_
34 
35 #include "Platinum.h"
36 #include "PltUPnP.h"
37 #include "GPACFileMediaServer.h"
38 #include "GPACMediaRenderer.h"
39 #include "GPACMediaController.h"
40 #include "GenericDevice.h"
41 
42 #include <gpac/modules/term_ext.h>
43 #include <gpac/term_info.h>
44 #include <gpac/thread.h>
45 #include <gpac/network.h>
46 #include <gpac/options.h>
47 #include <gpac/internal/terminal_dev.h>
48 
49 #ifdef GPAC_HAS_SPIDERMONKEY
50 
51 #include <gpac/internal/scenegraph_dev.h>
52 #include <gpac/internal/smjs_api.h>
53 
54 #endif
55 
56 class GPAC_DeviceItem;
57 
58 
59 class GF_UPnP
60 {
61 public:
62 	GF_UPnP();
63 	~GF_UPnP();
64 
65 	/*load UPnP services*/
66 	void Load(GF_Terminal *term);
67 	/*unload UPnP services*/
68 	void Unload();
69 
70 	/*GPAC event filter*/
71 	Bool ProcessEvent(GF_Event *evt);
72 
73 	GF_TermExt *term_ext;
74 	/*GPAC's terminal*/
75 	GF_Terminal *m_pTerm;
76 
77 	/*Platinum's UPnP stack*/
78 	PLT_UPnP *m_pPlatinum;
79 
80 	/*GPAC UPnP/DLNA media renderer if loaded*/
81 	GPAC_MediaRenderer *m_pMediaRenderer;
82 	/*is renderer bound to the script ? If so, events are dispatched to the script's "UPnP" object*/
83 	Bool m_renderer_bound;
84 	NPT_String m_IPFilter;
85 
86 	/*regular media file server from platinum*/
87 	GPAC_FileMediaServer *m_pMediaServer;
88 
89 	/*GPAC's AVControlPoint*/
90 	GPAC_MediaController *m_pAVCtrlPoint;
91 
92 	void LockJavascript(Bool do_lock);
93 
94 	/*callback from GPAC MediaRenderer*/
95 	void OnConnect(const char *url, const char *src_url);
96 	void OnPause(Bool do_resume, const char *src_url);
97 	void OnStop(const char *src_url);
98 	void OnSeek(Double time);
99 	void OnSetPlayMode(const char *src_url);
100 	void onDurationChanged(s32 renderer_idx, Double dur);
101 	void onTimeChanged(s32 renderer_idx, Double time);
102 	void ContainerChanged(PLT_DeviceDataReference& device, const char *item_id, const char *update_id);
103 	NPT_String OnMigrate();
104 
105 	GPAC_GenericController *m_pGenericController;
106 
107 	PLT_CtrlPoint *m_pCtrlPoint;
108 	PLT_CtrlPointReference m_ctrlPtRef;
109 
110 	GF_TermEventFilter evt_filter;
111 	/*JS bindings*/
112 #ifdef GPAC_HAS_SPIDERMONKEY
113 	Bool LoadJS(GF_TermExtJS *param);
114 	u32 m_nbJSInstances;
115 	JSContext *m_pJSCtx;
116 	JSObject *m_pObj;
117 	GF_JSClass upnpClass;
118 	GF_JSClass upnpDeviceClass;
119 	GF_JSClass upnpGenericDeviceClass;
120 	GF_JSClass upnpServiceClass;
121 
122 	GF_List *m_Devices;
123 	u32 last_time, upnp_init_time;
124 
125 	/*callback from AVControlPoint device discovery*/
126 	void OnMediaServerAdd(PLT_DeviceDataReference& device, int added);
127 	void OnMediaRendererAdd(PLT_DeviceDataReference& device, int added);
128 
129 	void OnDeviceAdd(GPAC_DeviceItem *item, int added);
130 
131 
132 	jsval GetUPnPDevice(const char *src_url);
133 
134 #else
OnMediaServerAdd(PLT_DeviceDataReference & device,int added)135 	void OnMediaServerAdd(PLT_DeviceDataReference& device, int added) {}
OnMediaRendererAdd(PLT_DeviceDataReference & device,int added)136 	void OnMediaRendererAdd(PLT_DeviceDataReference& device, int added) {}
OnDeviceAdd(GPAC_DeviceItem * item,int added)137 	void OnDeviceAdd(GPAC_DeviceItem *item, int added) {}
138 #endif
139 
140 };
141 
142 #ifdef GPAC_HAS_SPIDERMONKEY
143 SMJS_DECL_FUNC_PROP_GET( upnpservice_getProperty);
144 
145 #ifdef USE_FFDEV_17
146 #define VPASSIGN(__b) __vp.set( __b )
147 #define VPGET() (jsval) __vp
148 #else
149 #define VPASSIGN(__b) *vp = __b
150 #define VPGET() *vp
151 #endif
152 
153 #endif
154 
155 void format_time_string(char *str, Double dur);
156 
157 
158 #endif	/*_GPAC_PLATINUM_H_*/
159