First try

AudioMixer has same issue transitioning from silence to encoded
audio and back, it seems.  This makes that go away, but I don't
like it.  Better to support a flush function in the encoder but
for now lets do this and be sure it is the entire issue.
This commit is contained in:
David Kelly 2016-10-26 17:41:34 -07:00
parent 15ee56a50f
commit 6a61762659
3 changed files with 20 additions and 0 deletions

View file

@ -819,6 +819,9 @@ void AudioMixer::broadcastMixes() {
std::unique_ptr<NLPacket> mixPacket;
if (mixHasAudio) {
// may need to flush, this checks
nodeData->flushEncoder();
int mixPacketBytes = sizeof(quint16) + AudioConstants::MAX_CODEC_NAME_LENGTH_ON_WIRE
+ AudioConstants::NETWORK_FRAME_BYTES_STEREO;
mixPacket = NLPacket::create(PacketType::MixedAudio, mixPacketBytes);
@ -852,6 +855,9 @@ void AudioMixer::broadcastMixes() {
// pack number of silent audio samples
quint16 numSilentSamples = AudioConstants::NETWORK_FRAME_SAMPLES_STEREO;
mixPacket->writePrimitive(numSilentSamples);
// we will need to flush encoder since we are sending silent packets outside it
nodeData->shouldFlushEncoder();
}
// Send audio environment

View file

@ -366,6 +366,16 @@ void AudioMixerClientData::sendSelectAudioFormat(SharedNodePointer node, const Q
nodeList->sendPacket(std::move(replyPacket), *node);
}
void AudioMixerClientData::flushEncoder() {
static QByteArray zeros(AudioConstants::NETWORK_FRAME_BYTES_STEREO, 0);
static QByteArray encodedZeros;
if (_shouldFlushEncoder) {
_shouldFlushEncoder = false;
if (_encoder) {
_encoder->encode(zeros, encodedZeros);
}
}
}
void AudioMixerClientData::setupCodec(CodecPluginPointer codec, const QString& codecName) {
cleanupCodec(); // cleanup any previously allocated coders first

View file

@ -77,6 +77,8 @@ public:
encodedBuffer = decodedBuffer;
}
}
void flushEncoder();
void shouldFlushEncoder() { _shouldFlushEncoder = true; }
QString getCodecName() { return _selectedCodecName; }
@ -105,6 +107,8 @@ private:
QString _selectedCodecName;
Encoder* _encoder{ nullptr }; // for outbound mixed stream
Decoder* _decoder{ nullptr }; // for mic stream
bool _shouldFlushEncoder { false };
};
#endif // hifi_AudioMixerClientData_h