[ekiga/gnome-2-26] Fixed the codec description and codec list code a little... #574675 is now ok, but there's worse



commit 2eaa6d8114b95c0722ce9fb09f4cbee087d4d29a
Author: Julien Puydt <jpuydt src gnome org>
Date:   Tue Mar 17 20:28:05 2009 +0000

    Fixed the codec description and codec list code a little... #574675 is now ok, but there's worse
    
    svn path=/trunk/; revision=7777
---
 lib/engine/components/opal/opal-call-manager.cpp   |    4 +-
 .../components/opal/opal-codec-description.cpp     |   19 ++--
 lib/engine/protocol/codec-description.cpp          |  116 ++++++++++++++------
 lib/engine/protocol/codec-description.h            |   35 ++++++-
 4 files changed, 124 insertions(+), 50 deletions(-)

diff --git a/lib/engine/components/opal/opal-call-manager.cpp b/lib/engine/components/opal/opal-call-manager.cpp
index 007266b..acec19d 100644
--- a/lib/engine/components/opal/opal-call-manager.cpp
+++ b/lib/engine/components/opal/opal-call-manager.cpp
@@ -367,7 +367,7 @@ void CallManager::set_codecs (Ekiga::CodecList & _codecs)
     Ekiga::CodecList::iterator i  = 
       search_n (_codecs.begin (), _codecs.end (), 1, *it, same_codec_desc);
     if (i == _codecs.end ()) {
-      _codecs.push_back (*it);
+      _codecs.append (*it);
     }
   }
 
@@ -379,7 +379,7 @@ void CallManager::set_codecs (Ekiga::CodecList & _codecs)
     Ekiga::CodecList::iterator i  = 
       search_n (all_codecs.begin (), all_codecs.end (), 1, *it, same_codec_desc);
     if (i == all_codecs.end ()) {
-      _codecs.erase (it);
+      _codecs.remove (it);
       it = _codecs.begin ();
     }
   }
