Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/mythtv/libs/libmythtv/mythraopconnection.cpp b/mythtv/libs/libmytht
- index 962c142..b9060f0 100644
- --- a/mythtv/libs/libmythtv/mythraopconnection.cpp
- +++ b/mythtv/libs/libmythtv/mythraopconnection.cpp
- @@ -220,10 +220,9 @@ void MythRAOPConnection::udpDataReady(QByteArray buf, QHost
- while (tmp_pkt.size > 0)
- {
- - int decoded_data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
- - int16_t *samples = (int16_t *)av_mallocz(AVCODEC_MAX_AUDIO_FRAME_SIZE);
- - int ret = avcodec_decode_audio3(ctx, samples,
- - &decoded_data_size, &tmp_pkt);
- + AVFrame *frame = avcodec_alloc_frame();
- + int got_frame = 0;
- + int ret = avcodec_decode_audio4(ctx, frame, &got_frame, &tmp_pkt);
- if (ret < 0)
- {
- @@ -231,22 +230,27 @@ void MythRAOPConnection::udpDataReady(QByteArray buf, QHos
- break;
- }
- - if (decoded_data_size > 0)
- + if (ret > 0 && got_frame)
- {
- - int frames = (ctx->channels <= 0 || decoded_data_size < 0) ? -1 :
- - decoded_data_size /
- - (ctx->channels * av_get_bits_per_sample_fmt(ctx->sample_fmt)>>3
- - AudioFrame aframe;
- - aframe.samples = samples;
- - aframe.frames = frames;
- - aframe.size = decoded_data_size;
- + int decoded_size =
- + av_samples_get_buffer_size(NULL, ctx->channels,
- + frame->nb_samples,
- + ctx->sample_fmt, 1);
- +
- + frame->linesize[0] = decoded_size;
- + int frames = frame->nb_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, aframe);
- - m_queueLength += aframe.frames;
- + m_audioQueue.insert(this_timestamp, frame);
- + m_queueLength += frames;
- ProcessAudio(timenow);
- this_timestamp += (frames * 1000) / m_sampleRate;
- @@ -345,14 +349,15 @@ void MythRAOPConnection::ProcessSyncPacket(const QByteArra
- int MythRAOPConnection::ExpireAudio(uint64_t timestamp)
- {
- int res = 0;
- - QMutableMapIterator<uint64_t,AudioFrame> it(m_audioQueue);
- + QMutableMapIterator<uint64_t,AVFrame*> it(m_audioQueue);
- while (it.hasNext())
- {
- it.next();
- if (it.key() < timestamp)
- {
- - AudioFrame frame = it.value();
- - av_free((void *)frame.samples);
- + AVFrame *frame = it.value();
- + m_queueLength -= frame->nb_samples;
- + av_free((void *)frame);
- m_audioQueue.remove(it.key());
- m_queueLength -= frame.frames;
- res++;
- @@ -389,15 +394,15 @@ void MythRAOPConnection::ProcessAudio(uint64_t timenow)
- m_latencyQueued += queue_length;
- m_latencyCounter++;
- - QMapIterator<uint64_t,AudioFrame> it(m_audioQueue);
- + QMapIterator<uint64_t,AVFrame*> it(m_audioQueue);
- while (it.hasNext())
- {
- it.next();
- if (it.key() < ideal_ts)
- {
- - AudioFrame aframe = it.value();
- - m_audio->AddData((char *)aframe.samples, aframe.size,
- - it.key(), aframe.frames);
- + AVFrame *frame = it.value();
- + m_audio->AddData(frame->extended_data[0], frame->linesize[0],
- + it.key(), frame->nb_samples);
- }
- }
- @@ -781,7 +786,7 @@ bool MythRAOPConnection::CreateDecoder(void)
- return false;
- }
- - m_codeccontext = avcodec_alloc_context();
- + m_codeccontext = avcodec_alloc_context3(m_codec);
- if (m_codec && m_codeccontext)
- {
- unsigned char* extradata = new unsigned char[36];
- @@ -806,7 +811,7 @@ bool MythRAOPConnection::CreateDecoder(void)
- m_codeccontext->extradata = extradata;
- m_codeccontext->extradata_size = 36;
- m_codeccontext->channels = 2;
- - if (avcodec_open(m_codeccontext, m_codec) < 0)
- + if (avcodec_open2(m_codeccontext, m_codec, NULL) < 0)
- {
- LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to open ALAC decoder - going
- DestroyDecoder();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement