[vlc-commits] mux: ts: fix service strings encoding
Francois Cartegnie
git at videolan.org
Mon Apr 25 16:08:24 CEST 2016
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Apr 25 15:53:19 2016 +0200| [d680ada88ae3405d89102dd750fab2d9cd0895aa] | committer: Francois Cartegnie
mux: ts: fix service strings encoding
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d680ada88ae3405d89102dd750fab2d9cd0895aa
---
modules/mux/mpeg/tables.c | 48 +++++++++++++++++++++++++++++++++------------
modules/mux/mpeg/tables.h | 4 ++--
modules/mux/mpeg/ts.c | 5 +++--
3 files changed, 41 insertions(+), 16 deletions(-)
diff --git a/modules/mux/mpeg/tables.c b/modules/mux/mpeg/tables.c
index 8ade82c..3813f75 100644
--- a/modules/mux/mpeg/tables.c
+++ b/modules/mux/mpeg/tables.c
@@ -323,6 +323,36 @@ static void UpdateServiceType( uint8_t *pi_service_cat, uint8_t *pi_service_type
}
}
+static inline size_t Write_AnnexA_String( uint8_t *p_dest, const char *p_src )
+{
+ size_t i_src;
+ if( p_src == NULL || !(i_src = strlen( p_src )) )
+ {
+ p_dest[0] = 0;
+ return 1;
+ }
+
+ bool b_latin = (p_src[0] > 0x20);
+ for ( size_t i=0; i< i_src && b_latin; i++ )
+ b_latin &= !( p_src[i] & 0x80 );
+
+ if( b_latin )
+ {
+ i_src = __MIN( i_src, UINT8_MAX );
+ p_dest[0] = i_src; /* Total size */
+ memcpy( &p_dest[1], p_src, i_src );
+ return 1 + i_src;
+ }
+ else
+ {
+ i_src = __MIN( i_src, UINT8_MAX - 1 );
+ p_dest[0] = 1 + i_src; /* Total size */
+ p_dest[1] = 0x15; /* UTF8 Encoding */
+ memcpy( &p_dest[2], p_src, i_src );
+ return 2 + i_src;
+ }
+}
+
void BuildPMT( dvbpsi_t *p_dvbpsi, vlc_object_t *p_object,
void *p_opaque, PEStoTSCallback pf_callback,
int i_tsid, int i_pmt_version_number,
@@ -535,25 +565,19 @@ void BuildPMT( dvbpsi_t *p_dvbpsi, vlc_object_t *p_object,
const char *psz_sdtprov = p_sdt->desc[i].psz_provider;
const char *psz_sdtserv = p_sdt->desc[i].psz_service_name;
- size_t i_prov = (psz_sdtprov) ? __MIN(255, strlen(psz_sdtprov)) : 0;
- size_t i_serv = (psz_sdtserv) ? __MIN(255, strlen(psz_sdtserv)) : 0;
-
- uint8_t psz_sdt_desc[4 + i_prov + i_serv];
+ uint8_t p_sdt_desc[4 + 255 * 2];
+ size_t i_sdt_desc = 0;
/* mapped service type according to es types */
- psz_sdt_desc[0] = pi_service_types[i];
+ p_sdt_desc[i_sdt_desc++] = pi_service_types[i];
/* service provider name length */
- psz_sdt_desc[1] = i_prov;
- memcpy( &psz_sdt_desc[2], psz_sdtprov, i_prov );
+ i_sdt_desc += Write_AnnexA_String( &p_sdt_desc[i_sdt_desc], psz_sdtprov );
/* service name length */
- psz_sdt_desc[ 2 + i_prov ] = i_serv;
- memcpy( &psz_sdt_desc[3+i_prov], psz_sdtserv, i_serv );
+ i_sdt_desc += Write_AnnexA_String( &p_sdt_desc[i_sdt_desc], psz_sdtserv );
- dvbpsi_sdt_service_descriptor_add( p_service, 0x48,
- (3 + i_prov + i_serv),
- psz_sdt_desc );
+ dvbpsi_sdt_service_descriptor_add( p_service, 0x48, i_sdt_desc, p_sdt_desc );
}
free( pi_service_types );
diff --git a/modules/mux/mpeg/tables.h b/modules/mux/mpeg/tables.h
index b302558..061ca5d 100644
--- a/modules/mux/mpeg/tables.h
+++ b/modules/mux/mpeg/tables.h
@@ -28,8 +28,8 @@ typedef struct
int i_netid;
struct
{
- char *psz_provider;
- char *psz_service_name; /* name of program */
+ char *psz_provider; /* provider in UTF8 */
+ char *psz_service_name; /* program in UTF8 */
} desc[MAX_SDT_DESC];
} sdt_psi_t;
diff --git a/modules/mux/mpeg/ts.c b/modules/mux/mpeg/ts.c
index f8e8447..00f769a 100644
--- a/modules/mux/mpeg/ts.c
+++ b/modules/mux/mpeg/ts.c
@@ -39,6 +39,7 @@
#include <vlc_sout.h>
#include <vlc_block.h>
#include <vlc_rand.h>
+#include <vlc_charset.h>
#include <vlc_iso_lang.h>
@@ -614,9 +615,9 @@ static int Open( vlc_object_t *p_this )
*psz_end++ = '\0';
if (i % 2)
- p_sys->sdt.desc[i/2].psz_service_name = strdup(psz_sdttoken);
+ p_sys->sdt.desc[i/2].psz_service_name = FromLocaleDup( psz_sdttoken );
else
- p_sys->sdt.desc[i/2].psz_provider = strdup(psz_sdttoken);
+ p_sys->sdt.desc[i/2].psz_provider = FromLocaleDup( psz_sdttoken );
psz_sdttoken = psz_end;
}
More information about the vlc-commits
mailing list