Advertisement
Guest User

Untitled

a guest
Apr 11th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. diff --git a/mythtv/libs/libmythtv/mythraopconnection.cpp b/mythtv/libs/libmytht
  2. index 962c142..b9060f0 100644
  3. --- a/mythtv/libs/libmythtv/mythraopconnection.cpp
  4. +++ b/mythtv/libs/libmythtv/mythraopconnection.cpp
  5. @@ -220,10 +220,9 @@ void MythRAOPConnection::udpDataReady(QByteArray buf, QHost
  6.  
  7. while (tmp_pkt.size > 0)
  8. {
  9. - int decoded_data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
  10. - int16_t *samples = (int16_t *)av_mallocz(AVCODEC_MAX_AUDIO_FRAME_SIZE);
  11. - int ret = avcodec_decode_audio3(ctx, samples,
  12. - &decoded_data_size, &tmp_pkt);
  13. + AVFrame *frame = avcodec_alloc_frame();
  14. + int got_frame = 0;
  15. + int ret = avcodec_decode_audio4(ctx, frame, &got_frame, &tmp_pkt);
  16.  
  17. if (ret < 0)
  18. {
  19. @@ -231,22 +230,27 @@ void MythRAOPConnection::udpDataReady(QByteArray buf, QHos
  20. break;
  21. }
  22.  
  23. - if (decoded_data_size > 0)
  24. + if (ret > 0 && got_frame)
  25. {
  26. - int frames = (ctx->channels <= 0 || decoded_data_size < 0) ? -1 :
  27. - decoded_data_size /
  28. - (ctx->channels * av_get_bits_per_sample_fmt(ctx->sample_fmt)>>3
  29. - AudioFrame aframe;
  30. - aframe.samples = samples;
  31. - aframe.frames = frames;
  32. - aframe.size = decoded_data_size;
  33. + int decoded_size =
  34. + av_samples_get_buffer_size(NULL, ctx->channels,
  35. + frame->nb_samples,
  36. + ctx->sample_fmt, 1);
  37. +
  38. + frame->linesize[0] = decoded_size;
  39. + int frames = frame->nb_samples;
  40. + if (frames != 352)
  41. + {
  42. + LOG(VB_GENERAL, LOG_WARNING,
  43. + LOC + QString("Decoded %1 frames (not 352)") .arg(frames));
  44. + }
  45.  
  46. if (m_audioQueue.contains(this_timestamp))
  47. LOG(VB_GENERAL, LOG_WARNING,
  48. LOC + "Duplicate packet timestamp.");
  49.  
  50.  
  51. - m_audioQueue.insert(this_timestamp, aframe);
  52. - m_queueLength += aframe.frames;
  53. + m_audioQueue.insert(this_timestamp, frame);
  54. + m_queueLength += frames;
  55. ProcessAudio(timenow);
  56.  
  57. this_timestamp += (frames * 1000) / m_sampleRate;
  58. @@ -345,14 +349,15 @@ void MythRAOPConnection::ProcessSyncPacket(const QByteArra
  59. int MythRAOPConnection::ExpireAudio(uint64_t timestamp)
  60. {
  61. int res = 0;
  62. - QMutableMapIterator<uint64_t,AudioFrame> it(m_audioQueue);
  63. + QMutableMapIterator<uint64_t,AVFrame*> it(m_audioQueue);
  64. while (it.hasNext())
  65. {
  66. it.next();
  67. if (it.key() < timestamp)
  68. {
  69. - AudioFrame frame = it.value();
  70. - av_free((void *)frame.samples);
  71. + AVFrame *frame = it.value();
  72. + m_queueLength -= frame->nb_samples;
  73. + av_free((void *)frame);
  74. m_audioQueue.remove(it.key());
  75. m_queueLength -= frame.frames;
  76. res++;
  77. @@ -389,15 +394,15 @@ void MythRAOPConnection::ProcessAudio(uint64_t timenow)
  78. m_latencyQueued += queue_length;
  79. m_latencyCounter++;
  80.  
  81. - QMapIterator<uint64_t,AudioFrame> it(m_audioQueue);
  82. + QMapIterator<uint64_t,AVFrame*> it(m_audioQueue);
  83. while (it.hasNext())
  84. {
  85. it.next();
  86. if (it.key() < ideal_ts)
  87. {
  88. - AudioFrame aframe = it.value();
  89. - m_audio->AddData((char *)aframe.samples, aframe.size,
  90. - it.key(), aframe.frames);
  91. + AVFrame *frame = it.value();
  92. + m_audio->AddData(frame->extended_data[0], frame->linesize[0],
  93. + it.key(), frame->nb_samples);
  94. }
  95. }
  96.  
  97.  
  98. @@ -781,7 +786,7 @@ bool MythRAOPConnection::CreateDecoder(void)
  99. return false;
  100. }
  101.  
  102. - m_codeccontext = avcodec_alloc_context();
  103. + m_codeccontext = avcodec_alloc_context3(m_codec);
  104. if (m_codec && m_codeccontext)
  105. {
  106. unsigned char* extradata = new unsigned char[36];
  107. @@ -806,7 +811,7 @@ bool MythRAOPConnection::CreateDecoder(void)
  108. m_codeccontext->extradata = extradata;
  109. m_codeccontext->extradata_size = 36;
  110. m_codeccontext->channels = 2;
  111. - if (avcodec_open(m_codeccontext, m_codec) < 0)
  112. + if (avcodec_open2(m_codeccontext, m_codec, NULL) < 0)
  113. {
  114. LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to open ALAC decoder - going
  115. DestroyDecoder();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement