?? ts.c
字號:
0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 }; uint32_t i_crc = 0xffffffff; /* Calculate the CRC */ while( i_count > 0 ) { i_crc = (i_crc<<8) ^ CRC32[ (i_crc>>24) ^ ((uint32_t)*p_begin) ]; p_begin++; i_count--; } return( i_crc );}static void GetPAT( sout_mux_t *p_mux, sout_buffer_chain_t *c ){ sout_mux_sys_t *p_sys = p_mux->p_sys; sout_buffer_t *p_pat; bits_buffer_t bits; p_pat = sout_BufferNew( p_mux->p_sout, 1024 ); p_pat->i_pts = 0; p_pat->i_dts = 0; p_pat->i_length = 0; bits_initwrite( &bits, 1024, p_pat->p_buffer ); bits_write( &bits, 8, 0 ); // pointer bits_write( &bits, 8, 0x00 ); // table id bits_write( &bits, 1, 1 ); // section_syntax_indicator bits_write( &bits, 1, 0 ); // 0 bits_write( &bits, 2, 0x03 ); // reserved FIXME bits_write( &bits, 12, 13 ); // XXX for one program only XXX bits_write( &bits, 16, 0x01 ); // FIXME stream id bits_write( &bits, 2, 0x03 ); // FIXME bits_write( &bits, 5, p_sys->i_pat_version_number ); bits_write( &bits, 1, 1 ); // current_next_indicator bits_write( &bits, 8, 0 ); // section number bits_write( &bits, 8, 0 ); // last section number bits_write( &bits, 16, 1 ); // program number bits_write( &bits, 3, 0x07 ); // reserved bits_write( &bits, 13, p_sys->pmt.i_pid ); // program map pid bits_write( &bits, 32, CalculateCRC( bits.p_data + 1, bits.i_data - 1) ); p_pat->i_size = bits.i_data; PEStoTS( p_mux->p_sout, c, p_pat, &p_sys->pat );}static void GetPMT( sout_mux_t *p_mux, sout_buffer_chain_t *c ){ sout_mux_sys_t *p_sys = p_mux->p_sys; sout_buffer_t *p_pmt; bits_buffer_t bits; int i_stream; p_pmt = sout_BufferNew( p_mux->p_sout, 1024 ); p_pmt->i_pts = 0; p_pmt->i_dts = 0; p_pmt->i_length = 0; bits_initwrite( &bits, 1024, p_pmt->p_buffer ); bits_write( &bits, 8, 0 ); // pointer bits_write( &bits, 8, 0x02 ); // table id bits_write( &bits, 1, 1 ); // section_syntax_indicator bits_write( &bits, 1, 0 ); // 0 bits_write( &bits, 2, 0 ); // reserved FIXME bits_write( &bits, 12, 13 + 5 * p_mux->i_nb_inputs ); bits_write( &bits, 16, 1 ); // FIXME program number bits_write( &bits, 2, 0 ); // FIXME bits_write( &bits, 5, p_sys->i_pmt_version_number ); bits_write( &bits, 1, 1 ); // current_next_indicator bits_write( &bits, 8, 0 ); // section number bits_write( &bits, 8, 0 ); // last section number bits_write( &bits, 3, 0 ); // reserved bits_write( &bits, 13, p_sys->i_pcr_pid ); // FIXME FXIME PCR_PID FIXME bits_write( &bits, 4, 0 ); // reserved FIXME bits_write( &bits, 12, 0 ); // program info len FIXME for( i_stream = 0; i_stream < p_mux->i_nb_inputs; i_stream++ ) { ts_stream_t *p_stream; p_stream = (ts_stream_t*)p_mux->pp_inputs[i_stream]->p_sys; bits_write( &bits, 8, p_stream->i_stream_type ); // stream_type bits_write( &bits, 3, 0 ); // reserved bits_write( &bits, 13, p_stream->i_pid ); // es pid bits_write( &bits, 4, 0 ); //reserved bits_write( &bits, 12, 0 ); // es info len FIXME } bits_write( &bits, 32, CalculateCRC( bits.p_data + 1, bits.i_data - 1) ); p_pmt->i_size = bits.i_data; PEStoTS( p_mux->p_sout, c, p_pmt, &p_sys->pmt );}#elif defined MODULE_NAME_IS_mux_ts_dvbpsistatic sout_buffer_t *WritePSISection( sout_instance_t *p_sout, dvbpsi_psi_section_t* p_section ){ sout_buffer_t *p_psi, *p_first = NULL; while( p_section ) { int i_size; i_size = (uint32_t)( p_section->p_payload_end - p_section->p_data )+ ( p_section->b_syntax_indicator ? 4 : 0 ); p_psi = sout_BufferNew( p_sout, i_size + 1 ); p_psi->i_pts = 0; p_psi->i_dts = 0; p_psi->i_length = 0; p_psi->i_size = i_size + 1; p_psi->p_buffer[0] = 0; // pointer memcpy( p_psi->p_buffer + 1, p_section->p_data, i_size ); sout_BufferChain( &p_first, p_psi ); p_section = p_section->p_next; } return( p_first );}static void GetPAT( sout_mux_t *p_mux, sout_buffer_chain_t *c ){ sout_mux_sys_t *p_sys = p_mux->p_sys; sout_buffer_t *p_pat; dvbpsi_pat_t pat; dvbpsi_psi_section_t *p_section; dvbpsi_InitPAT( &pat, 0x01, // i_ts_id p_sys->i_pat_version_number, 1 ); // b_current_next /* add all program (only one) */ dvbpsi_PATAddProgram( &pat, 1, // i_number p_sys->pmt.i_pid ); // i_pid p_section = dvbpsi_GenPATSections( &pat, 0 ); // max program per section p_pat = WritePSISection( p_mux->p_sout, p_section ); PEStoTS( p_mux->p_sout, c, p_pat, &p_sys->pat ); dvbpsi_DeletePSISections( p_section ); dvbpsi_EmptyPAT( &pat );}static uint32_t GetDescriptorLength24b( int i_length ){ uint32_t i_l1, i_l2, i_l3; i_l1 = i_length&0x7f; i_l2 = ( i_length >> 7 )&0x7f; i_l3 = ( i_length >> 14 )&0x7f; return( 0x808000 | ( i_l3 << 16 ) | ( i_l2 << 8 ) | i_l1 );}static void GetPMT( sout_mux_t *p_mux, sout_buffer_chain_t *c ){ sout_mux_sys_t *p_sys = p_mux->p_sys; sout_buffer_t *p_pmt; dvbpsi_pmt_t pmt; dvbpsi_pmt_es_t *p_es; dvbpsi_psi_section_t *p_section; int i_stream; dvbpsi_InitPMT( &pmt, 0x01, // program number p_sys->i_pmt_version_number, 1, // b_current_next p_sys->i_pcr_pid ); if( p_sys->i_mpeg4_streams > 0 ) { uint8_t iod[4096]; bits_buffer_t bits; bits_buffer_t bits_fix_IOD; /* Make valgrind happy : it works at byte level not bit one so * bit_write confuse it (but DON'T CHANGE the way that bit_write is * working (needed when fixing some bits) */ memset( iod, 0, 4096 ); bits_initwrite( &bits, 4096, iod ); // IOD_label bits_write( &bits, 8, 0x01 ); // InitialObjectDescriptor bits_align( &bits ); bits_write( &bits, 8, 0x02 ); // tag bits_fix_IOD = bits; // save states to fix length later bits_write( &bits, 24, GetDescriptorLength24b( 0 ) ); // variable length (fixed later) bits_write( &bits, 10, 0x01 ); // ObjectDescriptorID bits_write( &bits, 1, 0x00 ); // URL Flag bits_write( &bits, 1, 0x00 ); // includeInlineProfileLevelFlag bits_write( &bits, 4, 0x0f ); // reserved bits_write( &bits, 8, 0xff ); // ODProfile (no ODcapability ) bits_write( &bits, 8, 0xff ); // sceneProfile bits_write( &bits, 8, 0xfe ); // audioProfile (unspecified) bits_write( &bits, 8, 0xfe ); // visualProfile( // ) bits_write( &bits, 8, 0xff ); // graphicProfile (no ) for( i_stream = 0; i_stream < p_mux->i_nb_inputs; i_stream++ ) { ts_stream_t *p_stream; p_stream = (ts_stream_t*)p_mux->pp_inputs[i_stream]->p_sys; if( p_stream->i_stream_id == 0xfa || p_stream->i_stream_id == 0xfb ) { bits_buffer_t bits_fix_ESDescr, bits_fix_Decoder; /* ES descriptor */ bits_align( &bits ); bits_write( &bits, 8, 0x03 ); // ES_DescrTag bits_fix_ESDescr = bits; bits_write( &bits, 24, GetDescriptorLength24b( 0 ) ); // variable size bits_write( &bits, 16, p_stream->i_es_id ); bits_write( &bits, 1, 0x00 ); // streamDependency bits_write( &bits, 1, 0x00 ); // URL Flag bits_write( &bits, 1, 0x00 ); // OCRStreamFlag bits_write( &bits, 5, 0x1f ); // streamPriority // DecoderConfigDesciptor bits_align( &bits ); bits_write( &bits, 8, 0x04 ); // DecoderConfigDescrTag bits_fix_Decoder = bits; bits_write( &bits, 24, GetDescriptorLength24b( 0 ) ); if( p_stream->i_stream_type == 0x10 ) { bits_write( &bits, 8, 0x20 ); // Visual 14496-2 bits_write( &bits, 6, 0x04 ); // VisualStream } else if( p_stream->i_stream_type == 0x11 ) { bits_write( &bits, 8, 0x40 ); // Audio 14496-3 bits_write( &bits, 6, 0x05 ); // AudioStream } else { bits_write( &bits, 8, 0x00 ); bits_write( &bits, 6, 0x00 ); msg_Err( p_mux->p_sout,"Unsupported stream_type => broken IOD"); } bits_write( &bits, 1, 0x00 ); // UpStream bits_write( &bits, 1, 0x01 ); // reserved bits_write( &bits, 24, 1024 * 1024 ); // bufferSizeDB bits_write( &bits, 32, 0x7fffffff ); // maxBitrate bits_write( &bits, 32, 0 ); // avgBitrate if( p_stream->i_decoder_specific_info > 0 ) { int i; // DecoderSpecificInfo bits_align( &bits ); bits_write( &bits, 8, 0x05 ); // tag bits_write( &bits, 24, GetDescriptorLength24b( p_stream->i_decoder_specific_info ) ); for( i = 0; i < p_stream->i_decoder_specific_info; i++ ) { bits_write( &bits, 8, ((uint8_t*)p_stream->p_decoder_specific_info)[i] ); } } /* fix Decoder length */ bits_write( &bits_fix_Decoder, 24, GetDescriptorLength24b( bits.i_data - bits_fix_Decoder.i_data - 3 ) ); /* SLConfigDescriptor : predifined (0x01) */ bits_align( &bits ); bits_write( &bits, 8, 0x06 ); // tag bits_write( &bits, 24, GetDescriptorLength24b( 8 ) ); bits_write( &bits, 8, 0x01 ); // predefined bits_write( &bits, 1, 0 ); // durationFlag bits_write( &bits, 32, 0 ); // OCRResolution bits_write( &bits, 8, 0 ); // OCRLength bits_write( &bits, 8, 0 ); // InstantBitrateLength bits_align( &bits ); /* fix ESDescr length */ bits_write( &bits_fix_ESDescr, 24, GetDescriptorLength24b( bits.i_data - bits_fix_ESDescr.i_data - 3 ) ); } } bits_align( &bits ); /* fix IOD length */ bits_write( &bits_fix_IOD, 24, GetDescriptorLength24b( bits.i_data - bits_fix_IOD.i_data - 3 ) ); dvbpsi_PMTAddDescriptor( &pmt, 0x1d, bits.i_data, bits.p_data ); } for( i_stream = 0; i_stream < p_mux->i_nb_inputs; i_stream++ ) { ts_stream_t *p_stream; p_stream = (ts_stream_t*)p_mux->pp_inputs[i_stream]->p_sys; p_es = dvbpsi_PMTAddES( &pmt, p_stream->i_stream_type, p_stream->i_pid ); if( p_stream->i_stream_id == 0xfa || p_stream->i_stream_id == 0xfb ) { uint8_t es_id[2]; /* SL descriptor */ es_id[0] = (p_stream->i_es_id >> 8)&0xff; es_id[1] = (p_stream->i_es_id)&0xff; dvbpsi_PMTESAddDescriptor( p_es, 0x1f, 2, es_id ); } else if( p_stream->i_stream_type == 0xa0 ) { uint8_t data[512]; int i_extra = __MIN( p_stream->i_decoder_specific_info, 502 ); /* private DIV3 descripor */ memcpy( &data[0], &p_stream->i_bih_codec, 4 ); data[4] = ( p_stream->i_bih_width >> 8 )&0xff; data[5] = ( p_stream->i_bih_width )&0xff; data[6] = ( p_stream->i_bih_height>> 8 )&0xff; data[7] = ( p_stream->i_bih_height )&0xff; data[8] = ( i_extra >> 8 )&0xff; data[9] = ( i_extra )&0xff; if( i_extra > 0 ) { memcpy( &data[10], p_stream->p_decoder_specific_info, i_extra ); } /* 0xa0 is private */ dvbpsi_PMTESAddDescriptor( p_es, 0xa0, i_extra + 10, data ); } else if( p_stream->i_stream_type == 0x81 ) { uint8_t format[4] = { 0x41, 0x43, 0x2d, 0x33 }; /* "registration" descriptor : "AC-3" */ dvbpsi_PMTESAddDescriptor( p_es, 0x05, 4, format ); } if( p_stream->lang[0] != 0 ) { uint8_t data[4]; /* I construct the content myself, way faster than looking at * over complicated/mind broken libdvbpsi way */ data[0] = p_stream->lang[0]; data[1] = p_stream->lang[1]; data[2] = p_stream->lang[2]; data[3] = 0x00; /* audio type: 0x00 undefined */ dvbpsi_PMTESAddDescriptor( p_es, 0x0a, 4, data ); } } p_section = dvbpsi_GenPMTSections( &pmt ); p_pmt = WritePSISection( p_mux->p_sout, p_section ); PEStoTS( p_mux->p_sout, c, p_pmt, &p_sys->pmt ); dvbpsi_DeletePSISections( p_section ); dvbpsi_EmptyPMT( &pmt );}#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -