mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 12:12:32 +02:00
groundwork for injector support
This commit is contained in:
parent
ed9715ae5f
commit
7d608ba592
3 changed files with 33 additions and 7 deletions
|
@ -535,11 +535,6 @@ void AudioMixer::handleNegotiateAudioFormat(QSharedPointer<ReceivedMessage> mess
|
||||||
|
|
||||||
qDebug() << "selectedCodecName:" << selectedCodecName;
|
qDebug() << "selectedCodecName:" << selectedCodecName;
|
||||||
|
|
||||||
auto avatarAudioStream = clientData->getAvatarAudioStream();
|
|
||||||
if (avatarAudioStream) {
|
|
||||||
avatarAudioStream->setupCodec(selectedCodec, selectedCodecName, AudioConstants::MONO);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto replyPacket = NLPacket::create(PacketType::SelectedAudioFormat);
|
auto replyPacket = NLPacket::create(PacketType::SelectedAudioFormat);
|
||||||
|
|
||||||
// write them to our packet
|
// write them to our packet
|
||||||
|
|
|
@ -142,9 +142,16 @@ int AudioMixerClientData::parseData(ReceivedMessage& message) {
|
||||||
|
|
||||||
if (streamIt == _audioStreams.end()) {
|
if (streamIt == _audioStreams.end()) {
|
||||||
// we don't have this injected stream yet, so add it
|
// we don't have this injected stream yet, so add it
|
||||||
|
auto injectorStream = new InjectedAudioStream(streamIdentifier, isStereo, AudioMixer::getStreamSettings());
|
||||||
|
|
||||||
|
#if INJECTORS_SUPPORT_CODECS
|
||||||
|
injectorStream->setupCodec(_codec, _selectedCodecName, isStereo ? AudioConstants::STEREO : AudioConstants::MONO);
|
||||||
|
qDebug() << "creating new injectorStream... codec:" << _selectedCodecName;
|
||||||
|
#endif
|
||||||
|
|
||||||
auto emplaced = _audioStreams.emplace(
|
auto emplaced = _audioStreams.emplace(
|
||||||
streamIdentifier,
|
streamIdentifier,
|
||||||
std::unique_ptr<InjectedAudioStream> { new InjectedAudioStream(streamIdentifier, isStereo, AudioMixer::getStreamSettings()) }
|
std::unique_ptr<InjectedAudioStream> { injectorStream }
|
||||||
);
|
);
|
||||||
|
|
||||||
streamIt = emplaced.first;
|
streamIt = emplaced.first;
|
||||||
|
@ -343,6 +350,23 @@ void AudioMixerClientData::setupCodec(CodecPluginPointer codec, const QString& c
|
||||||
_selectedCodecName = codecName;
|
_selectedCodecName = codecName;
|
||||||
_encoder = codec->createEncoder(AudioConstants::SAMPLE_RATE, AudioConstants::STEREO);
|
_encoder = codec->createEncoder(AudioConstants::SAMPLE_RATE, AudioConstants::STEREO);
|
||||||
_decoder = codec->createDecoder(AudioConstants::SAMPLE_RATE, AudioConstants::MONO);
|
_decoder = codec->createDecoder(AudioConstants::SAMPLE_RATE, AudioConstants::MONO);
|
||||||
|
|
||||||
|
auto avatarAudioStream = getAvatarAudioStream();
|
||||||
|
if (avatarAudioStream) {
|
||||||
|
avatarAudioStream->setupCodec(codec, codecName, AudioConstants::MONO);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if INJECTORS_SUPPORT_CODECS
|
||||||
|
// fixup codecs for any active injectors...
|
||||||
|
auto it = _audioStreams.begin();
|
||||||
|
while (it != _audioStreams.end()) {
|
||||||
|
SharedStreamPointer stream = it->second;
|
||||||
|
if (stream->getType() == PositionalAudioStream::Injector) {
|
||||||
|
stream->setupCodec(codec, codecName, stream->isStereo() ? AudioConstants::STEREO : AudioConstants::MONO);
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioMixerClientData::cleanupCodec() {
|
void AudioMixerClientData::cleanupCodec() {
|
||||||
|
|
|
@ -289,16 +289,23 @@ int64_t AudioInjector::injectNextFrame() {
|
||||||
|
|
||||||
_currentPacket->seek(audioDataOffset);
|
_currentPacket->seek(audioDataOffset);
|
||||||
|
|
||||||
|
// This code is copying bytes from the _audioData directly into the packet, handling looping appropriately.
|
||||||
|
// Might be a reasonable place to do the encode step here.
|
||||||
|
QByteArray decodedAudio;
|
||||||
while (totalBytesLeftToCopy > 0) {
|
while (totalBytesLeftToCopy > 0) {
|
||||||
int bytesToCopy = std::min(totalBytesLeftToCopy, _audioData.size() - _currentSendOffset);
|
int bytesToCopy = std::min(totalBytesLeftToCopy, _audioData.size() - _currentSendOffset);
|
||||||
|
|
||||||
_currentPacket->write(_audioData.data() + _currentSendOffset, bytesToCopy);
|
decodedAudio.append(_audioData.data() + _currentSendOffset, bytesToCopy);
|
||||||
_currentSendOffset += bytesToCopy;
|
_currentSendOffset += bytesToCopy;
|
||||||
totalBytesLeftToCopy -= bytesToCopy;
|
totalBytesLeftToCopy -= bytesToCopy;
|
||||||
if (_options.loop && _currentSendOffset >= _audioData.size()) {
|
if (_options.loop && _currentSendOffset >= _audioData.size()) {
|
||||||
_currentSendOffset = 0;
|
_currentSendOffset = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// FIXME -- good place to call codec encode here. We need to figure out how to tell the AudioInjector which
|
||||||
|
// codec to use... possible through AbstractAudioInterface.
|
||||||
|
QByteArray encodedAudio = decodedAudio;
|
||||||
|
_currentPacket->write(encodedAudio.data(), encodedAudio.size());
|
||||||
|
|
||||||
// set the correct size used for this packet
|
// set the correct size used for this packet
|
||||||
_currentPacket->setPayloadSize(_currentPacket->pos());
|
_currentPacket->setPayloadSize(_currentPacket->pos());
|
||||||
|
|
Loading…
Reference in a new issue