mirror of
https://github.com/mpv-player/mpv
synced 2024-12-29 10:32:15 +00:00
demux: remove audio parser
The audio parser was needed only by the "old" demuxers, and demux_rawaudio. All other demuxers output already parsed packets. demux_rawaudio is usually for raw audio, so using a parser with it doesn't usually make sense. But you can also force it to read compressed formats with fixed packet sizes, in which case the parser would have been used. This use case is probably broken now, but you will be able to do the same thing with libavformat demuxers.
This commit is contained in:
parent
af0c41e162
commit
aac5d758c5
@ -344,7 +344,6 @@ static int control(sh_audio_t *sh, int cmd, void *arg)
|
||||
switch (cmd) {
|
||||
case ADCTRL_RESYNC_STREAM:
|
||||
avcodec_flush_buffers(ctx->avctx);
|
||||
ds_clear_parser(sh->ds);
|
||||
ctx->previous_data_left = 0;
|
||||
ctx->output_left = 0;
|
||||
return CONTROL_TRUE;
|
||||
@ -384,10 +383,7 @@ static int decode_new_packet(struct sh_audio *sh)
|
||||
if (!mpkt) {
|
||||
assert(!priv->previous_data_left);
|
||||
start = NULL;
|
||||
insize = 0;
|
||||
ds_parse(sh->ds, &start, &insize, pts, 0);
|
||||
if (insize <= 0)
|
||||
return -1; // error or EOF
|
||||
return -1; // error or EOF
|
||||
} else {
|
||||
assert(mpkt->len >= priv->previous_data_left);
|
||||
if (!priv->previous_data_left) {
|
||||
@ -396,8 +392,7 @@ static int decode_new_packet(struct sh_audio *sh)
|
||||
}
|
||||
insize = priv->previous_data_left;
|
||||
start = mpkt->buffer + mpkt->len - priv->previous_data_left;
|
||||
int consumed = ds_parse(sh->ds, &start, &insize, pts, 0);
|
||||
priv->previous_data_left -= consumed;
|
||||
priv->previous_data_left -= insize;
|
||||
priv->previous_data_left = FFMAX(priv->previous_data_left, 0);
|
||||
}
|
||||
|
||||
@ -420,7 +415,7 @@ static int decode_new_packet(struct sh_audio *sh)
|
||||
return -1;
|
||||
}
|
||||
// The "insize >= ret" test is sanity check against decoder overreads
|
||||
if (!sh->parser && insize >= ret)
|
||||
if (insize >= ret)
|
||||
priv->previous_data_left = insize - ret;
|
||||
if (!got_frame)
|
||||
return 0;
|
||||
|
@ -132,20 +132,8 @@ static int init(sh_audio_t *sh, const char *decoder)
|
||||
pts = MP_NOPTS_VALUE;
|
||||
x = 0;
|
||||
}
|
||||
ds_parse(sh->ds, &start, &x, pts, 0);
|
||||
srate = 48000; //fake value
|
||||
bps = 768000/8; //fake value
|
||||
if (x && sh->avctx) { // we have parser and large enough buffer
|
||||
if (sh->avctx->sample_rate < 44100) {
|
||||
mp_msg(MSGT_DECAUDIO,MSGL_INFO,
|
||||
"This stream sample_rate[%d Hz] may be broken. "
|
||||
"Force reset 48000Hz.\n",
|
||||
sh->avctx->sample_rate);
|
||||
srate = 48000; //fake value
|
||||
} else
|
||||
srate = sh->avctx->sample_rate;
|
||||
bps = sh->avctx->bit_rate/8;
|
||||
}
|
||||
sh->ds->buffer_pos -= in_size;
|
||||
|
||||
int num_channels = 0;
|
||||
@ -239,14 +227,10 @@ static int decode_audio(sh_audio_t *sh, unsigned char *buf,
|
||||
break;
|
||||
x = ds_get_packet_pts(sh->ds, &start, &pts);
|
||||
if (x <= 0) {
|
||||
x = 0;
|
||||
ds_parse(sh->ds, &start, &x, MP_NOPTS_VALUE, 0);
|
||||
if (x == 0)
|
||||
continue; // END_NOT_FOUND
|
||||
in_size = x;
|
||||
continue; // END_NOT_FOUND
|
||||
} else {
|
||||
in_size = x;
|
||||
consumed = ds_parse(sh->ds, &start, &x, pts, 0);
|
||||
consumed = x;
|
||||
if (x == 0) {
|
||||
mp_msg(MSGT_DECAUDIO,MSGL_V,
|
||||
"start[%p] in_size[%d] consumed[%d] x[%d].\n",
|
||||
|
@ -46,8 +46,6 @@
|
||||
#error MP_INPUT_BUFFER_PADDING_SIZE is too small!
|
||||
#endif
|
||||
|
||||
static void clear_parser(sh_audio_t *sh);
|
||||
|
||||
// Demuxer list
|
||||
extern const struct demuxer_desc demuxer_desc_edl;
|
||||
extern const struct demuxer_desc demuxer_desc_cue;
|
||||
@ -370,7 +368,6 @@ static void free_sh_audio(demuxer_t *demuxer, int id)
|
||||
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_audio at %p\n", sh);
|
||||
free(sh->wf);
|
||||
free(sh->codecdata);
|
||||
clear_parser(sh);
|
||||
free_sh_stream(sh->gsh);
|
||||
}
|
||||
|
||||
@ -467,73 +464,6 @@ void ds_add_packet(demux_stream_t *ds, demux_packet_t *dp)
|
||||
ds->demuxer->video->packs);
|
||||
}
|
||||
|
||||
static void allocate_parser(AVCodecContext **avctx, AVCodecParserContext **parser, const char *format)
|
||||
{
|
||||
enum AVCodecID codec_id = mp_codec_to_av_codec_id(format);
|
||||
|
||||
switch (codec_id) {
|
||||
case AV_CODEC_ID_AAC_LATM:
|
||||
case AV_CODEC_ID_AC3:
|
||||
case AV_CODEC_ID_EAC3:
|
||||
case AV_CODEC_ID_DTS:
|
||||
case AV_CODEC_ID_FLAC:
|
||||
case AV_CODEC_ID_MLP:
|
||||
case AV_CODEC_ID_MP3:
|
||||
case AV_CODEC_ID_MP2:
|
||||
case AV_CODEC_ID_TRUEHD:
|
||||
*avctx = avcodec_alloc_context3(NULL);
|
||||
if (!*avctx)
|
||||
return;
|
||||
*parser = av_parser_init(codec_id);
|
||||
if (!*parser)
|
||||
av_freep(avctx);
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
|
||||
static void get_parser(sh_audio_t *sh, AVCodecContext **avctx, AVCodecParserContext **parser)
|
||||
{
|
||||
*avctx = NULL;
|
||||
*parser = NULL;
|
||||
|
||||
if (!sh || !sh->needs_parsing)
|
||||
return;
|
||||
|
||||
*avctx = sh->avctx;
|
||||
*parser = sh->parser;
|
||||
if (*parser)
|
||||
return;
|
||||
|
||||
allocate_parser(avctx, parser, sh->gsh->codec);
|
||||
sh->avctx = *avctx;
|
||||
sh->parser = *parser;
|
||||
}
|
||||
|
||||
int ds_parse(demux_stream_t *ds, uint8_t **buffer, int *len, double pts, int64_t pos)
|
||||
{
|
||||
AVCodecContext *avctx;
|
||||
AVCodecParserContext *parser;
|
||||
get_parser(ds->sh, &avctx, &parser);
|
||||
if (!parser)
|
||||
return *len;
|
||||
return av_parser_parse2(parser, avctx, buffer, len, *buffer, *len, pts, pts, pos);
|
||||
}
|
||||
|
||||
static void clear_parser(sh_audio_t *sh)
|
||||
{
|
||||
av_parser_close(sh->parser);
|
||||
sh->parser = NULL;
|
||||
av_freep(&sh->avctx);
|
||||
}
|
||||
|
||||
void ds_clear_parser(demux_stream_t *ds)
|
||||
{
|
||||
if (!ds->sh)
|
||||
return;
|
||||
clear_parser(ds->sh);
|
||||
}
|
||||
|
||||
void ds_read_packet(demux_stream_t *ds, stream_t *stream, int len,
|
||||
double pts, int64_t pos, bool keyframe)
|
||||
{
|
||||
|
@ -292,9 +292,6 @@ int ds_get_packet_pts(struct demux_stream *ds, unsigned char **start,
|
||||
struct demux_packet *ds_get_packet_sub(demux_stream_t *ds);
|
||||
struct demux_packet *ds_get_packet2(struct demux_stream *ds, bool repeat_last);
|
||||
double ds_get_next_pts(struct demux_stream *ds);
|
||||
int ds_parse(struct demux_stream *sh, uint8_t **buffer, int *len, double pts,
|
||||
int64_t pos);
|
||||
void ds_clear_parser(struct demux_stream *sh);
|
||||
|
||||
struct demuxer *demux_open(struct MPOpts *opts, struct stream *stream,
|
||||
int file_format, int aid, int vid, int sid,
|
||||
|
@ -70,7 +70,6 @@ static demuxer_t* demux_rawaudio_open(demuxer_t* demuxer) {
|
||||
demuxer->audio->id = 0;
|
||||
demuxer->audio->sh = sh_audio;
|
||||
sh_audio->ds = demuxer->audio;
|
||||
sh_audio->needs_parsing = 1;
|
||||
|
||||
return demuxer;
|
||||
}
|
||||
|
@ -117,10 +117,6 @@ typedef struct sh_audio {
|
||||
unsigned char *codecdata;
|
||||
int codecdata_len;
|
||||
int pts_bytes; // bytes output by decoder after last known pts
|
||||
/* things needed for parsing */
|
||||
bool needs_parsing;
|
||||
struct AVCodecContext *avctx;
|
||||
struct AVCodecParserContext *parser;
|
||||
} sh_audio_t;
|
||||
|
||||
typedef struct sh_video {
|
||||
|
Loading…
Reference in New Issue
Block a user