FfmpegDecoderPlugin.cxx 19.4 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2019 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/Init.hxx"
28
#include "lib/ffmpeg/Buffer.hxx"
29
#include "lib/ffmpeg/Frame.hxx"
30
#include "lib/ffmpeg/Format.hxx"
31
#include "lib/ffmpeg/Codec.hxx"
32
#include "lib/ffmpeg/SampleFormat.hxx"
33
#include "../DecoderAPI.hxx"
34
#include "FfmpegMetaData.hxx"
35
#include "FfmpegIo.hxx"
36
#include "pcm/Interleave.hxx"
37 38
#include "tag/Builder.hxx"
#include "tag/Handler.hxx"
39 40
#include "tag/ReplayGain.hxx"
#include "tag/MixRamp.hxx"
Max Kellermann's avatar
Max Kellermann committed
41
#include "input/InputStream.hxx"
42
#include "CheckAudioFormat.hxx"
43
#include "util/ScopeExit.hxx"
44
#include "util/ConstBuffer.hxx"
45
#include "LogV.hxx"
46 47

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

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

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

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

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

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

76
	return context;
77 78
}

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

	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);
	}

95
	return true;
96 97
}

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

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

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

	return -1;
}

122 123 124 125 126 127
/**
 * 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.
 */
128
static constexpr int64_t
129 130
start_time_fallback(const AVStream &stream)
{
131
	return FfmpegTimestampFallback(stream.start_time, 0);
132 133
}

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

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

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

164 165 166 167 168
		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));
169
	} else {
170
		output_buffer = frame.extended_data[0];
171 172
	}

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

176 177 178 179 180 181
/**
 * 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
182
StreamRelativePts(const AVPacket &packet, const AVStream &stream) noexcept
183 184 185 186 187 188 189 190 191
{
	auto pts = packet.pts;
	if (pts < 0 || pts == int64_t(AV_NOPTS_VALUE))
		return -1;

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

192 193 194 195 196 197 198
/**
 * 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,
199
	      const AVCodecContext &codec_context) noexcept
200 201 202 203
{
	return av_rescale_q(pts, stream.time_base, codec_context.time_base);
}

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

	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;
	}

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

235
static DecoderCommand
236
FfmpegReceiveFrames(DecoderClient &client, InputStream &is,
237 238 239 240 241 242 243 244 245 246 247 248
		    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:
249
			cmd = FfmpegSendFrame(client, is, codec_context,
250 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
					      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;
		}
	}
}

279 280 281
/**
 * Decode an #AVPacket and send the resulting PCM data to the decoder
 * API.
Max Kellermann's avatar
Max Kellermann committed
282
 *
283 284 285
 * @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
286
 */
287
static DecoderCommand
288
ffmpeg_send_packet(DecoderClient &client, InputStream &is,
289
		   AVPacket &&packet,
290 291 292
		   AVCodecContext &codec_context,
		   const AVStream &stream,
		   AVFrame &frame,
293
		   uint64_t min_frame, size_t pcm_frame_size,
294
		   FfmpegBuffer &buffer)
295
{
296 297
	size_t skip_bytes = 0;

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

310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
	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;
	}

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

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

339
	return cmd;
340 341
}

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

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

	char buffer[64];
	const char *name = av_get_sample_fmt_string(buffer, sizeof(buffer),
						    sample_fmt);
371
	if (name != nullptr)
372 373 374
		FormatError(ffmpeg_domain,
			    "Unsupported libavcodec SampleFormat value: %s (%d)",
			    name, sample_fmt);
375
	else
376 377 378
		FormatError(ffmpeg_domain,
			    "Unsupported libavcodec SampleFormat value: %d",
			    sample_fmt);
379
	return SampleFormat::UNDEFINED;
380 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
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)
{
408
	assert(audio_stream >= 0);
409

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

static void
416
FfmpegParseMetaData(DecoderClient &client,
417 418 419 420 421 422 423 424 425 426 427
		    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())
428
		client.SubmitReplayGain(&rg);
429 430

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

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

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

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

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

/**
 * Check if a new stream tag was received and pass it to
461
 * DecoderClient::SubmitTag().
462 463
 */
static void
464
FfmpegCheckTag(DecoderClient &client, InputStream &is,
465 466 467 468 469 470 471 472 473 474 475 476
	       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);
477
	if (!tag.empty())
478
		client.SubmitTag(is, tag.Commit());
479 480
}

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

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

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

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

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

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

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

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

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

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

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

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

537
	FfmpegParseMetaData(client, format_context, audio_stream);
538

539
	Ffmpeg::Frame frame;
540

541
	FfmpegBuffer interleaved_buffer;
542

543 544
	uint64_t min_frame = 0;

545
	DecoderCommand cmd = client.GetCommand();
546 547 548
	while (cmd != DecoderCommand::STOP) {
		if (cmd == DecoderCommand::SEEK) {
			int64_t where =
549
				ToFfmpegTime(client.GetSeekTime(),
550 551 552 553 554 555 556 557
					     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)
558
				client.SeekError();
559
			else {
560
				codec_context.FlushBuffers();
561 562
				min_frame = client.GetSeekFrame();
				client.CommandFinished();
563 564 565
			}
		}

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

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

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

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

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

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

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

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

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

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

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

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

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

	return true;
}

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

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

/**
658 659 660 661
 * 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.
662
 */
Max Kellermann's avatar
Max Kellermann committed
663
static const char *const ffmpeg_suffixes[] = {
664 665
	"16sv", "3g2", "3gp", "4xm", "8svx",
	"aa3", "aac", "ac3", "adx", "afc", "aif",
666 667 668 669
	"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",
670 671 672
	"gsm", "gxf", "iss", "m1v", "m2v", "m2t", "m2ts",
	"m4a", "m4b", "m4v",
	"mad",
673 674 675
	"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",
676
	"ogx", "oma", "ogg", "omg", "opus", "psp", "pva", "qcp", "qt", "r3d", "ra",
677
	"ram", "rl2", "rm", "rmvb", "roq", "rpl", "rvc", "shn", "smk", "snd",
678
	"sol", "son", "spx", "str", "swf", "tak", "tgi", "tgq", "tgv", "thp", "ts",
679
	"tsp", "tta", "xa", "xvid", "uv", "uv2", "vb", "vid", "vob", "voc",
680 681
	"vp6", "vmd", "wav", "webm", "wma", "wmv", "wsaud", "wsvga", "wv",
	"wve",
682
	nullptr
683 684
};

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

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

773
	nullptr
774 775
};

776 777 778 779 780
constexpr DecoderPlugin ffmpeg_decoder_plugin =
	DecoderPlugin("ffmpeg", ffmpeg_decode, ffmpeg_scan_stream)
	.WithInit(ffmpeg_init, ffmpeg_finish)
	.WithSuffixes(ffmpeg_suffixes)
	.WithMimeTypes(ffmpeg_mime_types);