1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
7 * Authors: David Flynn <davidf@rd.bbc.co.uk>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /* Dirac packetizer, formed of three parts:
25 * 1) Bitstream synchroniser (dirac_DoSync)
26 * - Given an arbitrary sequence of bytes, extract whole Dirac Data Units
27 * - Maps timestamps in supplied block_t's to the extracted Data Unit
28 * A time stamp applies to the next Data Unit to commence at, or after
29 * the first byte of the block_t with the timestamp.
30 * 2) Encapsulation Unit generation (dirac_BuildEncapsulationUnit)
31 * - Takes multiple well formed Dirac Data Units and forms them into a
32 * single encapsulation unit, suitable for muxing.
33 * - Sorts out any time stamps so that they only apply to pictures.
34 * 3) Timestamp generator (dirac_TimeGenPush)
35 * - Many streams will not be correctly timestamped, ie, DTS&PTS for
36 * every encapsulation unit. Timestamp generator syncs to avaliable
37 * timestamps and produces DTS&PTS for each encapsulation unit.
38 * - For 'Occasional' missing PTS|DTS:
39 * Missing timestamp is generated using interpolation from last
41 * - for All PTS missing:
42 * It is assumed that DTS values are fake, and are actually
43 * in the sequence of the PTS values at the output of a decoder.
44 * Fill in PTS by copying from DTS (accounting for reordering,
45 * by simulating reorder buffer); adjust DTS to provide correct
46 * value. This is how demuxers like AVI work.
47 * - for All DTS missing:
48 * (Ie, PTS is present), reorder buffer is simulated to determine
49 * PTS for each encapsulation unit.
50 * - NB, doesn't handle all pts missing with real dts. (no way to
51 * distinguish from the fake dts case.)
53 * DIRAC_NON_DATED is used to show a block should not have a time stamp
54 * associated (ie, don't interpolate a counter). At the output, these
55 * blocks get dated with the last used timestamp (or are merged with
56 * another encapsulation unit).
59 /*****************************************************************************
61 *****************************************************************************/
68 #include <vlc_common.h>
69 #include <vlc_plugin.h>
70 #include <vlc_codec.h>
71 #include <vlc_block.h>
74 #include <vlc_block_helper.h>
76 #define SANITIZE_PREV_PARSE_OFFSET 1
78 /*****************************************************************************
80 *****************************************************************************/
81 static int Open ( vlc_object_t * );
82 static void Close( vlc_object_t * );
85 set_category( CAT_SOUT )
86 set_subcategory( SUBCAT_SOUT_PACKETIZER )
87 set_description( N_("Dirac packetizer") )
88 set_capability( "packetizer", 50 )
89 set_callbacks( Open, Close )
92 /*****************************************************************************
94 *****************************************************************************/
98 block_bytestream_t bytestream;
102 /* recovered timestamp from bytesteram for use
103 * by synchroniser: should only get reset by the
104 * synchronizer upon a discontinuity sentinel */
108 /* build encapsulation unit state */
109 block_t *p_eu; /*< Current encapsulation unit being built */
110 block_t **pp_eu_last;
111 uint32_t u_eu_last_npo; /* last next_parse_offset at input to encapsulation */
115 /* timestamp generator state */
116 date_t dts; /*< timegen decode clock, increments at picture rate */
117 bool b_dts; /*< timegen decode clock valid */
119 bool b_pts; /*< timegen presentation time valid */
120 mtime_t i_pts; /*< timegen presentation time of picture u_pts_picnum */
121 uint32_t u_pts_picnum; /*< picture number of timegen presentation time */
123 mtime_t i_pts_offset; /*< maximum time between pts and dts */
125 /* p_outqueue is the list of encapsulation units that have been
126 * fed to the timegenerator. the timegenerator stamps them in
127 * the order it solves the time. the main packetizer loop removes
128 * completed encapsulation units from the front */
130 block_t **pp_outqueue_last;
131 /* p_out_dts points to an element in p_outqueue. It is used for VLC's
132 * fake pts hidden in DTS hack, as used by AVI */
135 uint32_t u_tg_last_picnum; /*< most recent picturenumber output from RoB */
136 bool b_tg_last_picnum; /*< u_tg_last_picnum valid */
138 struct dirac_reorder_buffer {
141 struct dirac_reorder_entry {
142 struct dirac_reorder_entry *p_next;
145 } p_entries[32], *p_head, *p_empty;
146 } reorder_buf; /*< reorder buffer, used by timegenerator */
148 /* packetizer state */
149 mtime_t i_pts_last_out; /*< last output [from packetizer] pts */
150 mtime_t i_dts_last_out; /*< last output [from packetizer] dts */
157 enum picture_coding_mode_t {
158 DIRAC_FRAME_CODING=0,
159 DIRAC_FIELD_CODING=1,
160 } u_picture_coding_mode;
161 } seq_hdr; /*< sequence header */
162 bool b_seen_seq_hdr; /* sequence header valid */
163 bool b_seen_eos; /* last data unit to be handled was an EOS */
167 uint32_t u_next_offset;
168 uint32_t u_prev_offset;
173 /*> next_parse_offset of the final data unit in associated block_t */
174 uint32_t u_last_next_offset;
175 /*> picture number is invalid if block has flags DIRAC_NON_DATED */
176 uint32_t u_picture_number;
177 } dirac_block_encap_t;
187 DIRAC_NON_DATED = (1 << BLOCK_FLAG_PRIVATE_SHIFT),
188 DIRAC_DISCARD = (2 << BLOCK_FLAG_PRIVATE_SHIFT),
197 * Block encapsulation functions.
198 * Things are greately simplified by associating some metadata
199 * with a block as it passes through the packetizer (saves having
200 * to determine it again)
202 * unfortunately p_block doesn't have a p_priv, so some fakage
204 * - Create a dummy block that has some extra storage, set up
205 * members to be identical to the actual block
206 * - Store private data there and pointer to orig block
207 * - modify block pointer to point to fake block
209 * NB, the add/new functions must not be used to blocks
210 * that are referenced in lists, etc., [in this code, this is ok]
211 * NB, don't call add on the same block multiple times (will leak)
213 * davidf has a patch that reverts this to use a p_priv in block_t.
218 dirac_block_encap_t *p_dbe;
221 static dirac_block_encap_t *dirac_RemoveBlockEncap( block_t *p_block )
223 fake_block_t *p_fake = (fake_block_t *)p_block;
224 dirac_block_encap_t *p_dbe = p_fake->p_dbe;
226 p_fake->p_dbe = NULL;
230 static void dirac_ReleaseBlockAndEncap( block_t *p_block )
232 fake_block_t *p_fake = (fake_block_t *)p_block;
234 free( dirac_RemoveBlockEncap( p_block ) );
235 block_Release( p_fake->p_orig );
239 static void dirac_AddBlockEncap( block_t **pp_block, dirac_block_encap_t *p_dbe )
241 /* must not fail, fixby: adding a p_priv to block_t */
242 fake_block_t *p_fake = xcalloc( 1, sizeof( *p_fake ) );
243 block_t *in = *pp_block, *out = &p_fake->fake;
245 block_Init( out, in->p_buffer, in->i_buffer );
246 out->i_flags = in->i_flags;
247 out->i_nb_samples = in->i_nb_samples;
248 out->i_pts = in->i_pts;
249 out->i_dts = in->i_dts;
250 out->i_length = in->i_length;
251 out->pf_release = dirac_ReleaseBlockAndEncap;
253 p_fake->p_dbe = p_dbe;
258 static dirac_block_encap_t *dirac_NewBlockEncap( block_t **pp_block )
260 dirac_block_encap_t *p_dbe = calloc( 1, sizeof( *p_dbe ) );
261 if( p_dbe ) dirac_AddBlockEncap( pp_block, p_dbe );
265 static dirac_block_encap_t *dirac_GetBlockEncap( block_t *p_block )
267 return ((fake_block_t *)p_block)->p_dbe;
271 * General utility funcions
275 * given a chain of block_t, allocate and return an array containing
276 * pointers to all the blocks. (Acts as a replacement for the old p_prev
277 * member of block_t) */
278 static int block_ChainToArray( block_t *p_block, block_t ***ppp_array)
284 block_ChainProperties( p_block, &i_num_blocks, NULL, NULL );
286 *ppp_array = calloc( i_num_blocks, sizeof( block_t* ) );
287 if( !*ppp_array ) return 0;
289 for( int i = 0; i < i_num_blocks; i++ )
291 (*ppp_array)[i] = p_block;
292 p_block = p_block->p_next;
299 * Destructively find and recover the earliest timestamp from start of
300 * bytestream, up to i_length.
302 static void dirac_RecoverTimestamps ( decoder_t *p_dec, size_t i_length )
304 decoder_sys_t *p_sys = p_dec->p_sys;
305 block_t *p_block = p_sys->bytestream.p_block;
307 /* Find the block with first non-flushed data */
308 size_t i_offset = p_sys->bytestream.i_offset;
309 for(; p_block != NULL; p_block = p_block->p_next )
311 if( i_offset < p_block->i_buffer )
313 i_offset -= p_block->i_buffer;
316 i_offset += i_length;
317 for(; p_block != NULL; p_block = p_block->p_next )
319 if( p_sys->i_sync_pts <= VLC_TS_INVALID && p_sys->i_sync_dts <= VLC_TS_INVALID )
321 /* oldest timestamp wins */
322 p_sys->i_sync_pts = p_block->i_pts;
323 p_sys->i_sync_dts = p_block->i_dts;
325 /* clear timestamps -- more than one data unit can come from a block */
326 p_block->i_flags = 0;
327 p_block->i_pts = p_block->i_dts = VLC_TS_INVALID;
328 if( i_offset < p_block->i_buffer )
330 i_offset -= p_block->i_buffer;
334 /* backdate the list [p_block .. p_block->p_next where p_next == p_last] */
335 static void dirac_BackdateDTS( block_t *p_block, block_t *p_last, date_t *p_dts )
337 /* Transverse p_last backwards. (no p_prev anymore) */
338 block_t **pp_array = NULL;
339 int n = block_ChainToArray( p_block, &pp_array );
340 while( n ) if( pp_array[--n] == p_last ) break;
341 /* want to start at p_last->p_prev */
344 if( pp_array[n]->i_flags & DIRAC_NON_DATED )
346 if( pp_array[n]->i_dts <= VLC_TS_INVALID )
347 pp_array[n]->i_dts = date_Decrement( p_dts, 1 );
352 /* backdate the list [p_block .. p_block->p_next where p_next == p_last] */
353 static void dirac_BackdatePTS( block_t *p_block, block_t *p_last, date_t *p_pts, uint32_t u_pts_picnum )
355 /* Transverse p_last backwards. (no p_prev anymore) */
356 block_t **pp_array = NULL;
357 int n = block_ChainToArray( p_block, &pp_array );
358 while( n ) if( pp_array[--n] == p_last ) break;
359 /* want to start at p_last->p_prev */
362 if( pp_array[n]->i_flags & DIRAC_NON_DATED )
364 if( pp_array[n]->i_dts > VLC_TS_INVALID )
366 dirac_block_encap_t *dbe = dirac_GetBlockEncap( pp_array[n] );
367 int32_t u_pic_num = dbe ? dbe->u_picture_number : 0;
368 int32_t i_dist = u_pic_num - u_pts_picnum;
371 pp_array[n]->i_pts = date_Increment( &pts, i_dist );
373 pp_array[n]->i_pts = date_Decrement( &pts, -i_dist );
379 * Dirac spec defined relations
382 static bool dirac_isEOS( uint8_t u_parse_code ) { return 0x10 == u_parse_code; }
383 static bool dirac_isSeqHdr( uint8_t u_parse_code ) { return 0 == u_parse_code; }
384 static bool dirac_isPicture( uint8_t u_parse_code ) { return 0x08 & u_parse_code; }
385 static int dirac_numRefs( uint8_t u_parse_code ) { return 0x3 & u_parse_code; }
387 static inline bool dirac_PictureNbeforeM( uint32_t u_n, uint32_t u_m )
389 /* specified as: u_n occurs before u_m if:
390 * (u_m - u_n) mod (1<<32) < D */
391 return (uint32_t)(u_m - u_n) < (1u<<31);
395 * Reorder buffer model
398 static void dirac_ReorderInit( struct dirac_reorder_buffer *p_rb )
400 memset( p_rb, 0, sizeof(*p_rb) );
401 p_rb->u_size_max = 2;
402 p_rb->p_empty = p_rb->p_entries;
403 p_rb->p_entries[31].p_next = NULL;
405 for( int i = 0; i < 31; i++ )
406 p_rb->p_entries[i].p_next = &p_rb->p_entries[i+1];
409 /* simulate the dirac picture reorder buffer */
410 static block_t *dirac_Reorder( decoder_t *p_dec, block_t *p_block_in, uint32_t u_picnum )
412 decoder_sys_t *p_sys = p_dec->p_sys;
414 if( !p_sys->reorder_buf.u_size_max )
415 /* reorder buffer disabled */
418 /* Modeling the reorder buffer:
419 * 1. If the reorder buffer is not full, insert picture for reordering.
420 * No picture is output by the system this picture period
421 * 2. If the reorder buffer is full:
422 * a. The picture decoded this period (u_picnum) bypasses the reorder
423 * buffer if it has a lower picture number than any entry in the
424 * reorder buffer. This picture is output by the system.
425 * b. Otherwise, the lowest picture number in the reorder buffer is
426 * removed from the buffer and output by the system. The current
427 * decoded picture (u_picnum) is inserted into the reorder buffer
430 block_t *p_block = NULL;
431 /* Determine if the picture needs to be inserted */
432 if( p_sys->reorder_buf.u_size == p_sys->reorder_buf.u_size_max )
434 /* (2) reorder buffer is full */
435 if( !p_sys->reorder_buf.u_size_max ||
436 dirac_PictureNbeforeM( u_picnum, p_sys->reorder_buf.p_head->u_picnum ) )
438 /* (2a) current picture is first in order */
442 /* (2b) extract the youngest picture in the buffer */
443 p_block = p_sys->reorder_buf.p_head->p_eu;
445 struct dirac_reorder_entry *p_tmp = p_sys->reorder_buf.p_head;
446 p_sys->reorder_buf.p_head = p_tmp->p_next;
447 p_tmp->p_next = p_sys->reorder_buf.p_empty;
448 p_sys->reorder_buf.p_empty = p_tmp;
450 p_sys->reorder_buf.u_size--;
453 /* (1) and (2b) both require u_picnum to be inserted */
454 struct dirac_reorder_entry *p_current = p_sys->reorder_buf.p_empty;
455 p_sys->reorder_buf.p_empty = p_current->p_next;
456 p_sys->reorder_buf.u_size++;
458 /* insertion sort to keep p_head always sorted, earliest first */
459 struct dirac_reorder_entry **pp_at = &p_sys->reorder_buf.p_head;
460 for( ; *pp_at; pp_at = &(*pp_at)->p_next )
461 if( dirac_PictureNbeforeM( u_picnum, (*pp_at)->u_picnum ) )
464 p_current->u_picnum = u_picnum;
465 p_current->p_eu = p_block_in;
466 p_current->p_next = *pp_at;
473 * bytestream parsing and unmarshalling functions
476 static bool dirac_UnpackParseInfo( parse_info_t *p_pi, block_bytestream_t *p_bs,
480 if( VLC_SUCCESS != block_PeekOffsetBytes( p_bs, u_offset, p_d, 13 ) )
483 if( p_d[0] != 'B' || p_d[1] != 'B' || p_d[2] != 'C' || p_d[3] != 'D' )
486 p_pi->i_parse_code = p_d[4];
487 p_pi->u_next_offset = p_d[5] << 24 | p_d[6] << 16 | p_d[7] << 8 | p_d[8];
488 p_pi->u_prev_offset = p_d[9] << 24 | p_d[10] << 16 | p_d[11] << 8 | p_d[12];
492 static uint32_t dirac_uint( bs_t *p_bs )
494 uint32_t u_count = 0, u_value = 0;
495 while( !bs_eof( p_bs ) && !bs_read( p_bs, 1 ) )
499 u_value |= bs_read( p_bs, 1 );
501 return (1 << u_count) - 1 + u_value;
504 static int dirac_bool( bs_t *p_bs )
506 return bs_read( p_bs, 1 );
509 /* read in useful bits from sequence header */
510 static bool dirac_UnpackSeqHdr( struct seq_hdr_t *p_sh, block_t *p_block )
513 bs_init( &bs, p_block->p_buffer, p_block->i_buffer );
514 bs_skip( &bs, 13*8 ); /* parse_info_header */
515 dirac_uint( &bs ); /* major_version */
516 dirac_uint( &bs ); /* minor_version */
517 dirac_uint( &bs ); /* profile */
518 dirac_uint( &bs ); /* level */
520 uint32_t u_video_format = dirac_uint( &bs ); /* index */
521 if( u_video_format > 20 )
523 /* don't know how to parse this header */
527 static const struct {
529 } dirac_size_tbl[] = {
530 {640,480}, {176,120}, {176,144}, {352,240}, {352,288}, {704,480},
531 {704,576}, {720,480}, {720,576}, {1280,720}, {1280,720}, {1920,1080},
532 {1920,1080}, {1920,1080}, {1920,1080}, {2048,1080}, {4096,2160},
533 {3840,2160}, {3840,2160}, {7680,4320}, {7680,4320},
536 p_sh->u_width = dirac_size_tbl[u_video_format].u_w;
537 p_sh->u_height = dirac_size_tbl[u_video_format].u_h;
538 if( dirac_bool( &bs ) )
540 p_sh->u_width = dirac_uint( &bs ); /* frame_width */
541 p_sh->u_height = dirac_uint( &bs ); /* frame_height */
544 if( dirac_bool( &bs ) )
546 dirac_uint( &bs ); /* chroma_format */
549 if( dirac_bool( &bs ) )
551 dirac_uint( &bs ); /* scan_format */
554 static const struct {
555 uint32_t u_n /* numerator */, u_d /* denominator */;
556 } dirac_frate_tbl[] = { /* table 10.3 */
557 {1, 1}, /* this value is not used */
558 {24000,1001}, {24,1}, {25,1}, {30000,1001}, {30,1},
559 {50,1}, {60000,1001}, {60,1}, {15000,1001}, {25,2},
562 const unsigned dirac_frate_tbl_size =
563 sizeof( dirac_frate_tbl ) / sizeof( *dirac_frate_tbl );
565 static const uint32_t dirac_vidfmt_frate[] = { /* table C.1 */
566 1, 9, 10, 9, 10, 9, 10, 4, 3, 7, 6, 4, 3, 7, 6, 2, 2, 7, 6, 7, 6,
569 p_sh->u_fps_num = dirac_frate_tbl[dirac_vidfmt_frate[u_video_format]].u_n;
570 p_sh->u_fps_den = dirac_frate_tbl[dirac_vidfmt_frate[u_video_format]].u_d;
571 if( dirac_bool( &bs ) )
573 uint32_t frame_rate_index = dirac_uint( &bs );
574 p_sh->u_fps_num = dirac_frate_tbl[frame_rate_index].u_n;
575 p_sh->u_fps_den = dirac_frate_tbl[frame_rate_index].u_d;
576 if( frame_rate_index >= dirac_frate_tbl_size )
581 if( frame_rate_index == 0 )
583 p_sh->u_fps_num = dirac_uint( &bs ); /* frame_rate_numerator */
584 p_sh->u_fps_den = dirac_uint( &bs ); /* frame_rate_denominator */
588 /* must have a valid framerate */
589 if( !p_sh->u_fps_num || !p_sh->u_fps_den )
592 if( dirac_bool( &bs ) )
594 uint32_t par_index = dirac_uint( &bs );
597 dirac_uint( &bs ); /* par_num */
598 dirac_uint( &bs ); /* par_den */
602 if( dirac_bool( &bs ) )
604 dirac_uint( &bs ); /* clean_width */
605 dirac_uint( &bs ); /* clean_height */
606 dirac_uint( &bs ); /* clean_left_offset */
607 dirac_uint( &bs ); /* clean_top_offset */
610 if( dirac_bool( &bs ) )
612 uint32_t signal_range_index = dirac_uint( &bs );
613 if( !signal_range_index )
615 dirac_uint( &bs ); /* luma_offset */
616 dirac_uint( &bs ); /* luma_excursion */
617 dirac_uint( &bs ); /* chroma_offset */
618 dirac_uint( &bs ); /* chroma_excursion */
622 if( dirac_bool( &bs ) )
624 uint32_t colour_spec_index = dirac_uint( &bs );
625 if( !colour_spec_index )
627 if( dirac_bool( &bs ) )
629 dirac_uint( &bs ); /* colour_primaries_index */
631 if( dirac_bool( &bs ) )
633 dirac_uint( &bs ); /* colour_matrix_index */
635 if( dirac_bool( &bs ) )
637 dirac_uint( &bs ); /* transfer_function_index */
642 p_sh->u_picture_coding_mode = dirac_uint( &bs );
648 * Data Unit marshalling functions
651 static block_t *dirac_EmitEOS( decoder_t *p_dec, uint32_t i_prev_parse_offset )
653 const uint8_t p_eos[] = { 'B','B','C','D',0x10,0,0,0,13,0,0,0,0 };
654 block_t *p_block = block_New( p_dec, 13 );
657 memcpy( p_block->p_buffer, p_eos, 13 );
659 SetDWBE( p_block->p_buffer + 9, i_prev_parse_offset );
661 p_block->i_flags = DIRAC_NON_DATED;
669 * Bytestream synchronizer
670 * maps [Bytes] -> DataUnit
672 static block_t *dirac_DoSync( decoder_t *p_dec )
674 decoder_sys_t *p_sys = p_dec->p_sys;
677 static const uint8_t p_parsecode[4] = {'B','B','C','D'};
679 switch( p_sys->i_state )
684 block_FindStartcodeFromOffset( &p_sys->bytestream, &p_sys->i_offset, p_parsecode, 4 ) )
686 /* p_sys->i_offset will have been set to:
687 * end of bytestream - amount of prefix found
688 * can resume search from this point when more data arrives */
691 /* candidate parse_code_prefix has been found at p_sys->i_offset */
692 if( VLC_SUCCESS != block_PeekOffsetBytes( &p_sys->bytestream, p_sys->i_offset + 12, NULL, 0 ) )
694 /* insufficient data has been accumulated to fully extract
695 * a parse_info header. exit for now in the hope of more
696 * data later to retry at exactly the same point */
699 p_sys->i_state = TRY_SYNC;
700 break; /* candidate found, try to sync */
702 case SYNCED: /* -> TRY_SYNC | NOT_SYNCED */
703 /* sanity: can only reach this after having extracted a DU,
704 * which causes data to be consumed and local i_offset to be reset */
705 assert( p_sys->i_offset == 0 );
706 if( VLC_SUCCESS != block_PeekOffsetBytes( &p_sys->bytestream, 12, NULL, 0 ) )
708 /* insufficient data has been accumulated to fully extract
709 * a parse_info header, retry later */
712 if( !dirac_UnpackParseInfo( &pu, &p_sys->bytestream, 0 )
713 || !pu.u_next_offset || (p_sys->u_last_npo != pu.u_prev_offset) )
715 /* !a: not a valid parse info.
716 * !pu.u_next_offset: don't know the length of the data unit
717 * search for the next one that points back
718 * to this one to determine length.
719 * (p_sys->u_last_npo != pu.u_prev_offset): some desync
721 p_sys->i_state = NOT_SYNCED;
724 if( pu.u_next_offset > 1024*1024 )
726 /* sanity check for erronious hugs next_parse_offsets
727 * (eg, 2^32-1) that would cause a very long wait
728 * and large space consumption: fall back to try sync */
729 p_sys->i_state = TRY_SYNC;
732 /* check that the start of the next data unit is avaliable */
734 block_PeekOffsetBytes( &p_sys->bytestream, pu.u_next_offset + 12, NULL, 0 ) )
736 return NULL; /* retry later */
738 /* attempt to syncronise backwards from pu.u_next_offset */
739 p_sys->i_offset = pu.u_next_offset;
741 case TRY_SYNC: /* -> SYNCED | NOT_SYNCED */
743 if( !p_sys->i_offset )
744 goto sync_fail; /* if a is at start of bytestream, b can't be in buffer */
747 bool a = dirac_UnpackParseInfo( &pu_a, &p_sys->bytestream, p_sys->i_offset );
748 if( !a || (pu_a.u_prev_offset > p_sys->i_offset) )
749 goto sync_fail; /* b lies beyond start of bytestream: can't sync */
751 if( !pu_a.u_prev_offset )
753 if( p_sys->i_state == TRY_SYNC )
755 goto sync_fail; /* can't find different pu_b from pu_a */
757 /* state == SYNCED: already know where pu_b is.
758 * pu_a has probably been inserted by something that doesn't
759 * know what the last next_parse_offset was */
760 pu_a.u_prev_offset = pu.u_next_offset;
763 parse_info_t *pu_b = &pu;
764 bool b = dirac_UnpackParseInfo( pu_b, &p_sys->bytestream, p_sys->i_offset - pu_a.u_prev_offset );
765 if( !b || (pu_b->u_next_offset && pu_a.u_prev_offset != pu_b->u_next_offset) )
767 /* if pu_b->u_next_offset = 0, have to assume we've synced, ie,
768 * just rely on finding a valid pu_b from pu_a. */
771 p_sys->u_last_npo = pu_b->u_next_offset;
772 if( !pu_b->u_next_offset ) pu_b->u_next_offset = pu_a.u_prev_offset;
773 /* offset was pointing at pu_a, rewind to point at pu_b */
774 p_sys->i_offset -= pu_a.u_prev_offset;
775 p_sys->i_state = SYNCED;
779 if( p_sys->i_state == SYNCED ) p_sys->i_offset = 0;
781 p_sys->i_state = NOT_SYNCED;
782 break; /* find somewhere else to try again */
785 } while( SYNCED != p_sys->i_state );
788 * synced, attempt to extract a data unit
791 /* recover any timestamps from the data that is about to be flushed */
792 dirac_RecoverTimestamps( p_dec, p_sys->i_offset );
794 /* flush everything up to the start of the DU */
795 block_SkipBytes( &p_sys->bytestream, p_sys->i_offset );
796 block_BytestreamFlush( &p_sys->bytestream );
799 /* setup the data unit buffer */
800 block_t *p_block = block_New( p_dec, pu.u_next_offset );
804 p_block->i_pts = p_sys->i_sync_pts;
805 p_block->i_dts = p_sys->i_sync_dts;
806 p_sys->i_sync_pts = p_sys->i_sync_dts = VLC_TS_INVALID;
808 /* recover any new timestamps from the data that is about to be consumed */
809 dirac_RecoverTimestamps( p_dec, p_sys->i_offset );
811 block_GetBytes( &p_sys->bytestream, p_block->p_buffer, p_block->i_buffer );
813 /* save parse offset in private area for later use */
814 dirac_block_encap_t *p_dbe = dirac_NewBlockEncap( &p_block );
815 if( p_dbe ) p_dbe->u_last_next_offset = pu.u_next_offset;
821 * Packet (Data Unit) inspection, learns parameters from sequence
822 * headers, sets up flags, drops unwanted data units, sets
823 * encapsulation unit termination policy
825 static int dirac_InspectDataUnit( decoder_t *p_dec, block_t **pp_block, block_t *p_eu )
827 decoder_sys_t *p_sys = p_dec->p_sys;
828 block_t *p_block = *pp_block;
829 uint8_t u_parse_code = p_block->p_buffer[4];
831 if( dirac_isEOS( u_parse_code ) )
833 if( p_sys->b_seen_eos )
835 /* remove duplicate EOS packets */
836 block_Release( p_block );
838 return DIRAC_DU_IN_EU;
840 /* p_block is an EOS packet */
841 p_eu->i_flags |= BLOCK_FLAG_END_OF_SEQUENCE;
842 /* for the moment, let this end an encapsulation unit */
843 /* seeing an eos packet requires a flush of the packetizer
844 * this is detected by the caller of this function */
845 p_sys->b_seen_seq_hdr = false;
846 p_sys->b_seen_eos = true;
847 return DIRAC_DU_ENDS_EU;
849 /* let anything down streem know too */
851 Actually, this is a bad idea:
852 - It sets the discontinuity for every dirac EOS packet
853 which doesnt imply a time discontinuity.
854 - When the syncronizer detects a real discontinuity, it
855 should copy the flags through.
856 p_eu->i_flags |= BLOCK_FLAG_DISCONTINUITY;
860 p_sys->b_seen_eos = false;
862 if( dirac_isPicture( u_parse_code ) )
864 /* timestamps apply to pictures only */
865 p_eu->i_dts = p_sys->i_eu_dts;
866 p_eu->i_pts = p_sys->i_eu_pts;
867 p_sys->i_eu_dts = p_sys->i_eu_pts = VLC_TS_INVALID;
869 if( !p_sys->b_seen_seq_hdr )
871 /* can't timestamp in this case, discard later
872 * so that the timestamps aren't lost */
873 p_eu->i_flags |= DIRAC_DISCARD;
875 /* p_block is a picture -- it ends the 'encapsulation unit' */
876 if( dirac_numRefs( u_parse_code ) )
878 /* if this picture is not an I frame, ensure that the
879 * random access point flags are not set */
880 p_eu->i_flags &= ~BLOCK_FLAG_TYPE_I;
882 dirac_block_encap_t *p_dbe = dirac_GetBlockEncap( p_block );
883 if( p_dbe && p_block->i_buffer > 13+4 )
885 /* record the picture number to save the time gen functions
886 * from having to inspect the data for it */
887 p_dbe->u_picture_number = GetDWBE( p_block->p_buffer + 13 );
889 return DIRAC_DU_ENDS_EU;
892 if( dirac_isSeqHdr( u_parse_code ) )
894 if( !dirac_UnpackSeqHdr( &p_sys->seq_hdr, p_block ) )
896 /* couldn't parse the sequence header, just ignore it */
897 return DIRAC_DU_IN_EU;
899 p_sys->b_seen_seq_hdr = true;
901 /* a sequence header followed by an I frame is a random
902 * access point; assume that this is the case */
903 p_eu->i_flags |= BLOCK_FLAG_TYPE_I;
905 es_format_t *p_es = &p_dec->fmt_out;
907 p_es->video.i_width = p_sys->seq_hdr.u_width;
908 p_es->video.i_height = p_sys->seq_hdr.u_height;
910 vlc_ureduce( &p_es->video.i_frame_rate, &p_es->video.i_frame_rate_base
911 , p_sys->seq_hdr.u_fps_num, p_sys->seq_hdr.u_fps_den, 0 );
913 /* when field coding, dts needs to be incremented in terms of field periods */
914 unsigned u_pics_per_sec = p_sys->seq_hdr.u_fps_num;
915 if( p_sys->seq_hdr.u_picture_coding_mode == DIRAC_FIELD_CODING )
919 date_Change( &p_sys->dts, u_pics_per_sec, p_sys->seq_hdr.u_fps_den );
921 /* TODO: set p_sys->reorder_buf.u_size_max */
922 p_sys->i_pts_offset = p_sys->reorder_buf.u_size_max
924 * p_es->video.i_frame_rate_base / p_es->video.i_frame_rate + 1;
926 /* stash a copy of the seqhdr
927 * - required for ogg muxing
928 * - useful for error checking
929 * - it isn't allowed to change until an eos */
930 free( p_es->p_extra );
931 p_es->p_extra = calloc( 1, p_block->i_buffer + 13 );
935 return DIRAC_DU_IN_EU;
937 p_es->i_extra = p_block->i_buffer;
938 memcpy( p_es->p_extra, p_block->p_buffer, p_block->i_buffer );
939 /* append EOS as per Ogg guidelines */
940 p_block = dirac_EmitEOS( p_dec, p_block->i_buffer );
943 memcpy( (uint8_t*)p_es->p_extra + p_es->i_extra, p_block->p_buffer, 13 );
947 return DIRAC_DU_IN_EU;
950 /* doesn't end an encapsulation unit */
951 return DIRAC_DU_IN_EU;
955 * Encapsulation (packetization) suitable for all muxing standards
956 * maps [DataUnit] -> EncapsulationUnit
958 static block_t *dirac_BuildEncapsulationUnit( decoder_t *p_dec, block_t *p_block )
960 decoder_sys_t *p_sys = p_dec->p_sys;
962 assert(p_block->i_buffer >= 13 && 0x42424344 == GetDWBE( p_block->p_buffer ));
964 if( p_sys->i_eu_pts <= VLC_TS_INVALID && p_sys->i_eu_dts <= VLC_TS_INVALID )
966 /* earliest block with pts/dts gets to set the pts/dts for the dated
967 * encapsulation unit as a whole */
968 /* NB, the 'earliest block' criteria is aribtary */
969 if( p_block->i_pts > VLC_TS_INVALID || p_block->i_dts > VLC_TS_INVALID )
971 p_sys->i_eu_pts = p_block->i_pts;
972 p_sys->i_eu_dts = p_block->i_dts;
976 /* inpectdataunit also updates flags for the EU.
977 * - if this is the first block in the EU, then it hasn't been added
978 * to the chain yet (so, p_block will become the front of the chain
979 * - otherwise, use the flags of the chain (first block) */
980 block_t *p_eu = p_sys->p_eu ? p_sys->p_eu : p_block;
981 int i_block = dirac_InspectDataUnit( p_dec, &p_block, p_eu);
985 /* block has been discarded during inspection */
986 /* becareful, don't discard anything that is dated,
987 * as this needs to go into the timegen loop. set
988 * the DIRAC_DISCARD block flag, and it'll be dropped
993 block_ChainLastAppend( &p_sys->pp_eu_last, p_block );
995 dirac_block_encap_t *p_dbe = dirac_GetBlockEncap( p_block );
996 #ifdef SANITIZE_PREV_PARSE_OFFSET
997 /* fixup prev_parse_offset to point to the last data unit
1001 SetDWBE( p_block->p_buffer + 9, p_sys->u_eu_last_npo );
1002 p_sys->u_eu_last_npo = p_dbe->u_last_next_offset;
1006 if( i_block != DIRAC_DU_ENDS_EU )
1008 /* encapsulation unit not ended */
1012 /* gather up encapsulation unit, reassociating the final
1013 * private state with the gathered block */
1014 block_t *p_eu_last = (block_t*) p_sys->pp_eu_last - offsetof( block_t, p_next );
1015 p_dbe = dirac_RemoveBlockEncap( p_eu_last );
1017 uint8_t u_parse_code = p_block->p_buffer[4];
1019 /* gather up the encapsulation unit */
1020 p_block = block_ChainGather( p_sys->p_eu );
1021 assert( p_block ); /* block_ChainGather doesn't define when it frees chain */
1023 p_block->i_flags |= DIRAC_NON_DATED;
1026 dirac_AddBlockEncap( &p_block, p_dbe );
1027 if( dirac_isPicture( u_parse_code ) ) p_block->i_flags &= ~DIRAC_NON_DATED;
1030 p_sys->pp_eu_last = &p_sys->p_eu;
1035 * dirac_TimeGenPush:
1036 * @p_dec: vlc object
1037 * @p_block_in: whole encapsulation unit to generate timestamps for
1041 * 1: EOS occurred, please flush and reset
1042 * 2: picture number discontinuity, please flush and reset
1044 static int dirac_TimeGenPush( decoder_t *p_dec, block_t *p_block_in )
1046 decoder_sys_t *p_sys = p_dec->p_sys;
1047 dirac_block_encap_t *p_dbe;
1049 if( p_block_in->i_flags & BLOCK_FLAG_END_OF_SEQUENCE )
1051 /* NB, this test occurs after the timegen push, so as to
1052 * push the block into the output queue */
1056 if( p_block_in->i_flags & DIRAC_NON_DATED )
1058 /* no picture found, which means p_block_in is a non-dated EU,
1059 * do not try and put a date on it */
1063 p_dbe = dirac_GetBlockEncap( p_block_in );
1064 uint32_t u_picnum = p_dbe ? p_dbe->u_picture_number : 0;
1066 * Simple DTS regeneration:
1067 * - DTS values linearly increase in stream order.
1068 * - Every time a DTS occurs at the input, sync to it
1069 * - If this is the first DTS seen, backdate all the previous ones that are undated
1070 * - If a DTS is missing, guess that it increases by one picture period
1071 * - If never seen DTS, don't do anything
1074 * Simple PTS regeneration
1075 * - PTS values do not linearly increase in stream order.
1076 * - Every time a PTS occurs at the input, sync to it and record picture number
1077 * - If a PTS is missing, guess that it differs by the product of picture
1078 * period and difference between picture number of sync point and current picture
1079 * - If this is the first PTS seen, backdate all previous ones that are undated
1080 * - If never seen PTS, don't do anything
1083 * Stage 1, sync to input timestamps, backdate timestamps for old
1084 * EUs that are in the outqueue with missing dates
1086 if( p_block_in->i_dts > VLC_TS_INVALID )
1088 /* if timestamps exist, sync to them */
1091 /* first dts seen, backdate any packets in outqueue */
1092 p_sys->b_dts = true;
1093 date_t dts = p_sys->dts;
1094 dirac_BackdateDTS( p_sys->p_outqueue, p_block_in, &dts );
1097 if( p_block_in->i_pts > VLC_TS_INVALID )
1099 /* if timestamps exist, sync to them */
1100 p_sys->u_pts_picnum = u_picnum;
1101 p_sys->i_pts = p_block_in->i_pts;
1104 /* first pts seen, backdate any packets in outqueue */
1105 p_sys->b_pts = true;
1106 date_t pts = p_sys->dts;
1107 date_Set( &pts, p_sys->i_pts );
1108 dirac_BackdatePTS( p_sys->p_outqueue, p_block_in, &pts, p_sys->u_pts_picnum );
1112 * Stage 2, don't attempt to forwards interpolate timestamps for
1113 * blocks if the picture rates aren't known
1115 if( !p_sys->b_seen_seq_hdr )
1121 * Stage 3, for block_in, interpolate any missing timestamps
1123 if( p_sys->b_dts && p_block_in->i_dts <= VLC_TS_INVALID )
1125 /* dts has previously been seen, but not this time, interpolate */
1126 p_block_in->i_dts = date_Increment( &p_sys->dts, 1 );
1129 if( p_sys->b_pts && p_block_in->i_pts <= VLC_TS_INVALID )
1131 /* pts has previously been seen, but not this time, interpolate */
1132 date_t pts = p_sys->dts;
1133 date_Set( &pts, p_sys->i_pts );
1134 int32_t i_dist = u_picnum - p_sys->u_pts_picnum;
1136 p_block_in->i_pts = date_Increment( &pts, i_dist );
1138 p_block_in->i_pts = date_Decrement( &pts, -i_dist );
1141 /* If pts and dts have been seen, there is no need to simulate operation
1142 * of the decoder reorder buffer */
1143 /* If neither have been seen, there is little point in simulating */
1144 if( p_sys->b_dts == p_sys->b_pts )
1147 if( !p_sys->p_out_dts )
1148 p_sys->p_out_dts = p_sys->p_outqueue;
1150 /* model the reorder buffer */
1151 block_t *p_block = dirac_Reorder( p_dec, p_block_in, u_picnum );
1155 /* A future ehancement is to stop modeling the reorder buffer as soon as
1156 * the first packet is output -- interpolate the past and freewheel for
1159 p_dbe = dirac_GetBlockEncap( p_block );
1160 u_picnum = p_dbe ? p_dbe->u_picture_number : 0;
1161 if( p_sys->b_tg_last_picnum )
1163 if( dirac_PictureNbeforeM( u_picnum, p_sys->u_tg_last_picnum ) )
1165 msg_Warn( p_dec, "stream jumped? %d < %d: resetting"
1166 , u_picnum, p_sys->u_tg_last_picnum );
1167 /* pictures only emerge from the reorder buffer in sequence
1168 * if a stream suddenly jumped backwards without a signaling
1169 * a discontinuity, some pictures will get stuck in the RoB.
1171 /* this could be a bit less indiscriminate */
1172 p_dbe = dirac_GetBlockEncap( p_sys->p_outqueue );
1173 uint32_t u_prev_parse_offset = p_dbe ? p_dbe->u_last_next_offset : 0;
1174 block_ChainRelease( p_sys->p_outqueue );
1175 p_sys->p_outqueue = dirac_EmitEOS( p_dec, u_prev_parse_offset );
1176 if( p_sys->p_outqueue )
1177 p_sys->p_outqueue->i_flags = BLOCK_FLAG_DISCONTINUITY | DIRAC_NON_DATED;
1178 /* return 2, so as not to reset the b_dts flags -- needed if
1179 * using the rawdirac demuxer with broken stream */
1183 p_sys->b_tg_last_picnum = true;
1184 p_sys->u_tg_last_picnum = u_picnum;
1188 /* some demuxers (eg, AVI) will provide a series of fake dts values,
1189 * which are actually inorder pts values (ie, what should be seen at
1190 * the output of a decoder. A main reason for simulating the reorder
1191 * buffer is to turn the inorder fakedts into an out-of-order pts */
1192 p_block->i_pts = p_sys->p_out_dts->i_dts;
1193 p_sys->p_out_dts->i_dts = VLC_TS_INVALID;
1196 /* If pts was copied from dts, the dts needs to be corrected to account for reordering*/
1197 /* If dts has never been seen, the same needs to happen */
1198 p_sys->p_out_dts->i_dts = p_block->i_pts - p_sys->i_pts_offset;
1200 /* move dts pointer */
1201 if( p_sys->p_out_dts )
1202 p_sys->p_out_dts = p_sys->p_out_dts->p_next;
1207 /*****************************************************************************
1208 * Packetize: form dated encapsulation units from anything
1209 *****************************************************************************/
1210 static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
1212 decoder_sys_t *p_sys = p_dec->p_sys;
1213 block_t *p_block = NULL;
1216 if( pp_block && *pp_block )
1218 p_block = *pp_block;
1221 if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
1223 /* pre-emptively insert an EOS at a discontinuity, protects
1224 * any decoders from any sudden changes */
1225 block_Release( p_block );
1226 p_block = dirac_EmitEOS( p_dec, 0 );
1229 p_block->p_next = dirac_EmitEOS( p_dec, 13 );
1230 /* need two EOS to ensure it gets detected by syncro
1231 * duplicates get discarded in forming encapsulation unit */
1234 else if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
1236 /* silently discard corruption sentinels,
1237 * synchronizer will then discard affected data units.
1238 * do not produce an EOS data unit as this is very
1239 * disruptive to the stream (and may make a larger error). */
1240 block_Release( p_block );
1244 block_BytestreamPush( &p_sys->bytestream, p_block );
1247 /* form as many encapsulation units as possible, give up
1248 * when the syncronizer runs out of input data */
1249 while( ( p_block = dirac_DoSync( p_dec ) ) )
1251 p_block = dirac_BuildEncapsulationUnit( p_dec, p_block );
1254 /* add to tail of output queue (ie, not reordered) */
1255 block_ChainLastAppend( &p_sys->pp_outqueue_last, p_block );
1256 /* insert encapsulation unit into timestamp generator
1257 * which then calculates some timestamps if required */
1258 i_flushing = dirac_TimeGenPush( p_dec, p_block );
1263 block_t *p_output = NULL;
1264 block_t **pp_output = &p_output;
1266 /* extract all the dated packets from the head of the output queue */
1267 /* explicitly nondated packets repeat the previous timestamps to
1268 * stop vlc discarding them */
1269 while( (p_block = p_sys->p_outqueue) )
1271 if( p_block->i_flags & DIRAC_DISCARD )
1273 p_sys->p_outqueue = p_block->p_next;
1274 p_block->p_next = NULL;
1275 block_Release( p_block );
1279 if( i_flushing || p_block->i_flags & DIRAC_NON_DATED )
1281 p_block->i_dts = p_sys->i_dts_last_out;
1282 p_block->i_pts = p_sys->i_pts_last_out;
1284 else if( p_block->i_pts <= VLC_TS_INVALID ) break;
1285 else if( p_block->i_dts <= VLC_TS_INVALID ) break;
1287 p_sys->i_dts_last_out = p_block->i_dts;
1288 p_sys->i_pts_last_out = p_block->i_pts;
1290 p_sys->p_outqueue = p_block->p_next;
1291 p_block->p_next = NULL;
1292 /* clear any flags we set */
1293 p_block->i_flags &= ~BLOCK_FLAG_PRIVATE_MASK;
1294 block_ChainLastAppend( &pp_output, p_block );
1296 mtime_t i_delay = p_block->i_pts - p_block->i_dts;
1298 msg_Err( p_dec, "pts - dts is negative(%"PRId64"): incorrect RoB size", i_delay );
1303 p_sys->i_eu_dts = p_sys->i_eu_pts = VLC_TS_INVALID;
1305 /* reset timegen state (except synchronizer) */
1306 p_sys->b_seen_seq_hdr = false;
1307 if( i_flushing < 2 )
1309 /* this state isn't safe to loose if there was
1310 * an unsignalled discontinuity */
1311 p_sys->b_pts = p_sys->b_dts = false;
1313 p_sys->b_tg_last_picnum = false;
1314 dirac_ReorderInit( &p_sys->reorder_buf );
1316 assert( p_sys->p_outqueue == NULL );
1317 p_sys->p_out_dts = NULL;
1320 /* perform sanity check:
1321 * if there were a block at the front of outqueue that never
1322 * satisfied the extraction criteria, but all blocks after did,
1323 * the output queue would grow bounded by the stream length.
1324 * If there are 10 data units in the output queue, assume this
1325 * has happened and purge all blocks that fail extraction criteria */
1327 block_ChainProperties( p_sys->p_outqueue, &i_count, NULL, NULL );
1330 p_block = p_sys->p_outqueue;
1333 block_t *p_block_next = p_block->p_next;
1334 if( p_block->i_pts > VLC_TS_INVALID && p_block->i_dts > VLC_TS_INVALID )
1336 block_Release( p_block );
1337 p_sys->p_outqueue = p_block = p_block_next;
1341 if( !p_sys->p_outqueue )
1343 p_sys->pp_outqueue_last = &p_sys->p_outqueue;
1348 /*****************************************************************************
1349 * Open: probe the packetizer and return score
1350 *****************************************************************************/
1351 static int Open( vlc_object_t *p_this )
1353 decoder_t *p_dec = (decoder_t*)p_this;
1354 decoder_sys_t *p_sys;
1356 if( p_dec->fmt_in.i_codec != VLC_CODEC_DIRAC )
1357 return VLC_EGENERIC;
1359 p_dec->pf_packetize = Packetize;
1361 /* Create the output format */
1362 es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
1363 p_dec->p_sys = p_sys = calloc( 1, sizeof( decoder_sys_t ) );
1368 p_sys->i_eu_pts = p_sys->i_eu_dts = VLC_TS_INVALID;
1369 p_sys->i_sync_pts = p_sys->i_sync_dts = VLC_TS_INVALID;
1370 p_sys->i_dts_last_out = p_sys->i_pts_last_out = VLC_TS_INVALID;
1372 p_sys->i_state = NOT_SYNCED;
1373 block_BytestreamInit( &p_sys->bytestream );
1375 p_sys->pp_outqueue_last = &p_sys->p_outqueue;
1376 p_sys->pp_eu_last = &p_sys->p_eu;
1378 date_Init( &p_sys->dts, 1, 1 );
1379 dirac_ReorderInit( &p_sys->reorder_buf );
1381 if( p_dec->fmt_in.i_extra > 0 )
1383 /* handle hacky systems like ogg that dump some headers
1384 * in p_extra. and packetizers that expect it to be filled
1385 * in before real startup */
1386 block_t *p_init = block_New( p_dec, p_dec->fmt_in.i_extra );
1389 /* memory might be avaliable soon. it isn't the end of
1390 * the world that fmt_in.i_extra isn't handled */
1393 memcpy( p_init->p_buffer, p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra );
1394 /* in theory p_extra should contain just a seqhdr&EOS. if just a
1395 * seqhdr, ensure it is extracted by appending an EOS with
1396 * prev_offset = seqhdr length, ie i_extra. If all were actually
1397 * ok, this won't do anything bad */
1398 if( ( p_init->p_next = dirac_EmitEOS( p_dec, p_dec->fmt_in.i_extra ) ) )
1400 /* to ensure that one of these two EOS dataunits gets extracted,
1401 * send a second one */
1402 p_init->p_next->p_next = dirac_EmitEOS( p_dec, 13 );
1406 while( ( p_block = Packetize( p_dec, &p_init ) ) )
1407 block_Release( p_block );
1413 /*****************************************************************************
1415 *****************************************************************************/
1416 static void Close( vlc_object_t *p_this )
1418 decoder_t *p_dec = (decoder_t*)p_this;
1419 decoder_sys_t *p_sys = p_dec->p_sys;
1421 block_BytestreamRelease( &p_sys->bytestream );
1422 if( p_sys->p_outqueue )
1423 block_ChainRelease( p_sys->p_outqueue );
1425 block_ChainRelease( p_sys->p_eu );