Hi!
I was trying to save incoming RTP stream to an AmAudioFile. The problem
is, that by default the session tries to call an fwrite() for every
incoming packet, and with that I was not even able to make 80
simultaneous call perfect recordings. IO load ...
I put in a 40960B buffer before the fwrite(), and with that I almost got
to 300 identical recordings.
Index: core/AmAudioFile.h
===================================================================
--- core/AmAudioFile.h (revision 20319)
+++ core/AmAudioFile.h (revision 20320)
@@ -107,6 +107,9 @@
/** internal function for opening the file */
int fpopen_int(const string& filename, OpenMode mode, FILE* n_fp, const string& subtype);
+ unsigned char *write_buffer;
+ int write_buffer_index;
+
public:
AmSharedVar<bool> loop;
AmSharedVar<bool> autorewind;
Index: core/AmAudioFile.cpp
===================================================================
--- core/AmAudioFile.cpp (revision 20319)
+++ core/AmAudioFile.cpp (revision 20320)
@@ -243,13 +244,19 @@
: AmBufferedAudio(0, 0, 0), data_size(0),
fp(0), begin(0), loop(false), autorewind(false),
on_close_done(false),
- close_on_exit(true)
+ close_on_exit(true),
+ write_buffer(NULL)
{
}
AmAudioFile::~AmAudioFile()
{
close();
+ if (write_buffer != NULL)
+ {
+ delete[] write_buffer;
+ write_buffer = NULL;
+ }
}
void AmAudioFile::rewind()
@@ -324,6 +331,11 @@
void AmAudioFile::close()
{
if(fp){
+ if (write_buffer != NULL && write_buffer_index > 0)
+ {
+ fwrite((void*)((unsigned char*)write_buffer), 1, write_buffer_index, fp);
+ write_buffer_index = 0;
+ }
on_close();
if(close_on_exit)
@@ -415,6 +427,8 @@
return ret;
}
+#define BUFFER_SIZE (40960)
+
int AmAudioFile::write(unsigned int user_ts, unsigned int size)
{
if(!fp){
@@ -425,11 +439,22 @@
if (getMode() != AmAudioFile::Write) {
return size;
}
+ if (write_buffer == NULL)
+ {
+ write_buffer = new unsigned char[BUFFER_SIZE];
+ write_buffer_index = 0;
+ }
+ if (size + write_buffer_index > BUFFER_SIZE)
+ {
+ fwrite((void*)((unsigned char*)write_buffer), 1, write_buffer_index, fp);
+ write_buffer_index = 0;
+ }
+ memcpy(&write_buffer[write_buffer_index], samples, size);
+ write_buffer_index += size;
- int s = fwrite((void*)((unsigned char*)samples),1,size,fp);
- if(s>0)
- data_size += s;
- return (!ferror(fp) ? s : -1);
+ if(size>0)
+ data_size += size;
+ return (!ferror(fp) ? size : -1);
}
int AmAudioFile::getLength()
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev