[FFmpeg-devel] [PATCH 1/3] lavu/frame: add av_frame_check_align().

Nicolas George george at nsup.org
Thu May 18 11:11:12 EEST 2017


Signed-off-by: Nicolas George <george at nsup.org>
---
 doc/APIchanges    |  3 +++
 libavutil/frame.c | 17 +++++++++++++++++
 libavutil/frame.h |  8 ++++++++
 3 files changed, 28 insertions(+)


With the linesize check and without the 1<<.


diff --git a/doc/APIchanges b/doc/APIchanges
index 67a6142401..6d3b573c2d 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2017-05-18 - xxxxxxxxxx - lavu 55.63.100 - frame.h
+  Add av_frame_check_align().
+
 2017-05-15 - xxxxxxxxxx - lavc 57.96.100 - avcodec.h
   VideoToolbox hardware-accelerated decoding now supports the new hwaccel API,
   which can create the decoder context and allocate hardware frames automatically.
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 24d5d5f184..aed3cd04ec 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -781,3 +781,20 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type)
     }
     return NULL;
 }
+
+int av_frame_check_align(const AVFrame *frame, unsigned align)
+{
+    unsigned mask = align - 1;
+    unsigned i;
+
+    for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
+        if (((intptr_t)frame->data[i] & mask) ||
+            (frame->linesize[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;
+}
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 26261d7e40..1cbf7c7a5a 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -772,6 +772,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 alignment.
+ * @return  >0 if aligned, 0 if not
+ */
+int av_frame_check_align(const AVFrame *frame, unsigned align);
+
+/**
  * @}
  */
 
-- 
2.11.0



More information about the ffmpeg-devel mailing list