git-svn-id: svn://kolibrios.org@2415 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2012-02-28 08:45:00 +00:00
parent 0735fd9e1b
commit 0f5cbca619
7 changed files with 608 additions and 204 deletions

View File

@ -6,6 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <winlib.h>
#include "sound.h" #include "sound.h"
#include "fplay.h" #include "fplay.h"
@ -78,8 +79,6 @@ int decode_audio(AVCodecContext *ctx, queue_t *qa)
AVPacket pkt; AVPacket pkt;
AVPacket pkt_tmp; AVPacket pkt_tmp;
uint8_t *audio_data;
int audio_size;
int len; int len;
int data_size=0; int data_size=0;

View File

@ -10,6 +10,7 @@
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <ctype.h> #include <ctype.h>
#include <winlib.h>
#include "sound.h" #include "sound.h"
#include "fplay.h" #include "fplay.h"
@ -51,6 +52,8 @@ int main( int argc, char *argv[])
movie_file = argv[1]; movie_file = argv[1];
/* register all codecs, demux and protocols */ /* register all codecs, demux and protocols */
// av_log_set_level(AV_LOG_INFO);
avcodec_register_all(); avcodec_register_all();
avdevice_register_all(); avdevice_register_all();
av_register_all(); av_register_all();
@ -61,7 +64,7 @@ int main( int argc, char *argv[])
return -1; // Couldn't open file return -1; // Couldn't open file
}; };
printf("%s\n\r", __FUNCTION__); // printf("%s\n\r", __FUNCTION__);
// Retrieve stream information // Retrieve stream information
if(avformat_find_stream_info(pFormatCtx, NULL)<0) if(avformat_find_stream_info(pFormatCtx, NULL)<0)
@ -72,7 +75,7 @@ int main( int argc, char *argv[])
// __asm__ __volatile__("int3"); // __asm__ __volatile__("int3");
// dump_format(pFormatCtx, 0, argv[1], 0); // dump_format(pFormatCtx, 0, argv[1], 0);
// Find the first video stream // Find the first video stream
videoStream=-1; videoStream=-1;
@ -207,7 +210,7 @@ void decoder()
// __asm__ __volatile__("int3"); // __asm__ __volatile__("int3");
if(q_video.size+q_audio.size < 16*1024*1024) if(q_video.size+q_audio.size < 12*1024*1024)
{ {
err = av_read_frame(pFormatCtx, &packet); err = av_read_frame(pFormatCtx, &packet);
if( err < 0) if( err < 0)
@ -241,7 +244,7 @@ void decoder()
ret = 1; ret = 1;
while(status != 0 && ret) while( (status != 0) && ret)
{ {
ret = decode_video(pCodecCtx, &q_video); ret = decode_video(pCodecCtx, &q_video);
ret |= decode_audio(aCodecCtx, &q_audio); ret |= decode_audio(aCodecCtx, &q_audio);
@ -250,6 +253,6 @@ void decoder()
delay(50); delay(50);
status = 0; status = 0;
printf("status = 0\n"); printf("status = 0\n");
delay(200); delay(300);
}; };

View File

@ -5,14 +5,6 @@
typedef unsigned int color_t; typedef unsigned int color_t;
typedef unsigned int count_t; typedef unsigned int count_t;
typedef struct
{
int left;
int top;
int right;
int bottom;
}rect_t;
typedef struct typedef struct
{ {
uint32_t width; uint32_t width;
@ -24,6 +16,11 @@ typedef struct
typedef struct render render_t; typedef struct render render_t;
#define HAS_LEFT (1<<0)
#define HAS_TOP (1<<1)
#define HAS_RIGHT (1<<2)
#define HAS_BOTTOM (1<<3)
struct render struct render
{ {
uint32_t caps; uint32_t caps;
@ -32,14 +29,22 @@ struct render
uint32_t win_width; uint32_t win_width;
uint32_t win_height; uint32_t win_height;
rect_t rc_client;
rect_t rcvideo;
rect_t rcleft;
rect_t rctop;
rect_t rcright;
rect_t rcbottom;
uint32_t layout;
bitmap_t bitmap[4]; bitmap_t bitmap[4];
uint32_t ctx_format; uint32_t ctx_format;
int target; int target;
window_t *win;
enum{ enum{
EMPTY, INIT }state; EMPTY, INIT }state;
enum{ enum win_state win_state;
NORMAL, MINIMIZED, ROLLED
}win_state;
void (*draw)(render_t *render, AVPicture *picture); void (*draw)(render_t *render, AVPicture *picture);
}; };
@ -90,7 +95,10 @@ render_t *create_render(uint32_t width, uint32_t height,
uint32_t ctx_format, uint32_t flags); uint32_t ctx_format, uint32_t flags);
int init_render(render_t *render, int width, int height); int init_render(render_t *render, int width, int height);
void render_adjust_size(render_t *render); void render_adjust_size(render_t *render, window_t *win);
int render_set_size(render_t *render, int width, int height);
void render_draw_client(render_t *render);
int init_audio(int format); int init_audio(int format);
int audio_thread(void *param); int audio_thread(void *param);
@ -120,16 +128,6 @@ static inline void GetNotify(void *event)
::"a"(68),"b"(14),"c"(event)); ::"a"(68),"b"(14),"c"(event));
} }
static inline uint32_t check_os_event()
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(11));
return val;
};
static inline uint32_t get_os_button() static inline uint32_t get_os_button()
{ {
uint32_t val; uint32_t val;
@ -154,48 +152,8 @@ static inline void delay(uint32_t time)
::"a"(5), "b"(time)); ::"a"(5), "b"(time));
}; };
static inline draw_bitmap(void *bitmap, int x, int y, int w, int h)
{
__asm__ __volatile__(
"int $0x40"
::"a"(7), "b"(bitmap),
"c"((w << 16) | h),
"d"((x << 16) | y));
}
static inline void BeginDraw(void)
{
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(1));
};
static inline void EndDraw(void)
{
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(2));
};
static inline void DrawWindow(int x, int y, int w, int h, char *name,
color_t workcolor, uint32_t style)
{
__asm__ __volatile__(
"int $0x40"
::"a"(0),
"b"((x << 16) | (w & 0xFFFF)),
"c"((y << 16) | (h & 0xFFFF)),
"d"((style << 24) | (workcolor & 0xFFFFFF)),
"D"(name));
};
static inline void get_proc_info(char *info)
{
__asm__ __volatile__(
"int $0x40"
::"a"(9), "b"(info), "c"(-1)
:"memory");
}
#define HW_BIT_BLIT (1<<0) /* BGRX blitter */ #define HW_BIT_BLIT (1<<0) /* BGRX blitter */
#define HW_TEX_BLIT (1<<1) /* stretch blit */ #define HW_TEX_BLIT (1<<1) /* stretch blit */
@ -204,6 +162,7 @@ static inline void get_proc_info(char *info)
uint32_t InitPixlib(uint32_t flags); uint32_t InitPixlib(uint32_t flags);
int create_bitmap(bitmap_t *bitmap); int create_bitmap(bitmap_t *bitmap);
int lock_bitmap(bitmap_t *bitmap);
int resize_bitmap(bitmap_t *bitmap); int resize_bitmap(bitmap_t *bitmap);
int blit_bitmap(bitmap_t *bitmap, int dst_x, int dst_y, int blit_bitmap(bitmap_t *bitmap, int dst_x, int dst_y,
int w, int h); int w, int h);

