[FFmpeg-devel] [PATCH] lavu/stereo3d: add serialization and deserialization functions
Rodger Combs
rodger.combs at gmail.com
Mon Oct 26 20:45:48 CET 2015
---
doc/APIchanges | 3 ++
libavutil/Makefile | 1 +
libavutil/stereo3d.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++
libavutil/stereo3d.h | 47 ++++++++++++++++
libavutil/version.h | 2 +-
tests/fate/libavutil.mak | 4 ++
tests/ref/fate/stereo3d | 16 ++++++
7 files changed, 209 insertions(+), 1 deletion(-)
create mode 100644 tests/ref/fate/stereo3d
diff --git a/doc/APIchanges b/doc/APIchanges
index f6b583e..f191b81 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2015-08-28
API changes, most recent first:
+2015-10-24 - xxxxxxx - lavu 55.5.100 - stereo3d.h
+ Add serialization and deserialization functions for AVStereo3D
+
2015-10-22 - xxxxxxx - lavc 57.9.100 / lavc 57.5.0 - avcodec.h
Add data and linesize array to AVSubtitleRect, to be used instead of
the ones from the embedded AVPicture.
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 1bac2b9..c924e6e 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -188,6 +188,7 @@ TESTPROGS = adler32 \
ripemd \
sha \
sha512 \
+ stereo3d \
softfloat \
tree \
twofish \
diff --git a/libavutil/stereo3d.c b/libavutil/stereo3d.c
index 50cd928..1804268 100644
--- a/libavutil/stereo3d.c
+++ b/libavutil/stereo3d.c
@@ -23,6 +23,7 @@
#include "mem.h"
#include "stereo3d.h"
+#include "bprint.h"
AVStereo3D *av_stereo3d_alloc(void)
{
@@ -41,3 +42,139 @@ AVStereo3D *av_stereo3d_create_side_data(AVFrame *frame)
return (AVStereo3D *)side_data->data;
}
+
+struct type_name {
+ const char *name;
+ const char *description;
+};
+
+static const struct type_name type_names[] = {
+ [AV_STEREO3D_2D] = {"2D", "2D"},
+ [AV_STEREO3D_SIDEBYSIDE] = {"SBS", "side by side"},
+ [AV_STEREO3D_TOPBOTTOM] = {"TB", "top and bottom"},
+ [AV_STEREO3D_FRAMESEQUENCE] = {"FS", "frame alternate"},
+ [AV_STEREO3D_CHECKERBOARD] = {"CB", "checkerboard"},
+ [AV_STEREO3D_SIDEBYSIDE_QUINCUNX] = {"SBSQ", "side by side (quincunx subsampling)"},
+ [AV_STEREO3D_LINES] = {"LI", "interleaved lines"},
+ [AV_STEREO3D_COLUMNS] = {"CI", "interleaved columns"},
+};
+
+static const struct type_name flag_names[] = {
+ [0] = {"INV", "inverted"}
+};
+
+void av_get_stereo3d_string(char *buf, int buf_size, AVStereo3D *stereo3d, int humanize)
+{
+ AVBPrint bp;
+
+ av_bprint_init_for_buffer(&bp, buf, buf_size);
+ av_bprint_stereo3d(&bp, stereo3d, humanize);
+}
+
+const char *av_stereo3d_type_get_name(enum AVStereo3DType type)
+{
+ if ((unsigned)type >= FF_ARRAY_ELEMS(type_names))
+ return NULL;
+ return type_names[type].name;
+}
+
+const char *av_stereo3d_type_get_description(enum AVStereo3DType type)
+{
+ if ((unsigned)type >= FF_ARRAY_ELEMS(type_names))
+ return NULL;
+ return type_names[type].description;
+}
+
+void av_bprint_stereo3d(struct AVBPrint *bp, const AVStereo3D *stereo3d, int humanize)
+{
+ int i;
+
+ if ((unsigned)stereo3d->type < FF_ARRAY_ELEMS(type_names))
+ av_bprintf(bp, "%s", humanize ? type_names[stereo3d->type].description
+ : type_names[stereo3d->type].name);
+ else
+ av_bprintf(bp, "%s", humanize ? "unknown" : "UND");
+
+ for (i = 0; i < FF_ARRAY_ELEMS(flag_names); i++) {
+ if (stereo3d->flags & (1 << i)) {
+ if (humanize)
+ av_bprintf(bp, " (%s)", flag_names[i].description);
+ else
+ av_bprintf(bp, "+%s", flag_names[i].name);
+ }
+ }
+}
+
+int av_get_stereo3d(AVStereo3D *stereo3d, const char *name)
+{
+ int found;
+ int i;
+ const char *end = strchr(name, '+');
+ int len;
+
+ if (end)
+ len = end - name;
+ else
+ len = strlen(name);
+
+ found = 0;
+ for (i = 0; i < FF_ARRAY_ELEMS(type_names); i++) {
+ if (!strncmp(name, type_names[i].name, len)) {
+ stereo3d->type = i;
+ found = 1;
+ break;
+ }
+ }
+
+ if (!found)
+ return AVERROR(EINVAL);
+
+ while (end) {
+ name = end + 1;
+ end = strchr(name, '+');
+ if (end)
+ len = end - name;
+ else
+ len = strlen(name);
+
+ found = 0;
+ for (i = 0; i < FF_ARRAY_ELEMS(flag_names); i++) {
+ if (!strncmp(name, flag_names[i].name, len)) {
+ stereo3d->flags |= (1 << i);
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ return AVERROR(EINVAL);
+ }
+
+ return 0;
+}
+
+#ifdef TEST
+
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ int i, j;
+ char buf[64];
+ AVStereo3D stereo3d = {0};
+
+ for (i = 0; i < FF_ARRAY_ELEMS(type_names); i++) {
+ for (j = 0; j < 2; j++) {
+ int flags = j ? AV_STEREO3D_FLAG_INVERT : 0;
+ stereo3d.type = i;
+ stereo3d.flags = flags;
+ av_get_stereo3d_string(buf, sizeof(buf), &stereo3d, 0);
+ memset(&stereo3d, sizeof(stereo3d), 0);
+ av_get_stereo3d(&stereo3d, buf);
+ printf("%s\n", buf);
+ }
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/libavutil/stereo3d.h b/libavutil/stereo3d.h
index 1135dc9..8b8aced 100644
--- a/libavutil/stereo3d.h
+++ b/libavutil/stereo3d.h
@@ -149,4 +149,51 @@ AVStereo3D *av_stereo3d_alloc(void);
*/
AVStereo3D *av_stereo3d_create_side_data(AVFrame *frame);
+/**
+ * Parse a string to an AVStereo3D struct.
+ *
+ * @param stereo3d struct to fill
+ * @param name name to parse, in the format returned by av_bprint_stereo3d() with
+ * humanize = 0
+ * @return 0 on success; negative AVERROR code on error.
+ */
+int av_get_stereo3d(AVStereo3D *stereo3d, const char *name);
+
+/**
+ * Return a description of an AVStereo3D.
+ *
+ * @param buf buffer to write into
+ * @param buf_size size in bytes of the buffer
+ * @param stereo3d the struct to describe
+ * @param humanize if non-zero, returns a human-readable string; see av_bprint_stereo3d()
+ */
+void av_get_stereo3d_string(char *buf, int buf_size, AVStereo3D *stereo3d, int humanize);
+
+struct AVBPrint;
+/**
+ * Append a description of an AVStereo3D to a bprint buffer.
+ *
+ * @param bp buffer to write into
+ * @param stereo3d the struct to describe
+ * @param humanize if non-zero, append a human-readable string. Otherwise, append a
+ machine-readable string that can be parsed with av_get_stereo3d().
+ */
+void av_bprint_stereo3d(struct AVBPrint *bp, const AVStereo3D *stereo3d, int humanize);
+
+/**
+ * Get the name of a given AVStereo3DType.
+ *
+ * @return type name on success, NULL on error.
+ */
+const char *av_stereo3d_type_get_name(enum AVStereo3DType type);
+
+/**
+ * Get the description of a given AVStereo3DType.
+ *
+ * @return type description on success, NULL on error.
+ */
+const char *av_stereo3d_type_get_description(enum AVStereo3DType type);
+
+
+
#endif /* AVUTIL_STEREO3D_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 8ed3b7c..909f9a6 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -56,7 +56,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 55
-#define LIBAVUTIL_VERSION_MINOR 4
+#define LIBAVUTIL_VERSION_MINOR 5
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak
index 022ae6a..4c60b9e 100644
--- a/tests/fate/libavutil.mak
+++ b/tests/fate/libavutil.mak
@@ -107,6 +107,10 @@ FATE_LIBAVUTIL += fate-sha512
fate-sha512: libavutil/sha512-test$(EXESUF)
fate-sha512: CMD = run libavutil/sha512-test
+FATE_LIBAVUTIL += fate-stereo3d
+fate-stereo3d: libavutil/stereo3d-test$(EXESUF)
+fate-stereo3d: CMD = run libavutil/stereo3d-test
+
FATE_LIBAVUTIL += fate-tree
fate-tree: libavutil/tree-test$(EXESUF)
fate-tree: CMD = run libavutil/tree-test
diff --git a/tests/ref/fate/stereo3d b/tests/ref/fate/stereo3d
new file mode 100644
index 0000000..12f2d3c
--- /dev/null
+++ b/tests/ref/fate/stereo3d
@@ -0,0 +1,16 @@
+2D
+2D+INV
+SBS
+SBS+INV
+TB
+TB+INV
+FS
+FS+INV
+CB
+CB+INV
+SBSQ
+SBSQ+INV
+LI
+LI+INV
+CI
+CI+INV
--
2.6.2
More information about the ffmpeg-devel
mailing list