Files
FreeJ/lib/flash/flash.cc
jaromil e277373f70 sound removed from gplflash library,
better optimization flags



git-svn-id: svn://dyne.org/rastasoft/freej/freej@622 383723c8-4afa-0310-b8a8-b1afb83214fc
2005-08-05 21:50:49 +00:00

304 lines
7.0 KiB
C++

/////////////////////////////////////////////////////////////
// Flash Plugin and Player
// Copyright (C) 1998,1999 Olivier Debon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
///////////////////////////////////////////////////////////////
// Author : Olivier Debon <odebon@club-internet.fr>
//
#include "swf.h"
#include "graphic16.h"
#include "graphic24.h"
#include "graphic32.h"
#ifdef RCSID
static char *rcsid = "$Id: flash.cc,v 1.4 2004/12/22 18:58:30 tgc Exp $";
#endif
// Interface with standard C
extern "C" {
FlashHandle
FlashNew()
{
FlashMovie *fh;
fh = new FlashMovie;
fh->main = new CInputScript;
return (FlashHandle)fh;
}
int
FlashParse(FlashHandle flashHandle, int level, char *data, long size)
{
FlashMovie *fh;
CInputScript *script;
int status = FLASH_PARSE_ERROR;
fh = (FlashMovie *)flashHandle;
for(script = fh->main; script != NULL; script = script->next) {
if (script->level == level) {
status = script->ParseData(fh, data, size);
if (status & FLASH_PARSE_START) {
fh->msPerFrame = 1000/fh->main->frameRate;
script->program->rewindMovie();
}
break;
}
}
return status;
}
void
FlashGetInfo(FlashHandle flashHandle, struct FlashInfo *fi)
{
FlashMovie *fh;
fh = (FlashMovie *)flashHandle;
fi->version = fh->main->m_fileVersion;
fi->frameRate = fh->main->frameRate;
fi->frameCount = fh->main->frameCount;
fi->frameWidth = fh->main->frameRect.xmax - fh->main->frameRect.xmin;
fi->frameHeight = fh->main->frameRect.ymax - fh->main->frameRect.ymin;
fi->fileFormat = 0;
// Add file format field info]
if( TRUE == fh->main->m_bCompressed )
fi->fileFormat |= FLASH_COMPRESSED;
if( TRUE == fh->main->m_bExe )
fi->fileFormat |= FLASH_EXE;
}
long FlashGraphicInit(FlashHandle flashHandle, FlashDisplay *fd)
{
FlashMovie *fh;
fh = (FlashMovie *)flashHandle;
switch (fd->bpp) {
case 4:
fh->gd = new GraphicDevice32(fd);
break;
case 3:
fh->gd = new GraphicDevice24(fd);
break;
case 2:
fh->gd = new GraphicDevice16(fd);
break;
default:
fprintf(stderr, "Unsupported depth\n");
}
fh->gd->setMovieDimension(fh->main->frameRect.xmax - fh->main->frameRect.xmin,
fh->main->frameRect.ymax - fh->main->frameRect.ymin);
return 1; // Ok
}
void
FlashSoundInit(FlashHandle flashHandle, char *device)
{
FlashMovie *fh;
fh = (FlashMovie *)flashHandle;
}
void
FlashZoom(FlashHandle flashHandle, int zoom)
{
FlashMovie *fh;
fh = (FlashMovie *)flashHandle;
fh->gd->setMovieZoom(zoom);
}
void
FlashOffset(FlashHandle flashHandle, int x, int y)
{
FlashMovie *fh;
fh = (FlashMovie *)flashHandle;
fh->gd->setMovieOffset(x,y);
}
long
FlashExec(FlashHandle flashHandle, long flag,
FlashEvent *fe, struct timeval *wakeDate)
{
FlashMovie *fh;
long wakeUp = 0;
struct timeval time_correction;
unsigned int cor_sec, cor_usec;
gettimeofday(&time_correction,0);
fh = (FlashMovie *)flashHandle;
if (fh->main == NULL) return 0; // Not ready
if (fh->main->program == NULL) return 0; // Not ready
if (fh->main->program->nbFrames == 0) return 0; // Still not ready
// Sometimes we arrive a bit later or even earlier than expected.
// It's usually not by much, but it tends to add up
// so figure out how far off we are and compensate for the next time
if (fh->main->program->currentFrame!=0) {
cor_sec= time_correction.tv_sec-wakeDate->tv_sec;
cor_usec= time_correction.tv_usec-wakeDate->tv_usec;
}
else {
cor_sec=0;
cor_usec=0;
}
if (fh->gd == 0) return 0;
switch (flag & FLASH_CMD_MASK) {
case FLASH_STOP:
fh->main->program->pauseMovie();
wakeUp = 0;
break;
case FLASH_CONT:
fh->main->program->continueMovie();
wakeUp = FLASH_STATUS_WAKEUP;
break;
case FLASH_REWIND:
fh->main->program->rewindMovie();
wakeUp = 0;
break;
case FLASH_STEP:
fh->main->program->nextStepMovie();
wakeUp = 0;
break;
}
if (flag & FLASH_WAKEUP) {
// Compute next wakeup time
gettimeofday(wakeDate,0);
wakeDate->tv_usec += fh->msPerFrame*1000;
wakeDate->tv_sec -= cor_sec;
wakeDate->tv_usec -= cor_usec;
if (wakeDate->tv_usec > 1000000) {
wakeDate->tv_usec -= 1000000;
wakeDate->tv_sec++;
}
// Play frame
wakeUp = fh->processMovie(fh->gd);
}
if (checkFlashTimer(&fh->scheduledTime)) {
if (fh->handleEvent(fh->gd, &fh->scheduledEvent)) {
wakeUp = 1;
}
setFlashTimer(&fh->scheduledTime, -1);
}
if (flag & FLASH_EVENT) {
wakeUp = fh->handleEvent(fh->gd, fe);
if (wakeUp) {
/* Wake up at once, except for mouse move (40 ms after) */
/* commenting this part out makes the plugin/player more
* usable, since now it doesn't stop when moving the mouse,
* except for moving it over buttons
gettimeofday(wakeDate,0);
if (fe->type == FeMouseMove) {
wakeDate->tv_usec += 40*1000;
if (wakeDate->tv_usec > 1000000) {
wakeDate->tv_usec -= 1000000;
wakeDate->tv_sec++;
}
}*/
}
}
return wakeUp || (fh->scheduledTime.tv_sec != -1);
}
void FlashSetGetSwfMethod(FlashHandle flashHandle, void (*getSwf)(char *url, int level, void *clientData), void *clientData)
{
FlashMovie *fh;
fh = (FlashMovie *)flashHandle;
fh->getSwf = getSwf;
fh->getSwfClientData = clientData;
}
void
FlashSetCursorOnOffMethod(FlashHandle flashHandle, void (*cursorOnOff)(int , void *), void *clientData)
{
FlashMovie *fh;
fh = (FlashMovie *)flashHandle;
fh->cursorOnOff = cursorOnOff;
fh->cursorOnOffClientData = clientData;
}
void
FlashSetGetUrlMethod(FlashHandle flashHandle, void (*getUrl)(char *, char *, void *), void *clientData)
{
FlashMovie *fh;
fh = (FlashMovie *)flashHandle;
fh->getUrl = getUrl;
fh->getUrlClientData = clientData;
}
void
FlashClose(FlashHandle flashHandle)
{
FlashMovie *fh;
fh = (FlashMovie *)flashHandle;
delete fh;
}
void
FlashSettings(FlashHandle flashHandle, long settings)
{
FlashMovie *fh;
fh = (FlashMovie *)flashHandle;
fh->main->program->modifySettings( settings );
}
int shape_size,shape_nb,shaperecord_size,shaperecord_nb,style_size,style_nb;
void flash_dump(void)
{
printf("flash: shape_size=%d (nb=%d)\n",shape_size,shape_nb);
printf("flash: shaperecord_size=%d (nb=%d)\n",shaperecord_size,shaperecord_nb);
printf("flash: style_size=%d (nb=%d)\n",style_size,style_nb);
}
}; /* end of extern C */