|
From: Tapio V. <aa...@us...> - 2011-01-26 10:37:35
|
Module: editor
Branch: master
Commit: a7dff611f9190d89c97a99ccca77757fb0d4ce2e
Author: Tapio Vierros <tap...@gm...>
Date: Wed Jan 26 12:36:19 2011 +0200
Synchronous FFmpeg opening: no more waiting for duration availability.
---
ffmpeg.cc | 13 +++++++------
pitchvis.cc | 7 +------
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/ffmpeg.cc b/ffmpeg.cc
index 2c563dd..889a83a 100644
--- a/ffmpeg.cc
+++ b/ffmpeg.cc
@@ -19,9 +19,13 @@ extern "C" {
FFmpeg::FFmpeg(std::string const& _filename, unsigned int rate):
m_filename(_filename), m_rate(rate), m_quit(), m_running(), m_eof(), m_seekTarget(getNaN()),
pFormatCtx(), pResampleCtx(), img_convert_ctx(), pAudioCodecCtx(), pAudioCodec(),
- audioStream(-1), m_position(),
- m_thread(new boost::thread(boost::ref(*this)))
-{}
+ audioStream(-1), m_position()
+{
+ open(); // Throws on error
+ m_running = true;
+ audioQueue.setDuration(duration());
+ m_thread.reset(new boost::thread(boost::ref(*this)));
+}
FFmpeg::~FFmpeg() {
m_quit = true;
@@ -87,9 +91,6 @@ void FFmpeg::open() {
}
void FFmpeg::operator()() {
- try { open(); } catch (std::exception const& e) { std::cerr << "FFMPEG failed to open " << m_filename << ": " << e.what() << std::endl; m_quit = true; return; }
- m_running = true;
- audioQueue.setDuration(duration());
int errors = 0;
while (!m_quit) {
try {
diff --git a/pitchvis.cc b/pitchvis.cc
index be788b3..b2becc4 100644
--- a/pitchvis.cc
+++ b/pitchvis.cc
@@ -29,13 +29,8 @@ void PitchVis::run()
{
// Initialize FFmpeg decoding
FFmpeg mpeg(fileName.toStdString(), rate);
- while(std::isnan(mpeg.duration()) || std::isinf(mpeg.duration())) {
- if (mpeg.terminating()) // Check if FFMPEG has failed
- return;
- msleep(1000); // Wait for ffmpeg to be ready
- }
- msleep(1000); // Wait some more
setWidth(mpeg.duration() * rate / step); // Estimation
+ msleep(1000); // Wait some
curX = 0;
for (std::vector<float> data(step*2); mpeg.audioQueue(&*data.begin(), &*data.end(), curX * step * 2); ++curX) {
msleep(2);
|