Mercurial > hg > easaier-soundaccess
comparison data/fileio/VideoFileReader.cpp @ 167:2ac52ea3c1c4
video mouse events are in SDL now.
The code is really better now, but there is a display bug when you zoom in, zoom out
author | benoitrigolleau |
---|---|
date | Fri, 16 Nov 2007 15:18:44 +0000 |
parents | c946c19e6329 |
children | be6d31baecb9 |
comparison
equal
deleted
inserted
replaced
166:0442224a9553 | 167:2ac52ea3c1c4 |
---|---|
18 //#include "system/System.h" | 18 //#include "system/System.h" |
19 | 19 |
20 #include <sys/types.h> | 20 #include <sys/types.h> |
21 #include <sys/stat.h> | 21 #include <sys/stat.h> |
22 #include <fcntl.h> | 22 #include <fcntl.h> |
23 #include <cassert> | |
23 | 24 |
24 #include <iostream> | 25 #include <iostream> |
25 | 26 |
26 #include <QApplication> | 27 #include <QApplication> |
27 #include <QFileInfo> | 28 #include <QFileInfo> |
30 #include "VideoFileReader.h" | 31 #include "VideoFileReader.h" |
31 | 32 |
32 #ifdef WIN32 | 33 #ifdef WIN32 |
33 #include <Windows.h> | 34 #include <Windows.h> |
34 #endif | 35 #endif |
35 extern float zoomFivan; | |
36 long long countFreq; | 36 long long countFreq; |
37 int Videow=320; | 37 int Videow=320; |
38 int Videoh=240; | 38 int Videoh=240; |
39 float zoomFivan=1; | |
39 VideoFileReader::VideoFileReader(QString path, bool showProgress, CacheMode mode) : | 40 VideoFileReader::VideoFileReader(QString path, bool showProgress, CacheMode mode) : |
40 CodedAudioFileReader(mode), | 41 CodedAudioFileReader(mode), |
41 m_path(path) | 42 m_path(path) |
42 { | 43 { |
43 m_frameCount = 0; | 44 m_frameCount = 0; |
45 m_sampleRate = 0; | 46 m_sampleRate = 0; |
46 m_fileSize = 0; | 47 m_fileSize = 0; |
47 m_bitrateNum = 0; | 48 m_bitrateNum = 0; |
48 m_bitrateDenom = 0; | 49 m_bitrateDenom = 0; |
49 m_cancelled = false; | 50 m_cancelled = false; |
51 m_zoomfactor = 1; | |
50 | 52 |
51 struct stat stat; | 53 struct stat stat; |
52 if (::stat(path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) { | 54 if (::stat(path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) { |
53 m_error = QString("File %1 does not exist.").arg(path); | 55 m_error = QString("File %1 does not exist.").arg(path); |
54 return; | 56 return; |
193 // we get the size from our active video stream, if no active video stream | 195 // we get the size from our active video stream, if no active video stream |
194 // exists, width and height are set to default values (320x240) | 196 // exists, width and height are set to default values (320x240) |
195 SDL_ffmpegGetVideoSize(file, &w, &h); | 197 SDL_ffmpegGetVideoSize(file, &w, &h); |
196 | 198 |
197 MainWindow * MWins=MainWindow::instance(); | 199 MainWindow * MWins=MainWindow::instance(); |
200 | |
201 | |
202 | |
203 SDL_Init(SDL_INIT_VIDEO); | |
204 Videow=w;//=320*m_zoomfactor; | |
205 Videoh=h;//=240*m_zoomfactor; | |
206 | |
207 //TODO update the size according to the component size | |
208 // this will not work if video size is bigger than window size. | |
209 m_width =w; | |
210 m_height =h; | |
211 | |
198 MWins->setSDLInitSize(w,h); | 212 MWins->setSDLInitSize(w,h); |
199 | |
200 | |
201 SDL_Init(SDL_INIT_VIDEO); | |
202 Videow=w=320*zoomFivan; | |
203 Videoh=h=240*zoomFivan; | |
204 // Open the Video device | 213 // Open the Video device |
205 screen = SDL_SetVideoMode(w, h, 0, SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); | 214 screen = SDL_SetVideoMode(w, h, 0, SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); |
206 //SDL_WM_SetCaption("EASAIER Video Player", "EASAIER Video Player"); | 215 //SDL_WM_SetCaption("EASAIER Video Player", "EASAIER Video Player"); |
207 if(!screen) { | 216 if(!screen) { |
208 printf("Couldn't open video: %s\n", SDL_GetError()); | 217 fprintf(stderr, "Couldn't open video: %s\n", SDL_GetError()); |
209 return false; | 218 return false; |
210 } | 219 } |
211 return true; | 220 return true; |
212 } | 221 } |
213 | 222 |
214 int VideoFileReader::videoPlayCall(void *t) | 223 int VideoFileReader::videoPlayCall(void *t) |
215 { | 224 { |
216 return ((VideoFileReader *)t)->videoPlay(); | 225 return ((VideoFileReader *)t)->videoPlay(); |
217 } | 226 } |
227 | |
228 void VideoFileReader::processEvents() | |
229 { | |
230 SDL_Event event; | |
231 | |
232 while (SDL_PollEvent(&event)) | |
233 { | |
234 float signe = 1; | |
235 switch (event.type) | |
236 { | |
237 case SDL_MOUSEMOTION: | |
238 break; | |
239 case SDL_MOUSEBUTTONDOWN: | |
240 switch(event.button.button){ | |
241 case SDL_BUTTON_LEFT : | |
242 break; | |
243 case SDL_BUTTON_MIDDLE: | |
244 break; | |
245 case SDL_BUTTON_RIGHT: | |
246 break; | |
247 default: | |
248 break; | |
249 } | |
250 break; | |
251 case SDL_MOUSEBUTTONUP: | |
252 | |
253 switch(event.button.button){ | |
254 case SDL_BUTTON_LEFT : | |
255 break; | |
256 case SDL_BUTTON_MIDDLE: | |
257 break; | |
258 case SDL_BUTTON_RIGHT: | |
259 break; | |
260 case SDL_BUTTON_WHEELDOWN: | |
261 signe = -1; | |
262 case SDL_BUTTON_WHEELUP: | |
263 float f,f2; | |
264 f = m_zoomfactor + signe * 0.1; | |
265 f2 = f; | |
266 if((int)(m_width*f+0.5)%4){ | |
267 f = (m_width*f - (int)(m_width*f+0.5)%4)/m_width; | |
268 } | |
269 m_zoomfactor=f; | |
270 | |
271 break; | |
272 default: | |
273 break; | |
274 } | |
275 break; | |
276 | |
277 default: | |
278 break; | |
279 } | |
280 } | |
281 } | |
218 | 282 |
219 int | 283 int |
220 VideoFileReader::videoPlay() | 284 VideoFileReader::videoPlay() |
221 { | 285 { |
222 | 286 |
241 film->timer=film->timer/(film->countFreq); | 305 film->timer=film->timer/(film->countFreq); |
242 film->timebase=1; | 306 film->timebase=1; |
243 film->vs[film->videoStream]->lastTimeStamp=0; | 307 film->vs[film->videoStream]->lastTimeStamp=0; |
244 while( film->videoThreadActive ) { | 308 while( film->videoThreadActive ) { |
245 | 309 |
246 if (!(w==(int)(320*zoomFivan))){ | 310 if (!(w==(int)(Videow*m_zoomfactor))){ |
247 w=320*zoomFivan; | 311 w=Videow*m_zoomfactor; |
248 h=240*zoomFivan; | 312 h=Videoh*m_zoomfactor; |
249 // Open the Video device | 313 if (w<80 || h<60){ |
250 screen = SDL_SetVideoMode(w, h, 0, SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); | 314 w=80; |
251 } | 315 h=60; |
316 m_zoomfactor = 80.0/Videow; | |
317 } | |
318 // Open the Video device | |
319 zoomFivan = m_zoomfactor; | |
320 screen = SDL_SetVideoMode(w, h, 0, SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); | |
321 MWins->setSDLInitSize(w,h); | |
322 m_width =w; | |
323 m_height =h; | |
324 | |
325 } | |
326 // calls process events function, to take in account the user input | |
327 processEvents(); | |
252 if (MWins->isAudioPlaying()) | 328 if (MWins->isAudioPlaying()) |
253 { | 329 { |
254 if ((SDL_ffmpegGetState(film))||((long)(abs((long)(film->audioTime - (int64_t)(MWins->Get_CurAudioTime()))))>=1000)) | 330 if ((SDL_ffmpegGetState(film))||((long)(abs((long)(film->audioTime - (int64_t)(MWins->Get_CurAudioTime()))))>=1000)) |
255 { | 331 { |
256 //SDL_Delay(1000); | 332 //SDL_Delay(1000); |