[asterisk-commits] rizzo: branch rizzo/video_v2 r82494 - /team/rizzo/video_v2/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Sep 16 05:58:59 CDT 2007
Author: rizzo
Date: Sun Sep 16 05:58:59 2007
New Revision: 82494
URL: http://svn.digium.com/view/asterisk?view=rev&rev=82494
Log:
cleanup a bit the video conversion routines so we can try to
use them also for the webcam/x11 formats.
Modified:
team/rizzo/video_v2/channels/console_video.c
Modified: team/rizzo/video_v2/channels/console_video.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/video_v2/channels/console_video.c?view=diff&rev=82494&r1=82493&r2=82494
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Sun Sep 16 05:58:59 2007
@@ -102,8 +102,10 @@
int w; /* geometry */
int h;
int fd; /* file descriptor */
+ int pix_fmt; /* source pixel format */
+
struct dbuf_t buf;
- AVCodecContext *context;
+ AVCodecContext *context; /* encoding context */
AVCodec *codec;
AVFrame *frame;
int lasttxframe; /* XXX - useless: RTP overwrite seqno */
@@ -231,6 +233,7 @@
im->data,
im->bits_per_pixel,
im->red_mask, im->green_mask, im->blue_mask);
+ v->pix_fmt = PIX_FMT_RGB565
v->fd = -2;
} else {
v->fd = open(device, O_RDONLY | O_NONBLOCK);
@@ -495,8 +498,9 @@
return video_out_uninit(v);
}
+ v->pix_fmt = PIX_FMT_YUV420P; /* default - camera format */
v->context = avcodec_alloc_context();
- v->context->pix_fmt = PIX_FMT_YUV420P;
+ v->context->pix_fmt = v->pix_fmt;
v->context->width = v->w;
v->context->height = v->h;
v->context->rtp_mode = 1;
@@ -694,6 +698,9 @@
* - Set the video mode to use the resolution specified by the codec context
* - Create a YUV Overlay to copy into it the decoded frame
* - After the decoded frame is copied into the overlay, we display it
+ *
+ * The size is taken from the configuration.
+ *
* TODO: change the call img_convert(): it is deprecated.
* 'out' is set to display the outgoing stream
*/
@@ -701,22 +708,33 @@
{
AVPicture pict;
SDL_Rect rect;
- int w, h;
+ int w = env->w, h = env->h;
+ int in_w, in_h;
AVCodecContext *c; /* shorthand */
SDL_Overlay *bmp;
+ AVPicture *pict_in = NULL; /* conversion source */
+ char *src = NULL; /* pixel input */
+ int pix_fmt;
+
int fmt = SDL_YV12_OVERLAY;
fmt = SDL_IYUV_OVERLAY;
if (!env->initialized)
return;
- if (out) {
+ if (out) { /* webcam/x11 to sdl */
+ src = env->out.buf.data;
c = env->out.context;
+ pix_fmt = env->out.pix_fmt;
+ in_w = env->w;
+ in_h = env->h;
} else {
+ pict_in = (AVPicture *)env->in.frame;
c = env->in.context;
- }
- w = env->out.w ? env->out.w : c->width; /* pick geometry between webcam and default */
- h = env->out.h ? env->out.h : c->height; /* pick geometry between webcam and default */
+ pix_fmt = c->pix_fmt;
+ in_w = c->width;
+ in_h = c->height;
+ }
#if 0
fprintf(stderr, "thd %p env->out %dx%d in.ctx %dx%d default %dx%d\n",
pthread_self(),
@@ -724,6 +742,7 @@
#endif
ast_mutex_lock(&env->lock);
+ /* first time we run, we also initialize sdl and the two bitmaps we use */
if(env->screen == NULL) {
env->screen = SDL_SetVideoMode(2*w, h, 0, 0);
if(!env->screen) {
@@ -748,25 +767,24 @@
pict.linesize[1] = bmp->pitches[2];
pict.linesize[2] = bmp->pitches[1];
- if (out) { /* raw stream from camera */
- int l4 = w*h/4; /* U or v frame */
- if (!env->out.buf.data) {
+ if (pict_in == NULL) { /* raw stream in YUV format, usually from camera */
+ int l4 = w*h/4; /* size of U or V frame */
+ if (!src) {
ast_log(LOG_WARNING, "no buffer for show frame\n");
} else {
- bcopy(env->out.buf.data, bmp->pixels[0], 4*l4);
- bcopy(env->out.buf.data + 4*l4, bmp->pixels[2], l4);
- bcopy(env->out.buf.data + 5*l4, bmp->pixels[1], l4);
+ bcopy(src, bmp->pixels[0], 4*l4);
+ bcopy(src + 4*l4, bmp->pixels[2], l4);
+ bcopy(src + 5*l4, bmp->pixels[1], l4);
}
} else { /* decode */
#ifdef OLD_FFMPEG /* XXX img_convert is deprecated */
/* env->initialized guarantees that in.frame exists */
- img_convert(&pict, PIX_FMT_YUV420P, (AVPicture *)env->in.frame, c->pix_fmt, c->width, c->height);
+ img_convert(&pict, PIX_FMT_YUV420P, pict_in, pix_fmt, w, h);
#else /* XXX replacement */
struct SwsContext *convert_ctx;
- AVPicture *pict_in = (AVPicture *)env->in.frame;
-
- convert_ctx = sws_getContext(c->width, c->height, c->pix_fmt /* input format */,
- w, h, PIX_FMT_YUV420P /* output format ? */,
+
+ convert_ctx = sws_getContext(in_w, in_h, pix_fmt /* input format */,
+ w, h, PIX_FMT_YUV420P /* output format for sdl */,
SWS_BICUBIC, NULL, NULL, NULL);
if (convert_ctx == NULL) {
ast_log(LOG_ERROR, "FFMPEG::convert_cmodel : swscale context initialization failed");
@@ -775,7 +793,7 @@
sws_scale(convert_ctx,
pict_in->data, pict_in->linesize,
- w, h, /* src slice */
+ in_w, in_h, /* src slice */
pict.data, pict.linesize);
sws_freeContext(convert_ctx);
More information about the asterisk-commits
mailing list