Commit 3ee8ca9b authored by Aurelien Jacobs's avatar Aurelien Jacobs

add avcodec_get_subtitle_defaults() to initialize AVSubtitle struct

Call this new function before decode() to replace the custom and
inconsistant initialization in various decoders.
This function is equivalent to avcodec_get_frame_defaults() for AVFrame.
Signed-off-by: 's avatarAurelien Jacobs <aurel@gnuage.org>
parent c104a6e9
......@@ -62,11 +62,6 @@ int ff_ass_subtitle_header_default(AVCodecContext *avctx)
ASS_DEFAULT_ALIGNMENT);
}
void ff_ass_init(AVSubtitle *sub)
{
memset(sub, 0, sizeof(*sub));
}
static int ts_to_string(char *str, int strlen, int ts)
{
int h, m, s;
......
......@@ -69,13 +69,6 @@ int ff_ass_subtitle_header(AVCodecContext *avctx,
*/
int ff_ass_subtitle_header_default(AVCodecContext *avctx);
/**
* Initialize an AVSubtitle structure for use with ff_ass_add_rect().
*
* @param sub pointer to the AVSubtitle
*/
void ff_ass_init(AVSubtitle *sub);
/**
* Add an ASS dialog line to an AVSubtitle as a new AVSubtitleRect.
*
......
......@@ -38,8 +38,6 @@ static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
const char *ptr = avpkt->data;
int len, size = avpkt->size;
ff_ass_init(data);
while (size > 0) {
len = ff_ass_add_rect(data, ptr, 0, 0/* FIXME: duration */, 1);
if (len < 0)
......
......@@ -1323,10 +1323,7 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
int i;
int offset_x=0, offset_y=0;
sub->rects = NULL;
sub->start_display_time = 0;
sub->end_display_time = ctx->time_out * 1000;
sub->format = 0;
if (display_def) {
offset_x = display_def->x;
......
......@@ -173,7 +173,6 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header,
if (buf_size < 10)
return -1;
memset(sub_header, 0, sizeof(*sub_header));
if (AV_RB16(buf) == 0) { /* HD subpicture with 4-byte offsets */
big_offsets = 1;
......
......@@ -357,7 +357,6 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
* not been cleared by a subsequent empty display command.
*/
memset(sub, 0, sizeof(*sub));
// Blank if last object_number was 0.
// Note that this may be wrong for more complex subtitles.
if (!ctx->presentation.object_number)
......
......@@ -216,8 +216,6 @@ static int srt_decode_frame(AVCodecContext *avctx,
if (avpkt->size <= 0)
return avpkt->size;
ff_ass_init(sub);
while (ptr < end && *ptr) {
ptr = read_ts(ptr, &ts_start, &ts_end, &x1, &y1, &x2, &y2);
if (!ptr)
......
......@@ -474,6 +474,12 @@ AVFrame *avcodec_alloc_frame(void){
return pic;
}
static void avcodec_get_subtitle_defaults(AVSubtitle *sub)
{
memset(sub, 0, sizeof(*sub));
sub->pts = AV_NOPTS_VALUE;
}
int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
{
int ret= -1;
......@@ -795,6 +801,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
avctx->pkt = avpkt;
*got_sub_ptr = 0;
avcodec_get_subtitle_defaults(sub);
ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
if (*got_sub_ptr)
avctx->frame_number++;
......
......@@ -55,8 +55,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
int64_t packet_time = 0;
GetBitContext gb;
memset(sub, 0, sizeof(*sub));
// check that at least header fits
if (buf_size < 27 + 7 * 2 + 4 * 3) {
av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
......
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