[vlc-devel] [PATCH 5/5] demux: mp4: add support for tx3g (fix #8305)

Francois Cartegnie fcvlcdev at free.fr
Sat Mar 22 07:15:15 CET 2014


---
 modules/demux/mp4/libmp4.c | 13 +++++++++-
 modules/demux/mp4/libmp4.h |  7 ++++++
 modules/demux/mp4/mp4.c    | 61 +++++++++++++++++++++++-----------------------
 3 files changed, 50 insertions(+), 31 deletions(-)

diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 1357f44..50f77a6 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -1842,7 +1842,7 @@ static int MP4_ReadBox_sample_text( stream_t *p_stream, MP4_Box_t *p_box )
     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] = 0;
+    p_box->data.p_sample_text->i_background_color[3] = 0xFF;
 
     MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_top );
     MP4_GET2BYTES( p_box->data.p_sample_text->i_text_box_left );
@@ -1879,6 +1879,13 @@ static int MP4_ReadBox_sample_tx3g( stream_t *p_stream, MP4_Box_t *p_box )
     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
@@ -3218,6 +3225,10 @@ static const struct
     { ATOM_free,    MP4_ReadBoxSkip,          MP4_FreeBox_Common },
     { ATOM_wide,    MP4_ReadBoxSkip,          MP4_FreeBox_Common },
 
+    /* Subtitles */
+    { ATOM_tx3g,    MP4_ReadBox_sample_tx3g,      MP4_FreeBox_Common },
+    //{ ATOM_text,    MP4_ReadBox_sample_text,      MP4_FreeBox_Common },
+
     /* for codecs */
     { ATOM_soun,    MP4_ReadBox_sample_soun,  MP4_FreeBox_sample_soun },
     { ATOM_ms02,    MP4_ReadBox_sample_soun,  MP4_FreeBox_sample_soun },
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index c430f22..3f539ec 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -580,6 +580,13 @@ typedef struct
     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
+
     // TODO to complete
 } MP4_Box_data_sample_text_t;
 
diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index 7ac64e2..9523ec6 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -753,36 +753,12 @@ static int Demux( demux_t *p_demux )
                     MP4_TrackUnselect( p_demux, tk );
                     break;
                 }
-
                 else if( tk->fmt.i_cat == SPU_ES )
                 {
-                    if( tk->fmt.i_codec == VLC_CODEC_SUBT &&
-                        p_block->i_buffer >= 2 )
-                    {
-                        size_t i_size = GetWBE( p_block->p_buffer );
-
-                        if( i_size + 2 <= p_block->i_buffer )
-                        {
-                            char *p;
-                            /* remove the length field, and append a '\0' */
-                            memmove( &p_block->p_buffer[0],
-                                     &p_block->p_buffer[2], i_size );
-                            p_block->p_buffer[i_size] = '\0';
-                            p_block->i_buffer = i_size + 1;
-
-                            /* convert \r -> \n */
-                            while( ( p = strchr((char *) p_block->p_buffer, '\r' ) ) )
-                            {
-                                *p = '\n';
-                            }
-                        }
-                        else
-                        {
-                            /* Invalid */
-                            p_block->i_buffer = 0;
-                        }
-                    }
+                    if ( tk->fmt.i_codec != VLC_CODEC_TX3G )
+                        p_block->i_buffer = 0;
                 }
+
                 /* dts */
                 p_block->i_dts = VLC_TS_0 + MP4_TrackGetDTS( p_demux, tk );
                 /* pts */
@@ -1910,7 +1886,31 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
 
         case( VLC_FOURCC( 't', 'e', 'x', 't' ) ):
         case( VLC_FOURCC( 't', 'x', '3', 'g' ) ):
-            p_track->fmt.i_codec = VLC_CODEC_SUBT;
+        {
+            p_track->fmt.i_codec = VLC_CODEC_TX3G;
+            MP4_Box_data_sample_text_t *p_text = p_sample->data.p_sample_text;
+            if ( p_text )
+            {
+                text_style_t *p_style = text_style_New();
+                if ( p_style )
+                {
+                    if ( p_text->i_font_size ) /* !WARN: % in absolute storage */
+                        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;
+                    }
+                    if ( p_text->i_background_color )
+                    {
+                        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_track->fmt.subs.p_style = p_style;
+            }
             /* FIXME: Not true, could be UTF-16 with a Byte Order Mark (0xfeff) */
             /* FIXME UTF-8 doesn't work here ? */
             if( p_track->b_mac_encoding )
@@ -1918,7 +1918,7 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
             else
                 p_track->fmt.subs.psz_encoding = strdup( "UTF-8" );
             break;
-
+        }
         case VLC_FOURCC('y','v','1','2'):
             p_track->fmt.i_codec = VLC_CODEC_YV12;
             break;
@@ -2571,10 +2571,11 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track,
             p_track->fmt.i_cat = VIDEO_ES;
             break;
 
+        case( ATOM_tx3g ):
         case( ATOM_text ):
         case( ATOM_subp ):
-        case( ATOM_tx3g ):
         case( ATOM_sbtl ):
+            p_track->fmt.i_codec = VLC_CODEC_TX3G;
             p_track->fmt.i_cat = SPU_ES;
             break;
 
-- 
1.8.5.3




More information about the vlc-devel mailing list