[svn-commits] rizzo: branch rizzo/astobj2 r77809 - /team/rizzo/astobj2/channels/chan_oss.c
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Mon Jul 30 20:40:05 CDT 2007
Author: rizzo
Date: Mon Jul 30 20:40:05 2007
New Revision: 77809
URL: http://svn.digium.com/view/asterisk?view=rev&rev=77809
Log:
use two overlays for incoming and outgoing video
Modified:
team/rizzo/astobj2/channels/chan_oss.c
Modified: team/rizzo/astobj2/channels/chan_oss.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_oss.c?view=diff&rev=77809&r1=77808&r2=77809
==============================================================================
--- team/rizzo/astobj2/channels/chan_oss.c (original)
+++ team/rizzo/astobj2/channels/chan_oss.c Mon Jul 30 20:40:05 2007
@@ -373,7 +373,7 @@
SDL_Surface *screen;
int initialized;
- SDL_Overlay *bmp;
+ SDL_Overlay *bmp[2];
struct ast_frame *echo;
@@ -479,7 +479,7 @@
for (;;) {
int r, l = v->buf.size - v->buf.used;
r = read(v->fd, v->buf.data + v->buf.used, l);
- ast_log(LOG_WARNING, "read %d of %d bytes from webcam\n", r, l);
+ // ast_log(LOG_WARNING, "read %d of %d bytes from webcam\n", r, l);
if (r < 0) { /* read error */
return 0;
}
@@ -494,13 +494,13 @@
}
#endif /* HAVE_V4L */
-static void show_frame(struct video_desc *env);
-
-static void webcam_encode(struct video_out_desc *v)
-{
- struct timeval now = ast_tvnow();
- ast_log(LOG_WARNING, "video frame ready at %d.%06d\n",
- (int)now.tv_sec % 1000, (int)now.tv_usec);
+static void show_frame(struct video_desc *env, int out);
+
+static void webcam_encode(struct video_desc *env)
+{
+ // struct timeval now = ast_tvnow();
+ // ast_log(LOG_WARNING, "video frame ready at %d.%06d\n", (int)now.tv_sec % 1000, (int)now.tv_usec);
+ show_frame(env, 1);
}
/* Helper function to process incoming video.
@@ -603,7 +603,7 @@
{
env->screen = NULL;
env->initialized = 0;
- env->bmp = NULL;
+ env->bmp[0] = env->bmp[1] = NULL;
avcodec_init();
/*
* Register all codecs supported by the ffmpeg library.
@@ -640,8 +640,10 @@
}
ast_log(LOG_WARNING, "ffmpeg_uninit drop %d frames\n", i);
video_in_uninit(&env->in);
- if (env->bmp)
- SDL_FreeYUVOverlay(env->bmp);
+ if (env->bmp[0])
+ SDL_FreeYUVOverlay(env->bmp[0]);
+ if (env->bmp[1])
+ SDL_FreeYUVOverlay(env->bmp[1]);
SDL_Quit();
if (env->out.buf.data) {
@@ -767,17 +769,21 @@
* - Create a YUV Overlay to copy into it the decoded frame
* - After the decoded frame is copied into the overlay, we display it
* TODO: change the call img_convert(): it is deprecated.
- */
-static void show_frame(struct video_desc *env)
+ * 'out' is set to display the outgoing stream
+ */
+static void show_frame(struct video_desc *env, int out)
{
AVPicture pict;
SDL_Rect rect;
AVCodecContext *c = env->in.context; /* shorthand */
+ int w = env->out.w ? env->out.w : c->width; /* pick geometry between webcam and default */
+ int h = env->out.h ? env->out.h : c->height; /* pick geometry between webcam and default */
+ SDL_Overlay *bmp;
if (!env->initialized)
return;
if(env->screen == NULL) {
- env->screen = SDL_SetVideoMode(c->width, c->height, 0, 0);
+ env->screen = SDL_SetVideoMode(2*w, h, 0, 0);
if(!env->screen) {
ast_log(LOG_ERROR, "SDL: could not set video mode - exiting\n");
return;
@@ -785,29 +791,34 @@
SDL_WM_SetCaption("Asterisk console Video Output", NULL);
}
- if(!env->bmp)
- env->bmp = SDL_CreateYUVOverlay(c->width, c->height,
- SDL_YV12_OVERLAY, env->screen);
-
- SDL_LockYUVOverlay(env->bmp);
- pict.data[0] = env->bmp->pixels[0];
- pict.data[1] = env->bmp->pixels[2];
- pict.data[2] = env->bmp->pixels[1];
- pict.linesize[0] = env->bmp->pitches[0];
- pict.linesize[1] = env->bmp->pitches[2];
- pict.linesize[2] = env->bmp->pitches[1];
-
+ if(!env->bmp[0])
+ env->bmp[0] = SDL_CreateYUVOverlay(w, h, SDL_YV12_OVERLAY, env->screen);
+ if(!env->bmp[1])
+ env->bmp[1] = SDL_CreateYUVOverlay(w, h, SDL_YV12_OVERLAY, env->screen);
+
+ bmp = env->bmp[out];
+ SDL_LockYUVOverlay(bmp);
+ pict.data[0] = bmp->pixels[0];
+ pict.data[1] = bmp->pixels[2];
+ pict.data[2] = bmp->pixels[1];
+ pict.linesize[0] = bmp->pitches[0];
+ 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 */
+ bcopy(env->out.buf.data, bmp->pixels[0], 4*l4);
+ bcopy(env->out.buf.data + 4*l4, bmp->pixels[1], l4);
+ bcopy(env->out.buf.data + 5*l4, bmp->pixels[2], l4);
+ } else { /* decode */
#if 0 /* XXX img_convert is deprecated */
- img_convert(&pict, PIX_FMT_YUV420P,
- (AVPicture *)env->frame, c->pix_fmt,
- c->width, c->height);
+ img_convert(&pict, PIX_FMT_YUV420P, (AVPicture *)env->frame, c->pix_fmt, c->width, c->height);
#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 */,
- c->width, c->height, PIX_FMT_YUV420P /* output format ? */,
+ w, h, PIX_FMT_YUV420P /* output format ? */,
SWS_BICUBIC, NULL, NULL, NULL);
if (convert_ctx == NULL) {
ast_log(LOG_ERROR, "FFMPEG::convert_cmodel : swscale context initialization failed");
@@ -816,26 +827,19 @@
sws_scale(convert_ctx,
pict_in->data, pict_in->linesize,
- c->width, c->height,
+ w, h, /* src slice */
pict.data, pict.linesize);
sws_freeContext(convert_ctx);
- }
#endif /* XXX replacement */
-
- SDL_UnlockYUVOverlay(env->bmp);
-#if 0 /* more testing, overlay the received image with the local picture */
- ast_log(LOG_WARNING, "show_frame: linesize %d %d %d\n", pict.linesize[0], pict.linesize[1], pict.linesize[2]);
- if (env->webcam_imgbuf) {
- bcopy(env->webcam_imgbuf, pict.data[0], c->width*c->height);
- }
-#endif
- rect.x = 0;
+ }
+ SDL_UnlockYUVOverlay(bmp);
+ rect.x = w*out;
rect.y = 0;
- rect.w = c->width;
- rect.h = c->height;
- SDL_DisplayYUVOverlay(env->bmp, &rect);
+ rect.w = w;
+ rect.h = h;
+ SDL_DisplayYUVOverlay(bmp, &rect);
}
/*
@@ -931,7 +935,7 @@
env->in.buf.data[env->in.buf.used] = '\0';
if(f->subclass & 0x01) // RTP Marker
if(decode_video(&env->in)) {
- show_frame(env);
+ show_frame(env, 0);
env->in.completed = 0;
env->in.buf.used = 0;
}
@@ -1612,7 +1616,7 @@
struct video_desc *env = get_video_desc(c);
if (webcam_read(&env->out))
- webcam_encode(&env->out); /* get frames and put them in the queue */
+ webcam_encode(env); /* get frames and put them in the queue */
if (env->echo) {
struct ast_frame *f1;
int i = 0;
More information about the svn-commits
mailing list