[vlc-devel] [PATCH 3/9] demux: mkv: simplify block handling
Steve Lhomme
robux4 at ycbcr.xyz
Mon Jul 16 11:57:53 CEST 2018
Although I said everything in libmatroska can be used, this class is not
really supposed to be used, hence the name Internal.
But in reality it should be but with a different name. So we can use it
and will change the name when/if it does.
On 2018-07-16 5:19, Filip Roséen wrote:
> As KaxSimpleBlock and KaxBlock inherit from the same base we can get
> rid of all these nasty if-else's by creating an object that refers to
> the one we are interested in.
> ---
> modules/demux/mkv/matroska_segment_seeker.cpp | 17 ++++----
> modules/demux/mkv/mkv.cpp | 39 +++++++------------
> 2 files changed, 21 insertions(+), 35 deletions(-)
>
> diff --git a/modules/demux/mkv/matroska_segment_seeker.cpp b/modules/demux/mkv/matroska_segment_seeker.cpp
> index a4c5daec29..2c17b60328 100644
> --- a/modules/demux/mkv/matroska_segment_seeker.cpp
> +++ b/modules/demux/mkv/matroska_segment_seeker.cpp
> @@ -359,16 +359,13 @@ SegmentSeeker::index_unsearched_range( matroska_segment_c& ms, Range search_area
> if( ms.BlockGet( block, simpleblock, &b_key_picture, &b_discardable_picture, &i_block_duration ) )
> break;
>
> - if( simpleblock ) {
> - block_pos = simpleblock->GetElementPosition();
> - block_pts = simpleblock->GlobalTimecode() / 1000;
> - track_id = simpleblock->TrackNum();
> - }
> - else {
> - block_pos = block->GetElementPosition();
> - block_pts = block->GlobalTimecode() / 1000;
> - track_id = block->TrackNum();
> - }
> + KaxInternalBlock& internal_block = simpleblock
> + ? static_cast<KaxInternalBlock&>( *simpleblock )
> + : static_cast<KaxInternalBlock&>( *block );
> +
> + block_pos = internal_block.GetElementPosition();
> + block_pts = internal_block.GlobalTimecode() / 1000;
> + track_id = internal_block.TrackNum();
>
> bool const b_valid_track = ms.FindTrackByBlock( block, simpleblock ) != NULL;
>
> diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
> index 407bc50013..220a061e57 100644
> --- a/modules/demux/mkv/mkv.cpp
> +++ b/modules/demux/mkv/mkv.cpp
> @@ -517,6 +517,10 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
> demux_sys_t *p_sys = (demux_sys_t *)p_demux->p_sys;
> matroska_segment_c *p_segment = p_sys->p_current_vsegment->CurrentSegment();
>
> + KaxInternalBlock& internal_block = simpleblock
> + ? static_cast<KaxInternalBlock&>( *simpleblock )
> + : static_cast<KaxInternalBlock&>( *block );
> +
> if( !p_segment ) return;
>
> mkv_track_t *p_track = p_segment->FindTrackByBlock( block, simpleblock );
> @@ -550,28 +554,14 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
> }
>
> size_t frame_size = 0;
> - size_t block_size = 0;
> -
> - if( simpleblock != NULL )
> - block_size = simpleblock->GetSize();
> - else
> - block_size = block->GetSize();
> -
> - const unsigned int i_number_frames = block != NULL ? block->NumberFrames() :
> - ( simpleblock != NULL ? simpleblock->NumberFrames() : 0 );
> + size_t block_size = internal_block.GetSize();
> + const unsigned i_number_frames = internal_block.NumberFrames();
>
> for( unsigned int i_frame = 0; i_frame < i_number_frames; i_frame++ )
> {
> block_t *p_block;
> - DataBuffer *data;
> - if( simpleblock != NULL )
> - {
> - data = &simpleblock->GetBuffer(i_frame);
> - }
> - else
> - {
> - data = &block->GetBuffer(i_frame);
> - }
> + DataBuffer *data = &internal_block.GetBuffer(i_frame);
> +
> frame_size += data->Size();
> if( !data->Buffer() || data->Size() > frame_size || frame_size > block_size )
> {
> @@ -746,6 +736,10 @@ static int Demux( demux_t *p_demux)
> return VLC_DEMUXER_EOF;
> }
>
> + KaxInternalBlock& internal_block = block
> + ? static_cast<KaxInternalBlock&>( *block )
> + : static_cast<KaxInternalBlock&>( *simpleblock );
> +
> {
> mkv_track_t *p_track = p_segment->FindTrackByBlock( block, simpleblock );
>
> @@ -761,10 +755,7 @@ static int Demux( demux_t *p_demux)
>
> if( track.i_skip_until_fpos != std::numeric_limits<uint64_t>::max() ) {
>
> - uint64_t block_fpos = 0;
> -
> - if( block ) block_fpos = block->GetElementPosition();
> - else block_fpos = simpleblock->GetElementPosition();
> + uint64_t block_fpos = internal_block.GetElementPosition();
>
> if ( track.i_skip_until_fpos > block_fpos )
> {
> @@ -811,9 +802,7 @@ static int Demux( demux_t *p_demux)
> /* set pts */
> {
> p_sys->i_pts = p_sys->i_mk_chapter_time + VLC_TICK_0;
> -
> - if( simpleblock != NULL ) p_sys->i_pts += simpleblock->GlobalTimecode() / INT64_C( 1000 );
> - else p_sys->i_pts += block->GlobalTimecode() / INT64_C( 1000 );
> + p_sys->i_pts += internal_block.GlobalTimecode() / INT64_C( 1000 );
> }
>
> if ( p_vsegment->CurrentEdition() &&
> --
> 2.18.0
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list