1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
/////////////////////////////////////////////////////////////
// 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 */
|