From 3dacd6fa2aa86b31b73edda83f995b841e1d57b5 Mon Sep 17 00:00:00 2001
From: Nicolas George <george@nsup.org>
Date: Sat, 6 May 2017 10:56:33 +0200
Subject: [PATCH 1/3] lavu/frame: add av_frame_check_align().
TODO APIchanges and minor bump.
Signed-off-by: Nicolas George <george@nsup.org>
---
libavutil/frame.c | 18 ++++++++++++++++++
libavutil/frame.h | 8 ++++++++
2 files changed, 26 insertions(+)
@@ -777,3 +777,21 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type)
}
return NULL;
}
+
+int av_frame_check_align(AVFrame *frame, unsigned align)
+{
+ unsigned mask = (1 << align) - 1;
+ unsigned i;
+ int ret;
+
+ av_assert1(align < 16);
+ for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
+ if (((intptr_t)frame->data[i] & mask))
+ return 0;
+ if (!frame->extended_data || frame->extended_data == frame->data)
+ return 1;
+ for (i = AV_NUM_DATA_POINTERS; i < frame->channels; i++)
+ if (((intptr_t)frame->extended_data[i] & mask))
+ return 0;
+ return 1;
+}
@@ -746,6 +746,14 @@ void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);
const char *av_frame_side_data_name(enum AVFrameSideDataType type);
/**
+ * Check if the data pointers of a frame are aligned enough.
+ * Test if all frame data pointers have the alignment lower bits cleared,
+ * i.e. are a multiple of 1<<alignment.
+ * @return >0 if aligned, 0 if not
+ */
+int av_frame_check_align(AVFrame *frame, unsigned align);
+
+/**
* @}
*/
--
2.11.0
L'octidi 18 floréal, an CCXXV, Marton Balint a écrit : > I suggest to return 1 if an actual alignment (with deep copy) happened. Actually, as Muhammad just pointed and as I noticed a few minutes ago, we can not use the same function from lavfi and lavc, due to the get_buffer issue. I propose the attached patch to factor the alignment check (notice it is slightly more complex than in Muhammad's patch, because it takes care of all cases and not just the mp3lame crash). The realignment functions will look like: int ff_frame_realign(AVFrame *frame, unsigned align) { if (ff_frame_check_align(frame, align)) return 0; <copy-paste from av_frame_make_writable()> specific_get_buffer(frame); <copy-paste from av_frame_make_writable()> } If we were not so much in a rush, I would propose a solution to avoid the copy-paste, but it can wait for later. Regards,