Showing the changes to libavcodec (9 of 9 files). Show all
Unified · Split
| @@ -27,6 +27,7 @@ · 26 unmodified lines | ||
| 27 | 27 | #include "libavutil/opt.h" |
| 28 | 28 | #include "avcodec.h" |
| 29 | 29 | #include "av1_parse.h" |
| 30 | +#include "decode.h" | |
| 30 | 31 | #include "av1dec.h" |
| 31 | 32 | #include "atsc_a53.h" |
| 32 | 33 | #include "bytestream.h" |
| @@ -865,8 +866,7 @@ static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f) · 832 unmodified lines | ||
| 865 | 866 | if (avctx->hwaccel) { |
| 866 | 867 | const AVHWAccel *hwaccel = avctx->hwaccel; |
| 867 | 868 | if (hwaccel->frame_priv_data_size) { |
| 868 | − f->hwaccel_priv_buf = | |
| 869 | − av_buffer_allocz(hwaccel->frame_priv_data_size); | |
| 869 | + f->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(avctx, hwaccel); | |
| 870 | 870 | if (!f->hwaccel_priv_buf) { |
| 871 | 871 | ret = AVERROR(ENOMEM); |
| 872 | 872 | goto fail; |
| @@ -2259,6 +2259,14 @@ typedef struct AVHWAccel { · 2258 unmodified lines | ||
| 2259 | 2259 | * For thread-safe hwaccels only. |
| 2260 | 2260 | */ |
| 2261 | 2261 | int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src); |
| 2262 | + | |
| 2263 | + /** | |
| 2264 | + * Callback to free the hwaccel-specific frame data. | |
| 2265 | + * | |
| 2266 | + * @param hwctx a pointer to an AVHWDeviceContext. | |
| 2267 | + * @param data the per-frame hardware accelerator private data to be freed. | |
| 2268 | + */ | |
| 2269 | + void (*free_frame_priv)(void *hwctx, uint8_t *data); | |
| 2262 | 2270 | } AVHWAccel; |
| 2263 | 2271 | |
| 2264 | 2272 | /** |
| @@ -1718,3 +1718,23 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx) · 1717 unmodified lines | ||
| 1718 | 1718 | } |
| 1719 | 1719 | return 0; |
| 1720 | 1720 | } |
| 1721 | + | |
| 1722 | +AVBufferRef *ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, | |
| 1723 | + const AVHWAccel *hwaccel) | |
| 1724 | +{ | |
| 1725 | + AVBufferRef *ref; | |
| 1726 | + AVHWFramesContext *frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data; | |
| 1727 | + uint8_t *data = av_mallocz(hwaccel->frame_priv_data_size); | |
| 1728 | + if (!data) | |
| 1729 | + return NULL; | |
| 1730 | + | |
| 1731 | + ref = av_buffer_create(data, hwaccel->frame_priv_data_size, | |
| 1732 | + hwaccel->free_frame_priv, | |
| 1733 | + frames_ctx->device_ctx, 0); | |
| 1734 | + if (!ref) { | |
| 1735 | + av_free(data); | |
| 1736 | + return NULL; | |
| 1737 | + } | |
| 1738 | + | |
| 1739 | + return ref; | |
| 1740 | +} | |
| @@ -150,4 +150,15 @@ int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags); · 149 unmodified lines | ||
| 150 | 150 | int ff_side_data_update_matrix_encoding(AVFrame *frame, |
| 151 | 151 | enum AVMatrixEncoding matrix_encoding); |
| 152 | 152 | |
| 153 | +/** | |
| 154 | + * Allocate a hwaccel frame private data and create an AVBufferRef | |
| 155 | + * from it. | |
| 156 | + * | |
| 157 | + * @param avctx The codec context which to attach as an opaque value | |
| 158 | + * @param hwaccel The hwaccel for which to allocate | |
| 159 | + * @return The allocated buffer | |
| 160 | + */ | |
| 161 | +AVBufferRef *ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, | |
| 162 | + const AVHWAccel *hwaccel); | |
| 163 | + | |
| 153 | 164 | #endif /* AVCODEC_DECODE_H */ |
| @@ -33,6 +33,7 @@ · 32 unmodified lines | ||
| 33 | 33 | #include "libavutil/pixdesc.h" |
| 34 | 34 | #include "libavutil/timecode.h" |
| 35 | 35 | #include "internal.h" |
| 36 | +#include "decode.h" | |
| 36 | 37 | #include "cabac.h" |
| 37 | 38 | #include "cabac_functions.h" |
| 38 | 39 | #include "decode.h" |
| @@ -212,7 +213,7 @@ static int alloc_picture(H264Context *h, H264Picture *pic) · 173 unmodified lines | ||
| 212 | 213 | const AVHWAccel *hwaccel = h->avctx->hwaccel; |
| 213 | 214 | av_assert0(!pic->hwaccel_picture_private); |
| 214 | 215 | if (hwaccel->frame_priv_data_size) { |
| 215 | − pic->hwaccel_priv_buf = av_buffer_allocz(hwaccel->frame_priv_data_size); | |
| 216 | + pic->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(h->avctx, hwaccel); | |
| 216 | 217 | if (!pic->hwaccel_priv_buf) |
| 217 | 218 | return AVERROR(ENOMEM); |
| 218 | 219 | pic->hwaccel_picture_private = pic->hwaccel_priv_buf->data; |
| @@ -23,6 +23,7 @@ · 22 unmodified lines | ||
| 23 | 23 | |
| 24 | 24 | #include "libavutil/avassert.h" |
| 25 | 25 | |
| 26 | +#include "decode.h" | |
| 26 | 27 | #include "thread.h" |
| 27 | 28 | #include "hevc.h" |
| 28 | 29 | #include "hevcdec.h" |
| @@ -121,7 +122,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s) · 92 unmodified lines | ||
| 121 | 122 | const AVHWAccel *hwaccel = s->avctx->hwaccel; |
| 122 | 123 | av_assert0(!frame->hwaccel_picture_private); |
| 123 | 124 | if (hwaccel->frame_priv_data_size) { |
| 124 | − frame->hwaccel_priv_buf = av_buffer_allocz(hwaccel->frame_priv_data_size); | |
| 125 | + frame->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(s->avctx, hwaccel); | |
| 125 | 126 | if (!frame->hwaccel_priv_buf) |
| 126 | 127 | goto fail; |
| 127 | 128 | frame->hwaccel_picture_private = frame->hwaccel_priv_buf->data; |
| @@ -27,6 +27,8 @@ · 26 unmodified lines | ||
| 27 | 27 | |
| 28 | 28 | #include "avcodec.h" |
| 29 | 29 | #include "encode.h" |
| 30 | +#include "internal.h" | |
| 31 | +#include "decode.h" | |
| 30 | 32 | #include "motion_est.h" |
| 31 | 33 | #include "mpegpicture.h" |
| 32 | 34 | #include "mpegutils.h" |
| @@ -172,7 +174,7 @@ static int alloc_frame_buffer(AVCodecContext *avctx, Picture *pic, · 139 unmodified lines | ||
| 172 | 174 | if (avctx->hwaccel) { |
| 173 | 175 | assert(!pic->hwaccel_picture_private); |
| 174 | 176 | if (avctx->hwaccel->frame_priv_data_size) { |
| 175 | − pic->hwaccel_priv_buf = av_buffer_allocz(avctx->hwaccel->frame_priv_data_size); | |
| 177 | + pic->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(avctx, avctx->hwaccel); | |
| 176 | 178 | if (!pic->hwaccel_priv_buf) { |
| 177 | 179 | av_log(avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n"); |
| 178 | 180 | return -1; |
| @@ -109,7 +109,7 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) · 108 unmodified lines | ||
| 109 | 109 | if (s->avctx->hwaccel) { |
| 110 | 110 | const AVHWAccel *hwaccel = s->avctx->hwaccel; |
| 111 | 111 | if (hwaccel->frame_priv_data_size) { |
| 112 | − f->hwaccel_priv_buf = av_buffer_allocz(hwaccel->frame_priv_data_size); | |
| 112 | + f->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(s->avctx, hwaccel); | |
| 113 | 113 | if (!f->hwaccel_priv_buf) |
| 114 | 114 | goto fail; |
| 115 | 115 | f->hwaccel_picture_private = f->hwaccel_priv_buf->data; |
| @@ -136,7 +136,7 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f) · 135 unmodified lines | ||
| 136 | 136 | const AVHWAccel *hwaccel = avctx->hwaccel; |
| 137 | 137 | av_assert0(!f->hwaccel_picture_private); |
| 138 | 138 | if (hwaccel->frame_priv_data_size) { |
| 139 | − f->hwaccel_priv_buf = av_buffer_allocz(hwaccel->frame_priv_data_size); | |
| 139 | + f->hwaccel_priv_buf = ff_hwaccel_frame_priv_alloc(avctx, hwaccel); | |
| 140 | 140 | if (!f->hwaccel_priv_buf) |
| 141 | 141 | goto fail; |
| 142 | 142 | f->hwaccel_picture_private = f->hwaccel_priv_buf->data; |