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

V4L Class Reference

#include <v4l.h>

Inheritance diagram for V4L:

Inheritance graph
[legend]
Collaboration diagram for V4L:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 V4L ()
 Constructor for the V4L class.
virtual ~V4L ()
 Destructor for the V4L device.
void setInfo (char *device, char *input, char *audio, int sample)
bool openDevice ()
bool deviceAvailable ()
 Indicate if the device is available.
int getHandle ()
 Return the handle associated to the device.
unsigned int getNumberOfChannels ()
 Get the number of channels available.
V4LChannelgetChannel (unsigned int)
 Get the specified channel.
bool setChannel (unsigned int channel)
 Set specified channel.
unsigned int getNumberOfTuners ()
 Get the number of tuners associated to the current channel.
V4LTunergetTuner (unsigned int)
 Get a tuner associated to the current channel.
bool setTuner (unsigned int tuner)
 Set specified tuner.
bool setCaptureResolution (int width, int height)
 Set user defined resolution (where applicable).
int getWidth ()
 Get the capture width.
int getHeight ()
 Get the capture height.
void startAudio ()
 Turn on audio.
void stopAudio ()
 Turn off audio.
bool initialiseCapture (int format)
 Initialise capture.
void * getNextFrame ()
 Get the next frame.
void stopCapture ()
 Turn off capture.
int getFrequency ()
 Get the current frequency of the tuner.
bool setFrequency (int frequency)
 Set the current frequency of the tuner.
int getSignal ()
 Get the signal of the current tuned in frequency.
void report ()
 Gimme some info.
int mappedMemorySize (bool init=false)

Public Attributes

char * audio
V4LCapabilitycapability
int frameSample

Private Attributes

int fd
vector< V4LChannel * > channels
V4LChannelcurrent
int width
int height
void * map
video_mmap frame [32]
int frame_maps
int frame_next
int size
int frames
long long starttime
char * device
char * input
int sample
int fps

Constructor & Destructor Documentation

V4L::V4L  ) 
 

Constructor for the V4L class.

Definition at line 340 of file v4l.cc.

00341 {
00342     cout << "Opening V4L" << endl;
00343 }

V4L::~V4L  )  [virtual]
 

Destructor for the V4L device.

Definition at line 395 of file v4l.cc.

References capability, channels, and fd.

00396 {
00397     cout << "Closing V4L" << endl;
00398     if ( fd != -1 )
00399     {
00400         close( fd );
00401         for ( unsigned int index = 0; index < channels.size(); index ++ )
00402             delete channels[ index ];
00403         delete this->capability;
00404     }
00405 }


Member Function Documentation

bool V4L::deviceAvailable  ) 
 

Indicate if the device is available.

Returns:
true if available, false otherwise

Definition at line 412 of file v4l.cc.

References fd.

Referenced by PageBttv::activate(), and PageBttv::clean().

00413 {
00414     return fd != -1;
00415 }

V4LChannel * V4L::getChannel unsigned int  channel  ) 
 

Get the specified channel.

Parameters:
channel channel to obtain
Returns:
the number of channels

Definition at line 462 of file v4l.cc.

References channels.

00463 {
00464     if ( channel >= 0 && channel < channels.size() )
00465         return channels[ channel ];
00466     else
00467         return NULL;
00468 }

int V4L::getFrequency  ) 
 

Get the current frequency of the tuner.

Returns:
the current tuned in frequency.

Definition at line 681 of file v4l.cc.

References current, and fd.

Referenced by PageBttv::videoBack(), PageBttv::videoFastForward(), PageBttv::videoForward(), PageBttv::videoNextScene(), PageBttv::videoPreviousScene(), and PageBttv::videoRewind().

00682 {
00683     unsigned long current;
00684     ioctl( fd, VIDIOCGFREQ, &current );
00685     return ( int ) current;
00686 }

int V4L::getHandle  )  [virtual]
 

Return the handle associated to the device.

Returns:
the file descriptor of the open device.

Implements V4LDevice.

Definition at line 422 of file v4l.cc.

References fd.

Referenced by stopCapture().

00423 {
00424     return fd;
00425 }

int V4L::getHeight  ) 
 

Get the capture height.

Returns:
the height of the captured image

Definition at line 550 of file v4l.cc.

References height.

Referenced by GDKV4L::capture(), GDKV4L::draw(), gdkv4l_thread(), and initialiseCapture().

00551 {
00552     return height;
00553 }

void * V4L::getNextFrame  ) 
 

Get the next frame.

Returns:
the adress of the frame in the format specified

Definition at line 639 of file v4l.cc.

References current, fd, frame, frame_maps, frame_next, frames, map, and mappedMemorySize().

