[FFmpeg-cvslog] r19653 - in trunk/libavcodec: libschroedinger.c libschroedinger.h libschroedingerdec.c libschroedingerenc.c

diego subversion
Sat Aug 15 13:59:53 CEST 2009


Author: diego
Date: Sat Aug 15 13:59:53 2009
New Revision: 19653

Log:
Fix bug caused by difference in stride and picture width.

When a frame is allocated using libschroedinger routines, the frame data size
does not match the actual frame size if the width is not a multiple of 16. So
we cannot do a straightforward memcpy of the frame returned by libschroedinger
into the FFmpeg picture as the stride differs from the width.

Fix this bug by allocating for the libschroedinger frame with the dimensions
in AVCodecContext within libavcodec and passing the frame to libschroedinger.

patch by Anuradha Suraparaju, anuradha rd.bbc.co uk

Modified:
   trunk/libavcodec/libschroedinger.c
   trunk/libavcodec/libschroedinger.h
   trunk/libavcodec/libschroedingerdec.c
   trunk/libavcodec/libschroedingerenc.c

Modified: trunk/libavcodec/libschroedinger.c
==============================================================================
--- trunk/libavcodec/libschroedinger.c	Sat Aug 15 13:42:15 2009	(r19652)
+++ trunk/libavcodec/libschroedinger.c	Sat Aug 15 13:59:53 2009	(r19653)
@@ -77,3 +77,56 @@ int ff_get_schro_frame_format (SchroChro
     }
     return -1;
 }
+
+static void FreeSchroFrame(SchroFrame *frame, void *priv)
+{
+    AVPicture *p_pic = priv;
+
+    if (!p_pic)
+        return;
+
+    avpicture_free(p_pic);
+    av_freep(&p_pic);
+}
+
+SchroFrame *ff_create_schro_frame(AVCodecContext *avccontext,
+                                  SchroFrameFormat schro_frame_fmt)
+{
+    AVPicture *p_pic;
+    SchroFrame *p_frame;
+    int y_width, uv_width;
+    int y_height, uv_height;
+    int i;
+
+    y_width   = avccontext->width;
+    y_height  = avccontext->height;
+    uv_width  = y_width  >> (SCHRO_FRAME_FORMAT_H_SHIFT(schro_frame_fmt));
+    uv_height = y_height >> (SCHRO_FRAME_FORMAT_V_SHIFT(schro_frame_fmt));
+
+    p_pic = av_mallocz(sizeof(AVPicture));
+    avpicture_alloc(p_pic, avccontext->pix_fmt, y_width, y_height);
+
+    p_frame         = schro_frame_new();
+    p_frame->format = schro_frame_fmt;
+    p_frame->width  = y_width;
+    p_frame->height = y_height;
+    schro_frame_set_free_callback(p_frame, FreeSchroFrame, (void *)p_pic);
+
+    for (i = 0; i < 3; ++i) {
+        p_frame->components[i].width  = i ? uv_width : y_width;
+        p_frame->components[i].stride = p_pic->linesize[i];
+        p_frame->components[i].height = i ? uv_height : y_height;
+        p_frame->components[i].length =
+                 p_frame->components[i].stride * p_frame->components[i].height;
+        p_frame->components[i].data   = p_pic->data[i];
+
+        if (i) {
+            p_frame->components[i].v_shift =
+                SCHRO_FRAME_FORMAT_V_SHIFT(p_frame->format);
+            p_frame->components[i].h_shift =
+                SCHRO_FRAME_FORMAT_H_SHIFT(p_frame->format);
+        }
+    }
+
+    return p_frame;
+}

Modified: trunk/libavcodec/libschroedinger.h
==============================================================================
--- trunk/libavcodec/libschroedinger.h	Sat Aug 15 13:42:15 2009	(r19652)
+++ trunk/libavcodec/libschroedinger.h	Sat Aug 15 13:59:53 2009	(r19653)
@@ -53,4 +53,11 @@ SchroVideoFormatEnum ff_get_schro_video_
 int ff_get_schro_frame_format(SchroChromaFormat schro_chroma_fmt,
                               SchroFrameFormat  *schro_frame_fmt);
 
+/**
+* Create a Schro frame based on the dimensions and frame format
+* passed. Returns a pointer to a frame on success, NULL on failure.
+*/
+SchroFrame *ff_create_schro_frame(AVCodecContext *avccontext,
+                                  SchroFrameFormat schro_frame_fmt);
+
 #endif /* AVCODEC_LIBSCHROEDINGER_H */

Modified: trunk/libavcodec/libschroedingerdec.c
==============================================================================
--- trunk/libavcodec/libschroedingerdec.c	Sat Aug 15 13:42:15 2009	(r19652)
+++ trunk/libavcodec/libschroedingerdec.c	Sat Aug 15 13:59:53 2009	(r19653)
@@ -256,11 +256,8 @@ static int libschroedinger_decode_frame(
 
             case SCHRO_DECODER_NEED_FRAME:
                 /* Decoder needs a frame - create one and push it in. */
-
-                frame = schro_frame_new_and_alloc(NULL,
-                                                  p_schro_params->frame_format,
-                                                  format->width,
-                                                  format->height);
+                frame = ff_create_schro_frame(avccontext,
+                                              p_schro_params->frame_format);
                 schro_decoder_add_output_picture(decoder, frame);
                 break;
 

Modified: trunk/libavcodec/libschroedingerenc.c
==============================================================================
--- trunk/libavcodec/libschroedingerenc.c	Sat Aug 15 13:42:15 2009	(r19652)
+++ trunk/libavcodec/libschroedingerenc.c	Sat Aug 15 13:59:53 2009	(r19653)
@@ -223,15 +223,13 @@ static SchroFrame *libschroedinger_frame
     /* Input line size may differ from what the codec supports. Especially
      * when transcoding from one format to another. So use avpicture_layout
      * to copy the frame. */
-    in_frame = schro_frame_new_and_alloc(NULL,
-                                         p_schro_params->frame_format,
-                                         p_schro_params->format->width,
-                                         p_schro_params->format->height);
+    in_frame = ff_create_schro_frame(avccontext, p_schro_params->frame_format);
 
-    avpicture_layout((AVPicture *)in_data, avccontext->pix_fmt,
-                     avccontext->width, avccontext->height,
-                     in_frame->components[0].data,
-                     p_schro_params->frame_size);
+    if (in_frame)
+        avpicture_layout((AVPicture *)in_data, avccontext->pix_fmt,
+                          avccontext->width, avccontext->height,
+                          in_frame->components[0].data,
+                          p_schro_params->frame_size);
 
     return in_frame;
 }



More information about the ffmpeg-cvslog mailing list