31 #include "libavutil/avstring.h"
33 #include "libavutil/mathematics.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/imgutils.h"
36 #include "libavutil/dict.h"
37 #include "libavutil/parseutils.h"
38 #include "libavutil/samplefmt.h"
39 #include "libavutil/avassert.h"
40 #include "libavutil/time.h"
41 #include "libavformat/avformat.h"
42 #include "libavdevice/avdevice.h"
43 #include "libswscale/swscale.h"
44 #include "libavutil/opt.h"
45 #include "libavcodec/avfft.h"
46 #include "libswresample/swresample.h"
49 # include "libavfilter/avcodec.h"
50 # include "libavfilter/avfilter.h"
51 # include "libavfilter/buffersink.h"
52 # include "libavfilter/buffersrc.h"
56 #include <SDL_thread.h>
65 #define MAX_QUEUE_SIZE (15 * 1024 * 1024)
70 #define SDL_AUDIO_BUFFER_SIZE 1024
73 #define AV_SYNC_THRESHOLD_MIN 0.01
75 #define AV_SYNC_THRESHOLD_MAX 0.1
77 #define AV_SYNC_FRAMEDUP_THRESHOLD 0.1
79 #define AV_NOSYNC_THRESHOLD 10.0
82 #define SAMPLE_CORRECTION_PERCENT_MAX 10
85 #define EXTERNAL_CLOCK_SPEED_MIN 0.900
86 #define EXTERNAL_CLOCK_SPEED_MAX 1.010
87 #define EXTERNAL_CLOCK_SPEED_STEP 0.001
90 #define AUDIO_DIFF_AVG_NB 20
93 #define REFRESH_RATE 0.01
97 #define SAMPLE_ARRAY_SIZE (8 * 65536)
99 #define CURSOR_HIDE_DELAY 1000000
119 #define VIDEO_PICTURE_QUEUE_SIZE 3
120 #define SUBPICTURE_QUEUE_SIZE 4
337 #define FF_ALLOC_EVENT (SDL_USEREVENT)
338 #define FF_QUIT_EVENT (SDL_USEREVENT + 2)
347 if (channel_count1 == 1 && channel_count2 == 1)
350 return channel_count1 != channel_count2 || fmt1 != fmt2;
357 return channel_layout;
376 if (pkt == &flush_pkt)
388 SDL_CondSignal(q->
cond);
400 SDL_LockMutex(q->
mutex);
402 SDL_UnlockMutex(q->
mutex);
404 if (pkt != &flush_pkt && ret < 0)
424 q->
mutex = SDL_CreateMutex();
425 q->
cond = SDL_CreateCond();
433 SDL_LockMutex(q->
mutex);
434 for (pkt = q->
first_pkt; pkt != NULL; pkt = pkt1) {
443 SDL_UnlockMutex(q->
mutex);
449 SDL_DestroyMutex(q->
mutex);
450 SDL_DestroyCond(q->
cond);
455 SDL_LockMutex(q->
mutex);
459 SDL_CondSignal(q->
cond);
461 SDL_UnlockMutex(q->
mutex);
466 SDL_LockMutex(q->
mutex);
469 SDL_UnlockMutex(q->
mutex);
478 SDL_LockMutex(q->
mutex);
506 SDL_UnlockMutex(q->
mutex);
518 SDL_FillRect(screen, &rect, color);
519 if (update && w > 0 && h > 0)
520 SDL_UpdateRect(screen, x, y, w, h);
532 w2 = width - (x + w);
538 h2 = height - (y + h);
546 xleft + width - w2, ytop,
554 xleft + w1, ytop + height - h2,
559 #define ALPHA_BLEND(a, oldp, newp, s)\
560 ((((oldp << s) * (255 - (a))) + (newp * (a))) / (255 << s))
562 #define RGBA_IN(r, g, b, a, s)\
564 unsigned int v = ((const uint32_t *)(s))[0];\
565 a = (v >> 24) & 0xff;\
566 r = (v >> 16) & 0xff;\
567 g = (v >> 8) & 0xff;\
571 #define YUVA_IN(y, u, v, a, s, pal)\
573 unsigned int val = ((const uint32_t *)(pal))[*(const uint8_t*)(s)];\
574 a = (val >> 24) & 0xff;\
575 y = (val >> 16) & 0xff;\
576 u = (val >> 8) & 0xff;\
580 #define YUVA_OUT(d, y, u, v, a)\
582 ((uint32_t *)(d))[0] = (a << 24) | (y << 16) | (u << 8) | v;\
590 int wrap, wrap3, width2, skip2;
591 int y,
u,
v,
a, u1, v1,
a1, w, h;
595 int dstx, dsty, dstw, dsth;
597 dstw = av_clip(rect->
w, 0, imgw);
598 dsth = av_clip(rect->
h, 0, imgh);
599 dstx = av_clip(rect->
x, 0, imgw - dstw);
600 dsty = av_clip(rect->
y, 0, imgh - dsth);
605 width2 = ((dstw + 1) >> 1) + (dstx & ~dstw & 1);
610 pal = (
const uint32_t *)rect->
pict.
data[1];
627 for (w = dstw - (dstx & 1); w >= 2; w -= 2) {
654 p += wrap3 - dstw *
BPP;
655 lum += wrap - dstw - dstx;
656 cb += dst->
linesize[1] - width2 - skip2;
657 cr += dst->
linesize[2] - width2 - skip2;
659 for (h = dsth - (dsty & 1); h >= 2; h -= 2) {
684 for (w = dstw - (dstx & 1); w >= 2; w -= 2) {
716 p += -wrap3 + 2 *
BPP;
739 p += wrap3 + (wrap3 - dstw *
BPP);
740 lum += wrap + (wrap - dstw - dstx);
741 cb += dst->
linesize[1] - width2 - skip2;
742 cr += dst->
linesize[2] - width2 - skip2;
760 for (w = dstw - (dstx & 1); w >= 2; w -= 2) {
791 SDL_FreeYUVOverlay(vp->
bmp);
811 if (aspect_ratio <= 0.0)
813 aspect_ratio *= (float)vp->
width / (
float)vp->
height;
817 width = ((int)
rint(height * aspect_ratio)) & ~1;
818 if (width > scr_width) {
820 height = ((int)
rint(width / aspect_ratio)) & ~1;
822 x = (scr_width -
width) / 2;
823 y = (scr_height -
height) / 2;
824 rect->x = scr_xleft + x;
825 rect->y = scr_ytop +
y;
826 rect->w =
FFMAX(width, 1);
827 rect->h =
FFMAX(height, 1);
845 SDL_LockYUVOverlay (vp->
bmp);
847 pict.
data[0] = vp->
bmp->pixels[0];
848 pict.
data[1] = vp->
bmp->pixels[2];
849 pict.
data[2] = vp->
bmp->pixels[1];
859 SDL_UnlockYUVOverlay (vp->
bmp);
866 SDL_DisplayYUVOverlay(vp->
bmp, &rect);
869 int bgcolor = SDL_MapRGB(
screen->format, 0x00, 0x00, 0x00);
878 return a < 0 ? a%b + b : a%
b;
883 int i, i_start, x, y1,
y, ys, delay,
n, nb_display_channels;
884 int ch, channels, h, h2, bgcolor, fgcolor;
886 int rdft_bits, nb_freq;
888 for (rdft_bits = 1; (1 << rdft_bits) < 2 * s->
height; rdft_bits++)
890 nb_freq = 1 << (rdft_bits - 1);
894 nb_display_channels = channels;
896 int data_used= s->
show_mode == SHOW_MODE_WAVES ? s->
width : (2*nb_freq);
908 delay += 2 * data_used;
909 if (delay < data_used)
915 for (i = 0; i < 1000; i += channels) {
922 if (h < score && (b ^ c) < 0) {
934 bgcolor = SDL_MapRGB(
screen->format, 0x00, 0x00, 0x00);
940 fgcolor = SDL_MapRGB(
screen->format, 0xff, 0xff, 0xff);
943 h = s->
height / nb_display_channels;
946 for (ch = 0; ch < nb_display_channels; ch++) {
948 y1 = s->
ytop + ch * h + (h / 2);
949 for (x = 0; x < s->
width; x++) {
958 s->
xleft + x, ys, 1, y,
966 fgcolor = SDL_MapRGB(
screen->format, 0x00, 0x00, 0xff);
968 for (ch = 1; ch < nb_display_channels; ch++) {
969 y = s->
ytop + ch * h;
976 nb_display_channels=
FFMIN(nb_display_channels, 2);
986 for (ch = 0; ch < nb_display_channels; ch++) {
987 data[ch] = s->
rdft_data + 2 * nb_freq * ch;
989 for (x = 0; x < 2 * nb_freq; x++) {
990 double w = (x-nb_freq) * (1.0 / nb_freq);
1000 for (y = 0; y < s->
height; y++) {
1001 double w = 1 / sqrt(nb_freq);
1002 int a = sqrt(w * sqrt(data[0][2 * y + 0] * data[0][2 * y + 0] + data[0][2 * y + 1] * data[0][2 * y + 1]));
1003 int b = (nb_display_channels == 2 ) ? sqrt(w * sqrt(data[1][2 * y + 0] * data[1][2 * y + 0]
1004 + data[1][2 * y + 1] * data[1][2 * y + 1])) : a;
1007 fgcolor = SDL_MapRGB(
screen->format, a, b, (a + b) / 2);
1027 SDL_WaitThread(is->
read_tid, NULL);
1042 #if !CONFIG_AVFILTER
1073 int flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL;
1078 else flags |= SDL_RESIZABLE;
1080 if (vp && vp->
width) {
1096 w =
FFMIN(16383, w);
1100 screen = SDL_SetVideoMode(w, h, 0, flags);
1267 double sync_threshold, diff;
1280 if (diff <= -sync_threshold)
1281 delay =
FFMAX(0, delay + diff);
1283 delay = delay + diff;
1284 else if (diff >= sync_threshold)
1289 av_dlog(NULL,
"video: delay=%0.3f A-V=%f\n",
1368 double last_duration,
duration, delay;
1383 if (!
isnan(last_duration) && last_duration > 0 && last_duration < is->max_frame_duration) {
1393 if (time < is->frame_timer + delay && !redisplay) {
1409 duration = nextvp->
pts - vp->
pts;
1461 static int64_t last_time;
1463 int aqsize, vqsize, sqsize;
1467 if (!last_time || (cur_time - last_time) >= 30000) {
1485 "%7.2f %s:%7.3f fd=%4d aq=%5dKB vq=%5dKB sq=%5dB f=%"PRId64
"/%"PRId64
" \r",
1517 bufferdiff = vp->
bmp ?
FFMAX(vp->
bmp->pixels[0], vp->
bmp->pixels[1]) -
FFMIN(vp->
bmp->pixels[0], vp->
bmp->pixels[1]) : 0;
1518 if (!vp->
bmp || vp->
bmp->pitches[0] < vp->
width || bufferdiff < (int64_t)vp->
height * vp->
bmp->pitches[0]) {
1522 "Error: the video system does not support an image\n"
1523 "size of %dx%d pixels. Try using -lowres or -vf \"scale=w:h\"\n"
1524 "to reduce the image size.\n", vp->
width, vp->
height );
1537 for (i = 0; i < 3; i++) {
1544 if (bmp->pitches[i] > width) {
1545 maxp = bmp->pixels[i] + bmp->pitches[i] * height - 1;
1546 for (p = bmp->pixels[i] + width - 1; p < maxp; p += bmp->pitches[i])
1556 #if defined(DEBUG_SYNC) && 0
1557 printf(
"frame_type=%c pts=%0.3f\n",
1592 event.user.data1 = is;
1593 SDL_PushEvent(&event);
1617 SDL_LockYUVOverlay (vp->
bmp);
1619 pict.
data[0] = vp->
bmp->pixels[0];
1620 pict.
data[1] = vp->
bmp->pixels[2];
1621 pict.
data[2] = vp->
bmp->pixels[1];
1636 if (is->img_convert_ctx == NULL) {
1646 SDL_UnlockYUVOverlay(vp->
bmp);
1689 if (!got_picture && !pkt->
data)
1744 if (!outputs || !inputs) {
1752 outputs->
next = NULL;
1755 inputs->filter_ctx = sink_ctx;
1756 inputs->pad_idx = 0;
1757 inputs->next = NULL;
1776 char sws_flags_str[128];
1777 char buffersrc_args[256];
1787 snprintf(buffersrc_args,
sizeof(buffersrc_args),
1788 "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
1793 av_strlcatf(buffersrc_args,
sizeof(buffersrc_args),
":frame_rate=%d/%d", fr.
num, fr.
den);
1797 "ffplay_buffer", buffersrc_args, NULL,
1803 "ffplay_buffersink", NULL, NULL, graph);
1814 "ffplay_crop",
"floor(in_w/2)*2:floor(in_h/2)*2", NULL, graph)) < 0)
1833 int64_t channel_layouts[2] = { 0, -1 };
1834 int channels[2] = { 0, -1 };
1836 char aresample_swr_opts[512] =
"";
1838 char asrc_args[256];
1847 if (strlen(aresample_swr_opts))
1848 aresample_swr_opts[strlen(aresample_swr_opts)-1] =
'\0';
1851 ret =
snprintf(asrc_args,
sizeof(asrc_args),
1852 "sample_rate=%d:sample_fmt=%s:channels=%d:time_base=%d/%d",
1857 snprintf(asrc_args + ret,
sizeof(asrc_args) - ret,
1862 asrc_args, NULL, is->
agraph);
1878 if (force_output_format) {
1921 int last_serial = -1;
1938 if ( last_w != frame->
width
1939 || last_h != frame->
height
1940 || last_format != frame->
format
1941 || last_serial != serial) {
1943 "Video frame changed from size:%dx%d format:%s serial:%d to size:%dx%d format:%s serial:%d\n",
1953 event.user.data1 = is;
1954 SDL_PushEvent(&event);
1960 last_w = frame->
width;
1962 last_format = frame->
format;
1963 last_serial = serial;
2052 &got_subtitle, pkt);
2053 if (got_subtitle && sp->
sub.
format == 0) {
2077 }
else if (got_subtitle) {
2090 size = samples_size /
sizeof(short);
2108 int wanted_nb_samples = nb_samples;
2112 double diff, avg_diff;
2113 int min_nb_samples, max_nb_samples;
2127 wanted_nb_samples = nb_samples + (int)(diff * is->
audio_src.
freq);
2130 wanted_nb_samples =
FFMIN(
FFMAX(wanted_nb_samples, min_nb_samples), max_nb_samples);
2132 av_dlog(NULL,
"diff=%f adiff=%f sample_diff=%d apts=%0.3f %f\n",
2133 diff, avg_diff, wanted_nb_samples - nb_samples,
2144 return wanted_nb_samples;
2159 int len1, data_size, resampled_data_size;
2160 int64_t dec_channel_layout;
2163 int wanted_nb_samples;
2195 pkt_temp->
data += len1;
2196 pkt_temp->
size -= len1;
2197 if (pkt_temp->
data && pkt_temp->
size <= 0 || !pkt_temp->
data && !got_frame)
2199 if (!pkt_temp->
data && !got_frame)
2231 char buf1[1024], buf2[1024];
2235 "Audio frame changed from rate:%d ch:%d fmt:%s layout:%s serial:%d to rate:%d ch:%d fmt:%s layout:%s serial:%d\n",
2272 dec_channel_layout =
2288 "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n",
2324 if (len2 == out_count) {
2332 resampled_data_size = data_size;
2344 static double last_clock;
2345 printf(
"audio: delay=%0.3f clock=%0.3f clock0=%0.3f\n",
2351 return resampled_data_size;
2357 memset(pkt_temp, 0,
sizeof(*pkt_temp));
2358 pkt_temp->stream_index = -1;
2360 if (is->audioq.abort_request) {
2364 if (is->audioq.nb_packets == 0)
2365 SDL_CondSignal(is->continue_read_thread);
2373 is->audio_buf_frames_pending = 0;
2376 is->audio_frame_next_pts = is->audio_st->start_time;
2396 if (audio_size < 0) {
2424 static int audio_open(
void *opaque, int64_t wanted_channel_layout,
int wanted_nb_channels,
int wanted_sample_rate,
struct AudioParams *audio_hw_params)
2426 SDL_AudioSpec wanted_spec, spec;
2428 static const int next_nb_channels[] = {0, 0, 1, 6, 2, 6, 4, 6};
2430 env = SDL_getenv(
"SDL_AUDIO_CHANNELS");
2432 wanted_nb_channels = atoi(env);
2440 wanted_spec.freq = wanted_sample_rate;
2441 if (wanted_spec.freq <= 0 || wanted_spec.channels <= 0) {
2445 wanted_spec.format = AUDIO_S16SYS;
2446 wanted_spec.silence = 0;
2449 wanted_spec.userdata = opaque;
2450 while (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
2451 av_log(NULL,
AV_LOG_WARNING,
"SDL_OpenAudio (%d channels): %s\n", wanted_spec.channels, SDL_GetError());
2452 wanted_spec.channels = next_nb_channels[
FFMIN(7, wanted_spec.channels)];
2453 if (!wanted_spec.channels) {
2455 "No more channel combinations to try, audio open failed\n");
2460 if (spec.format != AUDIO_S16SYS) {
2462 "SDL advised audio format %d is not supported!\n", spec.format);
2465 if (spec.channels != wanted_spec.channels) {
2467 if (!wanted_channel_layout) {
2469 "SDL advised channel count %d is not supported!\n", spec.channels);
2475 audio_hw_params->
freq = spec.freq;
2477 audio_hw_params->
channels = spec.channels;
2487 const char *forced_codec_name = NULL;
2491 int64_t channel_layout;
2493 int stream_lowres =
lowres;
2495 if (stream_index < 0 || stream_index >= ic->
nb_streams)
2506 if (forced_codec_name)
2510 "No codec could be found with name '%s'\n", forced_codec_name);
2512 "No codec could be found with id %d\n", avctx->
codec_id);
2620 if (stream_index < 0 || stream_index >= ic->
nb_streams)
2712 if(s->
pb && ( !strncmp(s->
filename,
"rtp:", 4)
2713 || !strncmp(s->
filename,
"udp:", 4)
2729 int64_t stream_start_time;
2730 int pkt_in_play_range = 0;
2733 int orig_nb_streams;
2734 SDL_mutex *wait_mutex = SDL_CreateMutex();
2736 memset(st_index, -1,
sizeof(st_index));
2766 "%s: could not find codec parameters\n", is->
filename);
2770 for (i = 0; i < orig_nb_streams; i++)
2812 st_index[AVMEDIA_TYPE_VIDEO],
2818 (st_index[AVMEDIA_TYPE_AUDIO] >= 0 ?
2819 st_index[AVMEDIA_TYPE_AUDIO] :
2820 st_index[AVMEDIA_TYPE_VIDEO]),
2829 if (st_index[AVMEDIA_TYPE_AUDIO] >= 0) {
2834 if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) {
2838 is->
show_mode = ret >= 0 ? SHOW_MODE_VIDEO : SHOW_MODE_RDFT;
2840 if (st_index[AVMEDIA_TYPE_SUBTITLE] >= 0) {
2851 if (infinite_buffer < 0 && is->realtime)
2864 #if CONFIG_RTSP_DEMUXER || CONFIG_MMSH_PROTOCOL
2875 int64_t seek_target = is->
seek_pos;
2876 int64_t seek_min = is->
seek_rel > 0 ? seek_target - is->
seek_rel + 2: INT64_MIN;
2877 int64_t seek_max = is->
seek_rel < 0 ? seek_target - is->
seek_rel - 2: INT64_MAX;
2884 "%s: error while seeking\n", is->
ic->
filename);
2929 SDL_LockMutex(wait_mutex);
2931 SDL_UnlockMutex(wait_mutex);
2959 SDL_LockMutex(wait_mutex);
2961 SDL_UnlockMutex(wait_mutex);
3004 event.user.data1 = is;
3005 SDL_PushEvent(&event);
3007 SDL_DestroyMutex(wait_mutex);
3053 int start_index, stream_index;
3069 stream_index = start_index;
3075 for (start_index = 0; start_index < nb_streams; start_index++)
3078 if (start_index == nb_streams)
3080 stream_index = start_index;
3085 if (++stream_index >= nb_streams)
3093 if (start_index == -1)
3097 if (stream_index == start_index)
3102 switch (codec_type) {
3117 if (p && stream_index != -1)
3126 #if defined(__APPLE__) && SDL_VERSION_ATLEAST(1, 2, 14)
3138 int bgcolor = SDL_MapRGB(
screen->format, 0x00, 0x00, 0x00);
3141 next = (next + 1) % SHOW_MODE_NB;
3142 }
while (next != is->
show_mode && (next == SHOW_MODE_VIDEO && !is->
video_st || next != SHOW_MODE_VIDEO && !is->
audio_st));
3153 double remaining_time = 0.0;
3155 while (!SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) {
3160 if (remaining_time > 0.0)
3161 av_usleep((int64_t)(remaining_time * 1000000.0));
3173 double incr, pos, frac;
3178 switch (event.type) {
3184 switch (event.key.keysym.sym) {
3262 case SDL_VIDEOEXPOSE:
3265 case SDL_MOUSEBUTTONDOWN:
3270 case SDL_MOUSEMOTION:
3276 if (event.type == SDL_MOUSEBUTTONDOWN) {
3279 if (event.motion.state != SDL_PRESSED)
3289 int tns, thh, tmm, tss;
3292 tmm = (tns % 3600) / 60;
3294 frac = x / cur_stream->
width;
3297 mm = (ns % 3600) / 60;
3300 "Seek to %2.0f%% (%2d:%02d:%02d) of total duration (%2d:%02d:%02d) \n", frac*100,
3301 hh, mm, ss, thh, tmm, tss);
3308 case SDL_VIDEORESIZE:
3309 screen = SDL_SetVideoMode(
FFMIN(16383, event.resize.w), event.resize.h, 0,
3310 SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL);
3353 if (!file_iformat) {
3368 if (!strcmp(arg,
"audio"))
3370 else if (!strcmp(arg,
"video"))
3372 else if (!strcmp(arg,
"ext"))
3395 show_mode = !strcmp(arg,
"video") ? SHOW_MODE_VIDEO :
3396 !strcmp(arg,
"waves") ? SHOW_MODE_WAVES :
3397 !strcmp(arg,
"rdft" ) ? SHOW_MODE_RDFT :
3406 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
3410 if (!strcmp(filename,
"-"))
3417 const char *spec = strchr(opt,
':');
3420 "No media specifier was specified in '%s' in option '%s'\n",
3431 "Invalid media specifier '%s' in option '%s'\n", spec, opt);
3441 {
"x",
HAS_ARG, { .func_arg =
opt_width },
"force displayed width",
"width" },
3442 {
"y",
HAS_ARG, { .func_arg =
opt_height },
"force displayed height",
"height" },
3451 {
"ss",
HAS_ARG, { .func_arg =
opt_seek },
"seek to a given position in seconds",
"pos" },
3452 {
"t",
HAS_ARG, { .func_arg =
opt_duration },
"play \"duration\" seconds of audio/video",
"duration" },
3464 {
"sync",
HAS_ARG |
OPT_EXPERT, { .func_arg =
opt_sync },
"set audio-video sync. type (type=audio/video/ext)",
"type" },
3477 {
"showmode",
HAS_ARG, { .func_arg =
opt_show_mode},
"select show mode (0 = video, 1 = waves, 2 = RDFT)",
"mode" },
3479 {
"i",
OPT_BOOL, { &dummy},
"read specified file",
"input_file"},
3480 {
"codec",
HAS_ARG, { .func_arg =
opt_codec},
"force decoder",
"decoder_name" },
3503 #if !CONFIG_AVFILTER
3508 printf(
"\nWhile playing:\n"
3510 "f toggle full screen\n"
3512 "a cycle audio channel in the current program\n"
3513 "v cycle video channel\n"
3514 "t cycle subtitle channel in the current program\n"
3516 "w show audio waves\n"
3517 "s activate frame-step mode\n"
3518 "left/right seek backward/forward 10 seconds\n"
3519 "down/up seek backward/forward 1 minute\n"
3520 "page down/page up seek backward/forward 10 minutes\n"
3521 "mouse click seek to percentage in file corresponding to fraction of width\n"
3529 *mtx = SDL_CreateMutex();
3534 return !!SDL_LockMutex(*mtx);
3536 return !!SDL_UnlockMutex(*mtx);
3538 SDL_DestroyMutex(*mtx);
3549 char dummy_videodriver[] =
"SDL_VIDEODRIVER=dummy";
3578 "Use -h to get full help or, even better, run 'man %s'\n",
program_name);
3585 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
3587 flags &= ~SDL_INIT_AUDIO;
3589 SDL_putenv(dummy_videodriver);
3590 #if !defined(__MINGW32__) && !defined(__APPLE__)
3591 flags |= SDL_INIT_EVENTTHREAD;
3593 if (SDL_Init (flags)) {
3600 const SDL_VideoInfo *
vi = SDL_GetVideoInfo();
3605 SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
3606 SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
3607 SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
#define EXTERNAL_CLOCK_SPEED_STEP
static void packet_queue_abort(PacketQueue *q)
static int opt_show_mode(void *optctx, const char *opt, const char *arg)
static void video_image_display(VideoState *is)
const char const char void * val
static void packet_queue_flush(PacketQueue *q)
static int error_concealment
#define CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
static double get_clock(Clock *c)
static int opt_height(void *optctx, const char *opt, const char *arg)
const AVClass * sws_get_class(void)
Get the AVClass for swsContext.
int64_t pts_correction_num_faulty_dts
Number of incorrect PTS values so far.
static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb_channels, int wanted_sample_rate, struct AudioParams *audio_hw_params)
void av_free_packet(AVPacket *pkt)
Free a packet.
#define EXTERNAL_CLOCK_SPEED_MIN
This structure describes decoded (raw) audio or video data.
#define VIDEO_PICTURE_QUEUE_SIZE
static double rint(double x)
int x
top left corner of pict, undefined when pict is not set
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
static AVInputFormat * file_iformat
VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE]
static void opt_input_file(void *optctx, const char *filename)
int av_lockmgr_register(int(*cb)(void **mutex, enum AVLockOp op))
Register a user provided lock manager supporting the operations specified by AVLockOp.
struct AudioParams audio_filter_src
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
static int opt_format(void *optctx, const char *opt, const char *arg)
#define AV_LOG_WARNING
Something somehow does not look correct.
static const AVFilterPad outputs[]
static int get_master_sync_type(VideoState *is)
#define AV_SYNC_FRAMEDUP_THRESHOLD
int64_t pos
byte position in stream, -1 if unknown
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
struct SwrContext * swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx)
Allocate SwrContext if needed and set/reset common parameters.
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
static int default_height
int av_usleep(unsigned usec)
Sleep for a period of time.
double frame_last_filter_delay
enum VideoState::ShowMode show_mode
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
#define av_opt_set_int_list(obj, name, val, term, flags)
Set a binary option to an integer list.
int av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
static int64_t audio_size
AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame)
Guess the sample aspect ratio of a frame, based on both the stream and the frame aspect ratio...
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const char *vfilters, AVFrame *frame)
AVCodecContext * codec
Codec context associated with this stream.
static void calculate_display_rect(SDL_Rect *rect, int scr_xleft, int scr_ytop, int scr_width, int scr_height, VideoPicture *vp)
static void stream_cycle_channel(VideoState *is, int codec_type)
static int opt_frame_pix_fmt(void *optctx, const char *opt, const char *arg)
int nb_colors
number of colors in pict, undefined when pict is not set
static void stream_toggle_pause(VideoState *is)
MyAVPacketList * first_pkt
int av_copy_packet(AVPacket *dst, AVPacket *src)
Copy packet, including contents.
uint8_t ** extended_data
pointers to the data planes/channels.
static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int seek_by_bytes)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
static void packet_queue_init(PacketQueue *q)
Various defines for YUV<->RGB conversion.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
enum AVMediaType codec_type
void show_banner(int argc, char **argv, const OptionDef *options)
Print the program banner to stderr.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
int64_t frame_last_dropped_pos
static int opt_codec(void *optctx, const char *opt, const char *arg)
static void set_clock_at(Clock *c, double pts, int serial, double time)
static void toggle_pause(VideoState *is)
SDL_Rect last_display_rect
AVFilterContext * filter_ctx
filter context associated to this input/output
double audio_diff_threshold
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
void avcodec_register_all(void)
Register all the codecs, parsers and bitstream filters which were enabled at configuration time...
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
static const char * audio_codec_name
int av_dup_packet(AVPacket *pkt)
#define AV_OPT_FLAG_FILTERING_PARAM
a generic parameter which can be set by the user for filtering
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, AVCodec *codec)
Filter out options for given codec.
AVLockOp
Lock operation used by lockmgr.
static VideoState * stream_open(const char *filename, AVInputFormat *iformat)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
void av_picture_copy(AVPicture *dst, const AVPicture *src, enum AVPixelFormat pix_fmt, int width, int height)
Copy image src to dst.
static void toggle_audio_display(VideoState *is)
AVRational av_guess_frame_rate(AVFormatContext *ctx, AVStream *stream, AVFrame *frame)
Guess the frame rate, based on both the container and codec information.
unsigned int nb_stream_indexes
#define AV_LOG_QUIET
Print no output.
int w
width of pict, undefined when pict is not set
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
double audio_diff_avg_coef
static double cb(void *priv, double x, double y)
static int workaround_bugs
static int read_thread(void *arg)
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance)
Activate resampling compensation.
static int64_t start_time
enum AVSampleFormat sample_fmt
audio sample format
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Trivial log callback.
int opt_default(void *optctx, const char *opt, const char *arg)
Fallback for options that are not explicitly handled, these will be parsed through AVOptions...
static void stream_component_close(VideoState *is, int stream_index)
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
static av_always_inline av_const int isnan(float x)
static int decode_interrupt_cb(void *ctx)
struct SwrContext * swr_ctx
static av_cold int end(AVCodecContext *avctx)
static void event_loop(VideoState *cur_stream)
int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Scale the image slice in srcSlice and put the resulting scaled slice in the image in dst...
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
static int cmp_audio_fmts(enum AVSampleFormat fmt1, int64_t channel_count1, enum AVSampleFormat fmt2, int64_t channel_count2)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static void packet_queue_destroy(PacketQueue *q)
static void alloc_picture(VideoState *is)
void init_opts(void)
Initialize the cmdutils option system, in particular allocate the *_opts contexts.
void avfilter_register_all(void)
Initialize the filter system.
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
void av_codec_set_lowres(AVCodecContext *avctx, int val)
static int64_t audio_callback_time
static double av_q2d(AVRational a)
Convert rational to double.
static int64_t get_valid_channel_layout(int64_t channel_layout, int channels)
int audio_buf_frames_pending
static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block, int *serial)
static void sigterm_handler(int sig)
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *, const char *))
int avformat_network_init(void)
Do global initialization of network components.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
static int configure_audio_filters(VideoState *is, const char *afilters, int force_output_format)
int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in, int in_count)
Convert audio.
static void copy(LZOContext *c, int cnt)
Copies bytes from input to output buffer with checking.
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
static void fill_rectangle(SDL_Surface *screen, int x, int y, int w, int h, int color, int update)
#define AV_NOSYNC_THRESHOLD
int h
height of pict, undefined when pict is not set
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
Print help for all options matching specified flags.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointers to the image data planes
const OptionDef options[]
static void duplicate_right_border_pixels(SDL_Overlay *bmp)
int audio_pkt_temp_serial
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Setup AVCodecContext options for avformat_find_stream_info().
AVDictionary * format_opts
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
#define SAMPLE_ARRAY_SIZE
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
static const uint8_t frame_size[4]
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
A link between two filters.
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, AVCodec **decoder_ret, int flags)
Find the "best" stream in the file.
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
static void video_refresh(void *opaque, double *remaining_time)
int sample_rate
samples per second
static int wanted_stream[AVMEDIA_TYPE_NB]
int y
top left corner of pict, undefined when pict is not set
char filename[1024]
input or output filename
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int error_concealment
error concealment flags
static int packet_queue_put_nullpacket(PacketQueue *q, int stream_index)
int capabilities
Codec capabilities.
#define RGBA_IN(r, g, b, a, s)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define CURSOR_HIDE_DELAY
int av_read_play(AVFormatContext *s)
Start playing a network-based stream (e.g.
static double compute_target_delay(double delay, VideoState *is)
void av_dict_free(AVDictionary **m)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
struct AVInputFormat * iformat
Can only be iformat or oformat, not both at the same time.
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
#define AV_LOG_SKIP_REPEATED
Skip repeated messages, this requires the user app to use av_log() instead of (f)printf as the 2 woul...
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
uint8_t silence_buf[SDL_AUDIO_BUFFER_SIZE]
static void stream_close(VideoState *is)
int av_frame_get_channels(const AVFrame *frame)
int frame_last_dropped_serial
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static void init_clock(Clock *c, int *queue_serial)
static enum ShowMode show_mode
New fields can be added to the end with minor version bumps.
static void packet_queue_start(PacketQueue *q)
AVPixelFormat
Pixel format.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
#define av_unused
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
static const int sample_rates[]
uint64_t channel_layout
Audio channel layout.
static int opt_sync(void *optctx, const char *opt, const char *arg)
static void update_sample_display(VideoState *is, short *samples, int samples_size)
void av_rdft_calc(RDFTContext *s, FFTSample *data)
uint32_t end_display_time
int64_t pts
Same as packet pts, in AV_TIME_BASE.
static AVPacket flush_pkt
uint64_t channel_layout
Channel layout of the audio data.
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
double frame_last_returned_time
const int program_birth_year
program birth year, defined by the program for show_banner()
static const char * subtitle_codec_name
static int subtitle_disable
static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t pos, int serial)
unsigned int nb_streams
A list of all streams in the file.
static SDL_Surface * screen
int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Get a frame with filtered data from sink and put it in frame.
int av_read_pause(AVFormatContext *s)
Pause a network-based stream (e.g.
static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, int is_silence, int64_t nb_samples_notify, AVRational time_base)
int64_t av_gettime(void)
Get the current time in microseconds.
#define SUBPICTURE_QUEUE_SIZE
enum AVPictureType pict_type
Picture type of the frame.
struct MyAVPacketList * next
#define AV_CH_LAYOUT_STEREO_DOWNMIX
AVPicture pict
data+linesize for the bitmap of this subtitle.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
#define AV_TIME_BASE
Internal time base represented as integer.
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
SDL_Thread * subtitle_tid
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() and chilren.
static int lockmgr(void **mtx, enum AVLockOp op)
static int opt_width(void *optctx, const char *opt, const char *arg)
double frame_last_dropped_pts
struct AudioParams audio_src
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void refresh_loop_wait_event(VideoState *is, SDL_Event *event)
static void set_clock_speed(Clock *c, double speed)
int64_t audio_frame_next_pts
void show_help_default(const char *opt, const char *arg)
Per-fftool specific help handler.
int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, const AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.
static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int imgw, int imgh)
MyAVPacketList * last_pkt
void av_rdft_end(RDFTContext *s)
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
static void step_to_next_frame(VideoState *is)
static int audio_decode_frame(VideoState *is)
Decode one audio frame and return its uncompressed size.
static int is_full_screen
#define AV_SYNC_THRESHOLD_MAX
char * name
unique name for this input/output in the list
static void fill_border(int xleft, int ytop, int width, int height, int x, int y, int w, int h, int color, int update)
size_t char * av_asprintf(const char *fmt,...) av_printf_format(1
Print arguments following specified format into a large enough auto allocated buffer.
static int decoder_reorder_pts
#define AUDIO_DIFF_AVG_NB
static void set_clock(Clock *c, double pts, int serial)
int16_t sample_array[SAMPLE_ARRAY_SIZE]
static const char * input_filename
int av_codec_get_max_lowres(const AVCodec *codec)
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal decoder state / flush internal buffers.
A linked-list of the inputs/outputs of the filter chain.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
int64_t video_current_pos
static int fs_screen_width
#define SAMPLE_CORRECTION_PERCENT_MAX
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
AVSampleFormat
Audio Sample Formats.
static int opt_duration(void *optctx, const char *opt, const char *arg)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static AVInputFormat * iformat
#define AV_LOG_INFO
Standard information.
AVFilterInOut * avfilter_inout_alloc(void)
Allocate a single AVFilterInOut entry.
const AVClass * avfilter_get_class(void)
enum AVMediaType codec_type
static void do_exit(VideoState *is)
int sample_rate
samples per second
static int exit_on_keydown
AVFilterContext * in_video_filter
main external API structure.
void swr_free(struct SwrContext **s)
Free the given SwrContext and set the pointer to NULL.
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
double max_frame_duration
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
AVIOContext * pb
I/O context.
SubPicture subpq[SUBPICTURE_QUEUE_SIZE]
void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.
static const char * window_title
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static int video_open(VideoState *is, int force_set_video_mode, VideoPicture *vp)
#define AVERROR_OPTION_NOT_FOUND
BYTE int const BYTE int int int height
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
int sample_rate
Sample rate of the audio data.
int configure_filtergraph(FilterGraph *fg)
static const AVFilterPad inputs[]
int pad_idx
index of the filt_ctx pad to use for linking
AVFilterLink ** inputs
array of pointers to input links
rational number numerator/denominator
#define AV_SYNC_THRESHOLD_MIN
static int get_video_frame(VideoState *is, AVFrame *frame, AVPacket *pkt, int *serial)
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
Parse a string specifying a time and return its corresponding value as a number of microseconds...
static void video_audio_display(VideoState *s)
#define EXTERNAL_CLOCK_SPEED_MAX
struct SwsContext * sws_opts
discard useless packets like 0 size packets in avi
static int is_realtime(AVFormatContext *s)
static void check_external_clock_speed(VideoState *is)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVFilterContext * out_video_filter
int queue_attachments_req
AVFilterContext * in_audio_filter
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
int error
contains the error code or 0 if no error happened
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
Parse a string and return its corresponding value as a double.
static int stream_component_open(VideoState *is, int stream_index)
static int64_t cursor_last_shown
static int opt_frame_size(void *optctx, const char *opt, const char *arg)
#define RGB_TO_U_CCIR(r1, g1, b1, shift)
double frame_last_duration
int64_t start_time
Decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds...
static double lum(void *priv, double x, double y)
static int synchronize_audio(VideoState *is, int nb_samples)
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
#define RGB_TO_V_CCIR(r1, g1, b1, shift)
int64_t av_frame_get_best_effort_timestamp(const AVFrame *frame)
Accessors for some AVFrame fields.
SDL_cond * continue_read_thread
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
struct SwsContext * sws_getCachedContext(struct SwsContext *context, int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Check if context can be reused, otherwise reallocate a new one.
static int exit_on_mousedown
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
#define SDL_AUDIO_BUFFER_SIZE
#define CODEC_FLAG_EMU_EDGE
Don't draw edges.
void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
#define YUVA_OUT(d, y, u, v, a)
static int video_thread(void *arg)
AVDictionary * codec_opts
struct AudioParams audio_tgt
#define ALPHA_BLEND(a, oldp, newp, s)
static int display_disable
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
static int opt_seek(void *optctx, const char *opt, const char *arg)
static void free_picture(VideoPicture *vp)
int disposition
AV_DISPOSITION_* bit field.
uint32_t start_display_time
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
static void update_video_pts(VideoState *is, double pts, int64_t pos, int serial)
int workaround_bugs
Work around bugs in encoders which sometimes cannot be detected automatically.
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents...
int channels
Number of channels.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
#define RGB_TO_Y_CCIR(r, g, b)
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
static int infinite_buffer
int eof_reached
true if eof reached
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int channels
number of audio channels
unsigned int audio_buf1_size
static int pictq_prev_picture(VideoState *is)
void av_log_set_flags(int arg)
AVFilterContext * out_audio_filter
static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
void show_help_children(const AVClass *class, int flags)
Show help for all options with given flags in class and all its children.
int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs, void *log_ctx)
Add a graph described by a string to a graph.
AVProgram * av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
Find the programs which belong to a given stream.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int bit_rate
Decoding: total stream bitrate in bit/s, 0 if not available.
static enum AVSampleFormat sample_fmts[]
int64_t duration
Decoding: duration of the stream, in AV_TIME_BASE fractional seconds.
static const char * video_codec_name
int64_t pts_correction_num_faulty_pts
Current statistics for PTS correction.
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
#define AV_DICT_IGNORE_SUFFIX
static int subtitle_thread(void *arg)
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
static double get_master_clock(VideoState *is)
int main(int argc, char **argv)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static double cr(void *priv, double x, double y)
unsigned int audio_buf_size
static void free_subpicture(SubPicture *sp)
#define YUVA_IN(y, u, v, a, s, pal)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
static void video_display(VideoState *is)
unsigned int * stream_index
static int compute_mod(int a, int b)
This structure stores compressed data.
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
int nb_samples
number of audio samples (per channel) described by this frame
static void sync_clock_to_slave(Clock *c, Clock *slave)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int64_t av_frame_get_pkt_pos(const AVFrame *frame)
static void toggle_full_screen(VideoState *is)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static int fs_screen_height
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...) av_printf_format(3
Append output to a string, according to a format.
AVPacket attached_pic
For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet will contain the attached pictu...
const char program_name[]
program name, defined by the program for show_version().
#define AV_NOPTS_VALUE
Undefined timestamp value.
static void pictq_next_picture(VideoState *is)
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.