# HG changeset patch # User lbarthelemy # Date 1195550097 0 # Node ID caaddda5477cd69b33a39eb1edfe8bf9dd7f2f6e # Parent 269562a2b89c8c5416bb4e09352515932ec5a501 - window size limited to a multiple of 4 - allow to have a bigger image than original, - add several cleans on pointers diff -r 269562a2b89c -r caaddda5477c sv/videoio/SDL_ffmpeg.cpp --- a/sv/videoio/SDL_ffmpeg.cpp Mon Nov 19 16:11:02 2007 +0000 +++ b/sv/videoio/SDL_ffmpeg.cpp Tue Nov 20 09:14:57 2007 +0000 @@ -478,6 +478,7 @@ // reserve some pointers for use in loop AVFrame *inFrame, *inFrameRGB; + uint8_t *inVideoBuffer = NULL; // allocate a frame inFrame = avcodec_alloc_frame(); @@ -487,7 +488,7 @@ if(SDL_ffmpegValidVideo(file)) { // allocate buffer - uint8_t *inVideoBuffer = (uint8_t*)malloc( avpicture_get_size(file->vs[file->videoStream]->pixFmt, + inVideoBuffer = (uint8_t*)malloc( avpicture_get_size(file->vs[file->videoStream]->pixFmt, file->vs[file->videoStream]->width, file->vs[file->videoStream]->height) ); @@ -611,10 +612,10 @@ // { int w=(int)(zoomFivan*320+0.5); int h=(int)(zoomFivan*240+0.5); - if ((w>file->vs[file->videoStream]->width)||(h>file->vs[file->videoStream]->height)){ - w=file->vs[file->videoStream]->width; - h=file->vs[file->videoStream]->height; - } + //if ((w>file->vs[file->videoStream]->width)||(h>file->vs[file->videoStream]->height)){ + // w=file->vs[file->videoStream]->width; + // h=file->vs[file->videoStream]->height; + //} // Be sure we have a multiple of 4 w &= 0xFFFFFFFC; h &= 0xFFFFFFFC; @@ -630,13 +631,36 @@ exit(1); } } - + + // check to see if buffer is at the same size than the screen + if (inFrameRGB->linesize[0]/3 != w ) { + av_free(inFrameRGB); + free(inVideoBuffer); + //avcodec_default_release_buffer(img_convert_ctx , inFrameRGB); + inFrameRGB = avcodec_alloc_frame(); + // allocate buffer + inVideoBuffer = (uint8_t*)malloc( avpicture_get_size(file->vs[file->videoStream]->pixFmt, + w, + h) ); + + // put buffer into our reserved frame + avpicture_fill( (AVPicture*)inFrameRGB, + inVideoBuffer, + file->vs[file->videoStream]->pixFmt, + w, + h); + + } + ((AVPicture*)inFrameRGB)->linesize[0]=(int)w*3; - sws_scale(img_convert_ctx, ((AVPicture*)inFrame)->data, ((AVPicture*)inFrame)->linesize, - 0, file->vs[file->videoStream]->height, ((AVPicture*)inFrameRGB)->data, ((AVPicture*)inFrameRGB)->linesize); - sws_freeContext(img_convert_ctx); - img_convert_ctx=NULL; - // we convert whatever type of data we got to RGB24 + sws_scale(img_convert_ctx, + ((AVPicture*)inFrame)->data, ((AVPicture*)inFrame)->linesize, 0, file->vs[file->videoStream]->height, + ((AVPicture*)inFrameRGB)->data, ((AVPicture*)inFrameRGB)->linesize); + + sws_freeContext(img_convert_ctx); + img_convert_ctx=NULL; + + // we convert whatever type of data we got to RGB24 /* img_convert((AVPicture*)inFrameRGB, file->vs[file->videoStream]->pixFmt, (AVPicture*)inFrame, @@ -644,12 +668,12 @@ file->vs[file->videoStream]->width, file->vs[file->videoStream]->height); */ + // allocate image room buf->img = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 24, 0x0000FF, 0x00FF00, 0xFF0000, 0); - // copy image data to image room memcpy(buf->img->pixels, inFrameRGB->data[0], w*h* 3); @@ -706,8 +730,18 @@ if ((file->skipAudio)&&(file->delay)) SDL_Delay(3); } + + if (inVideoBuffer) + { + free(inVideoBuffer); + inVideoBuffer = NULL; + } + // if we stop this thread, we can release the packet we reserved av_free_packet(&pack); + free(samples); + av_free(inFrameRGB); + av_free(inFrame); return 0; }