While that's not the cause of this issue (camera quits streaming), your note got me looking at the read_frame code.

I'd had a code fragment that just ignored the frame (by re-queuing without processing it) when it didn't match the expected frame size. However, that code was for a specific camera resolution and needed changing for the camera I'm testing with now.

But, the hang occurs immediately after receiving frames of the expected size. I fixedthe code that ignores frames with unexpected buffer sizes, but it never executes even when I see the hangs. So, that's not what's causing this issue.

But thanks for the good suggestion! It lead me to fix what would have been a nasty bug.

Code for read_frame:

Qt Code:
  1. int CameraInterface::read_frame(int)
  2. {
  3. struct v4l2_buffer buf;
  4. unsigned int i;
  5. //qDebug() << frames_read++;
  6. if (testing_only) return 0;
  7.  
  8.  
  9. if (!stream_forever && frames_read >= frame_count)
  10. {
  11. qDebug() << "frame count exceeded";
  12. emit frames_done();
  13. return 0;
  14. }
  15.  
  16. switch (io)
  17. {
  18. .....
  19.  
  20. case IO_METHOD_MMAP:
  21. CLEAR(buf);
  22.  
  23. buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  24. buf.memory = V4L2_MEMORY_MMAP;
  25.  
  26. if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf))
  27. {
  28. switch (errno)
  29. {
  30. case EAGAIN:
  31. return 0;
  32.  
  33. case EIO:
  34. /* Could ignore EIO, see spec. */
  35.  
  36. /* fall through */
  37.  
  38. default:
  39. errno_exit("VIDIOC_DQBUF");
  40. }
  41. }
  42. #if 0
  43. qDebug() << "frames read: " << frames_read++;
  44. if (frames_read % 2)
  45. {
  46. qDebug() << "skipping frame";
  47. xioctl(fd, VIDIOC_QBUF, &buf);
  48. return 1;
  49. }
  50. #endif
  51. frameQueued = false;
  52. assert(buf.index < n_buffers);
  53.  
  54. qDebug() << "\t\t\tframe DQ'ed, bytes " << buf.bytesused << "buffers = " << n_buffers;
  55. if (buf.bytesused != 921600)
  56. {
  57. qDebug() << "partial frame";
  58. xioctl(fd, VIDIOC_QBUF, &buf);
  59. frameQueued = true;
  60. qDebug() << "Unexpected framesize" << buf.bytesused;
  61. //exit(-1);
  62. }
  63. /*
  64.   if (!colorCamera && buf.bytesused < 1843200)
  65.   {
  66.   xioctl(fd, VIDIOC_QBUF, &buf);
  67.   frameQueued = true;
  68.   qDebug() << "Partial frame" << buf.bytesused;
  69.   }
  70.   */
  71. else
  72. {
  73.  
  74. emit frameReady(buffers[buf.index].start,buf.bytesused);
  75.  
  76. // when streaming expect client to send message to queue next frame
  77. // otherwise, we know there's been seconds for client to process frame
  78. // setup = false;
  79. if (!setup)
  80. {
  81. xioctl(fd, VIDIOC_QBUF, &buf);
  82. frameQueued=true;
  83. }
  84. }
  85.  
  86. break;
  87.  
  88. ...
To copy to clipboard, switch view to plain text mode