2 * GPAC - Multimedia Framework C SDK
\r
4 * Copyright (c) Jean Le Feuvre 2000-2005
\r
5 * All rights reserved
\r
7 * This file is part of GPAC / modules interfaces
\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
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
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
25 #ifndef _GF_SERVICE_H_
\r
26 #define _GF_SERVICE_H_
\r
32 /*for SL, ESD and OD*/
\r
33 #include <gpac/mpeg4_odf.h>
\r
34 #include <gpac/download.h>
\r
36 /*handle to service*/
\r
37 typedef struct _net_service GF_ClientService;
\r
39 /*handle to channel*/
\r
40 typedef void *LPNETCHANNEL;
\r
44 /*channel control, app->module. Note that most modules don't need to handle pause/resume/set_speed*/
\r
49 GF_NET_CHAN_SET_SPEED,
\r
50 /*channel configuration, app->module*/
\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
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
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
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
87 /*retrieves whether service can be cached (rtp, http streaming radios, etc) or not. No associated struct*/
\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
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
105 LPNETCHANNEL on_channel;
\r
108 /*GF_NET_CHAN_PLAY, GF_NET_CHAN_SET_SPEED*/
\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
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
127 LPNETCHANNEL on_channel;
\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
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
136 /*audio frame duration and sample rate if any - this is needed by some RTP payload*/
\r
137 u32 frame_duration, sample_rate;
\r
140 /*GF_NET_CHAN_BUFFER, GF_NET_CHAN_BUFFER_QUERY*/
\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
149 /*only used with GF_NET_CHAN_BUFFER_QUERY - amount of media in decoding buffer, in ms*/
\r
153 /*GF_NET_CHAN_DURATION*/
\r
157 LPNETCHANNEL on_channel;
\r
158 /*duration in sec*/
\r
160 } GF_NetComDuration;
\r
162 /*GF_NET_CHAN_GET_DSI*/
\r
166 LPNETCHANNEL on_channel;
\r
167 /*carries specific info for codec - data shall be allocated by service and is freed by user*/
\r
172 /*GF_NET_CHAN_SET_PADDING*/
\r
176 LPNETCHANNEL on_channel;
\r
178 } GF_NetComPadding;
\r
180 /*GF_NET_CHAN_MAP_TIME*/
\r
184 LPNETCHANNEL on_channel;
\r
185 /*MediaTime at this timestamp*/
\r
187 /*TS where mapping is done (in SL TS resolution)*/
\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
193 /*GF_NET_CHAN_ISMACRYP_CFG*/
\r
197 LPNETCHANNEL on_channel;
\r
200 /*per channel, regardless of DRM schemes (ISMA, OMA, )*/
\r
201 u32 scheme_version;
\r
203 const char *scheme_uri;
\r
204 const char *kms_uri;
\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
212 /*SHA-1 file hash*/
\r
214 } GF_NetComDRMConfig;
\r
216 /*GF_NET_CHAN_GET_ESD*/
\r
220 LPNETCHANNEL on_channel;
\r
222 Bool is_iod_stream;
\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
231 typedef struct __netstatcom
\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
250 /*GF_NET_CHAN_GET_PIXEL_AR*/
\r
254 LPNETCHANNEL on_channel;
\r
255 u32 hSpacing, vSpacing;
\r
256 } GF_NetComPixelAR;
\r
258 /*GF_NET_SERVICE_INFO*/
\r
259 typedef struct __netinfocom
\r
262 /*currently NULL only*/
\r
263 LPNETCHANNEL on_channel;
\r
264 /*packed trackNumber(16 bits)/totaltrack(16 bits)*/
\r
268 const char *artist;
\r
269 const char *comment;
\r
270 const char *composer;
\r
272 const char *writer;
\r
275 /*GF_NET_CHAN_GET_PIXEL_AR*/
\r
280 } GF_NetComHasAudio;
\r
282 typedef union __netcommand
\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
305 /*interface name and version for input service*/
\r
306 #define GF_NET_CLIENT_INTERFACE GF_4CC('G', 'I', 'S', 0x01)
\r
308 typedef struct _netinterface
\r
310 /* interface declaration*/
\r
311 GF_DECL_MODULE_INTERFACE
\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
317 Bool (*CanHandleURL)(struct _netinterface *, const char *url);
\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
322 GF_Err (*ConnectService) (struct _netinterface *, GF_ClientService *serv, const char *url);
\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
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
332 GF_Err (*CloseService) (struct _netinterface *);
\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
350 GF_Descriptor *(*GetServiceDescriptor) (struct _netinterface *, u32 expect_type, const char *sub_url);
\r
353 /*sends command to the service / channel - cf command structure*/
\r
354 GF_Err (*ServiceCommand) (struct _netinterface *, GF_NetworkCommand *com);
\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
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
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
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
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
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
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
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
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
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
413 void gf_term_add_media(GF_ClientService *service, GF_Descriptor *media_desc, Bool no_scene_update);
\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
421 GF_InputService *gf_term_get_service_interface(GF_ClientService *service);
\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
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
434 /*MPEG-4 media cache interface name*/
\r
435 #define GF_STREAMING_MEDIA_CACHE GF_4CC('G', 'M', 'C', 0x01)
\r
437 typedef struct _cacheinterface
\r
439 /* interface declaration*/
\r
440 GF_DECL_MODULE_INTERFACE
\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
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
460 } GF_StreamingCache;
\r
467 #endif /*_GF_SERVICE_H_*/
\r