summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/ffmpeg/ffplay.c
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/ffmpeg/ffplay.c')
-rw-r--r--chromium/third_party/ffmpeg/ffplay.c87
1 files changed, 66 insertions, 21 deletions
diff --git a/chromium/third_party/ffmpeg/ffplay.c b/chromium/third_party/ffmpeg/ffplay.c
index 4893ebcb2f5..86b9126ab2d 100644
--- a/chromium/third_party/ffmpeg/ffplay.c
+++ b/chromium/third_party/ffmpeg/ffplay.c
@@ -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 {
@@ -357,8 +359,6 @@ int64_t get_valid_channel_layout(int64_t channel_layout, int channels)
return 0;
}
-static int packet_queue_put(PacketQueue *q, AVPacket *pkt);
-
static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
{
MyAVPacketList *pkt1;
@@ -1608,7 +1608,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);
}
}
@@ -1727,7 +1727,8 @@ static int get_video_frame(VideoState *is, AVFrame *frame, AVPacket *pkt, int *s
static int configure_filtergraph(AVFilterGraph *graph, const char *filtergraph,
AVFilterContext *source_ctx, AVFilterContext *sink_ctx)
{
- int ret;
+ int ret, i;
+ int nb_filters = graph->nb_filters;
AVFilterInOut *outputs = NULL, *inputs = NULL;
if (filtergraph) {
@@ -1755,6 +1756,10 @@ static int configure_filtergraph(AVFilterGraph *graph, const char *filtergraph,
goto fail;
}
+ /* Reorder the filters to ensure that inputs of the custom filters are merged first */
+ for (i = 0; i < graph->nb_filters - nb_filters; i++)
+ FFSWAP(AVFilterContext*, graph->filters[i], graph->filters[i + nb_filters]);
+
ret = avfilter_graph_config(graph, NULL);
fail:
avfilter_inout_free(&outputs);
@@ -1920,7 +1925,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 +1951,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 +1965,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;
@@ -2167,7 +2167,6 @@ static int audio_decode_frame(VideoState *is)
return AVERROR(ENOMEM);
} else {
av_frame_unref(is->frame);
- avcodec_get_frame_defaults(is->frame);
}
if (is->audioq.serial != is->audio_pkt_temp_serial)
@@ -2242,7 +2241,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
@@ -2379,8 +2377,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();
@@ -2390,7 +2386,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);
@@ -2406,11 +2402,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);
}
}
@@ -2469,6 +2464,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;
}
@@ -2573,7 +2574,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));
@@ -2751,6 +2752,8 @@ static int read_thread(void *arg)
if (genpts)
ic->flags |= AVFMT_FLAG_GENPTS;
+ av_format_inject_global_side_data(ic);
+
opts = setup_find_stream_info_opts(ic, codec_opts);
orig_nb_streams = ic->nb_streams;
@@ -2947,6 +2950,8 @@ static int read_thread(void *arg)
packet_queue_put_nullpacket(&is->videoq, is->video_stream);
if (is->audio_stream >= 0)
packet_queue_put_nullpacket(&is->audioq, is->audio_stream);
+ if (is->subtitle_stream >= 0)
+ packet_queue_put_nullpacket(&is->subtitleq, is->subtitle_stream);
SDL_Delay(10);
eof=0;
continue;
@@ -3117,6 +3122,11 @@ static void stream_cycle_channel(VideoState *is, int codec_type)
the_end:
if (p && stream_index != -1)
stream_index = p->stream_index[stream_index];
+ av_log(NULL, AV_LOG_INFO, "Switch %s stream from #%d to #%d\n",
+ av_get_media_type_string(codec_type),
+ old_index,
+ stream_index);
+
stream_component_close(is, old_index);
stream_component_open(is, stream_index);
}
@@ -3167,6 +3177,33 @@ static void refresh_loop_wait_event(VideoState *is, SDL_Event *event) {
}
}
+static void seek_chapter(VideoState *is, int incr)
+{
+ int64_t pos = get_master_clock(is) * AV_TIME_BASE;
+ int i;
+
+ if (!is->ic->nb_chapters)
+ return;
+
+ /* find the current chapter */
+ for (i = 0; i < is->ic->nb_chapters; i++) {
+ AVChapter *ch = is->ic->chapters[i];
+ if (av_compare_ts(pos, AV_TIME_BASE_Q, ch->start, ch->time_base) < 0) {
+ i--;
+ break;
+ }
+ }
+
+ i += incr;
+ i = FFMAX(i, 0);
+ if (i >= is->ic->nb_chapters)
+ return;
+
+ av_log(NULL, AV_LOG_VERBOSE, "Seeking to chapter %d.\n", i);
+ stream_seek(is, av_rescale_q(is->ic->chapters[i]->start, is->ic->chapters[i]->time_base,
+ AV_TIME_BASE_Q), 0, 0);
+}
+
/* handle an event sent by the GUI */
static void event_loop(VideoState *cur_stream)
{
@@ -3216,11 +3253,19 @@ static void event_loop(VideoState *cur_stream)
toggle_audio_display(cur_stream);
break;
case SDLK_PAGEUP:
- incr = 600.0;
- goto do_seek;
+ if (cur_stream->ic->nb_chapters <= 1) {
+ incr = 600.0;
+ goto do_seek;
+ }
+ seek_chapter(cur_stream, 1);
+ break;
case SDLK_PAGEDOWN:
- incr = -600.0;
- goto do_seek;
+ if (cur_stream->ic->nb_chapters <= 1) {
+ incr = -600.0;
+ goto do_seek;
+ }
+ seek_chapter(cur_stream, -1);
+ break;
case SDLK_LEFT:
incr = -10.0;
goto do_seek;