00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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 }