Skip to content

Commit

Permalink
Fixed the 'non blocking pipe' issue - #21.
Browse files Browse the repository at this point in the history
  • Loading branch information
smallfly committed Jul 20, 2015
1 parent e2fbd37 commit 9e08db6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/ofxVideoRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <unistd.h>
#include <fcntl.h>

int setNonblocking(int fd)
int setNonBlocking(int fd)
{
int flags;

Expand Down Expand Up @@ -113,6 +113,10 @@ void ofxVideoDataWriterThread::signal(){
condition.signal();
}

void ofxVideoDataWriterThread::setPipeNonBlocking(){
setNonBlocking(fd);
}

//===============================
ofxAudioDataWriterThread::ofxAudioDataWriterThread(){};
void ofxAudioDataWriterThread::setup(string filePath, lockFreeQueue<audioFrameShort *> *q){
Expand Down Expand Up @@ -162,6 +166,10 @@ void ofxAudioDataWriterThread::signal(){
condition.signal();
}

void ofxAudioDataWriterThread::setPipeNonBlocking(){
setNonBlocking(fd);
}

//===============================
ofxVideoRecorder::ofxVideoRecorder()
{
Expand Down Expand Up @@ -277,11 +285,9 @@ bool ofxVideoRecorder::setupCustomOutput(int w, int h, float fps, int sampleRate
ffmpegThread.setup(cmd.str()); // start ffmpeg thread, will wait for input pipes to be opened

if(bRecordAudio){
// audioPipeFd = ::open(audioPipePath.c_str(), O_WRONLY);
audioThread.setup(audioPipePath, &audioFrames);
}
if(bRecordVideo){
// videoPipeFd = ::open(videoPipePath.c_str(), O_WRONLY);
videoThread.setup(videoPipePath, &frames);
}

Expand Down Expand Up @@ -415,8 +421,8 @@ void ofxVideoRecorder::close()

if(bRecordVideo && bRecordAudio) {
//set pipes to non_blocking so we dont get stuck at the final writes
setNonblocking(audioPipeFd);
setNonblocking(videoPipeFd);
audioThread.setPipeNonBlocking();
videoThread.setPipeNonBlocking();

while(frames.size() > 0 && audioFrames.size() > 0) {
// if there are frames in the queue or the thread is writing, signal them until the work is done.
Expand All @@ -426,7 +432,7 @@ void ofxVideoRecorder::close()
}
else if(bRecordVideo) {
//set pipes to non_blocking so we dont get stuck at the final writes
setNonblocking(videoPipeFd);
videoThread.setPipeNonBlocking();

while(frames.size() > 0) {
// if there are frames in the queue or the thread is writing, signal them until the work is done.
Expand All @@ -435,7 +441,7 @@ void ofxVideoRecorder::close()
}
else if(bRecordAudio) {
//set pipes to non_blocking so we dont get stuck at the final writes
setNonblocking(audioPipeFd);
audioThread.setPipeNonBlocking();

while(audioFrames.size() > 0) {
// if there are frames in the queue or the thread is writing, signal them until the work is done.
Expand Down
2 changes: 2 additions & 0 deletions src/ofxVideoRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ofxVideoDataWriterThread : public ofThread {
void setup(string filePath, lockFreeQueue<ofPixels *> * q);
void threadedFunction();
void signal();
void setPipeNonBlocking();
bool isWriting() { return bIsWriting; }
void close() { bClose = true; stopThread(); signal(); }
private:
Expand All @@ -78,6 +79,7 @@ class ofxAudioDataWriterThread : public ofThread {
void setup(string filePath, lockFreeQueue<audioFrameShort *> * q);
void threadedFunction();
void signal();
void setPipeNonBlocking();
bool isWriting() { return bIsWriting; }
void close() { bClose = true; stopThread(); signal(); }
private:
Expand Down

0 comments on commit 9e08db6

Please sign in to comment.