Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

DvEncoder Class Reference

#include <v4l.h>

List of all members.

Public Member Functions

 DvEncoder (char *, int, int)
 ~DvEncoder ()
EncoderFramegetFrame ()
void doneWithFrame (EncoderFrame *)
void writeThread ()

Static Public Member Functions

static void * startThread (void *)

Public Attributes

char * audio

Private Attributes

unsigned char data [144000]
dv_encoder_t * encoder
FILE * p
bool active
pthread_t thread
pthread_mutex_t mutex
char * filename
int width
int height

Static Private Attributes

static deque< EncoderFrame * > used
 Rudimentary encoding class for raw dv stream.
static deque< EncoderFrame * > available


Constructor & Destructor Documentation

DvEncoder::DvEncoder char *  ,
int  ,
int 
 

Definition at line 760 of file v4l.cc.

References available, Preferences::getInstance(), mutex, startThread(), and thread.

00760                                                             : active( false ), audio( "/dev/dsp" )
00761 {
00762     this->width = width;
00763     this->height = height;
00764 
00765     this->filename = filename;
00766     for ( int i = 0; i < Preferences::getInstance().dvCaptureBuffers; ++i )
00767     {
00768         available.push_back( NULL );
00769     }
00770 
00771     pthread_mutex_init( &mutex, NULL );
00772     pthread_create( &thread, NULL, startThread, this );
00773 }

DvEncoder::~DvEncoder  ) 
 

Definition at line 775 of file v4l.cc.

References active, available, thread, and used.

00776 {
00777     active = false;
00778     pthread_join( thread, NULL );
00779 
00780     for ( int i = available.size(); i > 0; --i )
00781     {
00782         EncoderFrame *frame = available[ 0 ];
00783         available.pop_front();
00784         delete frame;
00785     }
00786 
00787     for ( int i = used.size(); i > 0; --i )
00788     {
00789         EncoderFrame *frame = used[ 0 ];
00790         used.pop_front();
00791         delete frame;
00792     }
00793 }


Member Function Documentation

void DvEncoder::doneWithFrame EncoderFrame  ) 
 

Definition at line 813 of file v4l.cc.

References mutex, and used.

Referenced by GDKV4L::capture().

00814 {
00815     pthread_mutex_lock( &mutex );
00816     used.push_back( frame );
00817     pthread_mutex_unlock( &mutex );
00818 }

EncoderFrame * DvEncoder::getFrame  ) 
 

Definition at line 795 of file v4l.cc.

References available, and mutex.

Referenced by GDKV4L::capture().

00796 {
00797     EncoderFrame * frame = NULL;
00798 
00799     pthread_mutex_lock( &mutex );
00800     if ( available.size() > 0 )
00801     {
00802         frame = available[ 0 ];
00803         if ( frame == NULL )
00804             frame = new EncoderFrame;
00805 
00806         available.pop_front();
00807     }
00808     pthread_mutex_unlock( &mutex );
00809 
00810     return frame;
00811 }

void * DvEncoder::startThread void *   )  [static]
 

Definition at line 820 of file v4l.cc.

References encoder, and writeThread().

Referenced by DvEncoder().

00821 {
00822     DvEncoder * encoder = ( DvEncoder * ) ptr;
00823     cout << "starting encoder thread..." << endl;
00824     encoder->writeThread( );
00825     return NULL;
00826 }

void DvEncoder::writeThread  ) 
 

Definition at line 828 of file v4l.cc.

References active, audio, available, KinoVideoPipe::CloseVideo(), KinoVideoFactory::CreateVideoPipe(), ENCODE_YUV, filename, FileTracker::GetInstance(), height, EncoderFrame::image, mutex, KinoVideoPipe::OpenVideoPipe(), KinoVideoPipe::OutputVideoFrame(), PIPE_VIDEO_DV_PGM, PIPE_VIDEO_DV_YUV, used, and width.

Referenced by startThread().

