[FFmpeg-devel] [PATCH] add avcodec_get_subtitle_defaults() to initialize AVSubtitle struct
Aurelien Jacobs
aurel at gnuage.org
Tue Apr 5 10:04:33 CEST 2011
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: Aurelien Jacobs <aurel at gnuage.org>
---
libavcodec/ass.c | 5 -----
libavcodec/ass.h | 7 -------
libavcodec/assdec.c | 2 --
libavcodec/avcodec.h | 7 +++++++
libavcodec/dvbsubdec.c | 3 ---
libavcodec/dvdsubdec.c | 1 -
libavcodec/pgssubdec.c | 1 -
libavcodec/srtdec.c | 2 --
libavcodec/utils.c | 7 +++++++
libavcodec/version.h | 2 +-
libavcodec/xsubdec.c | 2 --
11 files changed, 15 insertions(+), 24 deletions(-)
diff --git a/libavcodec/ass.c b/libavcodec/ass.c
index 7553bf0..a23567c 100644
--- a/libavcodec/ass.c
+++ b/libavcodec/ass.c
@@ -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;
diff --git a/libavcodec/ass.h b/libavcodec/ass.h
index e04b4cc..74ef61b 100644
--- a/libavcodec/ass.h
+++ b/libavcodec/ass.h
@@ -70,13 +70,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.
*
* @param sub pointer to the AVSubtitle
diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c
index c1ad0c4..024127a 100644
--- a/libavcodec/assdec.c
+++ b/libavcodec/assdec.c
@@ -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)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 4659719..e063cb1 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3655,6 +3655,13 @@ void avcodec_get_frame_defaults(AVFrame *pic);
*/
AVFrame *avcodec_alloc_frame(void);
+/**
+ * Set the fields of the given AVSubtitle to default values.
+ *
+ * @param sub AVSubtitle of which the fields should be set to default values
+ */
+void avcodec_get_subtitle_defaults(AVSubtitle *sub);
+
int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index 4573713..288e6f5 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -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;
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 507c181..bb3e124 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -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;
diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index 3cc2e66..a91cfe7 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -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)
diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
index 701100a..aa73f4c 100644
--- a/libavcodec/srtdec.c
+++ b/libavcodec/srtdec.c
@@ -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)
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 42689e0..309c763 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -469,6 +469,12 @@ AVFrame *avcodec_alloc_frame(void){
return pic;
}
+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;
@@ -790,6 +796,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++;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 9d211b9..bea84d0 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -21,7 +21,7 @@
#define AVCODEC_VERSION_H
#define LIBAVCODEC_VERSION_MAJOR 52
-#define LIBAVCODEC_VERSION_MINOR 117
+#define LIBAVCODEC_VERSION_MINOR 118
#define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index d24588b..a577ac8 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -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");
--
1.7.4.1
More information about the ffmpeg-devel
mailing list