ffmovie.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include <SDL.h>
  2. #include <SDL_thread.h>
  3. #include <ffmpeg/avformat.h>
  4. #define MAX_SOURCENAME 1024
  5. #define MAX_AUDIOQ_SIZE (5 * 16 * 1024)
  6. /* SDL audio buffer size, in samples. Should be small to have precise
  7. A/V sync as SDL does not have hardware buffer fullness info. */
  8. #define SDL_AUDIO_BUFFER_SIZE 1024
  9. /* no AV sync correction is done if below the AV sync threshold */
  10. #define AV_SYNC_THRESHOLD 0.08
  11. /* no AV correction is done if too big error */
  12. #define AV_NOSYNC_THRESHOLD 10.0
  13. /* maximum audio speed change to get correct sync */
  14. #define SAMPLE_CORRECTION_PERCENT_MAX 10
  15. /* we use about AUDIO_DIFF_AVG_NB A-V differences to make the average */
  16. #define AUDIO_DIFF_AVG_NB 20
  17. /* NOTE: the size must be big enough to compensate the hardware audio buffersize size */
  18. #define SAMPLE_ARRAY_SIZE (2*65536)
  19. typedef struct PacketQueue {
  20. AVPacketList *first_pkt, *last_pkt;
  21. int nb_packets;
  22. int size;
  23. int abort_request;
  24. SDL_mutex *mutex;
  25. SDL_cond *cond;
  26. } PacketQueue;
  27. typedef struct FFMovie {
  28. SDL_Thread *decode_thread;
  29. int abort_request;
  30. int paused;
  31. AVFormatContext *context;
  32. double external_clock; /* external clock base */
  33. int64_t external_clock_time;
  34. double audio_clock;
  35. double audio_diff_cum; /* used for AV difference average computation */
  36. double audio_diff_avg_coef;
  37. double audio_diff_threshold;
  38. int audio_diff_avg_count;
  39. AVStream *audio_st;
  40. PacketQueue audioq;
  41. int audio_hw_buf_size;
  42. /* samples output by the codec. we reserve more space for avsync compensation */
  43. uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
  44. int audio_buf_size; /* in bytes */
  45. int audio_buf_index; /* in bytes */
  46. AVPacket audio_pkt;
  47. uint8_t *audio_pkt_data;
  48. int audio_pkt_size;
  49. int64_t audio_pkt_ipts;
  50. int audio_volume; /*must self implement*/
  51. int16_t sample_array[SAMPLE_ARRAY_SIZE];
  52. int sample_array_index;
  53. int frame_count;
  54. double frame_timer;
  55. double frame_last_pts;
  56. double frame_last_delay;
  57. double frame_delay; /*display time of each frame, based on fps*/
  58. double video_clock; /*seconds of video frame decoded*/
  59. AVStream *video_st;
  60. int64_t vidpkt_timestamp;
  61. int vidpkt_start;
  62. double video_last_P_pts; /* pts of the last P picture (needed if B
  63. frames are present) */
  64. double video_current_pts; /* current displayed pts (different from
  65. video_clock if frame fifos are used) */
  66. SDL_mutex *dest_mutex;
  67. double dest_showtime; /*when to next show the dest_overlay*/
  68. SDL_Overlay *dest_overlay;
  69. SDL_Surface *dest_surface;
  70. SDL_Rect dest_rect;
  71. double time_offset; /*track paused time*/
  72. int audio_disable;
  73. const char *sourcename;
  74. } FFMovie;
  75. FFMovie *ffmovie_open(const char *filename);
  76. FFMovie *ffmovie_reopen(FFMovie *movie);
  77. void ffmovie_close(FFMovie *movie);
  78. void ffmovie_play(FFMovie *movie);
  79. void ffmovie_stop(FFMovie *movie);
  80. void ffmovie_pause(FFMovie *movie);
  81. void ffmovie_setvolume(FFMovie *movie, int volume);
  82. void ffmovie_setdisplay(FFMovie *movie, SDL_Surface *dest, SDL_Rect *rect);
  83. void ffmovie_abortall(void);