OSDN Git Service

add tstools.
[rec10/rec10-git.git] / tstools / DtsEdit / src / gpac / internal / terminal_dev.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 / Stream Management sub-project\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_TERMINAL_DEV_H_\r
26 #define _GF_TERMINAL_DEV_H_\r
27 \r
28 #ifdef __cplusplus\r
29 extern "C" {\r
30 #endif\r
31 \r
32 \r
33 #include <gpac/terminal.h>\r
34 #include <gpac/mpeg4_odf.h>\r
35 \r
36 #include <gpac/modules/service.h>\r
37 #include <gpac/modules/codec.h>\r
38 #include <gpac/modules/ipmp.h>\r
39 #include <gpac/mediaobject.h>\r
40 #include <gpac/thread.h>\r
41 \r
42 typedef struct _inline_scene GF_InlineScene;\r
43 typedef struct _media_manager GF_MediaManager;\r
44 typedef struct _object_clock GF_Clock;\r
45 typedef struct _es_channel GF_Channel;\r
46 typedef struct _generic_codec GF_Codec;\r
47 typedef struct _composition_memory GF_CompositionMemory;\r
48 \r
49 \r
50 struct _net_service\r
51 {\r
52         /*the module handling this service - must be declared first to typecast with GF_DownlaodSession upon deletion*/\r
53         GF_InputService *ifce;\r
54 \r
55         /*the terminal*/\r
56         struct _tag_terminal *term;\r
57         /*service url*/\r
58         char *url;\r
59         /*od_manager owning service, NULL for services created for remote channels*/\r
60         struct _od_manager *owner;\r
61         /*number of attached remote channels ODM (ESD URLs)*/\r
62         u32 nb_ch_users;\r
63         /*number of attached remote ODM (OD URLs)*/\r
64         u32 nb_odm_users;\r
65         \r
66         /*clock objects. Kept at service level since ESID namespace is the service one*/\r
67         GF_List *Clocks;\r
68         /*all downloaders objects used in this service*/\r
69         GF_List *dnloads;\r
70         /*cache asscoiated with service, if any*/\r
71         GF_StreamingCache *cache;\r
72 };\r
73 \r
74 \r
75 /*opens service - performs URL concatenation if parent service specified*/\r
76 GF_ClientService *gf_term_service_new(GF_Terminal *term, GF_ObjectManager *owner, const char *url, const char *parent_url, GF_Err *ret_code);\r
77 /*destroy service*/\r
78 void gf_term_service_del(GF_ClientService *nets);\r
79 \r
80 /*access to the module interfaces - cf net_api.h GF_InputService for details*/\r
81 GF_Err gf_term_service_command(GF_ClientService *ns, GF_NetworkCommand *com);\r
82 Bool gf_term_service_can_handle_url(GF_ClientService *ns, char *url);\r
83 \r
84 GF_Err gf_term_channel_get_sl_packet(GF_ClientService *ns, LPNETCHANNEL channel, char **out_data_ptr, u32 *out_data_size, GF_SLHeader *out_sl_hdr, Bool *is_compressed, GF_Err *out_reception_status, Bool *is_new_data);\r
85 GF_Err gf_term_channel_release_sl_packet(GF_ClientService *ns, LPNETCHANNEL channel);\r
86 \r
87 /*cache open/close*/\r
88 GF_Err gf_term_service_cache_load(GF_ClientService *ns);\r
89 GF_Err gf_term_service_cache_close(GF_ClientService *ns, Bool no_save);\r
90 \r
91 /*forwards all clocks of the given amount of time. Can only be used when terminal is in paused mode\r
92 this is mainly designed for movie dumping in MP4Client*/\r
93 GF_Err gf_term_step_clocks(GF_Terminal * term, u32 ms_diff);\r
94 \r
95 void gf_term_sample_clocks(GF_Terminal *term);\r
96 \r
97 /*\r
98                 Inline scene stuff\r
99 */\r
100 struct _inline_scene\r
101 {\r
102         /*root OD of the subscene, ALWAYS namespace of the parent scene*/\r
103         struct _od_manager *root_od;\r
104         /*scene codec: top level decoder decoding/generating the scene - can be BIFS, VRML parser, etc*/\r
105         struct _generic_codec *scene_codec;\r
106         /*OD codec - specific to MPEG-4, only present at the inline level (media ressources are always scoped here)*/\r
107         struct _generic_codec *od_codec;\r
108 \r
109         /*struct _od_managers used, namespace of this scene. The chain does not have the root_od\r
110         it only contains OD sent through OD UPDATE in the OD stream(s) attached \r
111         to this scene. Remote ODs are not added, only there parents are*/\r
112         GF_List *ODlist;\r
113         /*list of MOs (links between OD and nodes)*/\r
114         GF_List *media_objects;\r
115         /*list of externproto libraries*/\r
116         GF_List *extern_protos;\r
117         /*list of nodes using this inline*/\r
118         GF_List *inline_nodes;\r
119         /*list of extra scene graphs (text streams, generic OSDs, ...)*/\r
120         GF_List *extra_scenes;\r
121         /*inline scene graph*/\r
122         GF_SceneGraph *graph;\r
123         /*graph state - if not attached, no traversing of inline\r
124         0: not attached\r
125         1: attached\r
126         2: temp graph attached. The temp graph is generated when waiting for the first scene AU to be processed\r
127         */\r
128         u32 graph_attached;\r
129         /*togles inline restart - needed because the restart may be triggered from inside the scene or from\r
130         parent scene, hence 2 render passes must be used\r
131         special value 2 means scene URL changes (for anchor navigation*/\r
132         u32 needs_restart;\r
133         /*duration of inline scene*/\r
134         u64 duration;\r
135         /*if not 0, all objects in the scene will run on this clock. Needed in GPAC when clock references do not\r
136         respect object graph (eg IOD depending on external stream for clock)*/\r
137         u16 force_sub_clock_id;\r
138         /*world info node or title node*/\r
139         void *world_info;\r
140 \r
141         Bool is_dynamic_scene;\r
142         /*clock for dynamic scene - current assumption is that all selected streams are synchronized in the dyn scene*/\r
143         GF_Clock *dyn_ck;\r
144         /*URLs of current video, audio and subs (we can't store objects since they may be destroyed when seeking)*/\r
145         SFURL visual_url, audio_url, text_url;\r
146         /*set to 1 when single time-line presentation with ONE OD AU is detected - the goal is to prevent\r
147         OD shutdown/startup when seeking. This will also remove unneeded net traffic for AddChannel/RemoveChannel\r
148         like RTSP TEARDOWN/SETUP*/\r
149         Bool static_media_ressources;\r
150 \r
151         /*current simulation time of the compositor*/\r
152         Double simulation_time;\r
153 \r
154         /*current IRI fragment if any*/\r
155         char *fragment_uri;\r
156 \r
157         /*secondary resource scene*/\r
158         Bool secondary_resource;\r
159 \r
160         char *redirect_xml_base;\r
161 };\r
162 \r
163 GF_InlineScene *gf_inline_new(GF_InlineScene *parentScene);\r
164 void gf_inline_del(GF_InlineScene *is);\r
165 struct _od_manager *gf_inline_find_odm(GF_InlineScene *is, u16 OD_ID);\r
166 void gf_inline_disconnect(GF_InlineScene *is, Bool for_shutdown);\r
167 void gf_inline_remove_object(GF_InlineScene *is, GF_ObjectManager *odm, Bool for_shutdown);\r
168 /*browse all (media) channels and send buffering info to the app*/\r
169 void gf_inline_buffering_info(GF_InlineScene *is);\r
170 void gf_inline_attach_to_compositor(GF_InlineScene *is);\r
171 struct _mediaobj *gf_inline_get_media_object(GF_InlineScene *is, MFURL *url, u32 obj_type_hint, Bool lock_timelines);\r
172 struct _mediaobj *gf_inline_get_media_object_ex(GF_InlineScene *is, MFURL *url, u32 obj_type_hint, Bool lock_timelines, struct _mediaobj *sync_ref, Bool always_load_new, GF_Node *node_ptr);\r
173 void gf_inline_setup_object(GF_InlineScene *is, GF_ObjectManager *odm);\r
174 /*restarts inline scene - care has to be taken not to remove the scene while it is traversed*/\r
175 void gf_inline_restart(GF_InlineScene *is);\r
176 /*updates scene duration based on settings*/\r
177 void gf_inline_set_duration(GF_InlineScene *is);\r
178 /*locate media object by ODID (non dynamic ODs) or URL (dynamic ODs)*/\r
179 struct _mediaobj *gf_inline_find_object(GF_InlineScene *is, u16 ODID, char *url);\r
180 /*returns scene time in sec - exact meaning of time depends on standard used*/\r
181 Double gf_inline_get_time(void *_is);\r
182 /*returns true if the given node DEF name is the url target view (eg blabla#myview)*/\r
183 Bool gf_inline_default_scene_viewpoint(GF_Node *node);\r
184 /*register extra scene graph for on-screen display*/\r
185 void gf_inline_register_extra_graph(GF_InlineScene *is, GF_SceneGraph *extra_scene, Bool do_remove);\r
186 /*forces scene size info (without changing pixel metrics) - this may be needed by modules using extra graphs (like timedtext)*/\r
187 void gf_inline_force_scene_size(GF_InlineScene *is, u32 width, u32 height);\r
188 /*regenerate a scene graph based on available objects - can only be called for dynamic OD streams*/\r
189 void gf_inline_regenerate(GF_InlineScene *is);\r
190 /*selects given ODM for dynamic scenes*/\r
191 void gf_inline_select_object(GF_InlineScene *is, GF_ObjectManager *odm);\r
192 /*restarts dynamic scene from given time: scene graph is not reseted, objects are just restarted\r
193 instead of closed and reopened. If a media control is present on inline, from_time is overriden by MC range*/\r
194 void gf_inline_restart_dynamic(GF_InlineScene *is, u64 from_time);\r
195 /*owner inline node has been modified*/\r
196 void gf_inline_on_modified(GF_Node *node);\r
197 /*returns scene graph associated with an externProto lib - exported for VRML/X3D loaded*/\r
198 GF_SceneGraph *gf_inline_get_proto_lib(void *_is, MFURL *lib_url);\r
199 /*exported for compositor: handles filtering of "self" parameter indicating anchor only acts on container inline scene\r
200 not root one. Returns 1 if handled (cf user.h, navigate event)*/\r
201 Bool gf_inline_process_anchor(GF_Node *caller, GF_Event *evt);\r
202 /*extern proto fetcher*/\r
203 GF_SceneGraph *gf_inline_get_proto_lib(void *SceneCallback, MFURL *lib_url);\r
204 void gf_inline_force_scene_size_video(GF_InlineScene *is, GF_MediaObject *mo);\r
205 void gf_inline_sample_time(GF_InlineScene *is);\r
206 /*compares object URL with another URL - ONLY USE THIS WITH DYNAMIC ODs*/\r
207 Bool gf_mo_is_same_url(GF_MediaObject *obj, MFURL *inline_url);\r
208 \r
209 void gf_mo_update_caps(GF_MediaObject *mo);\r
210 \r
211 \r
212 const char *gf_inline_get_fragment_uri(GF_Node *node);\r
213 void gf_inline_set_fragment_uri(GF_Node *node, const char *uri);\r
214 \r
215 enum\r
216 {\r
217         /*threading up to decoder*/\r
218         GF_TERM_THREAD_FREE,\r
219         /*single thread for all decoders*/\r
220         GF_TERM_THREAD_SINGLE,\r
221         /*all media (image, video, audio) decoders are threaded*/\r
222         GF_TERM_THREAD_MULTI,\r
223 };\r
224 \r
225 enum\r
226 {\r
227         GF_TERM_RUNNING= 1,\r
228         GF_TERM_DEAD = 1<<1,\r
229         GF_TERM_SINGLE_THREAD = 1<<2,\r
230         GF_TERM_MULTI_THREAD = 1<<3,\r
231         GF_TERM_SYSDEC_RESYNC = 1<<4,\r
232         GF_TERM_SINGLE_CLOCK = 1<<5,\r
233         GF_TERM_DRAW_FRAME = 1<<6\r
234 };\r
235 \r
236 \r
237 \r
238 struct _tag_terminal\r
239 {\r
240         u32 flags;\r
241 \r
242         /*callback to user application*/        \r
243         GF_User *user;\r
244         /*scene compositor*/\r
245         struct __tag_compositor *compositor;\r
246         /*file downloader*/\r
247         GF_DownloadManager *downloader;\r
248         /*top level scene*/\r
249         GF_InlineScene *root_scene;\r
250 \r
251         /*Media manager*/\r
252         GF_List *codecs;\r
253         /*mutex for decoder access*/\r
254         GF_Mutex *mm_mx;\r
255         /*decoding thread*/\r
256         GF_Thread *mm_thread;\r
257         /*last codec used in mm loop*/\r
258         u32 last_codec;\r
259         /*thread priority*/\r
260         s32 priority;\r
261         u32 cumulated_priority;\r
262         /*frame duration*/\r
263         u32 frame_duration;\r
264 \r
265         /*net services*/\r
266         GF_List *net_services;\r
267         /*net services to be destroyed*/\r
268         GF_List *net_services_to_remove;\r
269         /*channels waiting for service CONNECT ack to be setup*/\r
270         GF_List *channels_pending;\r
271         /*media objects pending for stop/play*/\r
272         GF_List *media_queue;\r
273         /*network lock*/\r
274         GF_Mutex *net_mx;\r
275         /*all X3D key/mouse/string sensors*/\r
276         GF_List *x3d_sensors;\r
277         /*all input stream decoders*/\r
278         GF_List *input_streams;\r
279         \r
280         /*options (cf config doc)*/\r
281         Bool enable_cache;\r
282         /*data timeout for network buffering in ms - if no data is received within this timeout\r
283         the initial buffering aborts. */\r
284         u32 net_data_timeout;\r
285 \r
286         u32 play_state;\r
287 \r
288         u32 reload_state;\r
289         char *reload_url;\r
290 \r
291         /*special list used by nodes needing a call to RenderNode but not in the traverese scene graph (VRML/MPEG-4 protos only). \r
292         For these nodes, the traverse effect passed will be NULL. This is only used by InputSensor node at the moment*/\r
293         GF_List *nodes_pending;\r
294 \r
295         /*root node of the user prefs*/\r
296         GF_SceneGraph *dcci_doc;\r
297 \r
298         GF_List *extensions;\r
299         GF_List *unthreaded_extensions;\r
300 };\r
301 \r
302 \r
303 \r
304 GF_Err gf_term_init_scheduler(GF_Terminal *term, u32 threading_mode);\r
305 void gf_term_stop_scheduler(GF_Terminal *term);\r
306 void gf_term_add_codec(GF_Terminal *term, GF_Codec *codec);\r
307 void gf_term_remove_codec(GF_Terminal *term, GF_Codec *codec);\r
308 void gf_term_start_codec(GF_Codec *codec);\r
309 void gf_term_stop_codec(GF_Codec *codec);\r
310 void gf_term_set_threading(GF_Terminal *term, u32 mode);\r
311 void gf_term_set_priority(GF_Terminal *term, s32 Priority);\r
312 \r
313 \r
314 /*error report function*/\r
315 void gf_term_message(GF_Terminal *app, const char *service, const char *message, GF_Err error);\r
316 /*creates service for given OD / URL*/\r
317 void gf_term_connect_object(GF_Terminal *app, GF_ObjectManager *odm, char *serviceURL, char *parent_url);\r
318 /*creates service for given channel / URL*/\r
319 GF_Err gf_term_connect_remote_channel(GF_Terminal *app, GF_Channel *ch, char *URL);\r
320 \r
321 /*called by media manager to perform service maintenance:\r
322 servive shutdown: this is needed because service handler may be asynchronous\r
323 object Play: this is needed to properly handle multiplexed sources (all channels must be connected before play)\r
324 service restart\r
325 */\r
326 void gf_term_handle_services(GF_Terminal *app);\r
327 /*close service and queue for delete*/\r
328 void gf_term_close_services(GF_Terminal *app, GF_ClientService *service);\r
329 \r
330 /*locks net manager*/\r
331 void gf_term_lock_net(GF_Terminal *app, Bool LockIt);\r
332 \r
333 \r
334 /*locks scene compositor*/\r
335 void gf_term_lock_compositor(GF_Terminal *app, Bool LockIt);\r
336 /*get scene compositor time - FIXME this is not flexible enough for SMIL/Multiple time containers*/\r
337 u32 gf_term_get_time(GF_Terminal *term);\r
338 /*forces scene composition*/\r
339 void gf_term_invalidate_compositor(GF_Terminal *term);\r
340 \r
341 /*callbacks for scene graph library so that all related ESM nodes are properly instanciated*/\r
342 void gf_term_node_callback(void *_is, u32 type, GF_Node *node, void *param);\r
343 \r
344 /*add/rem node requiring a call to render without being present in traversed graph (VRML/MPEG-4 protos). \r
345 For these nodes, the traverse effect passed will be NULL.*/\r
346 void gf_term_queue_node_traverse(GF_Terminal *term, GF_Node *node);\r
347 void gf_term_unqueue_node_traverse(GF_Terminal *term, GF_Node *node);\r
348 \r
349 \r
350 \r
351 /*clock*/\r
352 struct _object_clock \r
353 {\r
354         u16 clockID;    \r
355         GF_Terminal *term;\r
356         GF_Mutex *mx;\r
357         /*no_time_ctrl : set if ANY stream running on this clock has no time control capabilities - this avoids applying\r
358         mediaControl and others that would break stream dependencies*/\r
359         Bool use_ocr, clock_init, has_seen_eos, no_time_ctrl;\r
360         u32 init_time, StartTime, PauseTime, Paused;\r
361         /*the number of streams buffering on this clock*/\r
362         u32 Buffering;\r
363         /*associated media control if any*/\r
364         struct _media_control *mc;\r
365         /*for MC only (no FlexTime)*/\r
366         Fixed speed;\r
367         u32 discontinuity_time;\r
368         s32 drift;\r
369 };\r
370 \r
371 /*destroys clock*/\r
372 void gf_clock_del(GF_Clock *ck);\r
373 /*finds a clock by ID or by ES_ID*/\r
374 GF_Clock *gf_clock_find(GF_List *Clocks, u16 clockID, u16 ES_ID);\r
375 /*attach clock returns a new clock or the clock this stream (ES_ID) depends on (OCR_ES_ID)\r
376 hasOCR indicates whether the stream being attached carries object clock references\r
377 @clocks: list of clocks in ES namespace (service)\r
378 @is: inline scene to solve clock dependencies\r
379 */\r
380 GF_Clock *gf_clock_attach(GF_List *clocks, GF_InlineScene *is, u16 OCR_ES_ID, u16 ES_ID, s32 hasOCR);\r
381 /*reset clock (only called by channel owning clock)*/\r
382 void gf_clock_reset(GF_Clock *ck);\r
383 /*stops clock (only called for scene clock)*/\r
384 void gf_clock_stop(GF_Clock *ck);\r
385 /*return clock time in ms*/\r
386 u32 gf_clock_time(GF_Clock *ck);\r
387 /*return ellapsed time in ms since start of the clock*/\r
388 u32 gf_clock_ellapse_time(GF_Clock *ck);\r
389 /*sets clock time - FIXME: drift updates for OCRs*/\r
390 void gf_clock_set_time(GF_Clock *ck, u32 TS);\r
391 /*return clock time in ms without drift adjustment - used by audio objects only*/\r
392 u32 gf_clock_real_time(GF_Clock *ck);\r
393 /*pause the clock*/\r
394 void gf_clock_pause(GF_Clock *ck);\r
395 /*resume the clock*/\r
396 void gf_clock_resume(GF_Clock *ck);\r
397 /*returns true if clock started*/\r
398 Bool gf_clock_is_started(GF_Clock *ck);\r
399 /*toggles buffering on (clock is paused at the first stream buffering) */\r
400 void gf_clock_buffer_on(GF_Clock *ck);\r
401 /*toggles buffering off (clock is paused at the last stream restarting) */\r
402 void gf_clock_buffer_off(GF_Clock *ck);\r
403 /*set clock speed scaling factor*/\r
404 void gf_clock_set_speed(GF_Clock *ck, Fixed speed);\r
405 /*set clock drift - used to resync audio*/\r
406 void gf_clock_adjust_drift(GF_Clock *ck, s32 ms_drift);\r
407 \r
408 enum\r
409 {\r
410         /*channel is setup and waits for connection request*/\r
411         GF_ESM_ES_SETUP = 0,\r
412         /*waiting for server reply*/\r
413         GF_ESM_ES_WAIT_FOR_ACK,\r
414         /*connection OK*/\r
415         GF_ESM_ES_CONNECTED,\r
416         /*data exchange on this service/channel*/\r
417         GF_ESM_ES_RUNNING,\r
418         /*deconnection OK - a download channel can automatically disconnect when download is done*/\r
419         GF_ESM_ES_DISCONNECTED,\r
420         /*service/channel is not (no longer) available/found and should be removed*/\r
421         GF_ESM_ES_UNAVAILABLE\r
422 };\r
423 \r
424 /*data channel (elementary stream)*/\r
425 struct _es_channel \r
426 {\r
427         /*security check on channel*/\r
428         u32 chan_id;\r
429         /*service this channel belongs to*/\r
430         GF_ClientService *service;\r
431         /*stream descriptor*/\r
432         GF_ESD *esd;\r
433         /*parent OD for this stream*/\r
434         struct _od_manager *odm;\r
435         u32 es_state;\r
436         Bool is_pulling;\r
437         u32 media_padding_bytes;\r
438         /*IO mutex*/\r
439         GF_Mutex *mx;\r
440         u32 AU_Count;\r
441         /*decoding buffers for push mode*/\r
442         struct _decoding_buffer * AU_buffer_first, * AU_buffer_last;\r
443         /*static decoding buffer for pull mode*/\r
444         struct _decoding_buffer * AU_buffer_pull;\r
445         /*channel buffer flag*/\r
446         Bool BufferOn;\r
447         /*min level to trigger buffering on, max to trigger it off. */\r
448         u32 MinBuffer, MaxBuffer;\r
449         /*amount of buffered media - this is the DTS of the last received AU minus the onject clock time, to make sure\r
450         we always have MaxBuffer ms ready for composition when resuming the clock*/\r
451         s32 BufferTime;\r
452         /*last received AU time - if exceeding a certain time and buffering is on, buffering is turned off.\r
453         This is needed for streams with very short duration (less than buffer time) and stream with only one AU (BIFS/OD)*/\r
454         u32 last_au_time;\r
455         /*Current reassemnbling buffer - currently packets are NOT reordered, only AUs are*/\r
456         char *buffer;\r
457         u32 len, allocSize;\r
458         /*only for last packet of an AU*/\r
459         u8 padingBits;\r
460         Bool IsEndOfStream;\r
461         /*      SL reassembler  */\r
462         /*current AU TSs*/\r
463         u32 DTS, CTS;\r
464         /*AU and Packet seq num info*/\r
465         u32 au_sn, pck_sn;\r
466         u32 max_au_sn, max_pck_sn;\r
467         /*the AU length indicated in the SL Header. */\r
468         u32 AULength;\r
469         /*state indicator: 0 OK, 1: not tuned in, 2: has error and needs RAP*/\r
470         u32 stream_state;\r
471         /*the AU in reception is RAP*/\r
472         Bool IsRap;\r
473         /*signal that next AU is an AU start*/\r
474         Bool NextIsAUStart;\r
475         /*if codec resilient, packet drops are not considered as fatal for AU reconstruction (eg no wait for RAP)*/\r
476         Bool codec_resilient;\r
477         /*when starting a channel, the first AU is ALWAYS fetched when buffering - this forces\r
478         BIFS and OD to be decoded and first frame render, in order to detect media objects that would also need\r
479         buffering - note this doesn't affect the clock, it is still paused if buffering*/\r
480         Bool first_au_fetched;\r
481 \r
482         /* used in Carousel, to skip packets until the end of AU */ \r
483         Bool skip_carousel_au;\r
484         \r
485         /* TimeStamp to Media Time mapping*/\r
486         /*TS (in TSResolution) corresponding to the SeedTime of the decoder. Delivered by net, otherwise 0*/\r
487         u64 seed_ts;\r
488         /*media time offset corresponding to SeedTS. This is needed when the channel doesn't own the clock*/\r
489         u32 ts_offset;\r
490         /*scaling factors to remap to timestamps in milliseconds*/\r
491         u64 ts_res;\r
492         Double ocr_scale;\r
493         /*clock driving this stream - currently only CTS is supported (no OCR)*/\r
494         struct _object_clock *clock;\r
495         /*flag for clock init. Only a channel owning the clock will set this flag on clock init*/\r
496         Bool IsClockInit;\r
497 \r
498         /*duration of last received AU if any, 0 if not known (most of the time)*/\r
499         u32 au_duration;\r
500         /*A channel with this flag set considers each incoming packet as a complete AU and assigns timestamps \r
501         upon reception matching the reception time, then dispatching it into the decoding buffer (only tested\r
502         with audi video). This flag is turned on by setting esd->slconfig->predefined to 'SLPredef_SkipSL' */\r
503         Bool skip_sl;\r
504 \r
505         /*indicates that decoding can be called directly when receiving a complete AU on this channel\r
506         This is used by systems streams in non-seekable (eg broadcast/multicast, MPEG-2 TS multiplexes) to \r
507         make sure resources are setup as fast as possible. If the AU is too early, it will be kept in the \r
508         decoding buffer*/\r
509         Bool dispatch_after_db;\r
510 \r
511         /*indicates that decoding is called directly when receiving a packet on this channel\r
512         This is used to bypass SL defragmenting and decoding buffer for EIT internal streams*/\r
513         Bool bypass_sl_and_db;\r
514 \r
515         GF_IPMPTool *ipmp_tool;\r
516         Bool is_protected;\r
517 \r
518         /*TSs as received from network - these are used for cache storage*/\r
519         u64 net_dts, net_cts;\r
520 };\r
521 \r
522 /*creates a new channel for this stream*/\r
523 GF_Channel *gf_es_new(GF_ESD *esd);\r
524 /*destroys channel*/\r
525 void gf_es_del(GF_Channel *ch);\r
526 /*(un)locks channel*/\r
527 void gf_es_lock(GF_Channel *ch, u32 LockIt);\r
528 /*setup channel for reception of data*/\r
529 GF_Err gf_es_start(GF_Channel *ch);\r
530 /*stop channel from receiving data*/\r
531 GF_Err gf_es_stop(GF_Channel *ch);\r
532 /*handles reception of an SL PDU*/\r
533 void gf_es_receive_sl_packet(GF_ClientService *serv, GF_Channel *ch, char *StreamBuf, u32 StreamLength, GF_SLHeader *header, GF_Err reception_status);\r
534 /*signals end of stream on the channel*/\r
535 void gf_es_on_eos(GF_Channel *ch);\r
536 /*fetches first AU available for decoding on this channel*/\r
537 struct _decoding_buffer *gf_es_get_au(GF_Channel *ch);\r
538 /*drops first AU on this channel*/\r
539 void gf_es_drop_au(GF_Channel *ch);\r
540 /*performs final setup upon connection confirm*/\r
541 void gf_es_on_connect(GF_Channel *ch);\r
542 /*reconfigure SL for this channel*/\r
543 void gf_es_reconfig_sl(GF_Channel *ch, GF_SLConfig *slc);\r
544 /*hack for streaming: whenever a time map (media time <-> TS time) event is received on the channel reset decoding buffer\r
545 this is needed because all server tested resend packets on already running channel*/\r
546 void gf_es_map_time(GF_Channel *ch, Bool reset);\r
547 /*dummy channels are used by scene decoders which don't use ESM but load directly the scene graph themselves\r
548 these channels are ALWAYS pulling ones, and this function will init the channel clock if needed*/\r
549 void gf_es_init_dummy(GF_Channel *ch);\r
550 /*setup DRM info*/\r
551 void gf_es_config_drm(GF_Channel *ch, GF_NetComDRMConfig *isma_cryp);\r
552 \r
553 /*\r
554                 decoder stuff\r
555 */\r
556 enum\r
557 {\r
558         /*stop: the decoder is not playing*/\r
559         GF_ESM_CODEC_STOP       =       0,\r
560         /*stop: the decoder is playing*/\r
561         GF_ESM_CODEC_PLAY       =       1,\r
562         /*End Of Stream: when the base layer signals it's done, this triggers media-specific\r
563         handling of the CB. \r
564         For video, the output is kept alive, For audio, the output is reseted (don't want audio loop ;)*/\r
565         GF_ESM_CODEC_EOS        =       2,\r
566         /*pause: the decoder is stoped but the CB is kept intact\r
567         THIS IS NOT USED AS A CODEC STATUS, but only for signaling that the CB shouldn't \r
568         be reseted - the real status of a "paused" decoder is STOP*/\r
569         GF_ESM_CODEC_PAUSE      =       3,\r
570         /*Buffer: transition state: the decoder runs (fetch data/decode) but the clock\r
571         is not running (no composition). This is used for rebuffering channels (rtp...)*/\r
572         GF_ESM_CODEC_BUFFER =   4\r
573 };\r
574 \r
575 enum\r
576 {\r
577         GF_ESM_CODEC_HAS_UPSTREAM = 1,\r
578         /*the codec uses the interface from another codec (only used by private scene streams to handle\r
579         any intern sprite/animation streams)*/\r
580         GF_ESM_CODEC_IS_USE = 1<<1,\r
581         /*set for OD codec when static (ressources are declared in OD stream esd a la ISMA*/\r
582         GF_ESM_CODEC_IS_STATIC_OD = 1<<2,\r
583 };\r
584 \r
585 struct _generic_codec \r
586 {\r
587         /*codec type (streamType from base layer)*/\r
588         u32 type;\r
589         u32 flags;\r
590         /*current decoder interface */\r
591         GF_BaseDecoder *decio;\r
592         /*composition memory for media streams*/\r
593         struct _composition_memory *CB;\r
594         /*input media channles*/\r
595         GF_List *inChannels;\r
596         /*a pointer to the OD that owns the decoder.*/\r
597         struct _od_manager *odm;\r
598         u32 Status;\r
599         Bool Muted;\r
600         struct _object_clock *ck;\r
601         /*priority of this media object. This is ALWAYS the base layer priority\r
602         PriorityBoost is set when the CB is under critical limit (for now only audio uses the feature)\r
603         and results in a bigger time slice for the codec. Only on/off value for now*/\r
604         u32 Priority, PriorityBoost;\r
605         /*last processed DTS - sanity check for scalability*/\r
606         u32 last_unit_dts;\r
607         /*last processed CTS on base layer - seeking detection*/\r
608         u32 last_unit_cts;\r
609         /*in case the codec performs temporal re-ordering itself*/\r
610         Bool is_reordering;\r
611         u32 prev_au_size;\r
612         u32 bytes_per_sec;\r
613         Double fps;\r
614 \r
615         /*statistics*/\r
616         u32 last_stat_start, cur_bit_size;\r
617         u32 avg_bit_rate, max_bit_rate;\r
618         u32 total_dec_time, nb_dec_frames, max_dec_time;\r
619         /*number of droped frames*/\r
620         u32 nb_droped;\r
621 \r
622         /*for CTS reconstruction (channels not using SL): we cannot just update timing at each frame, not precise enough \r
623         since we use ms and not microsec TSs*/\r
624         u32 cur_audio_bytes, cur_video_frames;\r
625 };\r
626 \r
627 GF_Codec *gf_codec_new(GF_ObjectManager *odm, GF_ESD *base_layer, s32 PL, GF_Err *e);\r
628 void gf_codec_del(GF_Codec *codec);\r
629 GF_Err gf_codec_add_channel(GF_Codec *codec, GF_Channel *ch);\r
630 /*returns TRUE if stream was present, false otherwise*/\r
631 Bool gf_codec_remove_channel(GF_Codec *codec, GF_Channel *ch);\r
632 GF_Err gf_codec_process(GF_Codec *codec, u32 TimeAvailable);\r
633 GF_Err gf_codec_get_capability(GF_Codec *codec, GF_CodecCapability *cap);\r
634 GF_Err gf_codec_set_capability(GF_Codec *codec, GF_CodecCapability cap);\r
635 void gf_codec_set_status(GF_Codec *codec, u32 Status);\r
636 /*returns a new codec using an existing loaded decoder - only used by private scene to handle != timelines, for \r
637 instance when loading a BT with an animation stream*/\r
638 GF_Codec *gf_codec_use_codec(GF_Codec *codec, GF_ObjectManager *odm);\r
639 \r
640 /*OD manager*/\r
641 \r
642 enum\r
643 {\r
644         /*flag set if object cannot be time-controloed*/\r
645         GF_ODM_NO_TIME_CTRL = (1<<1),\r
646         /*flag set if subscene uses parent scene timeline*/\r
647         GF_ODM_INHERIT_TIMELINE = (1<<2),\r
648         /*flag set if object has been redirected*/\r
649         GF_ODM_REMOTE_OD = (1<<3),\r
650         /*flag set if object has profile indications*/\r
651         GF_ODM_HAS_PROFILES = (1<<4),\r
652         /*flag set if object governs profile of inline subscenes*/\r
653         GF_ODM_INLINE_PROFILES = (1<<5),\r
654         /*flag set if object declared by network service, not from OD stream*/\r
655         GF_ODM_NOT_IN_OD_STREAM = (1<<6),\r
656 \r
657         /*dynamic flags*/\r
658         \r
659         /*flag set if associated subscene must be regenerated*/\r
660         GF_ODM_REGENERATE_SCENE = (1<<10),\r
661 };\r
662 \r
663 enum\r
664 {\r
665         GF_ODM_STATE_STOP,\r
666         GF_ODM_STATE_PLAY,\r
667         GF_ODM_STATE_IN_SETUP,\r
668         GF_ODM_STATE_BLOCKED,\r
669 };\r
670 \r
671 struct _od_manager\r
672 {\r
673         /*pointer to terminal*/\r
674         struct _tag_terminal *term;\r
675         /*the service used by this ODM. If the service private data is this ODM, then the service was created for this ODM*/\r
676         GF_ClientService *net_service;\r
677         /*parent scene or NULL for root scene*/\r
678         struct _inline_scene *parentscene;\r
679         /*channels associated with this object (media channels, OCR, IPMP, OCI, etc)*/\r
680         GF_List *channels;\r
681         /*sub scene for inline/animation or NULL */\r
682         struct _inline_scene *subscene;\r
683         /*object codec (media or BIFS for AnimationStream) attached if any*/\r
684         struct _generic_codec *codec;\r
685         /*OCI codec attached if any*/\r
686         struct _generic_codec *oci_codec;\r
687         /*OCR codec attached if any*/\r
688         struct _generic_codec *ocr_codec;\r
689 \r
690         /*MPEG-4 object descriptor*/\r
691         GF_ObjectDescriptor *OD;\r
692 \r
693         /*exclusive access is required since rendering and media management don't always take place in the same thread*/\r
694         GF_Mutex *mx;\r
695 \r
696         u32 flags;\r
697 \r
698         /*PLs*/\r
699         u8 Audio_PL, Graphics_PL, OD_PL, Scene_PL, Visual_PL;\r
700         \r
701         /*interface with scene rendering*/\r
702         struct _mediaobj *mo;\r
703         \r
704         /*number of channels with connection not yet acknowledge*/\r
705         u32 pending_channels;\r
706         u32 state;\r
707         /* during playback: timing as evaluated by the composition memory or the scene codec */\r
708         u32 current_time;\r
709         /*full object duration 0 if unknown*/\r
710         u64 duration;\r
711         /*\r
712         upon start: media start time as requested by scene compositor (eg not media control)\r
713         set to -1 upon stop to postpone stop request\r
714         */\r
715         u64 media_start_time, media_stop_time;\r
716 \r
717         /*the one and only media control currently attached to this object*/\r
718         struct _media_control *media_ctrl;\r
719         /*the list of media control controling the object*/\r
720         GF_List *mc_stack;\r
721         /*the media sensor(s) attached to this object*/\r
722         GF_List *ms_stack;\r
723 };\r
724 \r
725 \r
726 GF_ObjectManager *gf_odm_new();\r
727 void gf_odm_del(GF_ObjectManager *ODMan);\r
728 void gf_odm_lock(GF_ObjectManager *odm, u32 LockIt);\r
729 \r
730 /*setup service entry point*/\r
731 void gf_odm_setup_entry_point(GF_ObjectManager *odm, const char *sub_url);\r
732 /*setup OD*/\r
733 void gf_odm_setup_object(GF_ObjectManager *odm, GF_ClientService *parent_serv);\r
734 /*disctonnect OD and removes it if desired (otherwise only STOP is propagated)*/\r
735 void gf_odm_disconnect(GF_ObjectManager *odman, Bool do_remove);\r
736 /*setup an ESD*/\r
737 GF_Err gf_odm_setup_es(GF_ObjectManager *odm, GF_ESD *esd, GF_ClientService *service, GF_MediaObject *sync_ref);\r
738 /*removes an ESD (this destroys associated channel if any)*/\r
739 void gf_odm_remove_es(GF_ObjectManager *odm, u16 ES_ID);\r
740 /*set stream duration - updates object duration accordingly*/\r
741 void gf_odm_set_duration(GF_ObjectManager *odm, GF_Channel *, u64 stream_duration);\r
742 /*signals end of stream on channels*/\r
743 void gf_odm_on_eos(GF_ObjectManager *odm, GF_Channel *);\r
744 /*start Object streams and queue object for network PLAY*/\r
745 void gf_odm_start(GF_ObjectManager *odm);\r
746 /*stop OD streams*/\r
747 void gf_odm_stop(GF_ObjectManager *odm, Bool force_close);\r
748 /*send PLAY request to network - needed to properly handle multiplexed inputs \r
749 ONLY called by service handler (media manager thread)*/\r
750 void gf_odm_play(GF_ObjectManager *odm);\r
751 \r
752 /*returns 1 if this is a segment switch, 0 otherwise - takes care of object restart if segment switch*/\r
753 Bool gf_odm_check_segment_switch(GF_ObjectManager *odm);\r
754 /*pause object (mediaControl use only)*/\r
755 void gf_odm_pause(GF_ObjectManager *odm);\r
756 /*resume object (mediaControl use only)*/\r
757 void gf_odm_resume(GF_ObjectManager *odm);\r
758 /*set object speed*/\r
759 void gf_odm_set_speed(GF_ObjectManager *odm, Fixed speed);\r
760 /*returns the clock of the media stream (video, audio or bifs), NULL otherwise */\r
761 struct _object_clock *gf_odm_get_media_clock(GF_ObjectManager *odm);\r
762 /*adds segment descriptors targeted by the URL to the list and sort them - the input list must be empty*/\r
763 void gf_odm_init_segments(GF_ObjectManager *odm, GF_List *list, MFURL *url);\r
764 /*returns true if this OD depends on the given clock*/\r
765 Bool gf_odm_shares_clock(GF_ObjectManager *odm, struct _object_clock *ock);\r
766 \r
767 GF_Segment *gf_odm_find_segment(GF_ObjectManager *odm, char *descName);\r
768 /*locks ODM with destruction check - returns 0 if object manager is not attached to object*/\r
769 Bool gf_odm_lock_mo(struct _mediaobj *mo);\r
770 \r
771 \r
772 /*GF_MediaObject: link between real object manager and scene. although there is a one-to-one mapping between a \r
773 MediaObject and an ObjectManager, we have to keep them seperated in order to handle OD remove commands which destroy\r
774 ObjectManagers. */\r
775 struct _mediaobj\r
776 {\r
777         /*type is as defined in constants.h # GF_MEDIA_OBJECT_* */\r
778         u32 type;\r
779         /*one of the above flags*/\r
780         u32 flags;\r
781 \r
782 \r
783         /* private to ESM*/\r
784 \r
785         /*media object manager - private to the sync engine*/\r
786         struct _od_manager *odm;\r
787         /*OD ID of the object*/\r
788         u32 OD_ID;\r
789         /*OD URL for object not using MPEG4 OD urls*/\r
790         MFURL URLs;\r
791         /*session join*/\r
792         u32 num_open;\r
793         /*shared object restart handling*/\r
794         u32 num_to_restart, num_restart;\r
795         Fixed speed;\r
796 \r
797         /*shared object info: if 0 a new frame will be checked, otherwise current is returned*/\r
798         u32 nb_fetch;\r
799         /*frame presentation time*/\r
800         u32 timestamp;\r
801         /*data frame size*/\r
802         u32 framesize;\r
803         /*pointer to data frame */\r
804         char *frame;\r
805         /*nodes currently registered with the media object - used to dispatch MediaAccessEvents*/\r
806         GF_List *nodes;\r
807         /*pointer to the node responsible for the creation of this media object\r
808         ONLY used for scene media type (animationStreams) \r
809         Reset upon creation of the decoder.\r
810         */\r
811         void *node_ptr;\r
812 };\r
813 \r
814 GF_MediaObject *gf_mo_new();\r
815 \r
816 \r
817 /*used for delayed channel setup*/\r
818 typedef struct \r
819 {\r
820         struct _generic_codec *dec;\r
821         struct _es_channel *ch; \r
822 } GF_ChannelSetup;\r
823 \r
824 /*post-poned channel connect*/\r
825 GF_Err gf_odm_post_es_setup(struct _es_channel *ch, struct _generic_codec *dec, GF_Err err);\r
826 \r
827 /*\r
828         special entry point: specify directly a service interface for service input\r
829 */\r
830 void gf_term_attach_service(GF_Terminal *term, GF_InputService *service_hdl);\r
831 \r
832 /*media access events */\r
833 void gf_term_service_media_event(GF_ObjectManager *odm, u32 event_type);\r
834 \r
835 u32 URL_GetODID(MFURL *url);\r
836 \r
837 #ifdef __cplusplus\r
838 }\r
839 #endif\r
840 \r
841 \r
842 #endif  /*_GF_TERMINAL_DEV_H_*/\r
843 \r
844 \r