/programs/media/Fplay/audio.c |
---|
14,13 → 14,8 |
astream_t astream; |
extern uint8_t *decoder_buffer; |
int resampler_size; |
volatile int sound_level_0; |
volatile int sound_level_1; |
volatile enum player_state player_state; |
volatile enum player_state decoder_state; |
volatile enum player_state sound_state; |
extern volatile enum player_state player_state; |
extern volatile uint32_t driver_lock; |
51,7 → 46,7 |
mutex_unlock(&driver_lock); |
// printf("sound version 0x%x\n", version); |
printf("sound version 0x%x\n", version); |
if( (SOUND_VERSION>(version&0xFFFF)) || |
(SOUND_VERSION<(version >> 16))) |
72,11 → 67,6 |
return 0; |
}; |
void set_audio_volume(int left, int right) |
{ |
SetVolume(hBuff, left, right); |
}; |
static uint64_t samples_lost; |
static double audio_delta; |
static double last_time_stamp; |
99,7 → 89,7 |
int data_size=0; |
if( astream.count > AVCODEC_MAX_AUDIO_FRAME_SIZE*7) |
return -1; |
return 1; |
if( get_packet(qa, &pkt) == 0 ) |
return 0; |
171,16 → 161,8 |
mutex_lock(&astream.lock); |
{ |
if(astream.count < buffsize) |
{ |
memset(astream.buffer+astream.count, |
0, buffsize-astream.count); |
astream.count = buffsize; |
}; |
SetBuffer(hbuff, astream.buffer, offset, buffsize); |
samples_written+= buffsize/4; |
astream.count -= buffsize; |
if(astream.count) |
memcpy(astream.buffer, astream.buffer+buffsize, astream.count); |
192,6 → 174,7 |
}; |
int audio_thread(void *param) |
{ |
SND_EVENT evnt; |
209,7 → 192,7 |
goto exit_whith_error; |
}; |
SetVolume(hBuff,-1875,-1875); |
SetVolume(hBuff,-1000,-1000); |
if((err = GetBufferSize(hBuff, &buffsize)) != 0) |
{ |
217,10 → 200,24 |
goto exit_whith_error; |
}; |
resampler_size = buffsize = buffsize/2; |
buffsize = buffsize/2; |
samples = buffsize/4; |
while( (astream.count < buffsize*2) && |
(player_state != CLOSED) ) |
yield(); |
mutex_lock(&astream.lock); |
{ |
SetBuffer(hBuff, astream.buffer, 0, buffsize); |
samples_written+= buffsize/4; |
astream.count -= buffsize; |
if(astream.count) |
memcpy(astream.buffer, astream.buffer+buffsize, astream.count); |
mutex_unlock(&astream.lock); |
}; |
while( player_state != CLOSED) |
{ |
uint32_t offset; |
227,29 → 224,55 |
double event_stamp, wait_stamp; |
int too_late = 0; |
switch(sound_state) |
if((player_state == PAUSE) || |
(player_state == PLAY_INIT) ) |
{ |
case PREPARE: |
if( active ) |
{ |
StopBuffer(hBuff); |
active = 0; |
}; |
delay(1); |
continue; |
} |
else if(player_state == REWIND) |
{ |
if( active ) |
{ |
StopBuffer(hBuff); |
active = 0; |
}; |
mutex_lock(&astream.lock); |
if(astream.count < buffsize*2) |
astream.count = 0; |
mutex_unlock(&astream.lock); |
delay(1); |
continue; |
} |
else if(player_state == PAUSE_2_PLAY) |
{ |
memset(astream.buffer+astream.count, |
0, buffsize*2-astream.count); |
astream.count = buffsize*2; |
// SetTimeBase(hBuff, audio_base); |
GetTimeStamp(hBuff, &last_time_stamp); |
// printf("last_time_stamp %f\n", last_time_stamp); |
if((err = PlayBuffer(hBuff, 0)) !=0 ) |
{ |
errstr = "Cannot play buffer\n\r"; |
goto exit_whith_error; |
}; |
active = 1; |
sync_audio(hBuff, buffsize); |
player_state = PLAY; |
printf("render: set audio latency to %f\n", audio_delta); |
} |
else if(player_state == REWIND_2_PLAY) |
{ |
while( (astream.count < buffsize*2) && |
(player_state != CLOSED) ) |
yield(); |
SetBuffer(hBuff, astream.buffer, 0, buffsize*2); |
astream.count -= buffsize*2; |
if(astream.count) |
memcpy(astream.buffer, astream.buffer+buffsize*2, astream.count); |
mutex_unlock(&astream.lock); |
SetTimeBase(hBuff, audio_base); |
case PAUSE_2_PLAY: |
GetTimeStamp(hBuff, &last_time_stamp); |
// printf("last audio time stamp %f\n", last_time_stamp); |
printf("last audio time stamp %f\n", last_time_stamp); |
if((err = PlayBuffer(hBuff, 0)) !=0 ) |
{ |
258,12 → 281,10 |
}; |
active = 1; |
sync_audio(hBuff, buffsize); |
sound_state = PLAY; |
// printf("render: set audio latency to %f\n", audio_delta); |
player_state = PLAY; |
printf("render: set audio latency to %f\n", audio_delta); |
}; |
/* breaktrough */ |
case PLAY: |
GetNotify(&evnt); |
if(evnt.code != 0xFF000001) |
279,71 → 300,42 |
continue; |
}; |
GetTimeStamp(hBuff, &event_stamp); |
offset = evnt.offset; |
mutex_lock(&astream.lock); |
if(astream.count < buffsize) |
while( (astream.count < buffsize) && |
(player_state != CLOSED) ) |
{ |
memset(astream.buffer+astream.count, |
0, buffsize-astream.count); |
astream.count = buffsize; |
yield(); |
GetTimeStamp(hBuff, &wait_stamp); |
if( (wait_stamp - event_stamp) > |
samples*1500/sample_rate ) |
{ |
samples_lost+= samples; |
audio_delta = (double)samples_lost*1000/sample_rate; |
// printf("audio delta %f\n", audio_delta); |
too_late = 1; |
break; |
} |
}; |
SetBuffer(hBuff, astream.buffer, offset, buffsize); |
if((too_late == 1) || (player_state == CLOSED)) |
{ |
double val = 0; |
int16_t *src = (int16_t*)astream.buffer; |
int samples = buffsize/2; |
int i; |
for(i = 0, val = 0; i < samples/2; i++, src++) |
if(val < abs(*src)) |
val= abs(*src); // * *src; |
sound_level_0 = val; //sqrt(val / (samples/2)); |
for(i = 0, val = 0; i < samples/2; i++, src++) |
if(val < abs(*src)) |
val= abs(*src); // * *src; |
sound_level_1 = val; //sqrt(val / (samples/2)); |
// printf("%d\n", sound_level); |
too_late = 0; |
continue; |
}; |
mutex_lock(&astream.lock); |
SetBuffer(hBuff, astream.buffer, offset, buffsize); |
samples_written+= buffsize/4; |
astream.count -= buffsize; |
if(astream.count) |
memcpy(astream.buffer, astream.buffer+buffsize, astream.count); |
mutex_unlock(&astream.lock); |
break; |
case PLAY_2_STOP: |
if( active ) |
{ |
ResetBuffer(hBuff, SND_RESET_ALL); |
audio_base = -1.0; |
active = 0; |
} |
sound_state = STOP; |
break; |
case PLAY_2_PAUSE: |
if( active ) |
{ |
StopBuffer(hBuff); |
}; |
sound_state = PAUSE; |
case PAUSE: |
case STOP: |
delay(1); |
}; |
} |
StopBuffer(hBuff); |
DestroyBuffer(hBuff); |
return 0; |
/programs/media/Fplay/fplay.c |
---|
15,9 → 15,7 |
#include "sound.h" |
#include "fplay.h" |
volatile enum player_state player_state = STOP; |
volatile enum player_state decoder_state = PREPARE; |
volatile enum player_state sound_state = STOP; |
volatile enum player_state player_state; |
uint32_t win_width, win_height; |
35,8 → 33,6 |
int have_sound = 0; |
uint8_t *decoder_buffer; |
extern int resampler_size; |
extern int sample_rate; |
char *movie_file; |
70,7 → 66,7 |
movie_file = argv[1]; |
/* register all codecs, demux and protocols */ |
av_log_set_level(AV_LOG_FATAL); |
// av_log_set_level(AV_LOG_INFO); |
avcodec_register_all(); |
avdevice_register_all(); |
137,6 → 133,8 |
return -1; // Didn't find a video stream |
} |
player_state = PLAY_INIT; |
// __asm__ __volatile__("int3"); |
// Get a pointer to the codec context for the video stream |
234,16 → 232,31 |
} |
static int load_frame() |
static int fill_queue() |
{ |
int eof = 0; |
AVPacket packet; |
while( !eof) |
{ |
int err; |
// __asm__ __volatile__("int3"); |
if(q_video.size+q_audio.size < 2*1024*1024) |
{ |
err = av_read_frame(pFormatCtx, &packet); |
if( err == 0) |
if( err < 0) |
{ |
eof = 1; |
if (err != AVERROR_EOF) |
printf("av_read_frame: error %x\n", err); |
break; |
} |
if(packet.stream_index==videoStream) |
{ |
put_packet(&q_video, &packet); |
} |
else if( (packet.stream_index == audioStream) && |
(have_sound != 0) ) |
{ |
250,163 → 263,124 |
put_packet(&q_audio, &packet); |
if(audio_base == -1.0) |
{ |
if (packet.pts != AV_NOPTS_VALUE) |
audio_base = get_audio_base() * packet.pts; |
if (packet.dts != AV_NOPTS_VALUE) |
audio_base = get_audio_base() * packet.dts; |
// printf("audio base %f\n", audio_base); |
}; |
} |
else av_free_packet(&packet); |
else |
{ |
av_free_packet(&packet); |
}; |
} |
else if (err != AVERROR_EOF) |
printf("av_read_frame: error %x\n", err); |
else break; |
}; |
return err; |
} |
return eof; |
}; |
static int fill_queue() |
void decoder() |
{ |
int err = 0; |
int eof; |
AVPacket packet; |
int ret; |
// __asm__ __volatile__("int3"); |
eof = fill_queue(); |
while( (q_video.size+q_audio.size < 2*1024*1024) && |
!err ) |
err = load_frame(); |
while( player_state != CLOSED && !eof) |
{ |
int err; |
return err; |
// __asm__ __volatile__("int3"); |
if( player_state == PAUSE ) |
{ |
delay(1); |
continue; |
}; |
if( player_state == REWIND ) |
{ |
// int64_t timestamp = 0; |
// int stream_index = av_find_default_stream_index(pFormatCtx); |
static void flush_all() |
// __asm__ __volatile__("int3"); |
if (pFormatCtx->start_time != AV_NOPTS_VALUE) |
rewind_pos += pFormatCtx->start_time; |
printf("rewind %8"PRId64"\n", rewind_pos); |
ret = avformat_seek_file(pFormatCtx, -1, INT64_MIN, |
rewind_pos, INT64_MAX, 0); |
// ret = avformat_seek_file(pFormatCtx, -1, 0, |
// 0, INT64_MAX, 0); |
// __asm__ __volatile__("int3"); |
if (ret < 0) |
{ |
AVPacket packet; |
printf("could not seek to position %f\n", |
(double)rewind_pos / AV_TIME_BASE); |
} |
else |
{ |
avcodec_flush_buffers(pCodecCtx); |
avcodec_flush_buffers(aCodecCtx); |
while( get_packet(&q_video, &packet) != 0) |
av_free_packet(&packet); |
while( get_packet(&q_audio, &packet)!= 0) |
av_free_packet(&packet); |
audio_base = -1.0; |
flush_video(); |
// __asm__ __volatile__("int3"); |
astream.count = 0; |
eof = fill_queue(); |
}; |
yield(); |
void decoder() |
{ |
int eof; |
AVPacket packet; |
int ret; |
int64_t min_pos, max_pos; |
flush_video(); |
while( player_state != CLOSED ) |
{ |
int err; |
player_state = REWIND_2_PLAY; |
printf("restart\n"); |
continue; |
}; |
// __asm__ __volatile__("int3"); |
switch(decoder_state) |
if(q_video.size+q_audio.size < 4*1024*1024) |
{ |
case PREPARE: |
eof = fill_queue(); |
do |
err = av_read_frame(pFormatCtx, &packet); |
if( err < 0) |
{ |
if( (q_video.size+q_audio.size < 4*1024*1024) && |
(eof == 0) ) |
eof = 1; |
if (err != AVERROR_EOF) |
printf("av_read_frame: error %x\n", err); |
continue; |
} |
if(packet.stream_index==videoStream) |
{ |
eof = load_frame(); |
put_packet(&q_video, &packet); |
} |
decode_video(pCodecCtx, &q_video); |
ret = decode_audio(aCodecCtx, &q_audio); |
}while(astream.count < resampler_size*2 && |
ret == 1); |
sound_state = PREPARE; |
decoder_state = PLAY; |
player_state = PLAY; |
case PLAY: |
if( (q_video.size+q_audio.size < 4*1024*1024) && |
(eof == 0) ) |
else if( (packet.stream_index == audioStream) && |
(have_sound != 0) ) |
{ |
eof = load_frame(); |
if(eof) printf("eof\n"); |
put_packet(&q_audio, &packet); |
} |
ret = decode_video(pCodecCtx, &q_video); |
ret|= decode_audio(aCodecCtx, &q_audio); |
if( eof && !ret) |
else |
{ |
decoder_state = STOP; |
// printf("stop decoder\n"); |
av_free_packet(&packet); |
}; |
case STOP: |
decode_video(pCodecCtx, &q_video); |
decode_audio(aCodecCtx, &q_audio); |
continue; |
}; |
decode_video(pCodecCtx, &q_video); |
decode_audio(aCodecCtx, &q_audio); |
delay(1); |
break; |
case PLAY_2_STOP: |
while(sound_state != STOP) |
delay(1); |
flush_all(); |
if (pFormatCtx->start_time != AV_NOPTS_VALUE) |
rewind_pos = pFormatCtx->start_time; |
else |
rewind_pos = 0; |
ret = avformat_seek_file(pFormatCtx, -1, INT64_MIN, |
rewind_pos, INT64_MAX, 0); |
decoder_state = STOP; |
break; |
case REWIND: |
while(sound_state != STOP) |
yield(); |
flush_all(); |
int opts = 0; |
if(rewind_pos < 0) |
{ |
rewind_pos = -rewind_pos; |
opts = AVSEEK_FLAG_BACKWARD; |
}; |
if (pFormatCtx->start_time != AV_NOPTS_VALUE) |
rewind_pos += pFormatCtx->start_time; |
// printf("rewind %8"PRId64"\n", rewind_pos); |
min_pos = rewind_pos - 1000000; |
max_pos = rewind_pos + 1000000; |
ret = avformat_seek_file(pFormatCtx, -1, INT64_MIN, |
rewind_pos, INT64_MAX, 0); |
// ret = avformat_seek_file(pFormatCtx, -1, min_pos, |
// rewind_pos, max_pos, opts); |
// __asm__ __volatile__("int3"); |
if (ret < 0) |
{ |
printf("could not seek to position %f\n", |
(double)rewind_pos / AV_TIME_BASE); |
} |
// printf("restart\n"); |
decoder_state = PREPARE; |
break; |
} |
}; |
ret = 1; |
while( (player_state != CLOSED) && ret) |
/programs/media/Fplay/fplay.h |
---|
52,25 → 52,13 |
}; |
enum player_state |
{ |
CLOSED = 0, |
PREPARE, |
STOP, |
PAUSE, |
PLAY, |
REWIND, |
PLAY_2_STOP, |
PLAY_2_PAUSE, |
PAUSE_2_PLAY, |
REWIND_2_PLAY, |
{ CLOSED=0,PLAY_INIT, |
STOP, PAUSE, PLAY, REWIND, |
PAUSE_2_PLAY, REWIND_2_PLAY |
}; |
#define ID_PLAY 100 |
#define ID_STOP 101 |
#define ID_PROGRESS 102 |
#define ID_VOL_LEVEL 103 |
#define ID_VOL_CTRL 104 |
#define ID_PROGRESS 101 |
typedef struct |
{ |
volatile uint32_t lock; |
124,7 → 112,6 |
int init_audio(int format); |
int audio_thread(void *param); |
void set_audio_volume(int left, int right); |
int init_video(AVCodecContext *ctx); |
int video_thread(void *param); |
191,4 → 178,4 |
int blit_bitmap(bitmap_t *bitmap, int dst_x, int dst_y, |
int w, int h); |
int init_fontlib(); |
/programs/media/Fplay/pixlib2.c |
---|
1,23 → 1,12 |
#include <stdint.h> |
//#include <libavcodec/avcodec.h> |
//#include <libavformat/avformat.h> |
//#include <libswscale/swscale.h> |
#include <libavcodec/avcodec.h> |
#include <libavformat/avformat.h> |
#include <libswscale/swscale.h> |
#include <stdio.h> |
//#include <fcntl.h> |
#include <fcntl.h> |
#include "../winlib/winlib.h" |
//#include "fplay.h" |
#include "system.h" |
#include "fplay.h" |
typedef struct |
{ |
uint32_t width; |
uint32_t height; |
uint32_t pitch; |
uint32_t handle; |
uint8_t *data; |
}bitmap_t; |
#define DISPLAY_VERSION 0x0200 /* 2.00 */ |
#define SRV_GETVERSION 0 |
24,51 → 13,20 |
#define SRV_GET_CAPS 3 |
#define SRV_CREATE_SURFACE 10 |
#define SRV_DESTROY_SURFACE 11 |
#define SRV_LOCK_SURFACE 12 |
#define SRV_UNLOCK_SURFACE 13 |
#define SRV_RESIZE_SURFACE 14 |
#define SRV_BLIT_BITMAP 15 |
#define SRV_BLIT_TEXTURE 16 |
#define SRV_BLIT_VIDEO 17 |
#define SRV_BLIT_VIDEO 20 |
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) |
//void InitPixlib(uint32_t flags); |
#define HW_BIT_BLIT (1<<0) /* BGRX blitter */ |
#define HW_TEX_BLIT (1<<1) /* stretch blit */ |
#define HW_VID_BLIT (1<<2) /* planar and packed video */ |
uint32_t InitPixlib(uint32_t flags); |
int create_bitmap(bitmap_t *bitmap); |
int lock_bitmap(bitmap_t *bitmap); |
int resize_bitmap(bitmap_t *bitmap); |
int blit_bitmap(bitmap_t *bitmap, int dst_x, int dst_y, |
int w, int h); |
static uint32_t service; |
static uint32_t blit_caps; |
static uint32_t screen_width; |
static uint32_t screen_height; |
typedef struct |
{ |
unsigned handle; |
unsigned io_code; |
void *input; |
int inp_size; |
void *output; |
int out_size; |
}ioctl_t; |
typedef struct |
{ |
uint32_t idx; |
union |
{ |
80,17 → 38,6 |
}; |
}hwcaps_t; |
static inline uint32_t GetScreenSize() |
{ |
uint32_t retval; |
__asm__ __volatile__( |
"int $0x40" |
:"=a"(retval) |
:"a"(61), "b"(1)); |
return retval; |
} |
static uint32_t get_service(char *name) |
{ |
uint32_t retval = 0; |
121,16 → 68,11 |
uint32_t InitPixlib(uint32_t caps) |
{ |
uint32_t api_version; |
uint32_t screensize; |
hwcaps_t hwcaps; |
ioctl_t io; |
// __asm__ __volatile__("int3"); |
screensize = GetScreenSize(); |
screen_width = screensize >> 16; |
screen_height = screensize & 0xFFFF; |
service = get_service("DISPLAY"); |
if(service == 0) |
goto fail; |
211,8 → 153,8 |
io_10.width = bitmap->width; |
io_10.height = bitmap->height; |
io_10.max_width = screen_width; |
io_10.max_height = screen_height; |
io_10.max_width = 0; |
io_10.max_height = 0; |
io_10.format = 0; |
io.handle = service; |
259,19 → 201,22 |
int lock_bitmap(bitmap_t *bitmap) |
{ |
// __asm__ __volatile__("int3"); |
int err = 0; |
if( blit_caps & HW_BIT_BLIT ) |
{ |
struct __attribute__((packed)) /* SRV_LOCK_SURFACE */ |
struct __attribute__((packed)) /* SRV_CREATE_SURFACE */ |
{ |
uint32_t handle; |
void *data; |
uint32_t pitch; |
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; |
280,7 → 225,7 |
io.handle = service; |
io.io_code = SRV_LOCK_SURFACE; |
io.input = &io_12; |
io.inp_size = BUFFER_SIZE(3); |
io.inp_size = BUFFER_SIZE(5); |
io.output = NULL; |
io.out_size = 0; |
291,16 → 236,33 |
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 err; |
return 0; |
}; |
struct blit_call |
{ |
int dstx; |
int dsty; |
int w; |
int h; |
int srcx; |
int srcy; |
int srcw; |
int srch; |
unsigned char *bitmap; |
int stride; |
}; |
int blit_bitmap(bitmap_t *bitmap, int dst_x, int dst_y, |
int w, int h) |
{ |
int err; |
if( blit_caps & HW_BIT_BLIT ) |
{ |
318,21 → 280,22 |
int src_y; |
uint32_t w; |
uint32_t h; |
}io_15; |
}io_20; |
ioctl_t io; |
int err; |
io_15.handle = bitmap->handle; |
io_15.dst_x = dst_x; |
io_15.dst_y = dst_y; |
io_15.src_x = 0; |
io_15.src_y = 0; |
io_15.w = w; |
io_15.h = h; |
io_20.handle = bitmap->handle; |
io_20.dst_x = dst_x; |
io_20.dst_y = dst_y; |
io_20.src_x = 0; |
io_20.src_y = 0; |
io_20.w = w; |
io_20.h = h; |
io.handle = service; |
io.io_code = SRV_BLIT_BITMAP; |
io.input = &io_15; |
io.io_code = SRV_BLIT_VIDEO; |
io.input = &io_20; |
io.inp_size = BUFFER_SIZE(7); |
io.output = NULL; |
io.out_size = 0; |
340,10 → 303,17 |
// printf("do blit %x pitch %d\n",bitmap->handle, |
// bitmap->pitch); |
err = call_service(&io); |
if (call_service(&io)==0) |
{ |
//bitmap->data = NULL; Not now, Serge |
// printf("blit done\n"); |
// delay(1); |
return 0; |
}; |
return err; |
}; |
struct blit_call bc; |
volatile struct blit_call bc; |
bc.dstx = dst_x; |
bc.dsty = dst_y; |
358,13 → 328,25 |
__asm__ __volatile__( |
"int $0x40" |
:"=a"(err) |
:"a"(73),"b"(0x00),"c"(&bc) |
::"a"(73),"b"(0x00),"c"(&bc) |
:"memory"); |
return err; |
return 0; |
}; |
static inline void* user_realloc(void *mem, size_t size) |
{ |
void *val; |
__asm__ __volatile__( |
"int $0x40" |
:"=a"(val) |
:"a"(68),"b"(20),"c"(size),"d"(mem) |
:"memory"); |
return val; |
} |
int resize_bitmap(bitmap_t *bitmap) |
{ |
// __asm__ __volatile__("int3"); |
371,37 → 353,8 |
if( blit_caps & HW_BIT_BLIT ) |
{ |
struct __attribute__((packed)) |
{ |
uint32_t handle; |
char *data; |
uint32_t new_w; |
uint32_t new_h; |
uint32_t pitch; |
}io_14; |
ioctl_t io; |
int err; |
io_14.handle = bitmap->handle; |
io_14.new_w = bitmap->width; |
io_14.new_h = bitmap->height; |
io.handle = service; |
io.io_code = SRV_RESIZE_SURFACE; |
io.input = &io_14; |
io.inp_size = BUFFER_SIZE(5); |
io.output = NULL; |
io.out_size = 0; |
err = call_service(&io); |
if(err==0) |
{ |
bitmap->pitch = io_14.pitch; |
bitmap->data = io_14.data; |
/* work in progress */ |
}; |
return err; |
}; |
uint32_t size; |
uint32_t pitch; |
/programs/media/Fplay/video.c |
---|
8,8 → 8,9 |
#include "../winlib/winlib.h" |
#include "sound.h" |
#include "fplay.h" |
#include <math.h> |
#define CAPTION_HEIGHT 24 |
extern int res_pause_btn[]; |
extern int res_pause_btn_pressed[]; |
17,8 → 18,6 |
extern int res_play_btn_pressed[]; |
extern int64_t stream_duration; |
extern volatile int sound_level_0; |
extern volatile int sound_level_1; |
typedef struct |
{ |
28,7 → 27,6 |
}vframe_t; |
vframe_t frames[4]; |
volatile int frames_count = 0; |
struct SwsContext *cvt_ctx = NULL; |
56,7 → 54,6 |
frames[i].pts = 0; |
frames[i].ready = 0; |
}; |
frames_count = 0; |
vfx = 0; |
dfx = 0; |
}; |
68,12 → 65,16 |
width = ctx->width; |
height = ctx->height; |
printf("w = %d h = %d\n\r", ctx->width, ctx->height); |
printf("w = %d h = %d\n\r", width, height); |
// __asm__ __volatile__("int3"); |
main_render = create_render(ctx->width, ctx->height, |
ctx->pix_fmt, HW_BIT_BLIT|HW_TEX_BLIT); |
// render = create_render(ctx->width, ctx->height, |
// ctx->pix_fmt, 0); |
// |
if( main_render == NULL) |
{ |
printf("Cannot create render\n\r"); |
120,12 → 121,11 |
double current_clock; |
if(frames[dfx].ready != 0 ) |
return -1; |
return 1; |
if( get_packet(qv, &pkt) == 0 ) |
return 0; |
/* |
current_clock = -90.0 + get_master_clock(); |
if( pkt.dts == AV_NOPTS_VALUE && |
138,7 → 138,7 |
pts *= av_q2d(video_time_base)*1000.0; |
*/ |
if( 1 /*pts > current_clock*/) |
{ |
frameFinished = 0; |
181,7 → 181,6 |
dfx++; |
dfx&= 3; |
frames_count++; |
}; |
}; |
av_free_packet(&pkt); |
190,35 → 189,10 |
} |
extern volatile enum player_state player_state; |
extern volatile enum player_state decoder_state; |
extern volatile enum player_state sound_state; |
//rect_t win_rect; |
extern int64_t rewind_pos; |
static void player_stop() |
{ |
window_t *win; |
win = main_render->win; |
rewind_pos = 0; |
win->panel.play_btn->img_default = res_play_btn; |
win->panel.play_btn->img_hilite = res_play_btn; |
win->panel.play_btn->img_pressed = res_play_btn_pressed; |
win->panel.prg->current = rewind_pos; |
send_message(&win->panel.ctrl, MSG_PAINT, 0, 0); |
player_state = STOP; |
decoder_state = PLAY_2_STOP; |
sound_state = PLAY_2_STOP; |
render_draw_client(main_render); |
// printf("stop player\n"); |
}; |
int MainWindowProc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
{ |
window_t *win; |
237,15 → 211,13 |
break; |
case MSG_LBTNDOWN: |
if(player_state == PAUSE) |
{ |
win->panel.play_btn->img_default = res_pause_btn; |
win->panel.play_btn->img_hilite = res_pause_btn; |
win->panel.play_btn->img_pressed = res_pause_btn_pressed; |
send_message(&win->panel.play_btn->ctrl, MSG_PAINT, 0, 0); |
player_state = PLAY; |
sound_state = PAUSE_2_PLAY; |
send_message(win->panel.play_btn, MSG_PAINT, 0, 0); |
player_state = PAUSE_2_PLAY; |
} |
else if(player_state == PLAY) |
253,9 → 225,8 |
win->panel.play_btn->img_default = res_play_btn; |
win->panel.play_btn->img_hilite = res_play_btn; |
win->panel.play_btn->img_pressed = res_play_btn_pressed; |
send_message(&win->panel.play_btn->ctrl, MSG_PAINT, 0, 0); |
send_message(win->panel.play_btn, MSG_PAINT, 0, 0); |
player_state = PAUSE; |
sound_state = PLAY_2_PAUSE; |
} |
break; |
268,8 → 239,7 |
win->panel.play_btn->img_default = res_pause_btn; |
win->panel.play_btn->img_hilite = res_pause_btn; |
win->panel.play_btn->img_pressed = res_pause_btn_pressed; |
player_state = PLAY; |
sound_state = PAUSE_2_PLAY; |
player_state = PAUSE_2_PLAY; |
} |
else if(player_state == PLAY) |
{ |
277,66 → 247,24 |
win->panel.play_btn->img_hilite = res_play_btn; |
win->panel.play_btn->img_pressed = res_play_btn_pressed; |
player_state = PAUSE; |
sound_state = PLAY_2_PAUSE; |
} |
else if(player_state == STOP) |
{ |
win->panel.play_btn->img_default = res_pause_btn; |
win->panel.play_btn->img_hilite = res_pause_btn; |
win->panel.play_btn->img_pressed = res_pause_btn_pressed; |
rewind_pos = 0; |
send_message(&win->panel.ctrl, MSG_PAINT, 0, 0); |
player_state = PLAY; |
decoder_state = PREPARE; |
} |
break; |
case ID_STOP: |
player_stop(); |
break; |
case ID_PROGRESS: |
case 101: //ID_PROGRESS: |
if(player_state != REWIND) |
{ |
progress_t *prg = (progress_t*)arg2; |
rewind_pos = (prg->max - prg->min)*prg->pos/prg->ctrl.w; |
rewind_pos = (int64_t)prg->pos * |
(prg->max - prg->min)/prg->ctrl.w; |
// printf("progress action pos: %d time: %f\n", prg->pos, (double)rewind_pos); |
// printf("progress action %f\n", (double)rewind_pos); |
player_state = REWIND; |
decoder_state = REWIND; |
sound_state = PLAY_2_STOP; |
if(rewind_pos < prg->current) |
{ |
prg->current = rewind_pos; |
rewind_pos = -rewind_pos; |
} |
else |
prg->current = rewind_pos; |
win->panel.play_btn->img_default = res_pause_btn; |
win->panel.play_btn->img_hilite = res_pause_btn; |
win->panel.play_btn->img_pressed = res_pause_btn_pressed; |
send_message(&prg->ctrl, MSG_PAINT, 0, 0); |
main_render->win->panel.prg->current = rewind_pos; |
send_message(&main_render->win->panel.ctrl, MSG_PAINT, 0, 0); |
}; |
break; |
case ID_VOL_CTRL: |
{ |
slider_t *sld = (slider_t*)arg2; |
int peak; |
int level; |
peak = sld->min + sld->pos * (sld->max - sld->min)/(96); |
// level = (log2(peak+16384)*10000.0)/15 - 10000; |
level = peak; |
// printf("level %d\n", level); |
set_audio_volume(level, level); |
send_message(&sld->ctrl, MSG_PAINT, 0, 0); |
win->panel.lvl->vol = level; |
} |
default: |
break; |
} |
352,9 → 280,6 |
void render_time(render_t *render) |
{ |
progress_t *prg = main_render->win->panel.prg; |
level_t *lvl = main_render->win->panel.lvl; |
double ctime; /* milliseconds */ |
double fdelay; /* milliseconds */ |
365,16 → 290,6 |
render->win->win_command = WIN_CLOSED; |
return; |
} |
else if(player_state == REWIND) |
{ |
yield(); |
return; |
} |
else if (decoder_state == STOP && frames_count == 0 && |
player_state != STOP) |
{ |
player_stop(); |
} |
else if(player_state != PLAY) |
{ |
yield(); |
381,7 → 296,6 |
return; |
}; |
#ifdef VERSION_A |
if(frames[vfx].ready == 1 ) |
{ |
410,16 → 324,8 |
// sys_time*10, frames[vfx].pts, ctime, fdelay); |
main_render->draw(main_render, &frames[vfx].picture); |
prg->current = frames[vfx].pts*1000; |
// printf("current %f\n", prg->current); |
lvl->current = vfx & 1 ? sound_level_1 : sound_level_0; |
send_message(&prg->ctrl, PRG_PROGRESS, 0, 0); |
if(main_render->win->panel.layout) |
send_message(&lvl->ctrl, MSG_PAINT, 0, 0); |
frames_count--; |
main_render->win->panel.prg->current = frames[vfx].pts*1000; |
send_message(&render->win->panel.prg->ctrl, MSG_PAINT, 0, 0); |
frames[vfx].ready = 0; |
vfx++; |
vfx&= 3; |
490,6 → 396,8 |
} |
extern char *movie_file; |
int video_thread(void *param) |
499,7 → 407,7 |
init_winlib(); |
MainWindow = create_window(movie_file,0, |
10,10,width,height+CAPTION_HEIGHT+PANEL_HEIGHT,MainWindowProc); |
10,10,width,height+29+55,MainWindowProc); |
MainWindow->panel.prg->max = stream_duration; |
// printf("MainWindow %x\n", MainWindow); |
509,12 → 417,11 |
show_window(MainWindow, NORMAL); |
render_draw_client(main_render); |
player_state = PLAY; |
player_state = PAUSE_2_PLAY; |
run_render(MainWindow, main_render); |
fini_winlib(); |
// printf("exit thread\n"); |
player_state = CLOSED; |
return 0; |
}; |
566,8 → 473,6 |
render->rcvideo.r = width; |
render->rcvideo.b = height; |
// printf("render width %d height %d\n",width, height); |
if( render->win_height > height ) |
{ |
int yoffs; |
656,12 → 561,9 |
uint32_t s, sw, sh; |
uint8_t state; |
right = win->w; |
bottom = win->h-CAPTION_HEIGHT-PANEL_HEIGHT; |
// printf("window width %d height %d\n", |
// right, bottom); |
bottom = win->h-CAPTION_HEIGHT-55; |
render->win_state = win->win_state; |
if(render->win_state == MINIMIZED) |
677,19 → 579,25 |
new_w = bottom*render->ctx_width/render->ctx_height; |
new_h = right*render->ctx_height/render->ctx_width; |
if(new_w > right) |
{ |
// printf("new_w %d new_h %d\n", new_w, new_h); |
s = right * bottom; |
sw = right * new_h; |
sh = bottom * new_w; |
if( abs(s-sw) > abs(s-sh)) |
new_h = bottom; |
else |
new_w = right; |
new_h = right*render->ctx_height/render->ctx_width; |
}; |
if(new_h > bottom) |
if(new_w < 64) |
{ |
new_h = bottom; |
new_w = bottom*render->ctx_width/render->ctx_height; |
new_w = 64; |
new_h = 64*render->ctx_height/render->ctx_width; |
}; |
render->win_width = win->w; |
render->win_height = win->h-CAPTION_HEIGHT-PANEL_HEIGHT; |
render->win_height = win->h-CAPTION_HEIGHT-55; |
render_set_size(render, new_w, new_h); |
}; |
712,8 → 620,8 |
} |
else |
{ |
dst_width = render->rcvideo.r; |
dst_height = render->rcvideo.b; |
dst_width = render->win_width; |
dst_height = render->win_height; |
}; |
cvt_ctx = sws_getCachedContext(cvt_ctx, |
731,7 → 639,7 |
ret = lock_bitmap(bitmap); |
if( ret != 0) |
{ |
printf("Cannot lock bitmap!\n"); |
printf("Cannot lock the bitmap!\n"); |
return ; |
} |
753,13 → 661,12 |
blit_bitmap(bitmap, render->rcvideo.l, |
CAPTION_HEIGHT+render->rcvideo.t, |
render->rcvideo.r, render->rcvideo.b); |
render->last_bitmap = bitmap; |
// printf("blit_bitmap\n"); |
// render->target++; |
// render->target&= 3; |
render->target++; |
render->target&= 3; |
} |
void draw_sw_picture(render_t *render, AVPicture *picture) |
808,7 → 715,8 |
render->win_state == ROLLED) |
return; |
if(player_state == PAUSE) |
if((player_state == PAUSE) || |
(player_state == PLAY_INIT) ) |
{ |
if(frames[vfx].ready == 1 ) |
main_render->draw(main_render, &frames[vfx].picture); |
815,11 → 723,6 |
else |
draw_bar(0, CAPTION_HEIGHT, render->win_width, |
render->rcvideo.b, 0); |
} |
else if( player_state == STOP ) |
{ |
draw_bar(0, CAPTION_HEIGHT, render->win_width, |
render->rcvideo.b, 0); |
}; |
if(render->layout & HAS_TOP) |
/programs/media/Fplay/winlib/minimize_btn_pressed.raw |
---|
File deleted |
\ No newline at end of file |
/programs/media/Fplay/winlib/minimize_btn.raw |
---|
File deleted |
\ No newline at end of file |
/programs/media/Fplay/winlib/prg_level.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Deleted: svn:mime-type |
-application/octet-stream |
\ No newline at end of property |
/programs/media/Fplay/winlib/alevel.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Deleted: svn:mime-type |
-application/octet-stream |
\ No newline at end of property |
/programs/media/Fplay/winlib/vol_slider.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Deleted: svn:mime-type |
-application/octet-stream |
\ No newline at end of property |
/programs/media/Fplay/winlib/stopbtn.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Deleted: svn:mime-type |
-application/octet-stream |
\ No newline at end of property |
/programs/media/Fplay/winlib/slider.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Deleted: svn:mime-type |
-application/octet-stream |
\ No newline at end of property |
/programs/media/Fplay/winlib/fontlib.c |
---|
File deleted |
/programs/media/Fplay/winlib/stopbtnp.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Deleted: svn:mime-type |
-application/octet-stream |
\ No newline at end of property |
/programs/media/Fplay/winlib/caption_right.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Deleted: svn:mime-type |
-application/octet-stream |
\ No newline at end of property |
/programs/media/Fplay/winlib/caption_body.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Deleted: svn:mime-type |
-application/octet-stream |
\ No newline at end of property |
/programs/media/Fplay/winlib/vol_level.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Deleted: svn:mime-type |
-application/octet-stream |
\ No newline at end of property |
/programs/media/Fplay/winlib/close_button_pressed.raw |
---|
File deleted |
\ No newline at end of file |
/programs/media/Fplay/winlib/caption_left.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Deleted: svn:mime-type |
-application/octet-stream |
\ No newline at end of property |
/programs/media/Fplay/winlib/close_button.raw |
---|
File deleted |
\ No newline at end of file |
/programs/media/Fplay/winlib/pbar.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Deleted: svn:mime-type |
-application/octet-stream |
\ No newline at end of property |
/programs/media/Fplay/winlib/button.c |
---|
2,14 → 2,8 |
#include "system.h" |
#include <stdlib.h> |
#include <string.h> |
#include <math.h> |
#include "winlib.h" |
extern int res_level[]; |
extern int res_slider[]; |
extern int res_vol_slider[]; |
extern int res_progress_bar[]; |
extern int res_prg_level[]; |
extern ctrl_t *mouse_capture; |
uint32_t main_cursor; |
17,52 → 11,39 |
static int button_proc(ctrl_t *btn, uint32_t msg, uint32_t arg1, uint32_t arg2); |
static int spinbtn_proc(ctrl_t *btn, uint32_t msg, uint32_t arg1, uint32_t arg2); |
ctrl_t *create_control(size_t size, int id, int x, int y, |
button_t *create_button(char *caption, int id, int x, int y, |
int w, int h, ctrl_t *parent) |
{ |
button_t *btn; |
int len; |
ctrl_t *ctrl; |
if( !parent ) |
return NULL; |
ctrl = (ctrl_t*)malloc(size); |
btn = (button_t*)malloc(sizeof(button_t)); |
link_initialize(&ctrl->link); |
list_initialize(&ctrl->child); |
link_initialize(&btn->link); |
list_initialize(&btn->child); |
ctrl->parent = parent; |
btn->handler = button_proc; |
btn->parent = parent; |
ctrl->ctx = parent->ctx; |
ctrl->id = id; |
btn->ctx = parent->ctx; |
btn->id = id; |
btn->style = 0; |
ctrl->rc.l = x; |
ctrl->rc.t = y ; |
btn->rc.l = x; |
btn->rc.t = y ; |
ctrl->rc.r = x + w; |
ctrl->rc.b = y + h; |
btn->rc.r = x + w; |
btn->rc.b = y + h; |
ctrl->w = w; |
ctrl->h = h; |
btn->w = w; |
btn->h = h; |
list_append(&ctrl->link, &parent->child); |
btn->state = 0; |
return ctrl; |
}; |
button_t *create_button(char *caption, int id, int x, int y, |
int w, int h, ctrl_t *parent) |
{ |
button_t *btn; |
int len; |
if( !parent ) |
return NULL; |
btn = (button_t*)create_control(sizeof(button_t), id, x, y, w, h, parent); |
btn->ctrl.handler = button_proc; |
btn->state = 0; |
btn->caption = caption; |
if( !caption ) |
81,6 → 62,8 |
btn->img_hilite = NULL; |
btn->img_pressed = NULL; |
list_append(&btn->link, &parent->child); |
return btn; |
}; |
125,10 → 108,10 |
int i, j; |
int x, y; |
ctx = btn->ctrl.ctx; |
ctx = btn->ctx; |
x = btn->ctrl.rc.l - ctx->offset_x; |
y = btn->ctrl.rc.t - ctx->offset_y; |
x = btn->rc.l - ctx->offset_x; |
y = btn->rc.t - ctx->offset_y; |
pixmap = ctx->pixmap; |
141,12 → 124,12 |
else if(btn->state & bHighlight) |
src = btn->img_hilite; |
for(i=0; i < btn->ctrl.h ;i++) |
for(i=0; i < btn->h ;i++) |
{ |
for(j = 0; j < btn->ctrl.w; j++) |
for(j=0; j<btn->w; j++) |
pixmap[j] = src[j]; |
pixmap+= ctx->stride/4; |
src+= btn->ctrl.w; |
src+=btn->w; |
}; |
return 0; |
180,7 → 163,7 |
case MSG_MOUSEENTER: |
// printf("mouse enter\n"); |
btn->state|= bHighlight; |
send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
send_message(btn, MSG_PAINT, 0, 0); |
break; |
case MSG_MOUSELEAVE: |
187,7 → 170,7 |
// printf("mouse leave\n"); |
if( (ctrl_t*)btn != mouse_capture) { |
btn->state &= ~bHighlight; |
send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
send_message(btn, MSG_PAINT, 0, 0); |
}; |
break; |
196,7 → 179,7 |
// printf("push button\n"); |
capture_mouse((ctrl_t*)btn); |
btn->state|= bPressed; |
send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
send_message(btn, MSG_PAINT, 0, 0); |
break; |
case MSG_LBTNUP: |
210,16 → 193,16 |
x = ((pos_t)arg2).x; |
y = ((pos_t)arg2).y; |
if( pt_in_rect( &btn->ctrl.rc, x, y) ) |
if( pt_in_rect( &btn->rc, x, y) ) |
state = bHighlight; |
else |
state = 0; |
if(action) |
send_message(btn->ctrl.parent,MSG_COMMAND,btn->ctrl.id,(int)btn); |
send_message(btn->parent,MSG_COMMAND,btn->id,(int)btn); |
btn->state = state; |
send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
send_message(btn, MSG_PAINT, 0, 0); |
break; |
case MSG_MOUSEMOVE: |
233,7 → 216,7 |
if( ! (btn->state & bHighlight)) |
{ |
btn->state|= bHighlight; |
send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
send_message(btn, MSG_PAINT, 0, 0); |
}; |
if( (ctrl_t*)btn != mouse_capture) |
244,26 → 227,26 |
old_state = btn->state; |
if( pt_in_rect(&btn->ctrl.rc, x, y) ) |
if( pt_in_rect(&btn->rc, x, y) ) |
btn->state |= bPressed; |
else |
btn->state &= ~bPressed; |
if( old_state ^ btn->state) |
send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
send_message(btn, MSG_PAINT, 0, 0); |
} |
return 0; |
}; |
int draw_progress(progress_t *prg, int background) |
int draw_progress(progress_t *prg) |
{ |
int *pixmap, *src; |
int *pixmap, src; |
ctx_t *ctx; |
int i, j; |
int x, y; |
int len = prg->ctrl.w; |
int len; |
ctx = prg->ctrl.ctx; |
270,37 → 253,19 |
x = prg->ctrl.rc.l - ctx->offset_x; |
y = prg->ctrl.rc.t - ctx->offset_y; |
if( background ) |
{ |
src = res_progress_bar; |
len = prg->current*prg->ctrl.w/(prg->max - prg->min); |
pixmap = ctx->pixmap; |
pixmap+= y * ctx->stride/4 + x; |
for(i=0; i < 10; i++) |
{ |
for(j = 0; j < len; j++) |
pixmap[j] = *src; |
src = 0x32ebfb; //btn->img_default; |
pixmap+= ctx->stride/4; |
src++; |
}; |
}; |
len = prg->current*prg->ctrl.w/(prg->max - prg->min); |
src = res_prg_level; |
pixmap = ctx->pixmap; |
pixmap+= y*ctx->stride/4 + x; |
for(i=0; i < prg->ctrl.h ;i++) |
{ |
for(j=0; j < len; j++) |
pixmap[j] = *src; |
pixmap[j] = src; |
pixmap+= ctx->stride/4; |
src++; |
}; |
return 0; |
315,7 → 280,7 |
switch( msg ) |
{ |
case MSG_PAINT: |
draw_progress(prg, 1); |
draw_progress(prg); |
update_rect(ctrl); |
break; |
324,11 → 289,6 |
send_message(ctrl->parent,MSG_COMMAND,ctrl->id,(int)ctrl); |
break; |
case PRG_PROGRESS: |
draw_progress(prg, 0); |
update_rect(ctrl); |
break; |
default: |
break; |
} |
345,273 → 305,33 |
if( !parent ) |
return NULL; |
prg = (progress_t*)create_control(sizeof(progress_t), id, x, y, w, h, parent); |
prg = (progress_t*)malloc(sizeof(progress_t)); |
link_initialize(&prg->ctrl.link); |
list_initialize(&prg->ctrl.child); |
prg->ctrl.handler = prg_proc; |
prg->ctrl.parent = parent; |
prg->ctrl.ctx = parent->ctx; |
prg->ctrl.id = id; |
prg->ctrl.rc.l = x; |
prg->ctrl.rc.t = y ; |
prg->ctrl.rc.r = x + w; |
prg->ctrl.rc.b = y + h; |
prg->ctrl.w = w; |
prg->ctrl.h = h; |
prg->min = 0; |
prg->max = 1; |
prg->current = 0; |
prg->pos = 0; |
list_append(&prg->ctrl.link, &parent->child); |
return prg; |
}; |
int draw_level(level_t *lvl) |
{ |
int *pixmap, *src; |
ctx_t *ctx; |
int i, j; |
int x, y; |
int len; |
double level; |
ctx = lvl->ctrl.ctx; |
x = lvl->ctrl.rc.l - ctx->offset_x; |
y = lvl->ctrl.rc.t - ctx->offset_y; |
level = (log2(lvl->current+1)-7)*12 + lvl->vol/50 ; |
len = level; |
if(len < 0) |
len = 0; |
if(len > 96) |
len = 96; |
pixmap = ctx->pixmap; |
pixmap+= y*ctx->stride/4 + x; |
// for(i=0; i < prg->ctrl.h ;i++) |
// { |
// for(j=0; j < len; j++) |
// pixmap[j] = src; |
// pixmap+= ctx->stride/4; |
// }; |
src = lvl->img_level; |
for(i=0; i < 10; i++) |
{ |
for(j = 0; j < 96; j++) |
pixmap[j] = 0xFF1C1C1C; |
pixmap+= ctx->stride/4; |
}; |
pixmap = ctx->pixmap; |
pixmap+= y*ctx->stride/4 + x; |
for(i=0; i < 10; i++) |
{ |
for(j = 0; j < len; j++) |
pixmap[j] = src[j]; |
pixmap+= ctx->stride/4; |
src+= 96; |
}; |
return 0; |
}; |
int lvl_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
{ |
level_t *lvl = (level_t*)ctrl; |
// int pos; |
switch( msg ) |
{ |
case MSG_PAINT: |
if(lvl->visible) |
{ |
draw_level(lvl); |
update_rect(ctrl); |
}; |
break; |
// case MSG_LBTNDOWN: |
// prg->pos = ((pos_t)arg2).x - ctrl->rc.l; |
// send_message(ctrl->parent,MSG_COMMAND,ctrl->id,(int)ctrl); |
// break; |
default: |
break; |
} |
return 0; |
}; |
level_t *create_level(char *caption, int id, int x, int y, |
int w, int h, ctrl_t *parent) |
{ |
level_t *lvl; |
if( !parent ) |
return NULL; |
lvl = (level_t*)create_control(sizeof(level_t), id, x, y, w, h, parent); |
lvl->ctrl.handler = lvl_proc; |
lvl->min = 0; |
lvl->max = 1; |
lvl->current = 0; |
lvl->pos = 0; |
lvl->visible = 0; |
lvl->img_level = res_level; |
return lvl; |
}; |
int draw_slider(slider_t *sld) |
{ |
int *pixmap, *src; |
ctx_t *ctx; |
int i, j; |
int x, y; |
int32_t len; |
double level; |
ctx = sld->ctrl.ctx; |
x = sld->ctrl.rc.l - ctx->offset_x; |
y = sld->ctrl.rc.t - ctx->offset_y; |
len = 96 + 12; |
pixmap = ctx->pixmap; |
pixmap+= y*ctx->stride/4 + x; |
for(i=0; i < 11; i++) |
{ |
for(j = 0; j < len; j++) |
pixmap[j] = 0xFF1C1C1C; |
pixmap+= ctx->stride/4; |
}; |
pixmap = ctx->pixmap; |
pixmap+= (y+4)*ctx->stride/4 + x + 6; |
src = sld->img_vol_slider; |
for(i = 0; i < 4; i++) |
{ |
for(j = 0; j < 96; j++) |
pixmap[j] = src[j]; |
pixmap+= ctx->stride/4; |
src+= 96; |
}; |
pixmap = ctx->pixmap; |
pixmap+= y*ctx->stride/4 + x + sld->pos; |
src = res_slider; |
for(i = 0; i < 11; i++) |
{ |
for(j = 0; j < 12; j++) |
pixmap[j] = src[j]; |
pixmap+= ctx->stride/4; |
src+= 12; |
}; |
return 0; |
}; |
int sld_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
{ |
slider_t *sld = (slider_t*)ctrl; |
int pos; |
switch( msg ) |
{ |
case MSG_PAINT: |
draw_slider(sld); |
update_rect(ctrl); |
break; |
case MSG_LBTNDOWN: |
capture_mouse(ctrl); |
sld->mode = 1; |
pos = ((pos_t)arg2).x - ctrl->rc.l - 6; |
if( pos < 0 ) |
pos = 0; |
else if(pos > 96) |
pos = 96; |
if( sld->pos != pos) |
{ |
sld->pos = pos; |
send_message(ctrl->parent,MSG_COMMAND,ctrl->id,(int)ctrl); |
}; |
break; |
case MSG_LBTNUP: |
if(sld->mode) |
{ |
release_mouse(); |
sld->mode = 0; |
}; |
break; |
case MSG_MOUSEMOVE: |
if(sld->mode) |
{ |
pos = ((pos_t)arg2).x - ctrl->rc.l - 6; |
if( pos < 0 ) |
pos = 0; |
else if(pos > 96) |
pos = 96; |
if( sld->pos != pos) |
{ |
sld->pos = pos; |
// printf("slider pos %d\n", sld->pos); |
send_message(ctrl->parent,MSG_COMMAND,ctrl->id,(int)ctrl); |
} |
}; |
break; |
case MSG_MOUSEENTER: |
panel_set_layout(ctrl->parent, 1); |
// printf("level on\n"); |
break; |
case MSG_MOUSELEAVE: |
panel_set_layout(ctrl->parent, 0); |
// printf("level off\n"); |
break; |
default: |
break; |
} |
return 0; |
}; |
slider_t *create_slider(char *caption, int id, int x, int y, |
int w, int h, ctrl_t *parent) |
{ |
slider_t *sld; |
if( !parent ) |
return NULL; |
sld = (slider_t*)create_control(sizeof(slider_t), id, x, y, w, h, parent); |
sld->ctrl.handler = sld_proc; |
sld->min = -5000; |
sld->max = 0; |
sld->current = 0; |
sld->pos = 60; |
sld->mode = 0; |
sld->img_vol_slider = res_vol_slider; |
return sld; |
}; |
/programs/media/Fplay/winlib/caption.c |
---|
5,6 → 5,7 |
#include <stdio.h> |
#include "winlib.h" |
#define CAPTION_HEIGHT 24 |
#define CAPTION_CORNER_W 8 |
extern int res_caption_left[]; |
19,8 → 20,6 |
extern int res_minimize_btn_hl[]; |
extern int res_minimize_btn_pressed[]; |
extern uint32_t main_cursor; |
void update_caption_size(window_t *win); |
int caption_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2); |
39,8 → 38,6 |
cpt->ctrl.handler = caption_proc; |
cpt->ctrl.parent = (ctrl_t*)win; |
cpt->text = win->caption_txt; |
ctx->pixmap = user_alloc(1920*CAPTION_HEIGHT*4); |
if(!ctx->pixmap) |
{ |
105,27 → 102,17 |
cpt->ctrl.h = CAPTION_HEIGHT; |
win->client.t = CAPTION_HEIGHT; |
cpt->close_btn->ctrl.rc.l = win->w - 25; |
cpt->close_btn->ctrl.rc.r = cpt->close_btn->ctrl.rc.l + |
cpt->close_btn->ctrl.w; |
cpt->close_btn->rc.l = win->w - 25; |
cpt->close_btn->rc.r = cpt->close_btn->rc.l + |
cpt->close_btn->w; |
cpt->minimize_btn->ctrl.rc.l = win->w - 25 - 16 - 5; |
cpt->minimize_btn->ctrl.rc.r = cpt->minimize_btn->ctrl.rc.l + |
cpt->minimize_btn->ctrl.w; |
cpt->minimize_btn->rc.l = win->w - 25 - 16 - 5; |
cpt->minimize_btn->rc.r = cpt->minimize_btn->rc.l + |
cpt->minimize_btn->w; |
}; |
typedef struct |
{ |
uint32_t width; |
uint32_t height; |
uint32_t pitch; |
uint32_t handle; |
uint8_t *data; |
}bitmap_t; |
extern int win_font; |
void draw_caption(caption_t *cpt) |
{ |
int *pixmap, *src; |
170,13 → 157,6 |
src+= CAPTION_CORNER_W; |
}; |
bitmap_t bitmap; |
bitmap.data = cpt->ctx.pixmap; |
bitmap.pitch = cpt->ctx.stride; |
draw_text(&bitmap, win_font, cpt->text, 8, 18, 0xFFFFFFFF); |
ctrl_t *child; |
child = (ctrl_t*)cpt->ctrl.child.next; |
213,19 → 193,18 |
send_message(child, msg, 0, arg2); |
else |
send_message(win->child_over, MSG_MOUSELEAVE, 0, arg2); |
}; |
} |
else if( child ) |
send_message(child, MSG_MOUSEENTER, 0, arg2); |
win->child_over = child; |
if( child ) |
{ |
send_message(child, MSG_MOUSEENTER, 0, arg2); |
send_message(child,msg,0,arg2); |
} |
else if(main_cursor != 0) |
{ |
set_cursor(0); |
main_cursor = 0; |
} |
// else if(main_cursor != 0) |
// { |
// set_cursor(0); |
// main_cursor = 0; |
// } |
break; |
/programs/media/Fplay/winlib/control.h |
---|
54,8 → 54,20 |
typedef struct |
{ |
ctrl_t ctrl; |
link_t link; |
link_t child; |
handler_t *handler; |
ctrl_t *parent; |
ctx_t *ctx; |
uint32_t id; |
uint32_t style; |
rect_t rc; |
int w; |
int h; |
uint32_t state; |
ostimer_t timer; |
78,30 → 90,6 |
typedef struct |
{ |
ctrl_t ctrl; |
int min; |
int max; |
int current; |
int pos; |
int vol; |
int visible; |
void *img_level; |
}level_t; |
typedef struct |
{ |
ctrl_t ctrl; |
int min; |
int max; |
int current; |
int pos; |
int mode; |
void *img_slider; |
void *img_vol_slider; |
}slider_t; |
typedef struct |
{ |
link_t link; |
link_t child; |
160,12 → 148,11 |
#define MSG_COMMAND 0x030 |
#define MSG_TIMER 0x031 |
#define LBN_DBLCLK 0x100 |
#define LBOX_READDIR 0x100 |
#define LBOX_GETFILENAME 0x101 |
#define PRG_PROGRESS 0x102 |
#define ID_CLOSE 1 |
#define ID_MINIMIZE 2 |
/programs/media/Fplay/winlib/cptleft.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/programs/media/Fplay/winlib/cptright.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/programs/media/Fplay/winlib/frame.c |
---|
5,6 → 5,7 |
#include <stdio.h> |
#include "winlib.h" |
#define CAPTION_HEIGHT 29 |
#define CAPTION_CORNER_W 8 |
#define FRAME_WIDTH 7 |
270,8 → 271,8 |
w = nrc.r - nrc.l; |
h = nrc.b - nrc.t; |
if(w <310) |
w = 310; |
if(w < 150) |
w = 150; |
if(h < 120) |
h = 120; |
/programs/media/Fplay/winlib/panel.c |
---|
4,14 → 4,11 |
#include <stdio.h> |
#include "winlib.h" |
#define PANEL_CORNER_W 8 |
#define PANEL_HEIGHT 55 |
#define PANEL_CORNER_W 16 |
#define FRAME_WIDTH 7 |
#define ID_PLAY 100 |
#define ID_STOP 101 |
#define ID_PROGRESS 102 |
#define ID_VOL_LEVEL 103 |
#define ID_VOL_CTRL 104 |
extern uint32_t main_cursor; |
25,9 → 22,6 |
extern int res_pause_btn[]; |
extern int res_pause_btn_pressed[]; |
extern int res_stop_btn[]; |
extern int res_stop_btn_pressed[]; |
//extern int res_minimize_btn[]; |
//extern int res_minimize_btn_hl[]; |
//extern int res_minimize_btn_pressed[]; |
40,8 → 34,6 |
{ |
button_t *btn; |
progress_t *prg; |
level_t *lvl; |
slider_t *sld; |
panel_t *panel = &win->panel; |
ctx_t *ctx = &panel->ctx; |
52,8 → 44,6 |
panel->ctrl.handler = panel_proc; |
panel->ctrl.parent = (ctrl_t*)win; |
panel->layout = 0; |
ctx->pixmap = user_alloc(1920*PANEL_HEIGHT*4); |
if(!ctx->pixmap) |
{ |
73,23 → 63,9 |
btn->img_hilite = res_pause_btn; |
btn->img_pressed = res_pause_btn_pressed; |
btn = create_button(NULL, ID_STOP,0,19,24,24,&panel->ctrl); |
panel->stop_btn = btn; |
btn->img_default = res_stop_btn; |
btn->img_hilite = res_stop_btn; |
btn->img_pressed = res_stop_btn_pressed; |
prg = create_progress(NULL,ID_PROGRESS,0,4,0,10,&panel->ctrl); |
prg = create_progress(NULL,101,0,4,0,8,&panel->ctrl); |
panel->prg = prg; |
lvl = create_level(NULL, ID_VOL_LEVEL, 0, 20, 96, 10, &panel->ctrl); |
lvl->vol = -1875; |
panel->lvl = lvl; |
sld = create_slider(NULL, ID_VOL_CTRL, 0, 20, 96+12, 12, &panel->ctrl); |
panel->sld = sld; |
// btn = create_button(NULL, ID_MINIMIZE,0,5,16,18,(ctrl_t*)cpt); |
// cpt->minimize_btn = btn; |
97,60 → 73,11 |
// btn->img_hilite = res_minimize_btn_hl; |
// btn->img_pressed = res_minimize_btn_pressed; |
update_panel_size(win); |
return 1; |
}; |
static void panel_update_layout(panel_t *panel) |
{ |
progress_t *prg = panel->prg; |
level_t *lvl = panel->lvl; |
if(panel->layout == 0) |
{ |
prg->ctrl.rc.l = panel->ctrl.rc.l; |
prg->ctrl.rc.t = panel->ctrl.rc.t+7; |
prg->ctrl.rc.r = panel->ctrl.rc.r; |
prg->ctrl.rc.b = prg->ctrl.rc.t + prg->ctrl.h; |
prg->ctrl.w = prg->ctrl.rc.r - prg->ctrl.rc.l; |
lvl->ctrl.rc.l = panel->ctrl.rc.l; |
lvl->ctrl.rc.t = panel->ctrl.rc.t+7; |
lvl->ctrl.rc.r = panel->lvl->ctrl.rc.l + panel->lvl->ctrl.w; |
lvl->ctrl.rc.b = panel->lvl->ctrl.rc.t + panel->lvl->ctrl.h; |
} |
else |
{ |
lvl->ctrl.rc.l = panel->ctrl.rc.l; |
lvl->ctrl.rc.t = panel->ctrl.rc.t+7; |
lvl->ctrl.rc.r = lvl->ctrl.rc.l + lvl->ctrl.w; |
lvl->ctrl.rc.b = lvl->ctrl.rc.t + lvl->ctrl.h; |
prg->ctrl.rc.l = lvl->ctrl.rc.r; |
prg->ctrl.rc.t = panel->ctrl.rc.t+7; |
prg->ctrl.rc.r = panel->ctrl.rc.r; |
prg->ctrl.rc.b = prg->ctrl.rc.t + prg->ctrl.h; |
prg->ctrl.w = prg->ctrl.rc.r - prg->ctrl.rc.l; |
}; |
}; |
void panel_set_layout(panel_t *panel, int layout) |
{ |
panel->layout = layout; |
panel->lvl->visible = layout; |
panel_update_layout(panel); |
send_message(&panel->prg->ctrl, MSG_PAINT, 0, 0); |
if(layout) |
send_message(&panel->lvl->ctrl, MSG_PAINT, 0, 0); |
}; |
void update_panel_size(window_t *win) |
{ |
panel_t *panel = &win->panel; |
188,22 → 115,25 |
panel->ctrl.h = PANEL_HEIGHT; |
win->client.b = win->h-PANEL_HEIGHT; |
panel->play_btn->ctrl.rc.l = win->w/2 - 16; |
panel->play_btn->ctrl.rc.t = panel->ctrl.rc.t+19; |
panel->play_btn->ctrl.rc.r = panel->play_btn->ctrl.rc.l + panel->play_btn->ctrl.w; |
panel->play_btn->ctrl.rc.b = panel->play_btn->ctrl.rc.t + panel->play_btn->ctrl.h; |
panel->play_btn->rc.l = win->w/2 - 16; |
panel->play_btn->rc.t = panel->ctrl.rc.t+19; |
panel->play_btn->rc.r = panel->play_btn->rc.l + panel->play_btn->w; |
panel->play_btn->rc.b = panel->play_btn->rc.t + panel->play_btn->h; |
panel->stop_btn->ctrl.rc.l = win->w/2 - 44; |
panel->stop_btn->ctrl.rc.t = panel->ctrl.rc.t+23; |
panel->stop_btn->ctrl.rc.r = panel->stop_btn->ctrl.rc.l + panel->stop_btn->ctrl.w; |
panel->stop_btn->ctrl.rc.b = panel->stop_btn->ctrl.rc.t + panel->stop_btn->ctrl.h; |
panel->prg->ctrl.rc.l = 8; |
panel->prg->ctrl.rc.t = panel->ctrl.rc.t+7; |
panel->prg->ctrl.rc.r = panel->ctrl.rc.r-8; |
panel->prg->ctrl.rc.b = panel->prg->ctrl.rc.t+8; |
panel->prg->ctrl.w = panel->prg->ctrl.rc.r - |
panel->prg->ctrl.rc.l; |
panel->sld->ctrl.rc.l = panel->ctrl.rc.l; |
panel->sld->ctrl.rc.t = panel->ctrl.rc.t+28; |
panel->sld->ctrl.rc.r = panel->sld->ctrl.rc.l + panel->sld->ctrl.w; |
panel->sld->ctrl.rc.b = panel->sld->ctrl.rc.t + panel->sld->ctrl.h; |
panel->prg->ctrl.h = panel->prg->ctrl.rc.b - |
panel->prg->ctrl.rc.t; |
panel_update_layout(panel); |
// cpt->minimize_btn->rc.l = win->w - 25 - 16 - 5; |
// cpt->minimize_btn->rc.r = cpt->minimize_btn->rc.l + |
// cpt->minimize_btn->w; |
}; |
304,9 → 234,7 |
switch((short)arg1) |
{ |
case ID_PLAY: |
case ID_STOP: |
case ID_PROGRESS: |
case ID_VOL_CTRL: |
case 101: |
win = get_parent_window(ctrl); |
send_message(win, msg, arg1, arg2); |
break; |
/programs/media/Fplay/winlib/panel.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/programs/media/Fplay/winlib/panelleft.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/programs/media/Fplay/winlib/panelright.raw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/programs/media/Fplay/winlib/res2.asm |
---|
25,27 → 25,15 |
public _res_pause_btn |
public _res_pause_btn_pressed |
public _res_stop_btn |
public _res_stop_btn_pressed |
public _res_cursor_ns |
public _res_cursor_we |
public _res_cursor_nwse |
public _res_cursor_nesw |
;public _res_logo |
section '.rdata' data readable align 16 |
public _res_level |
public _res_slider |
public _res_vol_slider |
public _res_progress_bar |
public _res_prg_level |
section '.rdata' data readable align 16 |
_res_caption_left: file 'cptleft.raw' |
_res_caption_right: file 'cptright.raw' |
_res_caption_body: file 'cptbody.raw' |
66,10 → 54,7 |
_res_pause_btn: file 'pausebtn.raw' |
_res_pause_btn_pressed: file 'pausebp.raw' |
_res_stop_btn: file 'stopbtn.raw' |
_res_stop_btn_pressed: file 'stopbtnp.raw' |
_res_minimize_btn: file 'minbn.raw' |
_res_minimize_btn_hl: file 'minbhl.raw' |
_res_minimize_btn_pressed: file 'minbp.raw' |
78,12 → 63,3 |
_res_cursor_we: file 'size_we.cur' |
_res_cursor_nwse: file 'size_nwse.cur' |
_res_cursor_nesw: file 'size_nesw.cur' |
;_res_logo: file 'logo.raw' |
_res_level: file 'vol_level.raw' |
_res_vol_slider: file 'vol_slider.raw' |
_res_slider: file 'slider.raw' |
_res_progress_bar: file 'pbar.raw' |
_res_prg_level: file 'prg_level.raw' |
/programs/media/Fplay/winlib/window.c |
---|
16,9 → 16,6 |
uint32_t cursor_nwse; |
uint32_t cursor_nesw; |
int win_font; |
static pos_t old_pos; |
ctrl_t *mouse_capture = NULL; |
517,26 → 514,9 |
cursor_we = load_cursor(res_cursor_we, LOAD_FROM_MEM); |
cursor_nwse = load_cursor(res_cursor_nwse, LOAD_FROM_MEM); |
cursor_nesw = load_cursor(res_cursor_nesw, LOAD_FROM_MEM); |
win_font = init_fontlib(); |
return 1; |
} |
int fini_winlib() |
{ |
int ret; |
ret = destroy_cursor(cursor_nesw); |
ret |= destroy_cursor(cursor_nwse); |
ret |= destroy_cursor(cursor_we); |
ret |= destroy_cursor(cursor_ns); |
return ret; |
}; |
void init_winlib(void) |
{ |
__asm__ __volatile__( |
589,7 → 569,7 |
__asm__ __volatile__( |
"int $0x40" |
::"a"(73),"b"(0x20),"c"(&bc.dstx)); |
::"a"(73),"b"(0),"c"(&bc.dstx)); |
}; |
/programs/media/Fplay/winlib/winlib.h |
---|
3,9 → 3,6 |
#include "control.h" |
#define CAPTION_HEIGHT 24 |
#define PANEL_HEIGHT 55 |
typedef struct |
{ |
link_t link; |
34,7 → 31,6 |
{ |
ctrl_t ctrl; |
ctx_t ctx; |
char *text; |
ctrl_t *child_over; |
button_t *close_btn; |
button_t *minimize_btn; |
47,12 → 43,8 |
ctx_t ctx; |
rect_t draw; |
ctrl_t *child_over; |
int layout; |
progress_t *prg; |
level_t *lvl; |
slider_t *sld; |
button_t *play_btn; |
button_t *stop_btn; |
}panel_t; |
typedef struct |
119,8 → 111,7 |
int w, int h, ctrl_t *parent); |
progress_t *create_progress(char *caption, int id, int x, int y, |
int w, int h, ctrl_t *parent); |
level_t *create_level(char *caption, int id, int x, int y, |
int w, int h, ctrl_t *parent); |
scroller_t *create_scroller(uint32_t style, int id, int x, int y, |
int w, int h, ctrl_t *parent); |
/programs/media/Fplay/system.h |
---|
264,18 → 264,6 |
return old; |
} |
static inline |
int destroy_cursor(uint32_t cursor) |
{ |
int ret; |
__asm__ __volatile__( |
"int $0x40" |
:"=a"(ret) |
:"a"(37), "b"(6), "c"(cursor) |
:"memory"); |
return ret; |
}; |
static inline void get_proc_info(char *info) |
{ |
__asm__ __volatile__( |
291,7 → 279,7 |
__asm__ __volatile__( |
"int $0x40" |
:"=a"(val) |
:"a"(68),"b"(20),"c"(size),"d"(mem) |
:"a"(68),"b"(12),"c"(size),"d"(mem) |
:"memory"); |
return val; |
/programs/media/Fplay/utils.c |
---|
46,8 → 46,8 |
AVPacketList *q_pkt; |
/* duplicate the packet */ |
// if (av_dup_packet(pkt) < 0) |
// return -1; |
if (av_dup_packet(pkt) < 0) |
return -1; |
q_pkt = av_malloc(sizeof(AVPacketList)); |
if (!q_pkt) |
/programs/media/Fplay/sound.h |
---|
74,7 → 74,6 |
#define SND_SETTIMEBASE 18 |
#define SND_GETTIMESTAMP 19 |
#define SND_RESET_ALL 3 |
#define PLAY_SYNC 0x80000000 |