Subversion Repositories Kolibri OS

Rev

Rev 6438 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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