summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libflash/libflashplugin.cpp
blob: 538c6955be9b11d95120750fce57e641dcd8a0e7 (plain)
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
/**********************************************************************
** Copyright (C) 2001 Trolltech AS.  All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "libflashplugin.h"

#if 0

bool LibFlashPlugin::audioReadSamples( short *output, int channel, long samples, int stream ) {
}


bool LibFlashPlugin::audioReReadSamples( short *output, int channel, long samples, int stream ) {
}


bool LibFlashPlugin::audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ) {
    samplesRead = samples;
}


bool LibFlashPlugin::audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ) {
}


bool LibFlashPlugin::videoReadFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, ColorFormat color_model, int stream ) {
}


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 ) {
/*
    int format = MPEG3_RGB565;
    switch ( color_model ) {
	case RGB565:	format = MPEG3_RGB565;   break;
	case RGBA8888:	format = MPEG3_RGBA8888; break;
	case BGRA8888:	format = MPEG3_BGRA8888; break;
    }
*/
}


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 ) {
}


FlashHandle file;
FlashDisplay *fd;

#endif


LibFlashPlugin::LibFlashPlugin() {
    file = NULL;
    fd = 0;
}
#include <stdio.h>
#include <stdlib.h>
static int readFile(const char *filename, char **buffer, long *size)
{
    FILE *in;
    char *buf;
    long length;

    printf("read files\n");

    in = fopen(filename,"r");
    if (in == 0) {
	perror(filename);
	return -1;
    }
    fseek(in,0,SEEK_END);
    length = ftell(in);
    rewind(in);
    buf = (char *)malloc(length);
    fread(buf,length,1,in);
    fclose(in);

    *size = length;
    *buffer = buf;

    return length;
}

static void showUrl(char *url, char * /*target*/, void * /*client_data*/) {
    printf("get url\n");
    printf("GetURL : %s\n", url);
}

static void getSwf(char *url, int level, void *client_data) {
    FlashHandle flashHandle = (FlashHandle) client_data;
    char *buffer;
    long size;

    printf("get swf\n");

    printf("LoadMovie: %s @ %d\n", url, level);
    if (readFile(url, &buffer, &size) > 0) {
	FlashParse(flashHandle, level, buffer, size);
    }
}

bool LibFlashPlugin::open( const QString& fileName ) {

    printf("opening file\n");

    delete fd;
    fd = new FlashDisplay;
    fd->pixels = new int[320*240*4];
    fd->width = 200;
    fd->bpl = 320*2;
    fd->height = 300;
    fd->depth = 16;
    fd->bpp = 2;
    fd->flash_refresh = 25;
    fd->clip_x = 0;
    fd->clip_y = 0;
    fd->clip_width = 0;
    fd->clip_height = 0;

    char *buffer;
    long size;
    int status;
    struct FlashInfo fi;

    if (readFile(fileName.latin1(), &buffer, &size) < 0)
	    exit(2);

    if (!(file = FlashNew()))
	    exit(1);

    do
	status = FlashParse(file, 0, buffer, size);
    while (status & FLASH_PARSE_NEED_DATA);

    free(buffer);
    FlashGetInfo(file, &fi);
    //FlashSettings(flashHandle, PLAYER_LOOP);
    FlashGraphicInit(file, fd);
    FlashSoundInit(file, "/dev/dsp");
    FlashSetGetUrlMethod(file, showUrl, 0);
    FlashSetGetSwfMethod(file, getSwf, (void*)file);

    printf("opened file\n");
}

// If decoder doesn't support audio then return 0 here
bool LibFlashPlugin::audioSetSample( long sample, int stream ) { return TRUE; }
long LibFlashPlugin::audioGetSample( int stream ) { return 0; }
//bool LibFlashPlugin::audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ) { return TRUE; }
//bool LibFlashPlugin::audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ) { return FALSE; }
bool LibFlashPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream ) { return FALSE; }
//bool LibFlashPlugin::audioReadSamples( short *output, int channel, long samples, int stream ) { return TRUE; }
//bool LibFlashPlugin::audioReReadSamples( short *output, int channel, long samples, int stream ) { return TRUE; }

// If decoder doesn't support video then return 0 here
int LibFlashPlugin::videoStreams() { return 1; }
int LibFlashPlugin::videoWidth( int stream ) { return 300; }
int LibFlashPlugin::videoHeight( int stream ) { return 200; }
double LibFlashPlugin::videoFrameRate( int stream ) { return 25.0; }
int LibFlashPlugin::videoFrames( int stream ) { return 1000000; }
bool LibFlashPlugin::videoSetFrame( long frame, int stream ) { return TRUE; }
long LibFlashPlugin::videoGetFrame( int stream ) { return 0; }
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; }
#include <time.h>
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 ) {
        struct timeval wd;
        FlashEvent fe;

/*
    delete fd;
    fd = new FlashDisplay;
    fd->pixels = output_rows[0];
    fd->width = 300; // out_w;
    fd->bpl = 640; // out_w*2;
    fd->height = 200;//out_h;
    fd->depth = 16;
    fd->bpp = 2;
    fd->flash_refresh = 50;
    fd->clip_x = 0;//in_x;
    fd->clip_y = 0;//in_y;
    fd->clip_width = 300;//in_w;
    fd->clip_height = 200;//in_h;
    FlashGraphicInit(file, fd);
*/

        long cmd = FLASH_WAKEUP;
        FlashExec(file, cmd, 0, &wd);

	fe.type = FeRefresh;
	cmd = FLASH_EVENT;
        FlashExec(file, cmd, &fe, &wd);
/*
	for (int i = 0; i < out_h; i++)
	    memcpy( output_rows[i], (char*)fd->pixels + i*fd->bpl, QMIN( fd->width * fd->bpp, out_w * fd->bpp ) );
*/	
	memcpy( output_rows[0], (char*)fd->pixels, out_w * out_h * 2 );
}

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; }

// Profiling
double LibFlashPlugin::getTime() { return 0.0; }

// Ignore if these aren't supported
bool LibFlashPlugin::setSMP( int cpus ) { return TRUE; }
bool LibFlashPlugin::setMMX( bool useMMX ) { return TRUE; }