FfmpegDecoderPlugin.cxx 19.4 KB
Newer Older
1
/*
2
 * Copyright 2003-2018 The Music Player Daemon Project
3
 * http://www.musicpd.org
4 5 6 7 8 9 10 11 12 13
 *
 * 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.
14 15 16 17
 *
 * 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.
18 19
 */

20 21 22
/* necessary because libavutil/common.h uses UINT64_C */
#define __STDC_CONSTANT_MACROS

23
#include "lib/ffmpeg/Time.hxx"
24
#include "FfmpegDecoderPlugin.hxx"
25
#include "lib/ffmpeg/Domain.hxx"
26
#include "lib/ffmpeg/Error.hxx"
27
#include "lib/ffmpeg/LogError.hxx"
28
#include "lib/ffmpeg/Init.hxx"
29
#include "lib/ffmpeg/Buffer.hxx"
30
#include "lib/ffmpeg/Frame.hxx"
31
#include "lib/ffmpeg/Format.hxx"
32
#include "lib/ffmpeg/Codec.hxx"
33
#include "lib/ffmpeg/SampleFormat.hxx"
34
#include "../DecoderAPI.hxx"
35
#include "FfmpegMetaData.hxx"
36
#include "FfmpegIo.hxx"
37
#include "pcm/Interleave.hxx"
38 39
#include "tag/Builder.hxx"
#include "tag/Handler.hxx"
40 41
#include "tag/ReplayGain.hxx"
#include "tag/MixRamp.hxx"
Max Kellermann's avatar
Max Kellermann committed
42
#include "input/InputStream.hxx"
43
#include "CheckAudioFormat.hxx"
44
#include "util/ScopeExit.hxx"
45
#include "util/ConstBuffer.hxx"
46
#include "LogV.hxx"
47 48

extern "C" {
49 50 51
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
52
#include <libavutil/avutil.h>
53
#include <libavutil/frame.h>
54
}
55

56 57 58
#include <assert.h>
#include <string.h>

59 60 61 62 63
/**
 * Muxer options to be passed to avformat_open_input().
 */
static AVDictionary *avformat_options = nullptr;

64
static Ffmpeg::FormatContext
65
FfmpegOpenInput(AVIOContext *pb,
66
		const char *filename,
67
		AVInputFormat *fmt)
68
{
69
	Ffmpeg::FormatContext context(pb);
70

71 72 73 74
	AVDictionary *options = nullptr;
	AtScopeExit(&options) { av_dict_free(&options); };
	av_dict_copy(&options, avformat_options, 0);

75
	context.OpenInput(filename, fmt, &options);
76

77
	return context;
78 79
}

80
static bool
81
ffmpeg_init(const ConfigBlock &block)
82
{
83
	FfmpegInit();
84 85 86 87 88 89 90 91 92 93 94 95

	static constexpr const char *option_names[] = {
		"probesize",
		"analyzeduration",
	};

	for (const char *name : option_names) {
		const char *value = block.GetBlockValue(name);
		if (value != nullptr)
			av_dict_set(&avformat_options, name, value, 0);
	}

96
	return true;
97 98
}

99
static void
100
ffmpeg_finish() noexcept
101 102 103 104
{
	av_dict_free(&avformat_options);
}

105 106
gcc_pure
static bool
107
IsAudio(const AVStream &stream) noexcept
108
{
109
	return stream.codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
110 111
}

112
gcc_pure
113
static int
114
ffmpeg_find_audio_stream(const AVFormatContext &format_context) noexcept
115
{
116
	for (unsigned i = 0; i < format_context.nb_streams; ++i)
117
		if (IsAudio(*format_context.streams[i]))
118 119 120 121 122
			return i;

	return -1;
}

123 124 125 126 127 128
/**
 * Accessor for AVStream::start_time that replaces AV_NOPTS_VALUE with
 * zero.  We can't use AV_NOPTS_VALUE in calculations, and we simply
 * assume that the stream's start time is zero, which appears to be
 * the best way out of that situation.
 */
