summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-03-20 11:43:20 +0100
committerMichael Niedermayer <michaelni@gmx.at>2013-03-20 11:43:29 +0100
commit54b0bef390edc0fbee91bf731bf0a686fadc9907 (patch)
tree3d9e0f8b46846f4bbe5bb288c633db74460a5725 /libavcodec
parentdf804041bd42d79b8cd01d7599c0d1f69c4027ee (diff)
parent4e70d66ded537cadd32dbd02a38c3d86a203c812 (diff)
Merge commit '4e70d66ded537cadd32dbd02a38c3d86a203c812'
* commit '4e70d66ded537cadd32dbd02a38c3d86a203c812': mpegvideo: fix allocation of the hwaccel_picture_private data lavc: update the doxy for avcodec_decode_{video,audio} wtih refcounting. Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/avcodec.h34
-rw-r--r--libavcodec/mpegvideo.c8
2 files changed, 28 insertions, 14 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index df1e247866..c3bd534ed7 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3628,11 +3628,17 @@ attribute_deprecated int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *s
*
* @param avctx the codec context
* @param[out] frame The AVFrame in which to store decoded audio samples.
- * Decoders request a buffer of a particular size by setting
- * AVFrame.nb_samples prior to calling get_buffer(). The
- * decoder may, however, only utilize part of the buffer by
- * setting AVFrame.nb_samples to a smaller value in the
- * output frame.
+ * The decoder will allocate a buffer for the decoded frame by
+ * calling the AVCodecContext.get_buffer2() callback.
+ * When AVCodecContext.refcounted_frames is set to 1, the frame is
+ * reference counted and the returned reference belongs to the
+ * caller. The caller must release the frame using av_frame_unref()
+ * when the frame is no longer needed. The caller may safely write
+ * to the frame if av_frame_is_writable() returns 1.
+ * When AVCodecContext.refcounted_frames is set to 0, the returned
+ * reference belongs to the decoder and is valid only until the
+ * next call to this function or until closing the decoder.
+ * The caller may not write to it.
* @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is
* non-zero.
* @param[in] avpkt The input AVPacket containing the input buffer.
@@ -3670,12 +3676,18 @@ int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
*
* @param avctx the codec context
* @param[out] picture The AVFrame in which the decoded video frame will be stored.
- * Use avcodec_alloc_frame to get an AVFrame, the codec will
- * allocate memory for the actual bitmap.
- * with default get/release_buffer(), the decoder frees/reuses the bitmap as it sees fit.
- * with overridden get/release_buffer() (needs CODEC_CAP_DR1) the user decides into what buffer the decoder
- * decodes and the decoder tells the user once it does not need the data anymore,
- * the user app can at this point free/reuse/keep the memory as it sees fit.
+ * Use av_frame_alloc() to get an AVFrame. The codec will
+ * allocate memory for the actual bitmap by calling the
+ * AVCodecContext.get_buffer2() callback.
+ * When AVCodecContext.refcounted_frames is set to 1, the frame is
+ * reference counted and the returned reference belongs to the
+ * caller. The caller must release the frame using av_frame_unref()
+ * when the frame is no longer needed. The caller may safely write
+ * to the frame if av_frame_is_writable() returns 1.
+ * When AVCodecContext.refcounted_frames is set to 0, the returned
+ * reference belongs to the decoder and is valid only until the
+ * next call to this function or until closing the decoder. The
+ * caller may not write to it.
*
* @param[in] avpkt The input AVpacket containing the input buffer.
* You can create such packet with av_init_packet() and by then setting
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index e4fa099acd..4c2ff80c51 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -269,11 +269,12 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
if (s->avctx->hwaccel) {
assert(!pic->hwaccel_picture_private);
if (s->avctx->hwaccel->priv_data_size) {
- pic->hwaccel_picture_private = av_mallocz(s->avctx->hwaccel->priv_data_size);
- if (!pic->hwaccel_picture_private) {
+ pic->hwaccel_priv_buf = av_buffer_allocz(s->avctx->hwaccel->priv_data_size);
+ if (!pic->hwaccel_priv_buf) {
av_log(s->avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n");
return -1;
}
+ pic->hwaccel_picture_private = pic->hwaccel_priv_buf->data;
}
}
@@ -293,7 +294,8 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
if (r < 0 || !pic->f.data[0]) {
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %p)\n",
r, pic->f.data[0]);
- av_freep(&pic->hwaccel_picture_private);
+ av_buffer_unref(&pic->hwaccel_priv_buf);
+ pic->hwaccel_picture_private = NULL;
return -1;
}