Unified · Split
| @@ -16,6 +16,9 @@ · 15 unmodified lines | ||
| 16 | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | +#include "libavutil/avassert.h" | |
| 20 | +#include "libavutil/buffer.h" | |
| 21 | + | |
| 19 | 22 | #include "avcodec.h" |
| 20 | 23 | #include "apv.h" |
| 21 | 24 | #include "cbs.h" |
| @@ -34,6 +37,11 @@ static const enum AVPixelFormat apv_format_table[5][5] = { · 12 unmodified lines | ||
| 34 | 37 | { AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUVA444P16 }, |
| 35 | 38 | }; |
| 36 | 39 | |
| 40 | +static void dummy_free(void *opaque, uint8_t *data) | |
| 41 | +{ | |
| 42 | + av_assert0(opaque == data); | |
| 43 | +} | |
| 44 | + | |
| 37 | 45 | static int parse(AVCodecParserContext *s, |
| 38 | 46 | AVCodecContext *avctx, |
| 39 | 47 | const uint8_t **poutbuf, int *poutbuf_size, |
| @@ -41,14 +49,20 @@ static int parse(AVCodecParserContext *s, · 1 unmodified line | ||
| 41 | 49 | { |
| 42 | 50 | APVParseContext *p = s->priv_data; |
| 43 | 51 | CodedBitstreamFragment *au = &p->au; |
| 52 | + AVBufferRef *ref = NULL; | |
| 44 | 53 | int ret; |
| 45 | 54 | |
| 46 | 55 | *poutbuf = buf; |
| 47 | 56 | *poutbuf_size = buf_size; |
| 48 | 57 | |
| 58 | + ref = av_buffer_create((uint8_t *)buf, buf_size, dummy_free, | |
| 59 | + (void *)buf, AV_BUFFER_FLAG_READONLY); | |
| 60 | + if (!ref) | |
| 61 | + return buf_size; | |
| 62 | + | |
| 49 | 63 | p->cbc->log_ctx = avctx; |
| 50 | 64 | |
| 51 | − ret = ff_cbs_read(p->cbc, au, NULL, buf, buf_size); | |
| 65 | + ret = ff_cbs_read(p->cbc, au, ref, buf, buf_size); | |
| 52 | 66 | if (ret < 0) { |
| 53 | 67 | av_log(avctx, AV_LOG_ERROR, "Failed to parse access unit.\n"); |
| 54 | 68 | goto end; |
| @@ -92,6 +106,8 @@ static int parse(AVCodecParserContext *s, · 37 unmodified lines | ||
| 92 | 106 | |
| 93 | 107 | end: |
| 94 | 108 | ff_cbs_fragment_reset(au); |
| 109 | + av_assert1(av_buffer_get_ref_count(ref) == 1); | |
| 110 | + av_buffer_unref(&ref); | |
| 95 | 111 | p->cbc->log_ctx = NULL; |
| 96 | 112 | |
| 97 | 113 | return buf_size; |