aboutsummaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer2012-09-25 13:34:06 +0200
committerMichael Niedermayer2012-09-25 15:15:16 +0200
commit46a35959d8c17f7ae272ca158d05e047d31e736c (patch)
tree2a999b2c04b33514efea0e2f75917e83a45e36e3 /libavcodec
parent2089f933003b951b96b95e976bd34bbeffbd29f3 (diff)
parent7751e4693dd10ec98c20fbd9887233b575034272 (diff)
Merge commit '7751e4693dd10ec98c20fbd9887233b575034272'
* commit '7751e4693dd10ec98c20fbd9887233b575034272': ogg: check that the expected number of headers had been parsed libx264: change default to closed gop to match x264cli Use avcodec_free_frame() to free AVFrames. lavf: use a malloced AVFrame in try_decode_frame(). lavc: add avcodec_free_frame(). lavc: ensure extended_data is set properly on decoding lavc: initialize AVFrame.extended_data in avcodec_get_frame_defaults() lavc: use av_mallocz to allocate AVFrames. lavc: rename the argument of avcodec_alloc_frame/get_frame_defaults Conflicts: doc/APIchanges doc/examples/decoding_encoding.c libavcodec/utils.c libavcodec/version.h libavfilter/src_movie.c libavformat/oggdec.c libavformat/oggdec.h libavformat/oggparsetheora.c libavformat/utils.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/avcodec.h18
-rw-r--r--libavcodec/libx264.c1
-rw-r--r--libavcodec/utils.c67
-rw-r--r--libavcodec/version.h2
4 files changed, 69 insertions, 19 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 0d643478f6..f6522d1d1a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3509,7 +3509,7 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
/**
* Allocate an AVFrame and set its fields to default values. The resulting
- * struct can be deallocated by simply calling av_free().
+ * struct must be freed using avcodec_free_frame().
*
* @return An AVFrame filled with default values or NULL on failure.
* @see avcodec_get_frame_defaults
@@ -3519,9 +3519,21 @@ AVFrame *avcodec_alloc_frame(void);
/**
* Set the fields of the given AVFrame to default values.
*
- * @param pic The AVFrame of which the fields should be set to default values.
+ * @param frame The AVFrame of which the fields should be set to default values.
*/
-void avcodec_get_frame_defaults(AVFrame *pic);
+void avcodec_get_frame_defaults(AVFrame *frame);
+
+/**
+ * Free the frame and any dynamically allocated objects in it,
+ * e.g. extended_data.
+ *
+ * @param frame frame to be freed. The pointer will be set to NULL.
+ *
+ * @warning this function does NOT free the data buffers themselves
+ * (it does not know how, since they might have been allocated with
+ * a custom get_buffer()).
+ */
+void avcodec_free_frame(AVFrame **frame);
#if FF_API_AVCODEC_OPEN
/**
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 2c4ffa205a..d012c92a48 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -694,6 +694,7 @@ static const AVCodecDefault x264_defaults[] = {
{ "cmp", "-1" },
{ "threads", AV_STRINGIFY(X264_THREADS_AUTO) },
{ "thread_type", "0" },
+ { "flags", "+cgop" },
{ NULL },
};
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 79bfe1d355..b95b419955 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -695,31 +695,54 @@ enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum
return fmt[0];
}
-void avcodec_get_frame_defaults(AVFrame *pic)
+void avcodec_get_frame_defaults(AVFrame *frame)
{
- memset(pic, 0, sizeof(AVFrame));
+#if LIBAVCODEC_VERSION_MAJOR >= 55
+ // extended_data should explicitly be freed when needed, this code is unsafe currently
+ // also this is not compatible to the <55 ABI/API
+ if (frame->extended_data != frame->data && 0)
+ av_freep(&frame->extended_data);
+#endif
- pic->pts =
- pic->pkt_dts =
- pic->pkt_pts =
- pic->best_effort_timestamp = AV_NOPTS_VALUE;
- pic->pkt_duration = 0;
- pic->pkt_pos = -1;
- pic->key_frame = 1;
- pic->sample_aspect_ratio = (AVRational) {0, 1 };
- pic->format = -1; /* unknown */
+ memset(frame, 0, sizeof(AVFrame));
+
+ frame->pts =
+ frame->pkt_dts =
+ frame->pkt_pts =
+ frame->best_effort_timestamp = AV_NOPTS_VALUE;
+ frame->pkt_duration = 0;
+ frame->pkt_pos = -1;
+ frame->key_frame = 1;
+ frame->sample_aspect_ratio = (AVRational) {0, 1 };
+ frame->format = -1; /* unknown */
+ frame->extended_data = frame->data;
}
AVFrame *avcodec_alloc_frame(void)
{
- AVFrame *pic = av_malloc(sizeof(AVFrame));
+ AVFrame *frame = av_mallocz(sizeof(AVFrame));
- if (pic == NULL)
+ if (frame == NULL)
return NULL;
- avcodec_get_frame_defaults(pic);
+ avcodec_get_frame_defaults(frame);
- return pic;
+ return frame;
+}
+
+void avcodec_free_frame(AVFrame **frame)
+{
+ AVFrame *f;
+
+ if (!frame || !*frame)
+ return;
+
+ f = *frame;
+
+ if (f->extended_data != f->data)
+ av_freep(&f->extended_data);
+
+ av_freep(frame);
}
#define MAKE_ACCESSORS(str, name, type, field) \
@@ -1572,6 +1595,10 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
} else
ret = 0;
+ /* many decoders assign whole AVFrames, thus overwriting extended_data;
+ * make sure it's set correctly */
+ picture->extended_data = picture->data;
+
return ret;
}
@@ -1629,6 +1656,7 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
int *got_frame_ptr,
const AVPacket *avpkt)
{
+ int planar, channels;
int ret = 0;
*got_frame_ptr = 0;
@@ -1710,6 +1738,15 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
ret = avpkt->size;
}
}
+
+ /* many decoders assign whole AVFrames, thus overwriting extended_data;
+ * make sure it's set correctly; assume decoders that actually use
+ * extended_data are doing it correctly */
+ planar = av_sample_fmt_is_planar(frame->format);
+ channels = av_get_channel_layout_nb_channels(frame->channel_layout);
+ if (!(planar && channels > AV_NUM_DATA_POINTERS))
+ frame->extended_data = frame->data;
+
return ret;
}
diff --git a/libavcodec/version.h b/libavcodec/version.h
index c1d0b7669d..d96086a4a6 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -27,7 +27,7 @@
*/
#define LIBAVCODEC_VERSION_MAJOR 54
-#define LIBAVCODEC_VERSION_MINOR 58
+#define LIBAVCODEC_VERSION_MINOR 59
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \