2010-06-30 09:55:14 +00:00
|
|
|
/*
|
|
|
|
* MPEG 1.0/2.0/2.5 audio layer I, II, III decoding with libmpg123
|
|
|
|
*
|
2013-10-04 17:22:22 +00:00
|
|
|
* Copyright (C) 2010-2013 Thomas Orgis <thomas@orgis.org>
|
2010-06-30 09:55:14 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-07-22 12:41:56 +00:00
|
|
|
#include "ad.h"
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/mp_msg.h"
|
2010-06-30 09:55:14 +00:00
|
|
|
|
|
|
|
#include <mpg123.h>
|
|
|
|
|
2013-11-12 21:27:36 +00:00
|
|
|
#if (defined MPG123_API_VERSION) && (MPG123_API_VERSION < 33)
|
|
|
|
#error "This should not happen"
|
2012-05-06 16:29:14 +00:00
|
|
|
#endif
|
2010-06-30 09:55:14 +00:00
|
|
|
|
|
|
|
struct ad_mpg123_context {
|
|
|
|
mpg123_handle *handle;
|
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
|
|
|
bool new_format;
|
|
|
|
int sample_size;
|
|
|
|
bool need_data;
|
2010-06-30 09:55:14 +00:00
|
|
|
/* Running mean for bit rate, stream length estimation. */
|
|
|
|
float mean_rate;
|
|
|
|
unsigned int mean_count;
|
|
|
|
/* Time delay for updates. */
|
|
|
|
short delay;
|
|
|
|
/* If the stream is actually VBR. */
|
|
|
|
char vbr;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
static void uninit(sh_audio_t *sh)
|
|
|
|
{
|
|
|
|
struct ad_mpg123_context *con = (struct ad_mpg123_context*) sh->context;
|
|
|
|
|
|
|
|
mpg123_close(con->handle);
|
|
|
|
mpg123_delete(con->handle);
|
|
|
|
talloc_free(sh->context);
|
|
|
|
sh->context = NULL;
|
|
|
|
mpg123_exit();
|
|
|
|
}
|
|
|
|
|
2010-06-30 09:55:14 +00:00
|
|
|
/* This initializes libmpg123 and prepares the handle, including funky
|
|
|
|
* parameters. */
|
|
|
|
static int preinit(sh_audio_t *sh)
|
|
|
|
{
|
2013-06-12 22:59:27 +00:00
|
|
|
int err;
|
2010-06-30 09:55:14 +00:00
|
|
|
struct ad_mpg123_context *con;
|
|
|
|
/* Assumption: You always call preinit + init + uninit, on every file.
|
|
|
|
* But you stop at preinit in case it fails.
|
|
|
|
* If that is not true, one must ensure not to call mpg123_init / exit
|
|
|
|
* twice in a row. */
|
|
|
|
if (mpg123_init() != MPG123_OK)
|
|
|
|
return 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
|
|
|
sh->context = talloc_zero(NULL, struct ad_mpg123_context);
|
2010-06-30 09:55:14 +00:00
|
|
|
con = sh->context;
|
|
|
|
/* Auto-choice of optimized decoder (first argument NULL). */
|
|
|
|
con->handle = mpg123_new(NULL, &err);
|
|
|
|
if (!con->handle)
|
|
|
|
goto bad_end;
|
|
|
|
|
|
|
|
/* Basic settings.
|
|
|
|
* Don't spill messages, enable better resync with non-seekable streams.
|
|
|
|
* Give both flags individually without error checking to keep going with
|
|
|
|
* old libmpg123. Generally, it is not fatal if the flags are not
|
|
|
|
* honored */
|
|
|
|
mpg123_param(con->handle, MPG123_ADD_FLAGS, MPG123_QUIET, 0.0);
|
2010-07-13 15:11:34 +00:00
|
|
|
/* Do not bail out on malformed streams at all.
|
|
|
|
* MPlayer does not handle a decoder throwing the towel on crappy input. */
|
|
|
|
mpg123_param(con->handle, MPG123_RESYNC_LIMIT, -1, 0.0);
|
2010-06-30 09:55:14 +00:00
|
|
|
|
|
|
|
/* Open decisions: Configure libmpg123 to force encoding (or stay open about
|
|
|
|
* library builds that support only float or int32 output), (de)configure
|
|
|
|
* gapless decoding (won't work with seeking in MPlayer, though).
|
|
|
|
* Don't forget to eventually enable ReplayGain/RVA support, too.
|
|
|
|
* Let's try to run with the default for now. */
|
|
|
|
|
2012-05-06 16:29:14 +00:00
|
|
|
/* That would produce floating point output.
|
2013-10-04 17:22:22 +00:00
|
|
|
* You can get 32 and 24 bit ints, even 8 bit via format matrix.
|
|
|
|
* If wanting a specific encoding here, configure format matrix and
|
|
|
|
* make sure it is in set_format(). */
|
2012-05-06 16:29:14 +00:00
|
|
|
/* mpg123_param(con->handle, MPG123_ADD_FLAGS, MPG123_FORCE_FLOAT, 0.); */
|
|
|
|
|
2010-06-30 09:55:14 +00:00
|
|
|
/* Example for RVA choice (available since libmpg123 1.0.0):
|
|
|
|
mpg123_param(con->handle, MPG123_RVA, MPG123_RVA_MIX, 0.0) */
|
|
|
|
|
2012-05-06 16:29:14 +00:00
|
|
|
/* Prevent funky automatic resampling.
|
|
|
|
* This way, we can be sure that one frame will never produce
|
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
|
|
|
* more than 1152 stereo samples.
|
|
|
|
* Background:
|
|
|
|
* Going to decode directly to the output buffer. It is important to have
|
|
|
|
* MPG123_AUTO_RESAMPLE disabled for the buffer size being an all-time
|
|
|
|
* limit.
|
|
|
|
* We need at least 1152 samples. dec_audio.c normally guarantees this. */
|
2012-05-06 16:29:14 +00:00
|
|
|
mpg123_param(con->handle, MPG123_REMOVE_FLAGS, MPG123_AUTO_RESAMPLE, 0.);
|
|
|
|
|
2010-06-30 09:55:14 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
bad_end:
|
|
|
|
if (!con->handle)
|
|
|
|
mp_msg(MSGT_DECAUDIO, MSGL_ERR, "mpg123 preinit error: %s\n",
|
|
|
|
mpg123_plain_strerror(err));
|
|
|
|
else
|
|
|
|
mp_msg(MSGT_DECAUDIO, MSGL_ERR, "mpg123 preinit error: %s\n",
|
|
|
|
mpg123_strerror(con->handle));
|
|
|
|
|
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
|
|
|
uninit(sh);
|
2010-06-30 09:55:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-04 17:22:22 +00:00
|
|
|
/* libmpg123 has a new format ready; query and store, return return value
|
|
|
|
of mpg123_getformat() */
|
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
|
|
|
static int set_format(sh_audio_t *sh)
|
2013-10-04 17:22:22 +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
|
|
|
struct ad_mpg123_context *con = sh->context;
|
2013-10-04 17:22:22 +00:00
|
|
|
int ret;
|
|
|
|
long rate;
|
|
|
|
int channels;
|
|
|
|
int encoding;
|
|
|
|
ret = mpg123_getformat(con->handle, &rate, &channels, &encoding);
|
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 (ret == MPG123_OK) {
|
2013-10-04 17:22:22 +00:00
|
|
|
mp_chmap_from_channels(&sh->channels, channels);
|
|
|
|
sh->samplerate = rate;
|
|
|
|
/* Without external force, mpg123 will always choose signed encoding,
|
|
|
|
* and non-16-bit only on builds that don't support it.
|
|
|
|
* Be reminded that it doesn't matter to the MPEG file what encoding
|
|
|
|
* is produced from it. */
|
|
|
|
switch (encoding) {
|
|
|
|
case MPG123_ENC_SIGNED_8:
|
|
|
|
sh->sample_format = AF_FORMAT_S8;
|
|
|
|
break;
|
|
|
|
case MPG123_ENC_SIGNED_16:
|
2013-11-15 20:25:05 +00:00
|
|
|
sh->sample_format = AF_FORMAT_S16;
|
2013-10-04 17:22:22 +00:00
|
|
|
break;
|
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
|
|
|
case MPG123_ENC_SIGNED_32:
|
2013-11-15 20:25:05 +00:00
|
|
|
sh->sample_format = AF_FORMAT_S32;
|
2013-10-04 17:22:22 +00:00
|
|
|
break;
|
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
|
|
|
case MPG123_ENC_FLOAT_32:
|
2013-11-15 20:25:05 +00:00
|
|
|
sh->sample_format = AF_FORMAT_FLOAT;
|
2013-10-04 17:22:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* This means we got a funny custom build of libmpg123 that only supports an unknown format. */
|
|
|
|
mp_msg(MSGT_DECAUDIO, MSGL_ERR,
|
|
|
|
"Bad encoding from mpg123: %i.\n", encoding);
|
|
|
|
return MPG123_ERR;
|
|
|
|
}
|
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
|
|
|
con->sample_size = channels * (af_fmt2bits(sh->sample_format) / 8);
|
2013-10-04 17:22:22 +00:00
|
|
|
con->new_format = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static int feed_new_packet(sh_audio_t *sh)
|
2010-06-30 09:55:14 +00:00
|
|
|
{
|
|
|
|
struct ad_mpg123_context *con = sh->context;
|
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
|
|
|
int ret;
|
2010-06-30 09:55:14 +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
|
|
|
struct demux_packet *pkt = demux_read_packet(sh->gsh);
|
|
|
|
if (!pkt)
|
|
|
|
return -1; /* EOF. */
|
2010-06-30 09:55:14 +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
|
|
|
/* Next bytes from that presentation time. */
|
|
|
|
if (pkt->pts != MP_NOPTS_VALUE) {
|
|
|
|
sh->pts = pkt->pts;
|
|
|
|
sh->pts_offset = 0;
|
2010-06-30 09:55:14 +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
|
|
|
/* Have to use mpg123_feed() to avoid decoding here. */
|
|
|
|
ret = mpg123_feed(con->handle, pkt->buffer, pkt->len);
|
|
|
|
talloc_free(pkt);
|
2010-06-30 09:55:14 +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 (ret == MPG123_ERR)
|
|
|
|
return -1;
|
2010-06-30 09:55:14 +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 (ret == MPG123_NEW_FORMAT)
|
|
|
|
con->new_format = 1;
|
|
|
|
|
|
|
|
return 0;
|
2010-06-30 09:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we really start accessing some data and determining file format.
|
2013-10-04 17:22:22 +00:00
|
|
|
* Format now is allowed to change on-the-fly. Here is the only point
|
|
|
|
* that has MPlayer react to errors. We have to pray that exceptional
|
|
|
|
* erros in other places simply cannot occur. */
|
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 int init(sh_audio_t *sh, const char *decoder)
|
2010-06-30 09:55:14 +00:00
|
|
|
{
|
|
|
|
struct ad_mpg123_context *con = sh->context;
|
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
|
|
|
int ret;
|
2010-06-30 09:55:14 +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
|
|
|
ret = mpg123_open_feed(con->handle);
|
|
|
|
if (ret != MPG123_OK)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
for (int n = 0; ; n++) {
|
|
|
|
if (feed_new_packet(sh) < 0) {
|
|
|
|
ret = MPG123_NEED_MORE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
size_t got_now = 0;
|
|
|
|
ret = mpg123_decode_frame(con->handle, NULL, NULL, &got_now);
|
|
|
|
if (ret == MPG123_OK || ret == MPG123_NEW_FORMAT) {
|
|
|
|
ret = set_format(sh);
|
|
|
|
if (ret == MPG123_OK)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ret != MPG123_NEED_MORE)
|
|
|
|
goto fail;
|
|
|
|
// max. 16 retries (randomly chosen number)
|
|
|
|
if (n > 16) {
|
|
|
|
ret = MPG123_NEED_MORE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2010-06-30 09:55:14 +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
|
|
|
fail:
|
|
|
|
if (ret == MPG123_NEED_MORE) {
|
|
|
|
mp_msg(MSGT_DECAUDIO, MSGL_ERR, "Could not find mp3 stream.\n");
|
2010-06-30 09:55:14 +00:00
|
|
|
} else {
|
|
|
|
mp_msg(MSGT_DECAUDIO, MSGL_ERR, "mpg123 init error: %s\n",
|
|
|
|
mpg123_strerror(con->handle));
|
|
|
|
}
|
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
|
|
|
|
|
|
|
uninit(sh);
|
|
|
|
return 0;
|
2010-06-30 09:55:14 +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
|
|
|
/* Compute bitrate from frame size. */
|
|
|
|
static int compute_bitrate(struct mpg123_frameinfo *i)
|
2010-06-30 09:55:14 +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
|
|
|
static const int samples_per_frame[4][4] = {
|
|
|
|
{-1, 384, 1152, 1152}, /* MPEG 1 */
|
|
|
|
{-1, 384, 1152, 576}, /* MPEG 2 */
|
|
|
|
{-1, 384, 1152, 576}, /* MPEG 2.5 */
|
|
|
|
{-1, -1, -1, -1}, /* Unknown */
|
|
|
|
};
|
|
|
|
return (int) ((i->framesize + 4) * 8 * i->rate * 0.001 /
|
|
|
|
samples_per_frame[i->version][i->layer] + 0.5);
|
2010-06-30 09:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update mean bitrate. This could be dropped if accurate time display
|
|
|
|
* on audio file playback is not desired. */
|
|
|
|
static void update_info(sh_audio_t *sh)
|
|
|
|
{
|
|
|
|
struct ad_mpg123_context *con = sh->context;
|
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 mpg123_frameinfo finfo;
|
|
|
|
if (mpg123_info(con->handle, &finfo) != MPG123_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (finfo.vbr != MPG123_CBR) {
|
|
|
|
if (--con->delay < 1) {
|
2010-06-30 09:55:14 +00:00
|
|
|
if (++con->mean_count > ((unsigned int) -1) / 2)
|
|
|
|
con->mean_count = ((unsigned int) -1) / 4;
|
|
|
|
|
|
|
|
/* Might not be numerically optimal, but works fine enough. */
|
|
|
|
con->mean_rate = ((con->mean_count - 1) * con->mean_rate +
|
|
|
|
finfo.bitrate) / con->mean_count;
|
|
|
|
sh->i_bps = (int) (con->mean_rate * 1000 / 8);
|
|
|
|
|
|
|
|
con->delay = 10;
|
|
|
|
}
|
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
|
|
|
} else {
|
|
|
|
sh->i_bps = (finfo.bitrate ? finfo.bitrate : compute_bitrate(&finfo))
|
|
|
|
* 1000 / 8;
|
|
|
|
con->delay = 1;
|
|
|
|
con->mean_rate = 0.;
|
|
|
|
con->mean_count = 0;
|
2010-06-30 09:55:14 +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
|
|
|
static int decode_audio(sh_audio_t *sh, struct mp_audio *buffer, int maxlen)
|
2010-06-30 09:55:14 +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
|
|
|
struct ad_mpg123_context *con = sh->context;
|
|
|
|
void *buf = buffer->planes[0];
|
|
|
|
int ret;
|
2010-06-30 09:55:14 +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 (con->new_format) {
|
|
|
|
ret = set_format(sh);
|
|
|
|
if (ret == MPG123_OK) {
|
|
|
|
return 0; // let caller handle format change
|
|
|
|
} else if (ret == MPG123_NEED_MORE) {
|
|
|
|
con->need_data = true;
|
|
|
|
} else {
|
|
|
|
goto mpg123_fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (con->need_data) {
|
|
|
|
if (feed_new_packet(sh) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-18 12:45:35 +00:00
|
|
|
if (sh->samplerate != buffer->rate ||
|
|
|
|
!mp_chmap_equals(&sh->channels, &buffer->channels) ||
|
|
|
|
sh->sample_format != buffer->format)
|
|
|
|
return 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
|
|
|
size_t got_now = 0;
|
|
|
|
ret = mpg123_replace_buffer(con->handle, buf, maxlen * con->sample_size);
|
|
|
|
if (ret != MPG123_OK)
|
|
|
|
goto mpg123_fail;
|
|
|
|
|
|
|
|
ret = mpg123_decode_frame(con->handle, NULL, NULL, &got_now);
|
|
|
|
|
|
|
|
int got_samples = got_now / con->sample_size;
|
|
|
|
buffer->samples += got_samples;
|
|
|
|
sh->pts_offset += got_samples;
|
|
|
|
|
|
|
|
if (ret == MPG123_NEW_FORMAT) {
|
|
|
|
con->new_format = true;
|
|
|
|
} else if (ret == MPG123_NEED_MORE) {
|
|
|
|
con->need_data = true;
|
|
|
|
} else if (ret != MPG123_OK && ret != MPG123_DONE) {
|
|
|
|
goto mpg123_fail;
|
|
|
|
}
|
2010-06-30 09:55:14 +00:00
|
|
|
|
|
|
|
update_info(sh);
|
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;
|
|
|
|
|
|
|
|
mpg123_fail:
|
|
|
|
mp_msg(MSGT_DECAUDIO, MSGL_ERR, "mpg123 decoding error: %s\n",
|
|
|
|
mpg123_strerror(con->handle));
|
|
|
|
return -1;
|
2010-06-30 09:55:14 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 18:32:10 +00:00
|
|
|
static int control(sh_audio_t *sh, int cmd, void *arg)
|
2010-06-30 09:55:14 +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
|
|
|
struct ad_mpg123_context *con = sh->context;
|
|
|
|
|
2010-06-30 09:55:14 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case ADCTRL_RESYNC_STREAM:
|
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
|
|
|
mpg123_close(con->handle);
|
|
|
|
|
|
|
|
if (mpg123_open_feed(con->handle) != MPG123_OK) {
|
2010-06-30 09:55:14 +00:00
|
|
|
mp_msg(MSGT_DECAUDIO, MSGL_ERR,
|
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
|
|
|
"mpg123 failed to reopen stream: %s\n",
|
|
|
|
mpg123_strerror(con->handle));
|
2010-06-30 09:55:14 +00:00
|
|
|
return CONTROL_FALSE;
|
|
|
|
}
|
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 CONTROL_TRUE;
|
2010-06-30 09:55:14 +00:00
|
|
|
}
|
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
}
|
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_decoder(list, "mpg123", "mp3", "mp3",
|
|
|
|
"High-performance decoder using libmpg123");
|
|
|
|
}
|
2013-07-22 12:41:56 +00:00
|
|
|
|
|
|
|
const struct ad_functions ad_mpg123 = {
|
|
|
|
.name = "mpg123",
|
|
|
|
.add_decoders = add_decoders,
|
|
|
|
.preinit = preinit,
|
|
|
|
.init = init,
|
|
|
|
.uninit = uninit,
|
|
|
|
.control = control,
|
|
|
|
.decode_audio = decode_audio,
|
|
|
|
};
|