129
static constexpr int64_t
130 131
start_time_fallback(const AVStream &stream)
{
132
	return FfmpegTimestampFallback(stream.start_time, 0);
133 134
}

135
/**
136
 * Copy PCM data from a non-empty AVFrame to an interleaved buffer.
137 138
 *
 * Throws #std::exception on error.
139
 */
140
static ConstBuffer<void>
141 142
copy_interleave_frame(const AVCodecContext &codec_context,
		      const AVFrame &frame,
143
		      FfmpegBuffer &global_buffer)
144
{
145 146
	assert(frame.nb_samples > 0);

147 148 149
	int plane_size;
	const int data_size =
		av_samples_get_buffer_size(&plane_size,
150 151 152
					   codec_context.channels,
					   frame.nb_samples,
					   codec_context.sample_fmt, 1);
153
	assert(data_size != 0);
154 155
	if (data_size < 0)
		throw MakeFfmpegError(data_size);
156

157
	void *output_buffer;
158 159
	if (av_sample_fmt_is_planar(codec_context.sample_fmt) &&
	    codec_context.channels > 1) {
160
		output_buffer = global_buffer.GetT<uint8_t>(data_size);
161
		if (output_buffer == nullptr)
162
			/* Not enough memory - shouldn't happen */
163
			throw std::bad_alloc();
164

165 166 167 168 169
		PcmInterleave(output_buffer,
			      ConstBuffer<const void *>((const void *const*)frame.extended_data,
							codec_context.channels),
			      frame.nb_samples,
			      av_get_bytes_per_sample(codec_context.sample_fmt));
170
	} else {
171
		output_buffer = frame.extended_data[0];
172 173
	}

174
	return { output_buffer, (size_t)data_size };
175 176
}

177 178 179 180 181 182
/**
 * Convert AVPacket::pts to a stream-relative time stamp (still in
 * AVStream::time_base units).  Returns a negative value on error.
 */
gcc_pure
static int64_t
183
StreamRelativePts(const AVPacket &packet, const AVStream &stream) noexcept
184 185 186 187 188 189 190 191 192
{
	auto pts = packet.pts;
	if (pts < 0 || pts == int64_t(AV_NOPTS_VALUE))
		return -1;

	auto start = start_time_fallback(stream);
	return pts - start;
}

193 194 195 196 197 198 199
/**
 * Convert a non-negative stream-relative time stamp in
 * AVStream::time_base units to a PCM frame number.
 */
gcc_pure
static uint64_t
PtsToPcmFrame(uint64_t pts, const AVStream &stream,
200
	      const AVCodecContext &codec_context) noexcept
201 202 203 204
{
	return av_rescale_q(pts, stream.time_base, codec_context.time_base);
}

205
/**
206 207
 * Invoke DecoderClient::SubmitData() with the contents of an
 * #AVFrame.
208 209
 */
static DecoderCommand
210
FfmpegSendFrame(DecoderClient &client, InputStream &is,
211 212 213 214 215
		AVCodecContext &codec_context,
		const AVFrame &frame,
		size_t &skip_bytes,
		FfmpegBuffer &buffer)
{
216 217
	ConstBuffer<void> output_buffer =
		copy_interleave_frame(codec_context, frame, buffer);
218 219 220 221 222 223 224 225 226 227 228 229 230

	if (skip_bytes > 0) {
		if (skip_bytes >= output_buffer.size) {
			skip_bytes -= output_buffer.size;
			return DecoderCommand::NONE;
		}

		output_buffer.data =
			(const uint8_t *)output_buffer.data + skip_bytes;
		output_buffer.size -= skip_bytes;
		skip_bytes = 0;
	}

231 232 233
	return client.SubmitData(is,
				 output_buffer.data, output_buffer.size,
				 codec_context.bit_rate / 1000);
234 235
}

236
static DecoderCommand
237
FfmpegReceiveFrames(DecoderClient &client, InputStream &is,
238 239 240 241 242 243 244 245 246 247 248 249
		    AVCodecContext &codec_context,
		    AVFrame &frame,
		    size_t &skip_bytes,
		    FfmpegBuffer &buffer,
		    bool &eof)
{
	while (true) {
		DecoderCommand cmd;

		int err = avcodec_receive_frame(&codec_context, &frame);
		switch (err) {
		case 0:
250
			cmd = FfmpegSendFrame(client, is, codec_context,
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
					      frame, skip_bytes,
					      buffer);
			if (cmd != DecoderCommand::NONE)
				return cmd;

			break;

		case AVERROR_EOF:
			eof = true;
			return DecoderCommand::NONE;

		case AVERROR(EAGAIN):
			/* need to call avcodec_send_packet() */
			return DecoderCommand::NONE;

		default:
			{
				char msg[256];
				av_strerror(err, msg, sizeof(msg));
				FormatWarning(ffmpeg_domain,
					      "avcodec_send_packet() failed: %s",
					      msg);
			}

			return DecoderCommand::STOP;
		}
	}
}

280 281 282
/**
 * Decode an #AVPacket and send the resulting PCM data to the decoder
 * API.
Max Kellermann's avatar
Max Kellermann committed
283
 *
284 285 286
 * @param min_frame skip all data before this PCM frame number; this
 * is used after seeking to skip data in an AVPacket until the exact
 * desired time stamp has been reached
287
 */
288
static DecoderCommand
289
ffmpeg_send_packet(DecoderClient &client, InputStream &is,
290
		   AVPacket &&packet,
291 292 293
		   AVCodecContext &codec_context,
		   const AVStream &stream,
		   AVFrame &frame,
294
		   uint64_t min_frame, size_t pcm_frame_size,
295
		   FfmpegBuffer &buffer)
296
{
297 298
	size_t skip_bytes = 0;

Max Kellermann's avatar
Max Kellermann committed
299
	const auto pts = StreamRelativePts(packet, stream);
300
	if (pts >= 0) {
301
		if (min_frame > 0) {
Max Kellermann's avatar
Max Kellermann committed
302 303
			auto cur_frame = PtsToPcmFrame(pts, stream,
						       codec_context);
304 305 306
			if (cur_frame < min_frame)
				skip_bytes = pcm_frame_size * (min_frame - cur_frame);
		} else
307 308
			client.SubmitTimestamp(FfmpegTimeToDouble(pts,
								  stream.time_base));
309
	}
310

311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
	bool eof = false;

	int err = avcodec_send_packet(&codec_context, &packet);
	switch (err) {
	case 0:
		break;

	case AVERROR_EOF:
		eof = true;
		break;

	default:
		{
			char msg[256];
			av_strerror(err, msg, sizeof(msg));
			FormatWarning(ffmpeg_domain,
				      "avcodec_send_packet() failed: %s", msg);
		}

		return DecoderCommand::NONE;
	}

333
	auto cmd = FfmpegReceiveFrames(client, is, codec_context,
334 335 336 337 338
				       frame,
				       skip_bytes, buffer, eof);

	if (eof)
		cmd = DecoderCommand::STOP;
339

340
	return cmd;
341 342
}

343
static DecoderCommand
344
ffmpeg_send_packet(DecoderClient &client, InputStream &is,
345 346 347
		   const AVPacket &packet,
		   AVCodecContext &codec_context,
		   const AVStream &stream,
348
		   AVFrame &frame,
349 350 351
		   uint64_t min_frame, size_t pcm_frame_size,
		   FfmpegBuffer &buffer)
{
352
	return ffmpeg_send_packet(client, is,
353 354 355 356 357 358 359 360
				  /* copy the AVPacket, because FFmpeg
				     < 3.0 requires this */
				  AVPacket(packet),
				  codec_context, stream,
				  frame, min_frame, pcm_frame_size,
				  buffer);
}

