Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRay Molenkamp <github@lazydodo.com>2020-01-14 21:31:02 +0300
committerRay Molenkamp <github@lazydodo.com>2020-01-14 21:31:02 +0300
commitf8b34d5ca45d9a35bec1c93717cac43f422c9877 (patch)
tree4a8ea3cc4890567909ded51c12f284a4f64de46b /tests
parent8e6c6e2ba103b16a5a7de766647e105c80237dd1 (diff)
test: Add basic codec test for ffmpeg.
This add a basic sanity check that validates the features we use from ffmpeg are actually available Differential Revision: https://developer.blender.org/D5999 Reviewed By: sybren
Diffstat (limited to 'tests')
-rw-r--r--tests/gtests/CMakeLists.txt3
-rw-r--r--tests/gtests/ffmpeg/CMakeLists.txt37
-rw-r--r--tests/gtests/ffmpeg/ffmpeg_codecs.cc147
3 files changed, 187 insertions, 0 deletions
diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt
index 7da65bcc8b9..bcf77fb6de7 100644
--- a/tests/gtests/CMakeLists.txt
+++ b/tests/gtests/CMakeLists.txt
@@ -16,6 +16,9 @@ if(WITH_GTESTS)
add_subdirectory(blenloader)
add_subdirectory(guardedalloc)
add_subdirectory(bmesh)
+ if(WITH_CODEC_FFMPEG)
+ add_subdirectory(ffmpeg)
+ endif()
if(WITH_ALEMBIC)
add_subdirectory(alembic)
endif()
diff --git a/tests/gtests/ffmpeg/CMakeLists.txt b/tests/gtests/ffmpeg/CMakeLists.txt
new file mode 100644
index 00000000000..2ccdd1ffa55
--- /dev/null
+++ b/tests/gtests/ffmpeg/CMakeLists.txt
@@ -0,0 +1,37 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# The Original Code is Copyright (C) 2014, Blender Foundation
+# All rights reserved.
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+ .
+ ..
+ ${FFMPEG_INCLUDE_DIRS}
+)
+
+set(LIB
+
+)
+
+include_directories(${INC})
+
+setup_libdirs()
+
+BLENDER_SRC_GTEST(ffmpeg "ffmpeg_codecs.cc" "${LIB}")
+
+setup_liblinks(ffmpeg_test)
diff --git a/tests/gtests/ffmpeg/ffmpeg_codecs.cc b/tests/gtests/ffmpeg/ffmpeg_codecs.cc
new file mode 100644
index 00000000000..bbf2b3a4111
--- /dev/null
+++ b/tests/gtests/ffmpeg/ffmpeg_codecs.cc
@@ -0,0 +1,147 @@
+#include "testing/testing.h"
+
+extern "C" {
+#include <libavcodec/avcodec.h>
+#include <libavutil/log.h>
+}
+
+bool test_vcodec(AVCodec *codec, AVPixelFormat pixelformat)
+{
+ av_log_set_level(AV_LOG_QUIET);
+ bool result = false;
+ if (codec) {
+ AVCodecContext *ctx = avcodec_alloc_context3(codec);
+ if (ctx) {
+ ctx->time_base.num = 1;
+ ctx->time_base.den = 25;
+ ctx->pix_fmt = pixelformat;
+ ctx->width = 720;
+ ctx->height = 576;
+ int open = avcodec_open2(ctx, codec, NULL);
+ if (open >= 0) {
+ avcodec_free_context(&ctx);
+ result = true;
+ }
+ }
+ }
+ return result;
+}
+bool test_acodec(AVCodec *codec, AVSampleFormat fmt)
+{
+ av_log_set_level(AV_LOG_QUIET);
+ bool result = false;
+ if (codec) {
+ AVCodecContext *ctx = avcodec_alloc_context3(codec);
+ if (ctx) {
+ ctx->sample_fmt = fmt;
+ ctx->sample_rate = 48000;
+ ctx->channel_layout = AV_CH_LAYOUT_MONO;
+ ctx->bit_rate = 128000;
+ int open = avcodec_open2(ctx, codec, NULL);
+ if (open >= 0) {
+ avcodec_free_context(&ctx);
+ result = true;
+ }
+ }
+ }
+ return result;
+}
+
+bool test_codec_video_by_codecid(AVCodecID codec_id, AVPixelFormat pixelformat)
+{
+ bool result = false;
+ AVCodec *codec = avcodec_find_encoder(codec_id);
+ if (codec)
+ result = test_vcodec(codec, pixelformat);
+ return result;
+}
+
+bool test_codec_video_by_name(const char *codecname, AVPixelFormat pixelformat)
+{
+ bool result = false;
+ AVCodec *codec = avcodec_find_encoder_by_name(codecname);
+ if (codec)
+ result = test_vcodec(codec, pixelformat);
+ return result;
+}
+
+bool test_codec_audio_by_codecid(AVCodecID codec_id, AVSampleFormat fmt)
+{
+ bool result = false;
+ AVCodec *codec = avcodec_find_encoder(codec_id);
+ if (codec)
+ result = test_acodec(codec, fmt);
+ return result;
+}
+
+bool test_codec_audio_by_name(const char *codecname, AVSampleFormat fmt)
+{
+ bool result = false;
+ AVCodec *codec = avcodec_find_encoder_by_name(codecname);
+ if (codec)
+ result = test_acodec(codec, fmt);
+ return result;
+}
+
+#define str(s) #s
+#define FFMPEG_TEST_VCODEC_ID(codec, fmt) \
+ TEST(CheckCodec, codec##_##fmt) \
+ { \
+ EXPECT_TRUE(test_codec_video_by_codecid(codec, fmt)); \
+ }
+
+#define FFMPEG_TEST_VCODEC_NAME(codec, fmt) \
+ TEST(CheckCodec, codec##_##fmt) \
+ { \
+ EXPECT_TRUE(test_codec_video_by_name(str(codec), fmt)); \
+ }
+
+#define FFMPEG_TEST_ACODEC_ID(codec, fmt) \
+ TEST(CheckCodec, codec##_##fmt) \
+ { \
+ EXPECT_TRUE(test_codec_audio_by_codecid(codec, fmt)); \
+ }
+
+#define FFMPEG_TEST_ACODEC_NAME(codec, fmt) \
+ TEST(CheckCodec, codec) \
+ { \
+ EXPECT_TRUE(test_codec_audio_by_name(str(codec), fmt)); \
+ }
+
+/* generic codec ID's used in blender */
+
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_HUFFYUV, AV_PIX_FMT_BGRA)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_HUFFYUV, AV_PIX_FMT_RGB32)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_FFV1, AV_PIX_FMT_RGB32)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_QTRLE, AV_PIX_FMT_ARGB)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_VP9, AV_PIX_FMT_YUVA420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_PNG, AV_PIX_FMT_RGBA)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_H264, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_MPEG4, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_THEORA, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_DVVIDEO, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_MPEG1VIDEO, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_MPEG2VIDEO, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_FLV1, AV_PIX_FMT_YUV420P)
+
+/* Audio codecs */
+
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_AAC, AV_SAMPLE_FMT_FLTP)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_AC3, AV_SAMPLE_FMT_FLTP)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_FLAC, AV_SAMPLE_FMT_S16)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_MP2, AV_SAMPLE_FMT_S16)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_MP3, AV_SAMPLE_FMT_FLTP)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_OPUS, AV_SAMPLE_FMT_FLT)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_PCM_S16LE, AV_SAMPLE_FMT_S16)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_VORBIS, AV_SAMPLE_FMT_FLTP)
+
+/* Libraries we count on ffmpeg being linked against */
+
+FFMPEG_TEST_VCODEC_NAME(libtheora, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_NAME(libx264, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_NAME(libvpx, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_NAME(libopenjpeg, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_NAME(libxvid, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_ACODEC_NAME(libvorbis, AV_SAMPLE_FMT_FLTP)
+FFMPEG_TEST_ACODEC_NAME(libopus, AV_SAMPLE_FMT_FLT)
+FFMPEG_TEST_ACODEC_NAME(libmp3lame, AV_SAMPLE_FMT_FLTP)