Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into module_frn
Browse files Browse the repository at this point in the history
  • Loading branch information
sh123 committed Apr 20, 2015
2 parents 5fdcc4a + d1d2059 commit ee3f873
Show file tree
Hide file tree
Showing 26 changed files with 2,275 additions and 101 deletions.
7 changes: 7 additions & 0 deletions src/async/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
by the decoder to write the correct number of samples to its audio sink.
All written samples will be zero-samples.

* Bugfix in Async::AudioRecorder: If a write error occurred, the audio pipe
could be blocked indefinitely. Error handling was improved all over. There
now is a "errorOccurred" signal and a "errorMsg" function.

* Bugfix in Async::AudioEncoder{Opus,Speex,Gsm}: Applications using the Opus,
Speex or Gsm audio encoders could crash due to some dangerous coding.



1.3.1 -- 02 Apr 2015
Expand Down
4 changes: 2 additions & 2 deletions src/async/audio/AsyncAudioEncoderGsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ int AudioEncoderGsm::writeSamples(const float *samples, int count)

if (gsm_buf_len == GSM_BUF_SIZE)
{
gsm_buf_len = 0;

gsm_frame frame[FRAME_COUNT];
for (int frameno=0; frameno<FRAME_COUNT; ++frameno)
{
gsm_encode(gsmh, gsm_buf + frameno * FRAME_SAMPLE_CNT, frame[frameno]);
}

writeEncodedSamples(frame, FRAME_COUNT * sizeof(gsm_frame));

gsm_buf_len = 0;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/async/audio/AsyncAudioEncoderOpus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ int AudioEncoderOpus::writeSamples(const float *samples, int count)

if (buf_len == frame_size)
{
buf_len = 0;
unsigned char output_buf[4000];
opus_int32 nbytes = opus_encode_float(enc, sample_buf, frame_size,
output_buf, sizeof(output_buf));
Expand All @@ -649,7 +650,6 @@ int AudioEncoderOpus::writeSamples(const float *samples, int count)
cerr << "**** ERROR: Opus encoder error: " << opus_strerror(frame_size)
<< endl;
}
buf_len = 0;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/async/audio/AsyncAudioEncoderSpeex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,14 @@ int AudioEncoderSpeex::writeSamples(const float *samples, int count)

if (++frame_cnt == frames_per_packet)
{
frame_cnt = 0;
speex_bits_insert_terminator(&bits);
int nbytes = speex_bits_nbytes(&bits);
char output_buf[nbytes];
nbytes = speex_bits_write(&bits, output_buf, nbytes);
speex_bits_reset(&bits);
//cout << "writing " << nbytes << " bytes\n";
writeEncodedSamples(output_buf, nbytes);
speex_bits_reset(&bits);
frame_cnt = 0;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/async/audio/AsyncAudioNoiseAdder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ using namespace Async;
****************************************************************************/

AudioNoiseAdder::AudioNoiseAdder(float level_db)
: sigma(sqrt(powf(10.0f, level_db / 10.0f) / 2.0f))
: sigma(sqrt(powf(10.0f, level_db / 10.0f) / 2.0f)), generate(false)
{
} /* AudioNoiseAdder::AudioNoiseAdder */

Expand Down
50 changes: 40 additions & 10 deletions src/async/audio/AsyncAudioRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cerrno>
#include <algorithm>
#include <sstream>
#include <sys/time.h>


/****************************************************************************
Expand Down Expand Up @@ -155,7 +158,7 @@ bool AudioRecorder::initialize(void)
file = fopen(filename.c_str(), "w");
if (file == NULL)
{
perror("*** ERROR fopen");
setErrMsgFromErrno("fopen");
return false;
}

Expand All @@ -164,10 +167,19 @@ bool AudioRecorder::initialize(void)
// Leave room for the wave file header
if (fseek(file, WAVE_HEADER_SIZE, SEEK_SET) != 0)
{
perror("fseek");
setErrMsgFromErrno("fseek");
fclose(file);
file = NULL;
return false;
}
}

samples_written = 0;
high_water_mark_reached = false;
timerclear(&begin_timestamp);
timerclear(&end_timestamp);
errmsg = "";

return true;

} /* AudioRecorder::initialize */
Expand All @@ -180,17 +192,23 @@ void AudioRecorder::setMaxRecordingTime(unsigned time_ms, unsigned hw_time_ms)
} /* AudioRecorder::setMaxRecordingTime */


void AudioRecorder::closeFile(void)
bool AudioRecorder::closeFile(void)
{
bool success = true;
if (file != NULL)
{
if (format == FMT_WAV)
{
writeWaveHeader();
success = writeWaveHeader();
}
if (fclose(file) != 0)
{
setErrMsgFromErrno("fclose");
success = false;
}
fclose(file);
file = NULL;
}
return success;
} /* AudioRecorder::closeFile */


Expand Down Expand Up @@ -239,10 +257,12 @@ int AudioRecorder::writeSamples(const float *samples, int count)
}

int written = fwrite(buf, sizeof(*buf), count, file);
if ((written == 0) && ferror(file))
if ((written != count) && ferror(file))
{
fclose(file);
file = NULL;
setErrMsgFromErrno("fwrite");
errorOccurred();
closeFile();
return count;
}

samples_written += written;
Expand Down Expand Up @@ -297,7 +317,7 @@ void AudioRecorder::flushSamples(void)
*
****************************************************************************/

void AudioRecorder::writeWaveHeader(void)
bool AudioRecorder::writeWaveHeader(void)
{
rewind(file);

Expand Down Expand Up @@ -351,8 +371,10 @@ void AudioRecorder::writeWaveHeader(void)

if (fwrite(buf, 1, WAVE_HEADER_SIZE, file) != WAVE_HEADER_SIZE)
{
perror("fwrite");
setErrMsgFromErrno("fwrite");
return false;
}
return true;
} /* AudioRecorder::writeWaveHeader */


Expand All @@ -378,6 +400,14 @@ int AudioRecorder::store16bitValue(char *ptr, uint16_t val)
} /* AudioRecorder::store32bitValue */


void AudioRecorder::setErrMsgFromErrno(const std::string &fname)
{
ostringstream ss;
ss << fname << ": " << strerror(errno);
errmsg = ss.str();
} /* AudioRecorder::setErrMsgFromErrno */



/*
* This file has not been truncated
Expand Down
31 changes: 29 additions & 2 deletions src/async/audio/AsyncAudioRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class AudioRecorder : public Async::AudioSink
* @return Return \em true if the initialization was successful
*
* This function will initialize the recorder and open the file.
* On error, this function returns \em false. The error message can be
* retrieved using the errorMsg function.
*/
bool initialize(void);

Expand All @@ -163,11 +165,14 @@ class AudioRecorder : public Async::AudioSink

/**
* @brief Close the file
* @returns Return \em true if closing went well or \em false otherwise
*
* This function will close the file being recorded to. When the file has
* been closed, all samples coming in after that will be discarded.
* If an error occurr, this function will return \em false. The error
* message can be retrieved using the errorMsg function.
*/
void closeFile(void);
bool closeFile(void);

/**
* @brief Find out how many samples that have been written so far
Expand Down Expand Up @@ -210,6 +215,16 @@ class AudioRecorder : public Async::AudioSink
*/
virtual void flushSamples(void);

/**
* @brief Return the current error message
* @returns Returns the currently set error message
*
* This function is used to retrieve the last set error message. It can
* for example be used when the initialize method return false or when the
* error signal is emitted.
*/
std::string errorMsg(void) const { return errmsg; }

/**
* @brief A signal that's emitted when the max recording time is reached
*
Expand All @@ -220,6 +235,16 @@ class AudioRecorder : public Async::AudioSink
*/
sigc::signal<void> maxRecordingTimeReached;

/**
* @brief This signal is emitted when an error occurrs in the recorder
*
* This signal will be emitted when an error occurrs in the recorder.
* After emitting the signal the associated file will be closed. All audio
* that is written after an error has occurred will be thrown away. To open
* a new file, call the initialize method again.
*/
sigc::signal<void> errorOccurred;

private:
std::string filename;
FILE *file;
Expand All @@ -231,12 +256,14 @@ class AudioRecorder : public Async::AudioSink
bool high_water_mark_reached;
struct timeval begin_timestamp;
struct timeval end_timestamp;
std::string errmsg;

AudioRecorder(const AudioRecorder&);
AudioRecorder& operator=(const AudioRecorder&);
void writeWaveHeader(void);
bool writeWaveHeader(void);
int store32bitValue(char *ptr, uint32_t val);
int store16bitValue(char *ptr, uint16_t val);
void setErrMsgFromErrno(const std::string &fname);

}; /* class AudioRecorder */

Expand Down
6 changes: 2 additions & 4 deletions src/svxlink/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@

* Now printing out when 1750Hz tone burst muting is active.

* Added support for the r828D rtl-sdr tuner.

* Now possible to use an RTL2832u DVB-T dongle directly via USB instead of
using rtl_tcp.
* Bugfix in the QSO recorder: If a write error occurred, the audio pipe could
get stuck leading to audio to stop flowing in other parts of SvxLink.



Expand Down
Loading

0 comments on commit ee3f873

Please sign in to comment.