return 0;
}
-#define RGB_TO_BGR(c) ((c & 0xff) << 16 | (c & 0xff00) | ((c >> 16) & 0xff))
+#define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff))
-static void libaribb24_handle_regions(AVCodecContext *avctx, AVSubtitle *sub)
+static int libaribb24_handle_regions(AVCodecContext *avctx, AVSubtitle *sub)
{
Libaribb24Context *b24 = avctx->priv_data;
const arib_buf_region_t *region = arib_decoder_get_regions(b24->decoder);
unsigned int profile_font_size = get_profile_font_size(avctx->profile);
AVBPrint buf = { 0 };
+ int ret = 0;
av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
if (region_length < 0) {
av_log(avctx, AV_LOG_ERROR, "Invalid negative region length!\n");
+ ret = AVERROR_INVALIDDATA;
break;
}
// font size
if (region->i_fontwidth != profile_font_size ||
region->i_fontheight != profile_font_size) {
- av_bprintf(&buf, "{\\fscx%d\\fscy%d}",
- (int)round(((double)region->i_fontwidth /
- (double)profile_font_size) * 100),
- (int)round(((double)region->i_fontheight /
- (double)profile_font_size) * 100));
+ av_bprintf(&buf, "{\\fscx%"PRId64"\\fscy%"PRId64"}",
+ av_rescale(region->i_fontwidth, 100,
+ profile_font_size),
+ av_rescale(region->i_fontheight, 100,
+ profile_font_size));
}
// TODO: positioning
region = region->p_next;
}
- av_log(avctx, AV_LOG_DEBUG, "Styled ASS line: %s\n",
- buf.str);
- ff_ass_add_rect(sub, buf.str, b24->read_order++,
- 0, NULL, NULL);
+ if (!av_bprint_is_complete(&buf))
+ ret = AVERROR(ENOMEM);
+
+ if (ret == 0) {
+ av_log(avctx, AV_LOG_DEBUG, "Styled ASS line: %s\n",
+ buf.str);
+
+ ret = ff_ass_add_rect(sub, buf.str, b24->read_order++,
+ 0, NULL, NULL);
+ }
av_bprint_finalize(&buf, NULL);
+
+ return ret;
}
static int libaribb24_decode(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *pkt)
const unsigned char *parsed_data = NULL;
char *decoded_subtitle = NULL;
time_t subtitle_duration = 0;
+ int ret = 0;
if (pkt->size <= 0)
return pkt->size;
avctx->time_base.num, avctx->time_base.den);
if (decoded_subtitle)
- libaribb24_handle_regions(avctx, sub);
+ ret = libaribb24_handle_regions(avctx, sub);
*got_sub_ptr = sub->num_rects > 0;
// longer and longer...
arib_finalize_decoder(b24->decoder);
- return pkt->size;
+ return ret < 0 ? ret : pkt->size;
}
static void libaribb24_flush(AVCodecContext *avctx)
#define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
{ "aribb24-base-path", "set the base path for the libaribb24 library",
- OFFSET(aribb24_base_path), AV_OPT_TYPE_STRING, { 0 }, 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",
- OFFSET(aribb24_skip_ruby), AV_OPT_TYPE_BOOL, { 1 }, 0, 1, SD },
+ OFFSET(aribb24_skip_ruby), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, SD },
{ NULL }
};
.version = LIBAVUTIL_VERSION_INT,
};
-AVCodec ff_libaribb24_decoder = {
+const AVCodec ff_libaribb24_decoder = {
.name = "libaribb24",
.long_name = NULL_IF_CONFIG_SMALL("libaribb24 ARIB STD-B24 caption decoder"),
.type = AVMEDIA_TYPE_SUBTITLE,