Mercurial > hg > easaier-soundaccess
diff data/fileio/VideoFileReader.cpp @ 191:be6d31baecb9
compilation under linux - kunbuntu V7.10 (without video support)
author | lbajardsilogic |
---|---|
date | Wed, 28 Nov 2007 13:03:45 +0000 |
parents | 2ac52ea3c1c4 |
children | 6eeb195adbb4 |
line wrap: on
line diff
--- a/data/fileio/VideoFileReader.cpp Tue Nov 27 13:26:04 2007 +0000 +++ b/data/fileio/VideoFileReader.cpp Wed Nov 28 13:03:45 2007 +0000 @@ -10,69 +10,71 @@ published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the file COPYING included with this distribution for more information. -*/ - -#ifdef HAVE_FFMPEG - - -//#include "system/System.h" - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <cassert> - -#include <iostream> - -#include <QApplication> -#include <QFileInfo> -#include <QProgressDialog> - -#include "VideoFileReader.h" - +*/ + +#ifdef HAVE_FFMPEG + + +//#include "system/System.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <cassert> + +#include <iostream> + +#include <QApplication> +#include <QFileInfo> +#include <QProgressDialog> + +#include <avformat.h> + +#include "VideoFileReader.h" + #ifdef WIN32 #include <Windows.h> -#endif -long long countFreq; -int Videow=320; -int Videoh=240; -float zoomFivan=1; -VideoFileReader::VideoFileReader(QString path, bool showProgress, CacheMode mode) : - CodedAudioFileReader(mode), - m_path(path) -{ - m_frameCount = 0; - m_channelCount = 0; - m_sampleRate = 0; - m_fileSize = 0; - m_bitrateNum = 0; - m_bitrateDenom = 0; - m_cancelled = false; - m_zoomfactor = 1; - - struct stat stat; - if (::stat(path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) { - m_error = QString("File %1 does not exist.").arg(path); - return; - } +#endif +long long countFreq; +int Videow=320; +int Videoh=240; +float zoomFivan=1; +VideoFileReader::VideoFileReader(QString path, bool showProgress, CacheMode mode) : + CodedAudioFileReader(mode), + m_path(path) +{ + m_frameCount = 0; + m_channelCount = 0; + m_sampleRate = 0; + m_fileSize = 0; + m_bitrateNum = 0; + m_bitrateDenom = 0; + m_cancelled = false; + m_zoomfactor = 1; + + struct stat stat; + if (::stat(path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) { + m_error = QString("File %1 does not exist.").arg(path); + return; + } // standard SDL initialization stuff if(SDL_Init(SDL_INIT_VIDEO|SDL_DOUBLEBUF|SDL_INIT_AUDIO) < 0) { m_error = QString("Failed to open file %1 for reading.").arg(SDL_GetError()); return; - } - m_fileSize = stat.st_size; - - + } + m_fileSize = stat.st_size; + + // open file from arg[1] film = SDL_ffmpegOpen(path.toLocal8Bit().data()); if (path.endsWith("mpg")) film->delay=1; if (path.endsWith("divx")) film->delay=1; if(!film) - { - m_error = QString("Failed to open file %1 for reading.").arg(path); - return; - } + { + m_error = QString("Failed to open file %1 for reading.").arg(path); + return; + } // print some info on detected stream to output film->skipAudio=0; film->skipVideo=0; @@ -84,26 +86,26 @@ film->skipVideo=1; for(s = 0; s<film->AStreams; s++) str = SDL_ffmpegGetAudioStream(film, s); - - SDL_ffmpegSelectAudioStream(film, 0); - - - if (showProgress) { - m_progress = new QProgressDialog - (QObject::tr("Decoding %1...").arg(QFileInfo(path).fileName()), - QObject::tr("Stop"), 0, 100); - m_progress->hide(); - } - + + SDL_ffmpegSelectAudioStream(film, 0); + + + if (showProgress) { + m_progress = new QProgressDialog + (QObject::tr("Decoding %1...").arg(QFileInfo(path).fileName()), + QObject::tr("Stop"), 0, 100); + m_progress->hide(); + } + m_sampleRate=str->sampleRate; int channels=str->channels; m_channelCount=channels; SDL_ffmpegPause(film, 0); SDL_ffmpegStartDecoding(film); - if (!decodeAudio(film)) { - m_error = QString("Failed to decode audio from file %1 for reading.").arg(path); - return; + if (!decodeAudio(film)) { + m_error = QString("Failed to decode audio from file %1 for reading.").arg(path); + return; } film->skipAudio=1; //SDL_ffmpegSeek(film, 0); @@ -112,28 +114,28 @@ film->skipVideo=0; film->videoThread=SDL_CreateThread(videoPlayCall,this); - - - - - - if (showProgress) { - delete m_progress; - m_progress = 0; - } - - //delete[] filebuffer; -} - - -VideoFileReader::~VideoFileReader() -{ - film->videoThreadActive = 0; - if(film->videoThread) SDL_WaitThread(film->videoThread, 0); -} -bool -VideoFileReader::decodeAudio(SDL_ffmpegFile* file) -{ + + + + + + if (showProgress) { + delete m_progress; + m_progress = 0; + } + + //delete[] filebuffer; +} + + +VideoFileReader::~VideoFileReader() +{ + film->videoThreadActive = 0; + if(film->videoThread) SDL_WaitThread(film->videoThread, 0); +} +bool +VideoFileReader::decodeAudio(SDL_ffmpegFile* file) +{ int64_t duration=((AVFormatContext *)file->_ffmpeg)->duration; @@ -141,27 +143,27 @@ m_cancelled=false; int audio_ends=0; while((elapsed < duration)&&!m_cancelled ) { - - elapsed = double(m_frameCount)*1000000 /(m_channelCount*m_sampleRate); - double percent = (elapsed * 100) / duration; - int progress = int(percent); - if (progress < 1) progress = 1; - if (progress > 99) progress = 99; - if (progress > m_progress->value()) { - m_progress->setValue(progress); - m_progress->show(); - m_progress->raise(); - qApp->processEvents(); - if (m_progress->wasCanceled()) { - m_cancelled = true; - } - } - + + elapsed = double(m_frameCount)*1000000 /(m_channelCount*m_sampleRate); + double percent = (elapsed * 100) / duration; + int progress = int(percent); + if (progress < 1) progress = 1; + if (progress > 99) progress = 99; + if (progress > m_progress->value()) { + m_progress->setValue(progress); + m_progress->show(); + m_progress->raise(); + qApp->processEvents(); + if (m_progress->wasCanceled()) { + m_cancelled = true; + } + } + // we tell SDL_ffmpegGetAudio how many bytes we need, the function then // fills this pointer with the amount of bytes it could actually give int gotLength = 100000; - if (!isDecodeCacheInitialised()) { - initialiseDecodeCache(); + if (!isDecodeCacheInitialised()) { + initialiseDecodeCache(); } // we try to get some data from our file // important! this call is paired with SDL_ffmpegReleaseAudio @@ -186,11 +188,11 @@ } m_frameCount/=m_channelCount; if (isDecodeCacheInitialised()) finishDecodeCache(); - return true; -} -bool -VideoFileReader::videoInit(SDL_ffmpegFile* file) -{ + return true; +} +bool +VideoFileReader::videoInit(SDL_ffmpegFile* file) +{ int w,h; // we get the size from our active video stream, if no active video stream // exists, width and height are set to default values (320x240) @@ -216,15 +218,15 @@ if(!screen) { fprintf(stderr, "Couldn't open video: %s\n", SDL_GetError()); return false; - } - return true; -} - + } + return true; +} + int VideoFileReader::videoPlayCall(void *t) { return ((VideoFileReader *)t)->videoPlay(); -} - +} + void VideoFileReader::processEvents() { SDL_Event event; @@ -278,19 +280,19 @@ break; } } -} - -int -VideoFileReader::videoPlay() -{ +} + +int +VideoFileReader::videoPlay() +{ film->videoThreadActive = 1; MainWindow * MWins=MainWindow::instance(); if (!videoInit(film)) { - m_error = QString("Failed to failed to initalized video file for reading."); - return 0; + m_error = QString("Failed to failed to initalized video file for reading."); + return 0; } //const SDL_VideoInfo * vid=SDL_GetVideoInfo(); film->audioTime =0; @@ -364,19 +366,19 @@ // we wish not to kill our poor cpu, so we give it some timeoff // SDL_Delay(1); - } + } // after all is said and done, we should call this - SDL_ffmpegFree(film); - return 0; -} - -void -VideoFileReader::getSupportedExtensions(std::set<QString> &extensions) -{ - extensions.insert("mpg"); - extensions.insert("avi"); - extensions.insert("divx"); - extensions.insert("mov"); -} - -#endif + SDL_ffmpegFree(film); + return 0; +} + +void +VideoFileReader::getSupportedExtensions(std::set<QString> &extensions) +{ + extensions.insert("mpg"); + extensions.insert("avi"); + extensions.insert("divx"); + extensions.insert("mov"); +} + +#endif