📄 ebflashplayer.c
字号:
///////////////////////////////////////////////////////////////////////////////
// $Id: ebflashplayer.c,v 1.2 2005/05/27 09:02:24 gaolh Exp $
//
// ebflashplayer.c: the flashplayer Control module.
//
// Copyright (C) 2004 Sheng Runze.
//
// Current maitainer: Sheng Runze.
//
// Create date: 2004/04/31
//
// Modify records:
//
///////////////////////////////////////////////////////////////////////////////
// Who When Where For What Status
//-----------------------------------------------------------------------------
// Sheng Runze 2004/04/31 tcl create create
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <zlib.h>
#include <minigui/network.h>
#include <minigui/flash.h>
#include "ebflashplayer.h"
#include "ebcontrol.h"
#define SRZ_PRINT(x...) fprintf(stderr,x)
#define WIDTH_BORDER 2
#define HEIGHT_CAPTION 16
extern int pm_soundId;
extern int pm_frameId;
static int EBFlashplayerControlProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam);
static void showUrl(char *url, char *target, void *client_data);
static int readFile(char *filename, char **buffer, int *size, int mode);
static void getSwf(char *url, int level, void *client_data);
static long FlashGraphicInitMg(FlashHandle fh, HWND hWnd);
static int ebFlashInit(HWND hWnd,FLASHPLAYERDATA2* pEBFlashData,char * url,int bsound);
static int ebFlashFinish(HWND hWnd,FLASHPLAYERDATA2* pEBFlashData);
static int TimerUpCome(HWND hWnd, PFLASHPLAYERDATA2 pEBFlashplayerData2);
typedef struct
{
FlashDisplay fd;
HWND hwnd;
PBITMAP bmp; // Graphic buffer
} MgContext;
MgContext xc1, *xc=&xc1;
BOOL RegisterEBFlashplayerControl(void)
{
WNDCLASS WndClass;
WndClass.spClassName = CTRL_EBFLASHPLAYER;
WndClass.dwStyle = WS_NONE;
WndClass.dwExStyle = WS_EX_NONE;
WndClass.hCursor = GetSystemCursor (IDC_ARROW);
WndClass.iBkColor = PIXEL_transparent;
WndClass.WinProc = EBFlashplayerControlProc;
return RegisterWindowClass (&WndClass);
}
void EBFlashplayerControlCleanup (void)
{
UnregisterWindowClass(CTRL_EBFLASHPLAYER);
}
static void FlashCopyMg(void)
{
HDC hdc;
hdc = GetClientDC(xc->hwnd);
FillBoxWithBitmap(hdc, 0, 0, xc->fd.width, xc->fd.height, xc->bmp);
ReleaseDC(hdc);
}
static int ebFlashFinish(HWND hWnd,FLASHPLAYERDATA2* pEBFlashData)
{
FLASHPLAYERADDDATA * pAddData = (FLASHPLAYERADDDATA *)(pEBFlashData->data);
if(pEBFlashData->CreateOK)
{
//StopFlashThread(pEBFlashData);
SRZ_PRINT("\nebFlashFinish>>> before FlashClose!!!");
FlashClose(pEBFlashData->flashHandle);
if(pAddData) KillTimer(hWnd,pAddData->timer_id);
pEBFlashData->flashHandle = NULL;
pEBFlashData->CreateOK = 0;
if(xc->bmp)
{
if(xc->bmp->bmBits) free(xc->bmp->bmBits);
free(xc->bmp);
xc->bmp = NULL;
}
SRZ_PRINT("\nebFlashFinish>>> leave!!!");
}
return 0;
}
static int ebFlashInit(HWND hWnd,FLASHPLAYERDATA2* pEBFlashData,char * url,int bsound)
{
int mode, result;
char * p;
char * buffer;
int size;
int status;
int speed, i;
FLASHPLAYERADDDATA * pAddData;
if(pEBFlashData->CreateOK) ebFlashFinish(hWnd,pEBFlashData);
pAddData = (FLASHPLAYERADDDATA *)(pEBFlashData->data);
pEBFlashData->CreateOK = 0;
pEBFlashData->timer_counter = 0;
pEBFlashData->skip = 0;
pEBFlashData->IsPause = 0;
pEBFlashData->nLastTick = 0;
memset(pEBFlashData->strURL,0,512);
strcpy(pEBFlashData->strURL,url);
buffer = NULL;
size = 0;
SRZ_PRINT("url: %s\nIsSound:(%d)\n", pEBFlashData->strURL, bsound);
p = strstr(pEBFlashData->strURL, "http://");
if((p != NULL) && (p == pEBFlashData->strURL))
{
result = DownloadHttpFile(pEBFlashData->strURL, HTTP_METHOD_GET|HTTP_METHOD_WHOLE, &buffer, &size, NULL);
if(result != HTTP_NO_ERROR || !buffer)
{
SRZ_PRINT("download file error!\n"); // to show error msg
if(buffer)
free(buffer);
return -1;
}
mode = SWFReadByBuffer;
}
else
{
mode = SWFReadByFile;
}
if(readFile(pEBFlashData->strURL, &buffer, &size, mode) < 0)
{
free(buffer);
return -1;
}
pEBFlashData->flashHandle = FlashNew();
if(pEBFlashData->flashHandle == 0)
{
if(pEBFlashData) free(pEBFlashData);
free(buffer);
return -3;
}
do
{
status = FlashParse(pEBFlashData->flashHandle, 0, buffer, size);
}while (status & FLASH_PARSE_NEED_DATA);
free(buffer);
if(status == FLASH_PARSE_ERROR)
{
SRZ_PRINT("ERROR: Parse error!\n");
return -1; // to show msg on window
}
FlashGetInfo(pEBFlashData->flashHandle, &pEBFlashData->nflashInfo);
FlashGraphicInitMg(pEBFlashData->flashHandle, hWnd);
if(bsound) FlashSoundInit(pEBFlashData->flashHandle);
FlashSetGetUrlMethod(pEBFlashData->flashHandle, showUrl, 0);
FlashSetGetSwfMethod(pEBFlashData->flashHandle, getSwf, (void*)pEBFlashData->flashHandle);
//speed = 300/pEBFlashData->nflashInfo.frameRate;
speed = 12;
SRZ_PRINT("\nebFlashInit >>frameRate: %d,framecount=%d",
pEBFlashData->nflashInfo.frameRate,pEBFlashData->nflashInfo.frameCount);
SetTimer(hWnd,pAddData->timer_id, speed);
pEBFlashData->CreateOK = 1;
//StartFlashThread(pEBFlashData);
return 0;
}
#if 0
void * myplayframe(void *arg)
{
struct timeval wd;
long cmd;
long wakeUp;
int ret = 0;
FLASHPLAYERDATA2* pEBFlashData = (FLASHPLAYERDATA2*)arg;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
while(pEBFlashData->CreateOK)
{
unsigned long passtick = 0;
unsigned long currTick = 0;
sem_wait(&(pEBFlashData->sem_start));
currTick = GetTickCount();
if(pEBFlashData->nLastTick <= 0)
pEBFlashData->nLastTick = currTick+2;
passtick = currTick - pEBFlashData->nLastTick;
passtick = passtick/2;
if(passtick < 1) passtick = 1;
if(passtick > 20) passtick = 6;
pEBFlashData->timer_counter += passtick;
pEBFlashData->nLastTick = currTick;
while(pEBFlashData->timer_counter > 0)
{
while(pEBFlashData->skip > 0)
{
cmd = FLASH_STEP;
wakeUp = FlashExec(pEBFlashData->flashHandle, cmd, 0, &wd);
pEBFlashData->skip--;
}
if(wakeUp)
{
cmd = FLASH_WAKEUP;
wakeUp = FlashExec(pEBFlashData->flashHandle, cmd, 0, &wd);
pEBFlashData->brefresh = 1;
}
pEBFlashData->skip = pEBFlashData->timer_counter - 1;
pEBFlashData->timer_counter = 0;
}
}
return;
}
void * myplaysound(void *arg)
{
long cmd;
int ret = 0;
FLASHPLAYERDATA2* pEBFlashData = (FLASHPLAYERDATA2*)arg;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
while(pEBFlashData->CreateOK)
{
sem_wait(&(pEBFlashData->sem_start));
cmd = FLASH_SOUND;
ret = FlashExec(pEBFlashData->flashHandle, cmd, 0, NULL);
sem_post(&(pEBFlashData->sem_start));
}
return NULL;
}
int StartFlashThread(FLASHPLAYERDATA2* pEBFlashData)
{
sem_init(&(pEBFlashData->sem_start), 0, 0);
pthread_create(&(pEBFlashData->thread), NULL, myplayframe, (void *)pEBFlashData);
pEBFlashData->bthreadok = 1;
//sem_post(&(pEBFlashData->sem_start));
return 0;
}
void StopFlashThread(FLASHPLAYERDATA2* pEBFlashData)
{
void * thread_result;
if(pEBFlashData->bthreadok == 1)
{
pthread_cancel(pEBFlashData->thread);
pthread_join(pEBFlashData->thread, &thread_result);
pEBFlashData->CreateOK = 0;
sem_destroy(&(pEBFlashData->sem_start));
}
}
#endif
static int EBFlashplayerControlProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
struct timeval wd;
long cmd;
long wakeUp;
FlashEvent fe;
DWORD dwStyle;
int id;
PFLASHPLAYERDATA2 pEBFlashData;
FLASHPLAYERADDDATA * pAddData;
pEBFlashData = (PFLASHPLAYERDATA2)GetWindowAdditionalData2 (hWnd);
id = GetDlgCtrlID (hWnd);
dwStyle = GetWindowStyle (hWnd);
switch (message)
{
case MSG_CREATE:
{
pEBFlashData = (FLASHPLAYERDATA2 *) calloc (1, sizeof(FLASHPLAYERDATA2));
if(pEBFlashData == NULL) return -1; // to show error msg on window
pEBFlashData->data = GetWindowAdditionalData(hWnd);
pAddData = (FLASHPLAYERADDDATA *)(pEBFlashData->data);
if(pAddData && pAddData->url)
{
if(ebFlashInit(hWnd, pEBFlashData, pAddData->url, pAddData->IsSound) != 0)
{
free(pEBFlashData);
SetWindowAdditionalData2(hWnd, (DWORD)0);
return 0;
}
}
SetWindowAdditionalData2(hWnd, (DWORD)pEBFlashData);
}
break;
case MSG_PAINT:
if(pEBFlashData && pEBFlashData->CreateOK)
{
fe.type = FeRefresh;
FlashExec(pEBFlashData->flashHandle, FLASH_EVENT, &fe, &wd);
}
break;
case MSG_TIMER:
if(pEBFlashData && pEBFlashData->CreateOK)
{
/*int cmd,ret;
sem_post(&(pEBFlashData->sem_start));
cmd = FLASH_SOUND;
ret = FlashExec(pEBFlashData->flashHandle, cmd, 0, NULL);
if(xc->fd.flash_refresh)
{
FlashCopyMg();
xc->fd.flash_refresh = 0;
}*/
if(pEBFlashData->nLastTick != 0)
{
unsigned long passtick = 0;
unsigned long currTick = GetTickCount();
passtick = currTick - pEBFlashData->nLastTick;
//if(pEBFlashData->nflashInfo.frameRate > 15)
{
passtick = ((passtick)*(pEBFlashData->nflashInfo.frameRate))/75;
if(passtick > 75)
passtick = 75;
//if(passtick > (pEBFlashData->nflashInfo.frameRate)*3)
// passtick = (pEBFlashData->nflashInfo.frameRate)*3;
}
/*else
{
passtick = ((passtick)*(pEBFlashData->nflashInfo.frameRate))/60;
if(passtick > (pEBFlashData->nflashInfo.frameRate)*6)
passtick = (pEBFlashData->nflashInfo.frameRate)*6;
}*/
if(passtick > 1)
{
pEBFlashData->timer_counter += passtick;
pEBFlashData->nLastTick = currTick;
}
}
else
{
pEBFlashData->nLastTick = GetTickCount();
pEBFlashData->timer_counter = 2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -