[FFmpeg-cvslog] jpegls: use the AVFrame API properly.

Anton Khirnov git at videolan.org
Sun Nov 17 13:58:15 CET 2013


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Nov  9 10:14:46 2013 +0100| [706a92926ccae390e3f74520a60b4d5790e8ddc4] | committer: Anton Khirnov

jpegls: use the AVFrame API properly.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=706a92926ccae390e3f74520a60b4d5790e8ddc4
---

 libavcodec/jpegls.h    |    1 -
 libavcodec/jpeglsenc.c |   27 +++++++++++++++------------
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/libavcodec/jpegls.h b/libavcodec/jpegls.h
index 4bf9562..eae3943 100644
--- a/libavcodec/jpegls.h
+++ b/libavcodec/jpegls.h
@@ -33,7 +33,6 @@
 
 typedef struct JpeglsContext {
     AVCodecContext *avctx;
-    AVFrame picture;
 } JpeglsContext;
 
 typedef struct JLSState {
diff --git a/libavcodec/jpeglsenc.c b/libavcodec/jpeglsenc.c
index 9f1fc1f..3af6412 100644
--- a/libavcodec/jpeglsenc.c
+++ b/libavcodec/jpeglsenc.c
@@ -248,8 +248,7 @@ static void ls_store_lse(JLSState *state, PutBitContext *pb)
 static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
                              const AVFrame *pict, int *got_packet)
 {
-    JpeglsContext *const s = avctx->priv_data;
-    AVFrame *const p       = &s->picture;
+    const AVFrame *const p = pict;
     const int near         = avctx->prediction_method;
     PutBitContext pb, pb2;
     GetBitContext gb;
@@ -258,10 +257,6 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
     int i, size, ret;
     int comps;
 
-    *p           = *pict;
-    p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
-
     if (avctx->pix_fmt == AV_PIX_FMT_GRAY8 ||
         avctx->pix_fmt == AV_PIX_FMT_GRAY16)
         comps = 1;
@@ -346,7 +341,7 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
                 Rc[j] = last[j];
             }
             last = cur;
-            cur += s->picture.linesize[0];
+            cur += p->linesize[0];
         }
     } else if (avctx->pix_fmt == AV_PIX_FMT_BGR24) {
         int j, width;
@@ -360,7 +355,7 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
                 Rc[j] = last[j];
             }
             last = cur;
-            cur += s->picture.linesize[0];
+            cur += p->linesize[0];
         }
     }
 
@@ -400,12 +395,20 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
     return 0;
 }
 
+static av_cold int encode_close(AVCodecContext *avctx)
+{
+    av_frame_free(&avctx->coded_frame);
+    return 0;
+}
+
 static av_cold int encode_init_ls(AVCodecContext *ctx)
 {
-    JpeglsContext *c = (JpeglsContext *)ctx->priv_data;
+    ctx->coded_frame = av_frame_alloc();
+    if (!ctx->coded_frame)
+        return AVERROR(ENOMEM);
 
-    c->avctx         = ctx;
-    ctx->coded_frame = &c->picture;
+    ctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
+    ctx->coded_frame->key_frame = 1;
 
     if (ctx->pix_fmt != AV_PIX_FMT_GRAY8  &&
         ctx->pix_fmt != AV_PIX_FMT_GRAY16 &&
@@ -423,8 +426,8 @@ AVCodec ff_jpegls_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("JPEG-LS"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_JPEGLS,
-    .priv_data_size = sizeof(JpeglsContext),
     .init           = encode_init_ls,
+    .close          = encode_close,
     .encode2        = encode_picture_ls,
     .pix_fmts       = (const enum AVPixelFormat[]) {
         AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,



More information about the ffmpeg-cvslog mailing list