[Redbutton-devel] SF.net SVN: redbutton: [76] redbutton-browser/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2006-05-22 16:04:05
|
Revision: 76 Author: skilvington Date: 2006-05-22 09:03:57 -0700 (Mon, 22 May 2006) ViewCVS: http://svn.sourceforge.net/redbutton/?rev=76&view=rev Log Message: ----------- allow video output resizing to change mid-stream Modified Paths: -------------- redbutton-browser/trunk/MHEGStreamPlayer.c redbutton-browser/trunk/MHEGVideoOutput.c redbutton-browser/trunk/MHEGVideoOutput.h Modified: redbutton-browser/trunk/MHEGStreamPlayer.c =================================================================== --- redbutton-browser/trunk/MHEGStreamPlayer.c 2006-05-22 13:57:21 UTC (rev 75) +++ redbutton-browser/trunk/MHEGStreamPlayer.c 2006-05-22 16:03:57 UTC (rev 76) @@ -404,6 +404,7 @@ out_height = vf->height; /* TODO */ /* use scaled values if ScaleVideo has been called */ +/* have a lock incase we are doing ScaleVideo in another thread */ /* scale up if fullscreen */ if(d->fullscreen) { @@ -432,7 +433,7 @@ /* remember the time stamp for this frame */ last_pts = vf->pts; //now=av_gettime(); -//printf("display frame %d: pts=%f this_time=%lld real_time=%lld (diff=%lld)\n", ++nframes, vf->pts, last_time, now, now-last_time); +//printf("display frame %d: pts=%f this_time=%lld real_time=%lld (diff=%lld)\n", nframes, vf->pts, last_time, now, now-last_time); /* origin of VideoClass */ /* TODO should probably have a lock for this in case we are doing SetPosition in another thread */ out_x = p->video->inst.Position.x_position; Modified: redbutton-browser/trunk/MHEGVideoOutput.c =================================================================== --- redbutton-browser/trunk/MHEGVideoOutput.c 2006-05-22 13:57:21 UTC (rev 75) +++ redbutton-browser/trunk/MHEGVideoOutput.c 2006-05-22 16:03:57 UTC (rev 76) @@ -2,7 +2,6 @@ * MHEGVideoOutput.h */ -#include <pthread.h> #include <sys/ipc.h> #include <sys/shm.h> #include <X11/Xlib.h> @@ -37,12 +36,20 @@ return x11_shm_fini(v); } +/* + * get ready to draw the given frame at the given output size + */ + void MHEGVideoOutput_prepareFrame(MHEGVideoOutput *v, VideoFrame *f, unsigned int out_width, unsigned int out_height) { return x11_shm_prepareFrame(v, f, out_width, out_height); } +/* + * draw the frame set up by MHEGVideoOutput_prepareFrame() at the given position on the contents Pixmap + */ + void MHEGVideoOutput_drawFrame(MHEGVideoOutput *v, int x, int y) { @@ -55,9 +62,8 @@ v->current_frame = NULL; v->resize_ctx = NULL; + v->resized_data = NULL; - v->tmpbuf_data = NULL; - return; } @@ -67,7 +73,7 @@ if(v->resize_ctx != NULL) { img_resample_close(v->resize_ctx); - safe_free(v->tmpbuf_data); + safe_free(v->resized_data); } if(v->current_frame != NULL) @@ -80,9 +86,9 @@ x11_shm_prepareFrame(MHEGVideoOutput *v, VideoFrame *f, unsigned int out_width, unsigned int out_height) { AVPicture *yuv_frame; - int tmpbuf_size; + int resized_size; - /* have we create the output frame yet */ + /* have we created the output frame yet */ if(v->current_frame == NULL) x11_shm_create_frame(v, out_width, out_height); @@ -93,17 +99,28 @@ /* see if the input size is different than the output size */ if(f->width != out_width || f->height != out_height) { -/* TODO */ -/* need to change resize_ctx if the input or output sizes have changed since last time */ -/* dont forget: img_resample_close(resize_ctx); */ -/* and to free or realloc tmpbuf_data */ - if(v->resize_ctx == NULL) + /* have the resize input or output dimensions changed */ + if(v->resize_ctx == NULL + || v->resize_in.width != f->width || v->resize_in.height != f->height + || v->resize_out.width != out_width || v->resize_out.height != out_height) { - v->resize_ctx = img_resample_init(out_width, out_height, f->width, f->height); - tmpbuf_size = avpicture_get_size(f->pix_fmt, out_width, out_height); - v->tmpbuf_data = safe_malloc(tmpbuf_size); - avpicture_fill(&v->resized_frame, v->tmpbuf_data, f->pix_fmt, out_width, out_height); + /* get rid of any existing resize context */ + if(v->resize_ctx != NULL) + img_resample_close(v->resize_ctx); + if((v->resize_ctx = img_resample_init(out_width, out_height, f->width, f->height)) == NULL) + fatal("Out of memory"); + /* remember the resize input and output dimensions */ + v->resize_in.width = f->width; + v->resize_in.height = f->height; + v->resize_out.width = out_width; + v->resize_out.height = out_height; + /* somewhere to store the resized frame */ + if((resized_size = avpicture_get_size(f->pix_fmt, out_width, out_height)) < 0) + fatal("x11_shm_prepareFrame: invalid frame size"); + v->resized_data = safe_realloc(v->resized_data, resized_size); + avpicture_fill(&v->resized_frame, v->resized_data, f->pix_fmt, out_width, out_height); } + /* resize it */ img_resample(v->resize_ctx, &v->resized_frame, &f->frame); yuv_frame = &v->resized_frame; } @@ -200,6 +217,7 @@ /* make sure no-one tries to use it */ v->current_frame = NULL; + /* get rid of the shared memory */ XShmDetach(d->dpy, &v->shm); shmdt(v->shm.shmaddr); shmctl(v->shm.shmid, IPC_RMID, NULL); Modified: redbutton-browser/trunk/MHEGVideoOutput.h =================================================================== --- redbutton-browser/trunk/MHEGVideoOutput.h 2006-05-22 13:57:21 UTC (rev 75) +++ redbutton-browser/trunk/MHEGVideoOutput.h 2006-05-22 16:03:57 UTC (rev 76) @@ -7,13 +7,21 @@ typedef struct { - XShmSegmentInfo shm; - AVPicture rgb_frame; - enum PixelFormat out_format; - ImgReSampleContext *resize_ctx; - AVPicture resized_frame; - uint8_t *tmpbuf_data; + unsigned int width; + unsigned int height; +} FrameSize; + +typedef struct +{ XImage *current_frame; /* frame we are currently displaying */ + XShmSegmentInfo shm; /* shared memory used by current_frame */ + AVPicture rgb_frame; /* ffmpeg wrapper for current_frame SHM data */ + enum PixelFormat out_format; /* rgb_frame ffmpeg pixel format */ + ImgReSampleContext *resize_ctx; /* NULL if we do not need to resize the frame */ + FrameSize resize_in; /* resize_ctx input dimensions */ + FrameSize resize_out; /* resize_ctx output dimensions */ + AVPicture resized_frame; /* resized output frame */ + uint8_t *resized_data; /* resized_frame data buffer */ } MHEGVideoOutput; void MHEGVideoOutput_init(MHEGVideoOutput *); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |