mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 12:34:48 +02:00
removed parseSilentPacketStreamProperties()
This commit is contained in:
parent
a2d66b9a8f
commit
f71e1edd30
6 changed files with 54 additions and 83 deletions
|
@ -104,13 +104,15 @@ int InboundAudioStream::parseData(const QByteArray& packet) {
|
||||||
|
|
||||||
packetReceivedUpdateTimingStats();
|
packetReceivedUpdateTimingStats();
|
||||||
|
|
||||||
int numAudioSamples;
|
int networkSamples;
|
||||||
|
|
||||||
if (packetType == PacketTypeSilentAudioFrame) {
|
if (packetType == PacketTypeSilentAudioFrame) {
|
||||||
readBytes += parseSilentPacketStreamProperties(packet.mid(readBytes), numAudioSamples);
|
quint16 numSilentSamples = *(reinterpret_cast<const quint16*>(dataAt));
|
||||||
|
readBytes += sizeof(quint16);
|
||||||
|
networkSamples = (int)numSilentSamples;
|
||||||
} else {
|
} else {
|
||||||
// parse the info after the seq number and before the audio data (the stream properties)
|
// parse the info after the seq number and before the audio data (the stream properties)
|
||||||
readBytes += parseStreamProperties(packetType, packet.mid(readBytes), numAudioSamples);
|
readBytes += parseStreamProperties(packetType, packet.mid(readBytes), networkSamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle this packet based on its arrival status.
|
// handle this packet based on its arrival status.
|
||||||
|
@ -120,16 +122,16 @@ int InboundAudioStream::parseData(const QByteArray& packet) {
|
||||||
// NOTE: we assume that each dropped packet contains the same number of samples
|
// NOTE: we assume that each dropped packet contains the same number of samples
|
||||||
// as the packet we just received.
|
// as the packet we just received.
|
||||||
int packetsDropped = arrivalInfo._seqDiffFromExpected;
|
int packetsDropped = arrivalInfo._seqDiffFromExpected;
|
||||||
writeSamplesForDroppedPackets(packetsDropped * numAudioSamples);
|
writeSamplesForDroppedPackets(packetsDropped * networkSamples);
|
||||||
|
|
||||||
// fall through to OnTime case
|
// fall through to OnTime case
|
||||||
}
|
}
|
||||||
case SequenceNumberStats::OnTime: {
|
case SequenceNumberStats::OnTime: {
|
||||||
// Packet is on time; parse its data to the ringbuffer
|
// Packet is on time; parse its data to the ringbuffer
|
||||||
if (packetType == PacketTypeSilentAudioFrame) {
|
if (packetType == PacketTypeSilentAudioFrame) {
|
||||||
writeDroppableSilentSamples(numAudioSamples);
|
writeDroppableSilentSamples(networkSamples);
|
||||||
} else {
|
} else {
|
||||||
readBytes += parseAudioData(packetType, packet.mid(readBytes), numAudioSamples);
|
readBytes += parseAudioData(packetType, packet.mid(readBytes), networkSamples);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -162,15 +164,40 @@ int InboundAudioStream::parseData(const QByteArray& packet) {
|
||||||
return readBytes;
|
return readBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int InboundAudioStream::parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples) {
|
||||||
|
// mixed audio packets do not have any info between the seq num and the audio data.
|
||||||
|
numAudioSamples = packetAfterSeqNum.size() / sizeof(int16_t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int InboundAudioStream::parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int numAudioSamples) {
|
int InboundAudioStream::parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int numAudioSamples) {
|
||||||
return _ringBuffer.writeData(packetAfterStreamProperties.data(), numAudioSamples * sizeof(int16_t));
|
return _ringBuffer.writeData(packetAfterStreamProperties.data(), numAudioSamples * sizeof(int16_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
int InboundAudioStream::parseSilentPacketStreamProperties(const QByteArray& packetAfterSeqNum, int& numAudioSamples) {
|
int InboundAudioStream::writeDroppableSilentSamples(int silentSamples) {
|
||||||
// this is a general silent packet; parse the number of silent samples
|
|
||||||
quint16 numSilentSamples = *(reinterpret_cast<const quint16*>(packetAfterSeqNum.data()));
|
// calculate how many silent frames we should drop.
|
||||||
numAudioSamples = numSilentSamples;
|
int samplesPerFrame = _ringBuffer.getNumFrameSamples();
|
||||||
return sizeof(quint16);
|
int desiredJitterBufferFramesPlusPadding = _desiredJitterBufferFrames + DESIRED_JITTER_BUFFER_FRAMES_PADDING;
|
||||||
|
int numSilentFramesToDrop = 0;
|
||||||
|
|
||||||
|
if (silentSamples >= samplesPerFrame && _currentJitterBufferFrames > desiredJitterBufferFramesPlusPadding) {
|
||||||
|
|
||||||
|
// our avg jitter buffer size exceeds its desired value, so ignore some silent
|
||||||
|
// frames to get that size as close to desired as possible
|
||||||
|
int numSilentFramesToDropDesired = _currentJitterBufferFrames - desiredJitterBufferFramesPlusPadding;
|
||||||
|
int numSilentFramesReceived = silentSamples / samplesPerFrame;
|
||||||
|
numSilentFramesToDrop = std::min(numSilentFramesToDropDesired, numSilentFramesReceived);
|
||||||
|
|
||||||
|
// dont reset _currentJitterBufferFrames here; we want to be able to drop further silent frames
|
||||||
|
// without waiting for _framesAvailableStat to fill up to 10s of samples.
|
||||||
|
_currentJitterBufferFrames -= numSilentFramesToDrop;
|
||||||
|
_silentFramesDropped += numSilentFramesToDrop;
|
||||||
|
|
||||||
|
_framesAvailableStat.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _ringBuffer.addSilentFrame(silentSamples - numSilentFramesToDrop * samplesPerFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
int InboundAudioStream::popSamples(int maxSamples, bool allOrNothing, bool starveIfNoSamplesPopped) {
|
int InboundAudioStream::popSamples(int maxSamples, bool allOrNothing, bool starveIfNoSamplesPopped) {
|
||||||
|
@ -386,34 +413,8 @@ void InboundAudioStream::packetReceivedUpdateTimingStats() {
|
||||||
_lastPacketReceivedTime = now;
|
_lastPacketReceivedTime = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
int InboundAudioStream::writeDroppableSilentSamples(int numSilentSamples) {
|
int InboundAudioStream::writeSamplesForDroppedPackets(int networkSamples) {
|
||||||
|
return writeDroppableSilentSamples(networkSamples);
|
||||||
// calculate how many silent frames we should drop.
|
|
||||||
int samplesPerFrame = _ringBuffer.getNumFrameSamples();
|
|
||||||
int desiredJitterBufferFramesPlusPadding = _desiredJitterBufferFrames + DESIRED_JITTER_BUFFER_FRAMES_PADDING;
|
|
||||||
int numSilentFramesToDrop = 0;
|
|
||||||
|
|
||||||
if (numSilentSamples >= samplesPerFrame && _currentJitterBufferFrames > desiredJitterBufferFramesPlusPadding) {
|
|
||||||
|
|
||||||
// our avg jitter buffer size exceeds its desired value, so ignore some silent
|
|
||||||
// frames to get that size as close to desired as possible
|
|
||||||
int numSilentFramesToDropDesired = _currentJitterBufferFrames - desiredJitterBufferFramesPlusPadding;
|
|
||||||
int numSilentFramesReceived = numSilentSamples / samplesPerFrame;
|
|
||||||
numSilentFramesToDrop = std::min(numSilentFramesToDropDesired, numSilentFramesReceived);
|
|
||||||
|
|
||||||
// dont reset _currentJitterBufferFrames here; we want to be able to drop further silent frames
|
|
||||||
// without waiting for _framesAvailableStat to fill up to 10s of samples.
|
|
||||||
_currentJitterBufferFrames -= numSilentFramesToDrop;
|
|
||||||
_silentFramesDropped += numSilentFramesToDrop;
|
|
||||||
|
|
||||||
_framesAvailableStat.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _ringBuffer.addSilentFrame(numSilentSamples - numSilentFramesToDrop * samplesPerFrame);
|
|
||||||
}
|
|
||||||
|
|
||||||
int InboundAudioStream::writeSamplesForDroppedPackets(int numSamples) {
|
|
||||||
return writeDroppableSilentSamples(numSamples);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float InboundAudioStream::getLastPopOutputFrameLoudness() const {
|
float InboundAudioStream::getLastPopOutputFrameLoudness() const {
|
||||||
|
|
|
@ -159,7 +159,7 @@ private:
|
||||||
void packetReceivedUpdateTimingStats();
|
void packetReceivedUpdateTimingStats();
|
||||||
int clampDesiredJitterBufferFramesValue(int desired) const;
|
int clampDesiredJitterBufferFramesValue(int desired) const;
|
||||||
|
|
||||||
int writeSamplesForDroppedPackets(int numSamples);
|
int writeSamplesForDroppedPackets(int networkSamples);
|
||||||
|
|
||||||
void popSamplesNoCheck(int samples);
|
void popSamplesNoCheck(int samples);
|
||||||
void framesAvailableChanged();
|
void framesAvailableChanged();
|
||||||
|
@ -171,17 +171,15 @@ protected:
|
||||||
|
|
||||||
/// parses the info between the seq num and the audio data in the network packet and calculates
|
/// parses the info between the seq num and the audio data in the network packet and calculates
|
||||||
/// how many audio samples this packet contains (used when filling in samples for dropped packets).
|
/// how many audio samples this packet contains (used when filling in samples for dropped packets).
|
||||||
virtual int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples) = 0;
|
/// default implementation assumes no stream properties and raw audio samples after stream propertiess
|
||||||
|
virtual int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& networkSamples);
|
||||||
|
|
||||||
/// parses a silent packet after the seq. default implementation assumes the number of silent samples
|
|
||||||
/// is the only thing in packetAfterSeqNum and should work in most cases
|
|
||||||
virtual int parseSilentPacketStreamProperties(const QByteArray& packetAfterSeqNum, int& numAudioSamples);
|
|
||||||
|
|
||||||
/// parses the audio data in the network packet.
|
/// parses the audio data in the network packet.
|
||||||
/// default implementation assumes packet contains raw audio samples after stream properties
|
/// default implementation assumes packet contains raw audio samples after stream properties
|
||||||
virtual int parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int numAudioSamples);
|
virtual int parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int networkSamples);
|
||||||
|
|
||||||
int writeDroppableSilentSamples(int numSilentSamples);
|
/// writes silent samples to the buffer that may be dropped to reduce latency caused by the buffer
|
||||||
|
virtual int writeDroppableSilentSamples(int silentSamples);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,3 @@ MixedAudioStream::MixedAudioStream(int numFrameSamples, int numFramesCapacity, c
|
||||||
: InboundAudioStream(numFrameSamples, numFramesCapacity, settings)
|
: InboundAudioStream(numFrameSamples, numFramesCapacity, settings)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int MixedAudioStream::parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples) {
|
|
||||||
// mixed audio packets do not have any info between the seq num and the audio data.
|
|
||||||
numAudioSamples = packetAfterSeqNum.size() / sizeof(int16_t);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,9 +20,6 @@ public:
|
||||||
MixedAudioStream(int numFrameSamples, int numFramesCapacity, const InboundAudioStream::Settings& settings);
|
MixedAudioStream(int numFrameSamples, int numFramesCapacity, const InboundAudioStream::Settings& settings);
|
||||||
|
|
||||||
float getNextOutputFrameLoudness() const { return _ringBuffer.getNextOutputFrameLoudness(); }
|
float getNextOutputFrameLoudness() const { return _ringBuffer.getNextOutputFrameLoudness(); }
|
||||||
|
|
||||||
protected:
|
|
||||||
int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_MixedAudioStream_h
|
#endif // hifi_MixedAudioStream_h
|
||||||
|
|
|
@ -22,29 +22,7 @@ void MixedProcessedAudioStream::outputFormatChanged(int outputFormatChannelCount
|
||||||
_ringBuffer.resizeForFrameSize(deviceOutputFrameSize);
|
_ringBuffer.resizeForFrameSize(deviceOutputFrameSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MixedProcessedAudioStream::parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples) {
|
int MixedProcessedAudioStream::parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int networkSamples) {
|
||||||
// mixed audio packets do not have any info between the seq num and the audio data.
|
|
||||||
int numNetworkSamples = packetAfterSeqNum.size() / sizeof(int16_t);
|
|
||||||
|
|
||||||
// since numAudioSamples is used to know how many samples to add for each dropped packet before this one,
|
|
||||||
// we want to set it to the number of device audio samples since this stream contains device audio samples, not network samples.
|
|
||||||
numAudioSamples = networkToDeviceSamples(numNetworkSamples);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int MixedProcessedAudioStream::parseSilentPacketStreamProperties(const QByteArray& packetAfterSeqNum, int& numAudioSamples) {
|
|
||||||
int numNetworkSamples;
|
|
||||||
int bytesRead = InboundAudioStream::parseSilentPacketStreamProperties(packetAfterSeqNum, numNetworkSamples);
|
|
||||||
|
|
||||||
// since numAudioSamples is used to know how many samples to add for each dropped packet before this one,
|
|
||||||
// we want to set it to the number of device audio samples since this stream contains device audio samples, not network samples.
|
|
||||||
numAudioSamples = networkToDeviceSamples(numNetworkSamples);
|
|
||||||
|
|
||||||
return bytesRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
int MixedProcessedAudioStream::parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int numAudioSamples) {
|
|
||||||
|
|
||||||
QByteArray outputBuffer;
|
QByteArray outputBuffer;
|
||||||
emit processSamples(packetAfterStreamProperties, outputBuffer);
|
emit processSamples(packetAfterStreamProperties, outputBuffer);
|
||||||
|
@ -54,7 +32,11 @@ int MixedProcessedAudioStream::parseAudioData(PacketType type, const QByteArray&
|
||||||
return packetAfterStreamProperties.size();
|
return packetAfterStreamProperties.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MixedProcessedAudioStream::writeDroppableSilentSamples(int silentSamples) {
|
||||||
|
return InboundAudioStream::writeDroppableSilentSamples(networkToDeviceSamples(silentSamples));
|
||||||
|
}
|
||||||
|
|
||||||
int MixedProcessedAudioStream::networkToDeviceSamples(int networkSamples) {
|
int MixedProcessedAudioStream::networkToDeviceSamples(int networkSamples) {
|
||||||
const int STEREO_DIVIDER = 2;
|
const int STEREO_DIVIDER = 2;
|
||||||
return networkSamples * _outputFormatChannelsTimesSampleRate / (STEREO_DIVIDER * SAMPLE_RATE);
|
return networkSamples * _outputFormatChannelsTimesSampleRate / (STEREO_DIVIDER * SAMPLE_RATE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,8 @@ public:
|
||||||
void outputFormatChanged(int outputFormatChannelCountTimesSampleRate);
|
void outputFormatChanged(int outputFormatChannelCountTimesSampleRate);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples);
|
int parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int networkSamples);
|
||||||
int parseSilentPacketStreamProperties(const QByteArray& packetAfterSeqNum, int& numAudioSamples);
|
int writeDroppableSilentSamples(int silentSamples);
|
||||||
int parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int numAudioSamples);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int networkToDeviceSamples(int networkSamples);
|
int networkToDeviceSamples(int networkSamples);
|
||||||
|
|
Loading…
Reference in a new issue