00829 {
00830     struct timespec tm =
00831         {
00832             0, 0
00833         };
00834     char command[ 10240 ];
00835     int counter = 0;
00836     struct stat stats;
00837     string thisfile;
00838 
00839     active = true;
00840 
00841     do
00842     {
00843         ostringstream sb;
00844         sb << filename << setfill( '0' ) << setw( 3 ) << ++ counter << ".dv";
00845         thisfile = sb.str();
00846         cout << ">>> Trying " << thisfile << endl;
00847     }
00848     while ( stat( thisfile.c_str(), &stats ) == 0 );
00849 
00850     KinoVideoPipe *encode = NULL;
00851 
00852     if ( ENCODE_YUV )
00853     {
00854         encode = KinoVideoFactory::CreateVideoPipe( PIPE_VIDEO_DV_YUV );
00855         sprintf( command, "ffmpeg -threads 2 -f yuv4mpegpipe -i pipe: -f audio_device -ac 2 -ar 48000 -i %s -y %s", audio, thisfile.c_str() );
00856 //      sprintf( command, "ffmpeg -f yuv4mpegpipe -i pipe: -f audio_device -ac 2 -ar 48000 -i %s -vcodec mpeg4 -qscale 1 -aspect 4:3 -acodec pcm_s16le -y %s.avi", audio, thisfile.c_str() );
00857     }
00858     else
00859     {
00860         encode = KinoVideoFactory::CreateVideoPipe( PIPE_VIDEO_DV_PGM );
00861         sprintf( command, "encodedv -a dsp -i pgm -p 2 -q 2 - %s > %s", audio, thisfile.c_str() );
00862     }
00863 
00864     encode->OpenVideoPipe( command, width, height );
00865 
00866     while ( active || used.size() > 0 )
00867     {
00868         if ( used.size() > 0 )
00869         {
00870             pthread_mutex_lock( &mutex );
00871             EncoderFrame *frame = used.front();
00872             used.pop_front();
00873             pthread_mutex_unlock( &mutex );
00874 
00875             if ( frame != NULL )
00876             {
00877                 if ( ENCODE_YUV )
00878                     encode->OutputVideoFrame( frame->image, width * height * 2 );
00879                 else
00880                     encode->OutputVideoFrame( frame->image, width * height * 3 / 2 );
00881 
00882                 pthread_mutex_lock( &mutex );
00883                 available.push_back( frame );
00884                 pthread_mutex_unlock( &mutex );
00885             }
00886         }
00887 
00888         nanosleep( &tm, NULL );
00889     }
00890 
00891     encode->CloseVideo();
00892 
00893     delete encode;
00894 
00895     FileTracker::GetInstance().Add( thisfile.c_str() );
00896 }


Member Data Documentation

bool DvEncoder::active [private]
 

Definition at line 217 of file v4l.h.

Referenced by writeThread(), and ~DvEncoder().

char* DvEncoder::audio
 

Definition at line 224 of file v4l.h.

Referenced by gdkv4l_thread(), and writeThread().

deque< EncoderFrame * > DvEncoder::available [static, private]
 

Definition at line 758 of file v4l.cc.

Referenced by DvEncoder(), getFrame(), writeThread(), and ~DvEncoder().

unsigned char DvEncoder::data[144000] [private]
 

Definition at line 212 of file v4l.h.

dv_encoder_t* DvEncoder::encoder [private]
 

Definition at line 213 of file v4l.h.

Referenced by startThread().

char* DvEncoder::filename [private]
 

Definition at line 220 of file v4l.h.

Referenced by writeThread().

int DvEncoder::height [private]
 

Definition at line 222 of file v4l.h.

Referenced by writeThread().

pthread_mutex_t DvEncoder::mutex [private]
 

Definition at line 219 of file v4l.h.

Referenced by doneWithFrame(), DvEncoder(), getFrame(), and writeThread().

FILE* DvEncoder::p [private]
 

Definition at line 214 of file v4l.h.

pthread_t DvEncoder::thread [private]
 

Definition at line 218 of file v4l.h.

Referenced by DvEncoder(), and ~DvEncoder().

deque< EncoderFrame * > DvEncoder::used [static, private]
 

Rudimentary encoding class for raw dv stream.

Definition at line 757 of file v4l.cc.

Referenced by doneWithFrame(), writeThread(), and ~DvEncoder().

int DvEncoder::width [private]
 

Definition at line 221 of file v4l.h.

Referenced by writeThread().


The documentation for this class was generated from the following files:
Generated on Sun Mar 11 22:12:48 2007 for Kino by  doxygen 1.4.2