Subversion Repositories Kolibri OS

Rev

Rev 6135 | Rev 6301 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1.  
  2. #include <libsync.h>
  3. #include <pixlib3.h>
  4. #include "list.h"
  5.  
  6. #define BLACK_MAGIC_SOUND
  7. #define BLACK_MAGIC_VIDEO
  8.  
  9. typedef unsigned int color_t;
  10. typedef unsigned int count_t;
  11.  
  12. typedef struct render  render_t;
  13. typedef struct vstate vst_t;
  14.  
  15. #define HAS_LEFT        (1<<0)
  16. #define HAS_TOP         (1<<1)
  17. #define HAS_RIGHT       (1<<2)
  18. #define HAS_BOTTOM      (1<<3)
  19.  
  20. typedef struct
  21. {
  22.     struct list_head list;
  23.     enum AVPixelFormat format;
  24.     AVPicture     picture;
  25.     planar_t*     planar;
  26.     int           is_hw_pic;
  27.     int           index;
  28.     double        pts;
  29.     double        pkt_pts;
  30.     volatile int  ready;
  31. }vframe_t;
  32.  
  33. struct render
  34. {
  35.     vst_t     *vst;
  36.     uint32_t   caps;
  37.     uint32_t   ctx_width;
  38.     uint32_t   ctx_height;
  39.     uint32_t   win_width;
  40.     uint32_t   win_height;
  41.  
  42.     rect_t     rc_client;
  43.     rect_t     rcvideo;
  44.     rect_t     rcleft;
  45.     rect_t     rctop;
  46.     rect_t     rcright;
  47.     rect_t     rcbottom;
  48.  
  49.     uint32_t   layout;
  50.     bitmap_t  *bitmap[4];
  51.     bitmap_t  *last_bitmap;
  52.  
  53.     uint32_t   ctx_format;
  54.     int        target;
  55.  
  56.     window_t   *win;
  57.     enum{
  58.       EMPTY, INIT }state;
  59.     enum win_state win_state;
  60.  
  61.     void (*draw)(render_t *render, vframe_t *vframe);
  62. };
  63.  
  64. enum player_state
  65. {
  66.     CLOSED = 0,
  67.     PREPARE,
  68.     STOP,
  69.     PAUSE,
  70.     PLAY,
  71.     REWIND,
  72.     PLAY_2_STOP,
  73.     PLAY_2_PAUSE,
  74.     PAUSE_2_PLAY,
  75.     REWIND_2_PLAY,
  76. };
  77.  
  78. #define ID_PLAY             100
  79. #define ID_STOP             101
  80. #define ID_PROGRESS         102
  81. #define ID_VOL_LEVEL        103
  82. #define ID_VOL_CTRL         104
  83.  
  84. typedef struct
  85. {
  86.     mutex_t lock;
  87.     char    *buffer;
  88.     int     count;
  89. }astream_t;
  90.  
  91. typedef struct
  92. {
  93.   unsigned int  code;
  94.   unsigned int  sender;
  95.   unsigned int  stream;
  96.   unsigned int  offset;
  97.   unsigned int  size;
  98.   unsigned int  unused[2];
  99. }SND_EVENT;
  100.  
  101.  
  102. typedef struct {
  103.     AVPacketList *first_pkt;
  104.     AVPacketList *last_pkt;
  105.     int size;
  106.     int count;
  107.     mutex_t       lock;
  108. } queue_t;
  109.  
  110. int put_packet(queue_t *q, AVPacket *pkt);
  111. int get_packet(queue_t *q, AVPacket *pkt);
  112.  
  113. struct vstate
  114. {
  115.     AVFormatContext *fCtx;              /* format context           */
  116.     AVCodecContext  *vCtx;              /* video decoder context    */
  117.     AVCodecContext  *aCtx;              /* audio decoder context    */
  118.     AVCodec         *vCodec;            /* video codec              */
  119.     AVCodec         *aCodec;            /* audio codec              */
  120.     char            *input_file;
  121.     char            *input_name;
  122.     int             vStream;            /* video stream index       */
  123.     int             aStream;            /* audio stream index       */
  124.     AVRational      video_time_base;
  125.     AVRational      audio_time_base;
  126.  
  127.     queue_t         q_video;            /* video packets queue      */
  128.     queue_t         q_audio;            /* audio packets queue      */
  129.  
  130.     mutex_t         gpu_lock;           /* gpu access lock. libdrm not yet thread safe :( */
  131.     mutex_t         decoder_lock;
  132.  
  133.     mutex_t         input_lock;
  134.     mutex_t         output_lock;
  135.     struct list_head input_list;
  136.     struct list_head output_list;
  137.  
  138.     AVFrame        *Frame;
  139.  
  140.     vframe_t       *decoder_frame;
  141.     volatile int    frames_count;
  142.     void           *hwCtx;              /* hardware context         */
  143.     int             hwdec:1;            /* hardware decoder         */
  144.     int             blit_bitmap:1;      /* hardware RGBA blitter    */
  145.     int             blit_texture:1;     /* hardware RGBA blit and scale */
  146.     int             blit_planar:1;      /* hardbare YUV blit and scale */
  147.     int             frame_reorder:1;
  148.     int             nframes;
  149.     vframe_t        vframes[16];
  150. };
  151.  
  152.  
  153. #define DECODER_THREAD  1
  154. #define AUDIO_THREAD    2
  155. #define VIDEO_THREAD    4
  156.  
  157. extern int threads_running;
  158. extern astream_t astream;
  159.  
  160. render_t *create_render(vst_t *vst, window_t *win, uint32_t flags);
  161. void destroy_render(render_t *render);
  162. int init_render(render_t *render, int width, int height);
  163. void render_adjust_size(render_t *render, window_t *win);
  164. void render_set_size(render_t *render, int width, int height);
  165. void render_draw_client(render_t *render);
  166.  
  167. int fplay_init_context(vst_t *vst);
  168.  
  169. int init_audio(int format);
  170. int audio_thread(void *param);
  171. void set_audio_volume(int left, int right);
  172.  
  173. int video_thread(void *param);
  174. void flush_video(vst_t* vst);
  175.  
  176. void decoder(vst_t *vst);
  177. int decode_video(vst_t* vst);
  178. int decode_audio(AVCodecContext  *ctx, queue_t *qa);
  179.  
  180. double get_master_clock(void);
  181.  
  182. static inline void GetNotify(void *event)
  183. {
  184.     __asm__ __volatile__ (
  185.     "int $0x40"
  186.     ::"a"(68),"b"(14),"c"(event));
  187. }
  188.  
  189. static inline double get_audio_base(vst_t* vst)
  190. {
  191.     return (double)av_q2d(vst->fCtx->streams[vst->aStream]->time_base)*1000;
  192. };
  193.  
  194. void va_create_planar(vst_t *vst, vframe_t *vframe);
  195.  
  196. int init_fontlib();
  197. char *get_moviefile();
  198.  
  199.