Referenced by GDKV4L::capture(), and GDKV4L::draw().

00640 {
00641     unsigned char * ret = NULL;
00642 
00643     int current = frame_next;
00644     frame_next = ( frame_next + 1 ) % frame_maps;
00645     
00646     if ( ioctl( fd, VIDIOCMCAPTURE, &frame[ frame_next ] ) == -1 )
00647         ; //cout << "Frame 1 Failed to initialise" << endl;
00648     if ( ioctl( fd, VIDIOCSYNC, &frame[ current ].frame ) == -1 )
00649         ; //cout << "Frame 0 Failed to sync" << endl;
00650     ret = ( unsigned char * ) map + current * ( mappedMemorySize( ) / frame_maps );
00651     
00652     frames ++;
00653 
00654     return ( void * ) ret;
00655 }

unsigned int V4L::getNumberOfChannels  ) 
 

Get the number of channels available.

Returns:
the number of channels

Definition at line 451 of file v4l.cc.

References channels.

Referenced by openDevice(), PageBttv::videoEndOfMovie(), and PageBttv::videoStartOfMovie().

00452 {
00453     return channels.size();
00454 }

unsigned int V4L::getNumberOfTuners  ) 
 

Get the number of tuners associated to the current channel.

Returns:
the number of tuners associated to the current channel

Definition at line 489 of file v4l.cc.

References current, and V4LChannel::getNumberOfTuners().

00490 {
00491     if ( current != NULL )
00492         return current->getNumberOfTuners();
00493     else
00494         return 0;
00495 }

int V4L::getSignal  ) 
 

Get the signal of the current tuned in frequency.

Definition at line 703 of file v4l.cc.

References current, and V4LChannel::getSignal().

Referenced by PageBttv::videoFastForward(), and PageBttv::videoRewind().

00704 {
00705     return current->getSignal();
00706 }

V4LTuner * V4L::getTuner unsigned int  tuner  ) 
 

Get a tuner associated to the current channel.

Parameters:
tuner tuner object to obtain
Returns:
a tuner object

Definition at line 503 of file v4l.cc.

References current, and V4LChannel::getTuner().

00504 {
00505     if ( current != NULL )
00506         return current->getTuner( tuner );
00507     else
00508         return NULL;
00509 }

int V4L::getWidth  ) 
 

Get the capture width.

Returns:
the width of the captured image

Definition at line 540 of file v4l.cc.

References width.

Referenced by GDKV4L::capture(), GDKV4L::draw(), gdkv4l_thread(), and initialiseCapture().

00541 {
00542     return width;
00543 }

bool V4L::initialiseCapture int  format  ) 
 

Initialise capture.

Parameters:
format v4l frame format (VIDEO_PALETTE_)
Returns:
true if successful, false otherwise

Definition at line 601 of file v4l.cc.

References fd, frame, frame_maps, frame_next, frames, getHeight(), getWidth(), height, map, mappedMemorySize(), size, starttime, and width.

Referenced by GDKV4L::capture(), and GDKV4L::draw().

00602 {
00603     size = width * height * 4;
00604 
00605     map = mmap( 0, mappedMemorySize( true ), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
00606 
00607     if ( map != NULL )
00608     {
00609         for ( int i = 0; i < frame_maps; i ++ )
00610         {
00611             frame[ i ].frame = i;
00612             frame[ i ].width = getWidth();
00613             frame[ i ].height = getHeight();
00614             frame[ i ].format = format;
00615         }
00616         
00617         struct timeval tv;
00618         gettimeofday( &tv, NULL );
00619         starttime = tv.tv_sec * 1000000 + tv.tv_usec;
00620         frames = 0;
00621         frame_next = 0;
00622         
00623         int retry = 0;
00624         while ( ioctl( fd, VIDIOCMCAPTURE, &frame[ 0 ] ) == -1 && retry ++ < frame_maps + 1 ) ;
00625         
00626         return true;
00627     }
00628     else
00629     {
00630         return false;
00631     }
00632 }

int V4L::mappedMemorySize bool  init = false  ) 
 

Definition at line 582 of file v4l.cc.

References fd, and frame_maps.

Referenced by getNextFrame(), initialiseCapture(), and stopCapture().

00583 {
00584     static video_mbuf buf;
00585     if ( init == true )
00586     {
00587         init = 1;
00588         ioctl( fd, VIDIOCGMBUF, &buf );
00589         cout << ">>> Mapped Memory Size = " << buf.size << " frames are " << buf.frames << endl;
00590         frame_maps = buf.frames;
00591     }
00592     return buf.size;
00593 }

bool V4L::openDevice  ) 
 

Definition at line 353 of file v4l.cc.

References capability, channels, current, device, fd, fps, frameSample, getNumberOfChannels(), height, sample, setCaptureResolution(), and width.

