Subversion Repositories Kolibri OS

Rev

Rev 6438 | 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 decoder
  114. {
  115.     const char     *name;
  116.     enum AVCodecID  codec_id;
  117.     int             profile;
  118.     enum AVPixelFormat pix_fmt;
  119.     int             width;
  120.     int             height;
  121.     AVFrame        *Frame;
  122.     vframe_t       *active_frame;
  123.     vframe_t        vframes[16];
  124.     int             nframes;
  125.     int             is_hw:1;
  126.     int             has_surfaces:1;
  127.     int             frame_reorder:1;
  128.     void          (*fini)(vst_t *vst);
  129. };
  130.  
  131. typedef struct decoder* decoder_init_fn(vst_t *vst);
  132. struct decoder* init_va_decoder(vst_t *vst);
  133.  
  134. struct vstate
  135. {
  136.     AVFormatContext *fCtx;              /* format context           */
  137.     AVCodecContext  *vCtx;              /* video decoder context    */
  138.     AVCodecContext  *aCtx;              /* audio decoder context    */
  139.     AVCodec         *vCodec;            /* video codec              */
  140.     AVCodec         *aCodec;            /* audio codec              */
  141.     char            *input_file;
  142.     char            *input_name;
  143.     int             vStream;            /* video stream index       */
  144.     int             aStream;            /* audio stream index       */
  145.     AVRational      video_time_base;
  146.     double          audio_timer_base;
  147.  
  148.     queue_t         q_video;            /* video packets queue      */
  149.     queue_t         q_audio;            /* audio packets queue      */
  150.  
  151.     mutex_t         gpu_lock;           /* gpu access lock. libdrm not yet thread safe :( */
  152.     mutex_t         decoder_lock;
  153.  
  154.     mutex_t         input_lock;
  155.     mutex_t         output_lock;
  156.     struct list_head input_list;
  157.     struct list_head output_list;
  158.     struct list_head destructor_list;
  159.  
  160.     struct decoder *decoder;
  161.     int             snd_format;
  162.     volatile int    frames_count;
  163.     unsigned int    has_sound:1;
  164.     unsigned int    audio_timer_valid:1;
  165.     unsigned int    blit_bitmap:1;      /* hardware RGBA blitter    */
  166.     unsigned int    blit_texture:1;     /* hardware RGBA blit and scale */
  167.     unsigned int    blit_planar:1;      /* hardbare YUV blit and scale */
  168. };
  169.  
  170.  
  171. #define DECODER_THREAD  1
  172. #define AUDIO_THREAD    2
  173. #define VIDEO_THREAD    4
  174.  
  175. extern volatile int threads_running;
  176. extern astream_t astream;
  177.  
  178. render_t *create_render(vst_t *vst, window_t *win, uint32_t flags);
  179. void destroy_render(render_t *render);
  180. int init_render(render_t *render, int width, int height);
  181. void render_adjust_size(render_t *render, window_t *win);
  182. void render_set_size(render_t *render, int width, int height);
  183. void render_draw_client(render_t *render);
  184.  
  185. int fplay_init_context(vst_t *vst);
  186.  
  187. int init_audio(vst_t* vst);
  188. int audio_thread(void *param);
  189. void set_audio_volume(int left, int right);
  190.  
  191. int video_thread(void *param);
  192. void flush_video(vst_t* vst);
  193.  
  194. int init_video_decoder(vst_t *vst);
  195. void fini_video_decoder(vst_t *vst);
  196. void decoder(vst_t *vst);
  197. int decode_video(vst_t* vst);
  198. int decode_audio(AVCodecContext  *ctx, queue_t *qa);
  199.  
  200. double get_master_clock(void);
  201.  
  202. static inline void GetNotify(void *event)
  203. {
  204.     __asm__ __volatile__ (
  205.     "int $0x40"
  206.     ::"a"(68),"b"(14),"c"(event));
  207. }
  208.  
  209. static inline double get_audio_base(vst_t* vst)
  210. {
  211.     return (double)av_q2d(vst->fCtx->streams[vst->aStream]->time_base)*1000;
  212. };
  213.  
  214. struct decoder* va_init_decoder(vst_t *vst);
  215. void va_create_planar(vst_t *vst, vframe_t *vframe);
  216.  
  217. int init_fontlib();
  218. char *get_moviefile();
  219.  
  220. #define ENTER()   printf("enter %s\n",__FUNCTION__)
  221. #define LEAVE()   printf("leave %s\n",__FUNCTION__)
  222. #define FAIL()    printf("fail %s\n",__FUNCTION__)
  223.  
  224.  
  225.