History

avcodec/apv_parser: use an AVBufferRef to avoid data copying

James Almer committed 1 year ago

Commit 0cabfdc1 parent 4bfe9c51 file · +17 −1Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/apv_parser.c+17−1
@@ -16,6 +16,9 @@ · 15 unmodified lines
1616 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717 */
1818
19+#include "libavutil/avassert.h"
20+#include "libavutil/buffer.h"
21+
1922 #include "avcodec.h"
2023 #include "apv.h"
2124 #include "cbs.h"
@@ -34,6 +37,11 @@ static const enum AVPixelFormat apv_format_table[5][5] = { · 12 unmodified lines
3437 { AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUVA444P16 },
3538 };
3639
40+static void dummy_free(void *opaque, uint8_t *data)
41+{
42+ av_assert0(opaque == data);
43+}
44+
3745 static int parse(AVCodecParserContext *s,
3846 AVCodecContext *avctx,
3947 const uint8_t **poutbuf, int *poutbuf_size,
@@ -41,14 +49,20 @@ static int parse(AVCodecParserContext *s, · 1 unmodified line
4149 {
4250 APVParseContext *p = s->priv_data;
4351 CodedBitstreamFragment *au = &p->au;
52+ AVBufferRef *ref = NULL;
4453 int ret;
4554
4655 *poutbuf = buf;
4756 *poutbuf_size = buf_size;
4857
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+
4963 p->cbc->log_ctx = avctx;
5064
51− ret = ff_cbs_read(p->cbc, au, NULL, buf, buf_size);
65+ ret = ff_cbs_read(p->cbc, au, ref, buf, buf_size);
5266 if (ret < 0) {
5367 av_log(avctx, AV_LOG_ERROR, "Failed to parse access unit.\n");
5468 goto end;
@@ -92,6 +106,8 @@ static int parse(AVCodecParserContext *s, · 37 unmodified lines
92106
93107 end:
94108 ff_cbs_fragment_reset(au);
109+ av_assert1(av_buffer_get_ref_count(ref) == 1);
110+ av_buffer_unref(&ref);
95111 p->cbc->log_ctx = NULL;
96112
97113 return buf_size;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t