fork download
  1. void AudioDecoder::DecodeThread()
  2. {
  3. AudioFrame frame;
  4. int len;
  5. int got_frame;
  6. int n;
  7.  
  8. if (_audio_pkt.data != NULL)
  9. av_free_packet(&_audio_pkt);
  10.  
  11. if(!_pkt_queue->Pop(&_audio_pkt))
  12. return;
  13.  
  14. _audio_pkt_tmp.data = _audio_pkt.data;
  15. _audio_pkt_tmp.size = _audio_pkt.size;
  16.  
  17. while(_audio_pkt_tmp.size > 0)
  18. {
  19. len = avcodec_decode_audio4(_audio_stream->codec, _av_frame, &got_frame, &_audio_pkt_tmp);
  20.  
  21. if (len < 0)
  22. {
  23. LOG "invalid audio packet or frame. Skipping packet"EL;
  24. break;
  25. }
  26.  
  27. _audio_pkt_tmp.data += len;
  28. _audio_pkt_tmp.size -= len;
  29.  
  30. if (!got_frame)
  31. continue;
  32.  
  33. // 1. copying decoded data into AudioFrame
  34. frame.size = av_samples_get_buffer_size(NULL, _audio_stream->codec->channels, _av_frame->nb_samples,_audio_stream->codec->sample_fmt, 1);
  35.  
  36. // frame.size= _av_frame->linesize[0];
  37.  
  38. LOG "frame size " << frame.size EL;
  39.  
  40. frame.data = fast_aligned(uint8_t,16,frame.size);
  41. memcpy(frame.data,_av_frame->data[0],frame.size);
  42. frame.pts = _pts;
  43.  
  44. n = 2 * _audio_stream->codec->channels;
  45. frame.duration = frame.size*1000 / (n * _audio_stream->codec->sample_rate);
  46. _pts += frame.duration;
  47.  
  48. // 2. save the frame
  49. if (!_frame_queue->Push(frame))
  50. return;
  51. avcodec_get_frame_defaults(_av_frame);
  52. }
  53.  
  54. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty