1 /*****************************************************************************
2 * ps.c: MPEG PS (ISO/IEC 13818-1) / MPEG SYSTEM (ISO/IEC 1172-1)
3 * multiplexer module for vlc
4 *****************************************************************************
5 * Copyright (C) 2001, 2002 the VideoLAN team
8 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * Eric Petit <titer@videolan.org>
10 * Gildas Bazin <gbazin@videolan.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
38 #include <vlc_codecs.h>
39 #include <vlc_block.h>
44 #include <vlc_iso_lang.h>
46 /*****************************************************************************
48 *****************************************************************************/
49 #define DTS_TEXT N_("DTS delay (ms)")
50 #define DTS_LONGTEXT N_("Delay the DTS (decoding time " \
51 "stamps) and PTS (presentation timestamps) of the data in the " \
52 "stream, compared to the SCRs. This allows for some buffering inside " \
53 "the client decoder.")
55 #define PES_SIZE_TEXT N_("PES maximum size")
56 #define PES_SIZE_LONGTEXT N_("Set the maximum allowed PES "\
57 "size when producing the MPEG PS streams.")
59 static int Open ( vlc_object_t * );
60 static void Close ( vlc_object_t * );
62 #define SOUT_CFG_PREFIX "sout-ps-"
65 set_description( N_("PS muxer") )
66 set_shortname( "MPEG-PS" )
67 set_category( CAT_SOUT )
68 set_subcategory( SUBCAT_SOUT_MUX )
69 set_capability( "sout mux", 50 )
71 add_shortcut( "mpeg1" )
73 set_callbacks( Open, Close )
75 add_integer( SOUT_CFG_PREFIX "dts-delay", 200, NULL, DTS_TEXT,
77 add_integer( SOUT_CFG_PREFIX "pes-max-size", PES_PAYLOAD_SIZE_MAX, NULL,
78 PES_SIZE_TEXT, PES_SIZE_LONGTEXT, true )
81 /*****************************************************************************
83 *****************************************************************************/
84 static int Control ( sout_mux_t *, int, va_list );
85 static int AddStream( sout_mux_t *, sout_input_t * );
86 static int DelStream( sout_mux_t *, sout_input_t * );
87 static int Mux ( sout_mux_t * );
89 /*****************************************************************************
91 *****************************************************************************/
93 static void MuxWritePackHeader ( sout_mux_t *, block_t **, mtime_t );
94 static void MuxWriteSystemHeader( sout_mux_t *, block_t **, mtime_t );
95 static void MuxWritePSM ( sout_mux_t *, block_t **, mtime_t );
97 static void StreamIdInit ( bool *id, int i_range );
98 static int StreamIdGet ( bool *id, int i_id_min, int i_id_max );
99 static void StreamIdRelease ( bool *id, int i_id_min, int i_id );
101 typedef struct ps_stream_s
105 int i_max_buff_size; /* used in system header */
107 /* Language is iso639-2T */
112 struct sout_mux_sys_t
114 /* Which id are unused */
115 bool stream_id_mpga[16]; /* 0xc0 -> 0xcf */
116 bool stream_id_mpgv[16]; /* 0xe0 -> 0xef */
117 bool stream_id_a52[8]; /* 0x80 -> 0x87 <- FIXME I'm not sure */
118 bool stream_id_spu[32]; /* 0x20 -> 0x3f */
119 bool stream_id_dts[8]; /* 0x88 -> 0x8f */
120 bool stream_id_lpcm[16]; /* 0xa0 -> 0xaf */
127 int i_rate_bound; /* units of 50 bytes/second */
129 int64_t i_instant_bitrate;
130 int64_t i_instant_size;
131 int64_t i_instant_dts;
138 uint32_t crc32_table[256];
141 static const char *const ppsz_sout_options[] = {
142 "dts-delay", "pes-max-size", NULL
145 /*****************************************************************************
147 *****************************************************************************/
148 static int Open( vlc_object_t *p_this )
150 sout_mux_t *p_mux = (sout_mux_t*)p_this;
151 sout_mux_sys_t *p_sys;
154 msg_Info( p_mux, "Open" );
155 config_ChainParse( p_mux, SOUT_CFG_PREFIX, ppsz_sout_options, p_mux->p_cfg );
157 p_mux->pf_control = Control;
158 p_mux->pf_addstream = AddStream;
159 p_mux->pf_delstream = DelStream;
161 p_mux->p_sys = p_sys = malloc( sizeof( sout_mux_sys_t ) );
163 /* Init free stream id */
164 StreamIdInit( p_sys->stream_id_a52, 8 );
165 StreamIdInit( p_sys->stream_id_dts, 8 );
166 StreamIdInit( p_sys->stream_id_mpga, 16 );
167 StreamIdInit( p_sys->stream_id_mpgv, 16 );
168 StreamIdInit( p_sys->stream_id_lpcm, 16 );
169 StreamIdInit( p_sys->stream_id_spu, 32 );
171 p_sys->i_audio_bound = 0;
172 p_sys->i_video_bound = 0;
173 p_sys->i_system_header = 0;
174 p_sys->i_pes_count = 0;
176 p_sys->i_psm_version = 0;
178 p_sys->i_instant_bitrate = 0;
179 p_sys->i_instant_size = 0;
180 p_sys->i_instant_dts = 0;
181 p_sys->i_rate_bound = 0;
182 p_sys->b_mpeg2 = !(p_mux->psz_mux && !strcmp( p_mux->psz_mux, "mpeg1" ));
184 var_Get( p_mux, SOUT_CFG_PREFIX "dts-delay", &val );
185 p_sys->i_dts_delay = (int64_t)val.i_int * 1000;
187 var_Get( p_mux, SOUT_CFG_PREFIX "pes-max-size", &val );
188 p_sys->i_pes_max_size = (int64_t)val.i_int;
190 /* Initialise CRC32 table */
195 for( i = 0; i < 256; i++ )
198 for( j = (i << 24) | 0x800000; j != 0x80000000; j <<= 1 )
199 k = (k << 1) ^ (((k ^ j) & 0x80000000) ? 0x04c11db7 : 0);
201 p_sys->crc32_table[i] = k;
208 /*****************************************************************************
210 *****************************************************************************/
211 static void Close( vlc_object_t * p_this )
213 sout_mux_t *p_mux = (sout_mux_t*)p_this;
214 sout_mux_sys_t *p_sys = p_mux->p_sys;
218 msg_Info( p_mux, "Close" );
220 p_end = block_New( p_mux, 4 );
221 p_end->p_buffer[0] = 0x00; p_end->p_buffer[1] = 0x00;
222 p_end->p_buffer[2] = 0x01; p_end->p_buffer[3] = 0xb9;
224 sout_AccessOutWrite( p_mux->p_access, p_end );
229 /*****************************************************************************
231 *****************************************************************************/
232 static int Control( sout_mux_t *p_mux, int i_query, va_list args )
240 case MUX_CAN_ADD_STREAM_WHILE_MUXING:
241 pb_bool = (bool*)va_arg( args, bool * );
245 case MUX_GET_ADD_STREAM_WAIT:
246 pb_bool = (bool*)va_arg( args, bool * );
251 ppsz = (char**)va_arg( args, char ** );
252 *ppsz = strdup( "video/mpeg" );
260 /*****************************************************************************
262 *****************************************************************************/
263 static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
265 sout_mux_sys_t *p_sys = p_mux->p_sys;
266 ps_stream_t *p_stream;
269 msg_Dbg( p_mux, "adding input codec=%4.4s",
270 (char*)&p_input->p_fmt->i_codec );
272 p_input->p_sys = p_stream = malloc( sizeof( ps_stream_t ) );
273 p_stream->i_stream_type = 0x81;
275 /* Init this new stream */
276 switch( p_input->p_fmt->i_codec )
279 p_stream->i_stream_id =
280 StreamIdGet( p_sys->stream_id_mpgv, 0xe0, 0xef );
281 p_stream->i_stream_type = 0x02; /* ISO/IEC 13818 Video */
284 p_stream->i_stream_id =
285 StreamIdGet( p_sys->stream_id_mpgv, 0xe0, 0xef );
286 p_stream->i_stream_type = 0x10;
289 p_stream->i_stream_id =
290 StreamIdGet( p_sys->stream_id_mpgv, 0xe0, 0xef );
291 p_stream->i_stream_type = 0x1b;
293 case VLC_CODEC_DVD_LPCM:
294 p_stream->i_stream_id =
295 0xbd00 | StreamIdGet( p_sys->stream_id_lpcm, 0xa0, 0xaf );
298 p_stream->i_stream_id =
299 0xbd00 | StreamIdGet( p_sys->stream_id_dts, 0x88, 0x8f );
302 p_stream->i_stream_id =
303 0xbd00 | StreamIdGet( p_sys->stream_id_a52, 0x80, 0x87 );
306 p_stream->i_stream_id =
307 StreamIdGet( p_sys->stream_id_mpga, 0xc0, 0xcf );
308 p_stream->i_stream_type = 0x03; /* ISO/IEC 11172 Audio */
311 p_stream->i_stream_id =
312 StreamIdGet( p_sys->stream_id_mpga, 0xc0, 0xcf );
313 p_stream->i_stream_type = 0x0f;
316 p_stream->i_stream_id =
317 0xbd00 | StreamIdGet( p_sys->stream_id_spu, 0x20, 0x3f );
323 if( p_stream->i_stream_id < 0 ) goto error;
325 if( p_input->p_fmt->i_cat == AUDIO_ES )
327 p_sys->i_audio_bound++;
328 p_stream->i_max_buff_size = 4 * 1024;
330 else if( p_input->p_fmt->i_cat == VIDEO_ES )
332 p_sys->i_video_bound++;
333 p_stream->i_max_buff_size = 400 * 1024; /* FIXME -- VCD uses 46, SVCD
334 uses 230, ffmpeg has 230 with a note that it is small */
337 { /* FIXME -- what's valid for not audio or video? */
338 p_stream->i_max_buff_size = 4 * 1024;
341 /* Try to set a sensible default value for the instant bitrate */
342 p_sys->i_instant_bitrate += p_input->p_fmt->i_bitrate + 1000/* overhead */;
344 /* FIXME -- spec requires an upper limit rate boundary in the system header;
345 our codecs are VBR; using 2x nominal rate, convert to 50 bytes/sec */
346 p_sys->i_rate_bound += p_input->p_fmt->i_bitrate * 2 / (8 * 50);
347 p_sys->i_psm_version++;
349 p_stream->lang[0] = p_stream->lang[1] = p_stream->lang[2] = 0;
350 if( p_input->p_fmt->psz_language )
352 char *psz = p_input->p_fmt->psz_language;
353 const iso639_lang_t *pl = NULL;
355 if( strlen( psz ) == 2 )
357 pl = GetLang_1( psz );
359 else if( strlen( psz ) == 3 )
361 pl = GetLang_2B( psz );
362 if( !strcmp( pl->psz_iso639_1, "??" ) )
364 pl = GetLang_2T( psz );
367 if( pl && strcmp( pl->psz_iso639_1, "??" ) )
369 p_stream->lang[0] = pl->psz_iso639_2T[0];
370 p_stream->lang[1] = pl->psz_iso639_2T[1];
371 p_stream->lang[2] = pl->psz_iso639_2T[2];
373 msg_Dbg( p_mux, " - lang=%c%c%c",
374 p_stream->lang[0], p_stream->lang[1], p_stream->lang[2] );
384 /*****************************************************************************
386 *****************************************************************************/
387 static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
389 sout_mux_sys_t *p_sys = p_mux->p_sys;
390 ps_stream_t *p_stream =(ps_stream_t*)p_input->p_sys;
392 msg_Dbg( p_mux, "removing input" );
393 switch( p_input->p_fmt->i_codec )
396 StreamIdRelease( p_sys->stream_id_mpgv, 0xe0,
397 p_stream->i_stream_id );
399 case VLC_CODEC_DVD_LPCM:
400 StreamIdRelease( p_sys->stream_id_lpcm, 0xa0,
401 p_stream->i_stream_id&0xff );
404 StreamIdRelease( p_sys->stream_id_dts, 0x88,
405 p_stream->i_stream_id&0xff );
408 StreamIdRelease( p_sys->stream_id_a52, 0x80,
409 p_stream->i_stream_id&0xff );
412 StreamIdRelease( p_sys->stream_id_mpga, 0xc0,
413 p_stream->i_stream_id );
416 StreamIdRelease( p_sys->stream_id_spu, 0x20,
417 p_stream->i_stream_id&0xff );
424 if( p_input->p_fmt->i_cat == AUDIO_ES )
426 p_sys->i_audio_bound--;
428 else if( p_input->p_fmt->i_cat == VIDEO_ES )
430 p_sys->i_video_bound--;
433 /* Try to set a sensible default value for the instant bitrate */
434 p_sys->i_instant_bitrate -= (p_input->p_fmt->i_bitrate + 1000);
435 /* rate_bound is in units of 50 bytes/second */
436 p_sys->i_rate_bound -= (p_input->p_fmt->i_bitrate * 2)/(8 * 50);
438 p_sys->i_psm_version++;
444 /*****************************************************************************
445 * Mux: Call each time there is new data for at least one stream
446 *****************************************************************************/
447 static int Mux( sout_mux_t *p_mux )
449 sout_mux_sys_t *p_sys = p_mux->p_sys;
453 sout_input_t *p_input;
454 ps_stream_t *p_stream;
456 block_t *p_ps, *p_data;
460 /* Choose which stream to mux */
461 int i_stream = sout_MuxGetStream( p_mux, 1, &i_dts );
467 p_input = p_mux->pp_inputs[i_stream];
468 p_stream = (ps_stream_t*)p_input->p_sys;
471 /* Write regulary PackHeader */
472 if( p_sys->i_pes_count % 30 == 0)
474 /* Update the instant bitrate every second or so */
475 if( p_sys->i_instant_size &&
476 i_dts - p_sys->i_instant_dts > 1000000 )
478 int64_t i_instant_bitrate = p_sys->i_instant_size * 8000000 /
479 ( i_dts - p_sys->i_instant_dts );
481 p_sys->i_instant_bitrate += i_instant_bitrate;
482 p_sys->i_instant_bitrate /= 2;
484 p_sys->i_instant_size = 0;
485 p_sys->i_instant_dts = i_dts;
487 else if( !p_sys->i_instant_size )
489 p_sys->i_instant_dts = i_dts;
492 MuxWritePackHeader( p_mux, &p_ps, i_dts );
495 /* Write regulary SystemHeader */
496 if( p_sys->i_pes_count % 300 == 0 )
500 MuxWriteSystemHeader( p_mux, &p_ps, i_dts );
502 /* For MPEG1 streaming, set HEADER flag */
503 for( p_pk = p_ps; p_pk != NULL; p_pk = p_pk->p_next )
505 p_pk->i_flags |= BLOCK_FLAG_HEADER;
509 /* Write regulary ProgramStreamMap */
510 if( p_sys->b_mpeg2 && p_sys->i_pes_count % 300 == 0 )
512 MuxWritePSM( p_mux, &p_ps, i_dts );
515 /* Get and mux a packet */
516 p_data = block_FifoGet( p_input->p_fifo );
517 EStoPES ( p_mux->p_sout, &p_data, p_data,
518 p_input->p_fmt, p_stream->i_stream_id,
519 p_sys->b_mpeg2, 0, 0, p_sys->i_pes_max_size );
521 block_ChainAppend( &p_ps, p_data );
523 /* Get size of output data so we can calculate the instant bitrate */
524 for( p_data = p_ps; p_data; p_data = p_data->p_next )
526 p_sys->i_instant_size += p_data->i_buffer;
529 sout_AccessOutWrite( p_mux->p_access, p_ps );
531 /* Increase counter */
532 p_sys->i_pes_count++;
538 /*****************************************************************************
540 *****************************************************************************/
541 static void StreamIdInit( bool *id, int i_range )
545 for( i = 0; i < i_range; i++ )
550 static int StreamIdGet( bool *id, int i_id_min, int i_id_max )
554 for( i = 0; i <= i_id_max - i_id_min; i++ )
565 static void StreamIdRelease( bool *id, int i_id_min, int i_id )
567 id[i_id - i_id_min] = true;
570 static void MuxWritePackHeader( sout_mux_t *p_mux, block_t **p_buf,
573 sout_mux_sys_t *p_sys = p_mux->p_sys;
579 i_scr = (i_dts - p_sys->i_dts_delay) * 9 / 100;
581 p_hdr = block_New( p_mux, 18 );
582 p_hdr->i_pts = p_hdr->i_dts = i_dts;
583 bits_initwrite( &bits, 14, p_hdr->p_buffer );
584 bits_write( &bits, 32, 0x01ba );
586 /* The spec specifies that the mux rate must be rounded upwards */
587 i_mux_rate = (p_sys->i_instant_bitrate + 8 * 50 - 1 ) / (8 * 50);
591 bits_write( &bits, 2, 0x01 );
595 bits_write( &bits, 4, 0x02 );
598 bits_write( &bits, 3, ( i_scr >> 30 )&0x07 );
599 bits_write( &bits, 1, 1 ); // marker
600 bits_write( &bits, 15, ( i_scr >> 15 )&0x7fff );
601 bits_write( &bits, 1, 1 ); // marker
602 bits_write( &bits, 15, i_scr&0x7fff );
603 bits_write( &bits, 1, 1 ); // marker
607 bits_write( &bits, 9, 0 ); // src extension
609 bits_write( &bits, 1, 1 ); // marker
611 bits_write( &bits, 22, i_mux_rate);
612 bits_write( &bits, 1, 1 ); // marker
616 bits_write( &bits, 1, 1 ); // marker
617 bits_write( &bits, 5, 0x1f ); // reserved
618 bits_write( &bits, 3, 0 ); // stuffing bytes
621 p_hdr->i_buffer = p_sys->b_mpeg2 ? 14: 12;
623 block_ChainAppend( p_buf, p_hdr );
626 static void MuxWriteSystemHeader( sout_mux_t *p_mux, block_t **p_buf,
629 sout_mux_sys_t *p_sys = p_mux->p_sys;
635 int i_nb_private, i_nb_stream;
638 /* Count the number of private stream */
639 for( i = 0, i_nb_private = 0; i < p_mux->i_nb_inputs; i++ )
641 ps_stream_t *p_stream;
643 p_stream = (ps_stream_t*)p_mux->pp_inputs[i]->p_sys;
645 if( ( p_stream->i_stream_id&0xff00 ) == 0xbd00 )
651 /* Private stream are declared only one time */
652 i_nb_stream = p_mux->i_nb_inputs -
653 ( i_nb_private > 0 ? i_nb_private - 1 : 0 );
655 p_hdr = block_New( p_mux, 12 + i_nb_stream * 3 );
656 p_hdr->i_dts = p_hdr->i_pts = i_dts;
658 /* The spec specifies that the reported rate_bound must be upper limit */
659 i_rate_bound = (p_sys->i_rate_bound);
661 bits_initwrite( &bits, 12 + i_nb_stream * 3, p_hdr->p_buffer );
662 bits_write( &bits, 32, 0x01bb );
663 bits_write( &bits, 16, 12 - 6 + i_nb_stream * 3 );
664 bits_write( &bits, 1, 1 ); // marker bit
665 bits_write( &bits, 22, i_rate_bound);
666 bits_write( &bits, 1, 1 ); // marker bit
668 bits_write( &bits, 6, p_sys->i_audio_bound );
669 bits_write( &bits, 1, 0 ); // fixed flag
670 bits_write( &bits, 1, 0 ); // CSPS flag
671 bits_write( &bits, 1, 0 ); // system audio lock flag
672 bits_write( &bits, 1, 0 ); // system video lock flag
674 bits_write( &bits, 1, 1 ); // marker bit
676 bits_write( &bits, 5, p_sys->i_video_bound );
677 bits_write( &bits, 1, 1 ); // packet rate restriction flag (1 for mpeg1)
678 bits_write( &bits, 7, 0xff ); // reserved bits
680 /* stream_id table */
681 for( i = 0, b_private = false; i < p_mux->i_nb_inputs; i++ )
683 sout_input_t *p_input;
684 ps_stream_t *p_stream;
686 p_input = p_mux->pp_inputs[i];
687 p_stream = (ps_stream_t *)p_input->p_sys;
689 if( ( p_stream->i_stream_id&0xff00 ) == 0xbd00 )
696 /* Write stream id */
697 bits_write( &bits, 8, 0xbd );
701 /* Write stream id */
702 bits_write( &bits, 8, p_stream->i_stream_id&0xff );
705 bits_write( &bits, 2, 0x03 ); /* reserved */
706 if( p_input->p_fmt->i_cat == AUDIO_ES )
708 bits_write( &bits, 1, 0 );
709 bits_write( &bits, 13, p_stream->i_max_buff_size / 128 );
711 else if( p_input->p_fmt->i_cat == VIDEO_ES )
713 bits_write( &bits, 1, 1 );
714 bits_write( &bits, 13, p_stream->i_max_buff_size / 1024);
718 /* FIXME -- the scale of 0 means do a /128 */
719 bits_write( &bits, 1, 0 );
720 bits_write( &bits, 13, p_stream->i_max_buff_size / 128 );
724 block_ChainAppend( p_buf, p_hdr );
727 static void MuxWritePSM( sout_mux_t *p_mux, block_t **p_buf, mtime_t i_dts )
729 sout_mux_sys_t *p_sys = p_mux->p_sys;
732 int i, i_psm_size = 16, i_es_map_size = 0;
734 for( i = 0; i < p_mux->i_nb_inputs; i++ )
736 sout_input_t *p_input = p_mux->pp_inputs[i];
737 ps_stream_t *p_stream = p_input->p_sys;
740 if( p_stream->lang[0] != 0 ) i_es_map_size += 6;
743 i_psm_size += i_es_map_size;
745 p_hdr = block_New( p_mux, i_psm_size );
746 p_hdr->i_dts = p_hdr->i_pts = i_dts;
748 memset( p_hdr->p_buffer, 0, p_hdr->i_buffer );
749 bits_initwrite( &bits, i_psm_size, p_hdr->p_buffer );
750 bits_write( &bits, 32, 0x01bc );
751 bits_write( &bits, 16, i_psm_size - 6 );
752 bits_write( &bits, 1, 1 ); /* current_next_indicator */
753 bits_write( &bits, 2, 0xF ); /* reserved */
754 bits_write( &bits, 5, p_sys->i_psm_version );
755 bits_write( &bits, 7, 0xFF ); /* reserved */
756 bits_write( &bits, 1, 1 ); /* marker */
758 bits_write( &bits, 16, 0 ); /* program_stream_info_length */
761 bits_write( &bits, 16, i_es_map_size ); /* elementary_stream_map_length */
762 for( i = 0; i < p_mux->i_nb_inputs; i++ )
764 sout_input_t *p_input = p_mux->pp_inputs[i];
765 ps_stream_t *p_stream = p_input->p_sys;
767 bits_write( &bits, 8, p_stream->i_stream_type ); /* stream_type */
768 bits_write( &bits, 8, p_stream->i_stream_id ); /* elementary_stream_id */
770 /* ISO639 language descriptor */
771 if( p_stream->lang[0] != 0 )
773 bits_write( &bits, 16, 6 ); /* elementary_stream_info_length */
775 bits_write( &bits, 8, 0x0a ); /* descriptor_tag */
776 bits_write( &bits, 8, 4 ); /* descriptor_length */
778 bits_write( &bits, 8, p_stream->lang[0] );
779 bits_write( &bits, 8, p_stream->lang[1] );
780 bits_write( &bits, 8, p_stream->lang[2] );
781 bits_write( &bits, 8, 0 ); /* audio type: 0x00 undefined */
785 bits_write( &bits, 16, 0 ); /* elementary_stream_info_length */
791 uint32_t i_crc = 0xffffffff;
792 for( i = 0; (size_t)i < p_hdr->i_buffer; i++ )
793 i_crc = (i_crc << 8) ^
794 p_sys->crc32_table[((i_crc >> 24) ^ p_hdr->p_buffer[i]) & 0xff];
796 bits_write( &bits, 32, i_crc );
799 block_ChainAppend( p_buf, p_hdr );