#include <page_export_pipe.h>
Inheritance diagram for ExportPipe:


Public Member Functions | |
| ExportPipe (PageExport *, KinoCommon *) | |
| Constructor for page. | |
| virtual | ~ExportPipe () |
| Destructor for page. | |
| void | start () |
| Start of page. | |
| void | clean () |
| Leaving the page. | |
| gulong | onActivate () |
| Define active widgets. | |
| void | loadTools (string directory) |
| Load all scripts in a given directory. | |
| void | activateTool (int tool) |
| void | selectTool (int tool) |
Private Member Functions | |
| enum export_result | doExport (PlayList *playlist, int begin, int end, int every, bool preview) |
| The actual export function. | |
Private Attributes | |
| vector< DVPipeTool * > | m_tools |
| char | playlistTempName [20] |
Definition at line 43 of file page_export_pipe.h.
|
||||||||||||
|
Constructor for page.
Definition at line 143 of file page_export_pipe.cc. References activateTool(), Export::common, KinoCommon::getWidget(), loadTools(), lookup_widget(), and on_tool_change(). 00143 : 00144 Export( _exportPage, _common ) 00145 { 00146 cerr << "> Creating ExportPipe Page" << endl; 00147 00148 loadTools( DATADIR "/kino/scripts/exports" ); 00149 string alternate_dir = string( getenv( "HOME" ) ) + string( "/kino/exports" ); 00150 loadTools( alternate_dir ); 00151 00152 char *kinoHome=getenv("KINO_HOME"); 00153 00154 if(kinoHome) 00155 { 00156 string alternate_dir = string( kinoHome ) + string( "/exports" ); 00157 loadTools( alternate_dir ); 00158 } 00159 00160 GtkWidget *window = common->getWidget(); 00161 GtkOptionMenu *option_menu = GTK_OPTION_MENU( lookup_widget( window, "optionmenu_pipe_tools" ) ); 00162 g_signal_connect( G_OBJECT( option_menu ), "changed", G_CALLBACK( on_tool_change ), this ); 00163 00164 activateTool( 0 ); 00165 }
|
|
|
Destructor for page.
Definition at line 170 of file page_export_pipe.cc. 00171 {
00172 cerr << "> Destroying ExportPipe Page" << endl;
00173 }
|
|
|
Definition at line 206 of file page_export_pipe.cc. References Export::common, KinoCommon::getWidget(), lookup_widget(), and m_tools. Referenced by ExportPipe(). 00207 {
00208 // Get the main widget
00209 GtkWidget * window = common->getWidget();
00210
00211 // Start with the option menu
00212 GtkOptionMenu *option_menu = GTK_OPTION_MENU( lookup_widget( window, "optionmenu_pipe_tools" ) );
00213 GtkMenu *menu = GTK_MENU( gtk_option_menu_get_menu( option_menu ) );
00214
00215 // Create a menu if we don't have one
00216 if ( menu == NULL )
00217 {
00218 menu = GTK_MENU( gtk_menu_new( ) );
00219 for ( unsigned int i = 0; i < m_tools.size( ); i ++ )
00220 {
00221 GtkWidget *item = gtk_menu_item_new_with_label( m_tools[ i ] ->m_description.c_str( ) );
00222 gtk_widget_show( item );
00223 gtk_menu_append( menu, item );
00224 }
00225
00226 gtk_option_menu_set_menu( option_menu, GTK_WIDGET( menu ) );
00227 }
00228
00229 // Set the active item
00230 gtk_option_menu_set_history( option_menu, index );
00231 }
|
|
|
Leaving the page.
Reimplemented from Export. Definition at line 292 of file page_export_pipe.cc. References playlistTempName. 00293 {
00294 cerr << ">> Leaving ExportPipe" << endl;
00295 if ( strcmp( playlistTempName, "" ) )
00296 unlink( playlistTempName );
00297 }
|
|
||||||||||||||||||||||||
|
The actual export function.
Implements Export. Definition at line 301 of file page_export_pipe.cc. References AUDIO_RESAMPLE_SRC_SINC_BEST_QUALITY, Export::calculateAdjustedRate(), AudioInfo::channels, DVPipeTool::close(), Export::common, DV_AUDIO_MAX_SAMPLES, DVPipeTool::execute(), EXPORT_RESULT_ABORT, EXPORT_RESULT_FAILURE, EXPORT_RESULT_SUCCESS, Export::exportPage, AudioInfo::frequency, Frame::GetAudioInfo(), AsyncAudioResample< input_t, output_t >::GetError(), PlayList::GetFrame(), GetFramePool(), AsyncAudioResample< input_t, output_t >::GetOutput(), KinoCommon::getPlayList(), KinoCommon::getWidget(), info, Export::innerLoopUpdate(), AsyncAudioResample< input_t, output_t >::IsError(), PageExport::isExporting, Frame::IsPAL(), lookup_widget(), DVPipeTool::m_flags, m_tools, DVPipeTool::output(), playlistTempName, AsyncAudioResample< input_t, output_t >::Process(), AudioInfo::samples, and PlayList::SavePlayList(). 00302 {
00303 enum export_result status = EXPORT_RESULT_SUCCESS;
00304 Frame& frame = *GetFramePool()->GetFrame();
00305 int i = -1, j;
00306
00307 // Get the main widget
00308 GtkWidget *window = common->getWidget();
00309
00310 // Obtain the selected tool
00311 GtkOptionMenu *option_menu = GTK_OPTION_MENU( lookup_widget( window, "optionmenu_pipe_tools" ) );
00312 DVPipeTool *tool = m_tools[ gtk_option_menu_get_history( option_menu ) ];
00313
00314 if ( tool != NULL )
00315 {
00316 // Determine the number of passes to do
00317 int passes = 1;
00318 if ( tool->m_flags.find("double-pass") != string::npos )
00319 passes = 2;
00320
00321 // Get the first frame to determine normalisation
00322 playlist->GetFrame( begin, frame );
00323
00324 // Set up resampling
00325 int16_le_t *audio_buffers[ 4 ];
00326 for ( int c = 0; c < 4; c++ )
00327 audio_buffers[ c ] = new int16_le_t[ 2 * DV_AUDIO_MAX_SAMPLES ];
00328
00329 // Get audio info
00330 AudioInfo info;
00331 frame.GetAudioInfo( info );
00332
00333 // Resample to 48000 if invalid rate detected
00334 if ( info.frequency == 0 )
00335 info.frequency = 48000;
00336
00337 // Evaluate argument for tool
00338 string normalisation = frame.IsPAL( ) ? "pal" : "ntsc";
00339 string aspect = frame.IsWide() ? "16:9" : "4:3";
00340 double length = ( double ) ( end - begin ) / ( frame.IsPAL( ) ? 25.0 : 29.97 );
00341
00342 // Get the profile
00343 GtkOptionMenu *option_menu = GTK_OPTION_MENU( lookup_widget( window, "optionmenu_pipe_profile" ) );
00344 int profile = gtk_option_menu_get_history( option_menu );
00345
00346 // Get the file name
00347 string filename = ( char* ) gtk_entry_get_text( GTK_ENTRY( lookup_widget( window, "entry_export_pipe_file" ) ) );
00348
00349 // first call to innerLoopUpdate initializes progress tracker, which
00350 // we want to do because calculateAdjustedRate generates paused time.
00351 innerLoopUpdate( begin, begin, end + (end - begin + 1) * (passes - 1), every );
00352
00353 // Determine correct amount of audio for duration
00354 double adjustedRate = calculateAdjustedRate( playlist, info.frequency, begin, end, every );
00355 if ( !adjustedRate )
00356 status = EXPORT_RESULT_ABORT;
00357
00358 for (int pass = 1; pass <= passes && exportPage->isExporting; pass++ )
00359 {
00360 // Execute the tool
00361 bool success = false;
00362 if ( common->getPlayList()->GetDocName() == "" )
00363 {
00364 if ( strcmp( playlistTempName, "" ) == 0 )
00365 {
00366 PlayList* copy = new PlayList( *( common->getPlayList() ) );
00367 strcpy( playlistTempName, "/tmp/kino.XXXXXX" );
00368 mkstemp( playlistTempName );
00369 copy->SavePlayList( playlistTempName );
00370 delete copy;
00371 }
00372 success = tool->execute( normalisation, length, profile, filename, playlistTempName, pass, aspect );
00373 }
00374 else
00375 {
00376 success = tool->execute( normalisation, length, profile, filename, common->getPlayList()->GetDocName(), pass, aspect );
00377 }
00378
00379 // Create the resampler
00380 AsyncAudioResample<int16_ne_t,int16_le_t>* resampler = new AsyncAudioResample<int16_ne_t,int16_le_t>(
00381 AUDIO_RESAMPLE_SRC_SINC_BEST_QUALITY, playlist, info.frequency, begin, end, every );
00382 if ( resampler->IsError() )
00383 {
00384 std::cerr << ">>> Resampler error: " << resampler->GetError() << std::endl;
00385 exportPage->isExporting = false;
00386 status = EXPORT_RESULT_FAILURE;
00387 }
00388
00389 // Iterate over all frames in selection
00390 for ( i = begin, j = 0; success && i <= end && exportPage->isExporting; i += every, j++ )
00391 {
00392 // Call innerLoopUpdate
00393 if ( passes > 1 )
00394 innerLoopUpdate( i + (end - begin + 1) / every * (pass - 1),
00395 begin, end + (end - begin + 1), every, i,
00396 pass == 1 ? _("Exporting (pass 1)") : _("Exporting (pass 2)") );
00397 else
00398 innerLoopUpdate( i, begin, end, every );
00399
00400 // Resample
00401 int requestedSamples = frame.CalculateNumberSamples( info.frequency, j );
00402 info.samples = resampler->Process( adjustedRate, requestedSamples );
00403 int16_le_t *p = resampler->GetOutput();
00404 for ( int s = 0; s < info.samples; s++ )
00405 for ( int c = 0; c < info.channels; c++ )
00406 audio_buffers[ c ][ s ] = *p++;
00407
00408 // Get the frame
00409 playlist->GetFrame( i, frame );
00410
00411 if ( info.samples )
00412 frame.EncodeAudio( info, audio_buffers );
00413
00414 // Write the frame
00415 success = tool->output( frame );
00416 }
00417 tool->close( );
00418 delete resampler;
00419 }
00420 for ( int c = 0; c < 4; c++ )
00421 delete[] audio_buffers[ c ];
00422 }
00423
00424 GetFramePool()->DoneWithFrame( &frame );
00425
00426 // Return result
00427 if ( status == EXPORT_RESULT_SUCCESS && !exportPage->isExporting )
00428 return EXPORT_RESULT_ABORT;
00429
00430 return status;
00431 }
|
|
|
Load all scripts in a given directory.
Definition at line 178 of file page_export_pipe.cc. References DVPipeTool::compare(), DVPipeTool::m_active, and m_tools. Referenced by ExportPipe(). 00179 {
00180 char * filename;
00181 struct dirent *entry;
00182
00183 DIR *dir = opendir( directory.c_str( ) );
00184
00185 if ( dir )
00186 {
00187 while ( ( entry = readdir( dir ) ) != NULL )
00188 {
00189 filename = g_strdup_printf( "%s/%s", directory.c_str( ), entry->d_name );
00190 if ( entry->d_name[ 0 ] != '.' )
00191 {
00192 fprintf( stderr, "%s\n", filename );
00193 DVPipeTool *tool = new DVPipeTool( filename );
00194 if ( tool->m_active )
00195 m_tools.push_back( tool );
00196 else
00197 delete tool;
00198 }
00199 g_free( filename );
00200 }
00201 closedir( dir );
00202 }
00203 std::sort( m_tools.begin(), m_tools.end(), DVPipeTool::compare );
00204 }
|
|
|
Define active widgets. This page does not support pausing, and if the system is not loaded, it does not support anything at all. Reimplemented from Export. Definition at line 284 of file page_export_pipe.cc. References EXPORT_EXPORT, EXPORT_PAUSE, and EXPORT_SCENE_LIST. 00285 {
00286 return EXPORT_EXPORT | EXPORT_SCENE_LIST | EXPORT_PAUSE;
00287 }
|
|
|
Definition at line 233 of file page_export_pipe.cc. References Export::common, KinoCommon::getWidget(), lookup_widget(), and m_tools. 00234 {
00235 // Get the main widget
00236 GtkWidget * window = common->getWidget();
00237
00238 // Populate the profiles
00239 GtkOptionMenu *option_menu = GTK_OPTION_MENU( lookup_widget( window, "optionmenu_pipe_profile" ) );
00240 GtkMenu *menu = GTK_MENU( gtk_option_menu_get_menu( option_menu ) );
00241
00242 // Remove the old menu if it exists
00243 if ( menu == NULL )
00244 gtk_option_menu_remove_menu( option_menu );
00245
00246 // Create a new one
00247 menu = GTK_MENU( gtk_menu_new( ) );
00248
00249 // Populate it...
00250 if ( m_tools[ index ] ->m_profiles.size( ) )
00251 {
00252 for ( unsigned int i = 0; i < m_tools[ index ] ->m_profiles.size( ); i ++ )
00253 {
00254 GtkWidget *item = gtk_menu_item_new_with_label( m_tools[ index ] ->m_profiles[ i ].c_str( ) );
00255 gtk_widget_show( item );
00256 gtk_menu_append( menu, item );
00257 }
00258 }
00259 else
00260 {
00261 GtkWidget *item = gtk_menu_item_new_with_label( "[No Profile Available]" );
00262 gtk_widget_show( item );
00263 gtk_menu_append( menu, item );
00264 }
00265
00266 // Set it
00267 gtk_option_menu_set_menu( option_menu, GTK_WIDGET( menu ) );
00268 }
|
|
|
Start of page.
Reimplemented from Export. Definition at line 273 of file page_export_pipe.cc. References playlistTempName. 00274 {
00275 cerr << ">> Entering ExportPipe" << endl;
00276 playlistTempName[ 0 ] = '\0';
00277 }
|
|
|
Definition at line 46 of file page_export_pipe.h. Referenced by activateTool(), doExport(), loadTools(), and selectTool(). |
|
|
Definition at line 47 of file page_export_pipe.h. Referenced by clean(), doExport(), and start(). |
1.4.2