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