361
gcc_const
362
static SampleFormat
363
ffmpeg_sample_format(enum AVSampleFormat sample_fmt) noexcept
364
{
365 366 367
	const auto result = Ffmpeg::FromFfmpegSampleFormat(sample_fmt);
	if (result != SampleFormat::UNDEFINED)
		return result;
368 369 370 371

	char buffer[64];
	const char *name = av_get_sample_fmt_string(buffer, sizeof(buffer),
						    sample_fmt);
372
	if (name != nullptr)
373 374 375
		FormatError(ffmpeg_domain,
			    "Unsupported libavcodec SampleFormat value: %s (%d)",
			    name, sample_fmt);
376
	else
377 378 379
		FormatError(ffmpeg_domain,
			    "Unsupported libavcodec SampleFormat value: %d",
			    sample_fmt);
380
	return SampleFormat::UNDEFINED;
381 382
}

383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
static void
FfmpegParseMetaData(AVDictionary &dict, ReplayGainInfo &rg, MixRampInfo &mr)
{
	AVDictionaryEntry *i = nullptr;

	while ((i = av_dict_get(&dict, "", i,
				AV_DICT_IGNORE_SUFFIX)) != nullptr) {
		const char *name = i->key;
		const char *value = i->value;

		if (!ParseReplayGainTag(rg, name, value))
			ParseMixRampTag(mr, name, value);
	}
}

static void
FfmpegParseMetaData(const AVStream &stream,
		    ReplayGainInfo &rg, MixRampInfo &mr)
{
	FfmpegParseMetaData(*stream.metadata, rg, mr);
}

static void
FfmpegParseMetaData(const AVFormatContext &format_context, int audio_stream,
		    ReplayGainInfo &rg, MixRampInfo &mr)
{
409
	assert(audio_stream >= 0);
410

411 412
	FfmpegParseMetaData(*format_context.metadata, rg, mr);
	FfmpegParseMetaData(*format_context.streams[audio_stream],
413 414 415 416
				    rg, mr);
}

static void
417
FfmpegParseMetaData(DecoderClient &client,
418 419 420 421 422 423 424 425 426 427 428
		    const AVFormatContext &format_context, int audio_stream)
{
	ReplayGainInfo rg;
	rg.Clear();

	MixRampInfo mr;
	mr.Clear();

	FfmpegParseMetaData(format_context, audio_stream, rg, mr);

	if (rg.IsDefined())
429
		client.SubmitReplayGain(&rg);
430 431

	if (mr.IsDefined())
432
		client.SubmitMixRamp(std::move(mr));
433 434
}

435
static void
436
FfmpegScanMetadata(const AVStream &stream, TagHandler &handler) noexcept
437
{
438
	FfmpegScanDictionary(stream.metadata, handler);
439 440 441 442
}

static void
FfmpegScanMetadata(const AVFormatContext &format_context, int audio_stream,
443
		   TagHandler &handler) noexcept
444
{
445 446
	assert(audio_stream >= 0);

447
	FfmpegScanDictionary(format_context.metadata, handler);
448
	FfmpegScanMetadata(*format_context.streams[audio_stream],
449
			   handler);
450 451
}

452 453 454 455
static void
FfmpegScanTag(const AVFormatContext &format_context, int audio_stream,
	      TagBuilder &tag)
{
456 457
	FullTagHandler h(tag);
	FfmpegScanMetadata(format_context, audio_stream, h);
458 459 460 461
}

/**
 * Check if a new stream tag was received and pass it to
462
 * DecoderClient::SubmitTag().
463 464
 */
static void
465
FfmpegCheckTag(DecoderClient &client, InputStream &is,
466 467 468 469 470 471 472 473 474 475 476 477
	       AVFormatContext &format_context, int audio_stream)
{
	AVStream &stream = *format_context.streams[audio_stream];
	if ((stream.event_flags & AVSTREAM_EVENT_FLAG_METADATA_UPDATED) == 0)
		/* no new metadata */
		return;

	/* clear the flag */
	stream.event_flags &= ~AVSTREAM_EVENT_FLAG_METADATA_UPDATED;

	TagBuilder tag;
	FfmpegScanTag(format_context, audio_stream, tag);
478
	if (!tag.empty())
479
		client.SubmitTag(is, tag.Commit());
480 481
}

482
static void
483
FfmpegDecode(DecoderClient &client, InputStream &input,
484
	     AVFormatContext &format_context)
