[ekiga] Cleaned some more the Ekiga::AudioInputCore api and code



commit 2e0fecb83bfa3b802614df73965a3b1321f9bf0a
Author: Julien Puydt <jpuydt gnome org>
Date:   Sun Sep 26 14:00:22 2010 +0200

    Cleaned some more the Ekiga::AudioInputCore api and code
    
    There was a good chunk of partially commented out code -- partially because
    the function declarations and definitions were not commented out, only the
    bodies.
    
    I removed everything.

 lib/engine/audioinput/audioinput-core.cpp |   85 ++---------------------------
 lib/engine/audioinput/audioinput-core.h   |   73 +++++++++----------------
 lib/engine/engine.cpp                     |    2 +-
 3 files changed, 32 insertions(+), 128 deletions(-)
---
diff --git a/lib/engine/audioinput/audioinput-core.cpp b/lib/engine/audioinput/audioinput-core.cpp
index a4661a3..8e03d94 100644
--- a/lib/engine/audioinput/audioinput-core.cpp
+++ b/lib/engine/audioinput/audioinput-core.cpp
@@ -1,4 +1,4 @@
-// 
+//
 /*
  * Ekiga -- A VoIP and Video-Conferencing application
  * Copyright (C) 2000-2009 Damien Sandras <dsandras seconix com>
@@ -42,74 +42,7 @@
 
 using namespace Ekiga;
 
-AudioInputCore::AudioPreviewManager::AudioPreviewManager (AudioInputCore& _audio_input_core, AudioOutputCore& _audio_output_core)
-: PThread (1000, NoAutoDeleteThread, HighestPriority, "PreviewManager"),
-  audio_input_core (_audio_input_core),
-  audio_output_core (_audio_output_core)
-{
-/*  frame = NULL;
-  // Since windows does not like to restart a thread that 
-  // was never started, we do so here
-  this->Resume ();
-  PWaitAndSignal m(quit_mutex);*/
-}
-
-AudioInputCore::AudioPreviewManager::~AudioPreviewManager ()
-{
-/*  if (!stop_thread)
-    stop();*/
-}
-/*
-void AudioInputCore::AudioPreviewManager::start (unsigned width, unsigned height)
-{
-  PTRACE(0, "PreviewManager\tStarting Preview");
-  stop_thread = false;
-  frame = (char*) malloc (unsigned (width * height * 3 / 2));
-
-  display_core.start();
-  this->Restart ();
-  thread_sync_point.Wait ();
-}
-
-void AudioInputCore::AudioPreviewManager::stop ()
-{
-  PTRACE(0, "PreviewManager\tStopping Preview");
-  stop_thread = true;
-
-  // Wait for the Main () method to be terminated 
-  PWaitAndSignal m(quit_mutex);
-
-  if (frame) {
-    free (frame);
-    frame = NULL;
-  }  
-  display_core.stop();
-}
-*/
-void AudioInputCore::AudioPreviewManager::Main ()
-{
-/*  PWaitAndSignal m(quit_mutex);
-  thread_sync_point.Signal ();
-
-  if (!frame)
-    return;
-    
-  unsigned width = 176;
-  unsigned height = 144;;
-  while (!stop_thread) {
-
-    audioinput_core.get_frame_data(width, height, frame);
-    display_core.set_frame_data(width, height, frame, true, 1);
-
-    // We have to sleep some time outside the mutex lock
-    // to give other threads time to get the mutex
-    // It will be taken into account by PAdaptiveDelay
-    Current()->Sleep (5);
-  }*/
-}
-
-AudioInputCore::AudioInputCore (boost::shared_ptr<AudioOutputCore> _audio_output_core):
-  preview_manager(*this, *_audio_output_core.get ())
+AudioInputCore::AudioInputCore ()
 {
   PWaitAndSignal m_var(core_mutex);
   PWaitAndSignal m_vol(volume_mutex);
@@ -281,7 +214,6 @@ void AudioInputCore::start_preview (unsigned channels, unsigned samplerate, unsi
 
   if (current_manager)
     current_manager->set_buffer_size(preview_config.buffer_size, preview_config.num_buffers);
-//    preview_manager.start(preview_config.channels,preview_config.samplerate);
 
   average_level = 0;
 }
@@ -297,7 +229,6 @@ void AudioInputCore::stop_preview ()
     PTRACE(1, "AudioInputCore\tTrying to stop preview in wrong state");
   }
 
-//     preview_manager.stop();
   internal_close();
   internal_set_manager(desired_device);
   preview_config.active = false;
@@ -386,7 +317,7 @@ void AudioInputCore::get_frame_data (char *data,
     }
   }
 
-  if (calculate_average) 
+  if (calculate_average)
     calculate_average_level((const short*) data, bytes_read);
 }
 
