fork download
  1. void VideoDecoder::DecodeThread()
  2. {
  3. AVPacket pkt;
  4. int len;
  5. uint8_t *data;
  6. int size;
  7. uint32_t h,w;
  8. OrderedFramesIterator it;
  9. bool success_push;
  10.  
  11. if(!_pkt_queue->Pop(&pkt))
  12. return;
  13.  
  14. data = pkt.data;
  15. size = pkt.size;
  16.  
  17. _pkt_pts = pkt.pts *_video_stream->time_base.num*1000/_video_stream->time_base.den;
  18.  
  19. int got_frame;
  20.  
  21. while (pkt.size > 0)
  22. {
  23. len = avcodec_decode_video2(_video_stream->codec,_av_frame,&got_frame,&pkt);
  24. if (len < 0)
  25. {
  26. LOG "invalid video packet or frame. Skipping packet" EL;
  27. break;
  28. }
  29.  
  30. if (got_frame!=0)
  31. {
  32. VideoFrame video_frame;
  33.  
  34. h = _video_stream->codec->height;
  35. w = _video_stream->codec->width;
  36.  
  37. video_frame.y = fast_alloc(uint8_t,h*w);
  38. video_frame.u = fast_alloc(uint8_t,h*w/4);
  39. video_frame.v = fast_alloc(uint8_t,h*w/4);
  40.  
  41. WritePlane(_av_frame->data[0],_av_frame->linesize[0],w,h,video_frame.y);
  42. WritePlane(_av_frame->data[1],_av_frame->linesize[1],w/2,h/2,video_frame.u);
  43. WritePlane(_av_frame->data[2],_av_frame->linesize[2],w/2,h/2,video_frame.v);
  44.  
  45. video_frame .pts = _pkt_pts;
  46. _pkt_pts += GetFramerateDelay();
  47.  
  48. _ordered_frames.insert(make_pair(video_frame.pts, video_frame));
  49. if (_av_frame->key_frame)
  50. {
  51. success_push = true;
  52. for (it = _ordered_frames.begin();
  53. it != _ordered_frames.end() && success_push;
  54. ++it)
  55. success_push = _frame_queue->Push((*it).second);
  56.  
  57. if (!success_push)
  58. {
  59. for (;
  60. it != _ordered_frames.end();
  61. ++it)
  62. {
  63. fast_free((*it).second.y);
  64. fast_free((*it).second.u);
  65. fast_free((*it).second.v);
  66. }
  67. }
  68.  
  69. _ordered_frames.clear();
  70. }
  71. }
  72.  
  73. pkt.size -= len;
  74. pkt.data += len;
  75. }
  76.  
  77. pkt.data = data;
  78. pkt.size = size;
  79.  
  80. av_free_packet(&pkt);
  81. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty