Module: sems
Branch: master
Commit: a1fb8aff150a6d297796357469115e65a65a81ba
URL: 
https://github.com/sems-server/sems/commit/a1fb8aff150a6d297796357469115e65a65a81ba

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date: 2015-06-08T22:01:04+02:00

b/f:core:audio: use audio fmt looked up with subtype name (corrects channels, 
rate)

---

Modified: core/AmAudioFile.cpp
Modified: core/AmAudioFile.h
Modified: core/AmPlugIn.cpp
Modified: core/AmPlugIn.h

---

Diff:  
https://github.com/sems-server/sems/commit/a1fb8aff150a6d297796357469115e65a65a81ba.diff
Patch: 
https://github.com/sems-server/sems/commit/a1fb8aff150a6d297796357469115e65a65a81ba.patch

---

diff --git a/core/AmAudioFile.cpp b/core/AmAudioFile.cpp
index f09a732..35b2161 100644
--- a/core/AmAudioFile.cpp
+++ b/core/AmAudioFile.cpp
@@ -42,6 +42,21 @@ AmAudioFileFormat::AmAudioFileFormat(const string& name, int 
subtype)
     channels = p_subtype->channels;
     subtype = p_subtype->type;
   } 
+  DBG("created AmAudioFileFormat of subtype %i, with rate %u, channels %u\n",
+      subtype, rate, channels);
+}
+
+AmAudioFileFormat::AmAudioFileFormat(const string& name, int subtype, 
amci_subtype_t* p_subtype)
+  : name(name), subtype(subtype), p_subtype(p_subtype)
+{
+  codec = getCodec();
+    
+  if(p_subtype && codec){
+    rate = p_subtype->sample_rate;
+    channels = p_subtype->channels;
+  } 
+  DBG("created AmAudioFileFormat of subtype %i, with rate %u, channels %u\n",
+      subtype, rate, channels);
 }
 
 amci_codec_t* AmAudioFileFormat::getCodec()
@@ -101,15 +116,16 @@ AmAudioFileFormat* AmAudioFile::fileName2Fmt(const 
string& name, const string& s
     return NULL;
   }
 
-  int subtype_id = -1;
   if (!subtype.empty()) {
-    subtype_id = AmPlugIn::instance()->subtypeID(iofmt, subtype);
-    if (subtype_id<0) {
-      WARN("subtype '%s' for file '%s' not found. Using default subtype\n",
-          subtype.c_str(), name.c_str());
+    amci_subtype_t* st = AmPlugIn::instance()->subtype(iofmt, subtype);
+    if (st!=NULL) {
+      return new AmAudioFileFormat(iofmt->name, st->type, st);
     }
+    WARN("subtype '%s' for file '%s' not found. Using default subtype\n",
+        subtype.c_str(), name.c_str());
   }
-  return new AmAudioFileFormat(iofmt->name, subtype_id);
+
+  return new AmAudioFileFormat(iofmt->name, -1);
 }
 
 
diff --git a/core/AmAudioFile.h b/core/AmAudioFile.h
index 3a06c56..0b56e22 100644
--- a/core/AmAudioFile.h
+++ b/core/AmAudioFile.h
@@ -54,6 +54,9 @@ class AmAudioFileFormat: public AmAudioFormat
    * @param subtype Subtype for the file format (see amci.h).
    */
   AmAudioFileFormat(const string& name, int subtype = -1);
+  /** format with rate & channels, not taken from subtype */
+
+  AmAudioFileFormat(const string& name, int subtype, amci_subtype_t* 
p_subtype);
 
   virtual ~AmAudioFileFormat()  { }
 
diff --git a/core/AmPlugIn.cpp b/core/AmPlugIn.cpp
index f210406..7664e91 100644
--- a/core/AmPlugIn.cpp
+++ b/core/AmPlugIn.cpp
@@ -448,20 +448,22 @@ amci_subtype_t* AmPlugIn::subtype(amci_inoutfmt_t* iofmt, 
int subtype)
   return 0;
 }
 
-int AmPlugIn::subtypeID(amci_inoutfmt_t* iofmt, const string& subtype_name) {
+amci_subtype_t* AmPlugIn::subtype(amci_inoutfmt_t* iofmt, const string& 
subtype_name) {
   if(!iofmt)
-    return -1;
+    return NULL;
 
+  DBG("looking for subtype '%s'\n", subtype_name.c_str());
   amci_subtype_t* st = iofmt->subtypes;
   if(subtype_name.empty()) // default subtype wanted
-    return st->type;
+    return st;
 
   for(;;st++){
     if(!st || st->type<0) break;
-    if(st->name == subtype_name)
-      return st->type;
+    if(st->name == subtype_name) {
+      return st;
+    }
   }
-  return -1;
+  return NULL;
 }
 
 AmSessionFactory* AmPlugIn::getFactory4App(const string& app_name)
diff --git a/core/AmPlugIn.h b/core/AmPlugIn.h
index 3895ec3..b8e6485 100644
--- a/core/AmPlugIn.h
+++ b/core/AmPlugIn.h
@@ -186,11 +186,11 @@ class AmPlugIn : public AmPayloadProvider
   amci_subtype_t*  subtype(amci_inoutfmt_t* iofmt, int subtype);
 
   /** 
-   * File subtype ID lookup function.
+   * File subtype lookup function.
    * @param subtype_name The subtype's name (e.g. Pcm16).
-   * @return -1 if failed.
+   * @return NULL if failed.
    */
-  int subtypeID(amci_inoutfmt_t* iofmt, const string& subtype_name);
+  amci_subtype_t* subtype(amci_inoutfmt_t* iofmt, const string& subtype_name);
 
   /** 
    * Codec lookup function.

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to