Commit c3c6e9b8 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: mp4: handle in sample text encoding (fix #11137)

parent edb0f284
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <vlc_plugin.h> #include <vlc_plugin.h>
#include <vlc_codec.h> #include <vlc_codec.h>
#include <vlc_sout.h> #include <vlc_sout.h>
#include <vlc_charset.h>
#include "substext.h" #include "substext.h"
...@@ -255,14 +256,21 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block ) ...@@ -255,14 +256,21 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
uint8_t *p_buf = p_block->p_buffer; uint8_t *p_buf = p_block->p_buffer;
/* Read our raw string and create the styled segment for HTML */ /* Read our raw string and create the styled segment for HTML */
uint16_t i_psz_length = GetWBE( p_buf ); uint16_t i_psz_bytelength = GetWBE( p_buf );
char *psz_subtitle = malloc( i_psz_length + 1 ); const uint8_t *p_pszstart = p_block->p_buffer + sizeof(uint16_t);
char *psz_subtitle;
if ( i_psz_bytelength > 2 &&
( !memcmp( p_pszstart, "\xFE\xFF", 2 ) || !memcmp( p_pszstart, "\xFF\xFE", 2 ) )
)
psz_subtitle = FromCharset( "UTF-16", p_pszstart, i_psz_bytelength );
else
psz_subtitle = malloc( i_psz_bytelength + 1 );
if ( !psz_subtitle ) return NULL; if ( !psz_subtitle ) return NULL;
memcpy( psz_subtitle, p_block->p_buffer + sizeof(uint16_t), i_psz_length ); memcpy( psz_subtitle, p_pszstart, i_psz_bytelength );
psz_subtitle[ i_psz_length ] = '\0'; psz_subtitle[ i_psz_bytelength ] = '\0';
p_buf += i_psz_length + sizeof(uint16_t); p_buf += i_psz_bytelength + sizeof(uint16_t);
for( uint16_t i=0; i < i_psz_length; i++ ) for( uint16_t i=0; i < i_psz_bytelength; i++ )
if ( psz_subtitle[i] == '\r' ) psz_subtitle[i] = '\n'; if ( psz_subtitle[i] == '\r' ) psz_subtitle[i] = '\n';
segment_t *p_segment = calloc( 1, sizeof(segment_t) ); segment_t *p_segment = calloc( 1, sizeof(segment_t) );
...@@ -317,8 +325,8 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block ) ...@@ -317,8 +325,8 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
while( i_cur_record++ < i_nbrecords ) while( i_cur_record++ < i_nbrecords )
{ {
if ( (size_t)(p_buf - p_block->p_buffer) < 12 ) break; if ( (size_t)(p_buf - p_block->p_buffer) < 12 ) break;
uint16_t i_start = __MIN( GetWBE(p_buf), i_psz_length - 1 ); uint16_t i_start = __MIN( GetWBE(p_buf), i_psz_bytelength - 1 );
uint16_t i_end = __MIN( GetWBE(p_buf + 2), i_psz_length - 1 ); uint16_t i_end = __MIN( GetWBE(p_buf + 2), i_psz_bytelength - 1 );
segment_style_t style; segment_style_t style;
style.i_flags = ConvertFlags( p_buf[6] ); style.i_flags = ConvertFlags( p_buf[6] );
......
...@@ -2001,7 +2001,6 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track, ...@@ -2001,7 +2001,6 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
} }
p_track->fmt.subs.p_style = p_style; 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 ? */ /* FIXME UTF-8 doesn't work here ? */
if( p_track->b_mac_encoding ) if( p_track->b_mac_encoding )
p_track->fmt.subs.psz_encoding = strdup( "MAC" ); p_track->fmt.subs.psz_encoding = strdup( "MAC" );
......
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