History

Merge commit 'bddd8cbf68551f6405b2bf77cc3e212af9fbe834'

* commit 'bddd8cbf68551f6405b2bf77cc3e212af9fbe834': Add transformation matrix API. Conflicts: libavcodec/avcodec.h libavcodec/utils.c libavutil/version.h

Michael Niedermayer committed 12 years ago

Commit ef1d4ee2 parents af72f62 bddd8cb9 files · +180 −1Browse files

Unified · Split

9 files
  1. Changelog +1 −0
  2. doc/APIchanges +8 −0
  3. libavcodec/avcodec.h +9 −0
  4. libavcodec/utils.c +10 −0
  5. libavutil/Makefile +2 −0
  6. libavutil/display.c +64 −0
  7. libavutil/display.h +77 −0
  8. libavutil/frame.h +8 −0
  9. libavutil/version.h +1 −1
Changelog+1−0
@@ -24,6 +24,7 @@ version <next>: · 23 unmodified lines
2424 - libbs2b-based stereo-to-binaural audio filter
2525 - libx264 reference frames count limiting depending on level
2626 - native Opus decoder
27+- display matrix export and rotation api
2728
2829
2930 version 2.2:
doc/APIchanges+8−0
@@ -15,6 +15,14 @@ libavutil: 2012-10-22 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2014-05-xx - xxxxxxx - lavu 53.15.0 - frame.h, display.h
19+ Add AV_FRAME_DATA_DISPLAYMATRIX for exporting frame-level
20+ spatial rendering on video frames for proper display.
21+
22+2014-05-xx - xxxxxxx - lavc 55.52.0 - avcodec.h
23+ Add AV_PKT_DATA_DISPLAYMATRIX for exporting packet-level
24+ spatial rendering on video frames for proper display.
25+
1826 2014-05-xx - xxxxxxx - lavf 55.17.1 - avformat.h
1927 Deprecate AVStream.pts and the AVFrac struct, which was its only use case.
2028 Those fields were poorly defined and not meant to be public, so there is
libavcodec/avcodec.h+9−0
@@ -1052,6 +1052,15 @@ enum AVPacketSideDataType { · 1051 unmodified lines
10521052 */
10531053 AV_PKT_DATA_REPLAYGAIN,
10541054
1055+ /**
1056+ * This side data contains a 3x3 transformation matrix describing an affine
1057+ * transformation that needs to be applied to the decoded video frames for
1058+ * correct presentation.
1059+ *
1060+ * See libavutil/display.h for a detailed description of the data.
1061+ */
1062+ AV_PKT_DATA_DISPLAYMATRIX,
1063+
10551064 /**
10561065 * Recommmends skipping the specified number of samples
10571066 * @code
libavcodec/utils.c+10−0
@@ -767,6 +767,16 @@ int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame) · 766 unmodified lines
767767
768768 memcpy(frame_sd->data, packet_sd, size);
769769 }
770+
771+ /* copy the displaymatrix to the output frame */
772+ packet_sd = av_packet_get_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, &size);
773+ if (packet_sd) {
774+ frame_sd = av_frame_new_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX, size);
775+ if (!frame_sd)
776+ return AVERROR(ENOMEM);
777+
778+ memcpy(frame_sd->data, packet_sd, size);
779+ }
770780 } else {
771781 frame->pkt_pts = AV_NOPTS_VALUE;
772782 av_frame_set_pkt_pos (frame, -1);
libavutil/Makefile+2−0
@@ -19,6 +19,7 @@ HEADERS = adler32.h \ · 18 unmodified lines
1919 common.h \
2020 cpu.h \
2121 crc.h \
22+ display.h \
2223 downmix_info.h \
2324 error.h \
2425 eval.h \
@@ -82,6 +83,7 @@ OBJS = adler32.o \ · 57 unmodified lines
8283 cpu.o \
8384 crc.o \
8485 des.o \
86+ display.o \
8587 downmix_info.o \
8688 error.o \
8789 eval.o \
libavutil/display.c+64−0
@@ -0,0 +1,64 @@
1+/*
2+ * Copyright (c) 2014 Vittorio Giovara <vittorio.giovara@gmail.com>
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#include <stdint.h>
22+#include <string.h>
23+#include <math.h>
24+
25+#include "display.h"
26+
27+// fixed point to double
28+#define CONV_FP(x) ((double) (x)) / (1 << 16)
29+
30+// double to fixed point
31+#define CONV_DB(x) (int32_t) ((x) * (1 << 16))
32+
33+double av_display_rotation_get(const int32_t matrix[9])
34+{
35+ double rotation, scale[2];
36+
37+ scale[0] = sqrt(CONV_FP(matrix[0]) * CONV_FP(matrix[0]) +
38+ CONV_FP(matrix[3]) * CONV_FP(matrix[3]));
39+ scale[1] = sqrt(CONV_FP(matrix[1]) * CONV_FP(matrix[1]) +
40+ CONV_FP(matrix[4]) * CONV_FP(matrix[4]));
41+
42+ if (scale[0] == 0.0 || scale[1] == 0.0)
43+ return NAN;
44+
45+ rotation = atan2(CONV_FP(matrix[1]) / scale[1],
46+ CONV_FP(matrix[0]) / scale[0]) * 180 / M_PI;
47+
48+ return rotation;
49+}
50+
51+void av_display_rotation_set(int32_t matrix[9], double angle)
52+{
53+ double radians = angle * M_PI / 180.0f;
54+ double c = cos(radians);
55+ double s = sin(radians);
56+
57+ memset(matrix, 0, 9 * sizeof(int32_t));
58+
59+ matrix[0] = CONV_DB(c);
60+ matrix[1] = CONV_DB(-s);
61+ matrix[3] = CONV_DB(s);
62+ matrix[4] = CONV_DB(c);
63+ matrix[8] = 1 << 30;
64+}
libavutil/display.h+77−0
@@ -0,0 +1,77 @@
1+/*
2+ * Copyright (c) 2014 Vittorio Giovara <vittorio.giovara@gmail.com>
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#ifndef AVUTIL_DISPLAY_H
22+#define AVUTIL_DISPLAY_H
23+
24+#include <stdint.h>
25+
26+/**
27+ * The display transformation matrix specifies an affine transformation that
28+ * should be applied to video frames for correct presentation. It is compatible
29+ * with the matrices stored in the ISO/IEC 14496-12 container format.
30+ *
31+ * The data is a 3x3 matrix represented as a 9-element array:
32+ *
33+ * | a b u |
34+ * (a, b, u, c, d, v, x, y, w) -> | c d v |
35+ * | x y w |
36+ *
37+ * All numbers are stored in native endianness, as 16.16 fixed-point values,
38+ * except for u, v and w, which are stored as 2.30 fixed-point values.
39+ *
40+ * The transformation maps a point (p, q) in the source (pre-transformation)
41+ * frame to the point (p', q') in the destination (post-transformation) frame as
42+ * follows:
43+ * | a b u |
44+ * (p, q, 1) . | c d v | = z * (p', q', 1)
45+ * | x y w |
46+ *
47+ * The transformation can also be more explicitly written in components as
48+ * follows:
49+ * p' = (a * p + c * q + x) / z;
50+ * q' = (b * p + d * q + y) / z;
51+ * z = u * p + v * q + w
52+ */
53+
54+/**
55+ * Extract the rotation component of the transformation matrix.
56+ *
57+ * @param matrix the transformation matrix
58+ * @return the angle (in degrees) by which the transformation rotates the frame.
59+ * The angle will be in range [-180.0, 180.0], or NaN if the matrix is
60+ * singular.
61+ *
62+ * @note floating point numbers are inherently inexact, so callers are
63+ * recommended to round the return value to nearest integer before use.
64+ */
65+double av_display_rotation_get(const int32_t matrix[9]);
66+
67+/**
68+ * Initialize a transformation matrix describing a pure rotation by the
69+ * specified angle (in degrees).
70+ *
71+ * @param matrix an allocated transformation matrix (will be fully overwritten
72+ * by this function)
73+ * @param angle rotation angle in degrees.
74+ */
75+void av_display_rotation_set(int32_t matrix[9], double angle);
76+
77+#endif /* AVUTIL_DISPLAY_H */
libavutil/frame.h+8−0
@@ -96,6 +96,14 @@ enum AVFrameSideDataType { · 95 unmodified lines
9696 * ReplayGain information in the form of the AVReplayGain struct.
9797 */
9898 AV_FRAME_DATA_REPLAYGAIN,
99+ /**
100+ * This side data contains a 3x3 transformation matrix describing an affine
101+ * transformation that needs to be applied to the frame for correct
102+ * presentation.
103+ *
104+ * See libavutil/display.h for a detailed description of the data.
105+ */
106+ AV_FRAME_DATA_DISPLAYMATRIX,
99107 };
100108
101109 typedef struct AVFrameSideData {
libavutil/version.h+1−1
@@ -56,7 +56,7 @@ · 55 unmodified lines
5656 */
5757
5858 #define LIBAVUTIL_VERSION_MAJOR 52
59−#define LIBAVUTIL_VERSION_MINOR 84
59+#define LIBAVUTIL_VERSION_MINOR 85
6060 #define LIBAVUTIL_VERSION_MICRO 100
6161
6262 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t