Skip to content

Commit

Permalink
[WIP] lavf/mpegts: use aribb24 to decode service names if demuxed as …
Browse files Browse the repository at this point in the history
…ARIB

The helper stuff should be moved to a separate aribb24 specific
file, but I am a lazy git for now.
  • Loading branch information
jeeb committed Apr 28, 2018
1 parent deaf00f commit 5c225ac
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ External library support:
--enable-jni enable JNI support [no]
--enable-ladspa enable LADSPA audio filtering [no]
--enable-libaom enable AV1 video encoding/decoding via libaom [no]
--enable-libaribb24 enable ARIB decoding via libaribb24 [no]
--enable-libass enable libass subtitles rendering,
needed for subtitles and ass filter [no]
--enable-libbluray enable BluRay reading using libbluray [no]
Expand Down Expand Up @@ -1672,6 +1673,7 @@ EXTERNAL_LIBRARY_LIST="
jni
ladspa
libaom
libaribb24
libass
libbluray
libbs2b
Expand Down Expand Up @@ -3134,6 +3136,7 @@ mp3_demuxer_select="mpegaudio_parser"
mp3_muxer_select="mpegaudioheader"
mp4_muxer_select="mov_muxer"
mpegts_demuxer_select="iso_media"
mpegts_demuxer_suggest="libaribb24"
mpegts_muxer_select="adts_muxer latm_muxer"
mpegtsraw_demuxer_select="mpegts_demuxer"
mxf_d10_muxer_select="mxf_muxer"
Expand Down Expand Up @@ -5962,6 +5965,7 @@ enabled gnutls && require_pkg_config gnutls gnutls gnutls/gnutls.h gn
enabled jni && { [ $target_os = "android" ] && check_header jni.h && enabled pthreads || die "ERROR: jni not found"; }
enabled ladspa && require_header ladspa.h
enabled libaom && require_pkg_config libaom "aom >= 0.1.0" aom/aom_codec.h aom_codec_version
enabled libaribb24 && require_pkg_config libaribb24 aribb24 "aribb24/aribb24.h" arib_instance_new
enabled lv2 && require_pkg_config lv2 lilv-0 "lilv-0/lilv/lilv.h" lilv_world_new
enabled libiec61883 && require libiec61883 libiec61883/iec61883.h iec61883_cmp_connect -lraw1394 -lavc1394 -lrom1394 -liec61883
enabled libass && require_pkg_config libass libass ass/ass.h ass_library_init
Expand Down
57 changes: 57 additions & 0 deletions libavformat/mpegts.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
#include "mpeg.h"
#include "isom.h"

#if CONFIG_LIBARIBB24
#include <aribb24/aribb24.h>
#include <aribb24/decoder.h>
#endif

/* maximum size in which we look for synchronization if
* synchronization is lost */
#define MAX_RESYNC_SIZE 65536
Expand Down Expand Up @@ -158,6 +163,10 @@ struct MpegTSContext {

enum MpegTSMode demux_mode;

#if CONFIG_LIBARIBB24
arib_instance_t *arib_helper_instance;
#endif

/******************************************/
/* private mpegts data */
/* scan context */
Expand Down Expand Up @@ -266,6 +275,33 @@ typedef struct PESContext {

extern AVInputFormat ff_mpegts_demuxer;

#if CONFIG_LIBARIBB24
// decode JIS 8-bit character to UTF-8 characters.
static char* decode_aribstring( arib_instance_t *p_instance, const unsigned char *psz_instring)
{
if( !psz_instring )
{
return NULL;
}
size_t i_in = strlen( (const char*)psz_instring );

arib_decoder_t *p_decoder = arib_get_decoder( p_instance );
if ( !p_decoder )
return NULL;

size_t i_out = i_in * 4;
char *psz_outstring = (char*) calloc( i_out + 1, sizeof(char) );

arib_initialize_decoder( p_decoder );
i_out = arib_decode_buffer( p_decoder,
psz_instring, i_in,
psz_outstring, i_out );
arib_finalize_decoder( p_decoder );

return psz_outstring;
}
#endif

static struct Program * get_program(MpegTSContext *ts, unsigned int programid)
{
int i;
Expand Down Expand Up @@ -2331,6 +2367,17 @@ static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
break;
name = getstr8(&p, p_end);
if (name) {
#if CONFIG_LIBARIBB24
char *arib_name = NULL;

if (ts->demux_mode == MPEGTS_MODE_ARIB &&
(arib_name = decode_aribstring(ts->arib_helper_instance,
name))) {
av_free(name);
name = arib_name;
}
#endif

AVProgram *program = av_new_program(ts->stream, sid);
if (program) {
av_dict_set(&program->metadata, "service_name", name, 0);
Expand Down Expand Up @@ -2731,6 +2778,13 @@ static int mpegts_read_header(AVFormatContext *s)
int len;
int64_t pos, probesize = s->probesize;

#if CONFIG_LIBARIBB24
if (!(ts->arib_helper_instance = arib_instance_new(NULL))) {
av_log(s, AV_LOG_ERROR, "Failed to allocate ARIB helper!\n");
return AVERROR(ENOMEM);
}
#endif

s->internal->prefer_codec_framerate = 1;

if (ffio_ensure_seekback(pb, probesize) < 0)
Expand Down Expand Up @@ -2924,6 +2978,9 @@ static void mpegts_free(MpegTSContext *ts)
static int mpegts_read_close(AVFormatContext *s)
{
MpegTSContext *ts = s->priv_data;
#if CONFIG_LIBARIBB24
arib_instance_destroy(ts->arib_helper_instance);
#endif
mpegts_free(ts);
return 0;
}
Expand Down

0 comments on commit 5c225ac

Please sign in to comment.