[vlc-commits] demux: mp4: merge text samples and pass to extradata
Francois Cartegnie
git at videolan.org
Fri Jan 5 20:58:42 CET 2018
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Jan 5 20:05:52 2018 +0100| [7bde66d8f3605447fee52d3fcf23271d6b6de47d] | committer: Francois Cartegnie
demux: mp4: merge text samples and pass to extradata
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7bde66d8f3605447fee52d3fcf23271d6b6de47d
---
modules/demux/mp4/essetup.c | 28 +++---------
modules/demux/mp4/libmp4.c | 101 +++++++-------------------------------------
modules/demux/mp4/libmp4.h | 21 +--------
3 files changed, 23 insertions(+), 127 deletions(-)
diff --git a/modules/demux/mp4/essetup.c b/modules/demux/mp4/essetup.c
index 36d1b91b13..4d3d212350 100644
--- a/modules/demux/mp4/essetup.c
+++ b/modules/demux/mp4/essetup.c
@@ -1274,36 +1274,18 @@ int SetupSpuES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
p_track->fmt.i_codec = VLC_CODEC_TX3G;
- if( p_text->i_display_flags & 0xC0000000 )
+ if( GetDWBE(p_text->p_data) & 0xC0000000 )
{
p_track->fmt.i_priority = ES_PRIORITY_SELECTABLE_MIN + 1;
p_track->b_forced_spu = true;
}
- text_style_t *p_style = text_style_Create( STYLE_NO_DEFAULTS );
- if ( p_style )
+ p_track->fmt.p_extra = malloc( p_text->i_data );
+ if( p_track->fmt.p_extra )
{
- if ( p_text->i_font_size ) /* !WARN: in % of 5% height */
- {
- p_style->i_font_size = p_text->i_font_size;
- }
- if ( p_text->i_font_color )
- {
- p_style->i_font_color = p_text->i_font_color >> 8;
- p_style->i_font_alpha = p_text->i_font_color & 0xFF;
- p_style->i_features |= (STYLE_HAS_FONT_ALPHA | STYLE_HAS_FONT_COLOR);
- }
- if ( p_text->i_background_color[3] >> 8 )
- {
- p_style->i_background_color = p_text->i_background_color[0] >> 8;
- p_style->i_background_color |= p_text->i_background_color[1] >> 8;
- p_style->i_background_color |= p_text->i_background_color[2] >> 8;
- p_style->i_background_alpha = p_text->i_background_color[3] >> 8;
- p_style->i_features |= (STYLE_HAS_BACKGROUND_ALPHA | STYLE_HAS_BACKGROUND_COLOR);
- }
+ memcpy( p_track->fmt.p_extra, p_text->p_data, p_text->i_data );
+ p_track->fmt.i_extra = p_text->i_data;
}
- assert(p_track->fmt.i_cat == SPU_ES);
- p_track->fmt.subs.p_style = p_style;
/* FIXME UTF-8 doesn't work here ? */
if( p_track->b_mac_encoding )
diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 2ff9f558e4..81bd189588 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -2770,52 +2770,30 @@ static int MP4_ReadBox_sample_hint8( stream_t *p_stream, MP4_Box_t *p_box )
MP4_READBOX_EXIT( 1 );
}
-static int MP4_ReadBox_sample_text( stream_t *p_stream, MP4_Box_t *p_box )
+static int MP4_FreeBox_sample_text( MP4_Box_t *p_box )
{
- int32_t t;
+ free( p_box->data.p_sample_text->p_data );
+}
+static int MP4_ReadBox_sample_text( stream_t *p_stream, MP4_Box_t *p_box )
+{
p_box->i_handler = ATOM_text;
- MP4_READBOX_ENTER( MP4_Box_data_sample_text_t, NULL );
+ MP4_READBOX_ENTER( MP4_Box_data_sample_text_t, MP4_FreeBox_sample_text );
MP4_GET4BYTES( p_box->data.p_sample_text->i_reserved1 );
MP4_GET2BYTES( p_box->data.p_sample_text->i_reserved2 );
MP4_GET2BYTES( p_box->data.p_sample_text->i_data_reference_index );
- MP4_GET4BYTES( p_box->data.p_sample_text->i_display_flags );
-
- MP4_GET4BYTES( t );
- switch( t )
- {
- /* FIXME search right signification */
- case 1: // Center
- p_box->data.p_sample_text->i_justification_horizontal = 1;
- p_box->data.p_sample_text->i_justification_vertical = 1;
- break;
- case -1: // Flush Right
- p_box->data.p_sample_text->i_justification_horizontal = -1;
- p_box->data.p_sample_text->i_justification_vertical = -1;
- break;
- case -2: // Flush Left
- p_box->data.p_sample_text->i_justification_horizontal = 0;
- p_box->data.p_sample_text->i_justification_vertical = 0;
- break;
- case 0: // Flush Default
- default:
- p_box->data.p_sample_text->i_justification_horizontal = 1;
- p_box->data.p_sample_text->i_justification_vertical = -1;
- break;
- }
+ if( i_read < 32 )
+ MP4_READBOX_EXIT( 0 );
- MP4_GET2BYTES( p_box->data.p_sample_text->i_background_color[0] );
- MP4_GET2BYTES( p_box->data.p_sample_text->i_background_color[1] );
- MP4_GET2BYTES( p_box->data.p_sample_text->i_background_color[2] );
- p_box->data.p_sample_text->i_background_color[3] = 0xFF;
+ p_box->data.p_sample_text->p_data = malloc( i_read );
+ if( !p_box->data.p_sample_text->p_data )
+ MP4_READBOX_EXIT( 0 );
- MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_top );
- MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_left );
- MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_bottom );
- MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_right );
+ p_box->data.p_sample_text->i_data = i_read;
+ memcpy( p_box->data.p_sample_text->p_data, p_peek, i_read );
#ifdef MP4_VERBOSE
msg_Dbg( p_stream, "read box: \"text\" in stsd text" );
@@ -2841,53 +2819,6 @@ static int MP4_ReadBox_sample_clcp( stream_t *p_stream, MP4_Box_t *p_box )
MP4_READBOX_EXIT( 1 );
}
-static int MP4_ReadBox_sample_tx3g( stream_t *p_stream, MP4_Box_t *p_box )
-{
- p_box->i_handler = ATOM_text;
- MP4_READBOX_ENTER( MP4_Box_data_sample_text_t, NULL );
-
- MP4_GET4BYTES( p_box->data.p_sample_text->i_reserved1 );
- MP4_GET2BYTES( p_box->data.p_sample_text->i_reserved2 );
-
- MP4_GET2BYTES( p_box->data.p_sample_text->i_data_reference_index );
-
- MP4_GET4BYTES( p_box->data.p_sample_text->i_display_flags );
-
- MP4_GET1BYTE ( p_box->data.p_sample_text->i_justification_horizontal );
- MP4_GET1BYTE ( p_box->data.p_sample_text->i_justification_vertical );
-
- MP4_GET1BYTE ( p_box->data.p_sample_text->i_background_color[0] );
- MP4_GET1BYTE ( p_box->data.p_sample_text->i_background_color[1] );
- MP4_GET1BYTE ( p_box->data.p_sample_text->i_background_color[2] );
- MP4_GET1BYTE ( p_box->data.p_sample_text->i_background_color[3] );
-
- MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_top );
- MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_left );
- MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_bottom );
- MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_right );
-
- MP4_GET4BYTES( p_box->data.p_sample_text->i_reserved3 );
-
- MP4_GET2BYTES( p_box->data.p_sample_text->i_font_id );
- MP4_GET1BYTE ( p_box->data.p_sample_text->i_font_face );
- MP4_GET1BYTE ( p_box->data.p_sample_text->i_font_size );
- MP4_GET4BYTES( p_box->data.p_sample_text->i_font_color );
-
-#ifdef MP4_VERBOSE
- msg_Dbg( p_stream, "read box: \"tx3g\" in stsd text" );
-#endif
- MP4_READBOX_EXIT( 1 );
-}
-
-
-#if 0
-/* We can't easily call it, and anyway ~ 20 bytes lost isn't a real problem */
-static void MP4_FreeBox_sample_text( MP4_Box_t *p_box )
-{
- free( p_box->data.p_sample_text->psz_text_name );
-}
-#endif
-
static void MP4_FreeBox_stsz( MP4_Box_t *p_box )
{
free( p_box->data.p_stsz->i_entry_size );
@@ -4299,10 +4230,9 @@ static int MP4_ReadBox_default( stream_t *p_stream, MP4_Box_t *p_box )
case ATOM_hint:
return MP4_ReadBox_sample_hint8( p_stream, p_box );
case ATOM_text:
- return MP4_ReadBox_sample_text( p_stream, p_box );
case ATOM_tx3g:
case ATOM_sbtl:
- return MP4_ReadBox_sample_tx3g( p_stream, p_box );
+ return MP4_ReadBox_sample_text( p_stream, p_box );
default:
msg_Warn( p_stream,
"unknown handler type in stsd (incompletely loaded)" );
@@ -4478,7 +4408,8 @@ static const struct
{ ATOM_binm, MP4_ReadBoxSkip, 0 },
/* Subtitles */
- { ATOM_tx3g, MP4_ReadBox_sample_tx3g, 0 },
+ { ATOM_tx3g, MP4_ReadBox_sample_text, ATOM_sbtl },
+ { ATOM_tx3g, MP4_ReadBox_sample_text, ATOM_text },
{ ATOM_c608, MP4_ReadBox_sample_clcp, ATOM_stsd },
//{ ATOM_text, MP4_ReadBox_sample_text, 0 },
/* In sample WebVTT subtitle atoms. No ATOM_wvtt in normal parsing */
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index af1cc4a93d..dede4545d1 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -742,26 +742,9 @@ typedef struct
uint16_t i_data_reference_index;
- uint32_t i_display_flags; // TextDescription and Tx3gDescription
-
- int8_t i_justification_horizontal; // left(0), centered(1), right(-1)
- int8_t i_justification_vertical; // top(0), centered(1), bottom(-1)
-
- uint16_t i_background_color[4];
-
- uint16_t i_text_box_top;
- uint16_t i_text_box_left;
- uint16_t i_text_box_bottom;
- uint16_t i_text_box_right;
-
- uint32_t i_reserved3;
-
- uint16_t i_font_id;
- uint8_t i_font_face;
- uint8_t i_font_size;
- uint32_t i_font_color; //RGBA
+ uint8_t *p_data;
+ size_t i_data;
- // TODO to complete
} MP4_Box_data_sample_text_t;
typedef struct
More information about the vlc-commits
mailing list