• Home
  • Raw
  • Download

Lines Matching refs:is

975 static void video_image_display(VideoState *is)  in video_image_display()  argument
981 vp = frame_queue_peek_last(&is->pictq); in video_image_display()
982 if (is->subtitle_st) { in video_image_display()
983 if (frame_queue_nb_remaining(&is->subpq) > 0) { in video_image_display()
984 sp = frame_queue_peek(&is->subpq); in video_image_display()
995 …if (realloc_texture(&is->sub_texture, SDL_PIXELFORMAT_ARGB8888, sp->width, sp->height, SDL_BLENDMO… in video_image_display()
1006 is->sub_convert_ctx = sws_getCachedContext(is->sub_convert_ctx, in video_image_display()
1010 if (!is->sub_convert_ctx) { in video_image_display()
1014 … if (!SDL_LockTexture(is->sub_texture, (SDL_Rect *)sub_rect, (void **)pixels, pitch)) { in video_image_display()
1015 … sws_scale(is->sub_convert_ctx, (const uint8_t * const *)sub_rect->data, sub_rect->linesize, in video_image_display()
1017 SDL_UnlockTexture(is->sub_texture); in video_image_display()
1027 …calculate_display_rect(&rect, is->xleft, is->ytop, is->width, is->height, vp->width, vp->height, v… in video_image_display()
1030 if (upload_texture(&is->vid_texture, vp->frame, &is->img_convert_ctx) < 0) in video_image_display()
1037 …SDL_RenderCopyEx(renderer, is->vid_texture, NULL, &rect, 0, NULL, vp->flip_v ? SDL_FLIP_VERTICAL :… in video_image_display()
1041 SDL_RenderCopy(renderer, is->sub_texture, NULL, &rect); in video_image_display()
1052 SDL_RenderCopy(renderer, is->sub_texture, sub_rect, &target); in video_image_display()
1205 static void stream_component_close(VideoState *is, int stream_index) in stream_component_close() argument
1207 AVFormatContext *ic = is->ic; in stream_component_close()
1216 decoder_abort(&is->auddec, &is->sampq); in stream_component_close()
1218 decoder_destroy(&is->auddec); in stream_component_close()
1219 swr_free(&is->swr_ctx); in stream_component_close()
1220 av_freep(&is->audio_buf1); in stream_component_close()
1221 is->audio_buf1_size = 0; in stream_component_close()
1222 is->audio_buf = NULL; in stream_component_close()
1224 if (is->rdft) { in stream_component_close()
1225 av_rdft_end(is->rdft); in stream_component_close()
1226 av_freep(&is->rdft_data); in stream_component_close()
1227 is->rdft = NULL; in stream_component_close()
1228 is->rdft_bits = 0; in stream_component_close()
1232 decoder_abort(&is->viddec, &is->pictq); in stream_component_close()
1233 decoder_destroy(&is->viddec); in stream_component_close()
1236 decoder_abort(&is->subdec, &is->subpq); in stream_component_close()
1237 decoder_destroy(&is->subdec); in stream_component_close()
1246 is->audio_st = NULL; in stream_component_close()
1247 is->audio_stream = -1; in stream_component_close()
1250 is->video_st = NULL; in stream_component_close()
1251 is->video_stream = -1; in stream_component_close()
1254 is->subtitle_st = NULL; in stream_component_close()
1255 is->subtitle_stream = -1; in stream_component_close()
1262 static void stream_close(VideoState *is) in stream_close() argument
1265 is->abort_request = 1; in stream_close()
1266 SDL_WaitThread(is->read_tid, NULL); in stream_close()
1269 if (is->audio_stream >= 0) in stream_close()
1270 stream_component_close(is, is->audio_stream); in stream_close()
1271 if (is->video_stream >= 0) in stream_close()
1272 stream_component_close(is, is->video_stream); in stream_close()
1273 if (is->subtitle_stream >= 0) in stream_close()
1274 stream_component_close(is, is->subtitle_stream); in stream_close()
1276 avformat_close_input(&is->ic); in stream_close()
1278 packet_queue_destroy(&is->videoq); in stream_close()
1279 packet_queue_destroy(&is->audioq); in stream_close()
1280 packet_queue_destroy(&is->subtitleq); in stream_close()
1283 frame_queue_destory(&is->pictq); in stream_close()
1284 frame_queue_destory(&is->sampq); in stream_close()
1285 frame_queue_destory(&is->subpq); in stream_close()
1286 SDL_DestroyCond(is->continue_read_thread); in stream_close()
1287 sws_freeContext(is->img_convert_ctx); in stream_close()
1288 sws_freeContext(is->sub_convert_ctx); in stream_close()
1289 av_free(is->filename); in stream_close()
1290 if (is->vis_texture) in stream_close()
1291 SDL_DestroyTexture(is->vis_texture); in stream_close()
1292 if (is->vid_texture) in stream_close()
1293 SDL_DestroyTexture(is->vid_texture); in stream_close()
1294 if (is->sub_texture) in stream_close()
1295 SDL_DestroyTexture(is->sub_texture); in stream_close()
1296 av_free(is); in stream_close()
1299 static void do_exit(VideoState *is) in do_exit() argument
1301 if (is) { in do_exit()
1302 stream_close(is); in do_exit()
1337 static int video_open(VideoState *is) in video_open() argument
1354 is->width = w; in video_open()
1355 is->height = h; in video_open()
1361 static void video_display(VideoState *is) in video_display() argument
1363 if (!is->width) in video_display()
1364 video_open(is); in video_display()
1368 if (is->audio_st && is->show_mode != SHOW_MODE_VIDEO) in video_display()
1369 video_audio_display(is); in video_display()
1370 else if (is->video_st) in video_display()
1371 video_image_display(is); in video_display()
1423 static int get_master_sync_type(VideoState *is) { in get_master_sync_type() argument
1424 if (is->av_sync_type == AV_SYNC_VIDEO_MASTER) { in get_master_sync_type()
1425 if (is->video_st) in get_master_sync_type()
1429 } else if (is->av_sync_type == AV_SYNC_AUDIO_MASTER) { in get_master_sync_type()
1430 if (is->audio_st) in get_master_sync_type()
1440 static double get_master_clock(VideoState *is) in get_master_clock() argument
1444 switch (get_master_sync_type(is)) { in get_master_clock()
1446 val = get_clock(&is->vidclk); in get_master_clock()
1449 val = get_clock(&is->audclk); in get_master_clock()
1452 val = get_clock(&is->extclk); in get_master_clock()
1458 static void check_external_clock_speed(VideoState *is) { in check_external_clock_speed() argument
1459 if (is->video_stream >= 0 && is->videoq.nb_packets <= EXTERNAL_CLOCK_MIN_FRAMES || in check_external_clock_speed()
1460 is->audio_stream >= 0 && is->audioq.nb_packets <= EXTERNAL_CLOCK_MIN_FRAMES) { in check_external_clock_speed()
1461 …set_clock_speed(&is->extclk, FFMAX(EXTERNAL_CLOCK_SPEED_MIN, is->extclk.speed - EXTERNAL_CLOCK_SPE… in check_external_clock_speed()
1462 } else if ((is->video_stream < 0 || is->videoq.nb_packets > EXTERNAL_CLOCK_MAX_FRAMES) && in check_external_clock_speed()
1463 (is->audio_stream < 0 || is->audioq.nb_packets > EXTERNAL_CLOCK_MAX_FRAMES)) { in check_external_clock_speed()
1464 …set_clock_speed(&is->extclk, FFMIN(EXTERNAL_CLOCK_SPEED_MAX, is->extclk.speed + EXTERNAL_CLOCK_SPE… in check_external_clock_speed()
1466 double speed = is->extclk.speed; in check_external_clock_speed()
1468 …set_clock_speed(&is->extclk, speed + EXTERNAL_CLOCK_SPEED_STEP * (1.0 - speed) / fabs(1.0 - speed)… in check_external_clock_speed()
1473 static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int seek_by_bytes) in stream_seek() argument
1475 if (!is->seek_req) { in stream_seek()
1476 is->seek_pos = pos; in stream_seek()
1477 is->seek_rel = rel; in stream_seek()
1478 is->seek_flags &= ~AVSEEK_FLAG_BYTE; in stream_seek()
1480 is->seek_flags |= AVSEEK_FLAG_BYTE; in stream_seek()
1481 is->seek_req = 1; in stream_seek()
1482 SDL_CondSignal(is->continue_read_thread); in stream_seek()
1487 static void stream_toggle_pause(VideoState *is) in stream_toggle_pause() argument
1489 if (is->paused) { in stream_toggle_pause()
1490 is->frame_timer += av_gettime_relative() / 1000000.0 - is->vidclk.last_updated; in stream_toggle_pause()
1491 if (is->read_pause_return != AVERROR(ENOSYS)) { in stream_toggle_pause()
1492 is->vidclk.paused = 0; in stream_toggle_pause()
1494 set_clock(&is->vidclk, get_clock(&is->vidclk), is->vidclk.serial); in stream_toggle_pause()
1496 set_clock(&is->extclk, get_clock(&is->extclk), is->extclk.serial); in stream_toggle_pause()
1497 is->paused = is->audclk.paused = is->vidclk.paused = is->extclk.paused = !is->paused; in stream_toggle_pause()
1500 static void toggle_pause(VideoState *is) in toggle_pause() argument
1502 stream_toggle_pause(is); in toggle_pause()
1503 is->step = 0; in toggle_pause()
1506 static void toggle_mute(VideoState *is) in toggle_mute() argument
1508 is->muted = !is->muted; in toggle_mute()
1511 static void update_volume(VideoState *is, int sign, double step) in update_volume() argument
1513 …double volume_level = is->audio_volume ? (20 * log(is->audio_volume / (double)SDL_MIX_MAXVOLUME) /… in update_volume()
1515is->audio_volume = av_clip(is->audio_volume == new_volume ? (is->audio_volume + sign) : new_volume… in update_volume()
1518 static void step_to_next_frame(VideoState *is) in step_to_next_frame() argument
1521 if (is->paused) in step_to_next_frame()
1522 stream_toggle_pause(is); in step_to_next_frame()
1523 is->step = 1; in step_to_next_frame()
1526 static double compute_target_delay(double delay, VideoState *is) in compute_target_delay() argument
1531 if (get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER) { in compute_target_delay()
1534 diff = get_clock(&is->vidclk) - get_master_clock(is); in compute_target_delay()
1540 if (!isnan(diff) && fabs(diff) < is->max_frame_duration) { in compute_target_delay()
1556 static double vp_duration(VideoState *is, Frame *vp, Frame *nextvp) { in vp_duration() argument
1559 if (isnan(duration) || duration <= 0 || duration > is->max_frame_duration) in vp_duration()
1568 static void update_video_pts(VideoState *is, double pts, int64_t pos, int serial) { in update_video_pts() argument
1570 set_clock(&is->vidclk, pts, serial); in update_video_pts()
1571 sync_clock_to_slave(&is->extclk, &is->vidclk); in update_video_pts()
1577 VideoState *is = opaque; in video_refresh() local
1582 if (!is->paused && get_master_sync_type(is) == AV_SYNC_EXTERNAL_CLOCK && is->realtime) in video_refresh()
1583 check_external_clock_speed(is); in video_refresh()
1585 if (!display_disable && is->show_mode != SHOW_MODE_VIDEO && is->audio_st) { in video_refresh()
1587 if (is->force_refresh || is->last_vis_time + rdftspeed < time) { in video_refresh()
1588 video_display(is); in video_refresh()
1589 is->last_vis_time = time; in video_refresh()
1591 *remaining_time = FFMIN(*remaining_time, is->last_vis_time + rdftspeed - time); in video_refresh()
1594 if (is->video_st) { in video_refresh()
1596 if (frame_queue_nb_remaining(&is->pictq) == 0) { in video_refresh()
1603 lastvp = frame_queue_peek_last(&is->pictq); in video_refresh()
1604 vp = frame_queue_peek(&is->pictq); in video_refresh()
1606 if (vp->serial != is->videoq.serial) { in video_refresh()
1607 frame_queue_next(&is->pictq); in video_refresh()
1612 is->frame_timer = av_gettime_relative() / 1000000.0; in video_refresh()
1614 if (is->paused) in video_refresh()
1618 last_duration = vp_duration(is, lastvp, vp); in video_refresh()
1619 delay = compute_target_delay(last_duration, is); in video_refresh()
1622 if (time < is->frame_timer + delay) { in video_refresh()
1623 *remaining_time = FFMIN(is->frame_timer + delay - time, *remaining_time); in video_refresh()
1627 is->frame_timer += delay; in video_refresh()
1628 if (delay > 0 && time - is->frame_timer > AV_SYNC_THRESHOLD_MAX) in video_refresh()
1629 is->frame_timer = time; in video_refresh()
1631 SDL_LockMutex(is->pictq.mutex); in video_refresh()
1633 update_video_pts(is, vp->pts, vp->pos, vp->serial); in video_refresh()
1634 SDL_UnlockMutex(is->pictq.mutex); in video_refresh()
1636 if (frame_queue_nb_remaining(&is->pictq) > 1) { in video_refresh()
1637 Frame *nextvp = frame_queue_peek_next(&is->pictq); in video_refresh()
1638 duration = vp_duration(is, vp, nextvp); in video_refresh()
1639 …if(!is->step && (framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) &… in video_refresh()
1640 is->frame_drops_late++; in video_refresh()
1641 frame_queue_next(&is->pictq); in video_refresh()
1646 if (is->subtitle_st) { in video_refresh()
1647 while (frame_queue_nb_remaining(&is->subpq) > 0) { in video_refresh()
1648 sp = frame_queue_peek(&is->subpq); in video_refresh()
1650 if (frame_queue_nb_remaining(&is->subpq) > 1) in video_refresh()
1651 sp2 = frame_queue_peek_next(&is->subpq); in video_refresh()
1655 if (sp->serial != is->subtitleq.serial in video_refresh()
1656 … || (is->vidclk.pts > (sp->pts + ((float) sp->sub.end_display_time / 1000))) in video_refresh()
1657 … || (sp2 && is->vidclk.pts > (sp2->pts + ((float) sp2->sub.start_display_time / 1000)))) in video_refresh()
1666 … if (!SDL_LockTexture(is->sub_texture, (SDL_Rect *)sub_rect, (void **)&pixels, &pitch)) { in video_refresh()
1669 SDL_UnlockTexture(is->sub_texture); in video_refresh()
1673 frame_queue_next(&is->subpq); in video_refresh()
1680 frame_queue_next(&is->pictq); in video_refresh()
1681 is->force_refresh = 1; in video_refresh()
1683 if (is->step && !is->paused) in video_refresh()
1684 stream_toggle_pause(is); in video_refresh()
1688 …if (!display_disable && is->force_refresh && is->show_mode == SHOW_MODE_VIDEO && is->pictq.rindex_… in video_refresh()
1689 video_display(is); in video_refresh()
1691 is->force_refresh = 0; in video_refresh()
1704 if (is->audio_st) in video_refresh()
1705 aqsize = is->audioq.size; in video_refresh()
1706 if (is->video_st) in video_refresh()
1707 vqsize = is->videoq.size; in video_refresh()
1708 if (is->subtitle_st) in video_refresh()
1709 sqsize = is->subtitleq.size; in video_refresh()
1711 if (is->audio_st && is->video_st) in video_refresh()
1712 av_diff = get_clock(&is->audclk) - get_clock(&is->vidclk); in video_refresh()
1713 else if (is->video_st) in video_refresh()
1714 av_diff = get_master_clock(is) - get_clock(&is->vidclk); in video_refresh()
1715 else if (is->audio_st) in video_refresh()
1716 av_diff = get_master_clock(is) - get_clock(&is->audclk); in video_refresh()
1721 get_master_clock(is), in video_refresh()
1722 … (is->audio_st && is->video_st) ? "A-V" : (is->video_st ? "M-V" : (is->audio_st ? "M-A" : " ")), in video_refresh()
1724 is->frame_drops_early + is->frame_drops_late, in video_refresh()
1728 is->video_st ? is->viddec.avctx->pts_correction_num_faulty_dts : 0, in video_refresh()
1729 is->video_st ? is->viddec.avctx->pts_correction_num_faulty_pts : 0); in video_refresh()
1744 static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, double duration, int64_t p… in queue_picture() argument
1753 if (!(vp = frame_queue_peek_writable(&is->pictq))) in queue_picture()
1771 frame_queue_push(&is->pictq); in queue_picture()
1775 static int get_video_frame(VideoState *is, AVFrame *frame) in get_video_frame() argument
1779 if ((got_picture = decoder_decode_frame(&is->viddec, frame, NULL)) < 0) in get_video_frame()
1786 dpts = av_q2d(is->video_st->time_base) * frame->pts; in get_video_frame()
1788 frame->sample_aspect_ratio = av_guess_sample_aspect_ratio(is->ic, is->video_st, frame); in get_video_frame()
1790 if (framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) { in get_video_frame()
1792 double diff = dpts - get_master_clock(is); in get_video_frame()
1794 diff - is->frame_last_filter_delay < 0 && in get_video_frame()
1795 is->viddec.pkt_serial == is->vidclk.serial && in get_video_frame()
1796 is->videoq.nb_packets) { in get_video_frame()
1797 is->frame_drops_early++; in get_video_frame()
1852 static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const char *vfilters, AVFr… in configure_video_filters() argument
1859 AVCodecParameters *codecpar = is->video_st->codecpar; in configure_video_filters()
1860 AVRational fr = av_guess_frame_rate(is->ic, is->video_st, NULL); in configure_video_filters()
1889 is->video_st->time_base.num, is->video_st->time_base.den, in configure_video_filters()
1930 double theta = get_rotation(is->video_st); in configure_video_filters()
1949 is->in_video_filter = filt_src; in configure_video_filters()
1950 is->out_video_filter = filt_out; in configure_video_filters()
1956 static int configure_audio_filters(VideoState *is, const char *afilters, int force_output_format) in configure_audio_filters() argument
1968 avfilter_graph_free(&is->agraph); in configure_audio_filters()
1969 if (!(is->agraph = avfilter_graph_alloc())) in configure_audio_filters()
1971 is->agraph->nb_threads = filter_nbthreads; in configure_audio_filters()
1977 av_opt_set(is->agraph, "aresample_swr_opts", aresample_swr_opts, 0); in configure_audio_filters()
1981 is->audio_filter_src.freq, av_get_sample_fmt_name(is->audio_filter_src.fmt), in configure_audio_filters()
1982 is->audio_filter_src.channels, in configure_audio_filters()
1983 1, is->audio_filter_src.freq); in configure_audio_filters()
1984 if (is->audio_filter_src.channel_layout) in configure_audio_filters()
1986 ":channel_layout=0x%"PRIx64, is->audio_filter_src.channel_layout); in configure_audio_filters()
1990 asrc_args, NULL, is->agraph); in configure_audio_filters()
1997 NULL, NULL, is->agraph); in configure_audio_filters()
2007 channel_layouts[0] = is->audio_tgt.channel_layout; in configure_audio_filters()
2008 channels [0] = is->audio_tgt.channel_layout ? -1 : is->audio_tgt.channels; in configure_audio_filters()
2009 sample_rates [0] = is->audio_tgt.freq; in configure_audio_filters()
2021 if ((ret = configure_filtergraph(is->agraph, afilters, filt_asrc, filt_asink)) < 0) in configure_audio_filters()
2024 is->in_audio_filter = filt_asrc; in configure_audio_filters()
2025 is->out_audio_filter = filt_asink; in configure_audio_filters()
2029 avfilter_graph_free(&is->agraph); in configure_audio_filters()
2036 VideoState *is = arg; in audio_thread() local
2052 if ((got_frame = decoder_decode_frame(&is->auddec, frame, NULL)) < 0) in audio_thread()
2062 cmp_audio_fmts(is->audio_filter_src.fmt, is->audio_filter_src.channels, in audio_thread()
2064 is->audio_filter_src.channel_layout != dec_channel_layout || in audio_thread()
2065 is->audio_filter_src.freq != frame->sample_rate || in audio_thread()
2066 is->auddec.pkt_serial != last_serial; in audio_thread()
2070 … av_get_channel_layout_string(buf1, sizeof(buf1), -1, is->audio_filter_src.channel_layout); in audio_thread()
2074is->audio_filter_src.freq, is->audio_filter_src.channels, av_get_sample_fmt_name(is->audio_filter_… in audio_thread()
2075 …>sample_rate, frame->channels, av_get_sample_fmt_name(frame->format), buf2, is->auddec.pkt_serial); in audio_thread()
2077 is->audio_filter_src.fmt = frame->format; in audio_thread()
2078 is->audio_filter_src.channels = frame->channels; in audio_thread()
2079 is->audio_filter_src.channel_layout = dec_channel_layout; in audio_thread()
2080 is->audio_filter_src.freq = frame->sample_rate; in audio_thread()
2081 last_serial = is->auddec.pkt_serial; in audio_thread()
2083 if ((ret = configure_audio_filters(is, afilters, 1)) < 0) in audio_thread()
2087 if ((ret = av_buffersrc_add_frame(is->in_audio_filter, frame)) < 0) in audio_thread()
2090 while ((ret = av_buffersink_get_frame_flags(is->out_audio_filter, frame, 0)) >= 0) { in audio_thread()
2091 tb = av_buffersink_get_time_base(is->out_audio_filter); in audio_thread()
2093 if (!(af = frame_queue_peek_writable(&is->sampq))) in audio_thread()
2098 af->serial = is->auddec.pkt_serial; in audio_thread()
2102 frame_queue_push(&is->sampq); in audio_thread()
2105 if (is->audioq.serial != is->auddec.pkt_serial) in audio_thread()
2109 is->auddec.finished = is->auddec.pkt_serial; in audio_thread()
2115 avfilter_graph_free(&is->agraph); in audio_thread()
2134 VideoState *is = arg; in video_thread() local
2139 AVRational tb = is->video_st->time_base; in video_thread()
2140 AVRational frame_rate = av_guess_frame_rate(is->ic, is->video_st, NULL); in video_thread()
2156 ret = get_video_frame(is, frame); in video_thread()
2166 || last_serial != is->viddec.pkt_serial in video_thread()
2167 || last_vfilter_idx != is->vfilter_idx) { in video_thread()
2173 … (const char *)av_x_if_null(av_get_pix_fmt_name(frame->format), "none"), is->viddec.pkt_serial); in video_thread()
2181 …if ((ret = configure_video_filters(graph, is, vfilters_list ? vfilters_list[is->vfilter_idx] : NUL… in video_thread()
2184 event.user.data1 = is; in video_thread()
2188 filt_in = is->in_video_filter; in video_thread()
2189 filt_out = is->out_video_filter; in video_thread()
2193 last_serial = is->viddec.pkt_serial; in video_thread()
2194 last_vfilter_idx = is->vfilter_idx; in video_thread()
2203 is->frame_last_returned_time = av_gettime_relative() / 1000000.0; in video_thread()
2208 is->viddec.finished = is->viddec.pkt_serial; in video_thread()
2213is->frame_last_filter_delay = av_gettime_relative() / 1000000.0 - is->frame_last_returned_time; in video_thread()
2214 if (fabs(is->frame_last_filter_delay) > AV_NOSYNC_THRESHOLD / 10.0) in video_thread()
2215 is->frame_last_filter_delay = 0; in video_thread()
2220 ret = queue_picture(is, frame, pts, duration, frame->pkt_pos, is->viddec.pkt_serial); in video_thread()
2223 if (is->videoq.serial != is->viddec.pkt_serial) in video_thread()
2241 VideoState *is = arg; in subtitle_thread() local
2247 if (!(sp = frame_queue_peek_writable(&is->subpq))) in subtitle_thread()
2250 if ((got_subtitle = decoder_decode_frame(&is->subdec, NULL, &sp->sub)) < 0) in subtitle_thread()
2259 sp->serial = is->subdec.pkt_serial; in subtitle_thread()
2260 sp->width = is->subdec.avctx->width; in subtitle_thread()
2261 sp->height = is->subdec.avctx->height; in subtitle_thread()
2265 frame_queue_push(&is->subpq); in subtitle_thread()
2274 static void update_sample_display(VideoState *is, short *samples, int samples_size) in update_sample_display() argument
2280 len = SAMPLE_ARRAY_SIZE - is->sample_array_index; in update_sample_display()
2283 memcpy(is->sample_array + is->sample_array_index, samples, len * sizeof(short)); in update_sample_display()
2285 is->sample_array_index += len; in update_sample_display()
2286 if (is->sample_array_index >= SAMPLE_ARRAY_SIZE) in update_sample_display()
2287 is->sample_array_index = 0; in update_sample_display()
2294 static int synchronize_audio(VideoState *is, int nb_samples) in synchronize_audio() argument
2299 if (get_master_sync_type(is) != AV_SYNC_AUDIO_MASTER) { in synchronize_audio()
2303 diff = get_clock(&is->audclk) - get_master_clock(is); in synchronize_audio()
2306 is->audio_diff_cum = diff + is->audio_diff_avg_coef * is->audio_diff_cum; in synchronize_audio()
2307 if (is->audio_diff_avg_count < AUDIO_DIFF_AVG_NB) { in synchronize_audio()
2309 is->audio_diff_avg_count++; in synchronize_audio()
2312 avg_diff = is->audio_diff_cum * (1.0 - is->audio_diff_avg_coef); in synchronize_audio()
2314 if (fabs(avg_diff) >= is->audio_diff_threshold) { in synchronize_audio()
2315 wanted_nb_samples = nb_samples + (int)(diff * is->audio_src.freq); in synchronize_audio()
2322 is->audio_clock, is->audio_diff_threshold); in synchronize_audio()
2327 is->audio_diff_avg_count = 0; in synchronize_audio()
2328 is->audio_diff_cum = 0; in synchronize_audio()
2342 static int audio_decode_frame(VideoState *is) in audio_decode_frame() argument
2350 if (is->paused) in audio_decode_frame()
2355 while (frame_queue_nb_remaining(&is->sampq) == 0) { in audio_decode_frame()
2356 …f ((av_gettime_relative() - audio_callback_time) > 1000000LL * is->audio_hw_buf_size / is->audio_t… in audio_decode_frame()
2361 if (!(af = frame_queue_peek_readable(&is->sampq))) in audio_decode_frame()
2363 frame_queue_next(&is->sampq); in audio_decode_frame()
2364 } while (af->serial != is->audioq.serial); in audio_decode_frame()
2373 wanted_nb_samples = synchronize_audio(is, af->frame->nb_samples); in audio_decode_frame()
2375 if (af->frame->format != is->audio_src.fmt || in audio_decode_frame()
2376 dec_channel_layout != is->audio_src.channel_layout || in audio_decode_frame()
2377 af->frame->sample_rate != is->audio_src.freq || in audio_decode_frame()
2378 (wanted_nb_samples != af->frame->nb_samples && !is->swr_ctx)) { in audio_decode_frame()
2379 swr_free(&is->swr_ctx); in audio_decode_frame()
2380 is->swr_ctx = swr_alloc_set_opts(NULL, in audio_decode_frame()
2381is->audio_tgt.channel_layout, is->audio_tgt.fmt, is->audio_tgt.freq, in audio_decode_frame()
2384 if (!is->swr_ctx || swr_init(is->swr_ctx) < 0) { in audio_decode_frame()
2388is->audio_tgt.freq, av_get_sample_fmt_name(is->audio_tgt.fmt), is->audio_tgt.channels); in audio_decode_frame()
2389 swr_free(&is->swr_ctx); in audio_decode_frame()
2392 is->audio_src.channel_layout = dec_channel_layout; in audio_decode_frame()
2393 is->audio_src.channels = af->frame->channels; in audio_decode_frame()
2394 is->audio_src.freq = af->frame->sample_rate; in audio_decode_frame()
2395 is->audio_src.fmt = af->frame->format; in audio_decode_frame()
2398 if (is->swr_ctx) { in audio_decode_frame()
2400 uint8_t **out = &is->audio_buf1; in audio_decode_frame()
2401 … int out_count = (int64_t)wanted_nb_samples * is->audio_tgt.freq / af->frame->sample_rate + 256; in audio_decode_frame()
2402 …int out_size = av_samples_get_buffer_size(NULL, is->audio_tgt.channels, out_count, is->audio_tgt.… in audio_decode_frame()
2409 …if (swr_set_compensation(is->swr_ctx, (wanted_nb_samples - af->frame->nb_samples) * is->audio_tgt.… in audio_decode_frame()
2410 … wanted_nb_samples * is->audio_tgt.freq / af->frame->sample_rate) < 0) { in audio_decode_frame()
2415 av_fast_malloc(&is->audio_buf1, &is->audio_buf1_size, out_size); in audio_decode_frame()
2416 if (!is->audio_buf1) in audio_decode_frame()
2418 len2 = swr_convert(is->swr_ctx, out, out_count, in, af->frame->nb_samples); in audio_decode_frame()
2425 if (swr_init(is->swr_ctx) < 0) in audio_decode_frame()
2426 swr_free(&is->swr_ctx); in audio_decode_frame()
2428 is->audio_buf = is->audio_buf1; in audio_decode_frame()
2429 … resampled_data_size = len2 * is->audio_tgt.channels * av_get_bytes_per_sample(is->audio_tgt.fmt); in audio_decode_frame()
2431 is->audio_buf = af->frame->data[0]; in audio_decode_frame()
2435 audio_clock0 = is->audio_clock; in audio_decode_frame()
2438 is->audio_clock = af->pts + (double) af->frame->nb_samples / af->frame->sample_rate; in audio_decode_frame()
2440 is->audio_clock = NAN; in audio_decode_frame()
2441 is->audio_clock_serial = af->serial; in audio_decode_frame()
2446 is->audio_clock - last_clock, in audio_decode_frame()
2447 is->audio_clock, audio_clock0); in audio_decode_frame()
2448 last_clock = is->audio_clock; in audio_decode_frame()
2457 VideoState *is = opaque; in sdl_audio_callback() local
2463 if (is->audio_buf_index >= is->audio_buf_size) { in sdl_audio_callback()
2464 audio_size = audio_decode_frame(is); in sdl_audio_callback()
2467 is->audio_buf = NULL; in sdl_audio_callback()
2468is->audio_buf_size = SDL_AUDIO_MIN_BUFFER_SIZE / is->audio_tgt.frame_size * is->audio_tgt.frame_si… in sdl_audio_callback()
2470 if (is->show_mode != SHOW_MODE_VIDEO) in sdl_audio_callback()
2471 update_sample_display(is, (int16_t *)is->audio_buf, audio_size); in sdl_audio_callback()
2472 is->audio_buf_size = audio_size; in sdl_audio_callback()
2474 is->audio_buf_index = 0; in sdl_audio_callback()
2476 len1 = is->audio_buf_size - is->audio_buf_index; in sdl_audio_callback()
2479 if (!is->muted && is->audio_buf && is->audio_volume == SDL_MIX_MAXVOLUME) in sdl_audio_callback()
2480 memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1); in sdl_audio_callback()
2483 if (!is->muted && is->audio_buf) in sdl_audio_callback()
2484 …SDL_MixAudioFormat(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, AUDIO_S16SYS, len1, is-… in sdl_audio_callback()
2488 is->audio_buf_index += len1; in sdl_audio_callback()
2490 is->audio_write_buf_size = is->audio_buf_size - is->audio_buf_index; in sdl_audio_callback()
2492 if (!isnan(is->audio_clock)) { in sdl_audio_callback()
2493 …et_clock_at(&is->audclk, is->audio_clock - (double)(2 * is->audio_hw_buf_size + is->audio_write_bu… in sdl_audio_callback()
2494 sync_clock_to_slave(&is->extclk, &is->audclk); in sdl_audio_callback()
2572 static int stream_component_open(VideoState *is, int stream_index) in stream_component_open() argument
2574 AVFormatContext *ic = is->ic; in stream_component_open()
2600 …case AVMEDIA_TYPE_AUDIO : is->last_audio_stream = stream_index; forced_codec_name = audio_… in stream_component_open()
2601 …case AVMEDIA_TYPE_SUBTITLE: is->last_subtitle_stream = stream_index; forced_codec_name = subtitle_… in stream_component_open()
2602 …case AVMEDIA_TYPE_VIDEO : is->last_video_stream = stream_index; forced_codec_name = video_… in stream_component_open()
2640 is->eof = 0; in stream_component_open()
2648 is->audio_filter_src.freq = avctx->sample_rate; in stream_component_open()
2649 is->audio_filter_src.channels = avctx->channels; in stream_component_open()
2650is->audio_filter_src.channel_layout = get_valid_channel_layout(avctx->channel_layout, avctx->chann… in stream_component_open()
2651 is->audio_filter_src.fmt = avctx->sample_fmt; in stream_component_open()
2652 if ((ret = configure_audio_filters(is, afilters, 0)) < 0) in stream_component_open()
2654 sink = is->out_audio_filter; in stream_component_open()
2666 if ((ret = audio_open(is, channel_layout, nb_channels, sample_rate, &is->audio_tgt)) < 0) in stream_component_open()
2668 is->audio_hw_buf_size = ret; in stream_component_open()
2669 is->audio_src = is->audio_tgt; in stream_component_open()
2670 is->audio_buf_size = 0; in stream_component_open()
2671 is->audio_buf_index = 0; in stream_component_open()
2674 is->audio_diff_avg_coef = exp(log(0.01) / AUDIO_DIFF_AVG_NB); in stream_component_open()
2675 is->audio_diff_avg_count = 0; in stream_component_open()
2678 is->audio_diff_threshold = (double)(is->audio_hw_buf_size) / is->audio_tgt.bytes_per_sec; in stream_component_open()
2680 is->audio_stream = stream_index; in stream_component_open()
2681 is->audio_st = ic->streams[stream_index]; in stream_component_open()
2683 if ((ret = decoder_init(&is->auddec, avctx, &is->audioq, is->continue_read_thread)) < 0) in stream_component_open()
2685 …if ((is->ic->iformat->flags & (AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK)) && !is in stream_component_open()
2686 is->auddec.start_pts = is->audio_st->start_time; in stream_component_open()
2687 is->auddec.start_pts_tb = is->audio_st->time_base; in stream_component_open()
2689 if ((ret = decoder_start(&is->auddec, audio_thread, "audio_decoder", is)) < 0) in stream_component_open()
2694 is->video_stream = stream_index; in stream_component_open()
2695 is->video_st = ic->streams[stream_index]; in stream_component_open()
2697 if ((ret = decoder_init(&is->viddec, avctx, &is->videoq, is->continue_read_thread)) < 0) in stream_component_open()
2699 if ((ret = decoder_start(&is->viddec, video_thread, "video_decoder", is)) < 0) in stream_component_open()
2701 is->queue_attachments_req = 1; in stream_component_open()
2704 is->subtitle_stream = stream_index; in stream_component_open()
2705 is->subtitle_st = ic->streams[stream_index]; in stream_component_open()
2707 if ((ret = decoder_init(&is->subdec, avctx, &is->subtitleq, is->continue_read_thread)) < 0) in stream_component_open()
2709 if ((ret = decoder_start(&is->subdec, subtitle_thread, "subtitle_decoder", is)) < 0) in stream_component_open()
2727 VideoState *is = ctx; in decode_interrupt_cb() local
2728 return is->abort_request; in decode_interrupt_cb()
2757 VideoState *is = arg; in read_thread() local
2776 is->eof = 0; in read_thread()
2791 ic->interrupt_callback.opaque = is; in read_thread()
2796 err = avformat_open_input(&ic, is->filename, is->iformat, &format_opts); in read_thread()
2798 print_error(is->filename, err); in read_thread()
2810 is->ic = ic; in read_thread()
2829 "%s: could not find codec parameters\n", is->filename); in read_thread()
2841 is->max_frame_duration = (ic->iformat->flags & AVFMT_TS_DISCONT) ? 10.0 : 3600.0; in read_thread()
2857 is->filename, (double)timestamp / AV_TIME_BASE); in read_thread()
2861 is->realtime = is_realtime(ic); in read_thread()
2864 av_dump_format(ic, 0, is->filename, 0); in read_thread()
2900 is->show_mode = show_mode; in read_thread()
2911 stream_component_open(is, st_index[AVMEDIA_TYPE_AUDIO]); in read_thread()
2916 ret = stream_component_open(is, st_index[AVMEDIA_TYPE_VIDEO]); in read_thread()
2918 if (is->show_mode == SHOW_MODE_NONE) in read_thread()
2919 is->show_mode = ret >= 0 ? SHOW_MODE_VIDEO : SHOW_MODE_RDFT; in read_thread()
2922 stream_component_open(is, st_index[AVMEDIA_TYPE_SUBTITLE]); in read_thread()
2925 if (is->video_stream < 0 && is->audio_stream < 0) { in read_thread()
2927 is->filename); in read_thread()
2932 if (infinite_buffer < 0 && is->realtime) in read_thread()
2936 if (is->abort_request) in read_thread()
2938 if (is->paused != is->last_paused) { in read_thread()
2939 is->last_paused = is->paused; in read_thread()
2940 if (is->paused) in read_thread()
2941 is->read_pause_return = av_read_pause(ic); in read_thread()
2946 if (is->paused && in read_thread()
2955 if (is->seek_req) { in read_thread()
2956 int64_t seek_target = is->seek_pos; in read_thread()
2957 int64_t seek_min = is->seek_rel > 0 ? seek_target - is->seek_rel + 2: INT64_MIN; in read_thread()
2958 int64_t seek_max = is->seek_rel < 0 ? seek_target - is->seek_rel - 2: INT64_MAX; in read_thread()
2962 ret = avformat_seek_file(is->ic, -1, seek_min, seek_target, seek_max, is->seek_flags); in read_thread()
2965 "%s: error while seeking\n", is->ic->url); in read_thread()
2967 if (is->audio_stream >= 0) in read_thread()
2968 packet_queue_flush(&is->audioq); in read_thread()
2969 if (is->subtitle_stream >= 0) in read_thread()
2970 packet_queue_flush(&is->subtitleq); in read_thread()
2971 if (is->video_stream >= 0) in read_thread()
2972 packet_queue_flush(&is->videoq); in read_thread()
2973 if (is->seek_flags & AVSEEK_FLAG_BYTE) { in read_thread()
2974 set_clock(&is->extclk, NAN, 0); in read_thread()
2976 set_clock(&is->extclk, seek_target / (double)AV_TIME_BASE, 0); in read_thread()
2979 is->seek_req = 0; in read_thread()
2980 is->queue_attachments_req = 1; in read_thread()
2981 is->eof = 0; in read_thread()
2982 if (is->paused) in read_thread()
2983 step_to_next_frame(is); in read_thread()
2985 if (is->queue_attachments_req) { in read_thread()
2986 if (is->video_st && is->video_st->disposition & AV_DISPOSITION_ATTACHED_PIC) { in read_thread()
2987 if ((ret = av_packet_ref(pkt, &is->video_st->attached_pic)) < 0) in read_thread()
2989 packet_queue_put(&is->videoq, pkt); in read_thread()
2990 packet_queue_put_nullpacket(&is->videoq, pkt, is->video_stream); in read_thread()
2992 is->queue_attachments_req = 0; in read_thread()
2997 (is->audioq.size + is->videoq.size + is->subtitleq.size > MAX_QUEUE_SIZE in read_thread()
2998 || (stream_has_enough_packets(is->audio_st, is->audio_stream, &is->audioq) && in read_thread()
2999 stream_has_enough_packets(is->video_st, is->video_stream, &is->videoq) && in read_thread()
3000 stream_has_enough_packets(is->subtitle_st, is->subtitle_stream, &is->subtitleq)))) { in read_thread()
3003 SDL_CondWaitTimeout(is->continue_read_thread, wait_mutex, 10); in read_thread()
3007 if (!is->paused && in read_thread()
3008 …(!is->audio_st || (is->auddec.finished == is->audioq.serial && frame_queue_nb_remaining(&is->sampq… in read_thread()
3009 …(!is->video_st || (is->viddec.finished == is->videoq.serial && frame_queue_nb_remaining(&is->pictq… in read_thread()
3011 stream_seek(is, start_time != AV_NOPTS_VALUE ? start_time : 0, 0, 0); in read_thread()
3019 if ((ret == AVERROR_EOF || avio_feof(ic->pb)) && !is->eof) { in read_thread()
3020 if (is->video_stream >= 0) in read_thread()
3021 packet_queue_put_nullpacket(&is->videoq, pkt, is->video_stream); in read_thread()
3022 if (is->audio_stream >= 0) in read_thread()
3023 packet_queue_put_nullpacket(&is->audioq, pkt, is->audio_stream); in read_thread()
3024 if (is->subtitle_stream >= 0) in read_thread()
3025 packet_queue_put_nullpacket(&is->subtitleq, pkt, is->subtitle_stream); in read_thread()
3026 is->eof = 1; in read_thread()
3035 SDL_CondWaitTimeout(is->continue_read_thread, wait_mutex, 10); in read_thread()
3039 is->eof = 0; in read_thread()
3049 if (pkt->stream_index == is->audio_stream && pkt_in_play_range) { in read_thread()
3050 packet_queue_put(&is->audioq, pkt); in read_thread()
3051 } else if (pkt->stream_index == is->video_stream && pkt_in_play_range in read_thread()
3052 && !(is->video_st->disposition & AV_DISPOSITION_ATTACHED_PIC)) { in read_thread()
3053 packet_queue_put(&is->videoq, pkt); in read_thread()
3054 } else if (pkt->stream_index == is->subtitle_stream && pkt_in_play_range) { in read_thread()
3055 packet_queue_put(&is->subtitleq, pkt); in read_thread()
3063 if (ic && !is->ic) in read_thread()
3071 event.user.data1 = is; in read_thread()
3080 VideoState *is; in stream_open() local
3082 is = av_mallocz(sizeof(VideoState)); in stream_open()
3083 if (!is) in stream_open()
3085 is->last_video_stream = is->video_stream = -1; in stream_open()
3086 is->last_audio_stream = is->audio_stream = -1; in stream_open()
3087 is->last_subtitle_stream = is->subtitle_stream = -1; in stream_open()
3088 is->filename = av_strdup(filename); in stream_open()
3089 if (!is->filename) in stream_open()
3091 is->iformat = iformat; in stream_open()
3092 is->ytop = 0; in stream_open()
3093 is->xleft = 0; in stream_open()
3096 if (frame_queue_init(&is->pictq, &is->videoq, VIDEO_PICTURE_QUEUE_SIZE, 1) < 0) in stream_open()
3098 if (frame_queue_init(&is->subpq, &is->subtitleq, SUBPICTURE_QUEUE_SIZE, 0) < 0) in stream_open()
3100 if (frame_queue_init(&is->sampq, &is->audioq, SAMPLE_QUEUE_SIZE, 1) < 0) in stream_open()
3103 if (packet_queue_init(&is->videoq) < 0 || in stream_open()
3104 packet_queue_init(&is->audioq) < 0 || in stream_open()
3105 packet_queue_init(&is->subtitleq) < 0) in stream_open()
3108 if (!(is->continue_read_thread = SDL_CreateCond())) { in stream_open()
3113 init_clock(&is->vidclk, &is->videoq.serial); in stream_open()
3114 init_clock(&is->audclk, &is->audioq.serial); in stream_open()
3115 init_clock(&is->extclk, &is->extclk.serial); in stream_open()
3116 is->audio_clock_serial = -1; in stream_open()
3123 is->audio_volume = startup_volume; in stream_open()
3124 is->muted = 0; in stream_open()
3125 is->av_sync_type = av_sync_type; in stream_open()
3126 is->read_tid = SDL_CreateThread(read_thread, "read_thread", is); in stream_open()
3127 if (!is->read_tid) { in stream_open()
3130 stream_close(is); in stream_open()
3133 return is; in stream_open()
3136 static void stream_cycle_channel(VideoState *is, int codec_type) in stream_cycle_channel() argument
3138 AVFormatContext *ic = is->ic; in stream_cycle_channel()
3143 int nb_streams = is->ic->nb_streams; in stream_cycle_channel()
3146 start_index = is->last_video_stream; in stream_cycle_channel()
3147 old_index = is->video_stream; in stream_cycle_channel()
3149 start_index = is->last_audio_stream; in stream_cycle_channel()
3150 old_index = is->audio_stream; in stream_cycle_channel()
3152 start_index = is->last_subtitle_stream; in stream_cycle_channel()
3153 old_index = is->subtitle_stream; in stream_cycle_channel()
3157 if (codec_type != AVMEDIA_TYPE_VIDEO && is->video_stream != -1) { in stream_cycle_channel()
3158 p = av_find_program_from_stream(ic, NULL, is->video_stream); in stream_cycle_channel()
3176 is->last_subtitle_stream = -1; in stream_cycle_channel()
3185 st = is->ic->streams[p ? p->stream_index[stream_index] : stream_index]; in stream_cycle_channel()
3210 stream_component_close(is, old_index); in stream_cycle_channel()
3211 stream_component_open(is, stream_index); in stream_cycle_channel()
3215 static void toggle_full_screen(VideoState *is) in toggle_full_screen() argument
3221 static void toggle_audio_display(VideoState *is) in toggle_audio_display() argument
3223 int next = is->show_mode; in toggle_audio_display()
3226 …} while (next != is->show_mode && (next == SHOW_MODE_VIDEO && !is->video_st || next != SHOW_MODE_V… in toggle_audio_display()
3227 if (is->show_mode != next) { in toggle_audio_display()
3228 is->force_refresh = 1; in toggle_audio_display()
3229 is->show_mode = next; in toggle_audio_display()
3233 static void refresh_loop_wait_event(VideoState *is, SDL_Event *event) { in refresh_loop_wait_event() argument
3244 if (is->show_mode != SHOW_MODE_NONE && (!is->paused || is->force_refresh)) in refresh_loop_wait_event()
3245 video_refresh(is, &remaining_time); in refresh_loop_wait_event()
3250 static void seek_chapter(VideoState *is, int incr) in seek_chapter() argument
3252 int64_t pos = get_master_clock(is) * AV_TIME_BASE; in seek_chapter()
3255 if (!is->ic->nb_chapters) in seek_chapter()
3259 for (i = 0; i < is->ic->nb_chapters; i++) { in seek_chapter()
3260 AVChapter *ch = is->ic->chapters[i]; in seek_chapter()
3269 if (i >= is->ic->nb_chapters) in seek_chapter()
3273 stream_seek(is, av_rescale_q(is->ic->chapters[i]->start, is->ic->chapters[i]->time_base, in seek_chapter()
3686 VideoState *is; in main() local
3770 is = stream_open(input_filename, file_iformat); in main()
3771 if (!is) { in main()
3776 event_loop(is); in main()