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

framedisplayer.cc

Go to the documentation of this file.
00001 /*
00002 * framedisplayer.cc -- sends frame objects to Displayer and audio device
00003 * Copyright (C) 2000 Arne Schirmacher <arne@schirmacher.de>
00004 * Copyright (C) 2001-2007 Dan Dennedy <dan@dennedy.org>
00005 *
00006 * This program is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU General Public License
00017 * along with this program; if not, write to the Free Software Foundation,
00018 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 #include <iostream>
00026 using std::cerr;
00027 using std::endl;
00028 
00029 #include <pthread.h>
00030 
00031 #include "framedisplayer.h"
00032 #include "preferences.h"
00033 #include "frame.h"
00034 
00035 FrameDisplayer::FrameDisplayer() : 
00036     displayer( NULL ), 
00037     resampler( NULL ), 
00038     audio_device( NULL ),
00039     audio_device_avail( FALSE ),
00040     prevIsWide( false )
00041 {
00042     for ( gint i = 0; i < 4; i++ )
00043         audio_buffers[ i ] = ( gint16 * ) malloc( 2 * DV_AUDIO_MAX_SAMPLES * sizeof( gint16 ) );
00044 }
00045 
00046 
00047 FrameDisplayer::~FrameDisplayer()
00048 {
00049     delete displayer;
00050     for ( gint i = 0; i < 4; i++ )
00051         free( audio_buffers[ i ] );
00052     CloseSound();
00053 }
00054 
00055 
00056 void FrameDisplayer::CloseSound()
00057 {
00058     if ( audio_device_avail )
00059     {
00060         kino_sound_close( audio_device );
00061         audio_device_avail = FALSE;
00062         audio_device = NULL;
00063         delete resampler;
00064         resampler = NULL;
00065     }
00066 }
00067 
00068 
00069 void FrameDisplayer::PutSound( Frame &frame )
00070 {
00071     static Preferences & prefs = Preferences::getInstance();
00072     if ( prefs.enableAudio )
00073     {
00074         if ( audio_device == NULL )
00075             audio_device = kino_sound_new();
00076         if ( audio_device != NULL )
00077         {
00078             if ( !audio_device_avail && 
00079                     ( audio_sampling_rate = kino_sound_init( frame.decoder->audio, audio_device, prefs.audioDevice ) ) != 0 )
00080             {
00081                 audio_device_avail = TRUE;
00082             }
00083             if ( audio_device_avail )
00084             {
00085                 if ( resampler == NULL )
00086                     resampler = AudioResampleFactory<int16_ne_t,int16_ne_t>::createAudioResample(
00087                                     AUDIO_RESAMPLE_SRC_SINC_FASTEST, audio_sampling_rate );
00088                 resampler->Resample( frame );
00089                 if ( resampler->size )
00090                     kino_sound_player( audio_device, resampler->output, resampler->size );
00091             }
00092         }
00093     }
00094 }
00095 
00096 void FrameDisplayer::Put( Frame &frame, GtkWidget *drawingarea, gboolean no_audio )
00097 {
00098     if ( frame.GetWidth() > 0 && frame.GetHeight() > 0 )
00099     {
00100         if ( displayer == NULL )
00101             displayer = FindDisplayer::getDisplayer( drawingarea, frame );
00102         if ( displayer != NULL )
00103         {
00104             DisplayerInput input = DISPLAY_NONE;
00105             switch ( displayer->format() )
00106             {
00107             case DISPLAY_YUV:
00108                 frame.ExtractPreviewYUV( pixels );
00109                 input = DISPLAY_YUV;
00110                 break;
00111             case DISPLAY_RGB:
00112             default:
00113                 frame.ExtractPreviewRGB( pixels );
00114                 input = DISPLAY_RGB;
00115                 break;
00116             }
00117             if ( !no_audio )
00118                 PutSound( frame );
00119             if ( prevIsWide != frame.IsWide() )
00120             {
00121                 prevIsWide = frame.IsWide();
00122                 // The numbers here do not affect the actual display size, only its aspect
00123                 gtk_widget_set_size_request( drawingarea, 320, frame.IsWide() ? 180 : 240 );
00124             }
00125             displayer->put( input, pixels, frame.GetWidth(), frame.GetHeight() );
00126         }
00127     }
00128 }

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