OSDN Git Service

add tstools.
[rec10/rec10-git.git] / tstools / DtsEdit / src / gpac / modules / service.h
1 /*\r
2  *                      GPAC - Multimedia Framework C SDK\r
3  *\r
4  *                      Copyright (c) Jean Le Feuvre 2000-2005 \r
5  *                                      All rights reserved\r
6  *\r
7  *  This file is part of GPAC / modules interfaces\r
8  *\r
9  *  GPAC is free software; you can redistribute it and/or modify\r
10  *  it under the terms of the GNU Lesser General Public License as published by\r
11  *  the Free Software Foundation; either version 2, or (at your option)\r
12  *  any later version.\r
13  *   \r
14  *  GPAC is distributed in the hope that it will be useful,\r
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  *  GNU Lesser General Public License for more details.\r
18  *   \r
19  *  You should have received a copy of the GNU Lesser General Public\r
20  *  License along with this library; see the file COPYING.  If not, write to\r
21  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. \r
22  *\r
23  */\r
24 \r
25 #ifndef _GF_SERVICE_H_\r
26 #define _GF_SERVICE_H_\r
27 \r
28 #ifdef __cplusplus\r
29 extern "C" {\r
30 #endif\r
31 \r
32 /*for SL, ESD and OD*/\r
33 #include <gpac/mpeg4_odf.h>\r
34 #include <gpac/download.h>\r
35 \r
36 /*handle to service*/\r
37 typedef struct _net_service GF_ClientService;\r
38 \r
39 /*handle to channel*/\r
40 typedef void *LPNETCHANNEL;\r
41 \r
42 enum\r
43 {\r
44         /*channel control, app->module. Note that most modules don't need to handle pause/resume/set_speed*/\r
45         GF_NET_CHAN_PLAY,\r
46         GF_NET_CHAN_STOP,\r
47         GF_NET_CHAN_PAUSE,\r
48         GF_NET_CHAN_RESUME,\r
49         GF_NET_CHAN_SET_SPEED,\r
50         /*channel configuration, app->module*/\r
51         GF_NET_CHAN_CONFIG,\r
52         /*channel duration, app<->module (in case duration is not known at setup)*/\r
53         GF_NET_CHAN_DURATION,\r
54         /*channel buffer, app->module*/\r
55         GF_NET_CHAN_BUFFER,\r
56         /*channel buffer query, app<-module*/\r
57         GF_NET_CHAN_BUFFER_QUERY,\r
58         /*retrieves DSI from channel (DSI may be caried by net with a != value than OD), app->module*/\r
59         GF_NET_CHAN_GET_DSI,\r
60         /*set media padding for all AUs fetched (pull mode only). \r
61         If not supported the channel will have to run in push mode. app->module*/\r
62         GF_NET_CHAN_SET_PADDING,\r
63         /*sets input channel to pull mode if possible, app->module*/\r
64         GF_NET_CHAN_SET_PULL,\r
65         /*query channel capability to pause/resume and seek(play from an arbitrary range)\r
66         a non-interactive channel doesn't have to handle SET_SPEED, PAUSE and RESUME commands but can \r
67         still work in pull mode*/\r
68         GF_NET_CHAN_INTERACTIVE,\r
69         /*map net time (OTB) to media time (up only) - this is needed by some signaling protocols when the \r
70         real play range is not the requested one */\r
71         GF_NET_CHAN_MAP_TIME,\r
72         /*reconfiguration of channel comming from network (up only) - this is used to override the SL config\r
73         if it differs from the one specified at config*/\r
74         GF_NET_CHAN_RECONFIG,\r
75         /*signal channel is ISMACryp'ted (net->term only)*/\r
76         GF_NET_CHAN_DRM_CFG,\r
77         \r
78         /*retrieves ESD for channel - net->term only, for cache configuration*/\r
79         GF_NET_CHAN_GET_ESD,\r
80         /*retrieves visual PAR as indicated in container if any*/\r
81         GF_NET_CHAN_GET_PIXEL_AR,\r
82         \r
83         /*service buffer query (for all channels running in service), app<-module*/\r
84         GF_NET_BUFFER_QUERY,\r
85         /*retrieves network stats for service/channel; app->module*/\r
86         GF_NET_GET_STATS,\r
87         /*retrieves whether service can be cached (rtp, http streaming radios, etc) or not. No associated struct*/\r
88         GF_NET_IS_CACHABLE,\r
89 \r
90         /*sets info for service - net->term only*/\r
91         GF_NET_SERVICE_INFO,\r
92         /*checks if there is an audio stream in the service - term->net only*/\r
93         GF_NET_SERVICE_HAS_AUDIO,\r
94 };\r
95 \r
96 /*channel command for all commands that don't need params:\r
97 GF_NET_CHAN_SET_PULL: module shall return GF_OK or GF_NOT_SUPPORTED\r
98 GF_NET_CHAN_INTERACTIVE: module shall return GF_OK or GF_NOT_SUPPORTED\r
99 */\r
100 typedef struct\r
101 {\r
102         /*command type*/\r
103         u32 command_type;\r
104         /*channel*/\r
105         LPNETCHANNEL on_channel;\r
106 } GF_NetComBase;\r
107 \r
108 /*GF_NET_CHAN_PLAY, GF_NET_CHAN_SET_SPEED*/\r
109 typedef struct\r
110 {\r
111         u32 command_type;\r
112         LPNETCHANNEL on_channel;\r
113         /*params for GF_NET_CHAN_PLAY, ranges in sec - if range is <0, then it is ignored (eg [2, -1] with speed>0 means 2 +oo) */\r
114         Double start_range, end_range;\r
115         /*params for GF_NET_CHAN_PLAY and GF_NET_CHAN_SPEED*/\r
116         Double speed;\r
117 } GF_NetComPlay;\r
118 \r
119 \r
120 /*GF_NET_CHAN_CONFIG, GF_NET_CHAN_RECONFIG\r
121 channel config may happen as soon as the channel is open, even if the module hasn't acknowledge creation\r
122 channel config can also be used from network to app, with GF_NET_CHAN_RECONFIG type - only the SL config is then used\r
123 */\r
124 typedef struct\r
125 {\r
126         u32 command_type;\r
127         LPNETCHANNEL on_channel;\r
128 \r
129         /*SL config of the stream as delivered in OD (app->channel) or by network (channel->app)*/\r
130         GF_SLConfig sl_config;          \r
131         /*stream priority packet drops are more tolerable if low priority - app->channel only*/\r
132         u32 priority;\r
133         /*sync ID: all channels with the same sync ID run on the same timeline, thus the module should \r
134         try to match this - note this may not be possible (typically RTP/RTSP)*/\r
135         u32 sync_id;\r
136         /*audio frame duration and sample rate if any - this is needed by some RTP payload*/\r
137         u32 frame_duration, sample_rate;\r
138 } GF_NetComConfig;\r
139 \r
140 /*GF_NET_CHAN_BUFFER, GF_NET_CHAN_BUFFER_QUERY*/\r
141 typedef struct\r
142 {\r
143         u32 command_type;\r
144         LPNETCHANNEL on_channel;\r
145         /*the recommended buffering limits in ms - this depends on the modules preferences and on the service \r
146         type (multicast, vod, ...) - below buffer_min the stream will pause if possible until buffer_max is reached\r
147         note the app will fill in default values before querying*/\r
148         u32 min, max;\r
149         /*only used with GF_NET_CHAN_BUFFER_QUERY - amount of media in decoding buffer, in ms*/\r
150         u32 occupancy;\r
151 } GF_NetComBuffer;\r
152 \r
153 /*GF_NET_CHAN_DURATION*/\r
154 typedef struct\r
155 {\r
156         u32 command_type;\r
157         LPNETCHANNEL on_channel;\r
158         /*duration in sec*/\r
159         Double duration;\r
160 } GF_NetComDuration;\r
161 \r
162 /*GF_NET_CHAN_GET_DSI*/\r
163 typedef struct\r
164 {\r
165         u32 command_type;\r
166         LPNETCHANNEL on_channel;\r
167         /*carries specific info for codec - data shall be allocated by service and is freed by user*/\r
168         char *dsi;\r
169         u32 dsi_len;\r
170 } GF_NetComGetDSI;\r
171 \r
172 /*GF_NET_CHAN_SET_PADDING*/\r
173 typedef struct\r
174 {\r
175         u32 command_type;\r
176         LPNETCHANNEL on_channel;\r
177         u32 padding_bytes;\r
178 } GF_NetComPadding;\r
179 \r
180 /*GF_NET_CHAN_MAP_TIME*/\r
181 typedef struct\r
182 {\r
183         u32 command_type;\r
184         LPNETCHANNEL on_channel;\r
185         /*MediaTime at this timestamp*/\r
186         Double media_time;\r
187         /*TS where mapping is done (in SL TS resolution)*/\r
188         u64 timestamp;\r
189         /*specifies whether decoder input data shall be discarded or only have its timing updated*/\r
190         Bool reset_buffers;\r
191 } GF_NetComMapTime;\r
192 \r
193 /*GF_NET_CHAN_ISMACRYP_CFG*/\r
194 typedef struct\r
195 {\r
196         u32 command_type;\r
197         LPNETCHANNEL on_channel;\r
198 \r
199 \r
200         /*per channel, regardless of DRM schemes (ISMA, OMA, )*/\r
201         u32 scheme_version;\r
202         u32 scheme_type;\r
203         const char *scheme_uri;\r
204         const char *kms_uri;\r
205         /*OMA DRM info*/\r
206         const char *contentID;\r
207         u32 oma_drm_crypt_type;\r
208         Bool oma_drm_use_pad, oma_drm_use_hdr;\r
209         const char *oma_drm_textual_headers;\r
210         u32 oma_drm_textual_headers_len;\r
211 \r
212         /*SHA-1 file hash*/\r
213         u8 hash[20];\r
214 } GF_NetComDRMConfig;\r
215 \r
216 /*GF_NET_CHAN_GET_ESD*/\r
217 typedef struct\r
218 {\r
219         u32 command_type;\r
220         LPNETCHANNEL on_channel;\r
221         const GF_ESD *esd;\r
222         Bool is_iod_stream;\r
223 } GF_NetComGetESD;\r
224 \r
225 /*GF_NET_GET_STATS\r
226 Notes\r
227 1: only channels using network must reply. All channels fetching data through a \r
228 file downloader (cf below) shall NOT answer, the app manages downloader bandwidth internally.\r
229 2: BANDWIDTH USED BY SIGNALING PROTOCOL IS IGNORED IN GPAC\r
230 */\r
231 typedef struct __netstatcom\r
232 {\r
233         u32 command_type;\r
234         /*MAY BE NULL, in which case the module must fill in ONLY the control channel part. This\r
235         is not used yet, but could be with a protocol using a single control socket for N media channels.*/\r
236         LPNETCHANNEL on_channel;\r
237         /*percentage of packet loss from network. This cannot be figured out by the app since there is no\r
238         one-to-one mapping between the protocol packets and the final SL packet (cf RTP payloads)*/\r
239         Float pck_loss_percentage;\r
240         /*channel port, control channel port if any (eg RTCP)*/\r
241         u16 port, ctrl_port;\r
242         /*bandwidth used by channel & its control channel if any (both up and down) - expressed in bits per second*/\r
243         u32 bw_up, bw_down, ctrl_bw_down, ctrl_bw_up;\r
244         /*set to 0 if channel is not part of a multiplex. Otherwise set to the multiplex port, and \r
245         above port info shall be identifiers in the multiplex - note that multiplexing overhead is ignored \r
246         in GPAC for the current time*/\r
247         u16 multiplex_port;\r
248 } GF_NetComStats;\r
249 \r
250 /*GF_NET_CHAN_GET_PIXEL_AR*/\r
251 typedef struct\r
252 {\r
253         u32 command_type;\r
254         LPNETCHANNEL on_channel;\r
255         u32 hSpacing, vSpacing;\r
256 } GF_NetComPixelAR;\r
257 \r
258 /*GF_NET_SERVICE_INFO*/\r
259 typedef struct __netinfocom\r
260 {\r
261         u32 command_type;\r
262         /*currently NULL only*/\r
263         LPNETCHANNEL on_channel;\r
264         /*packed trackNumber(16 bits)/totaltrack(16 bits)*/\r
265         u32 track_info;\r
266         u32 genre;\r
267         const char *album;\r
268         const char *artist;\r
269         const char *comment;\r
270         const char *composer;\r
271         const char *name;\r
272         const char *writer;\r
273 } GF_NetComInfo;\r
274 \r
275 /*GF_NET_CHAN_GET_PIXEL_AR*/\r
276 typedef struct\r
277 {\r
278         u32 command_type;\r
279         char *base_url;\r
280 } GF_NetComHasAudio;\r
281 \r
282 typedef union __netcommand\r
283 {\r
284         u32 command_type;\r
285         GF_NetComBase base;\r
286         GF_NetComPlay play;\r
287         GF_NetComConfig cfg;\r
288         GF_NetComBuffer buffer;\r
289         GF_NetComDuration duration;\r
290         GF_NetComGetDSI get_dsi;\r
291         GF_NetComPadding pad;\r
292         GF_NetComMapTime map_time;\r
293         GF_NetComStats net_stats;\r
294         GF_NetComDRMConfig drm_cfg;\r
295         GF_NetComGetESD cache_esd;\r
296         GF_NetComInfo info;\r
297         GF_NetComPixelAR par;\r
298         GF_NetComHasAudio audio;\r
299 } GF_NetworkCommand;\r
300 \r
301 /*\r
302         network modules\r
303 */\r
304 \r
305 /*interface name and version for input service*/\r
306 #define GF_NET_CLIENT_INTERFACE                 GF_4CC('G', 'I', 'S', 0x01)\r
307 \r
308 typedef struct _netinterface\r
309 {\r
310         /* interface declaration*/\r
311         GF_DECL_MODULE_INTERFACE\r
312 \r
313         /*retuns 1 if module can process this URL, 0 otherwise. This is only called when the file extension/mimeType cannot be\r
314         retrieved in the cfg file, otherwise the mime type/file ext is used to load service. Typically a module would \r
315         register its mime types in this function (cf gf_term_register_mime_type below)\r
316         */\r
317         Bool (*CanHandleURL)(struct _netinterface *, const char *url);\r
318 \r
319         /*connects the service to the desired URL - the service handle is used for callbacks. \r
320         Only one service can be connected to a loaded interface.\r
321         */\r
322         GF_Err (*ConnectService) (struct _netinterface *, GF_ClientService *serv, const char *url);\r
323 \r
324         /*disconnects service - the module is no longer used after this call - if immediate_shutdown is set the module\r
325         shall not attempt to get confirmation from remote side, it will be deleted right away\r
326         \r
327         NOTE: depending on how the client/server exchange is happening, it may happen that the CloseService is called\r
328         in the same context as a reply from your module. This can result into deadlocks if you're using threads. \r
329         You should therefore only try to destroy threads used in the interface shutdown process, which is guarantee\r
330         to be in a different context call.\r
331         */\r
332         GF_Err (*CloseService) (struct _netinterface *);\r
333 \r
334         /*retrieves service decsriptor (expressed as an MPEG4 OD/IOD) for accessing this service \r
335         descriptor is allocated by plugin and destroyed by user\r
336         the IOD shall refer to the service attached to the module\r
337         @expect_type is a hint in case the service regenerates an IOD. It indicates whether the entry point expected is \r
338         INLINE, BIFS animation stream, video, audio or input sensor.\r
339         @sub_url: indicates fetching of an IOD for a given object in the service.\r
340         Only used for services handling the optional CanHandleURLInService below\r
341                 NULL for main service\r
342                 service extension for sub-service (cf CanHandleURLInService below). For ex,\r
343                 "rtsp://myserver/file.mp4/ES_ID=3" and "rtsp://myserver/file.mp4/ES_ID=4" \r
344                 or "file.avi#audio" and "file.avi#video".In this case a partial IOD for the desired object is expected\r
345         Note: once a service is acknowledged as connected, this function must be executed synchronously\r
346         The service can return NULL for a descriptor:\r
347                 * if the expected media type is a single media, this means the media couldn't be found\r
348                 * if the expected media type is a scene, this means the terminalk shall create and manage the scene\r
349         */\r
350         GF_Descriptor *(*GetServiceDescriptor) (struct _netinterface *, u32 expect_type, const char *sub_url);\r
351         \r
352 \r
353         /*sends command to the service / channel - cf command structure*/\r
354         GF_Err (*ServiceCommand) (struct _netinterface *, GF_NetworkCommand *com);\r
355 \r
356         /*data channel setup - url is either\r
357         "ES_ID=ID" where ID is the stream ID in this service\r
358         or a control string depending on the service/stream. The URL is first used to load a module able to handle it, \r
359         so the module has no redirection to handle\r
360         */\r
361         GF_Err (*ConnectChannel) (struct _netinterface *, LPNETCHANNEL channel, const char *url, Bool upstream);\r
362         /*teardown of data channel*/\r
363         GF_Err (*DisconnectChannel) (struct _netinterface *, LPNETCHANNEL channel);\r
364 \r
365         /*optional - fetch MPEG4 data from channel - data shall not be duplicated and must be released at ReleaseData\r
366         SL info shall be written to provided header - if the data is a real SL packet the flag sl_compressed shall be \r
367         set to signal the app this is a full SL pdu (@out_sl_hdr is then ignored)\r
368         set to NULL if not supported\r
369         */\r
370         GF_Err (*ChannelGetSLP) (struct _netinterface *, LPNETCHANNEL channel, char **out_data_ptr, u32 *out_data_size, GF_SLHeader *out_sl_hdr, Bool *sl_compressed, GF_Err *out_reception_status, Bool *is_new_data);\r
371 \r
372         /*optional - release SLP data allocated on channel by the previous call, if any\r
373         set to NULL if not supported*/\r
374         GF_Err (*ChannelReleaseSLP) (struct _netinterface *, LPNETCHANNEL channel);\r
375 \r
376         /*this is needed for modules to query other modules, the typical case being 2 ESD URLs pointing to the \r
377         same media (audio and video streams in an RTSP session). This is always used on loaded modules but \r
378         doesn't have to be declared*/\r
379         Bool (*CanHandleURLInService)(struct _netinterface *, const char *url);\r
380 \r
381 /*private*/\r
382         void *priv;\r
383 } GF_InputService;\r
384 \r
385 /*callback functions - these can be linked with non-LGPL modules*/\r
386 /*message from service - error is set if error*/\r
387 void gf_term_on_message(GF_ClientService *service, GF_Err error, const char *message);\r
388 /*to call on service (if channel is NULL) or channel connect completed*/\r
389 void gf_term_on_connect(GF_ClientService *service, LPNETCHANNEL ns, GF_Err response);\r
390 /*to call on service (if channel is NULL) or channel disconnect completed*/\r
391 void gf_term_on_disconnect(GF_ClientService *service, LPNETCHANNEL ns, GF_Err response);\r
392 /* acknowledgement of service command - service commands handle both services and channels\r
393 Most of the time commands are NOT acknowledged, typical acknowledgement are needed for setup and control\r
394 with remote servers. \r
395 command can also be triggered from the service (QoS, broadcast announcements)\r
396 cf above for command usage\r
397 */\r
398 void gf_term_on_command(GF_ClientService *service, GF_NetworkCommand *com, GF_Err response);\r
399 /*to call when data packet is received. \r
400 @data, data_size: data received\r
401 @hdr: uncompressed SL header passed with data for stream sync - if not present then data shall be a valid SL packet \r
402         (header + PDU). Note that using an SLConfig resulting in an empty GF_SLHeader allows sending raw data directly\r
403 @reception_status: data reception status. To signal end of stream, set this to GF_EOS\r
404 */\r
405 void gf_term_on_sl_packet(GF_ClientService *service, LPNETCHANNEL ns, char *data, u32 data_size, GF_SLHeader *hdr, GF_Err reception_status);\r
406 /*returns URL associated with service (so that you don't need to store it)*/\r
407 const char *gf_term_get_service_url(GF_ClientService *service);\r
408 \r
409 /*adds a new media from network. !! The media descriptor is then owned/destroyed by the term!!\r
410 media_desc: object descriptor for the new media. May be NULL to force scene rebuilt.\r
411 no_scene_check: specifies if the scene description shall be rebuilt or not.\r
412 */\r
413 void gf_term_add_media(GF_ClientService *service, GF_Descriptor *media_desc, Bool no_scene_update);\r
414 \r
415 \r
416 /*check if @fileExt extension is supported for given mimeType, and if associated with module. If mimeType not registered, register it for given module*/\r
417 Bool gf_term_check_extension(GF_InputService *ifce, const char *mimeType, const char *extList, const char *description, const char *fileExt);\r
418 /*register mime types & file extensions - most modules should only need the check version above*/\r
419 void gf_term_register_mime_type(GF_InputService *ifce, const char *mimeType, const char *extList, const char *description);\r
420 \r
421 GF_InputService *gf_term_get_service_interface(GF_ClientService *service);\r
422 \r
423 /*file downloading - can and MUST be used by any module (regardless of license) in order not to interfere \r
424 with net management*/\r
425 /*creates a new downloading session in the given service - if url is relative, it will be interpreted through\r
426 the service URL*/\r
427 GF_DownloadSession * gf_term_download_new(GF_ClientService *service, const char *url, u32 flags, gf_dm_user_io user_io, void *cbk);\r
428 /*closes the downloading session*/\r
429 void gf_term_download_del(GF_DownloadSession * dnload);\r
430 /*send progress and connection messages to user...*/\r
431 void gf_term_download_update_stats(GF_DownloadSession * sess);\r
432 \r
433 \r
434 /*MPEG-4 media cache interface name*/\r
435 #define GF_STREAMING_MEDIA_CACHE                GF_4CC('G', 'M', 'C', 0x01)\r
436 \r
437 typedef struct _cacheinterface\r
438 {\r
439         /* interface declaration*/\r
440         GF_DECL_MODULE_INTERFACE\r
441 \r
442         /*opens media cache at given place - extension is handled by cache module\r
443         @serv: service owning cache (eg, where to send data when requested)\r
444         @keep_existing_files: don't overwrite previously recorded sessions*/\r
445         GF_Err (*Open)(struct _cacheinterface *, GF_ClientService *serv, const char *location_and_name, Bool keep_existing_files);\r
446         /*closes media cache, delete file(s) if desired*/\r
447         GF_Err (*Close)(struct _cacheinterface *, Bool delete_cache);\r
448         /*writes data to cache. data is always a complete AU as reconstructed by gpac core\r
449         If first time data is written, user should query channel desc through service commands*/\r
450         GF_Err (*Write)(struct _cacheinterface *, LPNETCHANNEL ch, char *data, u32 data_size, GF_SLHeader *sl_hdr);\r
451 \r
452         /*same as reader, except they MUST be provided - in other words, only PULL mode is supported for cache\r
453         at the current time*/\r
454         GF_Err (*ServiceCommand) (struct _cacheinterface *, GF_NetworkCommand *com);\r
455         GF_Err (*ChannelGetSLP) (struct _cacheinterface *, LPNETCHANNEL channel, char **out_data_ptr, u32 *out_data_size, GF_SLHeader *out_sl_hdr, Bool *sl_compressed, GF_Err *out_reception_status, Bool *is_new_data);\r
456         GF_Err (*ChannelReleaseSLP) (struct _cacheinterface *, LPNETCHANNEL channel);\r
457 \r
458         /*module private*/\r
459         void *priv;\r
460 } GF_StreamingCache;\r
461 \r
462 \r
463 #ifdef __cplusplus\r
464 }\r
465 #endif\r
466 \r
467 #endif  /*_GF_SERVICE_H_*/\r