View File

@ -4,6 +4,7 @@
#include <libswscale/swscale.h> #include <libswscale/swscale.h>
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <winlib.h>
#include "fplay.h" #include "fplay.h"
#define DISPLAY_VERSION 0x0200 /* 2.00 */ #define DISPLAY_VERSION 0x0200 /* 2.00 */
@ -12,6 +13,8 @@
#define SRV_GET_CAPS 3 #define SRV_GET_CAPS 3
#define SRV_CREATE_SURFACE 10 #define SRV_CREATE_SURFACE 10
#define SRV_LOCK_SURFACE 12
#define SRV_BLIT_VIDEO 20 #define SRV_BLIT_VIDEO 20
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
@ -195,6 +198,52 @@ int create_bitmap(bitmap_t *bitmap)
return -1; return -1;
}; };
int lock_bitmap(bitmap_t *bitmap)
{
// __asm__ __volatile__("int3");
if( blit_caps & HW_BIT_BLIT )
{
struct __attribute__((packed)) /* SRV_CREATE_SURFACE */
{
uint32_t handle; // ignored
void *data; // ignored
uint32_t width;
uint32_t height;
uint32_t pitch; // ignored
}io_12;
ioctl_t io;
int err;
io_12.handle = bitmap->handle;
io_12.pitch = 0;
io_12.data = 0;
io.handle = service;
io.io_code = SRV_LOCK_SURFACE;
io.input = &io_12;
io.inp_size = BUFFER_SIZE(5);
io.output = NULL;
io.out_size = 0;
err = call_service(&io);
if(err==0)
{
bitmap->pitch = io_12.pitch;
bitmap->data = io_12.data;
// printf("Lock hardware surface %x pitch %d, buffer %x\n",
// bitmap->handle, bitmap->pitch, bitmap->data);
return 0;
};
return err;
};
return 0;
};
struct blit_call struct blit_call
{ {
int dstx; int dstx;
@ -280,6 +329,8 @@ int blit_bitmap(bitmap_t *bitmap, int dst_x, int dst_y,
__asm__ __volatile__( __asm__ __volatile__(
"int $0x40" "int $0x40"
::"a"(73),"b"(0),"c"(&bc)); ::"a"(73),"b"(0),"c"(&bc));
return 0;
}; };

View File

@ -0,0 +1,311 @@
#include <newlib.h>
#include <stdint.h>
#include <stddef.h>
#ifdef CONFIG_DEBUF
#define DBG(format,...) printf(format,##__VA_ARGS__)
#else
#define DBG(format,...)
#endif
typedef unsigned int color_t;
typedef union __attribute__((packed))
{
uint32_t val;
struct
{
short x;
short y;
};
}pos_t;
typedef union __attribute__((packed))
{
uint32_t val;
struct
{
uint8_t state;
uint8_t code;
uint16_t ctrl_key;
};
}oskey_t;
static inline
void BeginDraw(void)
{
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(1));
};
static inline
void EndDraw(void)
{
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(2));
};
static inline void DrawWindow(int x, int y, int w, int h, char *name,
color_t workcolor, uint32_t style)
{
__asm__ __volatile__(
"int $0x40"
::"a"(0),
"b"((x << 16) | (w & 0xFFFF)),
"c"((y << 16) | (h & 0xFFFF)),
"d"((style << 24) | (workcolor & 0xFFFFFF)),
"D"(name));
};
static inline
pos_t get_mouse_pos(void)
{
pos_t val;
__asm__ __volatile__(
"int $0x40 \n\t"
"rol $16, %%eax"
:"=eax"(val)
:"a"(37),"b"(1));
return val;
}
static inline
pos_t get_cursor_pos(void)
{
pos_t val;
__asm__ __volatile__(
"int $0x40 \n\t"
"rol $16, %%eax"
:"=eax"(val)
:"a"(37),"b"(0));
return val;
}
static inline
uint32_t get_mouse_buttons(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37),"b"(2));
return val;
};
static inline
uint32_t get_mouse_wheels(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40 \n\t"
"rol $16, %%eax"
:"=a"(val)
:"a"(37),"b"(7));
return val;
};
static inline
uint32_t wait_for_event(uint32_t time)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(23), "b"(time));
return val;
};
static inline uint32_t check_os_event()
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(11));
return val;
};
static inline
uint32_t get_tick_count(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=eax"(val)
:"a"(26),"b"(9));
return val;
};
static inline
oskey_t get_key(void)
{
oskey_t val;
__asm__ __volatile__(
"int $0x40"
:"=eax"(val)
:"a"(2));
return val;
}
static inline
void draw_line(int xs, int ys, int xe, int ye, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(38), "d"(color),
"b"((xs << 16) | xe),
"c"((ys << 16) | ye));
}
static inline
void draw_bar(int x, int y, int w, int h, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(13), "d"(color),
"b"((x << 16) | w),
"c"((y << 16) | h));
}
static inline
void draw_bitmap(void *bitmap, int x, int y, int w, int h)
{
__asm__ __volatile__(
"int $0x40"
::"a"(7), "b"(bitmap),
"c"((w << 16) | h),
"d"((x << 16) | y));
}
static inline
void draw_text(const char *text, int x, int y, int len, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(4),"d"(text),
"b"((x << 16) | y),
"S"(len),"c"(color));
}
static inline
void *user_alloc(size_t size)
{
void *val;
__asm__ __volatile__(
"int $0x40"
:"=eax"(val)
:"a"(68),"b"(12),"c"(size));
return val;
}
static inline
int user_free(void *mem)
{
int val;
__asm__ __volatile__(
"int $0x40"
:"=eax"(val)
:"a"(68),"b"(12),"c"(mem));
return val;
}
static inline
int *user_unmap(void *base, size_t offset, size_t size)
{
void *val;
__asm__ __volatile__(
"int $0x40"
:"=eax"(val)
:"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
return val;
}
/*
extern inline
void exit(int status) __attribute__((noreturn)) ;
extern inline
void exit(int status)
{
__asm__ __volatile__(
"int $0x40"
::"a"(-1));
for(;;);
}
*/
static inline
uint32_t load_cursor(void *path, uint32_t flags)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=eax"(val)
:"a"(37), "b"(4), "c"(path), "d"(flags));
return val;
}
static inline
uint32_t set_cursor(uint32_t cursor)
{
uint32_t old;
__asm__ __volatile__(
"int $0x40"
:"=eax"(old)
:"a"(37), "b"(5), "c"(cursor));
return old;
}
static inline void get_proc_info(char *info)
{
__asm__ __volatile__(
"int $0x40"
:
:"a"(9), "b"(info), "c"(-1));
}
static inline
void* user_realloc(void *mem, size_t size)
{
void *val;
__asm__ __volatile__(
"int $0x40"
:"=eax"(val)
:"a"(68),"b"(12),"c"(size),"d"(mem)
:"memory");
return val;
}
void *load_file(const char *path, size_t *len);
void *get_resource(void *data, uint32_t id);
struct blit_call
{
int dstx;
int dsty;
int w;
int h;
int srcx;
int srcy;
int srcw;
int srch;
unsigned char *bitmap;
int stride;
};
void Blit(void *bitmap, int dst_x, int dst_y,
int src_x, int src_y, int w, int h,
int src_w, int src_h, int stride);