485
{
486
	const int find_result =
487
		avformat_find_stream_info(&format_context, nullptr);
488
	if (find_result < 0) {
489
		LogError(ffmpeg_domain, "Couldn't find stream info");
490 491
		return;
	}
492

493
	int audio_stream = ffmpeg_find_audio_stream(format_context);
494
	if (audio_stream == -1) {
495
		LogError(ffmpeg_domain, "No audio stream inside");
496 497
		return;
	}
498

499
	AVStream &av_stream = *format_context.streams[audio_stream];
500

501
	const auto &codec_params = *av_stream.codecpar;
502 503

	const AVCodecDescriptor *codec_descriptor =
504
		avcodec_descriptor_get(codec_params.codec_id);
505 506 507
	if (codec_descriptor != nullptr)
		FormatDebug(ffmpeg_domain, "codec '%s'",
			    codec_descriptor->name);
508

509
	AVCodec *codec = avcodec_find_decoder(codec_params.codec_id);
510 511

	if (!codec) {
512
		LogError(ffmpeg_domain, "Unsupported audio codec");
513 514 515
		return;
	}

516 517 518
	Ffmpeg::CodecContext codec_context(*codec);
	codec_context.FillFromParameters(*av_stream.codecpar);
	codec_context.Open(*codec, nullptr);
519

520
	const SampleFormat sample_format =
521
		ffmpeg_sample_format(codec_context->sample_fmt);
522 523
	if (sample_format == SampleFormat::UNDEFINED) {
		// (error message already done by ffmpeg_sample_format())
524
		return;
525
	}
526

527
	const auto audio_format = CheckAudioFormat(codec_context->sample_rate,
528
						   sample_format,
529
						   codec_context->channels);
530

531
	const SignedSongTime total_time =
532 533 534
		av_stream.duration != (int64_t)AV_NOPTS_VALUE
		? FromFfmpegTimeChecked(av_stream.duration, av_stream.time_base)
		: FromFfmpegTimeChecked(format_context.duration, AV_TIME_BASE_Q);
535

536
	client.Ready(audio_format, input.IsSeekable(), total_time);
537

538
	FfmpegParseMetaData(client, format_context, audio_stream);
539

540
	Ffmpeg::Frame frame;
541

542
	FfmpegBuffer interleaved_buffer;
543

544 545
	uint64_t min_frame = 0;

546
	DecoderCommand cmd = client.GetCommand();
547 548 549
	while (cmd != DecoderCommand::STOP) {
		if (cmd == DecoderCommand::SEEK) {
			int64_t where =
550
				ToFfmpegTime(client.GetSeekTime(),
551 552 553 554 555 556 557 558
					     av_stream.time_base) +
				start_time_fallback(av_stream);

			/* AVSEEK_FLAG_BACKWARD asks FFmpeg to seek to
			   the packet boundary before the seek time
			   stamp, not after */
			if (av_seek_frame(&format_context, audio_stream, where,
					  AVSEEK_FLAG_ANY|AVSEEK_FLAG_BACKWARD) < 0)
559
				client.SeekError();
560
			else {
561
				codec_context.FlushBuffers();
562 563
				min_frame = client.GetSeekFrame();
				client.CommandFinished();
564 565 566
			}
		}

567
		AVPacket packet;
568
		if (av_read_frame(&format_context, &packet) < 0)
569 570 571
			/* end of file */
			break;

572 573 574 575
		AtScopeExit(&packet) {
			av_packet_unref(&packet);
		};

576
		FfmpegCheckTag(client, input, format_context, audio_stream);
577

578
		if (packet.size > 0 && packet.stream_index == audio_stream) {
579
			cmd = ffmpeg_send_packet(client, input,
580
						 packet,
581
						 *codec_context,
582
						 av_stream,
583
						 *frame,
584
						 min_frame, audio_format.GetFrameSize(),
585
						 interleaved_buffer);
586 587
			min_frame = 0;
		} else
588
			cmd = client.GetCommand();
589
	}
590 591 592
}