@@ -398,7 +329,7 @@ void AudioInputCore::set_volume (unsigned volume)
 }
 
 void AudioInputCore::on_device_opened (AudioInputDevice device,
-                                       AudioInputSettings settings, 
+                                       AudioInputSettings settings,
                                        AudioInputManager *manager)
 {
   device_opened (*manager, device, settings);
@@ -418,9 +349,6 @@ void AudioInputCore::internal_set_device(const AudioInputDevice & device)
 {
   PTRACE(4, "AudioInputCore\tSetting device: " << device);
 
-  if (preview_config.active)
-    preview_manager.stop();
-
   if (preview_config.active || stream_config.active)
     internal_close();
 
@@ -433,7 +361,6 @@ void AudioInputCore::internal_set_device(const AudioInputDevice & device)
       if (current_manager)
         current_manager->set_buffer_size (preview_config.buffer_size, preview_config.num_buffers);
     }
-//    preview_manager.start();
   }
 
   if (stream_config.active) {
@@ -503,7 +430,7 @@ void AudioInputCore::calculate_average_level (const short *buffer, unsigned size
 {
   int sum = 0;
   unsigned csize = 0;
-  
+
   while (csize < (size>>1) ) {
 
     if (*buffer < 0)
@@ -513,6 +440,6 @@ void AudioInputCore::calculate_average_level (const short *buffer, unsigned size
 
     csize++;
   }
-	  
+
   average_level = log10 (9.0*sum/size/32767+1)*1.0;
 }
diff --git a/lib/engine/audioinput/audioinput-core.h b/lib/engine/audioinput/audioinput-core.h
index fa4b103..fe49741 100644
--- a/lib/engine/audioinput/audioinput-core.h
+++ b/lib/engine/audioinput/audioinput-core.h
@@ -62,27 +62,27 @@ namespace Ekiga
   /** Core object for the audio input support
    * The audio input core abstracts all functionality related to audio input
    * in a thread safe manner. Typically, most of the functions except start_stream(),
-   * stop_stream(), set_stream_buffer_size() and get_frame_data() will be called from 
-   * a UI thread, while the three mentioned funtions will be used by an audio 
+   * stop_stream(), set_stream_buffer_size() and get_frame_data() will be called from
+   * a UI thread, while the three mentioned funtions will be used by an audio
    * streaming thread.
-   * 
-   * The audio input core abstracts different audio input managers, which can 
-   * represent different backends like PTLIB, from the application and can 
+   *
+   * The audio input core abstracts different audio input managers, which can
+   * represent different backends like PTLIB, from the application and can
    * switch the input device transparently for the audio streaming thread
    * even while capturing is in progress.
    *
    * If the removal of an audio input device is detected by a failed
-   * read or by a message from the HalCore, the audio input core will 
+   * read or by a message from the HalCore, the audio input core will
    * determine the responsible audio input manager and send a signal to the UI,
-   * which can be used to update device lists. Also, if the removed device was the 
+   * which can be used to update device lists. Also, if the removed device was the
    * currently used one, the core falls back to the backup device.
-   * 
-   * A similar procedure is performed on the addition of a device. In case we fell 
+   *
+   * A similar procedure is performed on the addition of a device. In case we fell
    * back due to a removed device, and the respective device is re-added to the system,
    * it will be automatically activated.
    *
    * The audio input core can also be used in a preview mode, where it starts a separate
-   * thread (represented by the AudioPreviewManager), which grabs frames from the audio 
+   * thread (represented by the AudioPreviewManager), which grabs frames from the audio
    * input core and passes them to the audio output core. This can be used for audio device
    * testing. Note that, contrary to the video preview, the audio preview does not support
    * direct switching between the preview and the streaming mode, which must tus be
@@ -97,7 +97,7 @@ namespace Ekiga
       /** The constructor
        * @param _videooutput_core reference ot the audio output core.
        */
-      AudioInputCore (boost::shared_ptr<AudioOutputCore> _audio_output_core);
+      AudioInputCore ();
 
       /** The destructor
       */
@@ -150,16 +150,16 @@ namespace Ekiga
       /** Set a specific device
        * This function sets the current audio input device. This function can
        * also be used while in a stream or in preview mode. In that case the old
-       * device is closed and the new device opened automatically. 
+       * device is closed and the new device opened automatically.
        * @param device the new device to be used.
        */
       void set_device(const AudioInputDevice & device);
 
       /** Inform the core of an added audioinout device
        * This function is called by the HalCore when an audio device is added.
-       * It determines responsible managers for that specific device and informs the 
-       * GUI about the device that was added (via device_added signal). 
-       * In case the added device was the desired device and we fell back, 
+       * It determines responsible managers for that specific device and informs the
+       * GUI about the device that was added (via device_added signal).
+       * In case the added device was the desired device and we fell back,
        * we will reactivate it. MUST be called from main thread.
        * @param source the device source (e.g. alsa).
        * @param device_name the name of the added device.
@@ -169,8 +169,8 @@ namespace Ekiga
 
       /** Inform the core of a removed audioinput device
        * This function is called by the HalCore when an audio device is removed.
-       * It determines responsible managers for that specific device and informs the 
-       * GUI about the device that was removed (via device_removed signal). 
+       * It determines responsible managers for that specific device and informs the
+       * GUI about the device that was removed (via device_removed signal).
        * In case the removed device was the current device we fall back to the
        * fallback device. MUST be called from main thread.
        * @param source the device source (e.g. alsa).
@@ -179,11 +179,11 @@ namespace Ekiga
        */
       void remove_device (const std::string & source, const std::string & device_name, HalManager* manager);
 
- 
+
       /*** AudioInput Stream and Preview Management ***/
 
       /** Start the preview mode
-       * Contrary to the video input core this can only be done if 
+       * Contrary to the video input core this can only be done if
        * the streaming mode NOT active (responsability of the UI).
        * @param channels the number of channels (1 or 2).
        * @param samplerate the samplerate.
@@ -204,12 +204,12 @@ namespace Ekiga
       void set_stream_buffer_size (unsigned buffer_size, unsigned num_buffers);
 
       /** Start the stream mode
-       * Contrary to the video input core this can only be done if 
+       * Contrary to the video input core this can only be done if
        * preview is NOT active (responsability of the UI)
        * @param channels the number of channels (1 or 2).
        * @param samplerate the samplerate.
        * @param bits_per_sample the number of bits per sample (e.g. 8, 16).
-       */ 
+       */
       void start_stream (unsigned channels, unsigned samplerate, unsigned bits_per_sample);
 
       /** Stop the stream mode
@@ -219,7 +219,7 @@ namespace Ekiga
 
       /** Get one audio buffer from the current manager.
        * This function will block until the buffer is completely filled.
-       * Requires the stream or the preview (when being called from the 
+       * Requires the stream or the preview (when being called from the
        * VideoPreviewManager) to be started.
        * In case the device returns an error reading the frame, get_frame_data()
        * falls back to the fallback device and reads the frame from there. Thus
@@ -274,8 +274,8 @@ namespace Ekiga
       boost::signal2<void, AudioInputDevice, bool> device_removed;
 
   private:
-      void on_device_opened (AudioInputDevice device,  
-                             AudioInputSettings settings, 
+      void on_device_opened (AudioInputDevice device,
+                             AudioInputSettings settings,
                              AudioInputManager *manager);
       void on_device_closed (AudioInputDevice device, AudioInputManager *manager);
       void on_device_error  (AudioInputDevice device, AudioInputErrorCodes error_code, AudioInputManager *manager);
@@ -291,28 +291,8 @@ namespace Ekiga
 
   private:
 
-      class AudioPreviewManager : public PThread
-      {
-        PCLASSINFO(AudioPreviewManager, PThread);
-
-      public:
-        AudioPreviewManager(AudioInputCore& _audio_input_core, AudioOutputCore& _audio_output_core);
-        ~AudioPreviewManager();
-        virtual void start(){};
-        virtual void stop(){};
-
-      protected:
-        void Main (void);
-        bool stop_thread;
-        char* frame;
-        PMutex quit_mutex;     /* To exit */
-        PSyncPoint thread_sync_point;
-        AudioInputCore& audio_input_core;
-        AudioOutputCore& audio_output_core;
-      };
-
       typedef struct DeviceConfig {
-        bool active;
+	bool active;
 
         unsigned channels;
         unsigned samplerate;
@@ -322,8 +302,6 @@ namespace Ekiga
         unsigned num_buffers;
       } DeviceConfig;
 
-  private:
-
       std::set<AudioInputManager *> managers;
 
       DeviceConfig preview_config;
@@ -338,7 +316,6 @@ namespace Ekiga
       PMutex core_mutex;
       PMutex volume_mutex;
 
-      AudioPreviewManager preview_manager;
       AudioInputCoreConfBridge* audioinput_core_conf_bridge;
 
       float average_level;
diff --git a/lib/engine/engine.cpp b/lib/engine/engine.cpp
index 79e0a16..f474bf4 100644
--- a/lib/engine/engine.cpp
+++ b/lib/engine/engine.cpp
@@ -123,7 +123,7 @@ engine_init (Ekiga::ServiceCorePtr service_core,
   boost::shared_ptr<Ekiga::VideoOutputCore> videooutput_core (new Ekiga::VideoOutputCore);
   boost::shared_ptr<Ekiga::VideoInputCore> videoinput_core (new Ekiga::VideoInputCore (videooutput_core));
   boost::shared_ptr<Ekiga::AudioOutputCore> audiooutput_core (new Ekiga::AudioOutputCore);
-  boost::shared_ptr<Ekiga::AudioInputCore> audioinput_core (new Ekiga::AudioInputCore (audiooutput_core));
+  boost::shared_ptr<Ekiga::AudioInputCore> audioinput_core (new Ekiga::AudioInputCore);
   boost::shared_ptr<Ekiga::HalCore> hal_core (new Ekiga::HalCore);
   boost::shared_ptr<Ekiga::FriendOrFoe> friend_or_foe (new Ekiga::FriendOrFoe);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]