Permalink
Browse files

Fixed RAOP audio decoding to use all frames in a packet

While looking over what code needed changing for the next ffmpeg sync, I ran
across this, and found that it was not following the ffmpeg API usage
examples.

Basically, what was coded would decode one audio frame per received packet,
and unceremoniously toss away any remaining data.  I have fixed it to use
all of the received data.
(cherry picked from commit 86f5fd8)
  • Loading branch information...
1 parent a95a2ce commit e41a2832d6848186f940a5834a71d63ea3c4ed3d @Beirdo Beirdo committed Apr 5, 2012
Showing with 33 additions and 17 deletions.
  1. +33 −17 mythtv/libs/libmythtv/mythraopconnection.cpp
@@ -212,29 +212,45 @@ void MythRAOPConnection::udpDataReady(QByteArray buf, QHostAddress peer,
memcpy(decrypted_data + aeslen, data_in + aeslen, len - aeslen);
AVPacket tmp_pkt;
- memset(&tmp_pkt, 0, sizeof(tmp_pkt));
+ av_init_packet(&tmp_pkt);
tmp_pkt.data = decrypted_data;
tmp_pkt.size = len;
- int decoded_data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
- int16_t* samples = (int16_t *)av_mallocz(AVCODEC_MAX_AUDIO_FRAME_SIZE * sizeof(int32_t));
- int used = avcodec_decode_audio3(m_codeccontext, samples,
- &decoded_data_size, &tmp_pkt);
- if (used != len)
- {
- LOG(VB_GENERAL, LOG_WARNING, LOC +
- QString("Decoder only used %1 of %2 bytes.").arg(used).arg(len));
- }
- if (decoded_data_size / 4 != 352)
+ while (tmp_pkt.size > 0)
{
- LOG(VB_GENERAL, LOG_WARNING, LOC + QString("Decoded %1 frames (not 352)")
- .arg(decoded_data_size / 4));
- }
+ int decoded_data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
+ int16_t *samples = (int16_t *)av_mallocz(AVCODEC_MAX_AUDIO_FRAME_SIZE);
+ int used = avcodec_decode_audio3(m_codeccontext, samples,
+ &decoded_data_size, &tmp_pkt);
+
+ if (used < 0)
+ {
+ LOG(VB_GENERAL, LOG_ERR, LOC + QString("Error decoding audio"));
+ break;
+ }
- if (m_audioQueue.contains(this_timestamp))
- LOG(VB_GENERAL, LOG_WARNING, LOC + "Duplicate packet timestamp.");
+ if (decoded_data_size > 0)
+ {
+ int frames = decoded_data_size / 4;
- m_audioQueue.insert(this_timestamp, samples);
+ if (frames != 352)
+ {
+ LOG(VB_GENERAL, LOG_WARNING,
+ LOC + QString("Decoded %1 frames (not 352)") .arg(frames));
+ }
+
+ if (m_audioQueue.contains(this_timestamp))
+ LOG(VB_GENERAL, LOG_WARNING,
+ LOC + "Duplicate packet timestamp.");
+
+ m_audioQueue.insert(this_timestamp, samples);
+
+ this_timestamp += (frames * 1000) / m_sampleRate;
+ }
+
+ tmp_pkt.data += used;
+ tmp_pkt.size -= used;
+ }
// N.B. Unless playback is really messed up, this should only pass through
// properly sequenced packets

0 comments on commit e41a283

Please sign in to comment.