diff mbox

[FFmpeg-devel,v3] avcodec/libdav1d: fix setting AVFrame reordered_opaque

Message ID 20191018102216.509-1-andrey.semashev@gmail.com
State New
Headers show

Commit Message

Andrey Semashev Oct. 18, 2019, 10:22 a.m. UTC
Actually reorder the values.

Should effectively fix ticket #8300.

Signed-off-by: James Almer <jamrial@gmail.com>

Updated to avoid extra memory allocations on 64-bit platforms.

Signed-off-by: Andrey Semashev <andrey.semashev@gmail.com>
---
 libavcodec/libdav1d.c | 46 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)

Comments

Hendrik Leppkes Oct. 18, 2019, 11 a.m. UTC | #1
On Fri, Oct 18, 2019 at 12:22 PM Andrey Semashev
<andrey.semashev@gmail.com> wrote:
>
> Actually reorder the values.
>
> Should effectively fix ticket #8300.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
>
> Updated to avoid extra memory allocations on 64-bit platforms.
>

Lets not do this, the code for this is really ugly.

- Hendrik
James Almer Oct. 18, 2019, 12:52 p.m. UTC | #2
On 10/18/2019 7:22 AM, Andrey Semashev wrote:
> Actually reorder the values.
> 
> Should effectively fix ticket #8300.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> 
> Updated to avoid extra memory allocations on 64-bit platforms.
> 
> Signed-off-by: Andrey Semashev <andrey.semashev@gmail.com>

Please stop sending patches by other people with the authorship changed,
even if you modified it somewhat.

Suggest changes, or ask if I'm ok with you taking over the patch.
Anything else will more likely than not be seen as rude by anyone.
Andrey Semashev Oct. 18, 2019, 3:14 p.m. UTC | #3
On 2019-10-18 15:52, James Almer wrote:
> On 10/18/2019 7:22 AM, Andrey Semashev wrote:
>> Actually reorder the values.
>>
>> Should effectively fix ticket #8300.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>>
>> Updated to avoid extra memory allocations on 64-bit platforms.
>>
>> Signed-off-by: Andrey Semashev <andrey.semashev@gmail.com>
> 
> Please stop sending patches by other people with the authorship changed,
> even if you modified it somewhat.
> 
> Suggest changes, or ask if I'm ok with you taking over the patch.
> Anything else will more likely than not be seen as rude by anyone.

Sorry, I didn't mean to offend anyone. I honestly don't understand the 
problem. I didn't claim the credit for the original change and I did 
preserve your comment and Signed-off-by, didn't I? Is there something 
else that I should have done?

My aim was to demonstrate my suggestion and perhaps simplify your work. 
I don't care if my changes are taken or modified, credited or not. If 
that is not wanted, that is fine, I won't send any more patches.
James Almer Oct. 18, 2019, 3:26 p.m. UTC | #4
On 10/18/2019 12:14 PM, Andrey Semashev wrote:
> On 2019-10-18 15:52, James Almer wrote:
>> On 10/18/2019 7:22 AM, Andrey Semashev wrote:
>>> Actually reorder the values.
>>>
>>> Should effectively fix ticket #8300.
>>>
>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>>
>>> Updated to avoid extra memory allocations on 64-bit platforms.
>>>
>>> Signed-off-by: Andrey Semashev <andrey.semashev@gmail.com>
>>
>> Please stop sending patches by other people with the authorship changed,
>> even if you modified it somewhat.
>>
>> Suggest changes, or ask if I'm ok with you taking over the patch.
>> Anything else will more likely than not be seen as rude by anyone.
> 
> Sorry, I didn't mean to offend anyone. I honestly don't understand the
> problem. I didn't claim the credit for the original change and I did
> preserve your comment and Signed-off-by, didn't I? Is there something
> else that I should have done?

Yes, you should have kept the original author name. "git commit
--author="foo <bar>" or just "git commit --amend" should be enough to
preserve authorship.
If this patch was committed as is, it would be under your name.

> 
> My aim was to demonstrate my suggestion and perhaps simplify your work.
> I don't care if my changes are taken or modified, credited or not. If
> that is not wanted, that is fine, I won't send any more patches.

Patches are welcome, always. Just keep etiquette in mind (Don't take
over patches without asking first, don't change authorship, etc).
diff mbox

Patch

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;