[vlc-devel] [PATCH] lavf: Support rotation side data

Luca Barbato lu_zero at gentoo.org
Tue May 20 10:22:49 CEST 2014


Support stream side data only.
---

Now the accessor is available so I can send the patch.

 configure.ac                   |  2 ++
 modules/demux/avformat/demux.c | 69 ++++++++++++++++++++++++++++++------------
 2 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/configure.ac b/configure.ac
index fbb2a3b..2f344a0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2426,9 +2426,11 @@ AS_IF([test "${enable_avformat}" != "no"], [
       VLC_SAVE_FLAGS
       CPPFLAGS="${CPPFLAGS} ${AVFORMAT_CFLAGS}"
       CFLAGS="${CFLAGS} ${AVFORMAT_CFLAGS}"
+      LIBS="${LIBS} ${AVFORMAT_LIBS}"
       AC_CHECK_HEADERS(libavformat/avformat.h libavformat/avio.h)
       AC_CHECK_HEADERS(libavcodec/avcodec.h)
       AC_CHECK_HEADERS(libavutil/avutil.h)
+      AC_CHECK_FUNCS([av_stream_get_side_data])
       AS_IF([test "$enable_merge_ffmpeg" = "no"], [
         have_avformat="no"
       ])
diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
index 9eebac6..06b635a 100644
--- a/modules/demux/avformat/demux.c
+++ b/modules/demux/avformat/demux.c
@@ -40,6 +40,10 @@

 #include <libavformat/avformat.h>

+#if HAVE_AV_STREAM_GET_SIDE_DATA
+#include <libavutil/display.h>
+#endif
+
 #include "../../codec/avcodec/avcodec.h"
 #include "../../codec/avcodec/chroma.h"
 #include "../../codec/avcodec/avcommon.h"
@@ -109,6 +113,50 @@ static vlc_fourcc_t CodecTagToFourcc( uint32_t codec_tag )
 /*****************************************************************************
  * Open
  *****************************************************************************/
+
+
+static void get_rotation(es_format_t *fmt, AVStream *s)
+{
+    char const *kRotateKey = "rotate";
+    AVDictionaryEntry *rotation = av_dict_get(s->metadata, kRotateKey, NULL, 0);
+    long angle = 0;
+
+    if( rotation )
+    {
+        angle = strtol(rotation->value, NULL, 10);
+
+        if (angle > 45 && angle < 135)
+            fmt->video.orientation = ORIENT_ROTATED_90;
+
+        else if (angle > 135 && angle < 225)
+            fmt->video.orientation = ORIENT_ROTATED_180;
+
+        else if (angle > 225 && angle < 315)
+            fmt->video.orientation = ORIENT_ROTATED_270;
+
+        else
+            fmt->video.orientation = ORIENT_NORMAL;
+    }
+#if HAVE_AV_STREAM_GET_SIDE_DATA
+    int32_t *matrix = (int32_t *)av_stream_get_side_data(s, AV_PKT_DATA_DISPLAYMATRIX, NULL);
+    if( matrix ) {
+        angle = lround(av_display_rotation_get(matrix));
+
+        if (angle > 45 && angle < 135)
+            fmt->video.orientation = ORIENT_ROTATED_270;
+
+        else if (angle > 135 || angle < -135)
+            fmt->video.orientation = ORIENT_ROTATED_180;
+
+        else if (angle < -45 && angle > -135)
+            fmt->video.orientation = ORIENT_ROTATED_90;
+
+        else
+            fmt->video.orientation = ORIENT_NORMAL;
+    }
+#endif
+}
+
 int OpenDemux( vlc_object_t *p_this )
 {
     demux_t       *p_demux = (demux_t*)p_this;
@@ -336,26 +384,7 @@ int OpenDemux( vlc_object_t *p_this )
             fmt.video.i_width = cc->width;
             fmt.video.i_height = cc->height;

-            char const *kRotateKey = "rotate";
-            AVDictionaryEntry *rotation = av_dict_get(s->metadata, kRotateKey, NULL, 0);
-
-            if( rotation )
-            {
-
-                long angle = strtol(rotation->value, NULL, 10);
-
-                if (angle > 45 && angle < 135)
-                    fmt.video.orientation = ORIENT_ROTATED_90;
-
-                else if (angle > 135 && angle < 225)
-                    fmt.video.orientation = ORIENT_ROTATED_180;
-
-                else if (angle > 225 && angle < 315)
-                    fmt.video.orientation = ORIENT_ROTATED_270;
-
-                else
-                    fmt.video.orientation = ORIENT_NORMAL;
-            }
+            get_rotation(&fmt, s);

 #if LIBAVCODEC_VERSION_MAJOR < 54
             if( cc->palctrl )
--
1.8.5.2 (Apple Git-48)




More information about the vlc-devel mailing list