Author: sayer
Date: 2009-04-01 18:43:49 +0200 (Wed, 01 Apr 2009)
New Revision: 1350
Modified:
trunk/core/AmAudioFile.cpp
trunk/core/AmAudioFile.h
trunk/core/AmPlugIn.cpp
trunk/core/AmPlugIn.h
Log:
AmAudioFile's can now be recorded with a specified subtype, appended to the
filename after a pipe ('|') character, e.g.:
AmAudioFile f;
f.open("/tmp/record.wav|A-Law")
The subtypes are defined in the codec modules, currently:
- for wav:
Pcm16, A-Law, Mu-Law
- for ilbc:
iLBC30, iLBC20
Modified: trunk/core/AmAudioFile.cpp
===================================================================
--- trunk/core/AmAudioFile.cpp 2009-04-01 15:53:24 UTC (rev 1349)
+++ trunk/core/AmAudioFile.cpp 2009-04-01 16:43:49 UTC (rev 1350)
@@ -76,7 +76,7 @@
}
-AmAudioFileFormat* AmAudioFile::fileName2Fmt(const string& name)
+AmAudioFileFormat* AmAudioFile::fileName2Fmt(const string& name, const string&
subtype)
{
string ext = file_extension(name);
if(ext == ""){
@@ -90,7 +90,15 @@
return NULL;
}
- return new AmAudioFileFormat(iofmt->name);
+ 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());
+ }
+ }
+ return new AmAudioFileFormat(iofmt->name, subtype_id);
}
@@ -105,6 +113,17 @@
return -1;
}
+string AmAudioFile::getSubtype(string& filename) {
+ string res;
+ size_t dpos = filename.rfind('|');
+ if (dpos != string::npos) {
+ res = filename.substr(dpos+1);
+ filename = filename.substr(0, dpos);
+ }
+ return res;
+}
+
+
// returns 0 if everything's OK
// return -1 if error
int AmAudioFile::open(const string& filename, OpenMode mode, bool is_tmp)
@@ -116,13 +135,16 @@
FILE* n_fp = NULL;
+ string f_name = filename;
+ string subtype = getSubtype(f_name);
+
if(!is_tmp){
- n_fp = fopen(filename.c_str(),mode == AmAudioFile::Read ? "r" : "w+");
+ n_fp = fopen(f_name.c_str(),mode == AmAudioFile::Read ? "r" : "w+");
if(!n_fp){
if(mode == AmAudioFile::Read)
- ERROR("file not found: %s\n",filename.c_str());
+ ERROR("file not found: %s\n",f_name.c_str());
else
- ERROR("could not create/overwrite file: %s\n",filename.c_str());
+ ERROR("could not create/overwrite file: %s\n",f_name.c_str());
return -1;
}
} else {
@@ -133,22 +155,25 @@
}
}
- return fpopen_int(filename, mode, n_fp);
+ return fpopen_int(f_name, mode, n_fp, subtype);
}
int AmAudioFile::fpopen(const string& filename, OpenMode mode, FILE* n_fp)
{
close();
on_close_done = false;
- return fpopen_int(filename, mode, n_fp);
+ string f_name = filename;
+ string subtype = getSubtype(f_name);
+ return fpopen_int(f_name, mode, n_fp, subtype);
}
-int AmAudioFile::fpopen_int(const string& filename, OpenMode mode, FILE* n_fp)
+int AmAudioFile::fpopen_int(const string& filename, OpenMode mode, FILE* n_fp,
const string& subtype)
{
- AmAudioFileFormat* f_fmt = fileName2Fmt(filename);
+ AmAudioFileFormat* f_fmt = fileName2Fmt(filename, subtype);
if(!f_fmt){
- ERROR("while trying to the format of '%s'\n",filename.c_str());
+ ERROR("while trying to determine the format of '%s'\n",
+ filename.c_str());
return -1;
}
fmt.reset(f_fmt);
Modified: trunk/core/AmAudioFile.h
===================================================================
--- trunk/core/AmAudioFile.h 2009-04-01 15:53:24 UTC (rev 1349)
+++ trunk/core/AmAudioFile.h 2009-04-01 16:43:49 UTC (rev 1350)
@@ -99,10 +99,13 @@
int write(unsigned int user_ts, unsigned int size);
/** @return a file format from file name. (ex: '1234.wav') */
- virtual AmAudioFileFormat* fileName2Fmt(const string& name);
+ virtual AmAudioFileFormat* fileName2Fmt(const string& name, const string&
subtype);
+ /** @return subtype ID and trim filename if subtype embedded */
+ string getSubtype(string& filename);
+
/** internal function for opening the file */
- int fpopen_int(const string& filename, OpenMode mode, FILE* n_fp);
+ int fpopen_int(const string& filename, OpenMode mode, FILE* n_fp, const
string& subtype);
public:
AmSharedVar<bool> loop;
Modified: trunk/core/AmPlugIn.cpp
===================================================================
--- trunk/core/AmPlugIn.cpp 2009-04-01 15:53:24 UTC (rev 1349)
+++ trunk/core/AmPlugIn.cpp 2009-04-01 16:43:49 UTC (rev 1350)
@@ -420,6 +420,22 @@
return 0;
}
+int AmPlugIn::subtypeID(amci_inoutfmt_t* iofmt, const string& subtype_name) {
+ if(!iofmt)
+ return -1;
+
+ amci_subtype_t* st = iofmt->subtypes;
+ if(subtype_name.empty()) // default subtype wanted
+ return st->type;
+
+ for(;;st++){
+ if(!st || st->type<0) break;
+ if(st->name == subtype_name)
+ return st->type;
+ }
+ return -1;
+}
+
AmSessionFactory* AmPlugIn::getFactory4App(const string& app_name)
{
std::map<std::string,AmSessionFactory*>::iterator it =
name2app.find(app_name);
Modified: trunk/core/AmPlugIn.h
===================================================================
--- trunk/core/AmPlugIn.h 2009-04-01 15:53:24 UTC (rev 1349)
+++ trunk/core/AmPlugIn.h 2009-04-01 16:43:49 UTC (rev 1350)
@@ -172,6 +172,13 @@
amci_subtype_t* subtype(amci_inoutfmt_t* iofmt, int subtype);
/**
+ * File subtype ID lookup function.
+ * @param subtype_name The subtype's name (e.g. Pcm16).
+ * @return -1 if failed.
+ */
+ int subtypeID(amci_inoutfmt_t* iofmt, const string& subtype_name);
+
+ /**
* Codec lookup function.
* @param id Codec ID (see amci/codecs.h).
* @return NULL if failed.
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev