1 #include "testing/testing.h"
4 #include <libavcodec/avcodec.h>
5 #include <libavutil/log.h>
10 bool test_vcodec(AVCodec *codec, AVPixelFormat pixelformat)
12 av_log_set_level(AV_LOG_QUIET);
15 AVCodecContext *ctx = avcodec_alloc_context3(codec);
17 ctx->time_base.num = 1;
18 ctx->time_base.den = 25;
19 ctx->pix_fmt = pixelformat;
22 int open = avcodec_open2(ctx, codec,
NULL);
24 avcodec_free_context(&ctx);
31 bool test_acodec(AVCodec *codec, AVSampleFormat fmt)
33 av_log_set_level(AV_LOG_QUIET);
36 AVCodecContext *ctx = avcodec_alloc_context3(codec);
38 ctx->sample_fmt = fmt;
39 ctx->sample_rate = 48000;
40 ctx->channel_layout = AV_CH_LAYOUT_MONO;
41 ctx->bit_rate = 128000;
42 int open = avcodec_open2(ctx, codec,
NULL);
44 avcodec_free_context(&ctx);
52 bool test_codec_video_by_codecid(AVCodecID codec_id, AVPixelFormat pixelformat)
55 AVCodec *codec = avcodec_find_encoder(codec_id);
57 result = test_vcodec(codec, pixelformat);
61 bool test_codec_video_by_name(
const char *codecname, AVPixelFormat pixelformat)
64 AVCodec *codec = avcodec_find_encoder_by_name(codecname);
66 result = test_vcodec(codec, pixelformat);
70 bool test_codec_audio_by_codecid(AVCodecID codec_id, AVSampleFormat fmt)
73 AVCodec *codec = avcodec_find_encoder(codec_id);
75 result = test_acodec(codec, fmt);
79 bool test_codec_audio_by_name(
const char *codecname, AVSampleFormat fmt)
82 AVCodec *codec = avcodec_find_encoder_by_name(codecname);
84 result = test_acodec(codec, fmt);
89 #define FFMPEG_TEST_VCODEC_ID(codec, fmt) \
90 TEST(ffmpeg, codec##_##fmt) \
92 EXPECT_TRUE(test_codec_video_by_codecid(codec, fmt)); \
95 #define FFMPEG_TEST_VCODEC_NAME(codec, fmt) \
96 TEST(ffmpeg, codec##_##fmt) \
98 EXPECT_TRUE(test_codec_video_by_name(str(codec), fmt)); \
101 #define FFMPEG_TEST_ACODEC_ID(codec, fmt) \
102 TEST(ffmpeg, codec##_##fmt) \
104 EXPECT_TRUE(test_codec_audio_by_codecid(codec, fmt)); \
107 #define FFMPEG_TEST_ACODEC_NAME(codec, fmt) \
108 TEST(ffmpeg, codec) \
110 EXPECT_TRUE(test_codec_audio_by_name(str(codec), fmt)); \
#define FFMPEG_TEST_VCODEC_NAME(codec, fmt)
#define FFMPEG_TEST_ACODEC_NAME(codec, fmt)
#define FFMPEG_TEST_ACODEC_ID(codec, fmt)
#define FFMPEG_TEST_VCODEC_ID(codec, fmt)