Commit c490aa52 authored by Laurent Aimar's avatar Laurent Aimar

* mp4: support for tx3g subtitle (close #332)

parent e76d87b9
...@@ -1280,46 +1280,90 @@ static int MP4_ReadBox_sample_mp4s( stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -1280,46 +1280,90 @@ static int MP4_ReadBox_sample_mp4s( stream_t *p_stream, MP4_Box_t *p_box )
static int MP4_ReadBox_sample_text( stream_t *p_stream, MP4_Box_t *p_box ) static int MP4_ReadBox_sample_text( stream_t *p_stream, MP4_Box_t *p_box )
{ {
unsigned int i; unsigned int i;
int32_t t;
MP4_READBOX_ENTER( MP4_Box_data_sample_text_t ); MP4_READBOX_ENTER( MP4_Box_data_sample_text_t );
for( i = 0; i < 6 ; i++ ) MP4_GET4BYTES( p_box->data.p_sample_text->i_reserved1 );
{ MP4_GET2BYTES( p_box->data.p_sample_text->i_reserved2 );
MP4_GET1BYTE( p_box->data.p_sample_text->i_reserved1[i] );
}
MP4_GET2BYTES( p_box->data.p_sample_text->i_data_reference_index ); 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( p_box->data.p_sample_text->i_display_flags );
MP4_GET4BYTES( p_box->data.p_sample_text->i_justification );
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;
}
MP4_GET2BYTES( p_box->data.p_sample_text->i_background_color[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[1] );
MP4_GET2BYTES( p_box->data.p_sample_text->i_background_color[2] ); MP4_GET2BYTES( p_box->data.p_sample_text->i_background_color[2] );
p_box->data.p_sample_text->i_background_color[3] = 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 );
#ifdef MP4_VERBOSE
msg_Dbg( p_stream, "read box: \"text\" in stsd text" );
#endif
MP4_READBOX_EXIT( 1 );
}
MP4_GET8BYTES( p_box->data.p_sample_text->i_text_box ); static int MP4_ReadBox_sample_tx3g( stream_t *p_stream, MP4_Box_t *p_box )
MP4_GET8BYTES( p_box->data.p_sample_text->i_reserved2 ); {
unsigned int i;
int32_t t;
MP4_GET2BYTES( p_box->data.p_sample_text->i_font_number ); MP4_READBOX_ENTER( MP4_Box_data_sample_text_t );
MP4_GET2BYTES( p_box->data.p_sample_text->i_font_face );
MP4_GET2BYTES( p_box->data.p_sample_text->i_reserved3 ); 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_foreground_color[0] ); MP4_GET2BYTES( p_box->data.p_sample_text->i_data_reference_index );
MP4_GET2BYTES( p_box->data.p_sample_text->i_foreground_color[1] );
MP4_GET2BYTES( p_box->data.p_sample_text->i_foreground_color[2] ); MP4_GET4BYTES( p_box->data.p_sample_text->i_display_flags );
MP4_GET1BYTE( i ); MP4_GET1BYTE ( p_box->data.p_sample_text->i_justification_horizontal );
p_box->data.p_sample_text->psz_text_name = malloc( i + 1 ); MP4_GET1BYTE ( p_box->data.p_sample_text->i_justification_vertical );
memcpy( p_box->data.p_sample_text->psz_text_name, p_peek, i );
p_box->data.p_sample_text->psz_text_name[i] = '\0'; 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 );
#ifdef MP4_VERBOSE #ifdef MP4_VERBOSE
msg_Dbg( p_stream, "read box: \"text\" in stsd text name=%s", msg_Dbg( p_stream, "read box: \"text\" in stsd text" );
p_box->data.p_sample_text->psz_text_name );
#endif #endif
MP4_READBOX_EXIT( 1 ); MP4_READBOX_EXIT( 1 );
} }
#if 0 #if 0
/* We can't easily call it, and anyway ~ 20 bytes lost isn't a real problem */ /* 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 ) static void MP4_FreeBox_sample_text( MP4_Box_t *p_box )
...@@ -2066,6 +2110,8 @@ static int MP4_ReadBox_default( stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -2066,6 +2110,8 @@ static int MP4_ReadBox_default( stream_t *p_stream, MP4_Box_t *p_box )
return MP4_ReadBox_sample_vide( p_stream, p_box ); return MP4_ReadBox_sample_vide( p_stream, p_box );
case FOURCC_text: case FOURCC_text:
return MP4_ReadBox_sample_text( p_stream, p_box ); return MP4_ReadBox_sample_text( p_stream, p_box );
case FOURCC_tx3g:
return MP4_ReadBox_sample_tx3g( p_stream, p_box );
default: default:
msg_Warn( p_stream, msg_Warn( p_stream,
"unknown handler type in stsd (uncompletetly loaded)" ); "unknown handler type in stsd (uncompletetly loaded)" );
......
...@@ -178,6 +178,7 @@ ...@@ -178,6 +178,7 @@
#define FOURCC_priv VLC_FOURCC( 'p', 'r', 'i', 'v' ) #define FOURCC_priv VLC_FOURCC( 'p', 'r', 'i', 'v' )
#define FOURCC_text VLC_FOURCC( 't', 'e', 'x', 't' ) #define FOURCC_text VLC_FOURCC( 't', 'e', 'x', 't' )
#define FOURCC_tx3g VLC_FOURCC( 't', 'x', '3', 'g' )
#define FOURCC_subp VLC_FOURCC( 's', 'u', 'b', 'p' ) #define FOURCC_subp VLC_FOURCC( 's', 'u', 'b', 'p' )
#define FOURCC_0xa9nam VLC_FOURCC( 0xa9, 'n', 'a', 'm' ) #define FOURCC_0xa9nam VLC_FOURCC( 0xa9, 'n', 'a', 'm' )
...@@ -458,23 +459,45 @@ typedef struct MP4_Box_data_sample_vide_s ...@@ -458,23 +459,45 @@ typedef struct MP4_Box_data_sample_vide_s
} MP4_Box_data_sample_vide_t; } MP4_Box_data_sample_vide_t;
#define MP4_TEXT_DISPLAY_FLAG_DONT_DISPLAY (1<<0)
#define MP4_TEXT_DISPLAY_FLAG_AUTO_SCALE (1<<1)
#define MP4_TEXT_DISPLAY_FLAG_CLIP_TO_TEXT_BOX (1<<2)
#define MP4_TEXT_DISPLAY_FLAG_USE_MOVIE_BG_COLOR (1<<3)
#define MP4_TEXT_DISPLAY_FLAG_SHRINK_TEXT_BOX_TO_FIT (1<<4)
#define MP4_TEXT_DISPLAY_FLAG_SCROLL_IN (1<<5)
#define MP4_TEXT_DISPLAY_FLAG_SCROLL_OUT (1<<6)
#define MP4_TEXT_DISPLAY_FLAG_HORIZONTAL_SCROLL (1<<7)
#define MP4_TEXT_DISPLAY_FLAG_REVERSE_SCROLL (1<<8)
#define MP4_TEXT_DISPLAY_FLAG_CONTINUOUS_SCROLL (1<<9)
#define MP4_TEXT_DISPLAY_FLAG_FLOW_HORIZONTAL (1<<10)
#define MP4_TEXT_DISPLAY_FLAG_CONTINUOUS_KARAOKE (1<<11)
#define MP4_TEXT_DISPLAY_FLAG_DROP_SHADOW (1<<12)
#define MP4_TEXT_DISPLAY_FLAG_ANTI_ALIAS (1<<13)
#define MP4_TEXT_DISPLAY_FLAG_KEYED_TEXT (1<<14)
#define MP4_TEXT_DISPLAY_FLAG_INVERSE_HILITE (1<<15)
#define MP4_TEXT_DISPLAY_FLAG_COLOR_HILITE (1<<16)
#define MP4_TEXT_DISPLAY_FLAG_WRITE_VERTICALLY (1<<17)
typedef struct typedef struct
{ {
uint8_t i_reserved1[6]; uint32_t i_reserved1;
uint16_t i_reserved2;
uint16_t i_data_reference_index; uint16_t i_data_reference_index;
uint32_t i_display_flags; uint32_t i_display_flags; // TextDescription and Tx3gDescription
uint32_t i_justification;
uint16_t i_background_color[3]; int8_t i_justification_horizontal; // left(0), centered(1), right(-1)
uint64_t i_text_box; int8_t i_justification_vertical; // top(0), centered(1), bottom(-1)
uint64_t i_reserved2;
uint16_t i_font_number; uint16_t i_background_color[4];
uint16_t i_font_face;
uint16_t i_reserved3;
uint16_t i_foreground_color[3]; uint16_t i_text_box_top;
uint16_t i_text_box_left;
uint16_t i_text_box_bottom;
uint16_t i_text_box_right;
char *psz_text_name; // TODO to complete
} MP4_Box_data_sample_text_t; } MP4_Box_data_sample_text_t;
typedef struct MP4_Box_data_sample_hint_s typedef struct MP4_Box_data_sample_hint_s
......
...@@ -1278,6 +1278,7 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track, ...@@ -1278,6 +1278,7 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
break; break;
case( VLC_FOURCC( 't', 'e', 'x', 't' ) ): case( VLC_FOURCC( 't', 'e', 'x', 't' ) ):
case( VLC_FOURCC( 't', 'x', '3', 'g' ) ):
p_track->fmt.i_codec = VLC_FOURCC( 's', 'u', 'b', 't' ); p_track->fmt.i_codec = VLC_FOURCC( 's', 'u', 'b', 't' );
/* FIXME: Not true, could be UTF-16 with a Byte Order Mark (0xfeff) */ /* FIXME: Not true, could be UTF-16 with a Byte Order Mark (0xfeff) */
/* FIXME UTF-8 doesn't work here ? */ /* FIXME UTF-8 doesn't work here ? */
...@@ -1777,6 +1778,7 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track, ...@@ -1777,6 +1778,7 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track,
case( FOURCC_text ): case( FOURCC_text ):
case( FOURCC_subp ): case( FOURCC_subp ):
case( FOURCC_tx3g ):
p_track->fmt.i_cat = SPU_ES; p_track->fmt.i_cat = SPU_ES;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment