vlc | branch: master | Francois Cartegnie <[email protected]> | Mon Aug 19 18:58:51 2019 +0200| [cc669ab67785f932f95a1341623a4180ade135df] | committer: Francois Cartegnie
demux: ps: const correctness and less block_t dependency > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cc669ab67785f932f95a1341623a4180ade135df --- modules/access/dvdnav.c | 7 +-- modules/access/dvdread.c | 7 +-- modules/demux/mpeg/ps.c | 20 ++++++--- modules/demux/mpeg/ps.h | 113 +++++++++++++++++++++++++---------------------- modules/demux/vobsub.c | 2 +- 5 files changed, 82 insertions(+), 67 deletions(-) diff --git a/modules/access/dvdnav.c b/modules/access/dvdnav.c index 540e9aad4d..0a915f1e6a 100644 --- a/modules/access/dvdnav.c +++ b/modules/access/dvdnav.c @@ -1424,7 +1424,8 @@ static int DemuxBlock( demux_t *p_demux, const uint8_t *p, int len ) { vlc_tick_t i_scr; int i_mux_rate; - if( !ps_pkt_parse_pack( p_pkt, &i_scr, &i_mux_rate ) ) + if( !ps_pkt_parse_pack( p_pkt->p_buffer, p_pkt->i_buffer, + &i_scr, &i_mux_rate ) ) { es_out_SetPCR( p_demux->out, i_scr ); if( i_mux_rate > 0 ) p_sys->i_mux_rate = i_mux_rate; @@ -1434,7 +1435,7 @@ static int DemuxBlock( demux_t *p_demux, const uint8_t *p, int len ) } default: { - int i_id = ps_pkt_id( p_pkt ); + int i_id = ps_pkt_id( p_pkt->p_buffer, p_pkt->i_buffer ); if( i_id >= 0xc0 ) { ps_track_t *tk = &p_sys->tk[ps_id_to_tk(i_id)]; @@ -1510,7 +1511,7 @@ static void ESNew( demux_t *p_demux, int i_id ) if( tk->b_configured ) return; - if( ps_track_fill( tk, 0, i_id, NULL, true ) ) + if( ps_track_fill( tk, 0, i_id, NULL, 0, true ) ) { msg_Warn( p_demux, "unknown codec for id=0x%x", i_id ); return; diff --git a/modules/access/dvdread.c b/modules/access/dvdread.c index 10138189bd..7b3a4a3694 100644 --- a/modules/access/dvdread.c +++ b/modules/access/dvdread.c @@ -605,7 +605,8 @@ static int DemuxBlock( demux_t *p_demux, const uint8_t *p, int len ) { vlc_tick_t i_scr; int i_mux_rate; - if( !ps_pkt_parse_pack( p_pkt, &i_scr, &i_mux_rate ) ) + if( !ps_pkt_parse_pack( p_pkt->p_buffer, p_pkt->i_buffer, + &i_scr, &i_mux_rate ) ) { es_out_SetPCR( p_demux->out, VLC_TICK_0 + i_scr ); if( i_mux_rate > 0 ) p_sys->i_mux_rate = i_mux_rate; @@ -615,7 +616,7 @@ static int DemuxBlock( demux_t *p_demux, const uint8_t *p, int len ) } default: { - int i_id = ps_pkt_id( p_pkt ); + int i_id = ps_pkt_id( p_pkt->p_buffer, p_pkt->i_buffer ); if( i_id >= 0xc0 ) { ps_track_t *tk = &p_sys->tk[ps_id_to_tk(i_id)]; @@ -660,7 +661,7 @@ static void ESNew( demux_t *p_demux, int i_id, int i_lang ) if( tk->b_configured ) return; - if( ps_track_fill( tk, 0, i_id, NULL, true ) ) + if( ps_track_fill( tk, 0, i_id, NULL, 0, true ) ) { msg_Warn( p_demux, "unknown codec for id=0x%x", i_id ); return; diff --git a/modules/demux/mpeg/ps.c b/modules/demux/mpeg/ps.c index 859c23b313..68a69a4955 100644 --- a/modules/demux/mpeg/ps.c +++ b/modules/demux/mpeg/ps.c @@ -302,7 +302,7 @@ static int Probe( demux_t *p_demux, bool b_end ) return VLC_DEMUXER_EOF; } - i_id = ps_pkt_id( p_pkt ); + i_id = ps_pkt_id( p_pkt->p_buffer, p_pkt->i_buffer ); if( i_id >= 0xc0 ) { ps_track_t *tk = &p_sys->tk[ps_id_to_tk(i_id)]; @@ -322,7 +322,8 @@ static int Probe( demux_t *p_demux, bool b_end ) else if( i_id == PS_STREAM_ID_PACK_HEADER ) { vlc_tick_t i_scr; int dummy; - if( !b_end && !ps_pkt_parse_pack( p_pkt, &i_scr, &dummy ) ) + if( !b_end && !ps_pkt_parse_pack( p_pkt->p_buffer, p_pkt->i_buffer, + &i_scr, &dummy ) ) { if( p_sys->i_first_scr == VLC_TICK_INVALID ) p_sys->i_first_scr = i_scr; @@ -460,7 +461,8 @@ static int Demux( demux_t *p_demux ) break; case PS_STREAM_ID_PACK_HEADER: - if( !ps_pkt_parse_pack( p_pkt, &p_sys->i_pack_scr, &i_mux_rate ) ) + if( !ps_pkt_parse_pack( p_pkt->p_buffer, p_pkt->i_buffer, + &p_sys->i_pack_scr, &i_mux_rate ) ) { if( p_sys->i_first_scr == VLC_TICK_INVALID ) p_sys->i_first_scr = p_sys->i_pack_scr; @@ -476,7 +478,8 @@ static int Demux( demux_t *p_demux ) break; case PS_STREAM_ID_SYSTEM_HEADER: - if( !ps_pkt_parse_system( p_pkt, &p_sys->psm, p_sys->tk ) ) + if( !ps_pkt_parse_system( p_pkt->p_buffer, p_pkt->i_buffer, + &p_sys->psm, p_sys->tk ) ) { int i; for( i = 0; i < PS_TK_COUNT; i++ ) @@ -499,7 +502,9 @@ static int Demux( demux_t *p_demux ) if( p_sys->psm.i_version == 0xFFFF ) msg_Dbg( p_demux, "contains a PSM"); - ps_psm_fill( &p_sys->psm, p_pkt, p_sys->tk, p_demux->out ); + ps_psm_fill( &p_sys->psm, + p_pkt->p_buffer, p_pkt->i_buffer, + p_sys->tk, p_demux->out ); block_Release( p_pkt ); break; @@ -514,7 +519,7 @@ static int Demux( demux_t *p_demux ) case PS_STREAM_ID_PRIVATE_STREAM1: case PS_STREAM_ID_EXTENDED: { - int i_id = ps_pkt_id( p_pkt ); + int i_id = ps_pkt_id( p_pkt->p_buffer, p_pkt->i_buffer ); /* Small heuristic to improve MLP detection from AOB */ if( i_id == 0xa001 && p_sys->i_aob_mlp_count < 500 ) @@ -533,7 +538,8 @@ static int Demux( demux_t *p_demux ) if( !tk->b_configured ) { - if( !ps_track_fill( tk, &p_sys->psm, i_id, p_pkt, false ) ) + if( !ps_track_fill( tk, &p_sys->psm, i_id, + p_pkt->p_buffer, p_pkt->i_buffer, false ) ) { /* No PSM and no probing yet */ if( p_sys->format == PSMF_PS ) diff --git a/modules/demux/mpeg/ps.h b/modules/demux/mpeg/ps.h index 1ce0bb4185..097dcc1dbb 100644 --- a/modules/demux/mpeg/ps.h +++ b/modules/demux/mpeg/ps.h @@ -121,7 +121,9 @@ static inline bool ps_is_H264( const uint8_t *p_data, size_t i_data ) /* From id fill i_skip and es_format_t */ static inline int ps_track_fill( ps_track_t *tk, ps_psm_t *p_psm, - int i_id, block_t *p_pkt, bool b_mpeg2only ) + int i_id, + const uint8_t *p_pkt, size_t i_pkt, + bool b_mpeg2only ) { tk->i_skip = 0; tk->i_id = i_id; @@ -140,17 +142,17 @@ static inline int ps_track_fill( ps_track_t *tk, ps_psm_t *p_psm, bool b_eac3 = false; if( ( i_id&0xf0 ) == 0xc0 ) { - if( p_pkt == NULL || p_pkt->i_buffer < 9 ) + if( p_pkt == NULL || i_pkt < 9 ) return VLC_EGENERIC; - unsigned i_start = 9 + p_pkt->p_buffer[8]; - if( i_start + 9 < p_pkt->i_buffer ) + unsigned i_start = 9 + p_pkt[8]; + if( i_start + 9 < i_pkt ) { /* AC-3 marking, see vlc_a52_header_Parse */ - if( p_pkt->p_buffer[i_start + 4] == 0x0b || - p_pkt->p_buffer[i_start + 5] == 0x77 ) + if( p_pkt[i_start + 4] == 0x0b || + p_pkt[i_start + 5] == 0x77 ) { - int bsid = p_pkt->p_buffer[i_start + 9] >> 3; + int bsid = p_pkt[i_start + 9] >> 3; if( bsid > 10 ) b_eac3 = true; } @@ -261,10 +263,10 @@ static inline int ps_track_fill( ps_track_t *tk, ps_psm_t *p_psm, es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 ); } else if( p_pkt && i_type == 0x00 && /* Not from PSM */ - p_pkt->i_buffer > 9 + 5 && - p_pkt->i_buffer > 9U + 5 + p_pkt->p_buffer[8] && - ps_is_H264( &p_pkt->p_buffer[ 9 + p_pkt->p_buffer[8] ], - p_pkt->i_buffer - 9 - p_pkt->p_buffer[8] ) ) + i_pkt > 9 + 5 && + i_pkt > 9U + 5 + p_pkt[8] && + ps_is_H264( &p_pkt[ 9 + p_pkt[8] ], + i_pkt - 9 - p_pkt[8] ) ) { es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 ); } @@ -317,21 +319,23 @@ static inline int ps_track_fill( ps_track_t *tk, ps_psm_t *p_psm, } /* return the id of a PES (should be valid) */ -static inline int ps_pkt_id( block_t *p_pkt ) +static inline int ps_pkt_id( const uint8_t *p_pkt, size_t i_pkt ) { - if( p_pkt->p_buffer[3] == 0xbd ) + if(unlikely(i_pkt < 4)) + return 0; + if( p_pkt[3] == 0xbd ) { uint8_t i_sub_id = 0; - if( p_pkt->i_buffer >= 9 && - p_pkt->i_buffer > 9 + (size_t)p_pkt->p_buffer[8] ) + if( i_pkt >= 9 && + i_pkt > 9 + (size_t)p_pkt[8] ) { - const unsigned i_start = 9 + p_pkt->p_buffer[8]; - i_sub_id = p_pkt->p_buffer[i_start]; + const unsigned i_start = 9 + p_pkt[8]; + i_sub_id = p_pkt[i_start]; if( (i_sub_id & 0xfe) == 0xa0 && - p_pkt->i_buffer >= i_start + 7 && - ( p_pkt->p_buffer[i_start + 5] >= 0xc0 || - p_pkt->p_buffer[i_start + 6] != 0x80 ) ) + i_pkt >= i_start + 7 && + ( p_pkt[i_start + 5] >= 0xc0 || + p_pkt[i_start + 6] != 0x80 ) ) { /* AOB LPCM/MLP extension * XXX for MLP I think that the !=0x80 test is not good and @@ -343,13 +347,13 @@ static inline int ps_pkt_id( block_t *p_pkt ) /* VOB extension */ return 0xbd00 | i_sub_id; } - else if( p_pkt->p_buffer[3] == 0xfd && - p_pkt->i_buffer >= 9 && - (p_pkt->p_buffer[6]&0xC0) == 0x80 && /* mpeg2 */ - (p_pkt->p_buffer[7]&0x01) == 0x01 ) /* extension_flag */ + else if( i_pkt >= 9 && + p_pkt[3] == 0xfd && + (p_pkt[6]&0xC0) == 0x80 && /* mpeg2 */ + (p_pkt[7]&0x01) == 0x01 ) /* extension_flag */ { /* ISO 13818 amendment 2 and SMPTE RP 227 */ - const uint8_t i_flags = p_pkt->p_buffer[7]; + const uint8_t i_flags = p_pkt[7]; unsigned int i_skip = 9; /* Find PES extension */ @@ -370,34 +374,34 @@ static inline int ps_pkt_id( block_t *p_pkt ) if( (i_flags & 0x02 ) ) i_skip += 2; - if( i_skip < p_pkt->i_buffer && (p_pkt->p_buffer[i_skip]&0x01) ) + if( i_skip < i_pkt && (p_pkt[i_skip]&0x01) ) { - const uint8_t i_flags2 = p_pkt->p_buffer[i_skip]; + const uint8_t i_flags2 = p_pkt[i_skip]; /* Find PES extension 2 */ i_skip += 1; if( i_flags2 & 0x80 ) i_skip += 16; - if( (i_flags2 & 0x40) && i_skip < p_pkt->i_buffer ) - i_skip += 1 + p_pkt->p_buffer[i_skip]; + if( (i_flags2 & 0x40) && i_skip < i_pkt ) + i_skip += 1 + p_pkt[i_skip]; if( i_flags2 & 0x20 ) i_skip += 2; if( i_flags2 & 0x10 ) i_skip += 2; - if( i_skip + 1 < p_pkt->i_buffer ) + if( i_skip + 1 < i_pkt ) { - const int i_extension_field_length = p_pkt->p_buffer[i_skip]&0x7f; + const int i_extension_field_length = p_pkt[i_skip]&0x7f; if( i_extension_field_length >=1 ) { - int i_stream_id_extension_flag = (p_pkt->p_buffer[i_skip+1] >> 7)&0x1; + int i_stream_id_extension_flag = (p_pkt[i_skip+1] >> 7)&0x1; if( i_stream_id_extension_flag == 0 ) - return 0xfd00 | (p_pkt->p_buffer[i_skip+1]&0x7f); + return 0xfd00 | (p_pkt[i_skip+1]&0x7f); } } } } - return p_pkt->p_buffer[3]; + return p_pkt[3]; } /* return the size of the next packet */ @@ -432,16 +436,16 @@ static inline int ps_pkt_size( const uint8_t *p, int i_peek ) } /* parse a PACK PES */ -static inline int ps_pkt_parse_pack( block_t *p_pkt, vlc_tick_t *pi_scr, - int *pi_mux_rate ) +static inline int ps_pkt_parse_pack( const uint8_t *p_pkt, size_t i_pkt, + vlc_tick_t *pi_scr, int *pi_mux_rate ) { - uint8_t *p = p_pkt->p_buffer; - if( p_pkt->i_buffer >= 14 && (p[4] >> 6) == 0x01 ) + const uint8_t *p = p_pkt; + if( i_pkt >= 14 && (p[4] >> 6) == 0x01 ) { *pi_scr = FROM_SCALE( ExtractPackHeaderTimestamp( &p[4] ) ); *pi_mux_rate = ( p[10] << 14 )|( p[11] << 6 )|( p[12] >> 2); } - else if( p_pkt->i_buffer >= 12 && (p[4] >> 4) == 0x02 ) /* MPEG-1 Pack SCR, same bits as PES/PTS */ + else if( i_pkt >= 12 && (p[4] >> 4) == 0x02 ) /* MPEG-1 Pack SCR, same bits as PES/PTS */ { stime_t i_scr; if(!ExtractPESTimestamp( &p[4], 0x02, &i_scr )) @@ -457,26 +461,28 @@ static inline int ps_pkt_parse_pack( block_t *p_pkt, vlc_tick_t *pi_scr, } /* Parse a SYSTEM PES */ -static inline int ps_pkt_parse_system( block_t *p_pkt, ps_psm_t *p_psm, +static inline int ps_pkt_parse_system( const uint8_t *p_pkt, size_t i_pkt, + ps_psm_t *p_psm, ps_track_t tk[PS_TK_COUNT] ) { - uint8_t *p = &p_pkt->p_buffer[6 + 3 + 1 + 1 + 1]; + const uint8_t *p = &p_pkt[6 + 3 + 1 + 1 + 1]; + const uint8_t *p_pktend = &p_pkt[i_pkt]; /* System header is not useable if it references private streams (0xBD) * or 'all audio streams' (0xB8) or 'all video streams' (0xB9) */ - while( p < &p_pkt->p_buffer[p_pkt->i_buffer] && (p[0] & 0x80) ) + while( p < p_pktend && (p[0] & 0x80) ) { int i_id = p[0]; switch( i_id ) { case 0xB7: - if( &p_pkt->p_buffer[p_pkt->i_buffer] - p < 6 ) + if( p_pktend - p < 6 ) return VLC_EGENERIC; i_id = ((int)PS_STREAM_ID_EXTENDED << 8) | (p[2] & 0x7F); p += 6; break; default: - if( &p_pkt->p_buffer[p_pkt->i_buffer] - p < 3 ) + if( p_pktend - p < 3 ) return VLC_EGENERIC; p += 3; break; @@ -487,7 +493,7 @@ static inline int ps_pkt_parse_system( block_t *p_pkt, ps_psm_t *p_psm, int i_tk = ps_id_to_tk( i_id ); if( !tk[i_tk].b_configured ) - ps_track_fill( &tk[i_tk], p_psm, i_id, NULL, false ); + ps_track_fill( &tk[i_tk], p_psm, i_id, NULL, 0, false ); } return VLC_SUCCESS; } @@ -511,7 +517,8 @@ static inline int ps_pkt_parse_pes( vlc_object_t *p_object, block_t *p_pes, int if( i_skip_extra >= 0 ) i_skip += i_skip_extra; else if( p_pes->i_buffer > i_skip + 3 && - ( ps_pkt_id( p_pes ) == 0xa001 || ps_pkt_id( p_pes ) == 0xbda1 ) ) + ( ps_pkt_id( p_pes->p_buffer, p_pes->i_buffer ) == 0xa001 || + ps_pkt_id( p_pes->p_buffer, p_pes->i_buffer ) == 0xbda1 ) ) i_skip += 4 + p_pes->p_buffer[i_skip+3]; if( p_pes->i_buffer <= i_skip ) @@ -617,23 +624,22 @@ static inline void ps_parse_descriptors( const uint8_t *p_data, size_t i_data, } } -static inline int ps_psm_fill( ps_psm_t *p_psm, block_t *p_pkt, +static inline int ps_psm_fill( ps_psm_t *p_psm, + const uint8_t *p_buffer, size_t i_pkt, ps_track_t tk[PS_TK_COUNT], es_out_t *out ) { - size_t i_buffer = p_pkt->i_buffer; - uint8_t *p_buffer = p_pkt->p_buffer; size_t i_length, i_info_length, i_es_base; int i_version; bool b_single_extension; // Demux() checks that we have at least 4 bytes, but we need // at least 10 to read up to the info_length field - assert(i_buffer >= 4); - if( !p_psm || i_buffer < 10 || p_buffer[3] != PS_STREAM_ID_MAP) + assert(i_pkt >= 4); + if( !p_psm || i_pkt < 10 || p_buffer[3] != PS_STREAM_ID_MAP) return VLC_EGENERIC; i_length = GetWBE(&p_buffer[4]) + 6; - if( i_length > i_buffer ) return VLC_EGENERIC; + if( i_length > i_pkt ) return VLC_EGENERIC; if((p_buffer[6] & 0x80) == 0) /* current_next_indicator */ return VLC_EGENERIC; @@ -705,7 +711,8 @@ static inline int ps_psm_fill( ps_psm_t *p_psm, block_t *p_pkt, ps_track_t tk_tmp; es_format_Init( &tk_tmp.fmt, UNKNOWN_ES, 0 ); - if( ps_track_fill( &tk_tmp, p_psm, tk[i].i_id, p_pkt, false ) != VLC_SUCCESS ) + if( ps_track_fill( &tk_tmp, p_psm, tk[i].i_id, + p_buffer, i_pkt, false ) != VLC_SUCCESS ) continue; if( tk_tmp.fmt.i_codec == tk[i].fmt.i_codec ) diff --git a/modules/demux/vobsub.c b/modules/demux/vobsub.c index 4b5444e71b..d75f2d53d0 100644 --- a/modules/demux/vobsub.c +++ b/modules/demux/vobsub.c @@ -675,7 +675,7 @@ static int DemuxVobSub( demux_t *p_demux, block_t *p_bk ) memcpy( p_pkt->p_buffer, p, i_size); p += i_size; - i_id = ps_pkt_id( p_pkt ); + i_id = ps_pkt_id( p_pkt->p_buffer, p_pkt->i_buffer ); if( (i_id&0xffe0) != 0xbd20 || ps_pkt_parse_pes( VLC_OBJECT(p_demux), p_pkt, 1 ) ) { _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
