Mercurial > hg > easaier-soundaccess
changeset 170:caaddda5477c
- window size limited to a multiple of 4
- allow to have a bigger image than original,
- add several cleans on pointers
author | lbarthelemy |
---|---|
date | Tue, 20 Nov 2007 09:14:57 +0000 |
parents | 269562a2b89c |
children | ce31c4b3f5c6 |
files | sv/videoio/SDL_ffmpeg.cpp |
diffstat | 1 files changed, 46 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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; }