#include <iostream>#include <gtk/gtk.h>#include <math.h>#include <limits.h>#include <unistd.h>#include "page_capture.h"#include "riff.h"#include "avi.h"#include "playlist.h"#include "filehandler.h"#include "ieee1394io.h"#include "framedisplayer.h"#include "message.h"#include "error.h"#include "frame.h"#include "page_editor.h"#include "support.h"#include "callbacks.h"#include "commands.h"#include <pthread.h>Include dependency graph for page_capture.cc:

Go to the source code of this file.
Defines | |
| #define | BUFFERED_FRAMES 25 |
Functions | |
| static void * | captureThread (void *p) |
| static void * | avcThread (void *p) |
| static void * | videoThread (void *p) |
| static void | TriggerAction () |
| static int | WaitForAction (int lastPosition) |
| static void * | videoThread (gpointer p) |
| static void * | avcThread (gpointer p) |
| void | on_capture_page_record_button_clicked (GtkButton *button, gpointer user_data) |
| void | on_capture_page_stop_button_clicked (GtkButton *button, gpointer user_data) |
| void | on_capture_page_snapshot_button_clicked (GtkButton *button, gpointer user_data) |
| gboolean | on_entry_capture_file_focus_in_event (GtkWidget *widget, GdkEventFocus *event, gpointer user_data) |
| gboolean | on_entry_capture_file_focus_out_event (GtkWidget *widget, GdkEventFocus *event, gpointer user_data) |
| void | on_capture_file_button_clicked (GtkButton *button, gpointer user_data) |
| void | on_entry_capture_file_grab_focus (GtkWidget *widget, gpointer user_data) |
| void | on_capture_page_button_pressed (GtkButton *button, gpointer user_data) |
| void | on_capture_page_button_released (GtkButton *button, gpointer user_data) |
| void | on_capture_page_mute_button_toggled (GtkToggleButton *togglebutton, gpointer user_data) |
| void | on_capture_page_avc_button_clicked (GtkButton *button, gpointer user_data) |
Variables | |
| static FrameDisplayer * | displayer = NULL |
| navigate_control | g_nav_ctl |
| IEEE1394Reader * | reader = NULL |
| AVC * | avc = NULL |
| static FileHandler * | writer = NULL |
| char | cmd [] |
| static char | lastcmd [256] |
| static gchar | lastPreferenceFilename [512] |
| KinoCommon * | common |
| static quadlet_t | avcStatus |
| char | timecode [256] |
| static pthread_t | capturethread |
| static pthread_t | avcthread |
| static pthread_t | videothread |
| static gboolean | audioOn = FALSE |
| static pthread_mutex_t | writerlock = PTHREAD_MUTEX_INITIALIZER |
| static int | framePosition = -1 |
| static Frame * | frameBuffer [BUFFERED_FRAMES] |
| static int | frameCount = 0 |
| static int | framesCaptured = 0 |
| static int | prevFramesWritten = 0 |
| static pthread_mutex_t | condition_mutex = PTHREAD_MUTEX_INITIALIZER |
| static pthread_cond_t | condition = PTHREAD_COND_INITIALIZER |
| static bool | buttonGuard = true |
|
|
Definition at line 82 of file page_capture.cc. Referenced by captureThread(). |
|
|
Definition at line 1636 of file page_capture.cc. References navigate_control::capture_active, common, g_nav_ctl, Preferences::getInstance(), and KinoCommon::getPageCapture(). 01637 {
01638 while ( g_nav_ctl.capture_active )
01639 {
01640 // Check that device is still valid
01641 common->getPageCapture() ->CheckDevices( );
01642
01643 // Release temporarily
01644 struct timespec t =
01645 {
01646 0, ( unsigned long ) Preferences::getInstance().avcPollIntervalMs
01647 * 1000000UL
01648 };
01649 nanosleep( &t, NULL );
01650 }
01651
01652 return NULL;
01653 }
|
|
|
Referenced by PageCapture::start(). |
|
|
Definition at line 1479 of file page_capture.cc. References audioOn, BUFFERED_FRAMES, navigate_control::capture_active, common, IEEE1394Reader::DoneWithFrame(), frameBuffer, frameCount, framePosition, framesCaptured, g_nav_ctl, IEEE1394Reader::GetFrame(), IEEE1394Reader::GetInQueueSize(), Preferences::getInstance(), IEEE1394Reader::GetOutQueueSize(), KinoCommon::getPageCapture(), Frame::GetTimeCode(), Frame::IsNormalSpeed(), FrameDisplayer::PutSound(), reader, KinoCommon::setStatusBar(), TriggerAction(), IEEE1394Reader::WaitForAction(), FileHandler::WriteFrame(), writer, and writerlock. Referenced by PageCapture::start(). 01480 {
01481 Frame * frame = NULL;
01482
01483 // Make sure we can tell the difference between a used and unused frame
01484 for ( int index = 0; index < BUFFERED_FRAMES; index ++ )
01485 frameBuffer[ index ] = NULL;
01486
01487 framesCaptured = 0;
01488
01489 // Loop until we're informed otherwise
01490 while ( g_nav_ctl.capture_active )
01491 {
01492 // Wait for the reader to indicate that something has happened
01493 reader->WaitForAction( );
01494
01495 // Get the next frame
01496 frame = reader->GetFrame();
01497
01498 // Check if the out queue is falling behind
01499 bool critical_mass = reader->GetOutQueueSize( ) > reader->GetInQueueSize( );
01500
01501 // Make sure we return the oldest frame first
01502 if ( frame != NULL && frameCount == BUFFERED_FRAMES )
01503 {
01504 int oldest = ( framePosition + 1 ) % BUFFERED_FRAMES;
01505 frameBuffer[ oldest ] = NULL;
01506 frameCount --;
01507 }
01508
01509 // Put the last collected frame into the buffer so it can be picked up
01510 // by the video thread.
01511 if ( frame != NULL && !critical_mass )
01512 {
01513 // Bung it in to the buffer
01514 int newest = ( framePosition + 1 ) % BUFFERED_FRAMES;
01515 frameBuffer[ newest ] = frame;
01516 frameCount ++;
01517 framePosition = newest;
01518 TriggerAction( );
01519 }
01520
01521 // Do with it what needs to be done
01522 if ( frame != NULL )
01523 {
01524 TimeCode tc;
01525 frame->GetTimeCode( tc );
01526 if ( frame->IsNormalSpeed() &&
01527 ! ( tc.hour == 0 && tc.min == 0 && tc.sec == 0 && tc.frame == 0 ) )
01528 {
01529 // Play audio
01530 if ( audioOn && !critical_mass )
01531 if ( writer == NULL || ( writer != NULL && Preferences::getInstance().preview_capture ) )
01532 displayer->PutSound( *frame );
01533
01534 // All access to the writer is protected
01535 pthread_mutex_lock( &writerlock );
01536 if ( writer != NULL )
01537 {
01538 if ( !writer->WriteFrame( *frame ) )
01539 {
01540 pthread_mutex_unlock( &writerlock );
01541 gdk_threads_enter();
01542 common->getPageCapture() ->stopCapture();
01543 common->setStatusBar( _( "WARNING: Capture stopped. Disk full?" ) );
01544 gdk_threads_leave();
01545 }
01546 framesCaptured++;
01547 }
01548 pthread_mutex_unlock( &writerlock );
01549 }
01550 // Return the frame for reuse
01551 reader->DoneWithFrame( frame );
01552
01553 }
01554 }
01555
01556 // Set the buffer positional vars to defaults to allow restart
01557 frameCount = 0;
01558 framePosition = -1;
01559
01560 g_nav_ctl.capture_active = FALSE;
01561
01562 TriggerAction( );
01563
01564 return NULL;
01565 }
|
|
||||||||||||
|
Definition at line 1700 of file page_capture.cc. References common, navigate_control::escaped, g_nav_ctl, KinoCommon::getFileToSave(), and lookup_widget(). 01702 {
01703 g_nav_ctl.escaped = TRUE;
01704 gtk_entry_set_editable( GTK_ENTRY( lookup_widget( GTK_WIDGET( button ), "entry_capture_file" ) ), TRUE );
01705 gtk_widget_grab_focus( lookup_widget( GTK_WIDGET( button ), "entry_capture_file" ) );
01706 const char *filename = common->getFileToSave( _("Choose a DV file") );
01707 if ( strcmp( filename, "" ) )
01708 gtk_entry_set_text( GTK_ENTRY( lookup_widget( GTK_WIDGET( button ), "entry_capture_file" ) ), filename );
01709 }
|
|
||||||||||||
|
Definition at line 1750 of file page_capture.cc. References avcStatus, common, Preferences::getInstance(), KinoCommon::getPageCapture(), and TriggerAction(). 01752 {
01753 avcStatus = !avcStatus;
01754 Preferences::getInstance().enableAVC = common->getPageCapture( ) ->avc_enabled = !common->getPageCapture( ) ->avc_enabled;
01755 std::cerr << ">> AV/C " << ( common->getPageCapture( ) ->avc_enabled ? _( "Enabled" ) : _( "Disabled" ) ) << std::endl;
01756 TriggerAction( );
01757 }
|
|
||||||||||||
|
Definition at line 1722 of file page_capture.cc. 01724 {
01725 buttonGuard = false;
01726 }
|
|
||||||||||||
|
Definition at line 1730 of file page_capture.cc. 01732 {
01733 buttonGuard = true;
01734 }
|
|
||||||||||||
|
Definition at line 1738 of file page_capture.cc. References audioOn. 01740 {
01741 if ( ! buttonGuard )
01742 {
01743 audioOn = ! audioOn;
01744 buttonGuard = true;
01745 gtk_toggle_button_set_active( togglebutton, !audioOn );
01746 }
01747 }
|
|
||||||||||||
|
Definition at line 1656 of file page_capture.cc. References startCapture(). 01658 {
01659 startCapture();
01660 }
|
|
||||||||||||
|
Definition at line 1671 of file page_capture.cc. References saveFrame(). 01673 {
01674 saveFrame();
01675 }
|
|
||||||||||||
|
Definition at line 1664 of file page_capture.cc. References stopCapture(). 01666 {
01667 stopCapture();
01668 }
|
|
||||||||||||||||
|
Definition at line 1678 of file page_capture.cc. References navigate_control::escaped, and g_nav_ctl. 01681 {
01682 gtk_entry_set_editable( GTK_ENTRY( widget ), TRUE );
01683 g_nav_ctl.escaped = TRUE;
01684 return FALSE;
01685 }
|
|
||||||||||||||||
|
Definition at line 1689 of file page_capture.cc. References navigate_control::escaped, and g_nav_ctl. 01692 {
01693 gtk_entry_set_editable( GTK_ENTRY( widget ), FALSE );
01694 g_nav_ctl.escaped = FALSE;
01695 return FALSE;
01696 }
|
|
||||||||||||
|
Definition at line 1712 of file page_capture.cc. References navigate_control::escaped, and g_nav_ctl. 01714 {
01715 gtk_entry_set_editable( GTK_ENTRY( widget ), TRUE );
01716 g_nav_ctl.escaped = TRUE;
01717 }
|
|
|
Definition at line 1472 of file page_capture.cc. Referenced by PageMagick::AudioThread(), captureThread(), PageCapture::CheckDevices(), on_capture_page_avc_button_clicked(), and PageMagick::StopPreview(). 01473 {
01474 pthread_mutex_lock( &condition_mutex );
01475 pthread_cond_signal( &condition );
01476 pthread_mutex_unlock( &condition_mutex );
01477 }
|
|
|
Definition at line 1568 of file page_capture.cc. References avcStatus, navigate_control::capture_active, common, frameBuffer, framesCaptured, g_nav_ctl, FileHandler::GetFilename(), FileHandler::GetFramesWritten(), Preferences::getInstance(), KinoCommon::getPageCapture(), prevFramesWritten, FrameDisplayer::Put(), KinoCommon::setStatusBar(), WaitForAction(), writer, and writerlock. 01569 {
01570 int lastPosition = -1;
01571
01572 GtkWidget *drawingarea = ( GtkWidget* ) p;
01573 prevFramesWritten = 0;
01574
01575 while ( g_nav_ctl.capture_active )
01576 {
01577 int position = WaitForAction( lastPosition );
01578
01579 // Lock the gui
01580 gdk_threads_enter();
01581
01582 // If we have a valid position and it's different to the last iteration
01583 if ( g_nav_ctl.capture_active && position != -1 && position != lastPosition )
01584 {
01585
01586 // ... display it - note, the displayer and the frame may be destroyed
01587 // while waiting for the thread lock so additional checks are needed
01588 if ( ( displayer != NULL && frameBuffer[ position ] != NULL ) )
01589 {
01590 if ( writer == NULL || ( writer != NULL && Preferences::getInstance().preview_capture ) )
01591 {
01592 displayer->Put( *frameBuffer[ position ], drawingarea, TRUE );
01593 }
01594 }
01595
01596 // Remember the buffer position of the last frame displayed
01597 lastPosition = position;
01598 }
01599
01600 // Apply the changes to the GUI
01601 common->getPageCapture() ->applyAVCState( avcStatus );
01602 common->getPageCapture()->showFrameInfo( framesCaptured );
01603
01604 gdk_flush();
01605 gdk_threads_leave();
01606
01607 pthread_mutex_lock( &writerlock );
01608 if ( writer )
01609 {
01610 int framesWritten = writer->GetFramesWritten();
01611 string filename = writer->GetFilename();
01612 pthread_mutex_unlock( &writerlock );
01613
01614 if ( framesWritten < prevFramesWritten )
01615 {
01616 gdk_threads_enter();
01617 common->setStatusBar( ( string( _( "Capturing " ) ) + filename ).c_str() );
01618 gdk_threads_leave();
01619 common->getPageCapture()->collectFiles();
01620 }
01621 prevFramesWritten = framesWritten;
01622 }
01623 else
01624 {
01625 pthread_mutex_unlock( &writerlock );
01626 }
01627
01628 // Release temporarily
01629 struct timespec t = { 0, 0 };
01630 nanosleep( &t, NULL );
01631 }
01632
01633 return NULL;
01634 }
|
|
|
|
|
|
Definition at line 1460 of file page_capture.cc. References framePosition. Referenced by PageMagick::VideoThread(), and videoThread(). 01461 {
01462 if ( framePosition == lastPosition )
01463 {
01464 pthread_mutex_lock( &condition_mutex );
01465 pthread_cond_wait( &condition, &condition_mutex );
01466 pthread_mutex_unlock( &condition_mutex );
01467 }
01468
01469 return framePosition;
01470 }
|
|
|
|
|
Definition at line 65 of file page_capture.cc. Referenced by PageCapture::CheckDevices(), on_capture_page_avc_button_clicked(), and videoThread(). |
|
|
Definition at line 76 of file page_capture.cc. Referenced by PageCapture::clean(), and PageCapture::start(). |
|
|
Definition at line 1720 of file page_capture.cc. |
|
|
Definition at line 75 of file page_capture.cc. Referenced by PageCapture::clean(), and PageCapture::start(). |
|
|
Definition at line 49 of file page_editor.cc. Referenced by PageTrim::processCommand(), PageExport::processCommand(), PageEditor::processCommand(), PageCapture::processCommand(), PageTrim::processKeyboard(), PageExport::processKeyboard(), PageEditor::processKeyboard(), PageCapture::processKeyboard(), and showHelp(). |
|
|
Definition at line 58 of file commands.cc. |
|
|
Definition at line 1458 of file page_capture.cc. |
|
|
Definition at line 1457 of file page_capture.cc. |
|
|
Definition at line 44 of file page_capture.cc. |
|
|
Definition at line 86 of file page_capture.cc. Referenced by captureThread(), PageCapture::getFrame(), PageCapture::saveFrame(), PageCapture::startCapture(), videoThread(), and PageCapture::windowMoved(). |
|
|
Definition at line 87 of file page_capture.cc. Referenced by captureThread(). |
|
|
Definition at line 85 of file page_capture.cc. Referenced by captureThread(), PageCapture::getFrame(), PageCapture::saveFrame(), PageCapture::startCapture(), WaitForAction(), and PageCapture::windowMoved(). |
|
|
Definition at line 89 of file page_capture.cc. Referenced by captureThread(), and videoThread(). |
|
|
Definition at line 33 of file callbacks.c. |
|
|
Definition at line 62 of file page_capture.cc. Referenced by PageTrim::processCommand(), PageExport::processCommand(), PageEditor::processCommand(), PageCapture::processCommand(), PageTrim::processKeyboard(), PageExport::processKeyboard(), PageEditor::processKeyboard(), and PageCapture::processKeyboard(). |
|
|
Definition at line 63 of file page_capture.cc. Referenced by PageCapture::newFile(), PageCapture::PageCapture(), and PageCapture::start(). |
|
|
Definition at line 90 of file page_capture.cc. Referenced by videoThread(). |
|
|
Definition at line 58 of file page_capture.cc. Referenced by captureThread(), PageCapture::CheckDevices(), PageCapture::clean(), PageCapture::showFrameInfo(), PageCapture::start(), PageCapture::startCapture(), and PageCapture::~PageCapture(). |
|
|
Definition at line 66 of file page_capture.cc. Referenced by PageCapture::CheckDevices(), PageCapture::PageCapture(), and PageCapture::showFrameInfo(). |
|
|
Definition at line 77 of file page_capture.cc. Referenced by PageCapture::clean(), PageCapture::start(), PageEditor::startNavigator(), and PageEditor::stopNavigator(). |
|
|
Definition at line 60 of file page_capture.cc. Referenced by captureThread(), PageCapture::startCapture(), PageCapture::stopCapture(), and videoThread(). |
|
|
Definition at line 79 of file page_capture.cc. Referenced by captureThread(), PageCapture::startCapture(), PageCapture::stopCapture(), and videoThread(). |
1.4.2