[vlc-commits] demux: mkv: process block additions for WEBVTT
Francois Cartegnie
git at videolan.org
Wed Jul 22 16:17:38 CEST 2020
vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Jul 16 09:54:07 2020 +0200| [f176de7447c1198a0b7c2c19d57a940fccaf750c] | committer: Francois Cartegnie
demux: mkv: process block additions for WEBVTT
(cherry picked from commit 967bf75afc5b2bc6a648355f2bb24f664e6bc77a)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=f176de7447c1198a0b7c2c19d57a940fccaf750c
---
modules/demux/mkv/mkv.cpp | 18 +++++++++++++++-
modules/demux/mkv/util.cpp | 52 +++++++++++++++++++++++++++++++---------------
modules/demux/mkv/util.hpp | 3 ++-
3 files changed, 54 insertions(+), 19 deletions(-)
diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
index 647ec0ebac..9fecb52ed6 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -607,8 +607,24 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
case VLC_CODEC_WEBVTT:
{
+ const uint8_t *p_addition = NULL;
+ size_t i_addition = 0;
+ if(additions)
+ {
+ KaxBlockMore *blockmore = FindChild<KaxBlockMore>(*additions);
+ if(blockmore)
+ {
+ KaxBlockAdditional *addition = FindChild<KaxBlockAdditional>(*blockmore);
+ if(addition)
+ {
+ i_addition = static_cast<std::string::size_type>(addition->GetSize());
+ p_addition = reinterpret_cast<const uint8_t *>(addition->GetBuffer());
+ }
+ }
+ }
p_block = WEBVTT_Repack_Sample( p_block, /* D_WEBVTT -> webm */
- !p_track->codec.compare( 0, 1, "D" ) );
+ !p_track->codec.compare( 0, 1, "D" ),
+ p_addition, i_addition );
if( !p_block )
continue;
}
diff --git a/modules/demux/mkv/util.cpp b/modules/demux/mkv/util.cpp
index 9104deab0c..8afed9df72 100644
--- a/modules/demux/mkv/util.cpp
+++ b/modules/demux/mkv/util.cpp
@@ -243,20 +243,38 @@ void handle_real_audio(demux_t * p_demux, mkv_track_t * p_tk, block_t * p_blk, m
}
}
-block_t *WEBVTT_Repack_Sample(block_t *p_block, bool b_webm)
+block_t *WEBVTT_Repack_Sample(block_t *p_block, bool b_webm,
+ const uint8_t *p_add, size_t i_add)
{
struct webvtt_cueelements_s els;
memset(&els, 0, sizeof(els));
+ size_t newsize = 0;
+ block_t *newblock = nullptr;
/* Repack to ISOBMFF samples format */
if( !b_webm ) /* S_TEXT/WEBVTT */
{
- p_block = block_Realloc( p_block, 16, p_block->i_buffer );
- if( !p_block )
- return NULL;
- SetDWBE( p_block->p_buffer, p_block->i_buffer );
- memcpy( &p_block->p_buffer[ 4], "vttc", 4 );
- SetDWBE( &p_block->p_buffer[ 8], p_block->i_buffer - 8 );
- memcpy( &p_block->p_buffer[12], "payl", 4 );
+ /* process addition fields */
+ if( i_add )
+ {
+ const uint8_t *end = p_add + i_add;
+ const uint8_t *iden =
+ reinterpret_cast<const uint8_t *>(std::memchr( p_add, '\n', i_add ));
+ if( iden && ++iden != end )
+ {
+ els.sttg.p_data = p_add;
+ els.sttg.i_data = &iden[-1] - p_add;
+ const uint8_t *comm =
+ reinterpret_cast<const uint8_t *>(std::memchr( iden, '\n', end - iden ));
+ els.iden.p_data = iden;
+ if( comm )
+ els.iden.i_data = comm - iden;
+ else
+ els.iden.i_data = end - iden;
+ }
+ }
+ /* the payload being in the block */
+ els.payl.p_data = p_block->p_buffer;
+ els.payl.i_data = p_block->i_buffer;
}
else /* deprecated D_WEBVTT/ */
{
@@ -276,16 +294,16 @@ block_t *WEBVTT_Repack_Sample(block_t *p_block, bool b_webm)
els.sttg.i_data = &payl[-1] - sttg;
els.payl.p_data = payl;
els.payl.i_data = end - payl;
- size_t newsize = WEBVTT_Pack_CueElementsGetNewSize( &els );
- block_t *newblock = block_Alloc( newsize );
- if( !newblock )
- goto error;
- WEBVTT_Pack_CueElements( &els, newblock->p_buffer );
- block_CopyProperties( newblock, p_block );
- block_Release( p_block );
- return newblock;
}
- return p_block;
+
+ newsize = WEBVTT_Pack_CueElementsGetNewSize( &els );
+ newblock = block_Alloc( newsize );
+ if( !newblock )
+ goto error;
+ WEBVTT_Pack_CueElements( &els, newblock->p_buffer );
+ block_CopyProperties( newblock, p_block );
+ block_Release( p_block );
+ return newblock;
error:
block_Release( p_block );
diff --git a/modules/demux/mkv/util.hpp b/modules/demux/mkv/util.hpp
index f89e1cc89f..2cb6e90082 100644
--- a/modules/demux/mkv/util.hpp
+++ b/modules/demux/mkv/util.hpp
@@ -32,7 +32,8 @@ block_t *block_zlib_decompress( vlc_object_t *p_this, block_t *p_in_block );
block_t *MemToBlock( uint8_t *p_mem, size_t i_mem, size_t offset);
void handle_real_audio(demux_t * p_demux, mkv_track_t * p_tk, block_t * p_blk, mtime_t i_pts);
-block_t *WEBVTT_Repack_Sample(block_t *p_block, bool b_webm = false);
+block_t *WEBVTT_Repack_Sample(block_t *p_block, bool b_webm = false,
+ const uint8_t * = NULL, size_t = 0);
void send_Block( demux_t * p_demux, mkv_track_t * p_tk, block_t * p_block, unsigned int i_number_frames, mtime_t i_duration );
More information about the vlc-commits
mailing list