2 * FFplay : Simple Media Player based on the ffmpeg libraries
3 * Copyright (c) 2003 Fabrice Bellard
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #define HAVE_AV_CONFIG_H
25 #include <SDL_thread.h>
28 #undef main /* We don't want SDL to override our main() */
31 #if defined(__linux__)
41 #define MAX_VIDEOQ_SIZE (5 * 256 * 1024)
42 #define MAX_AUDIOQ_SIZE (5 * 16 * 1024)
44 /* SDL audio buffer size, in samples. Should be small to have precise
45 A/V sync as SDL does not have hardware buffer fullness info. */
46 #define SDL_AUDIO_BUFFER_SIZE 1024
48 /* no AV sync correction is done if below the AV sync threshold */
49 #define AV_SYNC_THRESHOLD 0.01
50 /* no AV correction is done if too big error */
51 #define AV_NOSYNC_THRESHOLD 10.0
53 /* maximum audio speed change to get correct sync */
54 #define SAMPLE_CORRECTION_PERCENT_MAX 10
56 /* we use about AUDIO_DIFF_AVG_NB A-V differences to make the average */
57 #define AUDIO_DIFF_AVG_NB 20
59 /* NOTE: the size must be big enough to compensate the hardware audio buffersize size */
60 #define SAMPLE_ARRAY_SIZE (2*65536)
62 typedef struct PacketQueue {
63 AVPacketList *first_pkt, *last_pkt;
71 #define VIDEO_PICTURE_QUEUE_SIZE 1
73 typedef struct VideoPicture {
74 double pts; /* presentation time stamp for this picture */
76 int width, height; /* source height & width */
81 AV_SYNC_AUDIO_MASTER, /* default choice */
83 AV_SYNC_EXTERNAL_CLOCK, /* synchronize to an external clock */
86 typedef struct VideoState {
87 SDL_Thread *parse_tid;
88 SDL_Thread *video_tid;
89 AVInputFormat *iformat;
98 int dtg_active_format;
103 double external_clock; /* external clock base */
104 int64_t external_clock_time;
107 double audio_diff_cum; /* used for AV difference average computation */
108 double audio_diff_avg_coef;
109 double audio_diff_threshold;
110 int audio_diff_avg_count;
113 int audio_hw_buf_size;
114 /* samples output by the codec. we reserve more space for avsync
116 uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
117 unsigned int audio_buf_size; /* in bytes */
118 int audio_buf_index; /* in bytes */
120 uint8_t *audio_pkt_data;
123 int show_audio; /* if true, display audio samples */
124 int16_t sample_array[SAMPLE_ARRAY_SIZE];
125 int sample_array_index;
129 double frame_last_pts;
130 double frame_last_delay;
135 double video_last_P_pts; /* pts of the last P picture (needed if B
136 frames are present) */
137 double video_current_pts; /* current displayed pts (different from
138 video_clock if frame fifos are used) */
139 int64_t video_current_pts_time; /* time at which we updated
140 video_current_pts - used to
141 have running video pts */
142 VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE];
143 int pictq_size, pictq_rindex, pictq_windex;
144 SDL_mutex *pictq_mutex;
145 SDL_cond *pictq_cond;
147 // QETimer *video_timer;
149 int width, height, xleft, ytop;
152 void show_help(void);
153 static int audio_write_get_buf_size(VideoState *is);
155 /* options specified by the user */
156 static AVInputFormat *file_iformat;
157 static AVImageFormat *image_format;
158 static const char *input_filename;
159 static int fs_screen_width;
160 static int fs_screen_height;
161 static int screen_width = 640;
162 static int screen_height = 480;
163 static int audio_disable;
164 static int video_disable;
165 static int display_disable;
166 static int show_status;
167 static int av_sync_type = AV_SYNC_AUDIO_MASTER;
168 static int64_t start_time = AV_NOPTS_VALUE;
169 static int debug = 0;
170 static int debug_mv = 0;
172 static int thread_count = 1;
173 static int workaround_bugs = 1;
175 static int lowres = 0;
176 static int idct = FF_IDCT_AUTO;
178 /* current context */
179 static int is_full_screen;
180 static VideoState *cur_stream;
181 static int64_t audio_callback_time;
183 #define FF_ALLOC_EVENT (SDL_USEREVENT)
184 #define FF_REFRESH_EVENT (SDL_USEREVENT + 1)
185 #define FF_QUIT_EVENT (SDL_USEREVENT + 2)
189 /* packet queue handling */
190 static void packet_queue_init(PacketQueue *q)
192 memset(q, 0, sizeof(PacketQueue));
193 q->mutex = SDL_CreateMutex();
194 q->cond = SDL_CreateCond();
197 static void packet_queue_flush(PacketQueue *q)
199 AVPacketList *pkt, *pkt1;
201 for(pkt = q->first_pkt; pkt != NULL; pkt = pkt1) {
203 av_free_packet(&pkt->pkt);
212 static void packet_queue_end(PacketQueue *q)
214 packet_queue_flush(q);
215 SDL_DestroyMutex(q->mutex);
216 SDL_DestroyCond(q->cond);
219 static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
223 /* duplicate the packet */
224 if (av_dup_packet(pkt) < 0)
227 pkt1 = av_malloc(sizeof(AVPacketList));
234 SDL_LockMutex(q->mutex);
240 q->last_pkt->next = pkt1;
243 q->size += pkt1->pkt.size;
244 /* XXX: should duplicate packet data in DV case */
245 SDL_CondSignal(q->cond);
247 SDL_UnlockMutex(q->mutex);
251 static void packet_queue_abort(PacketQueue *q)
253 SDL_LockMutex(q->mutex);
255 q->abort_request = 1;
257 SDL_CondSignal(q->cond);
259 SDL_UnlockMutex(q->mutex);
262 /* return < 0 if aborted, 0 if no packet and > 0 if packet. */
263 static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block)
268 SDL_LockMutex(q->mutex);
271 if (q->abort_request) {
278 q->first_pkt = pkt1->next;
282 q->size -= pkt1->pkt.size;
291 SDL_CondWait(q->cond, q->mutex);
294 SDL_UnlockMutex(q->mutex);
298 static inline void fill_rectangle(SDL_Surface *screen,
299 int x, int y, int w, int h, int color)
306 SDL_FillRect(screen, &rect, color);
310 /* draw only the border of a rectangle */
311 void fill_border(VideoState *s, int x, int y, int w, int h, int color)
315 /* fill the background */
319 w2 = s->width - (x + w);
325 h2 = s->height - (y + h);
328 fill_rectangle(screen,
332 fill_rectangle(screen,
333 s->xleft + s->width - w2, s->ytop,
336 fill_rectangle(screen,
337 s->xleft + w1, s->ytop,
338 s->width - w1 - w2, h1,
340 fill_rectangle(screen,
341 s->xleft + w1, s->ytop + s->height - h2,
342 s->width - w1 - w2, h2,
347 static void video_image_display(VideoState *is)
351 int width, height, x, y;
354 vp = &is->pictq[is->pictq_rindex];
356 /* XXX: use variable in the frame */
357 if (is->video_st->codec.sample_aspect_ratio.num == 0)
360 aspect_ratio = av_q2d(is->video_st->codec.sample_aspect_ratio)
361 * is->video_st->codec.width / is->video_st->codec.height;;
362 if (aspect_ratio <= 0.0)
363 aspect_ratio = (float)is->video_st->codec.width /
364 (float)is->video_st->codec.height;
365 /* if an active format is indicated, then it overrides the
368 if (is->video_st->codec.dtg_active_format != is->dtg_active_format) {
369 is->dtg_active_format = is->video_st->codec.dtg_active_format;
370 printf("dtg_active_format=%d\n", is->dtg_active_format);
374 switch(is->video_st->codec.dtg_active_format) {
375 case FF_DTG_AFD_SAME:
380 aspect_ratio = 4.0 / 3.0;
382 case FF_DTG_AFD_16_9:
383 aspect_ratio = 16.0 / 9.0;
385 case FF_DTG_AFD_14_9:
386 aspect_ratio = 14.0 / 9.0;
388 case FF_DTG_AFD_4_3_SP_14_9:
389 aspect_ratio = 14.0 / 9.0;
391 case FF_DTG_AFD_16_9_SP_14_9:
392 aspect_ratio = 14.0 / 9.0;
394 case FF_DTG_AFD_SP_4_3:
395 aspect_ratio = 4.0 / 3.0;
400 /* XXX: we suppose the screen has a 1.0 pixel ratio */
402 width = ((int)rint(height * aspect_ratio)) & -3;
403 if (width > is->width) {
405 height = ((int)rint(width / aspect_ratio)) & -3;
407 x = (is->width - width) / 2;
408 y = (is->height - height) / 2;
409 if (!is->no_background) {
410 /* fill the background */
411 // fill_border(is, x, y, width, height, QERGB(0x00, 0x00, 0x00));
413 is->no_background = 0;
415 rect.x = is->xleft + x;
416 rect.y = is->xleft + y;
419 SDL_DisplayYUVOverlay(vp->bmp, &rect);
422 fill_rectangle(screen,
423 is->xleft, is->ytop, is->width, is->height,
424 QERGB(0x00, 0x00, 0x00));
429 static inline int compute_mod(int a, int b)
438 static void video_audio_display(VideoState *s)
440 int i, i_start, x, y1, y, ys, delay, n, nb_display_channels;
441 int ch, channels, h, h2, bgcolor, fgcolor;
444 /* compute display index : center on currently output samples */
445 channels = s->audio_st->codec.channels;
446 nb_display_channels = channels;
449 delay = audio_write_get_buf_size(s);
452 /* to be more precise, we take into account the time spent since
453 the last buffer computation */
454 if (audio_callback_time) {
455 time_diff = av_gettime() - audio_callback_time;
456 delay += (time_diff * s->audio_st->codec.sample_rate) / 1000000;
459 delay -= s->width / 2;
460 if (delay < s->width)
462 i_start = compute_mod(s->sample_array_index - delay * channels, SAMPLE_ARRAY_SIZE);
463 s->last_i_start = i_start;
465 i_start = s->last_i_start;
468 bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
469 fill_rectangle(screen,
470 s->xleft, s->ytop, s->width, s->height,
473 fgcolor = SDL_MapRGB(screen->format, 0xff, 0xff, 0xff);
475 /* total height for one channel */
476 h = s->height / nb_display_channels;
477 /* graph height / 2 */
479 for(ch = 0;ch < nb_display_channels; ch++) {
481 y1 = s->ytop + ch * h + (h / 2); /* position of center line */
482 for(x = 0; x < s->width; x++) {
483 y = (s->sample_array[i] * h2) >> 15;
490 fill_rectangle(screen,
491 s->xleft + x, ys, 1, y,
494 if (i >= SAMPLE_ARRAY_SIZE)
495 i -= SAMPLE_ARRAY_SIZE;
499 fgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0xff);
501 for(ch = 1;ch < nb_display_channels; ch++) {
502 y = s->ytop + ch * h;
503 fill_rectangle(screen,
504 s->xleft, y, s->width, 1,
507 SDL_UpdateRect(screen, s->xleft, s->ytop, s->width, s->height);
510 /* display the current picture, if any */
511 static void video_display(VideoState *is)
513 if (is->audio_st && is->show_audio)
514 video_audio_display(is);
515 else if (is->video_st)
516 video_image_display(is);
519 static Uint32 sdl_refresh_timer_cb(Uint32 interval, void *opaque)
522 event.type = FF_REFRESH_EVENT;
523 event.user.data1 = opaque;
524 SDL_PushEvent(&event);
525 return 0; /* 0 means stop timer */
528 /* schedule a video refresh in 'delay' ms */
529 static void schedule_refresh(VideoState *is, int delay)
531 SDL_AddTimer(delay, sdl_refresh_timer_cb, is);
534 /* get the current audio clock value */
535 static double get_audio_clock(VideoState *is)
538 int hw_buf_size, bytes_per_sec;
539 pts = is->audio_clock;
540 hw_buf_size = audio_write_get_buf_size(is);
543 bytes_per_sec = is->audio_st->codec.sample_rate *
544 2 * is->audio_st->codec.channels;
547 pts -= (double)hw_buf_size / bytes_per_sec;
551 /* get the current video clock value */
552 static double get_video_clock(VideoState *is)
558 delta = (av_gettime() - is->video_current_pts_time) / 1000000.0;
560 return is->video_current_pts + delta;
563 /* get the current external clock value */
564 static double get_external_clock(VideoState *is)
568 return is->external_clock + ((ti - is->external_clock_time) * 1e-6);
571 /* get the current master clock value */
572 static double get_master_clock(VideoState *is)
576 if (is->av_sync_type == AV_SYNC_VIDEO_MASTER) {
578 val = get_video_clock(is);
580 val = get_audio_clock(is);
581 } else if (is->av_sync_type == AV_SYNC_AUDIO_MASTER) {
583 val = get_audio_clock(is);
585 val = get_video_clock(is);
587 val = get_external_clock(is);
592 /* seek in the stream */
593 static void stream_seek(VideoState *is, int64_t pos, int rel)
597 is->seek_flags = rel < 0 ? AVSEEK_FLAG_BACKWARD : 0;
600 /* pause or resume the video */
601 static void stream_pause(VideoState *is)
603 is->paused = !is->paused;
605 is->video_current_pts = get_video_clock(is);
609 /* called to display each frame */
610 static void video_refresh_timer(void *opaque)
612 VideoState *is = opaque;
614 double actual_delay, delay, sync_threshold, ref_clock, diff;
618 if (is->pictq_size == 0) {
619 /* if no picture, need to wait */
620 schedule_refresh(is, 1);
622 /* dequeue the picture */
623 vp = &is->pictq[is->pictq_rindex];
625 /* update current video pts */
626 is->video_current_pts = vp->pts;
627 is->video_current_pts_time = av_gettime();
629 /* compute nominal delay */
630 delay = vp->pts - is->frame_last_pts;
631 if (delay <= 0 || delay >= 1.0) {
632 /* if incorrect delay, use previous one */
633 delay = is->frame_last_delay;
635 is->frame_last_delay = delay;
636 is->frame_last_pts = vp->pts;
638 /* update delay to follow master synchronisation source */
639 if (((is->av_sync_type == AV_SYNC_AUDIO_MASTER && is->audio_st) ||
640 is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK)) {
641 /* if video is slave, we try to correct big delays by
642 duplicating or deleting a frame */
643 ref_clock = get_master_clock(is);
644 diff = vp->pts - ref_clock;
646 /* skip or repeat frame. We take into account the
647 delay to compute the threshold. I still don't know
648 if it is the best guess */
649 sync_threshold = AV_SYNC_THRESHOLD;
650 if (delay > sync_threshold)
651 sync_threshold = delay;
652 if (fabs(diff) < AV_NOSYNC_THRESHOLD) {
653 if (diff <= -sync_threshold)
655 else if (diff >= sync_threshold)
660 is->frame_timer += delay;
661 /* compute the REAL delay (we need to do that to avoid
663 actual_delay = is->frame_timer - (av_gettime() / 1000000.0);
664 if (actual_delay < 0.010) {
665 /* XXX: should skip picture */
666 actual_delay = 0.010;
668 /* launch timer for next picture */
669 schedule_refresh(is, (int)(actual_delay * 1000 + 0.5));
671 #if defined(DEBUG_SYNC)
672 printf("video: delay=%0.3f actual_delay=%0.3f pts=%0.3f A-V=%f\n",
673 delay, actual_delay, vp->pts, -diff);
676 /* display picture */
679 /* update queue size and signal for next picture */
680 if (++is->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE)
681 is->pictq_rindex = 0;
683 SDL_LockMutex(is->pictq_mutex);
685 SDL_CondSignal(is->pictq_cond);
686 SDL_UnlockMutex(is->pictq_mutex);
688 } else if (is->audio_st) {
689 /* draw the next audio frame */
691 schedule_refresh(is, 40);
693 /* if only audio stream, then display the audio bars (better
694 than nothing, just to test the implementation */
696 /* display picture */
699 schedule_refresh(is, 100);
702 static int64_t last_time;
707 cur_time = av_gettime();
708 if (!last_time || (cur_time - last_time) >= 500 * 1000) {
712 aqsize = is->audioq.size;
714 vqsize = is->videoq.size;
716 if (is->audio_st && is->video_st)
717 av_diff = get_audio_clock(is) - get_video_clock(is);
718 printf("%7.2f A-V:%7.3f aq=%5dKB vq=%5dKB \r",
719 get_master_clock(is), av_diff, aqsize / 1024, vqsize / 1024);
721 last_time = cur_time;
726 /* allocate a picture (needs to do that in main thread to avoid
727 potential locking problems */
728 static void alloc_picture(void *opaque)
730 VideoState *is = opaque;
733 vp = &is->pictq[is->pictq_windex];
736 SDL_FreeYUVOverlay(vp->bmp);
739 /* XXX: use generic function */
740 /* XXX: disable overlay if no hardware acceleration or if RGB format */
741 switch(is->video_st->codec.pix_fmt) {
742 case PIX_FMT_YUV420P:
743 case PIX_FMT_YUV422P:
744 case PIX_FMT_YUV444P:
746 case PIX_FMT_YUV410P:
747 case PIX_FMT_YUV411P:
755 vp->bmp = SDL_CreateYUVOverlay(is->video_st->codec.width,
756 is->video_st->codec.height,
759 vp->width = is->video_st->codec.width;
760 vp->height = is->video_st->codec.height;
762 SDL_LockMutex(is->pictq_mutex);
764 SDL_CondSignal(is->pictq_cond);
765 SDL_UnlockMutex(is->pictq_mutex);
768 static int queue_picture(VideoState *is, AVFrame *src_frame, double pts)
774 /* wait until we have space to put a new picture */
775 SDL_LockMutex(is->pictq_mutex);
776 while (is->pictq_size >= VIDEO_PICTURE_QUEUE_SIZE &&
777 !is->videoq.abort_request) {
778 SDL_CondWait(is->pictq_cond, is->pictq_mutex);
780 SDL_UnlockMutex(is->pictq_mutex);
782 if (is->videoq.abort_request)
785 vp = &is->pictq[is->pictq_windex];
787 /* alloc or resize hardware picture buffer */
789 vp->width != is->video_st->codec.width ||
790 vp->height != is->video_st->codec.height) {
795 /* the allocation must be done in the main thread to avoid
797 event.type = FF_ALLOC_EVENT;
798 event.user.data1 = is;
799 SDL_PushEvent(&event);
801 /* wait until the picture is allocated */
802 SDL_LockMutex(is->pictq_mutex);
803 while (!vp->allocated && !is->videoq.abort_request) {
804 SDL_CondWait(is->pictq_cond, is->pictq_mutex);
806 SDL_UnlockMutex(is->pictq_mutex);
808 if (is->videoq.abort_request)
812 /* if the frame is not skipped, then display it */
814 /* get a pointer on the bitmap */
815 SDL_LockYUVOverlay (vp->bmp);
817 dst_pix_fmt = PIX_FMT_YUV420P;
818 pict.data[0] = vp->bmp->pixels[0];
819 pict.data[1] = vp->bmp->pixels[2];
820 pict.data[2] = vp->bmp->pixels[1];
822 pict.linesize[0] = vp->bmp->pitches[0];
823 pict.linesize[1] = vp->bmp->pitches[2];
824 pict.linesize[2] = vp->bmp->pitches[1];
825 img_convert(&pict, dst_pix_fmt,
826 (AVPicture *)src_frame, is->video_st->codec.pix_fmt,
827 is->video_st->codec.width, is->video_st->codec.height);
828 /* update the bitmap content */
829 SDL_UnlockYUVOverlay(vp->bmp);
833 /* now we can update the picture count */
834 if (++is->pictq_windex == VIDEO_PICTURE_QUEUE_SIZE)
835 is->pictq_windex = 0;
836 SDL_LockMutex(is->pictq_mutex);
838 SDL_UnlockMutex(is->pictq_mutex);
843 /* compute the exact PTS for the picture if it is omitted in the stream */
844 static int output_picture2(VideoState *is, AVFrame *src_frame, double pts1)
846 double frame_delay, pts;
851 /* update video clock with pts, if present */
852 is->video_clock = pts;
854 pts = is->video_clock;
856 /* update video clock for next frame */
857 frame_delay = (double)is->video_st->codec.frame_rate_base /
858 (double)is->video_st->codec.frame_rate;
859 /* for MPEG2, the frame can be repeated, so we update the
861 if (src_frame->repeat_pict) {
862 frame_delay += src_frame->repeat_pict * (frame_delay * 0.5);
864 is->video_clock += frame_delay;
866 #if defined(DEBUG_SYNC) && 0
869 if (src_frame->pict_type == FF_B_TYPE)
871 else if (src_frame->pict_type == FF_I_TYPE)
875 printf("frame_type=%c clock=%0.3f pts=%0.3f\n",
879 return queue_picture(is, src_frame, pts);
882 static int video_thread(void *arg)
884 VideoState *is = arg;
885 AVPacket pkt1, *pkt = &pkt1;
886 int len1, got_picture;
887 AVFrame *frame= avcodec_alloc_frame();
891 while (is->paused && !is->videoq.abort_request) {
894 if (packet_queue_get(&is->videoq, pkt, 1) < 0)
896 /* NOTE: ipts is the PTS of the _first_ picture beginning in
897 this packet, if any */
899 if (pkt->dts != AV_NOPTS_VALUE)
900 pts = (double)pkt->dts / AV_TIME_BASE;
902 len1 = avcodec_decode_video(&is->video_st->codec,
904 pkt->data, pkt->size);
908 if (output_picture2(is, frame, pts) < 0)
914 stream_pause(cur_stream);
921 /* copy samples for viewing in editor window */
922 static void update_sample_display(VideoState *is, short *samples, int samples_size)
924 int size, len, channels;
926 channels = is->audio_st->codec.channels;
928 size = samples_size / sizeof(short);
930 len = SAMPLE_ARRAY_SIZE - is->sample_array_index;
933 memcpy(is->sample_array + is->sample_array_index, samples, len * sizeof(short));
935 is->sample_array_index += len;
936 if (is->sample_array_index >= SAMPLE_ARRAY_SIZE)
937 is->sample_array_index = 0;
942 /* return the new audio buffer size (samples can be added or deleted
943 to get better sync if video or external master clock) */
944 static int synchronize_audio(VideoState *is, short *samples,
945 int samples_size1, double pts)
950 n = 2 * is->audio_st->codec.channels;
951 samples_size = samples_size1;
953 /* if not master, then we try to remove or add samples to correct the clock */
954 if (((is->av_sync_type == AV_SYNC_VIDEO_MASTER && is->video_st) ||
955 is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK)) {
956 double diff, avg_diff;
957 int wanted_size, min_size, max_size, nb_samples;
959 ref_clock = get_master_clock(is);
960 diff = get_audio_clock(is) - ref_clock;
962 if (diff < AV_NOSYNC_THRESHOLD) {
963 is->audio_diff_cum = diff + is->audio_diff_avg_coef * is->audio_diff_cum;
964 if (is->audio_diff_avg_count < AUDIO_DIFF_AVG_NB) {
965 /* not enough measures to have a correct estimate */
966 is->audio_diff_avg_count++;
968 /* estimate the A-V difference */
969 avg_diff = is->audio_diff_cum * (1.0 - is->audio_diff_avg_coef);
971 if (fabs(avg_diff) >= is->audio_diff_threshold) {
972 wanted_size = samples_size + ((int)(diff * is->audio_st->codec.sample_rate) * n);
973 nb_samples = samples_size / n;
975 min_size = ((nb_samples * (100 - SAMPLE_CORRECTION_PERCENT_MAX)) / 100) * n;
976 max_size = ((nb_samples * (100 + SAMPLE_CORRECTION_PERCENT_MAX)) / 100) * n;
977 if (wanted_size < min_size)
978 wanted_size = min_size;
979 else if (wanted_size > max_size)
980 wanted_size = max_size;
982 /* add or remove samples to correction the synchro */
983 if (wanted_size < samples_size) {
985 samples_size = wanted_size;
986 } else if (wanted_size > samples_size) {
987 uint8_t *samples_end, *q;
991 nb = (samples_size - wanted_size);
992 samples_end = (uint8_t *)samples + samples_size - n;
995 memcpy(q, samples_end, n);
999 samples_size = wanted_size;
1003 printf("diff=%f adiff=%f sample_diff=%d apts=%0.3f vpts=%0.3f %f\n",
1004 diff, avg_diff, samples_size - samples_size1,
1005 is->audio_clock, is->video_clock, is->audio_diff_threshold);
1009 /* too big difference : may be initial PTS errors, so
1011 is->audio_diff_avg_count = 0;
1012 is->audio_diff_cum = 0;
1016 return samples_size;
1019 /* decode one audio frame and returns its uncompressed size */
1020 static int audio_decode_frame(VideoState *is, uint8_t *audio_buf, double *pts_ptr)
1022 AVPacket *pkt = &is->audio_pkt;
1023 int n, len1, data_size;
1027 /* NOTE: the audio packet can contain several frames */
1028 while (is->audio_pkt_size > 0) {
1029 len1 = avcodec_decode_audio(&is->audio_st->codec,
1030 (int16_t *)audio_buf, &data_size,
1031 is->audio_pkt_data, is->audio_pkt_size);
1033 /* if error, we skip the frame */
1034 is->audio_pkt_size = 0;
1038 is->audio_pkt_data += len1;
1039 is->audio_pkt_size -= len1;
1042 /* if no pts, then compute it */
1043 pts = is->audio_clock;
1045 n = 2 * is->audio_st->codec.channels;
1046 is->audio_clock += (double)data_size /
1047 (double)(n * is->audio_st->codec.sample_rate);
1048 #if defined(DEBUG_SYNC)
1050 static double last_clock;
1051 printf("audio: delay=%0.3f clock=%0.3f pts=%0.3f\n",
1052 is->audio_clock - last_clock,
1053 is->audio_clock, pts);
1054 last_clock = is->audio_clock;
1060 /* free the current packet */
1062 av_free_packet(pkt);
1064 if (is->paused || is->audioq.abort_request) {
1068 /* read next packet */
1069 if (packet_queue_get(&is->audioq, pkt, 1) < 0)
1071 is->audio_pkt_data = pkt->data;
1072 is->audio_pkt_size = pkt->size;
1074 /* if update the audio clock with the pts */
1075 if (pkt->pts != AV_NOPTS_VALUE) {
1076 is->audio_clock = (double)pkt->pts / AV_TIME_BASE;
1081 /* get the current audio output buffer size, in samples. With SDL, we
1082 cannot have a precise information */
1083 static int audio_write_get_buf_size(VideoState *is)
1085 return is->audio_hw_buf_size - is->audio_buf_index;
1089 /* prepare a new audio buffer */
1090 void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
1092 VideoState *is = opaque;
1093 int audio_size, len1;
1096 audio_callback_time = av_gettime();
1099 if (is->audio_buf_index >= is->audio_buf_size) {
1100 audio_size = audio_decode_frame(is, is->audio_buf, &pts);
1101 if (audio_size < 0) {
1102 /* if error, just output silence */
1103 is->audio_buf_size = 1024;
1104 memset(is->audio_buf, 0, is->audio_buf_size);
1107 update_sample_display(is, (int16_t *)is->audio_buf, audio_size);
1108 audio_size = synchronize_audio(is, (int16_t *)is->audio_buf, audio_size,
1110 is->audio_buf_size = audio_size;
1112 is->audio_buf_index = 0;
1114 len1 = is->audio_buf_size - is->audio_buf_index;
1117 memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1);
1120 is->audio_buf_index += len1;
1125 /* open a given stream. Return 0 if OK */
1126 static int stream_component_open(VideoState *is, int stream_index)
1128 AVFormatContext *ic = is->ic;
1129 AVCodecContext *enc;
1131 SDL_AudioSpec wanted_spec, spec;
1133 if (stream_index < 0 || stream_index >= ic->nb_streams)
1135 enc = &ic->streams[stream_index]->codec;
1137 /* prepare audio output */
1138 if (enc->codec_type == CODEC_TYPE_AUDIO) {
1139 wanted_spec.freq = enc->sample_rate;
1140 wanted_spec.format = AUDIO_S16SYS;
1141 /* hack for AC3. XXX: suppress that */
1142 if (enc->channels > 2)
1144 wanted_spec.channels = enc->channels;
1145 wanted_spec.silence = 0;
1146 wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
1147 wanted_spec.callback = sdl_audio_callback;
1148 wanted_spec.userdata = is;
1149 if (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
1150 fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError());
1153 is->audio_hw_buf_size = spec.size;
1156 codec = avcodec_find_decoder(enc->codec_id);
1157 enc->debug_mv = debug_mv;
1159 enc->workaround_bugs = workaround_bugs;
1160 enc->lowres = lowres;
1161 if(lowres) enc->flags |= CODEC_FLAG_EMU_EDGE;
1162 enc->idct_algo= idct;
1163 if(fast) enc->flags2 |= CODEC_FLAG2_FAST;
1165 avcodec_open(enc, codec) < 0)
1167 #if defined(HAVE_THREADS)
1169 avcodec_thread_init(enc, thread_count);
1171 enc->thread_count= thread_count;
1172 switch(enc->codec_type) {
1173 case CODEC_TYPE_AUDIO:
1174 is->audio_stream = stream_index;
1175 is->audio_st = ic->streams[stream_index];
1176 is->audio_buf_size = 0;
1177 is->audio_buf_index = 0;
1179 /* init averaging filter */
1180 is->audio_diff_avg_coef = exp(log(0.01) / AUDIO_DIFF_AVG_NB);
1181 is->audio_diff_avg_count = 0;
1182 /* since we do not have a precise anough audio fifo fullness,
1183 we correct audio sync only if larger than this threshold */
1184 is->audio_diff_threshold = 2.0 * SDL_AUDIO_BUFFER_SIZE / enc->sample_rate;
1186 memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
1187 packet_queue_init(&is->audioq);
1190 case CODEC_TYPE_VIDEO:
1191 is->video_stream = stream_index;
1192 is->video_st = ic->streams[stream_index];
1194 is->frame_last_delay = 40e-3;
1195 is->frame_timer = (double)av_gettime() / 1000000.0;
1196 is->video_current_pts_time = av_gettime();
1198 packet_queue_init(&is->videoq);
1199 is->video_tid = SDL_CreateThread(video_thread, is);
1207 static void stream_component_close(VideoState *is, int stream_index)
1209 AVFormatContext *ic = is->ic;
1210 AVCodecContext *enc;
1212 enc = &ic->streams[stream_index]->codec;
1214 switch(enc->codec_type) {
1215 case CODEC_TYPE_AUDIO:
1216 packet_queue_abort(&is->audioq);
1220 packet_queue_end(&is->audioq);
1222 case CODEC_TYPE_VIDEO:
1223 packet_queue_abort(&is->videoq);
1225 /* note: we also signal this mutex to make sure we deblock the
1226 video thread in all cases */
1227 SDL_LockMutex(is->pictq_mutex);
1228 SDL_CondSignal(is->pictq_cond);
1229 SDL_UnlockMutex(is->pictq_mutex);
1231 SDL_WaitThread(is->video_tid, NULL);
1233 packet_queue_end(&is->videoq);
1240 switch(enc->codec_type) {
1241 case CODEC_TYPE_AUDIO:
1242 is->audio_st = NULL;
1243 is->audio_stream = -1;
1245 case CODEC_TYPE_VIDEO:
1246 is->video_st = NULL;
1247 is->video_stream = -1;
1254 void dump_stream_info(AVFormatContext *s)
1257 fprintf(stderr, "Track: %d\n", s->track);
1258 if (s->title[0] != '\0')
1259 fprintf(stderr, "Title: %s\n", s->title);
1260 if (s->author[0] != '\0')
1261 fprintf(stderr, "Author: %s\n", s->author);
1262 if (s->album[0] != '\0')
1263 fprintf(stderr, "Album: %s\n", s->album);
1265 fprintf(stderr, "Year: %d\n", s->year);
1266 if (s->genre[0] != '\0')
1267 fprintf(stderr, "Genre: %s\n", s->genre);
1270 /* since we have only one decoding thread, we can use a global
1271 variable instead of a thread local variable */
1272 static VideoState *global_video_state;
1274 static int decode_interrupt_cb(void)
1276 return (global_video_state && global_video_state->abort_request);
1279 /* this thread gets the stream from the disk or the network */
1280 static int decode_thread(void *arg)
1282 VideoState *is = arg;
1283 AVFormatContext *ic;
1284 int err, i, ret, video_index, audio_index, use_play;
1285 AVPacket pkt1, *pkt = &pkt1;
1286 AVFormatParameters params, *ap = ¶ms;
1290 is->video_stream = -1;
1291 is->audio_stream = -1;
1293 global_video_state = is;
1294 url_set_interrupt_cb(decode_interrupt_cb);
1296 memset(ap, 0, sizeof(*ap));
1297 ap->image_format = image_format;
1298 ap->initial_pause = 1; /* we force a pause when starting an RTSP
1301 err = av_open_input_file(&ic, is->filename, is->iformat, 0, ap);
1303 print_error(is->filename, err);
1308 #ifdef CONFIG_NETWORK
1309 use_play = (ic->iformat == &rtsp_demux);
1314 err = av_find_stream_info(ic);
1316 fprintf(stderr, "%s: could not find codec parameters\n", is->filename);
1322 /* if seeking requested, we execute it */
1323 if (start_time != AV_NOPTS_VALUE) {
1326 timestamp = start_time;
1327 /* add the stream start time */
1328 if (ic->start_time != AV_NOPTS_VALUE)
1329 timestamp += ic->start_time;
1330 ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
1332 fprintf(stderr, "%s: could not seek to position %0.3f\n",
1333 is->filename, (double)timestamp / AV_TIME_BASE);
1337 /* now we can begin to play (RTSP stream only) */
1341 err = av_find_stream_info(ic);
1343 fprintf(stderr, "%s: could not find codec parameters\n", is->filename);
1349 for(i = 0; i < ic->nb_streams; i++) {
1350 AVCodecContext *enc = &ic->streams[i]->codec;
1351 switch(enc->codec_type) {
1352 case CODEC_TYPE_AUDIO:
1353 if (audio_index < 0 && !audio_disable)
1356 case CODEC_TYPE_VIDEO:
1357 if (video_index < 0 && !video_disable)
1365 dump_format(ic, 0, is->filename, 0);
1366 dump_stream_info(ic);
1369 /* open the streams */
1370 if (audio_index >= 0) {
1371 stream_component_open(is, audio_index);
1374 if (video_index >= 0) {
1375 stream_component_open(is, video_index);
1377 if (!display_disable)
1381 if (is->video_stream < 0 && is->audio_stream < 0) {
1382 fprintf(stderr, "%s: could not open codecs\n", is->filename);
1388 if (is->abort_request)
1390 #ifdef CONFIG_NETWORK
1391 if (is->paused != is->last_paused) {
1392 is->last_paused = is->paused;
1398 if (is->paused && ic->iformat == &rtsp_demux) {
1399 /* wait 10 ms to avoid trying to get another packet */
1406 /* XXX: must lock decoder threads */
1407 ret = av_seek_frame(is->ic, -1, is->seek_pos, is->seek_flags);
1409 fprintf(stderr, "%s: error while seeking\n", is->ic->filename);
1411 if (is->audio_stream >= 0) {
1412 packet_queue_flush(&is->audioq);
1414 if (is->video_stream >= 0) {
1415 packet_queue_flush(&is->videoq);
1416 avcodec_flush_buffers(&ic->streams[video_index]->codec);
1422 /* if the queue are full, no need to read more */
1423 if (is->audioq.size > MAX_AUDIOQ_SIZE ||
1424 is->videoq.size > MAX_VIDEOQ_SIZE ||
1425 url_feof(&ic->pb)) {
1430 ret = av_read_frame(ic, pkt);
1432 if (url_feof(&ic->pb) && url_ferror(&ic->pb) == 0) {
1433 SDL_Delay(100); /* wait for user event */
1438 if (pkt->stream_index == is->audio_stream) {
1439 packet_queue_put(&is->audioq, pkt);
1440 } else if (pkt->stream_index == is->video_stream) {
1441 packet_queue_put(&is->videoq, pkt);
1443 av_free_packet(pkt);
1446 /* wait until the end */
1447 while (!is->abort_request) {
1453 /* disable interrupting */
1454 global_video_state = NULL;
1456 /* close each stream */
1457 if (is->audio_stream >= 0)
1458 stream_component_close(is, is->audio_stream);
1459 if (is->video_stream >= 0)
1460 stream_component_close(is, is->video_stream);
1462 av_close_input_file(is->ic);
1463 is->ic = NULL; /* safety */
1465 url_set_interrupt_cb(NULL);
1470 event.type = FF_QUIT_EVENT;
1471 event.user.data1 = is;
1472 SDL_PushEvent(&event);
1477 static VideoState *stream_open(const char *filename, AVInputFormat *iformat)
1481 is = av_mallocz(sizeof(VideoState));
1484 pstrcpy(is->filename, sizeof(is->filename), filename);
1485 is->iformat = iformat;
1487 is->width = screen->w;
1488 is->height = screen->h;
1493 /* start video display */
1494 is->pictq_mutex = SDL_CreateMutex();
1495 is->pictq_cond = SDL_CreateCond();
1497 /* add the refresh timer to draw the picture */
1498 schedule_refresh(is, 40);
1500 is->av_sync_type = av_sync_type;
1501 is->parse_tid = SDL_CreateThread(decode_thread, is);
1502 if (!is->parse_tid) {
1509 static void stream_close(VideoState *is)
1513 /* XXX: use a special url_shutdown call to abort parse cleanly */
1514 is->abort_request = 1;
1515 SDL_WaitThread(is->parse_tid, NULL);
1517 /* free all pictures */
1518 for(i=0;i<VIDEO_PICTURE_QUEUE_SIZE; i++) {
1521 SDL_FreeYUVOverlay(vp->bmp);
1525 SDL_DestroyMutex(is->pictq_mutex);
1526 SDL_DestroyCond(is->pictq_cond);
1529 void stream_cycle_channel(VideoState *is, int codec_type)
1531 AVFormatContext *ic = is->ic;
1532 int start_index, stream_index;
1535 if (codec_type == CODEC_TYPE_VIDEO)
1536 start_index = is->video_stream;
1538 start_index = is->audio_stream;
1539 if (start_index < 0)
1541 stream_index = start_index;
1543 if (++stream_index >= is->ic->nb_streams)
1545 if (stream_index == start_index)
1547 st = ic->streams[stream_index];
1548 if (st->codec.codec_type == codec_type) {
1549 /* check that parameters are OK */
1550 switch(codec_type) {
1551 case CODEC_TYPE_AUDIO:
1552 if (st->codec.sample_rate != 0 &&
1553 st->codec.channels != 0)
1556 case CODEC_TYPE_VIDEO:
1564 stream_component_close(is, start_index);
1565 stream_component_open(is, stream_index);
1569 void toggle_full_screen(void)
1572 is_full_screen = !is_full_screen;
1573 if (!fs_screen_width) {
1574 /* use default SDL method */
1575 SDL_WM_ToggleFullScreen(screen);
1577 /* use the recorded resolution */
1578 flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
1579 if (is_full_screen) {
1580 w = fs_screen_width;
1581 h = fs_screen_height;
1582 flags |= SDL_FULLSCREEN;
1586 flags |= SDL_RESIZABLE;
1588 screen = SDL_SetVideoMode(w, h, 0, flags);
1589 cur_stream->width = w;
1590 cur_stream->height = h;
1594 void toggle_pause(void)
1597 stream_pause(cur_stream);
1601 void step_to_next_frame(void)
1604 if (cur_stream->paused)
1605 cur_stream->paused=0;
1606 cur_stream->video_current_pts = get_video_clock(cur_stream);
1614 stream_close(cur_stream);
1623 void toggle_audio_display(void)
1626 cur_stream->show_audio = !cur_stream->show_audio;
1630 /* handle an event sent by the GUI */
1631 void event_loop(void)
1634 double incr, pos, frac;
1637 SDL_WaitEvent(&event);
1638 switch(event.type) {
1640 switch(event.key.keysym.sym) {
1646 toggle_full_screen();
1652 case SDLK_s: //S: Step to next frame
1653 step_to_next_frame();
1657 stream_cycle_channel(cur_stream, CODEC_TYPE_AUDIO);
1661 stream_cycle_channel(cur_stream, CODEC_TYPE_VIDEO);
1664 toggle_audio_display();
1679 pos = get_master_clock(cur_stream);
1681 stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), incr);
1688 case SDL_MOUSEBUTTONDOWN:
1691 int tns, thh, tmm, tss;
1692 tns = cur_stream->ic->duration/1000000LL;
1694 tmm = (tns%3600)/60;
1696 frac = (double)event.button.x/(double)cur_stream->width;
1701 fprintf(stderr, "Seek to %2.0f%% (%2d:%02d:%02d) of total duration (%2d:%02d:%02d) \n", frac*100,
1702 hh, mm, ss, thh, tmm, tss);
1703 stream_seek(cur_stream, (int64_t)(cur_stream->ic->start_time+frac*cur_stream->ic->duration), 0);
1706 case SDL_VIDEORESIZE:
1708 screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0,
1709 SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL);
1710 cur_stream->width = event.resize.w;
1711 cur_stream->height = event.resize.h;
1718 case FF_ALLOC_EVENT:
1719 alloc_picture(event.user.data1);
1721 case FF_REFRESH_EVENT:
1722 video_refresh_timer(event.user.data1);
1730 void opt_width(const char *arg)
1732 screen_width = atoi(arg);
1735 void opt_height(const char *arg)
1737 screen_height = atoi(arg);
1740 static void opt_format(const char *arg)
1742 file_iformat = av_find_input_format(arg);
1743 if (!file_iformat) {
1744 fprintf(stderr, "Unknown input format: %s\n", arg);
1749 static void opt_image_format(const char *arg)
1753 for(f = first_image_format; f != NULL; f = f->next) {
1754 if (!strcmp(arg, f->name))
1758 fprintf(stderr, "Unknown image format: '%s'\n", arg);
1764 #ifdef CONFIG_NETWORK
1765 void opt_rtp_tcp(void)
1767 /* only tcp protocol */
1768 rtsp_default_protocols = (1 << RTSP_PROTOCOL_RTP_TCP);
1772 void opt_sync(const char *arg)
1774 if (!strcmp(arg, "audio"))
1775 av_sync_type = AV_SYNC_AUDIO_MASTER;
1776 else if (!strcmp(arg, "video"))
1777 av_sync_type = AV_SYNC_VIDEO_MASTER;
1778 else if (!strcmp(arg, "ext"))
1779 av_sync_type = AV_SYNC_EXTERNAL_CLOCK;
1784 void opt_seek(const char *arg)
1786 start_time = parse_date(arg, 1);
1789 static void opt_debug(const char *arg)
1794 static void opt_vismv(const char *arg)
1796 debug_mv = atoi(arg);
1799 static void opt_thread_count(const char *arg)
1801 thread_count= atoi(arg);
1802 #if !defined(HAVE_THREADS)
1803 fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
1807 const OptionDef options[] = {
1808 { "h", 0, {(void*)show_help}, "show help" },
1809 { "x", HAS_ARG, {(void*)opt_width}, "force displayed width", "width" },
1810 { "y", HAS_ARG, {(void*)opt_height}, "force displayed height", "height" },
1812 /* disabled as SDL/X11 does not support it correctly on application launch */
1813 { "fs", OPT_BOOL, {(void*)&is_full_screen}, "force full screen" },
1815 { "an", OPT_BOOL, {(void*)&audio_disable}, "disable audio" },
1816 { "vn", OPT_BOOL, {(void*)&video_disable}, "disable video" },
1817 { "ss", HAS_ARG, {(void*)&opt_seek}, "seek to a given position in seconds", "pos" },
1818 { "nodisp", OPT_BOOL, {(void*)&display_disable}, "disable graphical display" },
1819 { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
1820 { "img", HAS_ARG, {(void*)opt_image_format}, "force image format", "img_fmt" },
1821 { "stats", OPT_BOOL | OPT_EXPERT, {(void*)&show_status}, "show status", "" },
1822 { "debug", HAS_ARG | OPT_EXPERT, {(void*)opt_debug}, "print specific debug info", "" },
1823 { "bug", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&workaround_bugs}, "workaround bugs", "" },
1824 { "vismv", HAS_ARG | OPT_EXPERT, {(void*)opt_vismv}, "visualize motion vectors", "" },
1825 { "fast", OPT_BOOL | OPT_EXPERT, {(void*)&fast}, "non spec compliant optimizations", "" },
1826 { "lowres", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&lowres}, "", "" },
1827 { "idct", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&idct}, "set idct algo", "algo" },
1828 #ifdef CONFIG_NETWORK
1829 { "rtp_tcp", OPT_EXPERT, {(void*)&opt_rtp_tcp}, "force RTP/TCP protocol usage", "" },
1831 { "sync", HAS_ARG | OPT_EXPERT, {(void*)opt_sync}, "set audio-video sync. type (type=audio/video/ext)", "type" },
1832 { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
1836 void show_help(void)
1838 printf("ffplay version " FFMPEG_VERSION ", Copyright (c) 2003 Fabrice Bellard\n"
1839 "usage: ffplay [options] input_file\n"
1840 "Simple media player\n");
1842 show_help_options(options, "Main options:\n",
1844 show_help_options(options, "\nAdvanced options:\n",
1845 OPT_EXPERT, OPT_EXPERT);
1846 printf("\nWhile playing:\n"
1848 "f toggle full screen\n"
1850 "a cycle audio channel\n"
1851 "v cycle video channel\n"
1852 "w show audio waves\n"
1853 "left/right seek backward/forward 10 seconds\n"
1854 "down/up seek backward/forward 1 minute\n"
1855 "mouse click seek to percentage in file corresponding to fraction of width\n"
1860 void parse_arg_file(const char *filename)
1862 if (!strcmp(filename, "-"))
1864 input_filename = filename;
1867 /* Called from the main */
1868 int main(int argc, char **argv)
1872 /* register all codecs, demux and protocols */
1875 parse_options(argc, argv, options);
1877 if (!input_filename)
1880 if (display_disable) {
1883 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
1884 #ifndef CONFIG_WIN32
1885 flags |= SDL_INIT_EVENTTHREAD; /* Not supported on win32 */
1887 if (SDL_Init (flags)) {
1888 fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
1892 if (!display_disable) {
1894 /* save the screen resolution... SDL should allow full screen
1895 by resizing the window */
1898 dpy = XOpenDisplay(NULL);
1900 fs_screen_width = DisplayWidth(dpy, DefaultScreen(dpy));
1901 fs_screen_height = DisplayHeight(dpy, DefaultScreen(dpy));
1906 flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
1907 if (is_full_screen && fs_screen_width) {
1908 w = fs_screen_width;
1909 h = fs_screen_height;
1910 flags |= SDL_FULLSCREEN;
1914 flags |= SDL_RESIZABLE;
1916 screen = SDL_SetVideoMode(w, h, 0, flags);
1918 fprintf(stderr, "SDL: could not set video mode - exiting\n");
1921 SDL_WM_SetCaption("FFplay", "FFplay");
1924 SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
1925 SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
1926 SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
1927 SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
1929 cur_stream = stream_open(input_filename, file_iformat);