Referenced by PageBttv::start().

00354 {
00355     bool ret = true;
00356 
00357     if ( !strcmp( this->input, "PAL" ) )
00358     {
00359         this->width = 720;
00360         this->height = 576;
00361         this->fps = 25;
00362         this->frameSample = this->sample / this->fps;
00363     }
00364     else if ( !strcmp( this->input, "NTSC" ) )
00365     {
00366         this->width = 720;
00367         this->height = 480;
00368         this->fps = 30;
00369         this->frameSample = this->sample / this->fps;
00370     }
00371 
00372     this->current = NULL;
00373     this->fd = open( device, O_RDWR );
00374     if ( fd != -1 )
00375     {
00376         this->capability = new V4LCapability( this );
00377         for ( int index = 0; index < capability->getNumberOfChannels(); index ++ )
00378         {
00379             V4LChannel *channel = new V4LChannel( this, index );
00380             channels.insert( channels.end(), channel );
00381         }
00382         setCaptureResolution( this->width, this->height );
00383     }
00384     else
00385     {
00386         perror( "Unable to open video device" );
00387         ret = false;
00388     }
00389     return ret;
00390 }

void V4L::report  ) 
 

Gimme some info.

Definition at line 711 of file v4l.cc.

References capability, channels, and V4LCapability::report().

Referenced by PageBttv::start().

00712 {
00713     capability->report();
00714 
00715     for ( unsigned int index = 0; index < channels.size(); index ++ )
00716     {
00717         channels[ index ] ->report();
00718     }
00719 }

bool V4L::setCaptureResolution int  width,
int  height
 

Set user defined resolution (where applicable).

Parameters:
width width of capture
height height of capture

Definition at line 517 of file v4l.cc.

References capability, V4LCapability::getMaxHeight(), V4LCapability::getMaxWidth(), V4LCapability::getMinHeight(), V4LCapability::getMinWidth(), and V4LCapability::hasScaling().

Referenced by openDevice().

00518 {
00519     if ( width > capability->getMaxWidth() ||
00520             width < capability->getMinWidth() )
00521         return false;
00522     if ( height > capability->getMaxHeight() ||
00523             height < capability->getMinHeight() )
00524         return false;
00525     if ( !capability->hasScaling() && (
00526                 width != capability->getMaxWidth() ||
00527                 height != capability->getMaxHeight() ) )
00528         return false;
00529     this->width = width;
00530     this->height = height;
00531     cout << "Capture resolution set to " << width << ", " << height << endl;
00532     return true;
00533 }

bool V4L::setChannel unsigned int  channel  ) 
 

Set specified channel.

Parameters:
channel channel to use
Returns:
true if successful, false otherwise

Definition at line 433 of file v4l.cc.

References channels, current, and V4LDevice::request().

Referenced by PageBttv::start(), PageBttv::videoEndOfMovie(), and PageBttv::videoStartOfMovie().

00434 {
00435     if ( channel >= 0 && channel < channels.size() )
00436     {
00437         current = channels[ channel ];
00438         return this->request( VIDIOCSCHAN, current );
00439     }
00440     else
00441     {
00442         return false;
00443     }
00444 }

bool V4L::setFrequency int  frequency  ) 
 

Set the current frequency of the tuner.

Parameters:
frequency frequency to set
Returns:
the current tuned in frequency.

Definition at line 694 of file v4l.cc.

References fd.

Referenced by PageBttv::videoBack(), PageBttv::videoFastForward(), PageBttv::videoForward(), PageBttv::videoNextScene(), PageBttv::videoPreviousScene(), and PageBttv::videoRewind().

00695 {
00696     unsigned long val = ( unsigned long ) frequency & 0xffff;
00697     return ioctl( fd, VIDIOCSFREQ, &val ) != -1;
00698 }

void V4L::setInfo char *  device,
char *  input,
char *  audio,
int  sample
 

Definition at line 345 of file v4l.cc.

Referenced by PageBttv::start().

00346 {
00347     this->device = device;
00348     this->input = input;
00349     this->audio = audio;
00350     this->sample = sample;
00351 }

bool V4L::setTuner unsigned int  tuner  ) 
 

Set specified tuner.

Parameters:
tuner tuner to use
Returns:
true if successful, false otherwise

Definition at line 476 of file v4l.cc.

References current, and V4LChannel::setTuner().

Referenced by PageBttv::start().

00477 {
00478     if ( current != NULL )
00479         return current->setTuner( tuner );
00480     else
00481         return false;
00482 }

void V4L::startAudio  ) 
 

Turn on audio.

Definition at line 558 of file v4l.cc.

References fd.

Referenced by PageBttv::start().

