diff options
author | Anuradha Suraparaju <anuradha@rd.bbc.co.uk> | 2009-08-15 11:59:53 +0000 |
---|---|---|
committer | Diego Biurrun <diego@biurrun.de> | 2009-08-15 11:59:53 +0000 |
commit | d15f2e00c5a0c2b84f1a1f457044b6e57ca7e63d (patch) | |
tree | 0b005cec238ba7221133904d7188276696e27787 /libavcodec/libschroedinger.c | |
parent | 0ebe3b8e2bf74503d7c9cc383e29254a3cb06d55 (diff) | |
download | ffmpeg-d15f2e00c5a0c2b84f1a1f457044b6e57ca7e63d.tar.gz |
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
Originally committed as revision 19653 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/libschroedinger.c')
-rw-r--r-- | libavcodec/libschroedinger.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/libavcodec/libschroedinger.c b/libavcodec/libschroedinger.c index ec9bde4880..242d354be3 100644 --- a/libavcodec/libschroedinger.c +++ b/libavcodec/libschroedinger.c @@ -77,3 +77,56 @@ int ff_get_schro_frame_format (SchroChromaFormat schro_pix_fmt, } 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; +} |