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





git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1350 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 18 years ago
parent 2d4211cd1a
commit 1dbdf992a1

@ -76,7 +76,7 @@ amci_subtype_t* AmAudioFileFormat::getSubtype()
}
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 @@ AmAudioFileFormat* AmAudioFile::fileName2Fmt(const string& name)
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 @@ int AmAudioFileFormat::getCodecId()
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 @@ int AmAudioFile::open(const string& filename, OpenMode mode, bool is_tmp)
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 @@ int AmAudioFile::open(const string& filename, OpenMode mode, bool is_tmp)
}
}
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);

@ -99,10 +99,13 @@ protected:
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;

@ -420,6 +420,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) {
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);

@ -171,6 +171,13 @@ class AmPlugIn : public AmPayloadProviderInterface
*/
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).

Loading…
Cancel
Save