2010-01-30 16:57:40 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer 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.
|
|
|
|
*
|
|
|
|
* MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2002-03-25 21:06:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2011-08-21 19:47:59 +00:00
|
|
|
#include <stdbool.h>
|
2011-12-22 03:54:48 +00:00
|
|
|
#include <assert.h>
|
2002-03-25 21:06:01 +00:00
|
|
|
|
2011-08-21 19:13:49 +00:00
|
|
|
#include <libavcodec/avcodec.h>
|
2012-01-28 11:41:36 +00:00
|
|
|
#include <libavutil/opt.h>
|
2013-07-11 17:20:41 +00:00
|
|
|
#include <libavutil/common.h>
|
2011-08-21 19:13:49 +00:00
|
|
|
|
2011-08-21 19:47:59 +00:00
|
|
|
#include "talloc.h"
|
|
|
|
|
2002-03-25 21:06:01 +00:00
|
|
|
#include "config.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/av_common.h"
|
|
|
|
#include "common/codecs.h"
|
|
|
|
#include "common/msg.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/av_opts.h"
|
2002-03-25 21:06:01 +00:00
|
|
|
|
2013-07-22 12:41:56 +00:00
|
|
|
#include "ad.h"
|
2012-11-03 13:06:53 +00:00
|
|
|
#include "audio/fmt-conversion.h"
|
2002-03-25 21:06:01 +00:00
|
|
|
|
2012-11-10 15:19:45 +00:00
|
|
|
#include "compat/libav.h"
|
2002-03-25 21:06:01 +00:00
|
|
|
|
2011-08-21 19:47:59 +00:00
|
|
|
struct priv {
|
|
|
|
AVCodecContext *avctx;
|
2012-04-18 22:26:56 +00:00
|
|
|
AVFrame *avframe;
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
struct mp_audio frame;
|
2013-04-06 23:27:33 +00:00
|
|
|
bool force_channel_map;
|
2013-07-11 17:20:41 +00:00
|
|
|
struct demux_packet *packet;
|
2011-08-21 19:47:59 +00:00
|
|
|
};
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
static void uninit(struct dec_audio *da);
|
|
|
|
static int decode_new_packet(struct dec_audio *da);
|
2013-07-22 12:41:56 +00:00
|
|
|
|
2014-06-10 23:39:51 +00:00
|
|
|
#define OPT_BASE_STRUCT struct ad_lavc_params
|
|
|
|
struct ad_lavc_params {
|
|
|
|
float ac3drc;
|
|
|
|
int downmix;
|
|
|
|
int threads;
|
|
|
|
char *avopt;
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct m_sub_options ad_lavc_conf = {
|
|
|
|
.opts = (const m_option_t[]) {
|
|
|
|
OPT_FLOATRANGE("ac3drc", ac3drc, 0, 0, 2),
|
|
|
|
OPT_FLAG("downmix", downmix, 0),
|
|
|
|
OPT_INTRANGE("threads", threads, 0, 1, 16),
|
|
|
|
OPT_STRING("o", avopt, 0),
|
|
|
|
{0}
|
|
|
|
},
|
|
|
|
.size = sizeof(struct ad_lavc_params),
|
|
|
|
.defaults = &(const struct ad_lavc_params){
|
|
|
|
.ac3drc = 1.,
|
|
|
|
.downmix = 1,
|
|
|
|
.threads = 1,
|
|
|
|
},
|
2011-08-21 19:47:59 +00:00
|
|
|
};
|
|
|
|
|
2012-12-09 17:53:24 +00:00
|
|
|
struct pcm_map
|
|
|
|
{
|
|
|
|
int tag;
|
2013-11-11 17:40:59 +00:00
|
|
|
const char *codecs[6]; // {any, 1byte, 2bytes, 3bytes, 4bytes, 8bytes}
|
2012-12-09 17:53:24 +00:00
|
|
|
};
|
|
|
|
|
2013-11-11 17:40:59 +00:00
|
|
|
// NOTE: these are needed to make rawaudio with demux_mkv work.
|
2012-12-09 17:53:24 +00:00
|
|
|
static const struct pcm_map tag_map[] = {
|
|
|
|
// Microsoft PCM
|
|
|
|
{0x0, {NULL, "pcm_u8", "pcm_s16le", "pcm_s24le", "pcm_s32le"}},
|
|
|
|
{0x1, {NULL, "pcm_u8", "pcm_s16le", "pcm_s24le", "pcm_s32le"}},
|
|
|
|
// MS PCM, Extended
|
|
|
|
{0xfffe, {NULL, "pcm_u8", "pcm_s16le", "pcm_s24le", "pcm_s32le"}},
|
|
|
|
// IEEE float
|
2013-11-11 17:40:59 +00:00
|
|
|
{0x3, {"pcm_f32le", [5] = "pcm_f64le"}},
|
2012-12-09 17:53:24 +00:00
|
|
|
// 'raw '
|
|
|
|
{0x20776172, {"pcm_s16be", [1] = "pcm_u8"}},
|
2013-11-11 17:40:59 +00:00
|
|
|
// 'twos', used by demux_mkv.c internally
|
|
|
|
{MKTAG('t', 'w', 'o', 's'),
|
|
|
|
{NULL, "pcm_s8", "pcm_s16be", "pcm_s24be", "pcm_s32be"}},
|
2012-12-09 17:53:24 +00:00
|
|
|
{-1},
|
|
|
|
};
|
|
|
|
|
|
|
|
// For demux_rawaudio.c; needed because ffmpeg doesn't have these sample
|
|
|
|
// formats natively.
|
|
|
|
static const struct pcm_map af_map[] = {
|
|
|
|
{AF_FORMAT_U8, {"pcm_u8"}},
|
|
|
|
{AF_FORMAT_S8, {"pcm_u8"}},
|
|
|
|
{AF_FORMAT_U16_LE, {"pcm_u16le"}},
|
|
|
|
{AF_FORMAT_U16_BE, {"pcm_u16be"}},
|
|
|
|
{AF_FORMAT_S16_LE, {"pcm_s16le"}},
|
|
|
|
{AF_FORMAT_S16_BE, {"pcm_s16be"}},
|
|
|
|
{AF_FORMAT_U24_LE, {"pcm_u24le"}},
|
|
|
|
{AF_FORMAT_U24_BE, {"pcm_u24be"}},
|
|
|
|
{AF_FORMAT_S24_LE, {"pcm_s24le"}},
|
|
|
|
{AF_FORMAT_S24_BE, {"pcm_s24be"}},
|
|
|
|
{AF_FORMAT_U32_LE, {"pcm_u32le"}},
|
|
|
|
{AF_FORMAT_U32_BE, {"pcm_u32be"}},
|
|
|
|
{AF_FORMAT_S32_LE, {"pcm_s32le"}},
|
|
|
|
{AF_FORMAT_S32_BE, {"pcm_s32be"}},
|
|
|
|
{AF_FORMAT_FLOAT_LE, {"pcm_f32le"}},
|
|
|
|
{AF_FORMAT_FLOAT_BE, {"pcm_f32be"}},
|
2013-11-11 17:40:59 +00:00
|
|
|
{AF_FORMAT_DOUBLE_LE, {"pcm_f64le"}},
|
|
|
|
{AF_FORMAT_DOUBLE_BE, {"pcm_f64be"}},
|
2012-12-09 17:53:24 +00:00
|
|
|
{-1},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *find_pcm_decoder(const struct pcm_map *map, int format,
|
|
|
|
int bits_per_sample)
|
|
|
|
{
|
|
|
|
int bytes = (bits_per_sample + 7) / 8;
|
2013-11-11 17:40:59 +00:00
|
|
|
if (bytes == 8)
|
|
|
|
bytes = 5; // 64 bit entry
|
2012-12-09 17:53:24 +00:00
|
|
|
for (int n = 0; map[n].tag != -1; n++) {
|
|
|
|
const struct pcm_map *entry = &map[n];
|
|
|
|
if (entry->tag == format) {
|
|
|
|
const char *dec = NULL;
|
2013-11-11 17:40:59 +00:00
|
|
|
if (bytes >= 1 && bytes <= 5)
|
2012-12-09 17:53:24 +00:00
|
|
|
dec = entry->codecs[bytes];
|
|
|
|
if (!dec)
|
|
|
|
dec = entry->codecs[0];
|
|
|
|
if (dec)
|
|
|
|
return dec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
static int setup_format(struct dec_audio *da)
|
2010-07-15 17:59:46 +00:00
|
|
|
{
|
2013-11-23 20:22:17 +00:00
|
|
|
struct priv *priv = da->priv;
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
AVCodecContext *lavc_context = priv->avctx;
|
2013-11-23 20:22:17 +00:00
|
|
|
struct sh_audio *sh_audio = da->header->audio;
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
|
2013-11-26 23:11:35 +00:00
|
|
|
// Note: invalid parameters are rejected by dec_audio.c
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
|
2013-12-21 17:29:42 +00:00
|
|
|
int fmt = lavc_context->sample_fmt;
|
|
|
|
mp_audio_set_format(&da->decoded, af_from_avformat(fmt));
|
|
|
|
if (!da->decoded.format)
|
|
|
|
MP_FATAL(da, "unsupported lavc format %s", av_get_sample_fmt_name(fmt));
|
2013-11-26 23:11:35 +00:00
|
|
|
|
|
|
|
da->decoded.rate = lavc_context->sample_rate;
|
|
|
|
if (!da->decoded.rate && sh_audio->wf) {
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
// If not set, try container samplerate.
|
|
|
|
// (Maybe this can't happen, and it's an artifact from the past.)
|
2013-11-26 23:11:35 +00:00
|
|
|
da->decoded.rate = sh_audio->wf->nSamplesPerSec;
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_WARN(da, "using container rate.\n");
|
2013-07-16 20:44:15 +00:00
|
|
|
}
|
2010-11-21 12:52:08 +00:00
|
|
|
|
2013-04-06 20:43:12 +00:00
|
|
|
struct mp_chmap lavc_chmap;
|
|
|
|
mp_chmap_from_lavc(&lavc_chmap, lavc_context->channel_layout);
|
|
|
|
// No channel layout or layout disagrees with channel count
|
|
|
|
if (lavc_chmap.num != lavc_context->channels)
|
|
|
|
mp_chmap_from_channels(&lavc_chmap, lavc_context->channels);
|
2013-04-06 23:27:33 +00:00
|
|
|
if (priv->force_channel_map) {
|
|
|
|
if (lavc_chmap.num == sh_audio->channels.num)
|
|
|
|
lavc_chmap = sh_audio->channels;
|
|
|
|
}
|
2013-11-23 20:25:05 +00:00
|
|
|
mp_audio_set_channels(&da->decoded, &lavc_chmap);
|
2013-11-26 23:11:35 +00:00
|
|
|
|
2010-07-15 17:59:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-02 14:10:28 +00:00
|
|
|
static void set_from_wf(AVCodecContext *avctx, MP_WAVEFORMATEX *wf)
|
2013-02-09 14:15:32 +00:00
|
|
|
{
|
|
|
|
avctx->channels = wf->nChannels;
|
|
|
|
avctx->sample_rate = wf->nSamplesPerSec;
|
|
|
|
avctx->bit_rate = wf->nAvgBytesPerSec * 8;
|
|
|
|
avctx->block_align = wf->nBlockAlign;
|
|
|
|
avctx->bits_per_coded_sample = wf->wBitsPerSample;
|
|
|
|
|
2014-01-11 00:25:49 +00:00
|
|
|
if (wf->cbSize > 0)
|
|
|
|
mp_lavc_set_extradata(avctx, wf + 1, wf->cbSize);
|
2013-02-09 14:15:32 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
static int init(struct dec_audio *da, const char *decoder)
|
2002-03-25 21:06:01 +00:00
|
|
|
{
|
2013-11-23 20:22:17 +00:00
|
|
|
struct MPOpts *mpopts = da->opts;
|
2014-06-10 23:39:51 +00:00
|
|
|
struct ad_lavc_params *opts = mpopts->ad_lavc_params;
|
2002-04-03 21:01:15 +00:00
|
|
|
AVCodecContext *lavc_context;
|
|
|
|
AVCodec *lavc_codec;
|
2013-11-23 20:37:56 +00:00
|
|
|
struct sh_stream *sh = da->header;
|
|
|
|
struct sh_audio *sh_audio = sh->audio;
|
2002-04-01 13:10:03 +00:00
|
|
|
|
2013-04-06 23:27:33 +00:00
|
|
|
struct priv *ctx = talloc_zero(NULL, struct priv);
|
2013-11-23 20:22:17 +00:00
|
|
|
da->priv = ctx;
|
2013-04-06 23:27:33 +00:00
|
|
|
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
if (sh_audio->wf && strcmp(decoder, "pcm") == 0) {
|
2013-11-23 20:37:56 +00:00
|
|
|
decoder = find_pcm_decoder(tag_map, sh->format,
|
2012-12-09 17:53:24 +00:00
|
|
|
sh_audio->wf->wBitsPerSample);
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
} else if (sh_audio->wf && strcmp(decoder, "mp-pcm") == 0) {
|
2013-11-23 20:37:56 +00:00
|
|
|
decoder = find_pcm_decoder(af_map, sh->format, 0);
|
2013-04-06 23:27:33 +00:00
|
|
|
ctx->force_channel_map = true;
|
2012-12-09 17:53:24 +00:00
|
|
|
}
|
|
|
|
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
lavc_codec = avcodec_find_decoder_by_name(decoder);
|
|
|
|
if (!lavc_codec) {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_ERR(da, "Cannot find codec '%s' in libavcodec...\n", decoder);
|
2013-11-23 20:22:17 +00:00
|
|
|
uninit(da);
|
2011-08-21 19:13:49 +00:00
|
|
|
return 0;
|
2002-03-25 21:06:01 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2012-01-28 11:41:36 +00:00
|
|
|
lavc_context = avcodec_alloc_context3(lavc_codec);
|
2011-08-21 19:47:59 +00:00
|
|
|
ctx->avctx = lavc_context;
|
2014-03-16 11:50:15 +00:00
|
|
|
ctx->avframe = av_frame_alloc();
|
|
|
|
lavc_context->refcounted_frames = 1;
|
demux_lavf, ad_lavc, vd_lavc: pass codec header data directly
Instead of putting codec header data into WAVEFORMATEX and
BITMAPINFOHEADER, pass it directly via AVCodecContext. To do this, we
add mp_copy_lav_codec_headers(), which copies the codec header data
from one AVCodecContext to another (originally, the plan was to use
avcodec_copy_context() for this, but it looks like this would turn
decoder initialization into an even worse mess).
Get rid of the silly CodecID <-> codec_tag mapping. This was originally
needed for codecs.conf: codec tags were used to identify codecs, but
libavformat didn't always return useful codec tags (different file
formats can have different, overlapping tag numbers). Since we don't
go through WAVEFORMATEX etc. and pass all header data directly via
AVCodecContext, we can be absolutely sure that the codec tag mapping is
not needed anymore.
Note that this also destroys the "standard" MPlayer method of exporting
codec header data. WAVEFORMATEX and BITMAPINFOHEADER made sure that
other non-libavcodec decoders could be initialized. However, all these
decoders have been removed, so this is just cruft full of old hacks that
are not needed anymore. There's still ad_spdif and ad_mpg123, bu neither
of these need codec header data. Should we ever add non-libavcodec
decoders, better data structures without the past hacks could be added
to export the headers.
2013-02-09 14:15:37 +00:00
|
|
|
lavc_context->codec_type = AVMEDIA_TYPE_AUDIO;
|
|
|
|
lavc_context->codec_id = lavc_codec->id;
|
|
|
|
|
2013-04-06 20:43:12 +00:00
|
|
|
if (opts->downmix) {
|
|
|
|
lavc_context->request_channel_layout =
|
|
|
|
mp_chmap_to_lavc(&mpopts->audio_output_channels);
|
|
|
|
}
|
2002-10-28 00:40:42 +00:00
|
|
|
|
2012-01-28 11:41:36 +00:00
|
|
|
// Always try to set - option only exists for AC3 at the moment
|
2013-03-31 02:24:53 +00:00
|
|
|
av_opt_set_double(lavc_context, "drc_scale", opts->ac3drc,
|
2012-01-28 11:41:36 +00:00
|
|
|
AV_OPT_SEARCH_CHILDREN);
|
demux_lavf, ad_lavc, vd_lavc: pass codec header data directly
Instead of putting codec header data into WAVEFORMATEX and
BITMAPINFOHEADER, pass it directly via AVCodecContext. To do this, we
add mp_copy_lav_codec_headers(), which copies the codec header data
from one AVCodecContext to another (originally, the plan was to use
avcodec_copy_context() for this, but it looks like this would turn
decoder initialization into an even worse mess).
Get rid of the silly CodecID <-> codec_tag mapping. This was originally
needed for codecs.conf: codec tags were used to identify codecs, but
libavformat didn't always return useful codec tags (different file
formats can have different, overlapping tag numbers). Since we don't
go through WAVEFORMATEX etc. and pass all header data directly via
AVCodecContext, we can be absolutely sure that the codec tag mapping is
not needed anymore.
Note that this also destroys the "standard" MPlayer method of exporting
codec header data. WAVEFORMATEX and BITMAPINFOHEADER made sure that
other non-libavcodec decoders could be initialized. However, all these
decoders have been removed, so this is just cruft full of old hacks that
are not needed anymore. There's still ad_spdif and ad_mpg123, bu neither
of these need codec header data. Should we ever add non-libavcodec
decoders, better data structures without the past hacks could be added
to export the headers.
2013-02-09 14:15:37 +00:00
|
|
|
|
2013-03-31 02:24:53 +00:00
|
|
|
if (opts->avopt) {
|
|
|
|
if (parse_avopts(lavc_context, opts->avopt) < 0) {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_ERR(da, "setting AVOptions '%s' failed.\n", opts->avopt);
|
2013-11-23 20:22:17 +00:00
|
|
|
uninit(da);
|
2013-03-31 02:24:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-23 20:37:56 +00:00
|
|
|
lavc_context->codec_tag = sh->format;
|
2007-08-27 15:51:04 +00:00
|
|
|
lavc_context->sample_rate = sh_audio->samplerate;
|
2014-05-26 22:15:41 +00:00
|
|
|
lavc_context->bit_rate = sh_audio->bitrate;
|
2013-04-06 20:43:12 +00:00
|
|
|
lavc_context->channel_layout = mp_chmap_to_lavc(&sh_audio->channels);
|
2013-02-09 14:15:32 +00:00
|
|
|
|
|
|
|
if (sh_audio->wf)
|
|
|
|
set_from_wf(lavc_context, sh_audio->wf);
|
2002-10-28 00:40:42 +00:00
|
|
|
|
demux_lavf, ad_lavc, vd_lavc: pass codec header data directly
Instead of putting codec header data into WAVEFORMATEX and
BITMAPINFOHEADER, pass it directly via AVCodecContext. To do this, we
add mp_copy_lav_codec_headers(), which copies the codec header data
from one AVCodecContext to another (originally, the plan was to use
avcodec_copy_context() for this, but it looks like this would turn
decoder initialization into an even worse mess).
Get rid of the silly CodecID <-> codec_tag mapping. This was originally
needed for codecs.conf: codec tags were used to identify codecs, but
libavformat didn't always return useful codec tags (different file
formats can have different, overlapping tag numbers). Since we don't
go through WAVEFORMATEX etc. and pass all header data directly via
AVCodecContext, we can be absolutely sure that the codec tag mapping is
not needed anymore.
Note that this also destroys the "standard" MPlayer method of exporting
codec header data. WAVEFORMATEX and BITMAPINFOHEADER made sure that
other non-libavcodec decoders could be initialized. However, all these
decoders have been removed, so this is just cruft full of old hacks that
are not needed anymore. There's still ad_spdif and ad_mpg123, bu neither
of these need codec header data. Should we ever add non-libavcodec
decoders, better data structures without the past hacks could be added
to export the headers.
2013-02-09 14:15:37 +00:00
|
|
|
// demux_mkv, demux_mpg
|
2011-08-21 19:13:49 +00:00
|
|
|
if (sh_audio->codecdata_len && sh_audio->codecdata &&
|
|
|
|
!lavc_context->extradata) {
|
2014-01-11 00:25:49 +00:00
|
|
|
mp_lavc_set_extradata(lavc_context, sh_audio->codecdata,
|
|
|
|
sh_audio->codecdata_len);
|
2005-02-01 19:19:40 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 20:37:56 +00:00
|
|
|
if (sh->lav_headers)
|
|
|
|
mp_copy_lav_codec_headers(lavc_context, sh->lav_headers);
|
demux_lavf, ad_lavc, vd_lavc: pass codec header data directly
Instead of putting codec header data into WAVEFORMATEX and
BITMAPINFOHEADER, pass it directly via AVCodecContext. To do this, we
add mp_copy_lav_codec_headers(), which copies the codec header data
from one AVCodecContext to another (originally, the plan was to use
avcodec_copy_context() for this, but it looks like this would turn
decoder initialization into an even worse mess).
Get rid of the silly CodecID <-> codec_tag mapping. This was originally
needed for codecs.conf: codec tags were used to identify codecs, but
libavformat didn't always return useful codec tags (different file
formats can have different, overlapping tag numbers). Since we don't
go through WAVEFORMATEX etc. and pass all header data directly via
AVCodecContext, we can be absolutely sure that the codec tag mapping is
not needed anymore.
Note that this also destroys the "standard" MPlayer method of exporting
codec header data. WAVEFORMATEX and BITMAPINFOHEADER made sure that
other non-libavcodec decoders could be initialized. However, all these
decoders have been removed, so this is just cruft full of old hacks that
are not needed anymore. There's still ad_spdif and ad_mpg123, bu neither
of these need codec header data. Should we ever add non-libavcodec
decoders, better data structures without the past hacks could be added
to export the headers.
2013-02-09 14:15:37 +00:00
|
|
|
|
2013-12-04 19:58:53 +00:00
|
|
|
mp_set_avcodec_threads(lavc_context, opts->threads);
|
|
|
|
|
2002-03-25 21:06:01 +00:00
|
|
|
/* open it */
|
2012-01-28 11:41:36 +00:00
|
|
|
if (avcodec_open2(lavc_context, lavc_codec, NULL) < 0) {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_ERR(da, "Could not open codec.\n");
|
2013-11-23 20:22:17 +00:00
|
|
|
uninit(da);
|
2002-03-25 21:06:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_VERBOSE(da, "INFO: libavcodec \"%s\" init OK!\n",
|
2011-08-21 19:13:49 +00:00
|
|
|
lavc_codec->name);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
// Decode at least 1 sample: (to get header filled)
|
|
|
|
for (int tries = 1; ; tries++) {
|
2013-11-23 20:22:17 +00:00
|
|
|
int x = decode_new_packet(da);
|
2013-11-26 00:49:17 +00:00
|
|
|
if (x >= 0 && ctx->frame.samples > 0) {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_VERBOSE(da, "Initial decode succeeded after %d packets.\n", tries);
|
2011-08-21 19:13:49 +00:00
|
|
|
break;
|
2013-11-26 00:49:17 +00:00
|
|
|
}
|
|
|
|
if (tries >= 50) {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_ERR(da, "initial decode failed\n");
|
2013-11-23 20:22:17 +00:00
|
|
|
uninit(da);
|
2011-08-21 19:13:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2002-03-25 21:06:01 +00:00
|
|
|
|
2014-05-27 14:45:53 +00:00
|
|
|
if (lavc_context->bit_rate != 0)
|
|
|
|
da->bitrate = lavc_context->bit_rate;
|
|
|
|
else if (sh_audio->wf && sh_audio->wf->nAvgBytesPerSec)
|
2014-05-26 22:15:41 +00:00
|
|
|
da->bitrate = sh_audio->wf->nAvgBytesPerSec * 8;
|
2010-07-15 17:59:46 +00:00
|
|
|
|
2011-08-21 19:13:49 +00:00
|
|
|
return 1;
|
2002-03-25 21:06:01 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
static void uninit(struct dec_audio *da)
|
2002-03-25 21:06:01 +00:00
|
|
|
{
|
2013-11-23 20:22:17 +00:00
|
|
|
struct priv *ctx = da->priv;
|
2011-08-21 20:04:20 +00:00
|
|
|
if (!ctx)
|
|
|
|
return;
|
2011-08-21 19:47:59 +00:00
|
|
|
AVCodecContext *lavc_context = ctx->avctx;
|
2002-10-28 00:40:42 +00:00
|
|
|
|
2011-08-21 20:04:20 +00:00
|
|
|
if (lavc_context) {
|
2012-01-28 11:41:36 +00:00
|
|
|
if (avcodec_close(lavc_context) < 0)
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_ERR(da, "Could not close codec.\n");
|
2011-08-21 20:04:20 +00:00
|
|
|
av_freep(&lavc_context->extradata);
|
|
|
|
av_freep(&lavc_context);
|
|
|
|
}
|
2014-03-16 11:50:15 +00:00
|
|
|
av_frame_free(&ctx->avframe);
|
2002-03-25 21:06:01 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
static int control(struct dec_audio *da, int cmd, void *arg)
|
2002-03-25 21:06:01 +00:00
|
|
|
{
|
2013-11-23 20:22:17 +00:00
|
|
|
struct priv *ctx = da->priv;
|
2011-08-21 19:13:49 +00:00
|
|
|
switch (cmd) {
|
2013-11-27 19:54:07 +00:00
|
|
|
case ADCTRL_RESET:
|
2011-08-21 19:47:59 +00:00
|
|
|
avcodec_flush_buffers(ctx->avctx);
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
ctx->frame.samples = 0;
|
2013-07-11 17:20:41 +00:00
|
|
|
talloc_free(ctx->packet);
|
|
|
|
ctx->packet = NULL;
|
2011-08-21 19:13:49 +00:00
|
|
|
return CONTROL_TRUE;
|
2004-02-18 15:23:41 +00:00
|
|
|
}
|
|
|
|
return CONTROL_UNKNOWN;
|
2002-03-25 21:06:01 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
static int decode_new_packet(struct dec_audio *da)
|
2012-04-18 22:26:56 +00:00
|
|
|
{
|
2013-11-23 20:22:17 +00:00
|
|
|
struct priv *priv = da->priv;
|
2012-04-18 22:26:56 +00:00
|
|
|
AVCodecContext *avctx = priv->avctx;
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
|
|
|
|
priv->frame.samples = 0;
|
|
|
|
|
2013-07-11 17:20:41 +00:00
|
|
|
struct demux_packet *mpkt = priv->packet;
|
|
|
|
if (!mpkt)
|
2013-11-23 20:22:17 +00:00
|
|
|
mpkt = demux_read_packet(da->header);
|
2012-04-18 22:26:56 +00:00
|
|
|
|
2013-07-11 17:20:41 +00:00
|
|
|
priv->packet = talloc_steal(priv, mpkt);
|
|
|
|
|
2013-12-04 19:57:52 +00:00
|
|
|
int in_len = mpkt ? mpkt->len : 0;
|
2013-07-11 17:10:33 +00:00
|
|
|
|
2012-04-18 22:26:56 +00:00
|
|
|
AVPacket pkt;
|
av_common: add timebase parameter to mp_set_av_packet()
If the timebase is set, it's used for converting the packet timestamps.
Otherwise, the previous method of reinterpret-casting the mpv style
double timestamps to libavcodec style int64_t timestamps is used.
Also replace the kind of awkward mp_get_av_frame_pkt_ts() function by
mp_pts_from_av(), which simply converts timestamps in a way the old
function did. (Plus it takes a timebase parameter, similar to the
addition to mp_set_av_packet().)
Note that this should not change anything yet. The code in ad_lavc.c and
vd_lavc.c passes NULL for the timebase parameters. We could set
AVCodecContext.pkt_timebase and use that if we want to give libavcodec
"proper" timestamps.
This could be important for ad_lavc.c: some codecs (opus, probably mp3
and aac too) have weird requirements about doing decoding preroll on the
container level, and thus require adjusting the audio start timestamps
in some cases. libavcodec doesn't tell us how much was skipped, so we
either get shifted timestamps (by the length of the skipped data), or we
give it proper timestamps. (Note: libavcodec interprets or changes
timestamps only if pkt_timebase is set, which by default it is not.)
This would require selecting a timebase though, so I feel uncomfortable
with the idea. At least this change paves the way, and will allow some
testing.
2013-12-04 19:12:14 +00:00
|
|
|
mp_set_av_packet(&pkt, mpkt, NULL);
|
2013-06-02 23:55:48 +00:00
|
|
|
|
2013-12-04 19:57:52 +00:00
|
|
|
// If we don't have a PTS yet, use the first packet PTS we can get.
|
|
|
|
if (da->pts == MP_NOPTS_VALUE && mpkt && mpkt->pts != MP_NOPTS_VALUE) {
|
2013-11-23 20:22:17 +00:00
|
|
|
da->pts = mpkt->pts;
|
|
|
|
da->pts_offset = 0;
|
2012-04-18 22:26:56 +00:00
|
|
|
}
|
2013-12-04 19:57:52 +00:00
|
|
|
|
2012-04-18 22:26:56 +00:00
|
|
|
int got_frame = 0;
|
2014-03-16 11:50:15 +00:00
|
|
|
av_frame_unref(priv->avframe);
|
2012-04-18 22:26:56 +00:00
|
|
|
int ret = avcodec_decode_audio4(avctx, priv->avframe, &got_frame, &pkt);
|
2013-12-04 19:57:52 +00:00
|
|
|
if (mpkt) {
|
|
|
|
// At least "shorten" decodes sub-frames, instead of the whole packet.
|
|
|
|
// At least "mpc8" can return 0 and wants the packet again next time.
|
|
|
|
if (ret >= 0) {
|
|
|
|
ret = FFMIN(ret, mpkt->len); // sanity check against decoder overreads
|
|
|
|
mpkt->buffer += ret;
|
|
|
|
mpkt->len -= ret;
|
|
|
|
mpkt->pts = MP_NOPTS_VALUE; // don't reset PTS next time
|
|
|
|
}
|
|
|
|
if (mpkt->len == 0 || ret < 0) {
|
|
|
|
talloc_free(mpkt);
|
|
|
|
priv->packet = NULL;
|
|
|
|
}
|
2013-12-04 22:30:01 +00:00
|
|
|
// LATM may need many packets to find mux info
|
|
|
|
if (ret == AVERROR(EAGAIN))
|
|
|
|
return 0;
|
2013-07-11 17:20:41 +00:00
|
|
|
}
|
2012-04-18 22:26:56 +00:00
|
|
|
if (ret < 0) {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_VERBOSE(da, "lavc_audio: error\n");
|
2012-04-18 22:26:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!got_frame)
|
2013-12-04 19:57:52 +00:00
|
|
|
return mpkt ? 0 : -1; // -1: eof
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
if (setup_format(da) < 0)
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
priv->frame.samples = priv->avframe->nb_samples;
|
2013-11-23 20:25:05 +00:00
|
|
|
mp_audio_copy_config(&priv->frame, &da->decoded);
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
for (int n = 0; n < priv->frame.num_planes; n++)
|
|
|
|
priv->frame.planes[n] = priv->avframe->data[n];
|
|
|
|
|
2013-12-04 19:57:52 +00:00
|
|
|
double out_pts = mp_pts_from_av(priv->avframe->pkt_pts, NULL);
|
|
|
|
if (out_pts != MP_NOPTS_VALUE) {
|
|
|
|
da->pts = out_pts;
|
|
|
|
da->pts_offset = 0;
|
|
|
|
}
|
|
|
|
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_DBG(da, "Decoded %d -> %d samples\n", in_len,
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
priv->frame.samples);
|
2012-04-18 22:26:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
static int decode_audio(struct dec_audio *da, struct mp_audio *buffer, int maxlen)
|
2002-03-25 21:06:01 +00:00
|
|
|
{
|
2013-11-23 20:22:17 +00:00
|
|
|
struct priv *priv = da->priv;
|
2011-08-21 19:13:49 +00:00
|
|
|
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
if (!priv->frame.samples) {
|
2013-11-23 20:22:17 +00:00
|
|
|
if (decode_new_packet(da) < 0)
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
return -1;
|
2002-03-25 21:06:01 +00:00
|
|
|
}
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
|
|
|
|
if (!mp_audio_config_equals(buffer, &priv->frame))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
buffer->samples = MPMIN(priv->frame.samples, maxlen);
|
|
|
|
mp_audio_copy(buffer, 0, &priv->frame, 0, buffer->samples);
|
|
|
|
mp_audio_skip_samples(&priv->frame, buffer->samples);
|
2013-11-23 20:22:17 +00:00
|
|
|
da->pts_offset += buffer->samples;
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
return 0;
|
2002-03-25 21:06:01 +00:00
|
|
|
}
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
|
|
|
|
static void add_decoders(struct mp_decoder_list *list)
|
|
|
|
{
|
|
|
|
mp_add_lavc_decoders(list, AVMEDIA_TYPE_AUDIO);
|
|
|
|
mp_add_decoder(list, "lavc", "pcm", "pcm", "Raw PCM");
|
|
|
|
mp_add_decoder(list, "lavc", "mp-pcm", "mp-pcm", "Raw PCM");
|
|
|
|
}
|
2013-07-22 12:41:56 +00:00
|
|
|
|
|
|
|
const struct ad_functions ad_lavc = {
|
|
|
|
.name = "lavc",
|
|
|
|
.add_decoders = add_decoders,
|
|
|
|
.init = init,
|
|
|
|
.uninit = uninit,
|
|
|
|
.control = control,
|
|
|
|
.decode_audio = decode_audio,
|
|
|
|
};
|