[FFmpeg-devel] [PATCH v3] avcodec/libdav1d: fix setting AVFrame reordered_opaque
Andrey Semashev
andrey.semashev at gmail.com
Fri Oct 18 13:22:16 EEST 2019
Actually reorder the values.
Should effectively fix ticket #8300.
Signed-off-by: James Almer <jamrial at gmail.com>
Updated to avoid extra memory allocations on 64-bit platforms.
Signed-off-by: Andrey Semashev <andrey.semashev at gmail.com>
---
libavcodec/libdav1d.c | 46 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index 8aa248e6cd..ff94310b40 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -19,12 +19,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdint.h>
#include <dav1d/dav1d.h>
#include "libavutil/avassert.h"
#include "libavutil/mastering_display_metadata.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
+#include "libavutil/mem.h"
#include "avcodec.h"
#include "decode.h"
@@ -164,6 +166,12 @@ static void libdav1d_data_free(const uint8_t *data, void *opaque) {
av_buffer_unref(&buf);
}
+static void libdav1d_user_data_free(const uint8_t *data, void *opaque) {
+#if UINTPTR_MAX < UINT64_MAX
+ av_free((void *)data);
+#endif
+}
+
static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
{
Libdav1dContext *dav1d = c->priv_data;
@@ -191,6 +199,35 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
pkt.buf = NULL;
av_packet_unref(&pkt);
+
+#if UINTPTR_MAX >= UINT64_MAX
+ if (c->reordered_opaque != (int64_t)(intptr_t)(const uint8_t *)NULL) {
+ res = dav1d_data_wrap_user_data(data, (const uint8_t *)(intptr_t)c->reordered_opaque,
+ libdav1d_user_data_free, NULL);
+ if (res < 0) {
+ dav1d_data_unref(data);
+ return res;
+ }
+ }
+#else
+ if (c->reordered_opaque != AV_NOPTS_VALUE) {
+ int64_t *reordered_opaque = av_malloc(sizeof(int64_t));
+
+ if (!reordered_opaque) {
+ dav1d_data_unref(data);
+ return AVERROR(ENOMEM);
+ }
+
+ *reordered_opaque = c->reordered_opaque;
+ res = dav1d_data_wrap_user_data(data, (const uint8_t *)reordered_opaque,
+ libdav1d_user_data_free, NULL);
+ if (res < 0) {
+ av_free(reordered_opaque);
+ dav1d_data_unref(data);
+ return res;
+ }
+ }
+#endif
}
}
@@ -260,7 +297,14 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
else
frame->format = c->pix_fmt = pix_fmt[p->p.layout][p->seq_hdr->hbd];
- frame->reordered_opaque = c->reordered_opaque;
+#if UINTPTR_MAX >= UINT64_MAX
+ frame->reordered_opaque = (int64_t)(intptr_t)p->m.user_data.data;
+#else
+ if (p->m.user_data.data)
+ memcpy(&frame->reordered_opaque, p->m.user_data.data, sizeof(frame->reordered_opaque));
+ else
+ frame->reordered_opaque = AV_NOPTS_VALUE;
+#endif
// match timestamps and packet size
frame->pts = frame->best_effort_timestamp = p->m.timestamp;
--
2.20.1
More information about the ffmpeg-devel
mailing list