View File

@ -5,6 +5,7 @@
#include <libswscale/swscale.h> #include <libswscale/swscale.h>
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <winlib.h>
#include "fplay.h" #include "fplay.h"
extern uint32_t hw2d ; extern uint32_t hw2d ;

View File

@ -3,6 +3,9 @@
#include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include <libswscale/swscale.h> #include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
#include "system.h"
#include <winlib.h>
#include "sound.h" #include "sound.h"
#include "fplay.h" #include "fplay.h"
@ -21,7 +24,7 @@ struct SwsContext *cvt_ctx = NULL;
int vfx = 0; int vfx = 0;
int dfx = 0; int dfx = 0;
render_t *render; render_t *main_render;
int width; int width;
int height; int height;
@ -43,11 +46,14 @@ int init_video(AVCodecContext *ctx)
printf("w = %d h = %d\n\r", width, height); printf("w = %d h = %d\n\r", width, height);
// __asm__ __volatile__("int3"); // __asm__ __volatile__("int3");
render = create_render(ctx->width, ctx->height, main_render = create_render(ctx->width, ctx->height,
ctx->pix_fmt, HW_BIT_BLIT|HW_TEX_BLIT); ctx->pix_fmt, HW_BIT_BLIT|HW_TEX_BLIT);
if( render == NULL) // render = create_render(ctx->width, ctx->height,
// ctx->pix_fmt, 0);
//
if( main_render == NULL)
{ {
printf("Cannot create render\n\r"); printf("Cannot create render\n\r");
return 0; return 0;
@ -85,14 +91,11 @@ int init_video(AVCodecContext *ctx)
return 1; return 1;
}; };
int frameFinished=0;
static int frame_count;
int decode_video(AVCodecContext *ctx, queue_t *qv) int decode_video(AVCodecContext *ctx, queue_t *qv)
{ {
AVPacket pkt; AVPacket pkt;
double pts; double pts;
double av_time; int frameFinished;
if(frames[dfx].ready != 0 ) if(frames[dfx].ready != 0 )
return 1; return 1;
@ -130,7 +133,8 @@ int decode_video(AVCodecContext *ctx, queue_t *qv)
dst_pic = &frames[dfx].picture; dst_pic = &frames[dfx].picture;
av_image_copy(dst_pic->data, dst_pic->linesize, Frame->data, av_image_copy(dst_pic->data, dst_pic->linesize,
(const uint8_t**)Frame->data,
Frame->linesize, ctx->pix_fmt, ctx->width, ctx->height); Frame->linesize, ctx->pix_fmt, ctx->width, ctx->height);
frames[dfx].pts = pts*1000.0; frames[dfx].pts = pts*1000.0;
@ -147,102 +151,116 @@ int decode_video(AVCodecContext *ctx, queue_t *qv)
extern volatile uint32_t status; extern volatile uint32_t status;
rect_t win_rect; rect_t win_rect;
int check_events()
int MainWindowProc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
{ {
int ev; window_t *win;
ev = check_os_event(); win = (window_t*)ctrl;
switch(ev) switch(msg)
{ {
case 1: case MSG_SIZE:
render_adjust_size(render); //printf("MSG_SIZE\n");
BeginDraw(); render_adjust_size(main_render, win);
DrawWindow(0,0,0,0, NULL, 0x000000,0x73);
EndDraw();
break; break;
case 3: case MSG_DRAW_CLIENT:
if(get_os_button()==1) render_draw_client(main_render);
status = 0;
break; break;
case MSG_COMMAND:
switch((short)arg1)
{
case ID_CLOSE:
exit(0);
};
break;
default:
def_window_proc(ctrl,msg,arg1,arg2);
}; };
return 1; return 0;
} };
void render_time(render_t *render)
{
double ctime;
double fdelay;
if(status == 0)
{
render->win->win_command = WIN_CLOSED;
return;
};
if(frames[vfx].ready == 1 )
{
ctime = get_master_clock();
fdelay = (frames[vfx].pts - ctime);
// printf("pts %f time %f delay %f\n",
// frames[vfx].pts, ctime, fdelay);
if(fdelay < 0.0 )
{
int next_vfx;
fdelay = 0;
next_vfx = (vfx+1) & 3;
if( frames[next_vfx].ready == 1 )
{
if(frames[next_vfx].pts <= ctime)
{
frames[vfx].ready = 0; // skip this frame
vfx++;
vfx&= 3;
}
else
{
if( (frames[next_vfx].pts - ctime) <
( ctime - frames[vfx].pts) )
{
frames[vfx].ready = 0; // skip this frame
vfx++;
vfx&= 3;
fdelay = (frames[next_vfx].pts - ctime);
}
}
};
};
if(fdelay > 10.0)
{
delay( (uint32_t)(fdelay/10.0));
};
main_render->draw(main_render, &frames[vfx].picture);
frames[vfx].ready = 0;
vfx++;
vfx&= 3;
};
}
extern char *movie_file; extern char *movie_file;
int video_thread(void *param) int video_thread(void *param)
{ {
rect_t rc; window_t *MainWindow;
AVCodecContext *ctx = param;
BeginDraw(); init_winlib();
DrawWindow(10, 10, width+9, height+26, movie_file, 0x000000,0x73);
EndDraw();
render_adjust_size(render); MainWindow = create_window(movie_file,0,
10,10,width+14,height+29,MainWindowProc);
while( status != 0) // printf("MainWindow %x\n", MainWindow);
{
double ctime;
double fdelay;
check_events(); main_render->win = MainWindow;
if(frames[vfx].ready == 1 ) show_window(MainWindow, NORMAL);
{ run_render(MainWindow, main_render);
ctime = get_master_clock();
fdelay = (frames[vfx].pts - ctime);
// printf("pts %f time %f delay %f\n", // printf("exit thread\n");
// frames[vfx].pts, ctime, fdelay); status = 0;
if(fdelay < 0.0 )
{
int next_vfx;
fdelay = 0;
next_vfx = (vfx+1) & 3;
if( frames[next_vfx].ready == 1 )
{
if(frames[next_vfx].pts <= ctime)
{
frames[vfx].ready = 0; // skip this frame
vfx++;
vfx&= 3;
}
else
{
if( (frames[next_vfx].pts - ctime) <
( ctime - frames[vfx].pts) )
{
frames[vfx].ready = 0; // skip this frame
vfx++;
vfx&= 3;
fdelay = (frames[next_vfx].pts - ctime);
}
}
};
};
if(fdelay > 10.0)
{
delay( (uint32_t)(fdelay/10.0));
};
// blit_bitmap(&frames[vfx].bitmap, 5, 22, width, height);
// frames[vfx].frame->linesize[0]);
render->draw(render, &frames[vfx].picture);
frames[vfx].ready = 0;
vfx++;
vfx&= 3;
}
else
{
yield();
};
};
return 0; return 0;
}; };
@ -253,10 +271,12 @@ void draw_sw_picture(render_t *render, AVPicture *picture);
render_t *create_render(uint32_t width, uint32_t height, render_t *create_render(uint32_t width, uint32_t height,
uint32_t ctx_format, uint32_t flags) uint32_t ctx_format, uint32_t flags)
{ {
render_t *ren; render_t *render;
render = (render_t*)malloc(sizeof(*ren)); // __asm__ __volatile__("int3");
memset(ren, 0, sizeof(*ren));
render = (render_t*)malloc(sizeof(render_t));
memset(render, 0, sizeof(render_t));
render->ctx_width = width; render->ctx_width = width;
render->ctx_height = height; render->ctx_height = height;
@ -285,11 +305,51 @@ int render_set_size(render_t *render, int width, int height)
{ {
int i; int i;
render->win_width = width; render->layout = 0;
render->win_height = height; render->rcvideo.l = 0;
render->win_state = NORMAL; render->rcvideo.t = 0;
render->rcvideo.r = width;
render->rcvideo.b = height;
// printf("%s %dx%d\n",__FUNCTION__, width, height); if( render->win_height > height )
{
int yoffs;
yoffs = (render->win_height-height)/2;
if(yoffs)
{
render->rctop.t = 0;
render->rctop.b = yoffs;
render->rcvideo.t = yoffs;
render->layout |= HAS_TOP;
}
yoffs = render->win_height-(render->rcvideo.t+render->rcvideo.b);
if(yoffs)
{
render->rcbottom.t = render->rcvideo.t+render->rcvideo.b;
render->rcbottom.b = yoffs;
render->layout |= HAS_BOTTOM;
}
}
if( render->win_width > width )
{
int xoffs;
xoffs = (render->win_width-width)/2;
if(xoffs)
{
render->rcleft.r = xoffs;
render->rcvideo.l = xoffs;
render->layout |= HAS_LEFT;
}
xoffs = render->win_width-(render->rcvideo.l+render->rcvideo.r);
if(xoffs)
{
render->rcright.l = render->rcvideo.l+render->rcvideo.r;
render->rcright.r = xoffs;
render->layout |= HAS_RIGHT;
}
};
if(render->state == EMPTY) if(render->state == EMPTY)
{ {
@ -333,31 +393,22 @@ int render_set_size(render_t *render, int width, int height)
return 0; return 0;
}; };
void render_adjust_size(render_t *render) void render_adjust_size(render_t *render, window_t *win)
{ {
char proc_info[1024];
uint32_t right, bottom, new_w, new_h; uint32_t right, bottom, new_w, new_h;
uint32_t s, sw, sh; uint32_t s, sw, sh;
uint8_t state; uint8_t state;
get_proc_info(proc_info);
right = *(uint32_t*)(proc_info+62)+1; right = win->w;
bottom = *(uint32_t*)(proc_info+66)+1; bottom = win->h-29;
state = *(uint8_t*)(proc_info+70); render->win_state = win->win_state;
if(state & 2) if(render->win_state == MINIMIZED)
{ render->win_state = MINIMIZED;
return; return;
}
if(state & 4)
{
render->win_state = ROLLED;
return;
};
render->win_state = NORMAL; if(render->win_state == ROLLED)
return;
if( right == render->win_width && if( right == render->win_width &&
bottom == render->win_height) bottom == render->win_height)
@ -366,7 +417,6 @@ void render_adjust_size(render_t *render)
new_w = bottom*render->ctx_width/render->ctx_height; new_w = bottom*render->ctx_width/render->ctx_height;
new_h = right*render->ctx_height/render->ctx_width; new_h = right*render->ctx_height/render->ctx_width;
// printf("right %d bottom %d\n", right, bottom);
// printf("new_w %d new_h %d\n", new_w, new_h); // printf("new_w %d new_h %d\n", new_w, new_h);
s = right * bottom; s = right * bottom;
@ -383,22 +433,21 @@ void render_adjust_size(render_t *render)
new_w = 64; new_w = 64;
new_h = 64*render->ctx_height/render->ctx_width; new_h = 64*render->ctx_height/render->ctx_width;
}; };
__asm__ __volatile__(
"int $0x40"
::"a"(67), "b"(-1), "c"(-1),
"d"(new_w+9),"S"(new_h+26)
:"memory" );
render_set_size(render, new_w, new_h);
render->win_width = win->w;
render->win_height = win->h-29;
render_set_size(render, new_w, new_h);
}; };
void draw_hw_picture(render_t *render, AVPicture *picture) void draw_hw_picture(render_t *render, AVPicture *picture)
{ {
int dst_width, dst_height; int dst_width, dst_height;
uint8_t *data[4]; bitmap_t *bitmap;
uint8_t *data[4];
int linesize[4]; int linesize[4];
int ret;
if(render->win_state != NORMAL) if(render->win_state == ROLLED)
return; return;
if(render->caps & HW_TEX_BLIT) if(render->caps & HW_TEX_BLIT)
@ -421,26 +470,37 @@ void draw_hw_picture(render_t *render, AVPicture *picture)
printf("Cannot initialize the conversion context!\n"); printf("Cannot initialize the conversion context!\n");
return ; return ;
}; };
// printf("sws_getCachedContext\n");
data[0] = render->bitmap[render->target].data;
data[1] = render->bitmap[render->target].data+1;
data[2] = render->bitmap[render->target].data+2;
data[3] = render->bitmap[render->target].data+3;
linesize[0] = render->bitmap[render->target].pitch; bitmap = &render->bitmap[render->target];
linesize[1] = render->bitmap[render->target].pitch;
linesize[2] = render->bitmap[render->target].pitch; ret = lock_bitmap(bitmap);
linesize[3] = render->bitmap[render->target].pitch; if( ret != 0)
{
printf("Cannot lock the bitmap!\n");
return ;
}
// printf("sws_getCachedContext\n");
data[0] = bitmap->data;
data[1] = bitmap->data+1;
data[2] = bitmap->data+2;
data[3] = bitmap->data+3;
linesize[0] = bitmap->pitch;
linesize[1] = bitmap->pitch;
linesize[2] = bitmap->pitch;
linesize[3] = bitmap->pitch;
sws_scale(cvt_ctx, (const uint8_t* const *)picture->data, sws_scale(cvt_ctx, (const uint8_t* const *)picture->data,
picture->linesize, 0, render->ctx_height, data, linesize); picture->linesize, 0, render->ctx_height, data, linesize);
// printf("sws_scale\n"); // printf("sws_scale\n");
blit_bitmap(&render->bitmap[render->target], 5, 22, blit_bitmap(bitmap, render->rcvideo.l,
render->win_width, render->win_height); 29+render->rcvideo.t,
render->rcvideo.r, render->rcvideo.b);
// printf("blit_bitmap\n"); // printf("blit_bitmap\n");
delay(2);
render->target++; render->target++;
render->target&= 3; render->target&= 3;
} }
@ -450,13 +510,14 @@ void draw_sw_picture(render_t *render, AVPicture *picture)
uint8_t *data[4]; uint8_t *data[4];
int linesize[4]; int linesize[4];
if(render->win_state != NORMAL) if(render->win_state == MINIMIZED ||
render->win_state == ROLLED)
return; return;
cvt_ctx = sws_getCachedContext(cvt_ctx, cvt_ctx = sws_getCachedContext(cvt_ctx,
render->ctx_width, render->ctx_height, render->ctx_width, render->ctx_height,
render->ctx_format, render->ctx_format,
render->win_width, render->win_height, render->rcvideo.r, render->rcvideo.b,
PIX_FMT_BGRA, SWS_FAST_BILINEAR, NULL, NULL, NULL); PIX_FMT_BGRA, SWS_FAST_BILINEAR, NULL, NULL, NULL);
if(cvt_ctx == NULL) if(cvt_ctx == NULL)
{ {
@ -478,12 +539,31 @@ void draw_sw_picture(render_t *render, AVPicture *picture)
sws_scale(cvt_ctx, (const uint8_t* const *)picture->data, sws_scale(cvt_ctx, (const uint8_t* const *)picture->data,
picture->linesize, 0, render->ctx_height, data, linesize); picture->linesize, 0, render->ctx_height, data, linesize);
blit_bitmap(&render->bitmap[0], 5, 22, blit_bitmap(&render->bitmap[0], render->rcvideo.l,
render->win_width, render->win_height); render->rcvideo.t+29,
render->rcvideo.r, render->rcvideo.b);
}
void render_draw_client(render_t *render)
{
if(render->win_state == MINIMIZED ||
render->win_state == ROLLED)
return;
if(render->layout & HAS_TOP)
draw_bar(0, 29, render->win_width,
render->rctop.b, 0);
if(render->layout & HAS_LEFT)
draw_bar(0, render->rcvideo.t+29, render->rcleft.r,
render->rcvideo.b, 0);
if(render->layout & HAS_RIGHT)
draw_bar(render->rcright.l, render->rcvideo.t+29,
render->rcright.r, render->rcvideo.b, 0);
if(render->layout & HAS_BOTTOM)
draw_bar(0, render->rcbottom.t+29,
render->win_width, render->rcbottom.b, 0);
} }