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
|
|
|
|
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"
|
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 "core/codecs.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/mp_msg.h"
|
|
|
|
#include "core/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"
|
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
|
|
|
|
2007-11-01 06:51:38 +00:00
|
|
|
int fakemono = 0;
|
|
|
|
|
2013-01-31 09:44:15 +00:00
|
|
|
struct af_cfg af_cfg = {1, NULL}; // Configuration for audio filters
|
2002-03-25 21:23:06 +00:00
|
|
|
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
static int init_audio_codec(sh_audio_t *sh_audio, const char *decoder)
|
2002-03-25 21:23:06 +00:00
|
|
|
{
|
2010-04-23 17:50:11 +00:00
|
|
|
assert(!sh_audio->initialized);
|
|
|
|
resync_audio_stream(sh_audio);
|
2012-11-26 02:47:29 +00:00
|
|
|
sh_audio->samplesize = 2;
|
|
|
|
sh_audio->sample_format = AF_FORMAT_S16_NE;
|
2007-11-01 06:51:38 +00:00
|
|
|
if ((af_cfg.force & AF_INIT_FORMAT_MASK) == AF_INIT_FLOAT) {
|
2013-01-31 09:44:15 +00:00
|
|
|
int fmt = AF_FORMAT_FLOAT_NE;
|
|
|
|
if (sh_audio->ad_driver->control(sh_audio, ADCTRL_QUERY_FORMAT,
|
|
|
|
&fmt) == CONTROL_TRUE) {
|
|
|
|
sh_audio->sample_format = fmt;
|
|
|
|
sh_audio->samplesize = 4;
|
|
|
|
}
|
2007-11-01 06:51:38 +00:00
|
|
|
}
|
2010-04-23 17:50:11 +00:00
|
|
|
sh_audio->audio_out_minsize = 8192; // default, preinit() may change it
|
2007-11-01 06:51:38 +00:00
|
|
|
if (!sh_audio->ad_driver->preinit(sh_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
|
|
|
mp_tmsg(MSGT_DECAUDIO, MSGL_ERR, "Audio decoder preinit failed.\n");
|
2013-01-31 09:44:15 +00:00
|
|
|
return 0;
|
2007-11-01 06:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate audio in buffer: */
|
|
|
|
if (sh_audio->audio_in_minsize > 0) {
|
2013-01-31 09:44:15 +00:00
|
|
|
sh_audio->a_in_buffer_size = sh_audio->audio_in_minsize;
|
|
|
|
mp_tmsg(MSGT_DECAUDIO, MSGL_V,
|
|
|
|
"dec_audio: Allocating %d bytes for input buffer.\n",
|
|
|
|
sh_audio->a_in_buffer_size);
|
|
|
|
sh_audio->a_in_buffer = av_mallocz(sh_audio->a_in_buffer_size);
|
2007-11-01 06:51:38 +00:00
|
|
|
}
|
|
|
|
|
2009-12-29 13:51:59 +00:00
|
|
|
const int base_size = 65536;
|
|
|
|
// At least 64 KiB plus rounding up to next decodable unit size
|
|
|
|
sh_audio->a_buffer_size = base_size + sh_audio->audio_out_minsize;
|
2007-11-01 06:51:38 +00:00
|
|
|
|
2013-01-31 09:44:15 +00:00
|
|
|
mp_tmsg(MSGT_DECAUDIO, MSGL_V,
|
|
|
|
"dec_audio: Allocating %d + %d = %d bytes for output buffer.\n",
|
|
|
|
sh_audio->audio_out_minsize, base_size,
|
|
|
|
sh_audio->a_buffer_size);
|
2007-11-01 06:51:38 +00:00
|
|
|
|
2008-10-18 18:54:05 +00:00
|
|
|
sh_audio->a_buffer = av_mallocz(sh_audio->a_buffer_size);
|
2012-07-24 06:01:47 +00:00
|
|
|
if (!sh_audio->a_buffer)
|
|
|
|
abort();
|
2007-11-01 06:51:38 +00:00
|
|
|
sh_audio->a_buffer_len = 0;
|
|
|
|
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
if (!sh_audio->ad_driver->init(sh_audio, decoder)) {
|
|
|
|
mp_tmsg(MSGT_DECAUDIO, MSGL_V, "Audio decoder init failed.\n");
|
2013-01-31 09:44:15 +00:00
|
|
|
uninit_audio(sh_audio); // free buffers
|
|
|
|
return 0;
|
2007-11-01 06:51:38 +00:00
|
|
|
}
|
|
|
|
|
2008-02-14 14:23:55 +00:00
|
|
|
sh_audio->initialized = 1;
|
2007-11-01 06:51:38 +00:00
|
|
|
|
|
|
|
if (!sh_audio->channels || !sh_audio->samplerate) {
|
2013-01-31 09:44:15 +00:00
|
|
|
mp_tmsg(MSGT_DECAUDIO, MSGL_ERR, "Audio decoder did not specify "
|
2012-07-24 06:01:47 +00:00
|
|
|
"audio format!\n");
|
2013-01-31 09:44:15 +00:00
|
|
|
uninit_audio(sh_audio); // free buffers
|
|
|
|
return 0;
|
2007-11-01 06:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!sh_audio->o_bps)
|
2013-01-31 09:44:15 +00:00
|
|
|
sh_audio->o_bps = sh_audio->channels * sh_audio->samplerate
|
|
|
|
* sh_audio->samplesize;
|
2007-11-01 06:51:38 +00:00
|
|
|
return 1;
|
2002-03-25 21:23:06 +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 *mp_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);
|
|
|
|
for (int i = 0; mpcodecs_ad_drivers[i] != NULL; i++)
|
|
|
|
mpcodecs_ad_drivers[i]->add_decoders(list);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mp_decoder_list *mp_select_audio_decoders(const char *codec,
|
|
|
|
char *selection)
|
|
|
|
{
|
|
|
|
struct mp_decoder_list *list = mp_audio_decoder_list();
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
for (int i = 0; mpcodecs_ad_drivers[i] != NULL; i++) {
|
|
|
|
if (strcmp(mpcodecs_ad_drivers[i]->name, name) == 0)
|
|
|
|
return mpcodecs_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
|
|
|
}
|
|
|
|
|
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
|
|
|
int init_best_audio_codec(sh_audio_t *sh_audio, char *audio_decoders)
|
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
|
|
|
assert(!sh_audio->initialized);
|
|
|
|
|
|
|
|
struct mp_decoder_entry *decoder = NULL;
|
|
|
|
struct mp_decoder_list *list =
|
|
|
|
mp_select_audio_decoders(sh_audio->gsh->codec, audio_decoders);
|
|
|
|
|
|
|
|
mp_print_decoders(MSGT_DECAUDIO, MSGL_V, "Codec list:", list);
|
|
|
|
|
|
|
|
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;
|
|
|
|
mp_tmsg(MSGT_DECAUDIO, MSGL_V, "Opening audio decoder %s:%s\n",
|
|
|
|
sel->family, sel->decoder);
|
|
|
|
sh_audio->ad_driver = driver;
|
|
|
|
if (init_audio_codec(sh_audio, sel->decoder)) {
|
|
|
|
decoder = sel;
|
|
|
|
break;
|
2013-01-31 09:44:15 +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
|
|
|
sh_audio->ad_driver = NULL;
|
|
|
|
mp_tmsg(MSGT_DECAUDIO, MSGL_WARN, "Audio decoder init failed for "
|
|
|
|
"%s:%s\n", sel->family, sel->decoder);
|
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
|
|
|
if (sh_audio->initialized) {
|
|
|
|
sh_audio->gsh->decoder_desc =
|
|
|
|
talloc_asprintf(NULL, "%s [%s:%s]", decoder->desc, decoder->family,
|
|
|
|
decoder->decoder);
|
|
|
|
mp_msg(MSGT_DECAUDIO, MSGL_INFO, "Selected audio codec: %s\n",
|
|
|
|
sh_audio->gsh->decoder_desc);
|
|
|
|
mp_msg(MSGT_DECAUDIO, MSGL_V,
|
|
|
|
"AUDIO: %d Hz, %d ch, %s, %3.1f kbit/%3.2f%% (ratio: %d->%d)\n",
|
|
|
|
sh_audio->samplerate, sh_audio->channels,
|
|
|
|
af_fmt2str_short(sh_audio->sample_format),
|
|
|
|
sh_audio->i_bps * 8 * 0.001,
|
|
|
|
((float) sh_audio->i_bps / sh_audio->o_bps) * 100.0,
|
|
|
|
sh_audio->i_bps, sh_audio->o_bps);
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO,
|
|
|
|
"ID_AUDIO_BITRATE=%d\nID_AUDIO_RATE=%d\n" "ID_AUDIO_NCH=%d\n",
|
|
|
|
sh_audio->i_bps * 8, sh_audio->samplerate, sh_audio->channels);
|
|
|
|
} else {
|
|
|
|
mp_msg(MSGT_DECAUDIO, MSGL_ERR,
|
|
|
|
"Failed to initialize an audio decoder for codec '%s'.\n",
|
|
|
|
sh_audio->gsh->codec ? sh_audio->gsh->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);
|
|
|
|
return sh_audio->initialized;
|
2002-09-28 02:23:20 +00:00
|
|
|
}
|
|
|
|
|
2002-03-25 21:23:06 +00:00
|
|
|
void uninit_audio(sh_audio_t *sh_audio)
|
|
|
|
{
|
2007-11-01 06:51:38 +00:00
|
|
|
if (sh_audio->afilter) {
|
2013-01-31 09:44:15 +00:00
|
|
|
mp_msg(MSGT_DECAUDIO, MSGL_V, "Uninit audio filters...\n");
|
|
|
|
af_uninit(sh_audio->afilter);
|
|
|
|
free(sh_audio->afilter);
|
|
|
|
sh_audio->afilter = NULL;
|
2002-10-05 22:55:45 +00:00
|
|
|
}
|
2008-02-14 14:23:55 +00:00
|
|
|
if (sh_audio->initialized) {
|
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
|
|
|
mp_tmsg(MSGT_DECAUDIO, MSGL_V, "Uninit audio.\n");
|
2013-01-31 09:44:15 +00:00
|
|
|
sh_audio->ad_driver->uninit(sh_audio);
|
|
|
|
sh_audio->initialized = 0;
|
2002-09-01 23:33:30 +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(sh_audio->gsh->decoder_desc);
|
|
|
|
sh_audio->gsh->decoder_desc = NULL;
|
2008-10-18 18:54:05 +00:00
|
|
|
av_freep(&sh_audio->a_buffer);
|
|
|
|
av_freep(&sh_audio->a_in_buffer);
|
2002-03-25 21:23:06 +00:00
|
|
|
}
|
|
|
|
|
2003-01-18 17:34:02 +00:00
|
|
|
|
2007-11-01 06:51:38 +00:00
|
|
|
int init_audio_filters(sh_audio_t *sh_audio, int in_samplerate,
|
2013-01-31 09:44:15 +00:00
|
|
|
int *out_samplerate, int *out_channels, int *out_format)
|
2002-03-25 21:23:06 +00:00
|
|
|
{
|
2012-11-01 12:33:38 +00:00
|
|
|
struct af_stream *afs = sh_audio->afilter;
|
2007-11-01 06:51:38 +00:00
|
|
|
if (!afs) {
|
2013-01-31 09:44:15 +00:00
|
|
|
afs = calloc(1, sizeof(struct af_stream));
|
|
|
|
afs->opts = sh_audio->opts;
|
2007-11-01 06:51:38 +00:00
|
|
|
}
|
|
|
|
// input format: same as codec's output format:
|
|
|
|
afs->input.rate = in_samplerate;
|
2007-11-01 06:52:28 +00:00
|
|
|
afs->input.nch = sh_audio->channels;
|
|
|
|
afs->input.format = sh_audio->sample_format;
|
2007-11-01 06:51:38 +00:00
|
|
|
af_fix_parameters(&(afs->input));
|
|
|
|
|
|
|
|
// output format: same as ao driver's input format (if missing, fallback to input)
|
|
|
|
afs->output.rate = *out_samplerate;
|
|
|
|
afs->output.nch = *out_channels;
|
|
|
|
afs->output.format = *out_format;
|
|
|
|
af_fix_parameters(&(afs->output));
|
|
|
|
|
|
|
|
// filter config:
|
2012-11-01 11:25:14 +00:00
|
|
|
memcpy(&afs->cfg, &af_cfg, sizeof(struct af_cfg));
|
2007-11-01 06:51:38 +00:00
|
|
|
|
2013-01-31 09:44:15 +00:00
|
|
|
mp_tmsg(MSGT_DECAUDIO, MSGL_V,
|
|
|
|
"Building audio filter chain for %dHz/%dch/%s -> %dHz/%dch/%s...\n",
|
|
|
|
afs->input.rate, afs->input.nch,
|
|
|
|
af_fmt2str_short(afs->input.format), afs->output.rate,
|
|
|
|
afs->output.nch, af_fmt2str_short(afs->output.format));
|
2007-11-01 06:51:38 +00:00
|
|
|
|
|
|
|
// let's autoprobe it!
|
|
|
|
if (0 != af_init(afs)) {
|
2013-01-31 09:44:15 +00:00
|
|
|
sh_audio->afilter = NULL;
|
|
|
|
free(afs);
|
|
|
|
return 0; // failed :(
|
2007-11-01 06:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*out_samplerate = afs->output.rate;
|
|
|
|
*out_channels = afs->output.nch;
|
|
|
|
*out_format = afs->output.format;
|
|
|
|
|
|
|
|
// ok!
|
|
|
|
sh_audio->afilter = (void *) afs;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-07-02 06:22:32 +00:00
|
|
|
static void set_min_out_buffer_size(struct bstr *outbuf, int len)
|
2010-11-13 17:27:01 +00:00
|
|
|
{
|
2011-07-02 06:22:32 +00:00
|
|
|
size_t oldlen = talloc_get_size(outbuf->start);
|
|
|
|
if (oldlen < len) {
|
|
|
|
assert(outbuf->start); // talloc context should be already set
|
2013-01-31 09:44:15 +00:00
|
|
|
mp_msg(MSGT_DECAUDIO, MSGL_V, "Increasing filtered audio buffer size "
|
|
|
|
"from %zd to %d\n", oldlen, len);
|
2011-07-02 06:22:32 +00:00
|
|
|
outbuf->start = talloc_realloc_size(NULL, outbuf->start, len);
|
2010-11-13 17:27:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-02 06:22:32 +00:00
|
|
|
static int filter_n_bytes(sh_audio_t *sh, struct bstr *outbuf, int len)
|
2007-11-01 06:51:38 +00:00
|
|
|
{
|
2013-01-31 09:44:15 +00:00
|
|
|
assert(len - 1 + sh->audio_out_minsize <= sh->a_buffer_size);
|
2007-12-03 09:03:45 +00:00
|
|
|
|
2009-12-28 20:01:00 +00:00
|
|
|
int error = 0;
|
|
|
|
|
2007-11-01 06:52:19 +00:00
|
|
|
// Decode more bytes if needed
|
2010-07-15 17:59:46 +00:00
|
|
|
int old_samplerate = sh->samplerate;
|
|
|
|
int old_channels = sh->channels;
|
|
|
|
int old_sample_format = sh->sample_format;
|
2007-11-01 06:52:19 +00:00
|
|
|
while (sh->a_buffer_len < len) {
|
2013-01-31 09:44:15 +00:00
|
|
|
unsigned char *buf = sh->a_buffer + sh->a_buffer_len;
|
|
|
|
int minlen = len - sh->a_buffer_len;
|
|
|
|
int maxlen = sh->a_buffer_size - sh->a_buffer_len;
|
|
|
|
int ret = sh->ad_driver->decode_audio(sh, buf, minlen, maxlen);
|
|
|
|
int format_change = sh->samplerate != old_samplerate
|
2010-07-15 17:59:46 +00:00
|
|
|
|| sh->channels != old_channels
|
|
|
|
|| sh->sample_format != old_sample_format;
|
2013-01-31 09:44:15 +00:00
|
|
|
if (ret <= 0 || format_change) {
|
|
|
|
error = format_change ? -2 : -1;
|
2010-07-15 17:59:46 +00:00
|
|
|
// samples from format-changing call get discarded too
|
2013-01-31 09:44:15 +00:00
|
|
|
len = sh->a_buffer_len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sh->a_buffer_len += ret;
|
2007-11-01 06:52:19 +00:00
|
|
|
}
|
2007-11-01 06:51:38 +00:00
|
|
|
|
2009-12-28 20:01:00 +00:00
|
|
|
// Filter
|
2012-11-01 11:00:00 +00:00
|
|
|
struct mp_audio filter_input = {
|
2013-01-31 09:44:15 +00:00
|
|
|
.audio = sh->a_buffer,
|
|
|
|
.len = len,
|
|
|
|
.rate = sh->samplerate,
|
|
|
|
.nch = sh->channels,
|
|
|
|
.format = sh->sample_format
|
2009-12-28 20:01:00 +00:00
|
|
|
};
|
2007-11-01 06:52:19 +00:00
|
|
|
af_fix_parameters(&filter_input);
|
2012-11-01 11:00:00 +00:00
|
|
|
struct mp_audio *filter_output = af_play(sh->afilter, &filter_input);
|
2007-11-01 06:52:19 +00:00
|
|
|
if (!filter_output)
|
2013-01-31 09:44:15 +00:00
|
|
|
return -1;
|
2011-07-02 06:22:32 +00:00
|
|
|
set_min_out_buffer_size(outbuf, outbuf->len + filter_output->len);
|
|
|
|
memcpy(outbuf->start + outbuf->len, filter_output->audio,
|
|
|
|
filter_output->len);
|
|
|
|
outbuf->len += filter_output->len;
|
2007-11-01 06:51:38 +00:00
|
|
|
|
|
|
|
// remove processed data from decoder buffer:
|
2007-11-01 06:52:19 +00:00
|
|
|
sh->a_buffer_len -= len;
|
|
|
|
memmove(sh->a_buffer, sh->a_buffer + len, sh->a_buffer_len);
|
2007-11-01 06:51:38 +00:00
|
|
|
|
2007-11-01 06:52:19 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-07-02 06:22:32 +00:00
|
|
|
/* Try to get at least minlen decoded+filtered bytes in outbuf
|
2007-11-01 06:52:19 +00:00
|
|
|
* (total length including possible existing data).
|
|
|
|
* Return 0 on success, -1 on error/EOF (not distinguished).
|
2011-07-02 06:22:32 +00:00
|
|
|
* In the former case outbuf->len is always >= minlen on return.
|
|
|
|
* In case of EOF/error it might or might not be.
|
|
|
|
* Outbuf.start must be talloc-allocated, and will be reallocated
|
|
|
|
* if needed to fit all filter output. */
|
|
|
|
int decode_audio(sh_audio_t *sh_audio, struct bstr *outbuf, int minlen)
|
2007-11-01 06:52:19 +00:00
|
|
|
{
|
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
|
|
|
// Decoded audio must be cut at boundaries of this many bytes
|
2008-07-14 16:38:58 +00:00
|
|
|
int unitsize = sh_audio->channels * sh_audio->samplesize * 16;
|
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. */
|
|
|
|
double filter_multiplier = af_calc_filter_multiplier(sh_audio->afilter);
|
|
|
|
|
|
|
|
/* If the decoder set audio_out_minsize then it can do the equivalent of
|
|
|
|
* "while (output_len < target_len) output_len += audio_out_minsize;",
|
|
|
|
* so we must guarantee there is at least audio_out_minsize-1 bytes
|
|
|
|
* more space in the output buffer than the minimum length we try to
|
|
|
|
* decode. */
|
|
|
|
int max_decode_len = sh_audio->a_buffer_size - sh_audio->audio_out_minsize;
|
2012-02-19 13:49:04 +00:00
|
|
|
if (!unitsize)
|
|
|
|
return -1;
|
2007-11-01 06:52:19 +00:00
|
|
|
max_decode_len -= max_decode_len % unitsize;
|
|
|
|
|
2013-01-31 09:44:15 +00:00
|
|
|
while (minlen >= 0 && outbuf->len < minlen) {
|
|
|
|
// + some extra for possible filter buffering
|
|
|
|
int declen = (minlen - outbuf->len) / filter_multiplier + (unitsize << 5);
|
|
|
|
if (huge_filter_buffer)
|
|
|
|
/* Some filter must be doing significant buffering if the estimated
|
|
|
|
* input length didn't produce enough output from filters.
|
|
|
|
* Feed the filters 2k bytes at a time until we have enough output.
|
|
|
|
* Very small amounts could make filtering inefficient while large
|
|
|
|
* amounts can make MPlayer demux the file unnecessarily far ahead
|
|
|
|
* 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. */
|
|
|
|
declen = 2000;
|
|
|
|
declen -= declen % unitsize;
|
|
|
|
if (declen > max_decode_len)
|
|
|
|
declen = max_decode_len;
|
|
|
|
else
|
|
|
|
/* if this iteration does not fill buffer, we must have lots
|
|
|
|
* of buffering in filters */
|
|
|
|
huge_filter_buffer = 1;
|
|
|
|
int res = filter_n_bytes(sh_audio, outbuf, declen);
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
2007-11-01 06:52:19 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2002-03-25 21:23:06 +00:00
|
|
|
}
|
|
|
|
|
2011-07-02 06:22:32 +00:00
|
|
|
void decode_audio_prepend_bytes(struct bstr *outbuf, int count, int byte)
|
2010-11-13 17:27:01 +00:00
|
|
|
{
|
2011-07-02 06:22:32 +00:00
|
|
|
set_min_out_buffer_size(outbuf, outbuf->len + count);
|
|
|
|
memmove(outbuf->start + count, outbuf->start, outbuf->len);
|
|
|
|
memset(outbuf->start, byte, count);
|
|
|
|
outbuf->len += count;
|
2010-11-13 17:27:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-25 21:23:06 +00:00
|
|
|
void resync_audio_stream(sh_audio_t *sh_audio)
|
|
|
|
{
|
2013-01-31 09:44:15 +00:00
|
|
|
sh_audio->a_in_buffer_len = 0; // clear audio input buffer
|
2010-04-23 17:50:11 +00:00
|
|
|
sh_audio->pts = MP_NOPTS_VALUE;
|
2008-02-14 14:23:55 +00:00
|
|
|
if (!sh_audio->initialized)
|
2013-01-31 09:44:15 +00:00
|
|
|
return;
|
2007-11-01 06:51:38 +00:00
|
|
|
sh_audio->ad_driver->control(sh_audio, ADCTRL_RESYNC_STREAM, NULL);
|
2002-03-25 21:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void skip_audio_frame(sh_audio_t *sh_audio)
|
|
|
|
{
|
2008-02-14 14:23:55 +00:00
|
|
|
if (!sh_audio->initialized)
|
2013-01-31 09:44:15 +00:00
|
|
|
return;
|
|
|
|
if (sh_audio->ad_driver->control(sh_audio, ADCTRL_SKIP_FRAME, NULL)
|
|
|
|
== CONTROL_TRUE)
|
|
|
|
return;
|
2007-11-01 06:51:38 +00:00
|
|
|
// default skip code:
|
2013-01-31 09:44:15 +00:00
|
|
|
ds_fill_buffer(sh_audio->ds); // skip block
|
2002-03-25 21:23:06 +00:00
|
|
|
}
|