static void
593
ffmpeg_decode(DecoderClient &client, InputStream &input)
594
{
595
	AvioStream stream(&client, input);
596 597 598 599 600
	if (!stream.Open()) {
		LogError(ffmpeg_domain, "Failed to open stream");
		return;
	}

601
	auto format_context =
602
		FfmpegOpenInput(stream.io, input.GetURI(), nullptr);
603

604 605 606 607
	const auto *input_format = format_context->iformat;
	FormatDebug(ffmpeg_domain, "detected input format '%s' (%s)",
		    input_format->name, input_format->long_name);

608
	FfmpegDecode(client, input, *format_context);
609 610
}

611 612
static bool
FfmpegScanStream(AVFormatContext &format_context,
613
		 TagHandler &handler) noexcept
614 615 616 617 618 619
{
	const int find_result =
		avformat_find_stream_info(&format_context, nullptr);
	if (find_result < 0)
		return false;

620 621 622 623
	const int audio_stream = ffmpeg_find_audio_stream(format_context);
	if (audio_stream < 0)
		return false;

624 625
	const AVStream &stream = *format_context.streams[audio_stream];
	if (stream.duration != (int64_t)AV_NOPTS_VALUE)
626 627
		handler.OnDuration(FromFfmpegTime(stream.duration,
						  stream.time_base));
628
	else if (format_context.duration != (int64_t)AV_NOPTS_VALUE)
629 630
		handler.OnDuration(FromFfmpegTime(format_context.duration,
						  AV_TIME_BASE_Q));
631

632
	const auto &codec_params = *stream.codecpar;
633 634
	try {
		handler.OnAudioFormat(CheckAudioFormat(codec_params.sample_rate,
635
						       ffmpeg_sample_format(AVSampleFormat(codec_params.format)),
636 637 638 639
						       codec_params.channels));
	} catch (...) {
	}

640
	FfmpegScanMetadata(format_context, audio_stream, handler);
641 642 643 644

	return true;
}

645
static bool
646
ffmpeg_scan_stream(InputStream &is, TagHandler &handler) noexcept
647
try {
648 649
	AvioStream stream(nullptr, is);
	if (!stream.Open())
650
		return false;
651

652
	auto f = FfmpegOpenInput(stream.io, is.GetURI(), nullptr);
653
	return FfmpegScanStream(*f, handler);
654 655
} catch (...) {
	return false;
656 657 658
}

/**
659 660 661 662
 * A list of extensions found for the formats supported by ffmpeg.
 * This list is current as of 02-23-09; To find out if there are more
 * supported formats, check the ffmpeg changelog since this date for
 * more formats.
663
 */
Max Kellermann's avatar
Max Kellermann committed
664
static const char *const ffmpeg_suffixes[] = {
665 666
	"16sv", "3g2", "3gp", "4xm", "8svx",
	"aa3", "aac", "ac3", "adx", "afc", "aif",
667 668 669 670
	"aifc", "aiff", "al", "alaw", "amr", "anim", "apc", "ape", "asf",
	"atrac", "au", "aud", "avi", "avm2", "avs", "bap", "bfi", "c93", "cak",
	"cin", "cmv", "cpk", "daud", "dct", "divx", "dts", "dv", "dvd", "dxa",
	"eac3", "film", "flac", "flc", "fli", "fll", "flx", "flv", "g726",
671 672 673
	"gsm", "gxf", "iss", "m1v", "m2v", "m2t", "m2ts",
	"m4a", "m4b", "m4v",
	"mad",
674 675 676
	"mj2", "mjpeg", "mjpg", "mka", "mkv", "mlp", "mm", "mmf", "mov", "mp+",
	"mp1", "mp2", "mp3", "mp4", "mpc", "mpeg", "mpg", "mpga", "mpp", "mpu",
	"mve", "mvi", "mxf", "nc", "nsv", "nut", "nuv", "oga", "ogm", "ogv",
677
	"ogx", "oma", "ogg", "omg", "opus", "psp", "pva", "qcp", "qt", "r3d", "ra",
678
	"ram", "rl2", "rm", "rmvb", "roq", "rpl", "rvc", "shn", "smk", "snd",
679
	"sol", "son", "spx", "str", "swf", "tak", "tgi", "tgq", "tgv", "thp", "ts",
680
	"tsp", "tta", "xa", "xvid", "uv", "uv2", "vb", "vid", "vob", "voc",
681 682
	"vp6", "vmd", "wav", "webm", "wma", "wmv", "wsaud", "wsvga", "wv",
	"wve",
683
	nullptr
684 685
};

Max Kellermann's avatar
Max Kellermann committed
686
static const char *const ffmpeg_mime_types[] = {
687
	"application/flv",
688
	"application/m4a",
689 690 691 692 693
	"application/mp4",
	"application/octet-stream",
	"application/ogg",
	"application/x-ms-wmz",
	"application/x-ms-wmd",
694
	"application/x-ogg",
695 696 697 698 699
	"application/x-shockwave-flash",
	"application/x-shorten",
	"audio/8svx",
	"audio/16sv",
	"audio/aac",
700
	"audio/aacp",
701
	"audio/ac3",
702
	"audio/aiff"
703 704 705
	"audio/amr",
	"audio/basic",
	"audio/flac",
706 707
	"audio/m4a",
	"audio/mp4",
708 709 710
	"audio/mpeg",
	"audio/musepack",
	"audio/ogg",
711
	"audio/opus",
712 713
	"audio/qcelp",
	"audio/vorbis",
714
	"audio/vorbis+ogg",
715 716 717 718
	"audio/x-8svx",
	"audio/x-16sv",
	"audio/x-aac",
	"audio/x-ac3",
719
	"audio/x-adx",
720 721 722 723 724 725 726 727
	"audio/x-aiff"
	"audio/x-alaw",
	"audio/x-au",
	"audio/x-dca",
	"audio/x-eac3",
	"audio/x-flac",
	"audio/x-gsm",
	"audio/x-mace",
728
	"audio/x-matroska",
729 730
	"audio/x-monkeys-audio",
	"audio/x-mpeg",
731 732
	"audio/x-ms-wma",
	"audio/x-ms-wax",
733
	"audio/x-musepack",
734 735 736
	"audio/x-ogg",
	"audio/x-vorbis",
	"audio/x-vorbis+ogg",
737 738 739 740
	"audio/x-pn-realaudio",
	"audio/x-pn-multirate-realaudio",
	"audio/x-speex",
	"audio/x-tta"
741
	"audio/x-voc",
742 743 744 745 746 747 748 749
	"audio/x-wav",
	"audio/x-wma",
	"audio/x-wv",
	"video/anim",
	"video/quicktime",
	"video/msvideo",
	"video/ogg",
	"video/theora",
750
	"video/webm",
751 752 753 754 755 756 757
	"video/x-dv",
	"video/x-flv",
	"video/x-matroska",
	"video/x-mjpeg",
	"video/x-mpeg",
	"video/x-ms-asf",
	"video/x-msvideo",
758 759 760 761
	"video/x-ms-wmv",
	"video/x-ms-wvx",
	"video/x-ms-wm",
	"video/x-ms-wmx",
762 763 764 765 766 767
	"video/x-nut",
	"video/x-pva",
	"video/x-theora",
	"video/x-vid",
	"video/x-wmv",
	"video/x-xvid",
768 769 770 771 772 773

	/* special value for the "ffmpeg" input plugin: all streams by
	   the "ffmpeg" input plugin shall be decoded by this
	   plugin */
	"audio/x-mpd-ffmpeg",

774
	nullptr
775 776
};

777
const struct DecoderPlugin ffmpeg_decoder_plugin = {
778 779
	"ffmpeg",
	ffmpeg_init,
780
	ffmpeg_finish,
781 782 783 784 785 786 787
	ffmpeg_decode,
	nullptr,
	nullptr,
	ffmpeg_scan_stream,
	nullptr,
	ffmpeg_suffixes,
	ffmpeg_mime_types
788
};