diff --git a/lib/engine/components/opal/opal-codec-description.cpp b/lib/engine/components/opal/opal-codec-description.cpp
index 5a81d9d..ac8a113 100644
--- a/lib/engine/components/opal/opal-codec-description.cpp
+++ b/lib/engine/components/opal/opal-codec-description.cpp
@@ -27,7 +27,7 @@
 /*
  *                         opal-codec-description.cpp  -  description
  *                         ------------------------------------------
- *   begin                : written in January 2008 by Damien Sandras 
+ *   begin                : written in January 2008 by Damien Sandras
  *   copyright            : (c) 2008 by Damien Sandras
  *   description          : Opal codec description.
  *
@@ -43,14 +43,15 @@
 using namespace Opal;
 
 
-static  bool same_codec_desc (Ekiga::CodecDescription a, Ekiga::CodecDescription b)
-{ 
-  return (a.name == b.name && a.rate == b.rate); 
+static bool
+same_codec_desc (Ekiga::CodecDescription a, Ekiga::CodecDescription b)
+{
+  return (a.name == b.name && a.rate == b.rate);
 }
 
 
 CodecDescription::CodecDescription (OpalMediaFormat & format)
-: Ekiga::CodecDescription ()
+  : Ekiga::CodecDescription ()
 {
   name = (const char *) format.GetEncodingName ();
   if (name == "G722")
@@ -77,10 +78,10 @@ CodecList::CodecList (OpalMediaFormatList & list)
       if (desc.name.empty ())
         continue;
 
-      Ekiga::CodecList::iterator it = 
-        search_n ((*this).begin (), (*this).end (), 1, desc, same_codec_desc);
-      if (it == (*this).end ()) 
-        (*this).push_back (desc);
+      Ekiga::CodecList::iterator it =
+        search_n (begin (), end (), 1, desc, same_codec_desc);
+      if (it == end ())
+        append (desc);
       else {
         it->protocols.sort ();
         it->protocols.merge (desc.protocols);
diff --git a/lib/engine/protocol/codec-description.cpp b/lib/engine/protocol/codec-description.cpp
index d260cc2..fe06972 100644
--- a/lib/engine/protocol/codec-description.cpp
+++ b/lib/engine/protocol/codec-description.cpp
@@ -27,7 +27,7 @@
 /*
  *                         codec-description.cpp  -  description
  *                         ------------------------------------------
- *   begin                : written in January 2008 by Damien Sandras 
+ *   begin                : written in January 2008 by Damien Sandras
  *   copyright            : (c) 2008 by Damien Sandras
  *   description          : declaration of the interface of a codec description.
  *
@@ -44,7 +44,7 @@
 using namespace Ekiga;
 
 CodecDescription::CodecDescription ()
-: rate (0), active (true), audio (false)
+  : rate (0), active (true), audio (false)
 {
 }
 
@@ -54,7 +54,7 @@ CodecDescription::CodecDescription (std::string _name,
                                     bool _audio,
                                     std::string _protocols,
                                     bool _active)
-: name (_name), rate (_rate), active (_active), audio (_audio)
+  : name (_name), rate (_rate), active (_active), audio (_audio)
 {
   char *pch = NULL;
 
@@ -105,7 +105,8 @@ CodecDescription::CodecDescription (std::string codec)
 }
 
 
-std::string CodecDescription::str ()
+std::string
+CodecDescription::str ()
 {
   std::stringstream val;
   std::stringstream proto;
@@ -127,7 +128,8 @@ std::string CodecDescription::str ()
 }
 
 
-bool CodecDescription::operator== (const CodecDescription & c) const
+bool
+CodecDescription::operator== (const CodecDescription & c) const
 {
   CodecDescription d = c;
   CodecDescription e = (*this);
@@ -136,7 +138,8 @@ bool CodecDescription::operator== (const CodecDescription & c) const
 }
 
 
-bool CodecDescription::operator!= (const CodecDescription & c) const
+bool
+CodecDescription::operator!= (const CodecDescription & c) const
 {
   return (!((*this) == c));
 }
@@ -145,87 +148,126 @@ bool CodecDescription::operator!= (const CodecDescription & c) const
 CodecList::CodecList (GSList *codecs_config)
 {
   GSList *codecs_config_it = NULL;
-  
+
   codecs_config_it = (GSList *) codecs_config;
   while (codecs_config_it) {
 
 
     Ekiga::CodecDescription d = Ekiga::CodecDescription ((char *) codecs_config_it->data);
     if (!d.name.empty ())
-      (*this).push_back (d);
+      codecs.push_back (d);
 
     codecs_config_it = g_slist_next (codecs_config_it);
   }
 }
 
 
-void CodecList::append (CodecList & list)
+CodecList::iterator
+CodecList::begin ()
+{
+  return codecs.begin ();
+}
+
+CodecList::const_iterator CodecList::begin () const
+{
+  return codecs.begin ();
+}
+
+CodecList::iterator
+CodecList::end ()
 {
-  (*this).insert ((*this).begin (), list.begin (), list.end ());
+  return codecs.end ();
 }
 
+CodecList::const_iterator
+CodecList::end () const
+{
+  return codecs.end ();
+}
 
-CodecList CodecList::get_audio_list ()
+void
+CodecList::append (CodecList& other)
 {
-  CodecList list;
+  codecs.insert (end (), other.begin (), other.end ());
+}
 
-  for (CodecList::iterator it = (*this).begin ();
-       it != (*this).end ();
+void
+CodecList::append (CodecDescription& descr)
+{
+  codecs.push_back (descr);
+}
+
+void
+CodecList::remove (iterator it)
+{
+  codecs.erase (it);
+}
+
+CodecList
+CodecList::get_audio_list ()
+{
+  CodecList result;
+
+  for (iterator it = begin ();
+       it != end ();
        it++) {
 
     if ((*it).audio)
-      list.push_back (*it);
+      result.codecs.push_back (*it);
   }
 
-  return list;
+  return result;
 }
 
 
-CodecList CodecList::get_video_list ()
+CodecList
+CodecList::get_video_list ()
 {
-  CodecList list;
+  CodecList result;
 
-  for (CodecList::iterator it = (*this).begin ();
-       it != (*this).end ();
+  for (iterator it = begin ();
+       it != end ();
        it++) {
 
     if (!(*it).audio)
-      list.push_back (*it);
+      result.codecs.push_back (*it);
   }
 
-  return list;
+  return result;
 }
 
 
-GSList *CodecList::gslist ()
+GSList*
+CodecList::gslist ()
 {
-  GSList *list = NULL;
+  GSList* result = NULL;
 
-  for (CodecList::iterator it = (*this).begin ();
-       it != (*this).end ();
+  for (iterator it = begin ();
+       it != end ();
        it++) {
 
-    list = g_slist_append (list, g_strdup ((*it).str ().c_str ()));
+    result = g_slist_append (result, g_strdup ((*it).str ().c_str ()));
   }
 
-  return list;
+  return result;
 }
 
 
-bool CodecList::operator== (const CodecList & c) const
+bool
+CodecList::operator== (const CodecList & c) const
 {
   CodecList::const_iterator it2 = c.begin ();
 
-  if ((*this).size () != c.size ())
+  if (codecs.size () != c.codecs.size ())
     return false;
 
-  for (CodecList::const_iterator it = (*this).begin ();
-       it != (*this).end ();
+  for (const_iterator it = begin ();
+       it != end ();
        it++) {
 
-    if ((*it) != (*it2)) 
+    if ((*it) != (*it2))
       return false;
-    
+
     it2++;
   }
 
@@ -233,13 +275,15 @@ bool CodecList::operator== (const CodecList & c) const
 }
 
 
-bool CodecList::operator!= (const CodecList & c) const
+bool
+CodecList::operator!= (const CodecList & c) const
 {
   return (!(*this == c));
 }
 
 
-std::ostream& operator<< (std::ostream & os, const CodecList & c)
+std::ostream&
+operator<< (std::ostream & os, const CodecList & c)
 {
   std::stringstream str;
   for (CodecList::const_iterator it = c.begin ();
diff --git a/lib/engine/protocol/codec-description.h b/lib/engine/protocol/codec-description.h
index 4922f96..4359264 100644
--- a/lib/engine/protocol/codec-description.h
+++ b/lib/engine/protocol/codec-description.h
@@ -81,6 +81,9 @@ namespace Ekiga
        */
       CodecDescription (std::string codec);
 
