[vlc-commits] atsc_a65.h : add simple UTF16 decoding through handle
Francois Cartegnie
git at videolan.org
Wed Feb 10 10:38:55 CET 2016
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Feb 5 16:12:26 2016 +0100| [9dd307f7a67331dcf277f9206e874c0b37e9e6fc] | committer: Francois Cartegnie
atsc_a65.h : add simple UTF16 decoding through handle
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9dd307f7a67331dcf277f9206e874c0b37e9e6fc
---
modules/codec/atsc_a65.c | 57 ++++++++++++++++++++++++++++++++++++++--------
modules/codec/atsc_a65.h | 1 +
2 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/modules/codec/atsc_a65.c b/modules/codec/atsc_a65.c
index 91aa3e5..66eb192 100644
--- a/modules/codec/atsc_a65.c
+++ b/modules/codec/atsc_a65.c
@@ -64,7 +64,8 @@ const uint8_t ATSC_A65_MODE_RESERVED_RANGES[12] = {
struct atsc_a65_handle_t
{
char *psz_lang;
- vlc_iconv_t iconv16;
+ vlc_iconv_t iconv_ucs2;
+ vlc_iconv_t iconv_u16be;
};
atsc_a65_handle_t *atsc_a65_handle_New( const char *psz_lang )
@@ -77,15 +78,18 @@ atsc_a65_handle_t *atsc_a65_handle_New( const char *psz_lang )
else
p_handle->psz_lang = NULL;
- p_handle->iconv16 = NULL;
+ p_handle->iconv_ucs2 = NULL;
+ p_handle->iconv_u16be = NULL;
}
return p_handle;
}
void atsc_a65_handle_Release( atsc_a65_handle_t *p_handle )
{
- if( p_handle->iconv16 )
- vlc_iconv_close( p_handle->iconv16 );
+ if( p_handle->iconv_ucs2 )
+ vlc_iconv_close( p_handle->iconv_ucs2 );
+ if( p_handle->iconv_u16be )
+ vlc_iconv_close( p_handle->iconv_u16be );
free( p_handle->psz_lang );
free( p_handle );
}
@@ -145,12 +149,12 @@ static bool convert_encoding_set( atsc_a65_handle_t *p_handle,
else if( i_mode > ATSC_A65_MODE_UNICODE_RANGE_START && /* 8 range prefix + 8 */
i_mode <= ATSC_A65_MODE_UNICODE_RANGE_END )
{
- if( !p_handle->iconv16 )
+ if( !p_handle->iconv_ucs2 )
{
- if ( !(p_handle->iconv16 = vlc_iconv_open("UTF-8", "UCS-2BE")) )
+ if ( !(p_handle->iconv_ucs2 = vlc_iconv_open("UTF-8", "UCS-2BE")) )
return false;
}
- else if ( VLC_ICONV_ERR == vlc_iconv( p_handle->iconv16, NULL, NULL, NULL, NULL ) ) /* reset */
+ else if ( VLC_ICONV_ERR == vlc_iconv( p_handle->iconv_ucs2, NULL, NULL, NULL, NULL ) ) /* reset */
{
return false;
}
@@ -166,8 +170,8 @@ static bool convert_encoding_set( atsc_a65_handle_t *p_handle,
const size_t i_outbuf_size = i_src * 4;
size_t i_inbuf_remain = i_src * 2;
size_t i_outbuf_remain = i_outbuf_size;
- b_ret = ( VLC_ICONV_ERR != vlc_iconv( p_handle->iconv16, &p_inbuf, &i_inbuf_remain,
- &p_outbuf, &i_outbuf_remain ) );
+ b_ret = ( VLC_ICONV_ERR != vlc_iconv( p_handle->iconv_ucs2, &p_inbuf, &i_inbuf_remain,
+ &p_outbuf, &i_outbuf_remain ) );
psz_dest = psz_realloc;
i_mergmin1 += (i_outbuf_size - i_outbuf_remain);
psz_dest[i_mergmin1 - 1] = 0;
@@ -246,3 +250,38 @@ error:
}
#undef BUF_ADVANCE
+
+char * atsc_a65_Decode_simple_UTF16_string( atsc_a65_handle_t *p_handle, const uint8_t *p_buffer, size_t i_buffer )
+{
+ if( i_buffer < 1 )
+ return NULL;
+
+ if( !p_handle->iconv_u16be )
+ {
+ if ( !(p_handle->iconv_u16be = vlc_iconv_open("UTF-8", "UTF-16BE")) )
+ return NULL;
+ }
+ else if ( VLC_ICONV_ERR == vlc_iconv( p_handle->iconv_u16be, NULL, NULL, NULL, NULL ) ) /* reset */
+ {
+ return NULL;
+ }
+
+ const size_t i_target_buffer = i_buffer * 3 / 2;
+ size_t i_target_remaining = i_target_buffer;
+ const char *psz_toconvert = (const char *) p_buffer;
+ char *psz_converted_end;
+ char *psz_converted = psz_converted_end = malloc( i_target_buffer );
+
+ if( unlikely(!psz_converted) )
+ return NULL;
+
+ if( VLC_ICONV_ERR == vlc_iconv( p_handle->iconv_u16be, &psz_toconvert, &i_buffer,
+ &psz_converted_end, &i_target_remaining ) )
+ {
+ free( psz_converted );
+ psz_converted = NULL;
+ }
+
+ psz_converted[ i_target_buffer - i_target_remaining - 1 ] = 0;
+ return psz_converted;
+}
diff --git a/modules/codec/atsc_a65.h b/modules/codec/atsc_a65.h
index 828c106..f9aea7a 100644
--- a/modules/codec/atsc_a65.h
+++ b/modules/codec/atsc_a65.h
@@ -27,6 +27,7 @@ atsc_a65_handle_t *atsc_a65_handle_New( const char *psz_lang );
void atsc_a65_handle_Release( atsc_a65_handle_t * );
char * atsc_a65_Decode_multiple_string( atsc_a65_handle_t *, const uint8_t *, size_t );
+char * atsc_a65_Decode_simple_UTF16_string( atsc_a65_handle_t *, const uint8_t *, size_t );
static inline time_t atsc_a65_GPSTimeToEpoch( time_t i_seconds, time_t i_gpstoepoch_leaptime_offset )
{
More information about the vlc-commits
mailing list