From 571ef42dd4eb260b213464ed15d288a887b6679a Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sat, 26 Jan 2013 22:32:39 +0100 Subject: [PATCH 1/5] ffplay: dynamically allocate audio buffer We simply remove the fixed length VideoState->audio_buf2 and use the previously unused VideoState->audio_buf1. Fixes ticket #2191. Signed-off-by: Marton Balint --- ffplay.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ffplay.c b/ffplay.c index 93090ad60b..96a2ee1304 100644 --- a/ffplay.c +++ b/ffplay.c @@ -181,11 +181,11 @@ typedef struct VideoState { AVStream *audio_st; PacketQueue audioq; int audio_hw_buf_size; - DECLARE_ALIGNED(16,uint8_t,audio_buf2)[AVCODEC_MAX_AUDIO_FRAME_SIZE * 4]; uint8_t silence_buf[SDL_AUDIO_BUFFER_SIZE]; uint8_t *audio_buf; uint8_t *audio_buf1; unsigned int audio_buf_size; /* in bytes */ + unsigned int audio_buf1_size; int audio_buf_index; /* in bytes */ int audio_write_buf_size; AVPacket audio_pkt_temp; @@ -2143,8 +2143,9 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) if (is->swr_ctx) { const uint8_t **in = (const uint8_t **)is->frame->extended_data; - uint8_t *out[] = {is->audio_buf2}; - int out_count = sizeof(is->audio_buf2) / is->audio_tgt.channels / av_get_bytes_per_sample(is->audio_tgt.fmt); + uint8_t **out = &is->audio_buf1; + int out_count = (int64_t)wanted_nb_samples * is->audio_tgt.freq / is->frame->sample_rate + 256; + int out_size = av_samples_get_buffer_size(NULL, is->audio_tgt.channels, out_count, is->audio_tgt.fmt, 0); if (wanted_nb_samples != is->frame->nb_samples) { if (swr_set_compensation(is->swr_ctx, (wanted_nb_samples - is->frame->nb_samples) * is->audio_tgt.freq / is->frame->sample_rate, wanted_nb_samples * is->audio_tgt.freq / is->frame->sample_rate) < 0) { @@ -2152,6 +2153,9 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) break; } } + av_fast_malloc(&is->audio_buf1, &is->audio_buf1_size, out_size); + if (!is->audio_buf1) + return AVERROR(ENOMEM); len2 = swr_convert(is->swr_ctx, out, out_count, in, is->frame->nb_samples); if (len2 < 0) { fprintf(stderr, "swr_convert() failed\n"); @@ -2161,7 +2165,7 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) fprintf(stderr, "warning: audio buffer is probably too small\n"); swr_init(is->swr_ctx); } - is->audio_buf = is->audio_buf2; + is->audio_buf = is->audio_buf1; resampled_data_size = len2 * is->audio_tgt.channels * av_get_bytes_per_sample(is->audio_tgt.fmt); } else { is->audio_buf = is->frame->data[0]; @@ -2437,6 +2441,7 @@ static void stream_component_close(VideoState *is, int stream_index) av_free_packet(&is->audio_pkt); swr_free(&is->swr_ctx); av_freep(&is->audio_buf1); + is->audio_buf1_size = 0; is->audio_buf = NULL; avcodec_free_frame(&is->frame); From 4fd6e5af1e334875eca4f803bbcfac9219b0524a Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sun, 27 Jan 2013 00:45:47 +0100 Subject: [PATCH 2/5] ffplay: fix order of setting show_mode Without the fix the refresh event may have got called with unset show mode. Fixes ticket #2174. Signed-off-by: Marton Balint --- ffplay.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ffplay.c b/ffplay.c index 96a2ee1304..6cdbafe68c 100644 --- a/ffplay.c +++ b/ffplay.c @@ -2641,10 +2641,11 @@ static int read_thread(void *arg) if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) { ret = stream_component_open(is, st_index[AVMEDIA_TYPE_VIDEO]); } - is->refresh_tid = SDL_CreateThread(refresh_thread, is); if (is->show_mode == SHOW_MODE_NONE) is->show_mode = ret >= 0 ? SHOW_MODE_VIDEO : SHOW_MODE_RDFT; + is->refresh_tid = SDL_CreateThread(refresh_thread, is); + if (st_index[AVMEDIA_TYPE_SUBTITLE] >= 0) { stream_component_open(is, st_index[AVMEDIA_TYPE_SUBTITLE]); } From 5de3f724f1524ee01843f0d9c0033253b65c69ec Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sun, 27 Jan 2013 14:03:15 +0100 Subject: [PATCH 3/5] ffplay: remember last window dimensions After this change the dimensions of single image videos will be remembered when coming back from full screen. The issue was mentioned in ticket #2174. Signed-off-by: Marton Balint --- ffplay.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ffplay.c b/ffplay.c index 6cdbafe68c..c9750bf834 100644 --- a/ffplay.c +++ b/ffplay.c @@ -268,6 +268,8 @@ static const char *input_filename; static const char *window_title; static int fs_screen_width; static int fs_screen_height; +static int default_width = 640; +static int default_height = 480; static int screen_width = 0; static int screen_height = 0; static int audio_disable; @@ -1022,29 +1024,30 @@ static void sigterm_handler(int sig) exit(123); } -static int video_open(VideoState *is, int force_set_video_mode) +static int video_open(VideoState *is, int force_set_video_mode, VideoPicture *vp) { int flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL; int w,h; - VideoPicture *vp = &is->pictq[is->pictq_rindex]; SDL_Rect rect; if (is_full_screen) flags |= SDL_FULLSCREEN; else flags |= SDL_RESIZABLE; + if (vp && vp->width) { + calculate_display_rect(&rect, 0, 0, INT_MAX, vp->height, vp); + default_width = rect.w; + default_height = rect.h; + } + if (is_full_screen && fs_screen_width) { w = fs_screen_width; h = fs_screen_height; } else if (!is_full_screen && screen_width) { w = screen_width; h = screen_height; - } else if (vp->width) { - calculate_display_rect(&rect, 0, 0, INT_MAX, vp->height, vp); - w = rect.w; - h = rect.h; } else { - w = 640; - h = 480; + w = default_width; + h = default_height; } if (screen && is->width == screen->w && screen->w == w && is->height== screen->h && screen->h == h && !force_set_video_mode) @@ -1068,7 +1071,7 @@ static int video_open(VideoState *is, int force_set_video_mode) static void video_display(VideoState *is) { if (!screen) - video_open(is, 0); + video_open(is, 0, NULL); if (is->audio_st && is->show_mode != SHOW_MODE_VIDEO) video_audio_display(is); else if (is->video_st) @@ -1458,7 +1461,7 @@ static void alloc_picture(VideoState *is) avfilter_unref_bufferp(&vp->picref); #endif - video_open(is, 0); + video_open(is, 0, vp); vp->bmp = SDL_CreateYUVOverlay(vp->width, vp->height, SDL_YV12_OVERLAY, @@ -2919,7 +2922,7 @@ static void toggle_full_screen(VideoState *is) is->pictq[i].reallocate = 1; #endif is_full_screen = !is_full_screen; - video_open(is, 1); + video_open(is, 1, NULL); } static void toggle_pause(VideoState *is) From c5eab4bb70cc9884ff1e0e11cb2f980bb3b40937 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sat, 19 Jan 2013 01:44:38 +0100 Subject: [PATCH 4/5] ffplay: move up pause functions No change in functionality. Signed-off-by: Marton Balint --- ffplay.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ffplay.c b/ffplay.c index c9750bf834..c723b74a19 100644 --- a/ffplay.c +++ b/ffplay.c @@ -1220,6 +1220,20 @@ static void stream_toggle_pause(VideoState *is) is->paused = !is->paused; } +static void toggle_pause(VideoState *is) +{ + stream_toggle_pause(is); + is->step = 0; +} + +static void step_to_next_frame(VideoState *is) +{ + /* if the stream is paused unpause it, then step */ + if (is->paused) + stream_toggle_pause(is); + is->step = 1; +} + static double compute_target_delay(double delay, VideoState *is) { double sync_threshold, diff; @@ -2925,20 +2939,6 @@ static void toggle_full_screen(VideoState *is) video_open(is, 1, NULL); } -static void toggle_pause(VideoState *is) -{ - stream_toggle_pause(is); - is->step = 0; -} - -static void step_to_next_frame(VideoState *is) -{ - /* if the stream is paused unpause it, then step */ - if (is->paused) - stream_toggle_pause(is); - is->step = 1; -} - static void toggle_audio_display(VideoState *is) { int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); From 4ea7fbb2ec1a8833b6683655b98f4bf42f817102 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sat, 19 Jan 2013 01:57:50 +0100 Subject: [PATCH 5/5] ffplay: step to next frame if paused when seeking Signed-off-by: Marton Balint --- ffplay.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ffplay.c b/ffplay.c index c723b74a19..58ff99d4ce 100644 --- a/ffplay.c +++ b/ffplay.c @@ -2728,6 +2728,8 @@ static int read_thread(void *arg) } is->seek_req = 0; eof = 0; + if (is->paused) + step_to_next_frame(is); } if (is->queue_attachments_req) { avformat_queue_attached_pictures(ic);