📄 ts.c
字号:
} 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, VLC_FALSE );}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, VLC_FALSE );}#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, VLC_FALSE ); 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; 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 data[512]; bits_buffer_t bits; /* SL descriptor */ bits_initwrite( &bits, 512, data ); bits_write( &bits, 16, p_stream->i_es_id ); dvbpsi_PMTESAddDescriptor( p_es, 0x1f, bits.i_data, bits.p_data ); } else if( p_stream->i_stream_id == 0xa0 ) { uint8_t data[512]; uint8_t fcc[4]; bits_buffer_t bits; memcpy( fcc, &p_stream->i_bih_codec, 4 ); /* private DIV3 descripor */ bits_initwrite( &bits, 512, data ); bits_write( &bits, 8, fcc[0]); bits_write( &bits, 8, fcc[1]); bits_write( &bits, 8, fcc[2]); bits_write( &bits, 8, fcc[3]); bits_write( &bits, 16, p_stream->i_bih_width ); bits_write( &bits, 16, p_stream->i_bih_height ); bits_write( &bits, 16, p_stream->i_decoder_specific_info ); if( p_stream->i_decoder_specific_info > 0 ) { int i; for( i = 0; i < p_stream->i_decoder_specific_info; i++ ) { bits_write( &bits, 8, p_stream->p_decoder_specific_info[i] ); } } dvbpsi_PMTESAddDescriptor( p_es, 0xa0, // private bits.i_data, bits.p_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, VLC_FALSE ); dvbpsi_DeletePSISections( p_section ); dvbpsi_EmptyPMT( &pmt );}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -