Add AV_PKT_DATA_DISPLAYMATRIX and AV_FRAME_DATA_DISPLAYMATRIX as stream and
frame side data (respectively) to describe a display transformation matrix
for linear transformation operations on the decoded video.

Add APIs to easily access values such as rotation, scaling and translation.
---
 Changelog            |  1 +
 doc/APIchanges       |  7 ++++
 libavcodec/avcodec.h |  7 ++++
 libavcodec/utils.c   |  9 ++++++
 libavcodec/version.h |  2 +-
 libavutil/Makefile   |  2 ++
 libavutil/display.c  | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 libavutil/display.h  | 53 +++++++++++++++++++++++++++++++
 libavutil/frame.h    |  4 +++
 libavutil/version.h  |  2 +-
 10 files changed, 175 insertions(+), 2 deletions(-)
 create mode 100644 libavutil/display.c
 create mode 100644 libavutil/display.h

diff --git a/Changelog b/Changelog
index 55216e8..41f47c2 100644
--- a/Changelog
+++ b/Changelog
@@ -19,6 +19,7 @@ version <next>:
 - LucasArts SMUSH demuxer
 - MP2 encoding via TwoLAME
 - asettb filter
+- transformation matrix export and rotation/flip/translation api
 
 
 version 10:
diff --git a/doc/APIchanges b/doc/APIchanges
index ec1816a..f50a0ea 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,13 @@ libavutil:     2013-12-xx
 
 API changes, most recent first:
 
+2014-02-xx - xxxxxxx - lavu 53.12.0 - frame.h, display.h
+  Add AV_FRAME_DATA_DISPLAYMATRIX for exporting further
+  spatial rendering the video should do for proper display.
+
+2014-02-11 - xxxxxxx - lavc 55.47.0 - avcodec.h
+  Add AV_PKT_DATA_DISPLAYMATRIX for exporting the transformation matrix.
+
 2014-04-xx - xxxxxxx - lavu 53.11.0 - pixfmt.h
   Add AV_PIX_FMT_YVYU422 pixel format.
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 622eac3..ae72bf1 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -937,6 +937,13 @@ enum AVPacketSideDataType {
      * ReplayGain information in form of the AVReplayGain struct.
      */
     AV_PKT_DATA_REPLAYGAIN,
+
+    /**
+     * This side data contains a 3x2 matrix (math notation) describing
+     * two dimensional transformations to be applied on the decoded video.
+     * Elements are represented as s32le, fixed point 16.16.
+     */
+    AV_PKT_DATA_DISPLAYMATRIX,
 };
 
 typedef struct AVPacketSideData {
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index d9832e2..9229413 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -597,6 +597,15 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 
         memcpy(frame_sd->data, packet_sd, size);
     }
+    /* copy the displaymatrix to the output frame */
+    packet_sd = av_packet_get_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, &size);
+    if (packet_sd) {
+        frame_sd = av_frame_new_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX, 
size);
+        if (!frame_sd)
+            return AVERROR(ENOMEM);
+
+        memcpy(frame_sd->data, packet_sd, size);
+    }
 
     return 0;
 }
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 4a8febc..234d409 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 55
-#define LIBAVCODEC_VERSION_MINOR 46
+#define LIBAVCODEC_VERSION_MINOR 47
 #define LIBAVCODEC_VERSION_MICRO  0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavutil/Makefile b/libavutil/Makefile
index d5c1636..0f8ed08 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -16,6 +16,7 @@ HEADERS = adler32.h                                           
          \
           common.h                                                      \
           cpu.h                                                         \
           crc.h                                                         \
+          display.h                                                     \
           downmix_info.h                                                \
           error.h                                                       \
           eval.h                                                        \
@@ -69,6 +70,7 @@ OBJS = adler32.o                                              
          \
        cpu.o                                                            \
        crc.o                                                            \
        des.o                                                            \
+       display.o                                                        \
        downmix_info.o                                                   \
        error.o                                                          \
        eval.o                                                           \
diff --git a/libavutil/display.c b/libavutil/display.c
new file mode 100644
index 0000000..cc993f9
--- /dev/null
+++ b/libavutil/display.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) Vittorio Giovara <[email protected]>
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <math.h>
+
+#include "display.h"
+
+#define CONV_FP(x) ((double) (x)) / 65536
+
+int av_display_rotation_angle(uint8_t *matrix)
+{
+    int32_t (*display_matrix)[2] = (int32_t (*)[2])matrix;
+    double rotationf, scale[2];
+
+    scale[0] = sqrt(CONV_FP(display_matrix[0][0]) * 
CONV_FP(display_matrix[0][0]) +
+                    CONV_FP(display_matrix[1][0]) * 
CONV_FP(display_matrix[1][0]));
+    scale[1] = sqrt(CONV_FP(display_matrix[0][1]) * 
CONV_FP(display_matrix[0][1]) +
+                    CONV_FP(display_matrix[1][1]) * 
CONV_FP(display_matrix[1][1]));
+
+    rotationf = atan2(CONV_FP(display_matrix[0][1]) / scale[1],
+                      CONV_FP(display_matrix[0][0]) / scale[0]) * 180 / M_PI;
+
+    return (int) floor(rotationf);
+}
+
+AVRational av_display_scale_factor(uint8_t *matrix)
+{
+    int32_t (*display_matrix)[2] = (int32_t (*)[2])matrix;
+    double scale[2];
+
+    scale[0] = sqrt(CONV_FP(display_matrix[0][0]) * 
CONV_FP(display_matrix[0][0]) +
+                    CONV_FP(display_matrix[1][0]) * 
CONV_FP(display_matrix[1][0]));
+    scale[1] = sqrt(CONV_FP(display_matrix[0][1]) * 
CONV_FP(display_matrix[0][1]) +
+                    CONV_FP(display_matrix[1][1]) * 
CONV_FP(display_matrix[1][1]));
+
+    return (AVRational) { (int) floor(scale[0]), (int) floor(scale[1]) };
+}
+
+int av_display_hflip(uint8_t *matrix)
+{
+    int32_t (*display_matrix)[2] = (int32_t (*)[2])matrix;
+
+    if ( display_matrix[0][0] < 0 &&
+        !display_matrix[1][0] &&
+        !display_matrix[2][0])
+        return 1;
+
+    return 0;
+}
+
+int av_display_vflip(uint8_t *matrix)
+{
+    int32_t (*display_matrix)[2] = (int32_t (*)[2])matrix;
+
+    if ( display_matrix[1][1] < 0 &&
+        !display_matrix[0][1] &&
+        !display_matrix[2][1])
+        return 1;
+
+    return 0;
+}
+
+AVRational av_display_translation_factor(uint8_t *matrix)
+{
+    int32_t (*display_matrix)[2] = (int32_t (*)[2])matrix;
+    double translation[2];
+
+    translation[0] = CONV_FP(display_matrix[2][0]);
+    translation[1] = CONV_FP(display_matrix[2][1]);
+
+    return (AVRational) { (int) floor(translation[0]),
+                          (int) floor(translation[1]) };
+}
diff --git a/libavutil/display.h b/libavutil/display.h
new file mode 100644
index 0000000..a5de0bf
--- /dev/null
+++ b/libavutil/display.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) Vittorio Giovara <[email protected]>
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_DISPLAY_H
+#define AVUTIL_DISPLAY_H
+
+#include <stdint.h>
+
+#include "libavutil/rational.h"
+
+/**
+ * @return 0 no hflip, 1 hflip
+ */
+int av_display_hflip(uint8_t *matrix);
+
+/**
+ * @return 0 no vflip, 1 vflip
+ */
+int av_display_vflip(uint8_t *matrix);
+
+/**
+ * @return the translation amount as x:y
+ */
+AVRational av_display_translation_factor(uint8_t *matrix);
+
+/**
+ * @return the rotation angle in degrees.
+ */
+int av_display_rotation_angle(uint8_t *matrix);
+
+/**
+ * @return the scale scale factor as n:n.
+ */
+AVRational av_display_scale_factor(uint8_t *matrix);
+
+#endif /* AVUTIL_DISPLAY_H */
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 3bec8e5..bfd1937 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -73,6 +73,10 @@ enum AVFrameSideDataType {
      * ReplayGain information in the form of the AVReplayGain struct.
      */
     AV_FRAME_DATA_REPLAYGAIN,
+    /**
+     * Transformation matrix. Accessors defined in libavutil/display.h.
+     */
+    AV_FRAME_DATA_DISPLAYMATRIX,
 };
 
 typedef struct AVFrameSideData {
diff --git a/libavutil/version.h b/libavutil/version.h
index 8fd90bc..f32e8d0 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -54,7 +54,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 53
-#define LIBAVUTIL_VERSION_MINOR 11
+#define LIBAVUTIL_VERSION_MINOR 12
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
1.8.3.4 (Apple Git-47)

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to