[FFmpeg-devel] [PATCH] ffplay: use symbolic constant values for show_audio
Stefano Sabatini
stefano.sabatini-lala at poste.it
Tue Apr 12 13:11:25 CEST 2011
Also rename VideoState->show_audio to show_mode.
Improve readability.
---
ffplay.c | 21 ++++++++++++---------
1 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/ffplay.c b/ffplay.c
index b9e9d87..d9aa124 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -169,7 +169,9 @@ typedef struct VideoState {
enum AVSampleFormat audio_src_fmt;
AVAudioConvert *reformat_ctx;
- int show_audio; /* if true, display audio samples */
+ enum {
+ SHOW_MODE_VIDEO = 0, SHOW_MODE_WAVES, SHOW_MODE_RFDT, SHOW_MODE_NB
+ } show_mode;
int16_t sample_array[SAMPLE_ARRAY_SIZE];
int sample_array_index;
int last_i_start;
@@ -791,7 +793,7 @@ static void video_audio_display(VideoState *s)
channels = s->audio_st->codec->channels;
nb_display_channels = channels;
if (!s->paused) {
- int data_used= s->show_audio==1 ? s->width : (2*nb_freq);
+ int data_used= s->show_mode == SHOW_MODE_WAVES ? s->width : (2*nb_freq);
n = 2 * channels;
delay = audio_write_get_buf_size(s);
delay /= n;
@@ -808,7 +810,7 @@ static void video_audio_display(VideoState *s)
delay = data_used;
i_start= x = compute_mod(s->sample_array_index - delay * channels, SAMPLE_ARRAY_SIZE);
- if(s->show_audio==1){
+ if (s->show_mode == SHOW_MODE_WAVES) {
h= INT_MIN;
for(i=0; i<1000; i+=channels){
int idx= (SAMPLE_ARRAY_SIZE + x - i) % SAMPLE_ARRAY_SIZE;
@@ -830,7 +832,7 @@ static void video_audio_display(VideoState *s)
}
bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
- if(s->show_audio==1){
+ if (s->show_mode == SHOW_MODE_WAVES) {
fill_rectangle(screen,
s->xleft, s->ytop, s->width, s->height,
bgcolor);
@@ -970,7 +972,7 @@ static void video_display(VideoState *is)
{
if(!screen)
video_open(cur_stream);
- if (is->audio_st && is->show_audio)
+ if (is->audio_st && is->show_mode != SHOW_MODE_VIDEO)
video_audio_display(is);
else if (is->video_st)
video_image_display(is);
@@ -987,7 +989,8 @@ static int refresh_thread(void *opaque)
is->refresh=1;
SDL_PushEvent(&event);
}
- usleep(is->audio_st && is->show_audio ? rdftspeed*1000 : 5000); //FIXME ideally we should wait the correct time but SDLs event passing is so slow it would be silly
+ //FIXME ideally we should wait the correct time but SDLs event passing is so slow it would be silly
+ usleep(is->audio_st && is->show_mode != SHOW_MODE_VIDEO ? rdftspeed*1000 : 5000);
}
return 0;
}
@@ -2174,7 +2177,7 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
is->audio_buf_size = 1024;
memset(is->audio_buf, 0, is->audio_buf_size);
} else {
- if (is->show_audio)
+ if (is->show_mode != SHOW_MODE_VIDEO)
update_sample_display(is, (int16_t *)is->audio_buf, audio_size);
audio_size = synchronize_audio(is, (int16_t *)is->audio_buf, audio_size,
pts);
@@ -2479,7 +2482,7 @@ static int decode_thread(void *arg)
is->refresh_tid = SDL_CreateThread(refresh_thread, is);
if(ret<0) {
if (!display_disable)
- is->show_audio = 2;
+ is->show_mode = SHOW_MODE_RFDT;
}
if (st_index[AVMEDIA_TYPE_SUBTITLE] >= 0) {
@@ -2734,7 +2737,7 @@ static void toggle_audio_display(void)
{
if (cur_stream) {
int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
- cur_stream->show_audio = (cur_stream->show_audio + 1) % 3;
+ cur_stream->show_mode = (cur_stream->show_mode + 1) % SHOW_MODE_NB;
fill_rectangle(screen,
cur_stream->xleft, cur_stream->ytop, cur_stream->width, cur_stream->height,
bgcolor);
--
1.7.2.3
More information about the ffmpeg-devel
mailing list