00559 {
00560     struct video_audio audio;
00561     ioctl( fd, VIDIOCGAUDIO, &audio );
00562     if ( audio.flags & VIDEO_AUDIO_MUTE )
00563         audio.flags ^= VIDEO_AUDIO_MUTE;
00564     cout << "Volume : " << audio.volume << endl;
00565     audio.volume = 65535;
00566     ioctl( fd, VIDIOCSAUDIO, &audio );
00567 }

void V4L::stopAudio  ) 
 

Turn off audio.

Definition at line 572 of file v4l.cc.

References fd.

Referenced by PageBttv::clean().

00573 {
00574     struct video_audio audio;
00575     ioctl( fd, VIDIOCGAUDIO, &audio );
00576     audio.flags |= VIDEO_AUDIO_MUTE;
00577     cout << "Volume : " << audio.volume << endl;
00578     audio.volume = 0;
00579     ioctl( fd, VIDIOCSAUDIO, &audio );
00580 }

void V4L::stopCapture  ) 
 

Turn off capture.

Definition at line 660 of file v4l.cc.

References fps, frames, getHandle(), map, mappedMemorySize(), and starttime.

Referenced by GDKV4L::stopVideo().

00661 {
00662     if ( map != NULL )
00663     {
00664         struct timeval tv;
00665         gettimeofday( &tv, NULL );
00666         long long endtime = tv.tv_sec * 1000000 + tv.tv_usec;
00667         double fps = ( frames ) / ( ( ( double ) ( endtime - starttime ) ) / 1000000 );
00668         cout << "fps: " << fps << endl;
00669         munmap( map, mappedMemorySize() );
00670         map = NULL;
00671         int enable = 0;
00672         ioctl( getHandle(), VIDIOCCAPTURE, &enable );
00673     }
00674 }


Member Data Documentation

char* V4L::audio
 

Definition at line 163 of file v4l.h.

Referenced by gdkv4l_thread().

V4LCapability* V4L::capability
 

Definition at line 164 of file v4l.h.

Referenced by openDevice(), report(), setCaptureResolution(), and ~V4L().

vector<V4LChannel *> V4L::channels [private]
 

Definition at line 147 of file v4l.h.

Referenced by getChannel(), getNumberOfChannels(), openDevice(), report(), setChannel(), and ~V4L().

V4LChannel* V4L::current [private]
 

Definition at line 148 of file v4l.h.

Referenced by getFrequency(), getNextFrame(), getNumberOfTuners(), getSignal(), getTuner(), openDevice(), setChannel(), and setTuner().

char* V4L::device [private]
 

Definition at line 158 of file v4l.h.

Referenced by openDevice().

int V4L::fd [private]
 

Definition at line 146 of file v4l.h.

Referenced by deviceAvailable(), getFrequency(), getHandle(), getNextFrame(), initialiseCapture(), mappedMemorySize(), openDevice(), setFrequency(), startAudio(), stopAudio(), and ~V4L().

int V4L::fps [private]
 

Definition at line 161 of file v4l.h.

Referenced by openDevice(), and stopCapture().

struct video_mmap V4L::frame[32] [private]
 

Definition at line 152 of file v4l.h.

Referenced by GDKV4L::capture(), getNextFrame(), and initialiseCapture().

int V4L::frame_maps [private]
 

Definition at line 153 of file v4l.h.

Referenced by getNextFrame(), initialiseCapture(), and mappedMemorySize().

int V4L::frame_next [private]
 

Definition at line 154 of file v4l.h.

Referenced by getNextFrame(), and initialiseCapture().

int V4L::frames [private]
 

Definition at line 156 of file v4l.h.

Referenced by getNextFrame(), initialiseCapture(), and stopCapture().

int V4L::frameSample
 

Definition at line 190 of file v4l.h.

Referenced by openDevice().

int V4L::height [private]
 

Definition at line 150 of file v4l.h.

Referenced by getHeight(), initialiseCapture(), and openDevice().

char* V4L::input [private]
 

Reimplemented in GDKV4L.

Definition at line 159 of file v4l.h.

void* V4L::map [private]
 

Definition at line 151 of file v4l.h.

Referenced by getNextFrame(), initialiseCapture(), and stopCapture().

int V4L::sample [private]
 

Definition at line 160 of file v4l.h.

Referenced by openDevice().

int V4L::size [private]
 

Definition at line 155 of file v4l.h.

Referenced by initialiseCapture().

long long V4L::starttime [private]
 

Definition at line 157 of file v4l.h.

Referenced by initialiseCapture(), and stopCapture().

int V4L::width [private]
 

Definition at line 149 of file v4l.h.

Referenced by getWidth(), initialiseCapture(), and openDevice().


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