Subversion Repositories Kolibri OS

Rev

Rev 6301 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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