+      virtual ~CodecDescription ()
+      {}
+
       /** Return the codec description under the form of a string.
        * @return the std::string representing the string description.
        */
@@ -120,10 +123,14 @@ namespace Ekiga
     };
 
 
-  class CodecList : public std::list<CodecDescription>
+  class CodecList
     {
   public :
 
+      typedef std::list<CodecDescription> container_type;
+      typedef container_type::iterator iterator;
+      typedef container_type::const_iterator const_iterator;
+
       /** Constructor that creates an empty CodecList
        */
       CodecList () {};
@@ -133,12 +140,31 @@ namespace Ekiga
        */
       CodecList (GSList *);
 
+      virtual ~CodecList ()
+      {}
+
+      /** Iterators to loop on the list
+       *
+       */
+      iterator begin ();
+      const_iterator begin () const;
+      iterator end ();
+      const_iterator end () const;
 
       /** Append the given CodecList at the end of the current CodecList.
-       * @param list is the CodecList to append to the current one
+       * @param other is the CodecList to append to the current one
        */
-      void append (CodecList & list);
+      void append (CodecList& other);
 
+      /** Append the given codec description to the current CodecList.
+       * @param descr is the CodecDescription to append to the current list
+       */
+      void append (CodecDescription& descr);
+
+      /** Remove the codec description pointed to by the iterator
+       * @param iter is the iterator
+       */
+      void remove (iterator it);
 
       /** Return the list of audio codecs descriptions in the current CodecList 
        * @return the list of audio CodecDescription
@@ -168,6 +194,9 @@ namespace Ekiga
        * @return true if both CodecList are different, false otherwise
        */
       bool operator!= (const CodecList & c) const;
+
+    private:
+      container_type codecs;
     };
 
 /**



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