Browse code

ffplay: use audio parameters from the decoded frame instead of AVCodecContext

Based on commit by Justin Ruggles (the changed code is too different to apply as is)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2012/10/13 23:45:01
Showing 1 changed files
... ...
@@ -1974,34 +1974,34 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr)
1974 1974
                     flush_complete = 1;
1975 1975
                 continue;
1976 1976
             }
1977
-            data_size = av_samples_get_buffer_size(NULL, dec->channels,
1977
+            data_size = av_samples_get_buffer_size(NULL, is->frame->channels,
1978 1978
                                                    is->frame->nb_samples,
1979
-                                                   dec->sample_fmt, 1);
1979
+                                                   is->frame->format, 1);
1980 1980
 
1981 1981
             dec_channel_layout =
1982
-                (dec->channel_layout && dec->channels == av_get_channel_layout_nb_channels(dec->channel_layout)) ?
1983
-                dec->channel_layout : av_get_default_channel_layout(dec->channels);
1982
+                (is->frame->channel_layout && is->frame->channels == av_get_channel_layout_nb_channels(is->frame->channel_layout)) ?
1983
+                is->frame->channel_layout : av_get_default_channel_layout(is->frame->channels);
1984 1984
             wanted_nb_samples = synchronize_audio(is, is->frame->nb_samples);
1985 1985
 
1986
-            if (dec->sample_fmt    != is->audio_src.fmt            ||
1987
-                dec_channel_layout != is->audio_src.channel_layout ||
1988
-                dec->sample_rate   != is->audio_src.freq           ||
1989
-                (wanted_nb_samples != is->frame->nb_samples && !is->swr_ctx)) {
1986
+            if (is->frame->format        != is->audio_src.fmt            ||
1987
+                dec_channel_layout       != is->audio_src.channel_layout ||
1988
+                is->frame->sample_rate   != is->audio_src.freq           ||
1989
+                (wanted_nb_samples       != is->frame->nb_samples && !is->swr_ctx)) {
1990 1990
                 swr_free(&is->swr_ctx);
1991 1991
                 is->swr_ctx = swr_alloc_set_opts(NULL,
1992 1992
                                                  is->audio_tgt.channel_layout, is->audio_tgt.fmt, is->audio_tgt.freq,
1993
-                                                 dec_channel_layout,           dec->sample_fmt,   dec->sample_rate,
1993
+                                                 dec_channel_layout,           is->frame->format, is->frame->sample_rate,
1994 1994
                                                  0, NULL);
1995 1995
                 if (!is->swr_ctx || swr_init(is->swr_ctx) < 0) {
1996 1996
                     fprintf(stderr, "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n",
1997
-                        dec->sample_rate,   av_get_sample_fmt_name(dec->sample_fmt),   dec->channels,
1997
+                        is->frame->sample_rate,   av_get_sample_fmt_name(is->frame->format), (int)is->frame->channels,
1998 1998
                         is->audio_tgt.freq, av_get_sample_fmt_name(is->audio_tgt.fmt), is->audio_tgt.channels);
1999 1999
                     break;
2000 2000
                 }
2001 2001
                 is->audio_src.channel_layout = dec_channel_layout;
2002
-                is->audio_src.channels = dec->channels;
2003
-                is->audio_src.freq = dec->sample_rate;
2004
-                is->audio_src.fmt = dec->sample_fmt;
2002
+                is->audio_src.channels = is->frame->channels;
2003
+                is->audio_src.freq = is->frame->sample_rate;
2004
+                is->audio_src.fmt = is->frame->format;
2005 2005
             }
2006 2006
 
2007 2007
             if (is->swr_ctx) {
... ...
@@ -2009,8 +2009,8 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr)
2009 2009
                 uint8_t *out[] = {is->audio_buf2};
2010 2010
                 int out_count = sizeof(is->audio_buf2) / is->audio_tgt.channels / av_get_bytes_per_sample(is->audio_tgt.fmt);
2011 2011
                 if (wanted_nb_samples != is->frame->nb_samples) {
2012
-                    if (swr_set_compensation(is->swr_ctx, (wanted_nb_samples - is->frame->nb_samples) * is->audio_tgt.freq / dec->sample_rate,
2013
-                                                wanted_nb_samples * is->audio_tgt.freq / dec->sample_rate) < 0) {
2012
+                    if (swr_set_compensation(is->swr_ctx, (wanted_nb_samples - is->frame->nb_samples) * is->audio_tgt.freq / is->frame->sample_rate,
2013
+                                                wanted_nb_samples * is->audio_tgt.freq / is->frame->sample_rate) < 0) {
2014 2014
                         fprintf(stderr, "swr_set_compensation() failed\n");
2015 2015
                         break;
2016 2016
                     }
... ...
@@ -2035,7 +2035,7 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr)
2035 2035
             pts = is->audio_clock;
2036 2036
             *pts_ptr = pts;
2037 2037
             is->audio_clock += (double)data_size /
2038
-                (dec->channels * dec->sample_rate * av_get_bytes_per_sample(dec->sample_fmt));
2038
+                (is->frame->channels * is->frame->sample_rate * av_get_bytes_per_sample(is->frame->format));
2039 2039
 #ifdef DEBUG
2040 2040
             {
2041 2041
                 static double last_clock;