]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/v4l2_m2m_enc.c
avcodec: Constify AVCodecs
[ffmpeg] / libavcodec / v4l2_m2m_enc.c
index a21a7b6c6576acd131ef1ed667e088ee89a1923f..043fe80c695fff5b4767b9c8226a5c2652f62793 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/videodev2.h>
 #include <sys/ioctl.h>
 #include <search.h>
+#include "encode.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/internal.h"
 #include "libavutil/pixdesc.h"
@@ -288,11 +289,28 @@ static int v4l2_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
     V4L2m2mContext *s = ((V4L2m2mPriv*)avctx->priv_data)->context;
     V4L2Context *const capture = &s->capture;
     V4L2Context *const output = &s->output;
+    AVFrame *frame = s->frame;
     int ret;
 
     if (s->draining)
         goto dequeue;
 
+    if (!frame->buf[0]) {
+        ret = ff_encode_get_frame(avctx, frame);
+        if (ret < 0 && ret != AVERROR_EOF)
+            return ret;
+
+        if (ret == AVERROR_EOF)
+            frame = NULL;
+    }
+
+    ret = v4l2_send_frame(avctx, frame);
+    if (ret != AVERROR(EAGAIN))
+        av_frame_unref(frame);
+
+    if (ret < 0 && ret != AVERROR(EAGAIN))
+        return ret;
+
     if (!output->streamon) {
         ret = ff_v4l2_context_set_status(output, VIDIOC_STREAMON);
         if (ret) {
@@ -403,7 +421,7 @@ static const AVCodecDefault v4l2_m2m_defaults[] = {
 
 #define M2MENC(NAME, LONGNAME, OPTIONS_NAME, CODEC) \
     M2MENC_CLASS(NAME, OPTIONS_NAME) \
-    AVCodec ff_ ## NAME ## _v4l2m2m_encoder = { \
+    const AVCodec ff_ ## NAME ## _v4l2m2m_encoder = { \
         .name           = #NAME "_v4l2m2m" , \
         .long_name      = NULL_IF_CONFIG_SMALL("V4L2 mem2mem " LONGNAME " encoder wrapper"), \
         .type           = AVMEDIA_TYPE_VIDEO, \
@@ -411,13 +429,13 @@ static const AVCodecDefault v4l2_m2m_defaults[] = {
         .priv_data_size = sizeof(V4L2m2mPriv), \
         .priv_class     = &v4l2_m2m_ ## NAME ##_enc_class, \
         .init           = v4l2_encode_init, \
-        .send_frame     = v4l2_send_frame, \
         .receive_packet = v4l2_receive_packet, \
         .close          = v4l2_encode_close, \
         .defaults       = v4l2_m2m_defaults, \
         .capabilities   = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY, \
+        .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP, \
         .wrapper_name   = "v4l2m2m", \
-    };
+    }
 
 M2MENC(mpeg4,"MPEG4", mpeg4_options, AV_CODEC_ID_MPEG4);
 M2MENC(h263, "H.263", options,       AV_CODEC_ID_H263);