You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1451 lines
40KB

  1. /*
  2. * FFplay : Simple Media Player based on the ffmpeg libraries
  3. * Copyright (c) 2003 Fabrice Bellard
  4. *
  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.
  9. *
  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.
  14. *
  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
  18. */
  19. #define HAVE_AV_CONFIG_H
  20. #include "common.h"
  21. #include "avformat.h"
  22. #include "cmdutils.h"
  23. #include <SDL.h>
  24. #include <SDL_thread.h>
  25. #ifdef CONFIG_WIN32
  26. #undef main /* We don't want SDL to override our main() */
  27. #endif
  28. #if defined(__linux__)
  29. #define HAVE_X11
  30. #endif
  31. #ifdef HAVE_X11
  32. #include <X11/Xlib.h>
  33. #endif
  34. #define MAX_VIDEOQ_SIZE (5 * 256 * 1024)
  35. #define MAX_AUDIOQ_SIZE (5 * 16 * 1024)
  36. /* NOTE: the size must be big enough to compensate the hardware audio buffersize size */
  37. #define SAMPLE_ARRAY_SIZE (2*65536)
  38. typedef struct PacketQueue {
  39. AVPacketList *first_pkt, *last_pkt;
  40. int nb_packets;
  41. int size;
  42. int abort_request;
  43. SDL_mutex *mutex;
  44. SDL_cond *cond;
  45. } PacketQueue;
  46. #define VIDEO_PICTURE_QUEUE_SIZE 1
  47. typedef struct VideoPicture {
  48. int delay; /* delay before showing the next picture */
  49. SDL_Overlay *bmp;
  50. int width, height; /* source height & width */
  51. int allocated;
  52. } VideoPicture;
  53. enum {
  54. AV_SYNC_AUDIO_MASTER, /* default choice */
  55. AV_SYNC_VIDEO_MASTER,
  56. AV_SYNC_EXTERNAL_CLOCK, /* if external clock, then you must update external_clock yourself */
  57. };
  58. typedef struct VideoState {
  59. SDL_Thread *parse_tid;
  60. SDL_Thread *video_tid;
  61. int no_background;
  62. int abort_request;
  63. int paused;
  64. int last_paused;
  65. AVFormatContext *ic;
  66. int dtg_active_format;
  67. int audio_stream;
  68. int av_sync_type;
  69. double external_clock; /* external clock */
  70. double audio_clock; /* current audio clock value */
  71. AVStream *audio_st;
  72. PacketQueue audioq;
  73. int audio_hw_buf_size;
  74. /* samples output by the codec. we reserve more space for avsync
  75. compensation */
  76. uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
  77. int audio_buf_size; /* in bytes */
  78. int audio_buf_index; /* in bytes */
  79. AVPacket audio_pkt;
  80. uint8_t *audio_pkt_data;
  81. int audio_pkt_size;
  82. int64_t audio_pkt_ipts;
  83. int show_audio; /* if true, display audio samples */
  84. int16_t sample_array[SAMPLE_ARRAY_SIZE];
  85. int sample_array_index;
  86. int last_i_start;
  87. double video_clock; /* current video clock value */
  88. int video_stream;
  89. AVStream *video_st;
  90. PacketQueue videoq;
  91. VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE];
  92. int pictq_size, pictq_rindex, pictq_windex;
  93. SDL_mutex *pictq_mutex;
  94. SDL_cond *pictq_cond;
  95. // QETimer *video_timer;
  96. char filename[1024];
  97. int width, height, xleft, ytop;
  98. } VideoState;
  99. void show_help(void);
  100. int audio_write_get_buf_size(VideoState *is);
  101. /* options specified by the user */
  102. static AVInputFormat *file_iformat;
  103. static const char *input_filename;
  104. static int fs_screen_width;
  105. static int fs_screen_height;
  106. static int screen_width = 640;
  107. static int screen_height = 480;
  108. static int audio_disable;
  109. static int video_disable;
  110. static int display_disable;
  111. static int show_status;
  112. /* current context */
  113. static int is_full_screen;
  114. static VideoState *cur_stream;
  115. static int64_t audio_callback_time;
  116. #define FF_ALLOC_EVENT (SDL_USEREVENT)
  117. #define FF_REFRESH_EVENT (SDL_USEREVENT + 1)
  118. SDL_Surface *screen;
  119. /* packet queue handling */
  120. static void packet_queue_init(PacketQueue *q)
  121. {
  122. memset(q, 0, sizeof(PacketQueue));
  123. q->mutex = SDL_CreateMutex();
  124. q->cond = SDL_CreateCond();
  125. }
  126. static void packet_queue_end(PacketQueue *q)
  127. {
  128. AVPacketList *pkt, *pkt1;
  129. for(pkt = q->first_pkt; pkt != NULL; pkt = pkt1) {
  130. pkt1 = pkt->next;
  131. av_free_packet(&pkt->pkt);
  132. }
  133. SDL_DestroyMutex(q->mutex);
  134. SDL_DestroyCond(q->cond);
  135. }
  136. static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
  137. {
  138. AVPacketList *pkt1;
  139. pkt1 = av_malloc(sizeof(AVPacketList));
  140. if (!pkt1)
  141. return -1;
  142. pkt1->pkt = *pkt;
  143. pkt1->next = NULL;
  144. SDL_LockMutex(q->mutex);
  145. if (!q->last_pkt)
  146. q->first_pkt = pkt1;
  147. else
  148. q->last_pkt->next = pkt1;
  149. q->last_pkt = pkt1;
  150. q->nb_packets++;
  151. q->size += pkt1->pkt.size;
  152. /* XXX: should duplicate packet data in DV case */
  153. SDL_CondSignal(q->cond);
  154. SDL_UnlockMutex(q->mutex);
  155. return 0;
  156. }
  157. static void packet_queue_abort(PacketQueue *q)
  158. {
  159. SDL_LockMutex(q->mutex);
  160. q->abort_request = 1;
  161. SDL_CondSignal(q->cond);
  162. SDL_UnlockMutex(q->mutex);
  163. }
  164. /* return < 0 if aborted, 0 if no packet and > 0 if packet. */
  165. static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block)
  166. {
  167. AVPacketList *pkt1;
  168. int ret;
  169. SDL_LockMutex(q->mutex);
  170. for(;;) {
  171. if (q->abort_request) {
  172. ret = -1;
  173. break;
  174. }
  175. pkt1 = q->first_pkt;
  176. if (pkt1) {
  177. q->first_pkt = pkt1->next;
  178. if (!q->first_pkt)
  179. q->last_pkt = NULL;
  180. q->nb_packets--;
  181. q->size -= pkt1->pkt.size;
  182. *pkt = pkt1->pkt;
  183. av_free(pkt1);
  184. ret = 1;
  185. break;
  186. } else if (!block) {
  187. ret = 0;
  188. break;
  189. } else {
  190. SDL_CondWait(q->cond, q->mutex);
  191. }
  192. }
  193. SDL_UnlockMutex(q->mutex);
  194. return ret;
  195. }
  196. static inline void fill_rectangle(SDL_Surface *screen,
  197. int x, int y, int w, int h, int color)
  198. {
  199. SDL_Rect rect;
  200. rect.x = x;
  201. rect.y = y;
  202. rect.w = w;
  203. rect.h = h;
  204. SDL_FillRect(screen, &rect, color);
  205. }
  206. #if 0
  207. /* draw only the border of a rectangle */
  208. void fill_border(VideoState *s, int x, int y, int w, int h, int color)
  209. {
  210. int w1, w2, h1, h2;
  211. /* fill the background */
  212. w1 = x;
  213. if (w1 < 0)
  214. w1 = 0;
  215. w2 = s->width - (x + w);
  216. if (w2 < 0)
  217. w2 = 0;
  218. h1 = y;
  219. if (h1 < 0)
  220. h1 = 0;
  221. h2 = s->height - (y + h);
  222. if (h2 < 0)
  223. h2 = 0;
  224. fill_rectangle(screen,
  225. s->xleft, s->ytop,
  226. w1, s->height,
  227. color);
  228. fill_rectangle(screen,
  229. s->xleft + s->width - w2, s->ytop,
  230. w2, s->height,
  231. color);
  232. fill_rectangle(screen,
  233. s->xleft + w1, s->ytop,
  234. s->width - w1 - w2, h1,
  235. color);
  236. fill_rectangle(screen,
  237. s->xleft + w1, s->ytop + s->height - h2,
  238. s->width - w1 - w2, h2,
  239. color);
  240. }
  241. #endif
  242. static void video_image_display(VideoState *is)
  243. {
  244. VideoPicture *vp;
  245. float aspect_ratio;
  246. int width, height, x, y;
  247. SDL_Rect rect;
  248. vp = &is->pictq[is->pictq_rindex];
  249. if (vp->bmp) {
  250. /* XXX: use variable in the frame */
  251. aspect_ratio = is->video_st->codec.aspect_ratio;
  252. if (aspect_ratio <= 0.0)
  253. aspect_ratio = (float)is->video_st->codec.width /
  254. (float)is->video_st->codec.height;
  255. /* if an active format is indicated, then it overrides the
  256. mpeg format */
  257. #if 0
  258. if (is->video_st->codec.dtg_active_format != is->dtg_active_format) {
  259. is->dtg_active_format = is->video_st->codec.dtg_active_format;
  260. printf("dtg_active_format=%d\n", is->dtg_active_format);
  261. }
  262. #endif
  263. #if 0
  264. switch(is->video_st->codec.dtg_active_format) {
  265. case FF_DTG_AFD_SAME:
  266. default:
  267. /* nothing to do */
  268. break;
  269. case FF_DTG_AFD_4_3:
  270. aspect_ratio = 4.0 / 3.0;
  271. break;
  272. case FF_DTG_AFD_16_9:
  273. aspect_ratio = 16.0 / 9.0;
  274. break;
  275. case FF_DTG_AFD_14_9:
  276. aspect_ratio = 14.0 / 9.0;
  277. break;
  278. case FF_DTG_AFD_4_3_SP_14_9:
  279. aspect_ratio = 14.0 / 9.0;
  280. break;
  281. case FF_DTG_AFD_16_9_SP_14_9:
  282. aspect_ratio = 14.0 / 9.0;
  283. break;
  284. case FF_DTG_AFD_SP_4_3:
  285. aspect_ratio = 4.0 / 3.0;
  286. break;
  287. }
  288. #endif
  289. /* XXX: we suppose the screen has a 1.0 pixel ratio */
  290. height = is->height;
  291. width = ((int)rint(height * aspect_ratio)) & -3;
  292. if (width > is->width) {
  293. width = is->width;
  294. height = ((int)rint(width / aspect_ratio)) & -3;
  295. }
  296. x = (is->width - width) / 2;
  297. y = (is->height - height) / 2;
  298. if (!is->no_background) {
  299. /* fill the background */
  300. // fill_border(is, x, y, width, height, QERGB(0x00, 0x00, 0x00));
  301. } else {
  302. is->no_background = 0;
  303. }
  304. rect.x = is->xleft + x;
  305. rect.y = is->xleft + y;
  306. rect.w = width;
  307. rect.h = height;
  308. SDL_DisplayYUVOverlay(vp->bmp, &rect);
  309. } else {
  310. #if 0
  311. fill_rectangle(screen,
  312. is->xleft, is->ytop, is->width, is->height,
  313. QERGB(0x00, 0x00, 0x00));
  314. #endif
  315. }
  316. }
  317. static inline int compute_mod(int a, int b)
  318. {
  319. a = a % b;
  320. if (a >= 0)
  321. return a;
  322. else
  323. return a + b;
  324. }
  325. static void video_audio_display(VideoState *s)
  326. {
  327. int i, i_start, x, y1, y, ys, delay, n, nb_display_channels;
  328. int ch, channels, h, h2, bgcolor, fgcolor;
  329. int16_t time_diff;
  330. /* compute display index : center on currently output samples */
  331. channels = s->audio_st->codec.channels;
  332. nb_display_channels = channels;
  333. if (!s->paused) {
  334. n = 2 * channels;
  335. delay = audio_write_get_buf_size(s);
  336. delay /= n;
  337. /* to be more precise, we take into account the time spent since
  338. the last buffer computation */
  339. if (audio_callback_time) {
  340. time_diff = av_gettime() - audio_callback_time;
  341. delay += (time_diff * s->audio_st->codec.sample_rate) / 1000000;
  342. }
  343. delay -= s->width / 2;
  344. if (delay < s->width)
  345. delay = s->width;
  346. i_start = compute_mod(s->sample_array_index - delay * channels, SAMPLE_ARRAY_SIZE);
  347. s->last_i_start = i_start;
  348. } else {
  349. i_start = s->last_i_start;
  350. }
  351. bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
  352. fill_rectangle(screen,
  353. s->xleft, s->ytop, s->width, s->height,
  354. bgcolor);
  355. fgcolor = SDL_MapRGB(screen->format, 0xff, 0xff, 0xff);
  356. /* total height for one channel */
  357. h = s->height / nb_display_channels;
  358. /* graph height / 2 */
  359. h2 = (h * 9) / 20;
  360. for(ch = 0;ch < nb_display_channels; ch++) {
  361. i = i_start + ch;
  362. y1 = s->ytop + ch * h + (h / 2); /* position of center line */
  363. for(x = 0; x < s->width; x++) {
  364. y = (s->sample_array[i] * h2) >> 15;
  365. if (y < 0) {
  366. y = -y;
  367. ys = y1 - y;
  368. } else {
  369. ys = y1;
  370. }
  371. fill_rectangle(screen,
  372. s->xleft + x, ys, 1, y,
  373. fgcolor);
  374. i += channels;
  375. if (i >= SAMPLE_ARRAY_SIZE)
  376. i -= SAMPLE_ARRAY_SIZE;
  377. }
  378. }
  379. fgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0xff);
  380. for(ch = 1;ch < nb_display_channels; ch++) {
  381. y = s->ytop + ch * h;
  382. fill_rectangle(screen,
  383. s->xleft, y, s->width, 1,
  384. fgcolor);
  385. }
  386. SDL_UpdateRect(screen, s->xleft, s->ytop, s->width, s->height);
  387. }
  388. /* display the current picture, if any */
  389. static void video_display(VideoState *is)
  390. {
  391. if (is->audio_st && is->show_audio)
  392. video_audio_display(is);
  393. else if (is->video_st)
  394. video_image_display(is);
  395. }
  396. static Uint32 sdl_refresh_timer_cb(Uint32 interval, void *opaque)
  397. {
  398. SDL_Event event;
  399. event.type = FF_REFRESH_EVENT;
  400. event.user.data1 = opaque;
  401. SDL_PushEvent(&event);
  402. return 0; /* 0 means stop timer */
  403. }
  404. /* schedule a video refresh in 'delay' ms */
  405. static void schedule_refresh(VideoState *is, int delay)
  406. {
  407. SDL_AddTimer(delay, sdl_refresh_timer_cb, is);
  408. }
  409. /* called to display each frame */
  410. static void video_refresh_timer(void *opaque)
  411. {
  412. VideoState *is = opaque;
  413. VideoPicture *vp;
  414. if (is->video_st) {
  415. if (is->pictq_size == 0) {
  416. /* if no picture, need to wait */
  417. schedule_refresh(is, 40);
  418. } else {
  419. vp = &is->pictq[is->pictq_rindex];
  420. /* launch timer for next picture */
  421. schedule_refresh(is, vp->delay);
  422. /* display picture */
  423. video_display(is);
  424. /* update queue size and signal for next picture */
  425. if (++is->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE)
  426. is->pictq_rindex = 0;
  427. SDL_LockMutex(is->pictq_mutex);
  428. is->pictq_size--;
  429. SDL_CondSignal(is->pictq_cond);
  430. SDL_UnlockMutex(is->pictq_mutex);
  431. }
  432. } else if (is->audio_st) {
  433. /* draw the next audio frame */
  434. schedule_refresh(is, 40);
  435. /* if only audio stream, then display the audio bars (better
  436. than nothing, just to test the implementation */
  437. /* display picture */
  438. video_display(is);
  439. } else {
  440. schedule_refresh(is, 100);
  441. }
  442. if (show_status) {
  443. static int64_t last_time;
  444. int64_t cur_time;
  445. int aqsize, vqsize;
  446. cur_time = av_gettime();
  447. if (!last_time || (cur_time - last_time) >= 500 * 1000) {
  448. aqsize = 0;
  449. vqsize = 0;
  450. if (is->audio_st)
  451. aqsize = is->audioq.size;
  452. if (is->video_st)
  453. vqsize = is->videoq.size;
  454. printf("A:%7.2f V:%7.2f aq=%5dKB vq=%5dKB \r",
  455. is->audio_clock, is->video_clock, aqsize / 1024, vqsize / 1024);
  456. fflush(stdout);
  457. last_time = cur_time;
  458. }
  459. }
  460. }
  461. /* allocate a picture (needs to do that in main thread to avoid
  462. potential locking problems */
  463. static void alloc_picture(void *opaque)
  464. {
  465. VideoState *is = opaque;
  466. VideoPicture *vp;
  467. int is_yuv;
  468. vp = &is->pictq[is->pictq_windex];
  469. if (vp->bmp)
  470. SDL_FreeYUVOverlay(vp->bmp);
  471. /* XXX: use generic function */
  472. switch(is->video_st->codec.pix_fmt) {
  473. case PIX_FMT_YUV420P:
  474. case PIX_FMT_YUV422P:
  475. case PIX_FMT_YUV444P:
  476. case PIX_FMT_YUV422:
  477. case PIX_FMT_YUV410P:
  478. case PIX_FMT_YUV411P:
  479. is_yuv = 1;
  480. break;
  481. default:
  482. is_yuv = 0;
  483. break;
  484. }
  485. if (is_yuv) {
  486. vp->bmp = SDL_CreateYUVOverlay(is->video_st->codec.width,
  487. is->video_st->codec.height,
  488. SDL_YV12_OVERLAY,
  489. screen);
  490. } else {
  491. #if 0
  492. vp->bmp = bmp_alloc(screen,
  493. is->video_st->codec.width,
  494. is->video_st->codec.height,
  495. screen->bitmap_format,
  496. 0);
  497. #endif
  498. vp->bmp = NULL;
  499. }
  500. vp->width = is->video_st->codec.width;
  501. vp->height = is->video_st->codec.height;
  502. SDL_LockMutex(is->pictq_mutex);
  503. vp->allocated = 1;
  504. SDL_CondSignal(is->pictq_cond);
  505. SDL_UnlockMutex(is->pictq_mutex);
  506. }
  507. #define VIDEO_CORRECTION_THRESHOLD 0.2
  508. static int output_picture(VideoState *is, AVPicture *src_pict, double pts)
  509. {
  510. VideoPicture *vp;
  511. int dst_pix_fmt;
  512. AVPicture pict;
  513. double delay, ref_clock, diff;
  514. /* wait until we have space to put a new picture */
  515. SDL_LockMutex(is->pictq_mutex);
  516. while (is->pictq_size >= VIDEO_PICTURE_QUEUE_SIZE &&
  517. !is->videoq.abort_request) {
  518. SDL_CondWait(is->pictq_cond, is->pictq_mutex);
  519. }
  520. SDL_UnlockMutex(is->pictq_mutex);
  521. if (is->videoq.abort_request)
  522. return -1;
  523. vp = &is->pictq[is->pictq_windex];
  524. /* alloc or resize hardware picture buffer */
  525. if (!vp->bmp ||
  526. vp->width != is->video_st->codec.width ||
  527. vp->height != is->video_st->codec.height) {
  528. SDL_Event event;
  529. vp->allocated = 0;
  530. /* the allocation must be done in the main thread to avoid
  531. locking problems */
  532. event.type = FF_ALLOC_EVENT;
  533. event.user.data1 = is;
  534. SDL_PushEvent(&event);
  535. /* wait until the picture is allocated */
  536. SDL_LockMutex(is->pictq_mutex);
  537. while (!vp->allocated && !is->videoq.abort_request) {
  538. SDL_CondWait(is->pictq_cond, is->pictq_mutex);
  539. }
  540. SDL_UnlockMutex(is->pictq_mutex);
  541. if (is->videoq.abort_request)
  542. return -1;
  543. }
  544. if (vp->bmp) {
  545. /* get a pointer on the bitmap */
  546. SDL_LockYUVOverlay (vp->bmp);
  547. dst_pix_fmt = PIX_FMT_YUV420P;
  548. pict.data[0] = vp->bmp->pixels[0];
  549. pict.data[1] = vp->bmp->pixels[2];
  550. pict.data[2] = vp->bmp->pixels[1];
  551. pict.linesize[0] = vp->bmp->pitches[0];
  552. pict.linesize[1] = vp->bmp->pitches[2];
  553. pict.linesize[2] = vp->bmp->pitches[1];
  554. img_convert(&pict, dst_pix_fmt,
  555. src_pict, is->video_st->codec.pix_fmt,
  556. is->video_st->codec.width, is->video_st->codec.height);
  557. /* update the bitmap content */
  558. SDL_UnlockYUVOverlay(vp->bmp);
  559. /* compute delay for the next frame and take into account the
  560. pts if needed to make a correction. Since we do not support
  561. correct MPEG B frame PTS, we put a high threshold */
  562. if (is->av_sync_type == AV_SYNC_VIDEO_MASTER) {
  563. ref_clock = is->video_clock;
  564. } else if (is->av_sync_type == AV_SYNC_AUDIO_MASTER) {
  565. /* cannot use audio master if no audio, so fall back to no sync */
  566. if (!is->audio_st)
  567. ref_clock = is->video_clock;
  568. else
  569. ref_clock = is->audio_clock;
  570. } else {
  571. ref_clock = is->external_clock;
  572. }
  573. diff = is->video_clock - ref_clock;
  574. delay = (double)is->video_st->codec.frame_rate_base /
  575. (double)is->video_st->codec.frame_rate;
  576. if (fabs(diff) > VIDEO_CORRECTION_THRESHOLD) {
  577. /* if too big difference, then we adjust */
  578. delay += diff;
  579. /* compute the difference */
  580. if (delay < 0.01)
  581. delay = 0.01;
  582. else if (delay > 1.0)
  583. delay = 1.0;
  584. }
  585. vp->delay = (int)(delay * 1000 + 0.5);
  586. /* now we can update the picture count */
  587. if (++is->pictq_windex == VIDEO_PICTURE_QUEUE_SIZE)
  588. is->pictq_windex = 0;
  589. SDL_LockMutex(is->pictq_mutex);
  590. is->pictq_size++;
  591. SDL_UnlockMutex(is->pictq_mutex);
  592. }
  593. /* update video clock */
  594. if (pts != 0) {
  595. is->video_clock = pts;
  596. } else {
  597. is->video_clock += (double)is->video_st->codec.frame_rate_base /
  598. (double)is->video_st->codec.frame_rate;
  599. }
  600. return 0;
  601. }
  602. static int video_thread(void *arg)
  603. {
  604. VideoState *is = arg;
  605. AVPacket pkt1, *pkt = &pkt1;
  606. unsigned char *ptr;
  607. int len, len1, got_picture, i;
  608. AVFrame frame;
  609. AVPicture pict;
  610. int64_t ipts;
  611. double pts;
  612. for(;;) {
  613. while (is->paused && !is->videoq.abort_request) {
  614. SDL_Delay(10);
  615. }
  616. if (packet_queue_get(&is->videoq, pkt, 1) < 0)
  617. break;
  618. ipts = pkt->pts;
  619. ptr = pkt->data;
  620. if (is->video_st->codec.codec_id == CODEC_ID_RAWVIDEO) {
  621. avpicture_fill(&pict, ptr,
  622. is->video_st->codec.pix_fmt,
  623. is->video_st->codec.width,
  624. is->video_st->codec.height);
  625. pts = 0;
  626. if (ipts != AV_NOPTS_VALUE)
  627. pts = (double)ipts * is->ic->pts_num / is->ic->pts_den;
  628. if (output_picture(is, &pict, pts) < 0)
  629. goto the_end;
  630. } else {
  631. len = pkt->size;
  632. while (len > 0) {
  633. len1 = avcodec_decode_video(&is->video_st->codec,
  634. &frame, &got_picture, ptr, len);
  635. if (len1 < 0)
  636. break;
  637. if (got_picture) {
  638. for(i=0;i<4;i++) {
  639. pict.data[i] = frame.data[i];
  640. pict.linesize[i] = frame.linesize[i];
  641. }
  642. pts = 0;
  643. if (ipts != AV_NOPTS_VALUE)
  644. pts = (double)ipts * is->ic->pts_num / is->ic->pts_den;
  645. ipts = AV_NOPTS_VALUE;
  646. if (output_picture(is, &pict, pts) < 0)
  647. goto the_end;
  648. }
  649. ptr += len1;
  650. len -= len1;
  651. }
  652. }
  653. av_free_packet(pkt);
  654. }
  655. the_end:
  656. return 0;
  657. }
  658. /* copy samples for viewing in editor window */
  659. static void update_sample_display(VideoState *is, short *samples, int samples_size)
  660. {
  661. int size, len, channels;
  662. channels = is->audio_st->codec.channels;
  663. size = samples_size / sizeof(short);
  664. while (size > 0) {
  665. len = SAMPLE_ARRAY_SIZE - is->sample_array_index;
  666. if (len > size)
  667. len = size;
  668. memcpy(is->sample_array + is->sample_array_index, samples, len * sizeof(short));
  669. samples += len;
  670. is->sample_array_index += len;
  671. if (is->sample_array_index >= SAMPLE_ARRAY_SIZE)
  672. is->sample_array_index = 0;
  673. size -= len;
  674. }
  675. }
  676. /* maximum audio speed change to get correct sync */
  677. #define SAMPLE_CORRECTION_PERCENT_MAX 2
  678. /* return the new audio buffer size (samples can be added or deleted
  679. to get better sync if video or external master clock) */
  680. static int synchronize_audio(VideoState *is, short *samples,
  681. int samples_size, double pts)
  682. {
  683. int n, delay;
  684. double ref_clock;
  685. n = 2 * is->audio_st->codec.channels;
  686. if (is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK)
  687. ref_clock = is->external_clock;
  688. else if (is->av_sync_type == AV_SYNC_VIDEO_MASTER && is->video_st)
  689. ref_clock = is->video_clock;
  690. else
  691. ref_clock = is->audio_clock;
  692. /* if not master, then we try to remove or add samples to correct the clock */
  693. if (((is->av_sync_type == AV_SYNC_VIDEO_MASTER && is->video_st) ||
  694. is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK) && pts != 0) {
  695. double diff;
  696. int wanted_size, min_size, max_size, nb_samples;
  697. delay = audio_write_get_buf_size(is);
  698. diff = pts - (double)delay / (double)(n * is->audio_st->codec.sample_rate) - ref_clock;
  699. wanted_size = (int)(diff * is->audio_st->codec.sample_rate) * n;
  700. nb_samples = samples_size / n;
  701. min_size = ((nb_samples * (100 - SAMPLE_CORRECTION_PERCENT_MAX)) / 100) * n;
  702. max_size = ((nb_samples * (100 + SAMPLE_CORRECTION_PERCENT_MAX)) / 100) * n;
  703. if (wanted_size < min_size)
  704. wanted_size = min_size;
  705. else if (wanted_size > max_size)
  706. wanted_size = max_size;
  707. /* do the correct */
  708. /* XXX: do it better with sample interpolation */
  709. if (wanted_size < samples_size) {
  710. /* remove samples */
  711. samples_size = wanted_size;
  712. } else if (wanted_size > samples_size) {
  713. uint8_t *samples_end, *q;
  714. int nb;
  715. /* add samples */
  716. nb = (samples_size - wanted_size);
  717. samples_end = (uint8_t *)samples + samples_size - n;
  718. q = samples_end + n;
  719. while (nb > 0) {
  720. memcpy(q, samples_end, n);
  721. q += n;
  722. nb -= n;
  723. }
  724. samples_size = wanted_size;
  725. }
  726. }
  727. /* update audio clock */
  728. if (is->av_sync_type == AV_SYNC_AUDIO_MASTER && pts != 0) {
  729. /* a pts is given: we update the audio clock precisely */
  730. delay = audio_write_get_buf_size(is);
  731. is->audio_clock = pts - (double)delay / (double)(n * is->audio_st->codec.sample_rate);
  732. } else {
  733. is->audio_clock += (double)samples_size / (double)(n * is->audio_st->codec.sample_rate);
  734. }
  735. return samples_size;
  736. }
  737. /* decode one audio frame and returns its uncompressed size */
  738. static int audio_decode_frame(VideoState *is, uint8_t *audio_buf, double *pts_ptr)
  739. {
  740. AVPacket *pkt = &is->audio_pkt;
  741. int len1, data_size;
  742. double pts;
  743. for(;;) {
  744. if (is->paused || is->audioq.abort_request) {
  745. return -1;
  746. }
  747. while (is->audio_pkt_size > 0) {
  748. len1 = avcodec_decode_audio(&is->audio_st->codec,
  749. (int16_t *)audio_buf, &data_size,
  750. is->audio_pkt_data, is->audio_pkt_size);
  751. if (len1 < 0)
  752. break;
  753. is->audio_pkt_data += len1;
  754. is->audio_pkt_size -= len1;
  755. if (data_size > 0) {
  756. pts = 0;
  757. if (is->audio_pkt_ipts != AV_NOPTS_VALUE)
  758. pts = (double)is->audio_pkt_ipts * is->ic->pts_num / is->ic->pts_den;
  759. *pts_ptr = pts;
  760. is->audio_pkt_ipts = AV_NOPTS_VALUE;
  761. /* we got samples : we can exit now */
  762. return data_size;
  763. }
  764. }
  765. /* free previous packet if any */
  766. if (pkt->destruct)
  767. av_free_packet(pkt);
  768. /* read next packet */
  769. if (packet_queue_get(&is->audioq, pkt, 1) < 0)
  770. return -1;
  771. is->audio_pkt_data = pkt->data;
  772. is->audio_pkt_size = pkt->size;
  773. is->audio_pkt_ipts = pkt->pts;
  774. }
  775. }
  776. int audio_write_get_buf_size(VideoState *is)
  777. {
  778. int delay;
  779. delay = is->audio_hw_buf_size;
  780. #if 0
  781. /* just a test to check if the estimated delay is OK */
  782. {
  783. int val;
  784. if (ioctl(sdl_audio_fd, SNDCTL_DSP_GETODELAY, &val) < 0)
  785. perror("SNDCTL_DSP_GETODELAY");
  786. printf("real_delay=%d delay=%d\n", val, delay);
  787. }
  788. #endif
  789. return delay;
  790. }
  791. /* prepare a new audio buffer */
  792. void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
  793. {
  794. VideoState *is = opaque;
  795. int audio_size, len1;
  796. double pts;
  797. audio_callback_time = av_gettime();
  798. while (len > 0) {
  799. if (is->audio_buf_index >= is->audio_buf_size) {
  800. audio_size = audio_decode_frame(is, is->audio_buf, &pts);
  801. if (audio_size < 0) {
  802. /* if error, just output silence */
  803. is->audio_buf_size = 1024;
  804. memset(is->audio_buf, 0, is->audio_buf_size);
  805. } else {
  806. if (is->show_audio)
  807. update_sample_display(is, (int16_t *)is->audio_buf, audio_size);
  808. audio_size = synchronize_audio(is, (int16_t *)is->audio_buf, audio_size,
  809. pts);
  810. is->audio_buf_size = audio_size;
  811. }
  812. is->audio_buf_index = 0;
  813. }
  814. len1 = is->audio_buf_size - is->audio_buf_index;
  815. if (len1 > len)
  816. len1 = len;
  817. memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1);
  818. len -= len1;
  819. stream += len1;
  820. is->audio_buf_index += len1;
  821. }
  822. }
  823. /* open a given stream. Return 0 if OK */
  824. static int stream_component_open(VideoState *is, int stream_index)
  825. {
  826. AVFormatContext *ic = is->ic;
  827. AVCodecContext *enc;
  828. AVCodec *codec;
  829. SDL_AudioSpec wanted_spec, spec;
  830. if (stream_index < 0 || stream_index >= ic->nb_streams)
  831. return -1;
  832. enc = &ic->streams[stream_index]->codec;
  833. /* prepare audio output */
  834. if (enc->codec_type == CODEC_TYPE_AUDIO) {
  835. wanted_spec.freq = enc->sample_rate;
  836. wanted_spec.format = AUDIO_S16SYS;
  837. wanted_spec.channels = enc->channels;
  838. wanted_spec.silence = 0;
  839. wanted_spec.samples = 8192;
  840. wanted_spec.callback = sdl_audio_callback;
  841. wanted_spec.userdata = is;
  842. if (SDL_OpenAudio(&wanted_spec, &spec) < 0)
  843. return -1;
  844. is->audio_hw_buf_size = spec.size;
  845. }
  846. codec = avcodec_find_decoder(enc->codec_id);
  847. if (!codec ||
  848. avcodec_open(enc, codec) < 0)
  849. return -1;
  850. switch(enc->codec_type) {
  851. case CODEC_TYPE_AUDIO:
  852. is->audio_stream = stream_index;
  853. is->audio_st = ic->streams[stream_index];
  854. is->audio_buf_size = 0;
  855. is->audio_buf_index = 0;
  856. is->audio_pkt_size = 0;
  857. memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
  858. packet_queue_init(&is->audioq);
  859. SDL_PauseAudio(0);
  860. break;
  861. case CODEC_TYPE_VIDEO:
  862. is->video_stream = stream_index;
  863. is->video_st = ic->streams[stream_index];
  864. packet_queue_init(&is->videoq);
  865. is->video_tid = SDL_CreateThread(video_thread, is);
  866. break;
  867. default:
  868. break;
  869. }
  870. return 0;
  871. }
  872. static void stream_component_close(VideoState *is, int stream_index)
  873. {
  874. AVFormatContext *ic = is->ic;
  875. AVCodecContext *enc;
  876. enc = &ic->streams[stream_index]->codec;
  877. switch(enc->codec_type) {
  878. case CODEC_TYPE_AUDIO:
  879. packet_queue_abort(&is->audioq);
  880. SDL_CloseAudio();
  881. packet_queue_end(&is->audioq);
  882. break;
  883. case CODEC_TYPE_VIDEO:
  884. packet_queue_abort(&is->videoq);
  885. /* note: we also signal this mutex to make sure we deblock the
  886. video thread in all cases */
  887. SDL_LockMutex(is->pictq_mutex);
  888. SDL_CondSignal(is->pictq_cond);
  889. SDL_UnlockMutex(is->pictq_mutex);
  890. SDL_WaitThread(is->video_tid, NULL);
  891. packet_queue_end(&is->videoq);
  892. break;
  893. default:
  894. break;
  895. }
  896. avcodec_close(enc);
  897. switch(enc->codec_type) {
  898. case CODEC_TYPE_AUDIO:
  899. is->audio_st = NULL;
  900. is->audio_stream = -1;
  901. break;
  902. case CODEC_TYPE_VIDEO:
  903. is->video_st = NULL;
  904. is->video_stream = -1;
  905. break;
  906. default:
  907. break;
  908. }
  909. }
  910. /* since we have only one decoding thread, we can use a global
  911. variable instead of a thread local variable */
  912. static VideoState *global_video_state;
  913. static int decode_interrupt_cb(void)
  914. {
  915. return (global_video_state && global_video_state->abort_request);
  916. }
  917. /* this thread gets the stream from the disk or the network */
  918. static int decode_thread(void *arg)
  919. {
  920. VideoState *is = arg;
  921. AVFormatContext *ic;
  922. int err, i, ret, video_index, audio_index;
  923. AVPacket pkt1, *pkt = &pkt1;
  924. video_index = -1;
  925. audio_index = -1;
  926. is->video_stream = -1;
  927. is->audio_stream = -1;
  928. global_video_state = is;
  929. url_set_interrupt_cb(decode_interrupt_cb);
  930. err = av_open_input_file(&ic, is->filename, NULL, 0, NULL);
  931. if (err < 0)
  932. return 0;
  933. is->ic = ic;
  934. err = av_find_stream_info(ic);
  935. if (err < 0)
  936. goto fail;
  937. for(i = 0; i < ic->nb_streams; i++) {
  938. AVCodecContext *enc = &ic->streams[i]->codec;
  939. switch(enc->codec_type) {
  940. case CODEC_TYPE_AUDIO:
  941. if (audio_index < 0 && !audio_disable)
  942. audio_index = i;
  943. break;
  944. case CODEC_TYPE_VIDEO:
  945. if (video_index < 0 && !video_disable)
  946. video_index = i;
  947. break;
  948. default:
  949. break;
  950. }
  951. }
  952. if (show_status) {
  953. dump_format(ic, 0, is->filename, 0);
  954. }
  955. /* open the streams */
  956. if (audio_index >= 0) {
  957. stream_component_open(is, audio_index);
  958. }
  959. if (video_index >= 0) {
  960. stream_component_open(is, video_index);
  961. } else {
  962. if (!display_disable)
  963. is->show_audio = 1;
  964. }
  965. if (is->video_stream < 0 && is->audio_stream < 0) {
  966. goto fail;
  967. }
  968. for(;;) {
  969. if (is->abort_request)
  970. break;
  971. if (is->paused != is->last_paused) {
  972. is->last_paused = is->paused;
  973. if (ic->iformat == &rtsp_demux) {
  974. if (is->paused)
  975. rtsp_pause(ic);
  976. else
  977. rtsp_resume(ic);
  978. }
  979. }
  980. if (is->paused && ic->iformat == &rtsp_demux) {
  981. /* wait 10 ms to avoid trying to get another packet */
  982. /* XXX: horrible */
  983. SDL_Delay(10);
  984. continue;
  985. }
  986. /* if the queue are full, no need to read more */
  987. if (is->audioq.size > MAX_AUDIOQ_SIZE ||
  988. is->videoq.size > MAX_VIDEOQ_SIZE) {
  989. /* wait 10 ms */
  990. SDL_Delay(10);
  991. continue;
  992. }
  993. ret = av_read_packet(ic, pkt);
  994. if (ret < 0) {
  995. break;
  996. }
  997. if (pkt->stream_index == is->audio_stream) {
  998. packet_queue_put(&is->audioq, pkt);
  999. } else if (pkt->stream_index == is->video_stream) {
  1000. packet_queue_put(&is->videoq, pkt);
  1001. } else {
  1002. av_free_packet(pkt);
  1003. }
  1004. }
  1005. /* wait until the end */
  1006. while (!is->abort_request) {
  1007. SDL_Delay(100);
  1008. }
  1009. fail:
  1010. /* disable interrupting */
  1011. global_video_state = NULL;
  1012. /* close each stream */
  1013. if (is->audio_stream >= 0)
  1014. stream_component_close(is, is->audio_stream);
  1015. if (is->video_stream >= 0)
  1016. stream_component_close(is, is->video_stream);
  1017. av_close_input_file(is->ic);
  1018. is->ic = NULL; /* safety */
  1019. url_set_interrupt_cb(NULL);
  1020. return 0;
  1021. }
  1022. /* pause or resume the video */
  1023. static void stream_pause(VideoState *is)
  1024. {
  1025. is->paused = !is->paused;
  1026. }
  1027. static VideoState *stream_open(const char *filename)
  1028. {
  1029. VideoState *is;
  1030. is = av_mallocz(sizeof(VideoState));
  1031. if (!is)
  1032. return NULL;
  1033. pstrcpy(is->filename, sizeof(is->filename), filename);
  1034. if (screen) {
  1035. is->width = screen->w;
  1036. is->height = screen->h;
  1037. }
  1038. is->ytop = 0;
  1039. is->xleft = 0;
  1040. /* start video display */
  1041. is->pictq_mutex = SDL_CreateMutex();
  1042. is->pictq_cond = SDL_CreateCond();
  1043. /* add the refresh timer to draw the picture */
  1044. schedule_refresh(is, 40);
  1045. is->av_sync_type = AV_SYNC_AUDIO_MASTER;
  1046. is->parse_tid = SDL_CreateThread(decode_thread, is);
  1047. if (!is->parse_tid) {
  1048. av_free(is);
  1049. return NULL;
  1050. }
  1051. return is;
  1052. }
  1053. static void stream_close(VideoState *is)
  1054. {
  1055. VideoPicture *vp;
  1056. int i;
  1057. /* XXX: use a special url_shutdown call to abort parse cleanly */
  1058. is->abort_request = 1;
  1059. SDL_WaitThread(is->parse_tid, NULL);
  1060. /* free all pictures */
  1061. for(i=0;i<VIDEO_PICTURE_QUEUE_SIZE; i++) {
  1062. vp = &is->pictq[i];
  1063. if (vp->bmp) {
  1064. SDL_FreeYUVOverlay(vp->bmp);
  1065. vp->bmp = NULL;
  1066. }
  1067. }
  1068. SDL_DestroyMutex(is->pictq_mutex);
  1069. SDL_DestroyCond(is->pictq_cond);
  1070. }
  1071. void toggle_full_screen(void)
  1072. {
  1073. int w, h, flags;
  1074. is_full_screen = !is_full_screen;
  1075. if (!fs_screen_width) {
  1076. /* use default SDL method */
  1077. SDL_WM_ToggleFullScreen(screen);
  1078. } else {
  1079. /* use the recorded resolution */
  1080. flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
  1081. if (is_full_screen) {
  1082. w = fs_screen_width;
  1083. h = fs_screen_height;
  1084. flags |= SDL_FULLSCREEN;
  1085. } else {
  1086. w = screen_width;
  1087. h = screen_height;
  1088. flags |= SDL_RESIZABLE;
  1089. }
  1090. screen = SDL_SetVideoMode(w, h, 0, flags);
  1091. cur_stream->width = w;
  1092. cur_stream->height = h;
  1093. }
  1094. }
  1095. void toggle_pause(void)
  1096. {
  1097. if (cur_stream)
  1098. stream_pause(cur_stream);
  1099. }
  1100. void do_exit(void)
  1101. {
  1102. if (cur_stream) {
  1103. stream_close(cur_stream);
  1104. cur_stream = NULL;
  1105. }
  1106. if (show_status)
  1107. printf("\n");
  1108. SDL_Quit();
  1109. exit(0);
  1110. }
  1111. void toggle_audio_display(void)
  1112. {
  1113. if (cur_stream) {
  1114. cur_stream->show_audio = !cur_stream->show_audio;
  1115. }
  1116. }
  1117. /* handle an event sent by the GUI */
  1118. void event_loop(void)
  1119. {
  1120. SDL_Event event;
  1121. for(;;) {
  1122. SDL_WaitEvent(&event);
  1123. switch(event.type) {
  1124. case SDL_KEYDOWN:
  1125. switch(event.key.keysym.sym) {
  1126. case SDLK_ESCAPE:
  1127. case SDLK_q:
  1128. do_exit();
  1129. break;
  1130. case SDLK_f:
  1131. toggle_full_screen();
  1132. break;
  1133. case SDLK_p:
  1134. case SDLK_SPACE:
  1135. toggle_pause();
  1136. break;
  1137. case SDLK_a:
  1138. toggle_audio_display();
  1139. break;
  1140. default:
  1141. break;
  1142. }
  1143. break;
  1144. case SDL_VIDEORESIZE:
  1145. if (cur_stream) {
  1146. screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0,
  1147. SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL);
  1148. cur_stream->width = event.resize.w;
  1149. cur_stream->height = event.resize.h;
  1150. }
  1151. break;
  1152. case SDL_QUIT:
  1153. do_exit();
  1154. break;
  1155. case FF_ALLOC_EVENT:
  1156. alloc_picture(event.user.data1);
  1157. break;
  1158. case FF_REFRESH_EVENT:
  1159. video_refresh_timer(event.user.data1);
  1160. break;
  1161. default:
  1162. break;
  1163. }
  1164. }
  1165. }
  1166. void opt_width(const char *arg)
  1167. {
  1168. screen_width = atoi(arg);
  1169. }
  1170. void opt_height(const char *arg)
  1171. {
  1172. screen_height = atoi(arg);
  1173. }
  1174. static void opt_format(const char *arg)
  1175. {
  1176. file_iformat = av_find_input_format(arg);
  1177. if (!file_iformat) {
  1178. fprintf(stderr, "Unknown input format: %s\n", arg);
  1179. exit(1);
  1180. }
  1181. }
  1182. void opt_rtp_tcp(void)
  1183. {
  1184. /* only tcp protocol */
  1185. rtsp_default_protocols = (1 << RTSP_PROTOCOL_RTP_TCP);
  1186. }
  1187. const OptionDef options[] = {
  1188. { "h", 0, {(void*)show_help}, "show help" },
  1189. { "x", HAS_ARG, {(void*)opt_width}, "force displayed width", "width" },
  1190. { "y", HAS_ARG, {(void*)opt_height}, "force displayed height", "height" },
  1191. { "an", OPT_BOOL, {(void*)&audio_disable}, "disable audio" },
  1192. { "vn", OPT_BOOL, {(void*)&video_disable}, "disable video" },
  1193. { "nodisp", OPT_BOOL, {(void*)&display_disable}, "disable graphical display" },
  1194. { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
  1195. { "stats", OPT_BOOL | OPT_EXPERT, {(void*)&show_status}, "show status", "" },
  1196. { "rtp_tcp", OPT_EXPERT, {(void*)&opt_rtp_tcp}, "force RTP/TCP protocol usage", "" },
  1197. { NULL, },
  1198. };
  1199. void show_help(void)
  1200. {
  1201. printf("usage: ffplay [options] input_file\n"
  1202. "Simple media player\n");
  1203. printf("\n");
  1204. show_help_options(options);
  1205. printf("\nWhile playing:\n"
  1206. "q, ESC quit\n"
  1207. "f toggle full screen\n"
  1208. "p, SPC pause\n"
  1209. "a show audio waves\n"
  1210. );
  1211. exit(1);
  1212. }
  1213. void parse_arg_file(const char *filename)
  1214. {
  1215. input_filename = filename;
  1216. }
  1217. /* Called from the main */
  1218. int main(int argc, char **argv)
  1219. {
  1220. int flags;
  1221. /* register all codecs, demux and protocols */
  1222. av_register_all();
  1223. parse_options(argc, argv, options);
  1224. if (!input_filename)
  1225. show_help();
  1226. if (display_disable) {
  1227. video_disable = 1;
  1228. }
  1229. flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
  1230. #ifndef CONFIG_WIN32
  1231. flags |= SDL_INIT_EVENTTHREAD; /* Not supported on win32 */
  1232. #endif
  1233. if (SDL_Init (flags)) {
  1234. fprintf(stderr, "Could not initialize SDL - exiting\n");
  1235. exit(1);
  1236. }
  1237. if (!display_disable) {
  1238. screen = SDL_SetVideoMode(screen_width, screen_height, 0,
  1239. SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL);
  1240. if (!screen) {
  1241. fprintf(stderr, "SDL: could not set video mode - exiting\n");
  1242. exit(1);
  1243. }
  1244. SDL_WM_SetCaption("FFplay", "FFplay");
  1245. #ifdef HAVE_X11
  1246. /* save the screen resolution... SDL should allow full screen
  1247. by resizing the window */
  1248. {
  1249. Display *dpy;
  1250. dpy = XOpenDisplay(NULL);
  1251. if (dpy) {
  1252. fs_screen_width = DisplayWidth(dpy, DefaultScreen(dpy));
  1253. fs_screen_height = DisplayHeight(dpy, DefaultScreen(dpy));
  1254. XCloseDisplay(dpy);
  1255. }
  1256. }
  1257. #endif
  1258. }
  1259. SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
  1260. SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
  1261. SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
  1262. SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
  1263. cur_stream = stream_open(input_filename);
  1264. event_loop();
  1265. /* never returns */
  1266. return 0;
  1267. }