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

page_bttv.cc

Go to the documentation of this file.
00001 /*
00002 * Copyright (C) 2001-2007 Charles Yates <charles.yates@pandora.be>
00003 * Copyright (C) 2001-2007 Dan Dennedy <dan@dennedy.org>
00004 * This program is free software; you can redistribute it and/or modify
00005 * it under the terms of the GNU General Public License as published by
00006 * the Free Software Foundation; either version 2 of the License, or
00007 * (at your option) any later version.
00008 *
00009 * This program is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 * GNU General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program; if not, write to the Free Software Foundation,
00016 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 #ifdef HAVE_CONFIG_H
00019 #include <config.h>
00020 #endif
00021 
00022 #include <iostream>
00023 
00024 #include "kino_common.h"
00025 #include "page.h"
00026 
00027 #include "page_bttv.h"
00028 #include "displayer.h"
00029 #include "v4l.h"
00030 
00031 extern "C"
00032 {
00033 #include "support.h"
00034 
00035     extern KinoCommon *common;
00036 
00037     void
00038     on_v4l_capture_page_record_button_clicked
00039     ( GtkButton * button,
00040       gpointer user_data )
00041     {
00042 
00043         common->getPageBttv() ->startCapture();
00044     }
00045 
00046 
00047     void
00048     on_v4l_capture_page_stop_button_clicked
00049     ( GtkButton * button,
00050       gpointer user_data )
00051     {
00052         common->getPageBttv() ->stopCapture();
00053     }
00054 
00055     void
00056     on_button_v4l_file_clicked( GtkButton       *button,
00057                                 gpointer         user_data)
00058     {
00059         const char *filename = common->getFileToSave( _("Enter a File Name to Save As") );
00060         gtk_widget_grab_focus( lookup_widget( GTK_WIDGET( button ), "entry_v4l_file" ) );
00061         if ( strcmp( filename, "" ) )
00062             gtk_entry_set_text( GTK_ENTRY( lookup_widget( GTK_WIDGET( button ), "entry_v4l_file" ) ), filename );
00063     }
00064 
00065 }
00066 
00067 PageBttv::PageBttv( KinoCommon *common ) : seeking( false ), lastPreferenceFilename( "" ), channel( 0 )
00068 {
00069     this->common = common;
00070 }
00071 
00072 PageBttv::~PageBttv()
00073 {}
00074 
00075 void PageBttv::start()
00076 {
00077     std::cerr << ">>> Starting bttv" << std::endl;
00078     v4l = new GDKV4L( lookup_widget( common->getWidget(), "drawingarea3" ) );
00079     GtkEntry *fileEntry = GTK_ENTRY( lookup_widget( common->getWidget(), "entry_v4l_file" ) );
00080 
00081     // Determine the capture directory and file - rules are:
00082     // 1) if a full path is specified in the preferences, then use that
00083     // 2) if a non-full path is specified, then pick up the project directory and attach preference
00084 
00085     string capture_file_name = Preferences::getInstance().file;
00086     if ( capture_file_name[ 0 ] != '/' )
00087         capture_file_name = common->getPlayList( ) ->GetProjectDirectory( ) + "/" + capture_file_name;
00088 
00089     // If the preferences have changed, then update the filename
00090 
00091     if ( capture_file_name != lastPreferenceFilename )
00092     {
00093         lastPreferenceFilename = capture_file_name;
00094         gtk_entry_set_text( fileEntry, capture_file_name.c_str( ) );
00095     }
00096 
00097     Preferences &prefs = Preferences::getInstance();
00098     v4l->setInfo( prefs.v4lVideoDevice, prefs.v4lInput, prefs.v4lAudioDevice, atoi( prefs.v4lAudio ) );
00099 
00100     if ( v4l->openDevice() )
00101     {
00102         v4l->report();
00103         v4l->setChannel( channel );
00104         v4l->setTuner( 0 );
00105         v4l->startAudio();
00106         v4l->startVideo();
00107     }
00108     else
00109     {
00110         std::cerr << "unable to open video device" << std::endl;
00111     }
00112     gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( lookup_widget( common->getWidget(), "menuitem_v4l" ) ), TRUE );
00113 }
00114 
00115 gulong PageBttv::activate()
00116 {
00117     if ( v4l->deviceAvailable() )
00118         return VIDEO_START_OF_MOVIE | VIDEO_START_OF_SCENE | VIDEO_REWIND | VIDEO_BACK |
00119                VIDEO_PLAY | VIDEO_STOP |
00120                VIDEO_FAST_FORWARD | VIDEO_FORWARD | VIDEO_NEXT_SCENE | VIDEO_END_OF_MOVIE;
00121     else
00122         return 0;
00123 }
00124 
00125 void PageBttv::clean()
00126 {
00127     std::cerr << ">> Leaving bttv" << std::endl;
00128     if ( v4l->deviceAvailable() )
00129     {
00130         v4l->stopVideo();
00131         v4l->stopAudio();
00132     }
00133     delete v4l;
00134     v4l = NULL;
00135     std::cerr << ">> Left bttv" << std::endl;
00136 }
00137 
00141 void PageBttv::newFile( )
00142 {
00143     lastPreferenceFilename = "";
00144 }
00145 
00146 
00147 void PageBttv::videoStartOfMovie()
00148 {
00149     std::cerr << "channels = " << v4l->getNumberOfChannels( ) << " channel = " << channel;
00150     channel = ( channel - 1 ) % v4l->getNumberOfChannels( );
00151     v4l->setChannel( channel );
00152     std::cerr << " new channel = " << channel << std::endl;
00153 }
00154 
00155 void PageBttv::videoPreviousScene()
00156 {
00157     v4l->setFrequency( v4l->getFrequency() - 100 );
00158 }
00159 
00160 void PageBttv::videoRewind()
00161 {
00162     if ( seeking == true )
00163         return ;
00164     seeking = true;
00165     do
00166     {
00167         if ( ( v4l->getFrequency() - 1 ) > 0 )
00168             v4l->setFrequency( v4l->getFrequency() - 1 );
00169         else
00170             break;
00171     }
00172     while ( v4l->getSignal() != 0 );
00173     do
00174     {
00175         if ( ( v4l->getFrequency() - 2 ) > 0 )
00176             v4l->setFrequency( v4l->getFrequency() - 2 );
00177         else
00178             break;
00179         std::cerr << "frequency = " << v4l->getFrequency() << std::endl;
00180         while ( gtk_events_pending() )
00181         {
00182             gtk_main_iteration();
00183         }
00184     }
00185     while ( v4l->getSignal() == 0 && seeking );
00186     seeking = false;
00187 }
00188 
00189 void PageBttv::videoPlay()
00190 {
00191     v4l->startVideo();
00192 }
00193 
00194 void PageBttv::videoStop()
00195 {
00196     seeking = false;
00197     v4l->stopVideo();
00198 }
00199 
00200 void PageBttv::videoFastForward()
00201 {
00202     if ( seeking == true )
00203         return ;
00204     seeking = true;
00205     do
00206     {
00207         if ( ( v4l->getFrequency() + 1 ) < 0xffff )
00208             v4l->setFrequency( v4l->getFrequency() + 1 );
00209         else
00210             break;
00211     }
00212     while ( v4l->getSignal() != 0 );
00213     do
00214     {
00215         if ( ( v4l->getFrequency() + 2 ) < 0xffff )
00216             v4l->setFrequency( v4l->getFrequency() + 2 );
00217         else
00218             break;
00219         std::cerr << "frequency = " << v4l->getFrequency() << std::endl;
00220         while ( gtk_events_pending() )
00221         {
00222             gtk_main_iteration();
00223         }
00224     }
00225     while ( v4l->getSignal() == 0 && seeking );
00226     seeking = false;
00227 }
00228 
00229 void PageBttv::videoBack()
00230 {
00231     v4l->setFrequency( v4l->getFrequency() - 1 );
00232 }
00233 
00234 void PageBttv::videoForward()
00235 {
00236     v4l->setFrequency( v4l->getFrequency() + 1 );
00237 }
00238 
00239 void PageBttv::videoNextScene()
00240 {
00241     v4l->setFrequency( v4l->getFrequency() + 100 );
00242 }
00243 
00244 void PageBttv::videoEndOfMovie()
00245 {
00246     channel = ( channel + 1 ) % v4l->getNumberOfChannels( );
00247     v4l->setChannel( channel );
00248 }
00249 
00250 void PageBttv::startCapture()
00251 {
00252     v4l->startCapturing();
00253 }
00254 
00255 void PageBttv::stopCapture()
00256 {
00257     v4l->stopCapturing();
00258 }
00259 
00260 void PageBttv::saveFrame()
00261 {
00262     std::cerr << "BTTV Save Frame Requested" << std::endl;
00263 }
00264 

Generated on Sun Mar 11 22:11:46 2007 for Kino by  doxygen 1.4.2