Commit 9a4b3182 authored by rcombs's avatar rcombs

lavc/libaribb24: add default_profile option

This allows decoding of streams that don't have a profile tagged
(e.g. ones that were remuxed improperly).
parent 84fe53f6
...@@ -40,10 +40,18 @@ typedef struct Libaribb24Context { ...@@ -40,10 +40,18 @@ typedef struct Libaribb24Context {
char *aribb24_base_path; char *aribb24_base_path;
unsigned int aribb24_skip_ruby; unsigned int aribb24_skip_ruby;
int default_profile;
} Libaribb24Context; } Libaribb24Context;
static unsigned int get_profile_font_size(int profile) static unsigned int get_profile_font_size(AVCodecContext *avctx)
{ {
Libaribb24Context *b24 = avctx->priv_data;
int profile = avctx->profile;
if (profile == FF_PROFILE_UNKNOWN)
profile = b24->default_profile;
switch (profile) { switch (profile) {
case FF_PROFILE_ARIB_PROFILE_A: case FF_PROFILE_ARIB_PROFILE_A:
return 36; return 36;
...@@ -61,26 +69,31 @@ static void libaribb24_log(void *p, const char *msg) ...@@ -61,26 +69,31 @@ static void libaribb24_log(void *p, const char *msg)
static int libaribb24_generate_ass_header(AVCodecContext *avctx) static int libaribb24_generate_ass_header(AVCodecContext *avctx)
{ {
Libaribb24Context *b24 = avctx->priv_data;
unsigned int plane_width = 0; unsigned int plane_width = 0;
unsigned int plane_height = 0; unsigned int plane_height = 0;
unsigned int font_size = 0; unsigned int font_size = 0;
int profile = avctx->profile;
switch (avctx->profile) { if (profile == FF_PROFILE_UNKNOWN)
profile = b24->default_profile;
switch (profile) {
case FF_PROFILE_ARIB_PROFILE_A: case FF_PROFILE_ARIB_PROFILE_A:
plane_width = 960; plane_width = 960;
plane_height = 540; plane_height = 540;
font_size = get_profile_font_size(avctx->profile);
break; break;
case FF_PROFILE_ARIB_PROFILE_C: case FF_PROFILE_ARIB_PROFILE_C:
plane_width = 320; plane_width = 320;
plane_height = 180; plane_height = 180;
font_size = get_profile_font_size(avctx->profile);
break; break;
default: default:
av_log(avctx, AV_LOG_ERROR, "Unknown or unsupported profile set!\n"); av_log(avctx, AV_LOG_ERROR, "Unknown or unsupported profile set!\n");
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
font_size = get_profile_font_size(avctx);
avctx->subtitle_header = av_asprintf( avctx->subtitle_header = av_asprintf(
"[Script Info]\r\n" "[Script Info]\r\n"
"; Script generated by FFmpeg/Lavc%s\r\n" "; Script generated by FFmpeg/Lavc%s\r\n"
...@@ -135,6 +148,7 @@ static int libaribb24_init(AVCodecContext *avctx) ...@@ -135,6 +148,7 @@ static int libaribb24_init(AVCodecContext *avctx)
Libaribb24Context *b24 = avctx->priv_data; Libaribb24Context *b24 = avctx->priv_data;
void(* arib_dec_init)(arib_decoder_t* decoder) = NULL; void(* arib_dec_init)(arib_decoder_t* decoder) = NULL;
int ret_code = AVERROR_EXTERNAL; int ret_code = AVERROR_EXTERNAL;
int profile = avctx->profile;
if (!(b24->lib_instance = arib_instance_new(avctx))) { if (!(b24->lib_instance = arib_instance_new(avctx))) {
av_log(avctx, AV_LOG_ERROR, "Failed to initialize libaribb24!\n"); av_log(avctx, AV_LOG_ERROR, "Failed to initialize libaribb24!\n");
...@@ -158,7 +172,10 @@ static int libaribb24_init(AVCodecContext *avctx) ...@@ -158,7 +172,10 @@ static int libaribb24_init(AVCodecContext *avctx)
goto init_fail; goto init_fail;
} }
switch (avctx->profile) { if (profile == FF_PROFILE_UNKNOWN)
profile = b24->default_profile;
switch (profile) {
case FF_PROFILE_ARIB_PROFILE_A: case FF_PROFILE_ARIB_PROFILE_A:
arib_dec_init = arib_initialize_decoder_a_profile; arib_dec_init = arib_initialize_decoder_a_profile;
break; break;
...@@ -209,7 +226,7 @@ static int libaribb24_handle_regions(AVCodecContext *avctx, AVSubtitle *sub) ...@@ -209,7 +226,7 @@ static int libaribb24_handle_regions(AVCodecContext *avctx, AVSubtitle *sub)
{ {
Libaribb24Context *b24 = avctx->priv_data; Libaribb24Context *b24 = avctx->priv_data;
const arib_buf_region_t *region = arib_decoder_get_regions(b24->decoder); const arib_buf_region_t *region = arib_decoder_get_regions(b24->decoder);
unsigned int profile_font_size = get_profile_font_size(avctx->profile); unsigned int profile_font_size = get_profile_font_size(avctx);
AVBPrint buf = { 0 }; AVBPrint buf = { 0 };
int ret = 0; int ret = 0;
...@@ -371,6 +388,10 @@ static const AVOption options[] = { ...@@ -371,6 +388,10 @@ static const AVOption options[] = {
OFFSET(aribb24_base_path), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, SD }, OFFSET(aribb24_base_path), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, SD },
{ "aribb24-skip-ruby-text", "skip ruby text blocks during decoding", { "aribb24-skip-ruby-text", "skip ruby text blocks during decoding",
OFFSET(aribb24_skip_ruby), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, SD }, OFFSET(aribb24_skip_ruby), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, SD },
{ "default_profile", "default profile to use if not specified in the stream parameters",
OFFSET(default_profile), AV_OPT_TYPE_INT, { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, FF_PROFILE_ARIB_PROFILE_C, SD, "profile" },
{"a", "Profile A", 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_ARIB_PROFILE_A}, INT_MIN, INT_MAX, SD, "profile"},
{"c", "Profile C", 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_ARIB_PROFILE_C}, INT_MIN, INT_MAX, SD, "profile"},
{ NULL } { NULL }
}; };
......
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