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:23:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2007-11-01 06:52:19 +00:00
|
|
|
#include <assert.h>
|
2002-03-25 21:23:06 +00:00
|
|
|
|
2013-07-07 21:54:11 +00:00
|
|
|
#include <libavutil/mem.h>
|
|
|
|
|
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
|
|
|
#include "demux/codec_tags.h"
|
|
|
|
|
2002-03-25 21:23:06 +00:00
|
|
|
#include "config.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/codecs.h"
|
|
|
|
#include "common/msg.h"
|
2014-08-29 10:09:04 +00:00
|
|
|
#include "misc/bstr.h"
|
2002-03-25 21:23:06 +00:00
|
|
|
|
2007-03-15 17:10:36 +00:00
|
|
|
#include "stream/stream.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "demux/demux.h"
|
2002-03-25 21:23:06 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "demux/stheader.h"
|
2002-03-25 21:23:06 +00:00
|
|
|
|
|
|
|
#include "dec_audio.h"
|
|
|
|
#include "ad.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "audio/format.h"
|
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
|
|
|
#include "audio/audio.h"
|
2013-11-10 22:38:18 +00:00
|
|
|
#include "audio/audio_buffer.h"
|
2002-03-25 21:23:06 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "audio/filter/af.h"
|
2002-10-05 22:55:45 +00:00
|
|
|
|
2013-07-22 12:41:56 +00:00
|
|
|
extern const struct ad_functions ad_mpg123;
|
|
|
|
extern const struct ad_functions ad_lavc;
|
|
|
|
extern const struct ad_functions ad_spdif;
|
|
|
|
|
|
|
|
static const struct ad_functions * const ad_drivers[] = {
|
2014-09-22 20:38:06 +00:00
|
|
|
&ad_lavc,
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_MPG123
|
2013-07-22 12:41:56 +00:00
|
|
|
&ad_mpg123,
|
|
|
|
#endif
|
|
|
|
&ad_spdif,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
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
|
|
|
// Drop audio buffer and reinit it (after format change)
|
2013-11-26 23:11:35 +00:00
|
|
|
// Returns whether the format was valid at all.
|
|
|
|
static bool reinit_audio_buffer(struct dec_audio *da)
|
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
|
|
|
if (!mp_audio_config_valid(&da->decoded)) {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_ERR(da, "Audio decoder did not specify audio "
|
2013-11-26 23:11:35 +00:00
|
|
|
"format, or requested an unsupported configuration!\n");
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-23 20:25:05 +00:00
|
|
|
mp_audio_buffer_reinit(da->decode_buffer, &da->decoded);
|
2013-11-26 23:11:35 +00:00
|
|
|
return true;
|
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
|
|
|
static void uninit_decoder(struct dec_audio *d_audio)
|
2002-03-25 21:23:06 +00:00
|
|
|
{
|
2013-11-23 20:26:04 +00:00
|
|
|
if (d_audio->ad_driver) {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_VERBOSE(d_audio, "Uninit audio decoder.\n");
|
2013-11-23 20:22:17 +00:00
|
|
|
d_audio->ad_driver->uninit(d_audio);
|
|
|
|
}
|
2013-11-23 20:26:04 +00:00
|
|
|
d_audio->ad_driver = NULL;
|
2013-11-23 20:22:17 +00:00
|
|
|
talloc_free(d_audio->priv);
|
|
|
|
d_audio->priv = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int init_audio_codec(struct dec_audio *d_audio, const char *decoder)
|
|
|
|
{
|
|
|
|
if (!d_audio->ad_driver->init(d_audio, decoder)) {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_VERBOSE(d_audio, "Audio decoder init failed.\n");
|
2013-11-23 20:26:04 +00:00
|
|
|
d_audio->ad_driver = NULL;
|
2013-11-23 20:22:17 +00:00
|
|
|
uninit_decoder(d_audio);
|
2013-01-31 09:44:15 +00:00
|
|
|
return 0;
|
2007-11-01 06:51:38 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 23:11:35 +00:00
|
|
|
d_audio->decode_buffer = mp_audio_buffer_create(NULL);
|
2007-11-01 06:51:38 +00:00
|
|
|
return 1;
|
2002-03-25 21:23:06 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
struct mp_decoder_list *audio_decoder_list(void)
|
2007-11-01 06:51:38 +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
|
|
|
struct mp_decoder_list *list = talloc_zero(NULL, struct mp_decoder_list);
|
2013-07-22 12:41:56 +00:00
|
|
|
for (int i = 0; ad_drivers[i] != NULL; i++)
|
|
|
|
ad_drivers[i]->add_decoders(list);
|
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
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
static struct mp_decoder_list *audio_select_decoders(const char *codec,
|
|
|
|
char *selection)
|
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
|
|
|
{
|
2013-11-23 20:22:17 +00:00
|
|
|
struct mp_decoder_list *list = audio_decoder_list();
|
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
|
|
|
struct mp_decoder_list *new = mp_select_decoders(list, codec, selection);
|
|
|
|
talloc_free(list);
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ad_functions *find_driver(const char *name)
|
|
|
|
{
|
2013-07-22 12:41:56 +00:00
|
|
|
for (int i = 0; ad_drivers[i] != NULL; i++) {
|
|
|
|
if (strcmp(ad_drivers[i]->name, name) == 0)
|
|
|
|
return ad_drivers[i];
|
2002-09-28 02:23:20 +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
|
|
|
return NULL;
|
2002-09-28 02:23:20 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
int audio_init_best_codec(struct dec_audio *d_audio, char *audio_decoders)
|
2007-11-01 06:51:38 +00:00
|
|
|
{
|
2013-11-23 20:26:04 +00:00
|
|
|
assert(!d_audio->ad_driver);
|
2013-11-27 19:54:07 +00:00
|
|
|
audio_reset_decoding(d_audio);
|
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
|
|
|
|
|
|
|
struct mp_decoder_entry *decoder = NULL;
|
|
|
|
struct mp_decoder_list *list =
|
2013-11-23 20:22:17 +00:00
|
|
|
audio_select_decoders(d_audio->header->codec, audio_decoders);
|
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
|
|
|
|
2013-12-21 17:46:24 +00:00
|
|
|
mp_print_decoders(d_audio->log, MSGL_V, "Codec list:", list);
|
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
|
|
|
|
|
|
|
for (int n = 0; n < list->num_entries; n++) {
|
|
|
|
struct mp_decoder_entry *sel = &list->entries[n];
|
|
|
|
const struct ad_functions *driver = find_driver(sel->family);
|
|
|
|
if (!driver)
|
|
|
|
continue;
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_VERBOSE(d_audio, "Opening audio decoder %s:%s\n",
|
|
|
|
sel->family, sel->decoder);
|
2013-11-23 20:22:17 +00:00
|
|
|
d_audio->ad_driver = driver;
|
|
|
|
if (init_audio_codec(d_audio, sel->decoder)) {
|
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
|
|
|
decoder = sel;
|
|
|
|
break;
|
2013-01-31 09:44:15 +00:00
|
|
|
}
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_WARN(d_audio, "Audio decoder init failed for "
|
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
|
|
|
"%s:%s\n", sel->family, sel->decoder);
|
2002-09-28 02:23:20 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 20:26:04 +00:00
|
|
|
if (d_audio->ad_driver) {
|
2013-11-23 20:22:17 +00:00
|
|
|
d_audio->decoder_desc =
|
|
|
|
talloc_asprintf(d_audio, "%s [%s:%s]", decoder->desc, decoder->family,
|
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
|
|
|
decoder->decoder);
|
2014-05-31 20:07:36 +00:00
|
|
|
MP_VERBOSE(d_audio, "Selected audio codec: %s\n", d_audio->decoder_desc);
|
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 {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_ERR(d_audio, "Failed to initialize an audio decoder for codec '%s'.\n",
|
2013-11-23 20:22:17 +00:00
|
|
|
d_audio->header->codec ? d_audio->header->codec : "<unknown>");
|
2007-11-01 06:51:38 +00:00
|
|
|
}
|
2002-09-28 02:23:20 +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
|
|
|
talloc_free(list);
|
2013-11-23 20:26:04 +00:00
|
|
|
return !!d_audio->ad_driver;
|
2002-09-28 02:23:20 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
void audio_uninit(struct dec_audio *d_audio)
|
2002-03-25 21:23:06 +00:00
|
|
|
{
|
2013-11-23 20:22:17 +00:00
|
|
|
if (!d_audio)
|
|
|
|
return;
|
2014-10-01 23:47:27 +00:00
|
|
|
MP_VERBOSE(d_audio, "Uninit audio filters...\n");
|
|
|
|
af_destroy(d_audio->afilter);
|
2013-11-23 20:22:17 +00:00
|
|
|
uninit_decoder(d_audio);
|
|
|
|
talloc_free(d_audio->decode_buffer);
|
|
|
|
talloc_free(d_audio);
|
2002-03-25 21:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 18:40:43 +00:00
|
|
|
/* Decode packets until we know the audio format. Then reinit the buffer.
|
|
|
|
* Returns AD_OK on success, negative AD_* code otherwise.
|
|
|
|
* Also returns AD_OK if already initialized (and does nothing).
|
|
|
|
*/
|
|
|
|
int initial_audio_decode(struct dec_audio *da)
|
|
|
|
{
|
|
|
|
while (!mp_audio_config_valid(&da->decoded)) {
|
|
|
|
if (da->decoded.samples > 0)
|
|
|
|
return AD_ERR; // invalid format, rather than uninitialized
|
|
|
|
int ret = da->ad_driver->decode_packet(da);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (mp_audio_buffer_samples(da->decode_buffer) > 0) // avoid accidental flush
|
|
|
|
return AD_OK;
|
|
|
|
return reinit_audio_buffer(da) ? AD_OK : AD_ERR;
|
|
|
|
}
|
|
|
|
|
2013-11-10 22:38:18 +00:00
|
|
|
// Filter len bytes of input, put result into outbuf.
|
2013-11-23 20:22:17 +00:00
|
|
|
static int filter_n_bytes(struct dec_audio *da, struct mp_audio_buffer *outbuf,
|
2013-11-10 22:38:18 +00:00
|
|
|
int len)
|
2007-11-01 06:51:38 +00:00
|
|
|
{
|
2014-07-24 13:26:43 +00:00
|
|
|
bool format_change = false;
|
2009-12-28 20:01:00 +00:00
|
|
|
int error = 0;
|
|
|
|
|
2014-07-24 13:26:43 +00:00
|
|
|
assert(len > 0); // would break EOF logic below
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
while (mp_audio_buffer_samples(da->decode_buffer) < len) {
|
2014-07-24 13:25:48 +00:00
|
|
|
// Check for a format change
|
|
|
|
struct mp_audio config;
|
|
|
|
mp_audio_buffer_get_format(da->decode_buffer, &config);
|
2014-07-24 13:26:43 +00:00
|
|
|
format_change = !mp_audio_config_equals(&da->decoded, &config);
|
|
|
|
if (format_change) {
|
|
|
|
error = AD_EOF; // drain remaining data left in the current buffer
|
2013-01-31 09:44:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-07-21 17:29:37 +00:00
|
|
|
if (da->decoded.samples > 0) {
|
|
|
|
int copy = MPMIN(da->decoded.samples, len);
|
|
|
|
struct mp_audio append = da->decoded;
|
|
|
|
append.samples = copy;
|
|
|
|
mp_audio_buffer_append(da->decode_buffer, &append);
|
|
|
|
mp_audio_skip_samples(&da->decoded, copy);
|
2014-07-24 13:27:31 +00:00
|
|
|
da->pts_offset += copy;
|
2014-07-21 17:29:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
error = da->ad_driver->decode_packet(da);
|
|
|
|
if (error < 0)
|
|
|
|
break;
|
2007-11-01 06:52:19 +00:00
|
|
|
}
|
2007-11-01 06:51:38 +00:00
|
|
|
|
2014-07-28 18:40:43 +00:00
|
|
|
if (error == AD_WAIT)
|
|
|
|
return error;
|
|
|
|
|
2009-12-28 20:01:00 +00:00
|
|
|
// Filter
|
2013-12-04 23:01:46 +00:00
|
|
|
struct mp_audio filter_data;
|
|
|
|
mp_audio_buffer_peek(da->decode_buffer, &filter_data);
|
|
|
|
filter_data.rate = da->afilter->input.rate; // due to playback speed change
|
|
|
|
len = MPMIN(filter_data.samples, len);
|
|
|
|
filter_data.samples = len;
|
2014-07-24 13:26:07 +00:00
|
|
|
bool eof = error == AD_EOF && filter_data.samples == 0;
|
2013-12-04 23:01:46 +00:00
|
|
|
|
2013-12-04 23:29:10 +00:00
|
|
|
if (af_filter(da->afilter, &filter_data, eof ? AF_FILTER_FLAG_EOF : 0) < 0)
|
2014-07-20 18:42:03 +00:00
|
|
|
return AD_ERR;
|
2013-12-04 23:29:10 +00:00
|
|
|
|
2013-12-04 23:01:46 +00:00
|
|
|
mp_audio_buffer_append(outbuf, &filter_data);
|
2014-07-24 13:26:07 +00:00
|
|
|
if (error == AD_EOF && filter_data.samples > 0)
|
2013-12-04 23:29:10 +00:00
|
|
|
error = 0; // don't end playback yet
|
2007-11-01 06:51:38 +00:00
|
|
|
|
|
|
|
// remove processed data from decoder buffer:
|
2013-11-23 20:22:17 +00:00
|
|
|
mp_audio_buffer_skip(da->decode_buffer, len);
|
2007-11-01 06:51:38 +00:00
|
|
|
|
2014-07-24 13:26:43 +00:00
|
|
|
// if format was changed, and all data was drained, execute the format change
|
|
|
|
if (format_change && eof) {
|
|
|
|
error = AD_NEW_FMT;
|
2013-11-26 23:11:35 +00:00
|
|
|
if (!reinit_audio_buffer(da))
|
2014-07-20 18:42:03 +00:00
|
|
|
error = AD_ERR; // switch to invalid format
|
2013-11-26 23:11:35 +00:00
|
|
|
}
|
2013-11-18 12:45:35 +00:00
|
|
|
|
2007-11-01 06:52:19 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2013-11-10 22:38:18 +00:00
|
|
|
/* Try to get at least minsamples decoded+filtered samples in outbuf
|
2007-11-01 06:52:19 +00:00
|
|
|
* (total length including possible existing data).
|
2014-07-20 18:42:03 +00:00
|
|
|
* Return 0 on success, or negative AD_* error code.
|
2013-11-10 22:38:18 +00:00
|
|
|
* In the former case outbuf has at least minsamples buffered on return.
|
|
|
|
* In case of EOF/error it might or might not be. */
|
2013-11-23 20:22:17 +00:00
|
|
|
int audio_decode(struct dec_audio *d_audio, struct mp_audio_buffer *outbuf,
|
2013-11-10 22:38:18 +00:00
|
|
|
int minsamples)
|
2007-11-01 06:52:19 +00:00
|
|
|
{
|
2014-10-01 23:47:27 +00:00
|
|
|
if (d_audio->afilter->initialized < 1)
|
2014-07-28 18:40:43 +00:00
|
|
|
return AD_ERR;
|
|
|
|
|
2007-11-08 18:14:49 +00:00
|
|
|
// Indicates that a filter seems to be buffering large amounts of data
|
|
|
|
int huge_filter_buffer = 0;
|
2007-11-01 06:52:19 +00:00
|
|
|
|
|
|
|
/* Filter output size will be about filter_multiplier times input size.
|
|
|
|
* If some filter buffers audio in big blocks this might only hold
|
|
|
|
* as average over time. */
|
2013-11-23 20:22:17 +00:00
|
|
|
double filter_multiplier = af_calc_filter_multiplier(d_audio->afilter);
|
2007-11-01 06:52:19 +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
|
|
|
int prev_buffered = -1;
|
2014-04-17 19:47:00 +00:00
|
|
|
int res = 0;
|
|
|
|
MP_STATS(d_audio, "start audio");
|
|
|
|
while (res >= 0 && minsamples >= 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
|
|
|
int buffered = mp_audio_buffer_samples(outbuf);
|
|
|
|
if (minsamples < buffered || buffered == prev_buffered)
|
|
|
|
break;
|
|
|
|
prev_buffered = buffered;
|
2007-11-01 06:52:19 +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
|
|
|
int decsamples = (minsamples - buffered) / filter_multiplier;
|
2014-07-24 13:25:48 +00:00
|
|
|
// + some extra for possible filter buffering, and avoid 0
|
|
|
|
decsamples += 512;
|
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 (huge_filter_buffer) {
|
2013-01-31 09:44:15 +00:00
|
|
|
/* Some filter must be doing significant buffering if the estimated
|
|
|
|
* input length didn't produce enough output from filters.
|
2013-11-15 20:12:01 +00:00
|
|
|
* Feed the filters 250 samples at a time until we have enough
|
|
|
|
* output. Very small amounts could make filtering inefficient while
|
|
|
|
* large amounts can make mpv demux the file unnecessarily far ahead
|
2013-01-31 09:44:15 +00:00
|
|
|
* to get audio data and buffer video frames in memory while doing
|
|
|
|
* so. However the performance impact of either is probably not too
|
|
|
|
* significant as long as the value is not completely insane. */
|
2013-11-15 20:12:01 +00:00
|
|
|
decsamples = 250;
|
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 this iteration does not fill buffer, we must have lots
|
|
|
|
* of buffering in filters */
|
|
|
|
huge_filter_buffer = 1;
|
|
|
|
|
2014-04-17 19:47:00 +00:00
|
|
|
res = filter_n_bytes(d_audio, outbuf, decsamples);
|
2007-11-01 06:52:19 +00:00
|
|
|
}
|
2014-04-17 19:47:00 +00:00
|
|
|
MP_STATS(d_audio, "end audio");
|
|
|
|
return res;
|
2002-03-25 21:23:06 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 19:54:07 +00:00
|
|
|
void audio_reset_decoding(struct dec_audio *d_audio)
|
2002-03-25 21:23:06 +00:00
|
|
|
{
|
2013-11-23 20:26:04 +00:00
|
|
|
if (d_audio->ad_driver)
|
2013-11-27 19:54:07 +00:00
|
|
|
d_audio->ad_driver->control(d_audio, ADCTRL_RESET, NULL);
|
2014-10-01 23:47:27 +00:00
|
|
|
af_control_all(d_audio->afilter, AF_CONTROL_RESET, NULL);
|
2013-11-27 19:54:29 +00:00
|
|
|
d_audio->pts = MP_NOPTS_VALUE;
|
|
|
|
d_audio->pts_offset = 0;
|
|
|
|
if (d_audio->decode_buffer)
|
|
|
|
mp_audio_buffer_clear(d_audio->decode_buffer);
|
2002-03-25 21:23:06 +00:00
|
|
|
}
|