3 #include "testing/testing.h"
8 #include <libavcodec/avcodec.h>
9 #include <libavutil/channel_layout.h>
10 #include <libavutil/log.h>
15 bool test_vcodec(
const AVCodec *codec, AVPixelFormat pixelformat)
17 av_log_set_level(AV_LOG_QUIET);
20 AVCodecContext *ctx = avcodec_alloc_context3(codec);
22 ctx->time_base.num = 1;
23 ctx->time_base.den = 25;
24 ctx->pix_fmt = pixelformat;
27 int open = avcodec_open2(ctx, codec,
NULL);
29 avcodec_free_context(&ctx);
36 bool test_acodec(
const AVCodec *codec, AVSampleFormat fmt)
38 av_log_set_level(AV_LOG_QUIET);
41 AVCodecContext *ctx = avcodec_alloc_context3(codec);
43 ctx->sample_fmt = fmt;
44 ctx->sample_rate = 48000;
45 #ifdef FFMPEG_USE_OLD_CHANNEL_VARS
46 ctx->channel_layout = AV_CH_LAYOUT_MONO;
48 av_channel_layout_from_mask(&ctx->ch_layout, AV_CH_LAYOUT_MONO);
50 ctx->bit_rate = 128000;
51 int open = avcodec_open2(ctx, codec,
NULL);
53 avcodec_free_context(&ctx);
61 bool test_codec_video_by_codecid(AVCodecID codec_id, AVPixelFormat pixelformat)
64 const AVCodec *codec = avcodec_find_encoder(codec_id);
66 result = test_vcodec(codec, pixelformat);
70 bool test_codec_video_by_name(
const char *codecname, AVPixelFormat pixelformat)
73 const AVCodec *codec = avcodec_find_encoder_by_name(codecname);
75 result = test_vcodec(codec, pixelformat);
79 bool test_codec_audio_by_codecid(AVCodecID codec_id, AVSampleFormat fmt)
82 const AVCodec *codec = avcodec_find_encoder(codec_id);
84 result = test_acodec(codec, fmt);
88 bool test_codec_audio_by_name(
const char *codecname, AVSampleFormat fmt)
91 const AVCodec *codec = avcodec_find_encoder_by_name(codecname);
93 result = test_acodec(codec, fmt);
98 #define FFMPEG_TEST_VCODEC_ID(codec, fmt) \
99 TEST(ffmpeg, codec##_##fmt) \
101 EXPECT_TRUE(test_codec_video_by_codecid(codec, fmt)); \
104 #define FFMPEG_TEST_VCODEC_NAME(codec, fmt) \
105 TEST(ffmpeg, codec##_##fmt) \
107 EXPECT_TRUE(test_codec_video_by_name(str(codec), fmt)); \
110 #define FFMPEG_TEST_ACODEC_ID(codec, fmt) \
111 TEST(ffmpeg, codec##_##fmt) \
113 EXPECT_TRUE(test_codec_audio_by_codecid(codec, fmt)); \
116 #define FFMPEG_TEST_ACODEC_NAME(codec, fmt) \
117 TEST(ffmpeg, codec) \
119 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)