[asterisk-commits] rizzo: branch rizzo/video_v2 r85233 - /team/rizzo/video_v2/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Oct 10 06:37:38 CDT 2007
Author: rizzo
Date: Wed Oct 10 06:37:38 2007
New Revision: 85233
URL: http://svn.digium.com/view/asterisk?view=rev&rev=85233
Log:
various cleanup of the handling of video formats and keeping
status across sessions.
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=85233&r1=85232&r2=85233
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Wed Oct 10 06:37:38 2007
@@ -190,8 +190,6 @@
*/
/* all the following is config file info copied from the parent */
char videodevice[64];
- int w; /* geometry and other info, */
- int h;
int fps;
int bitrate;
@@ -227,7 +225,6 @@
AVCodec *codec; /* reference to the codec */
AVFrame *frame; /* place to store the frame */
AVCodecParserContext *parser;
- int completed; /* probably unnecessary */
uint16_t next_seq; /* must be 16 bit */
int discard; /* flag for discard status */
struct fbuf_t dec_in; /* incoming bitstream */
@@ -273,10 +270,6 @@
* received data descriptors, SDL info, etc.
*/
struct video_desc {
- int w; /* geometry */
- int h;
- int fps; /* framerate */
- int bitrate;
char codec_name[64];
pthread_t vthread; /* video thread */
@@ -562,7 +555,8 @@
int datalen;
int ret = av_parser_parse(v->parser, v->dec_ctx, &data, &datalen, src, srclen, 0, 0);
if (datalen) {
- ret = avcodec_decode_video(v->dec_ctx, v->frame, &(v->completed), data, datalen);
+ int dummy = 0;
+ ret = avcodec_decode_video(v->dec_ctx, v->frame, &dummy, data, datalen);
if (ret < 0) {
ast_log(LOG_NOTICE, "Error decoding\n");
return 0;
@@ -1091,16 +1085,24 @@
/*! \brief uninitialize the descriptor for remote video stream */
static int video_in_uninit(struct video_in_desc *v)
{
+ if (v->parser) {
+ av_parser_close(v->parser);
+ v->parser = NULL;
+ }
if (v->dec_ctx) {
avcodec_close(v->dec_ctx);
av_free(v->dec_ctx);
- }
- if (v->frame)
+ v->dec_ctx = NULL;
+ }
+ if (v->frame) {
av_free(v->frame);
+ v->frame = NULL;
+ }
+ v->codec = NULL; /* only a reference */
+ v->discard = 1; /* start in discard mode */
free_fbuf(&v->dec_in);
free_fbuf(&v->dec_out);
free_fbuf(&v->rem_dpy);
- bzero(v, sizeof(*v)); /* XXX too much, we are losing config info */
return -1; /* error, in case someone cares */
}
@@ -1111,11 +1113,11 @@
{
enum CodecID codec;
+ /* XXX should check that these are already set */
v->codec = NULL;
v->dec_ctx = NULL;
v->frame = NULL;
v->parser = NULL;
- v->completed = 0;
v->discard = 1;
codec = map_video_format(format, CM_RD);
@@ -1156,10 +1158,14 @@
if (v->enc_ctx) {
avcodec_close(v->enc_ctx);
av_free(v->enc_ctx);
- }
-
- if (v->frame)
+ v->enc_ctx = NULL;
+ }
+ if (v->frame) {
av_free(v->frame);
+ v->frame = NULL;
+ }
+ v->codec = NULL; /* only a reference */
+
free_fbuf(&v->loc_src);
free_fbuf(&v->enc_in);
free_fbuf(&v->enc_out);
@@ -1169,10 +1175,10 @@
v->dpy = NULL;
v->image = NULL;
}
- if (v->fd >= 0)
+ if (v->fd >= 0) {
close(v->fd);
- bzero(v, sizeof(*v));
- v->fd = -1;
+ v->fd = -1;
+ }
return -1;
}
@@ -1181,6 +1187,7 @@
* - AVCodecContext, AVCodec, AVFrame are used by ffmpeg for encoding;
* - encbuf is used to store the encoded frame (to be sent)
* - mtu is used to determine the max size of video fragment
+ * NOTE: we enter here with the video source already open.
*/
static int video_out_init(struct video_desc *env)
{
@@ -1248,7 +1255,6 @@
env->current_codec->enc_init(v);
- ast_log(LOG_WARNING, "w: %d h: %d fps: %d\n", v->w, v->h, v->fps);
v->enc_ctx->time_base = (AVRational){1, v->fps};
if (avcodec_open(v->enc_ctx, v->codec) < 0) {
ast_log(LOG_WARNING, "Unable to initialize the encoder %d\n",
@@ -1285,6 +1291,8 @@
/* wait for video thread to finish */
pthread_join(env->vthread, NULL);
ast_channel_lock(env->owner);
+ env->shutdown = 0;
+ env->vthread = NULL;
/* uninitialize the local and remote video environments */
video_in_uninit(&env->in);
@@ -1292,24 +1300,18 @@
/* uninitialize the SDL environment */
if (env->sdl_ok) {
- if (env->bmp[0])
- SDL_FreeYUVOverlay(env->bmp[0]);
- if (env->bmp[1])
- SDL_FreeYUVOverlay(env->bmp[1]);
- SDL_Quit();
- ast_mutex_destroy(&(env->sdl_lock));
- }
- { /* clear the struct but restore some fields */
- struct video_desc x = *env; /* make a copy */
- bzero(env, sizeof(struct video_desc));
- /* restore fields... */
- bcopy(x.out.videodevice, env->out.videodevice, sizeof(env->out.videodevice));
- bcopy(x.codec_name, env->codec_name, sizeof(env->codec_name));
- env->w = x.w;
- env->h = x.h;
- env->fps = x.fps;
- env->bitrate = x.bitrate;
- }
+ if (env->bmp[0])
+ SDL_FreeYUVOverlay(env->bmp[0]);
+ if (env->bmp[1])
+ SDL_FreeYUVOverlay(env->bmp[1]);
+ SDL_Quit();
+ env->bmp[0] = env->bmp[1] = NULL;
+ env->screen = NULL; /* XXX check reference */
+ bzero(env->rect, sizeof(env->rect));
+ ast_mutex_destroy(&(env->sdl_lock));
+
+ }
+ env->owner = NULL;
}
@@ -1547,7 +1549,6 @@
if (f->subclass & 0x01) { // RTP Marker
if (env->current_codec->dec_run(v, &v->dec_in)) {
show_frame(env, 0);
- v->completed = 0;
v->dec_in.used = 0;
}
}
@@ -1649,30 +1650,32 @@
return NULL;
}
+static void copy_geometry(struct fbuf_t *src, struct fbuf_t *dst)
+{
+ if (dst->w == 0)
+ dst->w = src->w;
+ if (dst->h == 0)
+ dst->h = src->h;
+}
+
/*! initialize the video environment.
- * From the config file we get some basic parameters, we must
- * propagate them to all the descriptor for the various video
- * representations that we handle.
+ * Apart from the formats (constant) used by sdl and the codec,
+ * we use enc_in as the basic geometry.
*/
static void init_env(struct video_desc *env)
{
- struct fbuf_t *c, *ei, *ld, *rd;
-
- /* Local video chain */
- c = &(env->out.loc_src);
- ei = &(env->out.enc_in);
- ld = &(env->out.loc_dpy);
- rd = &(env->in.rem_dpy);
+ struct fbuf_t *c = &(env->out.loc_src); /* local source */
+ struct fbuf_t *ei = &(env->out.enc_in); /* encoder input */
+ struct fbuf_t *ld = &(env->out.loc_dpy); /* local display */
+ struct fbuf_t *rd = &(env->in.rem_dpy); /* remote display */
+
c->pix_fmt = PIX_FMT_YUV420P; /* default - camera format */
ei->pix_fmt = PIX_FMT_YUV420P; /* encoder input */
ld->pix_fmt = rd->pix_fmt = PIX_FMT_YUV420P; /* sdl format */
- /* all size default to the same value */
- if (c->w == 0)
- c->w = env->w;
- if (c->h == 0)
- c->h = env->h;
- ei->w = ld->w = rd->w = env->w;
- ei->h = ld->h = rd->h = env->h;
+ /* inherit defaults */
+ copy_geometry(ei, c); /* camera inherits from encoder input */
+ copy_geometry(ei, rd); /* remote display inherits from encoder input */
+ copy_geometry(rd, ld); /* local display inherits from remote display */
}
/*!
@@ -1687,6 +1690,7 @@
{
int dpy_fmt = SDL_IYUV_OVERLAY; /* YV12 causes flicker in SDL */
struct fbuf_t *b;
+ int h;
if (env == NULL) /* video not initialized */
return;
@@ -1725,7 +1729,9 @@
/* again not fatal, just we won't display anything */
goto no_sdl;
}
- env->screen = SDL_SetVideoMode(2 * env->w, env->h, 0, 0);
+ h = MAX(env->in.rem_dpy.h, env->out.loc_dpy.h);
+ env->screen = SDL_SetVideoMode(env->in.rem_dpy.w + env->out.loc_dpy.w,
+ h, 0, 0);
if (!env->screen) {
ast_log(LOG_ERROR, "SDL: could not set video mode - exiting\n");
goto no_sdl;
@@ -1734,7 +1740,7 @@
b = &env->in.rem_dpy;
env->bmp[0] = SDL_CreateYUVOverlay(b->w, b->h, dpy_fmt, env->screen);
b = &env->out.loc_dpy;
- env->bmp[1] = SDL_CreateYUVOverlay(env->w, env->h, dpy_fmt, env->screen);
+ env->bmp[1] = SDL_CreateYUVOverlay(b->w, b->h, dpy_fmt, env->screen);
if (env->bmp[0] == NULL || env->bmp[1] == NULL) {
/* otherwise should release the screen */
goto no_sdl;
@@ -1756,16 +1762,14 @@
* now handle the local video source
*/
/* copy video source config from parent */
- if (env->fps == 0) {
- env->fps = 15;
- ast_log(LOG_WARNING, "fps unset, forcing to %d\n", env->fps);
- }
- env->out.fps = env->fps;
- if (env->bitrate == 0) {
- env->bitrate = 65000;
- ast_log(LOG_WARNING, "bitrate unset, forcing to %d\n", env->bitrate);
- }
- env->out.bitrate = env->bitrate;
+ if (env->out.fps == 0) {
+ env->out.fps = 15;
+ ast_log(LOG_WARNING, "fps unset, forcing to %d\n", env->out.fps);
+ }
+ if (env->out.bitrate == 0) {
+ env->out.bitrate = 65000;
+ ast_log(LOG_WARNING, "bitrate unset, forcing to %d\n", env->out.bitrate);
+ }
if (video_open(&env->out)) {
ast_log(LOG_WARNING, "cannot open local video source\n");
@@ -1805,14 +1809,17 @@
if (!strcasecmp(var, "videodevice")) {
ast_cli(fd, "videodevice is [%s]\n", env->out.videodevice);
- } else if (!strcasecmp(var, "videowidth")) {
- ast_cli(fd, "videowidth is [%d]\n", env->w);
- } else if (!strcasecmp(var, "videoheight")) {
- ast_cli(fd, "videoheight is [%d]\n", env->h);
+ } else if (!strcasecmp(var, "video_size")) {
+ ast_cli(fd, "sizes: video %dx%d camera %dx%d local %dx%d remote %dx%d in %dx%d\n",
+ env->out.enc_in.w, env->out.enc_in.h,
+ env->out.loc_src.w, env->out.loc_src.h,
+ env->out.loc_dpy.w, env->out.loc_src.h,
+ env->in.rem_dpy.w, env->in.rem_dpy.h,
+ env->in.dec_out.w, env->in.dec_out.h);
} else if (!strcasecmp(var, "bitrate")) {
- ast_cli(fd, "bitrate is [%d]\n", env->bitrate);
+ ast_cli(fd, "bitrate is [%d]\n", env->out.bitrate);
} else if (!strcasecmp(var, "fps")) {
- ast_cli(fd, "fps is [%d]\n", env->fps);
+ ast_cli(fd, "fps is [%d]\n", env->out.fps);
} else {
return 0; /* unrecognised */
}
@@ -1838,15 +1845,20 @@
return 1; /* error */
}
+ /* set default values */
+ ast_copy_string(env->out.videodevice, "X11", sizeof(env->out.videodevice));
+ env->out.fps = 5;
+ env->out.bitrate = 65000;
env->out.sendvideo = 1;
}
M_STR("videodevice", env->out.videodevice)
M_BOOL("sendvideo", env->out.sendvideo)
- M_UINT("videowidth", env->w)
- M_F("camera_format", video_geom(&env->out.loc_src, val))
- M_UINT("videoheight", env->h)
- M_UINT("fps", env->fps)
- M_UINT("bitrate", env->bitrate)
+ M_F("video_size", video_geom(&env->out.enc_in, val))
+ M_F("camera_size", video_geom(&env->out.loc_src, val))
+ M_F("local_size", video_geom(&env->out.loc_dpy, val))
+ M_F("remote_size", video_geom(&env->in.rem_dpy, val))
+ M_UINT("fps", env->out.fps)
+ M_UINT("bitrate", env->out.bitrate)
M_STR("videoformat", env->codec_name)
M_END(return 1;) /* the 'nothing found' case */
return 0; /* found something */
More information about the asterisk-commits
mailing list