Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

libflashplugin.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2001 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #include "libflashplugin.h"
00021 
00022 #if 0
00023 
00024 bool LibFlashPlugin::audioReadSamples( short *output, int channel, long samples, int stream ) {
00025 }
00026 
00027 
00028 bool LibFlashPlugin::audioReReadSamples( short *output, int channel, long samples, int stream ) {
00029 }
00030 
00031 
00032 bool LibFlashPlugin::audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ) {
00033     samplesRead = samples;
00034 }
00035 
00036 
00037 bool LibFlashPlugin::audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ) {
00038 }
00039 
00040 
00041 bool LibFlashPlugin::videoReadFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, ColorFormat color_model, int stream ) {
00042 }
00043 
00044 
00045 bool LibFlashPlugin::videoReadScaledFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, int out_w, int out_h, ColorFormat color_model, int stream ) {
00046 /*
00047     int format = MPEG3_RGB565;
00048     switch ( color_model ) {
00049         case RGB565:    format = MPEG3_RGB565;   break;
00050         case RGBA8888:  format = MPEG3_RGBA8888; break;
00051         case BGRA8888:  format = MPEG3_BGRA8888; break;
00052     }
00053 */
00054 }
00055 
00056 
00057 bool LibFlashPlugin::videoReadYUVFrame( char *y_output, char *u_output, char *v_output, int in_x, int in_y, int in_w, int in_h, int stream ) {
00058 }
00059 
00060 
00061 FlashHandle file;
00062 FlashDisplay *fd;
00063 
00064 #endif
00065 
00066 
00067 LibFlashPlugin::LibFlashPlugin() {
00068     file = NULL;
00069     fd = 0;
00070 }
00071 #include <stdio.h>
00072 #include <stdlib.h>
00073 static int readFile(const char *filename, char **buffer, long *size)
00074 {
00075     FILE *in;
00076     char *buf;
00077     long length;
00078 
00079     printf("read files\n");
00080 
00081     in = fopen(filename,"r");
00082     if (in == 0) {
00083         perror(filename);
00084         return -1;
00085     }
00086     fseek(in,0,SEEK_END);
00087     length = ftell(in);
00088     rewind(in);
00089     buf = (char *)malloc(length);
00090     fread(buf,length,1,in);
00091     fclose(in);
00092 
00093     *size = length;
00094     *buffer = buf;
00095 
00096     return length;
00097 }
00098 
00099 static void showUrl(char *url, char * /*target*/, void * /*client_data*/) {
00100     printf("get url\n");
00101     printf("GetURL : %s\n", url);
00102 }
00103 
00104 static void getSwf(char *url, int level, void *client_data) {
00105     FlashHandle flashHandle = (FlashHandle) client_data;
00106     char *buffer;
00107     long size;
00108 
00109     printf("get swf\n");
00110 
00111     printf("LoadMovie: %s @ %d\n", url, level);
00112     if (readFile(url, &buffer, &size) > 0) {
00113         FlashParse(flashHandle, level, buffer, size);
00114     }
00115 }
00116 
00117 bool LibFlashPlugin::open( const QString& fileName ) {
00118 
00119     printf("opening file\n");
00120 
00121     delete fd;
00122     fd = new FlashDisplay;
00123     fd->pixels = new int[320*240*4];
00124     fd->width = 200;
00125     fd->bpl = 320*2;
00126     fd->height = 300;
00127     fd->depth = 16;
00128     fd->bpp = 2;
00129     fd->flash_refresh = 25;
00130     fd->clip_x = 0;
00131     fd->clip_y = 0;
00132     fd->clip_width = 0;
00133     fd->clip_height = 0;
00134 
00135     char *buffer;
00136     long size;
00137     int status;
00138     struct FlashInfo fi;
00139 
00140     if (readFile(fileName.latin1(), &buffer, &size) < 0)
00141             exit(2);
00142 
00143     if (!(file = FlashNew()))
00144             exit(1);
00145 
00146     do
00147         status = FlashParse(file, 0, buffer, size);
00148     while (status & FLASH_PARSE_NEED_DATA);
00149 
00150     free(buffer);
00151     FlashGetInfo(file, &fi);
00152     //FlashSettings(flashHandle, PLAYER_LOOP);
00153     FlashGraphicInit(file, fd);
00154 #ifdef QT_QWS_DEVFS
00155     FlashSoundInit(file, "/dev/sound/dsp");
00156 #else
00157     FlashSoundInit(file, "/dev/dsp");
00158 #endif
00159     FlashSetGetUrlMethod(file, showUrl, 0);
00160     FlashSetGetSwfMethod(file, getSwf, (void*)file);
00161 
00162     printf("opened file\n");
00163 }
00164 
00165 // If decoder doesn't support audio then return 0 here
00166 bool LibFlashPlugin::audioSetSample( long sample, int stream ) { return TRUE; }
00167 long LibFlashPlugin::audioGetSample( int stream ) { return 0; }
00168 //bool LibFlashPlugin::audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ) { return TRUE; }
00169 //bool LibFlashPlugin::audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ) { return FALSE; }
00170 bool LibFlashPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream ) { return FALSE; }
00171 //bool LibFlashPlugin::audioReadSamples( short *output, int channel, long samples, int stream ) { return TRUE; }
00172 //bool LibFlashPlugin::audioReReadSamples( short *output, int channel, long samples, int stream ) { return TRUE; }
00173 
00174 // If decoder doesn't support video then return 0 here
00175 int LibFlashPlugin::videoStreams() { return 1; }
00176 int LibFlashPlugin::videoWidth( int stream ) { return 300; }
00177 int LibFlashPlugin::videoHeight( int stream ) { return 200; }
00178 double LibFlashPlugin::videoFrameRate( int stream ) { return 25.0; }
00179 int LibFlashPlugin::videoFrames( int stream ) { return 1000000; }
00180 bool LibFlashPlugin::videoSetFrame( long frame, int stream ) { return TRUE; }
00181 long LibFlashPlugin::videoGetFrame( int stream ) { return 0; }
00182 bool LibFlashPlugin::videoReadFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, ColorFormat color_model, int stream ) { return TRUE; }
00183 #include <time.h>
00184 bool LibFlashPlugin::videoReadScaledFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, int out_w, int out_h, ColorFormat color_model, int stream ) {
00185         struct timeval wd;
00186         FlashEvent fe;
00187 
00188 /*
00189     delete fd;
00190     fd = new FlashDisplay;
00191     fd->pixels = output_rows[0];
00192     fd->width = 300; // out_w;
00193     fd->bpl = 640; // out_w*2;
00194     fd->height = 200;//out_h;
00195     fd->depth = 16;
00196     fd->bpp = 2;
00197     fd->flash_refresh = 50;
00198     fd->clip_x = 0;//in_x;
00199     fd->clip_y = 0;//in_y;
00200     fd->clip_width = 300;//in_w;
00201     fd->clip_height = 200;//in_h;
00202     FlashGraphicInit(file, fd);
00203 */
00204 
00205         long cmd = FLASH_WAKEUP;
00206         FlashExec(file, cmd, 0, &wd);
00207 
00208         fe.type = FeRefresh;
00209         cmd = FLASH_EVENT;
00210         FlashExec(file, cmd, &fe, &wd);
00211 /*
00212         for (int i = 0; i < out_h; i++)
00213             memcpy( output_rows[i], (char*)fd->pixels + i*fd->bpl, QMIN( fd->width * fd->bpp, out_w * fd->bpp ) );
00214 */      
00215         memcpy( output_rows[0], (char*)fd->pixels, out_w * out_h * 2 );
00216 }
00217 
00218 bool LibFlashPlugin::videoReadYUVFrame( char *y_output, char *u_output, char *v_output, int in_x, int in_y, int in_w, int in_h, int stream ) { return TRUE; }
00219 
00220 // Profiling
00221 double LibFlashPlugin::getTime() { return 0.0; }
00222 
00223 // Ignore if these aren't supported
00224 bool LibFlashPlugin::setSMP( int cpus ) { return TRUE; }
00225 bool LibFlashPlugin::setMMX( bool useMMX ) { return TRUE; }
00226 
00227 

Generated on Sat Nov 5 16:15:35 2005 for OPIE by  doxygen 1.4.2