diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-12-29 16:32:43 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-12-29 16:32:46 +0100 |
commit | 828ac6d1b515ce421519a641b23b05127acc06cd (patch) | |
tree | ed53e59eae42529a062c7d23558f6bbde7d7fcfb | |
parent | 1acd029f40de1a0d3ca292cbbe06ea5a173a84ae (diff) | |
parent | ac7b4bfdeb6af11348f15d4a308fcbe61e68b58b (diff) | |
download | ffmpeg-828ac6d1b515ce421519a641b23b05127acc06cd.tar.gz |
Merge remote-tracking branch 'cus/stable'
* cus/stable:
ffplay: do not wait for the picture allocation to finish on exit
ffplay: remove two unneeded av_free_packet calls
ffplay: remove some unneded av_frame_unref calls
ffplay: remove unneeded avcodec_get_frame_defaults
ffplay: use precalculated frame size and bytes per sec values
ffplay: precalculate audio output frame size and byte per sec
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | ffplay.c | 25 |
1 files changed, 12 insertions, 13 deletions
@@ -145,6 +145,8 @@ typedef struct AudioParams { int channels; int64_t channel_layout; enum AVSampleFormat fmt; + int frame_size; + int bytes_per_sec; } AudioParams; typedef struct Clock { @@ -1608,7 +1610,7 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, double } /* if the queue is aborted, we have to pop the pending ALLOC event or wait for the allocation to complete */ if (is->videoq.abort_request && SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENTMASK(FF_ALLOC_EVENT)) != 1) { - while (!vp->allocated) { + while (!vp->allocated && !is->abort_request) { SDL_CondWait(is->pictq_cond, is->pictq_mutex); } } @@ -1920,7 +1922,6 @@ static int video_thread(void *arg) while (is->paused && !is->videoq.abort_request) SDL_Delay(10); - avcodec_get_frame_defaults(frame); av_free_packet(&pkt); ret = get_video_frame(is, frame, &pkt, &serial); @@ -1947,7 +1948,6 @@ static int video_thread(void *arg) event.type = FF_QUIT_EVENT; event.user.data1 = is; SDL_PushEvent(&event); - av_free_packet(&pkt); goto the_end; } filt_in = is->in_video_filter; @@ -1962,9 +1962,6 @@ static int video_thread(void *arg) ret = av_buffersrc_add_frame(filt_in, frame); if (ret < 0) goto the_end; - av_frame_unref(frame); - avcodec_get_frame_defaults(frame); - av_free_packet(&pkt); while (ret >= 0) { is->frame_last_returned_time = av_gettime() / 1000000.0; @@ -2241,7 +2238,6 @@ static int audio_decode_frame(VideoState *is) if ((ret = av_buffersrc_add_frame(is->in_audio_filter, is->frame)) < 0) return ret; - av_frame_unref(is->frame); #endif } #if CONFIG_AVFILTER @@ -2378,8 +2374,6 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len) { VideoState *is = opaque; int audio_size, len1; - int bytes_per_sec; - int frame_size = av_samples_get_buffer_size(NULL, is->audio_tgt.channels, 1, is->audio_tgt.fmt, 1); audio_callback_time = av_gettime(); @@ -2389,7 +2383,7 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len) if (audio_size < 0) { /* if error, just output silence */ is->audio_buf = is->silence_buf; - is->audio_buf_size = sizeof(is->silence_buf) / frame_size * frame_size; + is->audio_buf_size = sizeof(is->silence_buf) / is->audio_tgt.frame_size * is->audio_tgt.frame_size; } else { if (is->show_mode != SHOW_MODE_VIDEO) update_sample_display(is, (int16_t *)is->audio_buf, audio_size); @@ -2405,11 +2399,10 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len) stream += len1; is->audio_buf_index += len1; } - bytes_per_sec = is->audio_tgt.freq * is->audio_tgt.channels * av_get_bytes_per_sample(is->audio_tgt.fmt); is->audio_write_buf_size = is->audio_buf_size - is->audio_buf_index; /* Let's assume the audio driver that is used by SDL has two periods. */ if (!isnan(is->audio_clock)) { - set_clock_at(&is->audclk, is->audio_clock - (double)(2 * is->audio_hw_buf_size + is->audio_write_buf_size) / bytes_per_sec, is->audio_clock_serial, audio_callback_time / 1000000.0); + set_clock_at(&is->audclk, is->audio_clock - (double)(2 * is->audio_hw_buf_size + is->audio_write_buf_size) / is->audio_tgt.bytes_per_sec, is->audio_clock_serial, audio_callback_time / 1000000.0); sync_clock_to_slave(&is->extclk, &is->audclk); } } @@ -2468,6 +2461,12 @@ static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb audio_hw_params->freq = spec.freq; audio_hw_params->channel_layout = wanted_channel_layout; audio_hw_params->channels = spec.channels; + audio_hw_params->frame_size = av_samples_get_buffer_size(NULL, audio_hw_params->channels, 1, audio_hw_params->fmt, 1); + audio_hw_params->bytes_per_sec = av_samples_get_buffer_size(NULL, audio_hw_params->channels, audio_hw_params->freq, audio_hw_params->fmt, 1); + if (audio_hw_params->bytes_per_sec <= 0 || audio_hw_params->frame_size <= 0) { + av_log(NULL, AV_LOG_ERROR, "av_samples_get_buffer_size failed\n"); + return -1; + } return spec.size; } @@ -2572,7 +2571,7 @@ static int stream_component_open(VideoState *is, int stream_index) is->audio_diff_avg_count = 0; /* since we do not have a precise anough audio fifo fullness, we correct audio sync only if larger than this threshold */ - is->audio_diff_threshold = 2.0 * is->audio_hw_buf_size / av_samples_get_buffer_size(NULL, is->audio_tgt.channels, is->audio_tgt.freq, is->audio_tgt.fmt, 1); + is->audio_diff_threshold = 2.0 * is->audio_hw_buf_size / is->audio_tgt.bytes_per_sec; memset(&is->audio_pkt, 0, sizeof(is->audio_pkt)); memset(&is->audio_pkt_temp, 0, sizeof(is->audio_pkt_temp)); |