Add a Reset() method to AudioFrame.
This method is introduced to try to avoid inconsistent resetting of AudioFrame members to default/uninitialized values. Use it at the call points of DownConvertToCodecFormat(). Results in the following minor functional changes: - speech_activity_ is set to its uninitialized value. AFAICT, this member isn't used at all in the capture path. - timestamp_ is switched from -1 to 0. This member doesn't appear to be used either in the capture path, but left a TODO for wu to change the default value to better represent the uninitialized state. Bonus: Don't copy the frame on error in RemixAndResample(). An error indicates a logical fault (as pointed out by the asserts) that we should not attempt to recover from. BUG=3111 R=turaj@webrtc.org, wu@webrtc.org Review URL: https://webrtc-codereview.appspot.com/21519007 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6289 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@@ -667,6 +667,10 @@ class AudioFrame {
|
|||||||
AudioFrame();
|
AudioFrame();
|
||||||
virtual ~AudioFrame() {}
|
virtual ~AudioFrame() {}
|
||||||
|
|
||||||
|
// Resets all members to their default state (except does not modify the
|
||||||
|
// contents of |data_|).
|
||||||
|
void Reset();
|
||||||
|
|
||||||
// |interleaved_| is not changed by this method.
|
// |interleaved_| is not changed by this method.
|
||||||
void UpdateFrame(int id, uint32_t timestamp, const int16_t* data,
|
void UpdateFrame(int id, uint32_t timestamp, const int16_t* data,
|
||||||
int samples_per_channel, int sample_rate_hz,
|
int samples_per_channel, int sample_rate_hz,
|
||||||
@@ -687,6 +691,7 @@ class AudioFrame {
|
|||||||
// RTP timestamp of the first sample in the AudioFrame.
|
// RTP timestamp of the first sample in the AudioFrame.
|
||||||
uint32_t timestamp_;
|
uint32_t timestamp_;
|
||||||
// NTP time of the estimated capture time in local timebase in milliseconds.
|
// NTP time of the estimated capture time in local timebase in milliseconds.
|
||||||
|
// -1 represents an uninitialized value.
|
||||||
int64_t ntp_time_ms_;
|
int64_t ntp_time_ms_;
|
||||||
int16_t data_[kMaxDataSizeSamples];
|
int16_t data_[kMaxDataSizeSamples];
|
||||||
int samples_per_channel_;
|
int samples_per_channel_;
|
||||||
@@ -706,17 +711,24 @@ class AudioFrame {
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline AudioFrame::AudioFrame()
|
inline AudioFrame::AudioFrame()
|
||||||
: id_(-1),
|
: data_() {
|
||||||
timestamp_(0),
|
Reset();
|
||||||
ntp_time_ms_(0),
|
}
|
||||||
data_(),
|
|
||||||
samples_per_channel_(0),
|
inline void AudioFrame::Reset() {
|
||||||
sample_rate_hz_(0),
|
id_ = -1;
|
||||||
num_channels_(1),
|
// TODO(wu): Zero is a valid value for |timestamp_|. We should initialize
|
||||||
speech_type_(kUndefined),
|
// to an invalid value, or add a new member to indicate invalidity.
|
||||||
vad_activity_(kVadUnknown),
|
timestamp_ = 0;
|
||||||
energy_(0xffffffff),
|
ntp_time_ms_ = -1;
|
||||||
interleaved_(true) {}
|
samples_per_channel_ = 0;
|
||||||
|
sample_rate_hz_ = 0;
|
||||||
|
num_channels_ = 0;
|
||||||
|
speech_type_ = kUndefined;
|
||||||
|
vad_activity_ = kVadUnknown;
|
||||||
|
energy_ = 0xffffffff;
|
||||||
|
interleaved_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
inline void AudioFrame::UpdateFrame(int id, uint32_t timestamp,
|
inline void AudioFrame::UpdateFrame(int id, uint32_t timestamp,
|
||||||
const int16_t* data,
|
const int16_t* data,
|
||||||
|
@@ -43,7 +43,6 @@ void RemixAndResample(const AudioFrame& src_frame,
|
|||||||
if (resampler->InitializeIfNeeded(src_frame.sample_rate_hz_,
|
if (resampler->InitializeIfNeeded(src_frame.sample_rate_hz_,
|
||||||
dst_frame->sample_rate_hz_,
|
dst_frame->sample_rate_hz_,
|
||||||
audio_ptr_num_channels) == -1) {
|
audio_ptr_num_channels) == -1) {
|
||||||
dst_frame->CopyFrom(src_frame);
|
|
||||||
LOG_FERR3(LS_ERROR, InitializeIfNeeded, src_frame.sample_rate_hz_,
|
LOG_FERR3(LS_ERROR, InitializeIfNeeded, src_frame.sample_rate_hz_,
|
||||||
dst_frame->sample_rate_hz_, audio_ptr_num_channels);
|
dst_frame->sample_rate_hz_, audio_ptr_num_channels);
|
||||||
assert(false);
|
assert(false);
|
||||||
@@ -54,7 +53,6 @@ void RemixAndResample(const AudioFrame& src_frame,
|
|||||||
int out_length = resampler->Resample(audio_ptr, src_length, dst_frame->data_,
|
int out_length = resampler->Resample(audio_ptr, src_length, dst_frame->data_,
|
||||||
AudioFrame::kMaxDataSizeSamples);
|
AudioFrame::kMaxDataSizeSamples);
|
||||||
if (out_length == -1) {
|
if (out_length == -1) {
|
||||||
dst_frame->CopyFrom(src_frame);
|
|
||||||
LOG_FERR3(LS_ERROR, Resample, audio_ptr, src_length, dst_frame->data_);
|
LOG_FERR3(LS_ERROR, Resample, audio_ptr, src_length, dst_frame->data_);
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
@@ -81,6 +79,7 @@ void DownConvertToCodecFormat(const int16_t* src_data,
|
|||||||
assert(samples_per_channel <= kMaxMonoDataSizeSamples);
|
assert(samples_per_channel <= kMaxMonoDataSizeSamples);
|
||||||
assert(num_channels == 1 || num_channels == 2);
|
assert(num_channels == 1 || num_channels == 2);
|
||||||
assert(codec_num_channels == 1 || codec_num_channels == 2);
|
assert(codec_num_channels == 1 || codec_num_channels == 2);
|
||||||
|
dst_af->Reset();
|
||||||
|
|
||||||
// Never upsample the capture signal here. This should be done at the
|
// Never upsample the capture signal here. This should be done at the
|
||||||
// end of the send chain.
|
// end of the send chain.
|
||||||
@@ -116,9 +115,6 @@ void DownConvertToCodecFormat(const int16_t* src_data,
|
|||||||
dst_af->samples_per_channel_ = out_length / num_channels;
|
dst_af->samples_per_channel_ = out_length / num_channels;
|
||||||
dst_af->sample_rate_hz_ = destination_rate;
|
dst_af->sample_rate_hz_ = destination_rate;
|
||||||
dst_af->num_channels_ = num_channels;
|
dst_af->num_channels_ = num_channels;
|
||||||
dst_af->timestamp_ = -1;
|
|
||||||
dst_af->speech_type_ = AudioFrame::kNormalSpeech;
|
|
||||||
dst_af->vad_activity_ = AudioFrame::kVadUnknown;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MixWithSat(int16_t target[],
|
void MixWithSat(int16_t target[],
|
||||||
|
@@ -25,10 +25,9 @@ class AudioFrame;
|
|||||||
namespace voe {
|
namespace voe {
|
||||||
|
|
||||||
// Upmix or downmix and resample the audio in |src_frame| to |dst_frame|.
|
// Upmix or downmix and resample the audio in |src_frame| to |dst_frame|.
|
||||||
// Expects |dst_frame| to have its |num_channels_| and |sample_rate_hz_| set to
|
// Expects |dst_frame| to have its sample rate and channels members set to the
|
||||||
// the desired values. Updates |samples_per_channel_| accordingly.
|
// desired values. Updates the samples per channel member accordingly. No other
|
||||||
//
|
// members will be changed.
|
||||||
// On failure, returns -1 and copies |src_frame| to |dst_frame|.
|
|
||||||
void RemixAndResample(const AudioFrame& src_frame,
|
void RemixAndResample(const AudioFrame& src_frame,
|
||||||
PushResampler<int16_t>* resampler,
|
PushResampler<int16_t>* resampler,
|
||||||
AudioFrame* dst_frame);
|
AudioFrame* dst_frame);
|
||||||
@@ -37,6 +36,11 @@ void RemixAndResample(const AudioFrame& src_frame,
|
|||||||
// specified by |codec_num_channels| and |codec_rate_hz|. |mono_buffer| is
|
// specified by |codec_num_channels| and |codec_rate_hz|. |mono_buffer| is
|
||||||
// temporary space and must be of sufficient size to hold the downmixed source
|
// temporary space and must be of sufficient size to hold the downmixed source
|
||||||
// audio (recommend using a size of kMaxMonoDataSizeSamples).
|
// audio (recommend using a size of kMaxMonoDataSizeSamples).
|
||||||
|
//
|
||||||
|
// |dst_af| will have its data and format members (sample rate, channels and
|
||||||
|
// samples per channel) set appropriately. No other members will be changed.
|
||||||
|
// TODO(ajm): For now, this still calls Reset() on |dst_af|. Remove this, as
|
||||||
|
// it shouldn't be needed.
|
||||||
void DownConvertToCodecFormat(const int16_t* src_data,
|
void DownConvertToCodecFormat(const int16_t* src_data,
|
||||||
int samples_per_channel,
|
int samples_per_channel,
|
||||||
int num_channels,
|
int num_channels,
|
||||||
|
Reference in New Issue
Block a user