ソースを参照

linux-v4l2: Avoid stopping capture on AVERROR(EAGAIN)

v4l2-decoder: continue sending frame to codec
if avcodec_receive_frame() returns AVERROR(EAGAIN)
JiangXsong 3 ヶ月 前
コミット
bd6c4713bb
1 ファイル変更7 行追加2 行削除
  1. 7 2
      plugins/linux-v4l2/v4l2-decoder.c

+ 7 - 2
plugins/linux-v4l2/v4l2-decoder.c

@@ -17,6 +17,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <obs-module.h>
 #include <linux/videodev2.h>
+#include <libavutil/error.h>
 
 #include "v4l2-decoder.h"
 
@@ -86,14 +87,18 @@ void v4l2_destroy_decoder(struct v4l2_decoder *decoder)
 
 int v4l2_decode_frame(struct obs_source_frame *out, uint8_t *data, size_t length, struct v4l2_decoder *decoder)
 {
+	int r;
 	decoder->packet->data = data;
 	decoder->packet->size = length;
 	if (avcodec_send_packet(decoder->context, decoder->packet) < 0) {
 		blog(LOG_ERROR, "failed to send frame to codec");
 		return -1;
 	}
-
-	if (avcodec_receive_frame(decoder->context, decoder->frame) < 0) {
+	r = avcodec_receive_frame(decoder->context, decoder->frame);
+	if (r == AVERROR(EAGAIN)) {
+		blog(LOG_DEBUG, "failed to receive frame in this state, try to send new frame to codec");
+		return 0;
+	} else if (r < 0) {
 		blog(LOG_ERROR, "failed to receive frame from codec");
 		return -1;
 	}