mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-09-28 15:56:33 -04:00
Copy audio to UDP/RTP: Opus implementation (3)
This commit is contained in:
parent
4c85516741
commit
297dcce2d3
@ -269,19 +269,6 @@ void AudioNetSink::write(qint16 isample)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CodecOpus:
|
|
||||||
{
|
|
||||||
if (m_codecInputIndex == m_codecInputSize)
|
|
||||||
{
|
|
||||||
int nbBytes = m_opus.encode(m_codecInputSize, m_opusIn, (uint8_t *) m_data);
|
|
||||||
nbBytes = nbBytes > m_udpBlockSize ? m_udpBlockSize : nbBytes;
|
|
||||||
m_udpSocket->writeDatagram((const char*) m_data, (qint64 ) nbBytes, m_address, m_port);
|
|
||||||
m_codecInputIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_opusIn[m_codecInputIndex++] = sample;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CodecL16:
|
case CodecL16:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
@ -327,25 +314,6 @@ void AudioNetSink::write(qint16 isample)
|
|||||||
m_bufferIndex += 1;
|
m_bufferIndex += 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CodecOpus:
|
|
||||||
{
|
|
||||||
if (m_codecInputIndex == m_codecInputSize)
|
|
||||||
{
|
|
||||||
int nbBytes = m_opus.encode(m_codecInputSize, m_opusIn, (uint8_t *) m_data);
|
|
||||||
if (nbBytes != AudioOpus::m_bitrate/400) { // 8 bits for 1/50s (20ms)
|
|
||||||
qWarning("AudioNetSink::write: CodecOpus mono: unexpected output frame size: %d bytes", nbBytes);
|
|
||||||
}
|
|
||||||
m_bufferIndex = 0;
|
|
||||||
m_codecInputIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_codecInputIndex % m_codecRatio == 0) {
|
|
||||||
m_rtpBufferAudio->write((uint8_t *) &m_data[m_bufferIndex++]);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_opusIn[m_codecInputIndex++] = sample;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CodecL16:
|
case CodecL16:
|
||||||
default:
|
default:
|
||||||
m_rtpBufferAudio->write((uint8_t *) &sample);
|
m_rtpBufferAudio->write((uint8_t *) &sample);
|
||||||
@ -391,21 +359,6 @@ void AudioNetSink::write(qint16 ilSample, qint16 irSample)
|
|||||||
case CodecPCMU:
|
case CodecPCMU:
|
||||||
case CodecG722:
|
case CodecG722:
|
||||||
break; // mono modes - do nothing
|
break; // mono modes - do nothing
|
||||||
case CodecOpus:
|
|
||||||
{
|
|
||||||
if (m_codecInputIndex == m_codecInputSize)
|
|
||||||
{
|
|
||||||
int nbBytes = m_opus.encode(m_codecInputSize, m_opusIn, (uint8_t *) m_data);
|
|
||||||
nbBytes = nbBytes > m_udpBlockSize ? m_udpBlockSize : nbBytes;
|
|
||||||
m_udpSocket->writeDatagram((const char*) m_data, (qint64 ) nbBytes, m_address, m_port);
|
|
||||||
m_codecInputIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_opusIn[2*m_codecInputIndex] = lSample;
|
|
||||||
m_opusIn[2*m_codecInputIndex+1] = rSample;
|
|
||||||
m_codecInputIndex++;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CodecL8:
|
case CodecL8:
|
||||||
{
|
{
|
||||||
qint8 *p = (qint8*) &m_data[m_bufferIndex];
|
qint8 *p = (qint8*) &m_data[m_bufferIndex];
|
||||||
@ -437,27 +390,6 @@ void AudioNetSink::write(qint16 ilSample, qint16 irSample)
|
|||||||
case CodecPCMU:
|
case CodecPCMU:
|
||||||
case CodecG722:
|
case CodecG722:
|
||||||
break; // mono modes - do nothing
|
break; // mono modes - do nothing
|
||||||
case CodecOpus:
|
|
||||||
{
|
|
||||||
if (m_codecInputIndex == m_codecInputSize)
|
|
||||||
{
|
|
||||||
int nbBytes = m_opus.encode(m_codecInputSize, m_opusIn, (uint8_t *) m_data);
|
|
||||||
if (nbBytes != AudioOpus::m_bitrate/400) { // 8 bits for 1/50s (20ms)
|
|
||||||
qWarning("AudioNetSink::write: CodecOpus stereo: unexpected output frame size: %d bytes", nbBytes);
|
|
||||||
}
|
|
||||||
m_bufferIndex = 0;
|
|
||||||
m_codecInputIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_codecInputIndex % m_codecRatio == 0) {
|
|
||||||
m_rtpBufferAudio->write((uint8_t *) &m_data[m_bufferIndex++]);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_opusIn[2*m_codecInputIndex] = lSample;
|
|
||||||
m_opusIn[2*m_codecInputIndex+1] = rSample;
|
|
||||||
m_codecInputIndex++;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CodecL8:
|
case CodecL8:
|
||||||
{
|
{
|
||||||
qint8 pl = lSample / 256;
|
qint8 pl = lSample / 256;
|
||||||
|
@ -107,8 +107,8 @@ void RTPSink::setPayloadInformation(PayloadType payloadType, int sampleRate)
|
|||||||
case PayloadG722:
|
case PayloadG722:
|
||||||
m_sampleBytes = 1;
|
m_sampleBytes = 1;
|
||||||
m_rtpSession.SetDefaultPayloadType(9);
|
m_rtpSession.SetDefaultPayloadType(9);
|
||||||
m_packetSamples = m_sampleRate / 50; // 20ms packet samples
|
m_packetSamples = 160; // Fixed 8 kB/s 20ms packet samples
|
||||||
timestampinc = m_sampleRate / 50; // 1 channel
|
timestampinc = 160; // 1 channel
|
||||||
break;
|
break;
|
||||||
case PayloadOpus:
|
case PayloadOpus:
|
||||||
m_sampleBytes = 1;
|
m_sampleBytes = 1;
|
||||||
|
@ -353,7 +353,7 @@ void AudioDialogX::check()
|
|||||||
else if (m_outputDeviceInfo.udpChannelCodec == AudioOutput::UDPCodecOpus)
|
else if (m_outputDeviceInfo.udpChannelCodec == AudioOutput::UDPCodecOpus)
|
||||||
{
|
{
|
||||||
int effectiveSampleRate = m_outputDeviceInfo.sampleRate/decimationFactor;
|
int effectiveSampleRate = m_outputDeviceInfo.sampleRate/decimationFactor;
|
||||||
if ((effectiveSampleRate != 48000) || (effectiveSampleRate != 24000) || (effectiveSampleRate != 16000) || (effectiveSampleRate != 12000)) {
|
if ((effectiveSampleRate != 48000) && (effectiveSampleRate != 24000) && (effectiveSampleRate != 16000) && (effectiveSampleRate != 12000)) {
|
||||||
QMessageBox::information(this, tr("Message"), tr("Opus takes only 48, 24, 16 or 12 kHz sample rates"));
|
QMessageBox::information(this, tr("Message"), tr("Opus takes only 48, 24, 16 or 12 kHz sample rates"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user