comparison sv/videoio/SDL_ffmpeg.cpp @ 256:6eeb195adbb4

Video works fine now. Ivan fixed bugs.
author benoitrigolleau
date Tue, 17 Jun 2008 11:59:02 +0000
parents f0e9330bee36
children
comparison
equal deleted inserted replaced
255:1f26f21febd9 256:6eeb195adbb4
44 #include "../../sv/main/MainWindow.h" 44 #include "../../sv/main/MainWindow.h"
45 #include <time.h> 45 #include <time.h>
46 46
47 //const int SDL_FFMPEG_MAX_BUFFERED_FRAMES = 25; 47 //const int SDL_FFMPEG_MAX_BUFFERED_FRAMES = 25;
48 //const int SDL_FFMPEG_MAX_BUFFERED_SAMPLES = 512 * 512; 48 //const int SDL_FFMPEG_MAX_BUFFERED_SAMPLES = 512 * 512;
49 extern float zoomFivan; 49 extern int zoomWivan;
50 extern int zoomHivan;
50 int FFMPEG_init_was_called = 0; 51 int FFMPEG_init_was_called = 0;
51 FILE *pFile, *tFile; 52 //FILE *pFile, *tFile;
52 int64_t Time,Time1; 53 int64_t Time,Time1;
53 int64_t realt=0; 54 int64_t realt=0;
54 55
55 SDL_ffmpegFile* SDL_ffmpegCreateFile() { 56 SDL_ffmpegFile* SDL_ffmpegCreateFile() {
56 57
61 // create a semaphore for every file 62 // create a semaphore for every file
62 file->decode = SDL_CreateSemaphore(1); 63 file->decode = SDL_CreateSemaphore(1);
63 64
64 Time=0; 65 Time=0;
65 Time1=0; 66 Time1=0;
66 fopen_s (&pFile,"myfile.txt","w"); 67 //fopen_s (&pFile,"myfile.txt","w");
67 fopen_s (&tFile,"Timestampfile.txt","w"); 68 // fopen_s (&tFile,"Timestampfile.txt","w");
68 // allocate room for VStreams 69 // allocate room for VStreams
69 file->vs = (SDL_ffmpegStream**)malloc( sizeof(SDL_ffmpegStream*) * MAX_STREAMS ); 70 file->vs = (SDL_ffmpegStream**)malloc( sizeof(SDL_ffmpegStream*) * MAX_STREAMS );
70 if(!file->vs) { 71 if(!file->vs) {
71 free( file ); 72 free( file );
72 return 0; 73 return 0;
266 float ratio; 267 float ratio;
267 int64_t pos,pos1, pos2, timestamp; 268 int64_t pos,pos1, pos2, timestamp;
268 //for(i=0; i<SDL_FFMPEG_MAX_BUFFERED_FRAMES; i++) { 269 //for(i=0; i<SDL_FFMPEG_MAX_BUFFERED_FRAMES; i++) {
269 pos=MWinsA->Get_CurAudioTime(); 270 pos=MWinsA->Get_CurAudioTime();
270 271
271 if (pFile) 272 /* if (pFile)
272 { 273 {
273 fprintf (pFile, "p: \t %u\t", pos); 274 fprintf (pFile, "p: \t %u\t", pos);
274 } 275 }*/
275 //if (MWinsA->Get_HardwareBufferTime()==0) 276 //if (MWinsA->Get_HardwareBufferTime()==0)
276 // pos1=0; 277 // pos1=0;
277 //else { 278 //else {
278 // pos1=MWinsA->Get_HardwareBufferTime(); 279 // pos1=MWinsA->Get_HardwareBufferTime();
279 // //fprintf (tFile, "%u\t", pos1); 280 // //fprintf (tFile, "%u\t", pos1);
282 // 283 //
283 // pos1=(timeTemp-pos1)/(file->countFreq*hopfactor); 284 // pos1=(timeTemp-pos1)/(file->countFreq*hopfactor);
284 // fprintf (pFile, "%u\t", pos1); 285 // fprintf (pFile, "%u\t", pos1);
285 //} 286 //}
286 //pos2=pos+pos1; 287 //pos2=pos+pos1;
287 if (pFile) 288 /*if (pFile)
288 { 289 {
289 fprintf (pFile, "%u\n", pos); 290 fprintf (pFile, "%u\n", pos);
290 } 291 }*/
291 292
292 // if this entry does not exist, continue 293 // if this entry does not exist, continue
293 while(((file->vs[file->videoStream]->writeImage - file->vs[file->videoStream]->readImage)>0)&&(file->vs[file->videoStream]->imageBuffer[file->vs[file->videoStream]->readImage%SDL_FFMPEG_MAX_BUFFERED_FRAMES]->timestamp <= pos + ((AVFormatContext*)file->_ffmpeg)->start_time/1000))//&& (file->vs[file->videoStream]->imageBuffer[file->vs[file->videoStream]->readImage%SDL_FFMPEG_MAX_BUFFERED_FRAMES]->timestamp >= pos - file->timebase+ ((AVFormatContext*)file->_ffmpeg)->start_time/1000)) 294 while(((file->vs[file->videoStream]->writeImage - file->vs[file->videoStream]->readImage)>0)&&(file->vs[file->videoStream]->imageBuffer[file->vs[file->videoStream]->readImage%SDL_FFMPEG_MAX_BUFFERED_FRAMES]->timestamp <= pos + ((AVFormatContext*)file->_ffmpeg)->start_time/1000))//&& (file->vs[file->videoStream]->imageBuffer[file->vs[file->videoStream]->readImage%SDL_FFMPEG_MAX_BUFFERED_FRAMES]->timestamp >= pos - file->timebase+ ((AVFormatContext*)file->_ffmpeg)->start_time/1000))
294 { 295 {
295 //pos=MWinsA->Get_CurAudioTime(); 296 //pos=MWinsA->Get_CurAudioTime();
331 } 332 }
332 } 333 }
333 334
334 335
335 pos=MWinsA->Get_CurAudioTime(); 336 pos=MWinsA->Get_CurAudioTime();
336 if (pFile) 337 /* if (pFile)
337 { 338 {
338 fprintf (pFile, "e:\t%u\t", pos); 339 fprintf (pFile, "e:\t%u\t", pos);
339 } 340 }*/
340 //if (MWinsA->Get_HardwareBufferTime()==0) 341 //if (MWinsA->Get_HardwareBufferTime()==0)
341 // pos1=0; 342 // pos1=0;
342 //else { 343 //else {
343 // pos1=MWinsA->Get_HardwareBufferTime(); 344 // pos1=MWinsA->Get_HardwareBufferTime();
344 // //fprintf (tFile, "%u\t", pos1); 345 // //fprintf (tFile, "%u\t", pos1);
374 tt=tt/(file->countFreq)-file->timer; 375 tt=tt/(file->countFreq)-file->timer;
375 376
376 QueryPerformanceCounter((LARGE_INTEGER *)(&file->timer)); 377 QueryPerformanceCounter((LARGE_INTEGER *)(&file->timer));
377 file->timer=file->timer/(file->countFreq); 378 file->timer=file->timer/(file->countFreq);
378 realt+=tt; 379 realt+=tt;
379 fprintf (tFile, "%u\t", x); 380 /*fprintf (tFile, "%u\t", x);
380 fprintf (tFile, "%u\t", realt); 381 fprintf (tFile, "%u\t", realt);
381 fprintf (tFile, "%u\t", tt); 382 fprintf (tFile, "%u\t", tt);*/
382 timestamp=(pos-option->timestamp+((AVFormatContext*)file->_ffmpeg)->start_time/1000)/MWinsA->getPlaySpeedVal(); 383 timestamp=(pos-option->timestamp+((AVFormatContext*)file->_ffmpeg)->start_time/1000)/MWinsA->getPlaySpeedVal();
383 fprintf (tFile, "%u\t", pos);//+ (file->vs[file->videoStream]->timeBase)/4+((AVFormatContext*)file->_ffmpeg)->start_time/1000); 384 /*fprintf (tFile, "%u\t", option->timestamp);//+ (file->vs[file->videoStream]->timeBase)/4+((AVFormatContext*)file->_ffmpeg)->start_time/1000);
384 fprintf (tFile, "%d\n", timestamp); 385 fprintf (tFile, "%d\n", timestamp);*/
385 // we did found an option, so we return the imagedata 386 // we did found an option, so we return the imagedata
386 return option->img; 387 return option->img;
387 } 388 }
388 389
389 int SDL_ffmpegReleaseVideo(SDL_ffmpegFile *file, SDL_Surface *bmp) { 390 int SDL_ffmpegReleaseVideo(SDL_ffmpegFile *file, SDL_Surface *bmp) {
617 } 618 }
618 619
619 // if new timestamp is from future, we proceed 620 // if new timestamp is from future, we proceed
620 // if(buf->timestamp >= SDL_ffmpegGetPosition(file)) 621 // if(buf->timestamp >= SDL_ffmpegGetPosition(file))
621 // { 622 // {
622 int w=(int)(zoomFivan*320+0.5); 623 int w=zoomWivan;//(int)(zoomFivan*320+0.5);
623 int h=(int)(zoomFivan*240+0.5); 624 int h=zoomHivan;//(int)(zoomFivan*240+0.5);
624 //if ((w>file->vs[file->videoStream]->width)||(h>file->vs[file->videoStream]->height)){ 625 //if ((w>file->vs[file->videoStream]->width)||(h>file->vs[file->videoStream]->height)){
625 // w=file->vs[file->videoStream]->width; 626 // w=file->vs[file->videoStream]->width;
626 // h=file->vs[file->videoStream]->height; 627 // h=file->vs[file->videoStream]->height;
627 //} 628 //}
628 // Be sure we have a multiple of 4 629 // Be sure we have a multiple of 4