[asterisk-commits] rizzo: branch rizzo/astobj2 r77264 - /team/rizzo/astobj2/channels/chan_oss.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jul 26 03:19:30 CDT 2007


Author: rizzo
Date: Thu Jul 26 03:19:29 2007
New Revision: 77264

URL: http://svn.digium.com/view/asterisk?view=rev&rev=77264
Log:
+ fix console hangup
+ introduce a translation map for asterisk-ffmpeg codec formats


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=77264&r1=77263&r2=77264
==============================================================================
--- team/rizzo/astobj2/channels/chan_oss.c (original)
+++ team/rizzo/astobj2/channels/chan_oss.c Thu Jul 26 03:19:29 2007
@@ -348,6 +348,16 @@
 	int                     discard;
 };
 
+struct _cm {	/* map ffmpeg codec types to asterisk formats */
+	uint32_t	ast_format;	/* 0 is a terminator */
+	enum CodecID	codec;
+};
+
+static struct _cm video_formats[] = {
+	{ AST_FORMAT_H263_PLUS,	CODEC_ID_H263 },
+	{ 0,			0 },
+};
+
 /* Helper function to process incoming video.
  * For each incoming video call invoke ffmpeg_init() to intialize
  * the decoding structure then incoming video frames are processed
@@ -358,10 +368,6 @@
  * to display the frame.
  *
  */
-/* Initialize the decoding structure */
-static void ffmpeg_init(struct video_desc *);
-/* Uninitialize the decoding structure */
-static void ffmpeg_uninit(struct video_desc *);
 /* Extract the bitstream from the RTP payload */
 static uint8_t *pre_process_data(uint8_t *, int *);
 /* Decode video frame once completed */
@@ -373,8 +379,18 @@
 
 /* Macros used as a wrapper around the actual video format we want to use */
 #define AST_FORMAT_CUSTOM (AST_FORMAT_H263_PLUS)
-#define CODEC_ID_CUSTOM CODEC_ID_H263
 static int write_video(struct ast_channel *chan, struct ast_frame *f);
+
+/*! \brief map an asterisk format into an ffmpeg one */
+static enum CodecID map_video_format(uint32_t ast_format)
+{
+	struct _cm *i;
+
+	for (i = video_formats; i->ast_format != 0; i++)
+		if (ast_format & i->ast_format)
+			return i->codec;
+	return CODEC_ID_NONE;
+}
 
 /*
  * It initializes the video_desc struct which contains all the structures
@@ -387,8 +403,10 @@
  * - Allocation of a new frame
  * - Initializzation of the SDL environment to support the video
  */
-static void ffmpeg_init(struct video_desc *env)
-{
+static void ffmpeg_init(struct video_desc *env, uint32_t format)
+{
+	enum CodecID codec;
+
 	env->codec              = NULL;
 	env->context            = NULL;
 	env->frame              = NULL;
@@ -401,6 +419,8 @@
 	env->bmp                = NULL;
 	env->lastrxframe        = -1;
 
+	codec = map_video_format(format);
+	ast_log(LOG_WARNING, "init for format 0x%x gives %d\n", format, codec);
 	avcodec_init();
 	/*
 	 * Register all codecs supported by the ffmpeg library.
@@ -411,9 +431,9 @@
 	 * Searching for the H.263+ decoder; in the decoding process
 	 * the H.263 decoder in compatible with H.263+ stream.
 	 */
-	env->codec = avcodec_find_decoder(CODEC_ID_H263);
+	env->codec = avcodec_find_decoder(codec);
 	if(!env->codec) {
-		ast_log(LOG_WARNING, "Unable to find the H.263 decoder\n");;
+		ast_log(LOG_WARNING, "Unable to find the decoder for format %d\n", codec);
 		return;
 	}
 
@@ -426,7 +446,7 @@
 		return;
 	}
 
-	env->parser = av_parser_init(CODEC_ID_H263);
+	env->parser = av_parser_init(codec);
 	if(!env->parser) {
 		ast_log(LOG_WARNING, "Unable to initialize the H.263 codec parser\n");
 		return;
@@ -453,10 +473,6 @@
  */
 static void ffmpeg_uninit(struct video_desc *env)
 {
-	if (!env) {
-		ast_log(LOG_WARNING, "ffmpeg_uninit on null\n");
-		return;
-	}
 	if(env->context) {
 		avcodec_close(env->context);
 		av_free(env->context);
@@ -596,7 +612,6 @@
 		env->bmp = SDL_CreateYUVOverlay(env->context->width, env->context->height,
 			SDL_YV12_OVERLAY, env->screen);
 
-ast_log(LOG_WARNING, "locked sdl\n");
 	SDL_LockYUVOverlay(env->bmp);
 	pict.data[0] = env->bmp->pixels[0];
 	pict.data[1] = env->bmp->pixels[2];
@@ -609,7 +624,6 @@
 		(AVPicture *)env->frame, env->context->pix_fmt,
 		env->context->width, env->context->height);
 	SDL_UnlockYUVOverlay(env->bmp);
-ast_log(LOG_WARNING, "unlocked sdl\n");
 
 	rect.x = 0; rect.y = 0;
 	rect.w = env->context->width;
@@ -632,6 +646,8 @@
 	int len;
 	struct video_desc *env = get_video_desc(chan);
 
+	if(!env->initialized)
+		ffmpeg_init(env, f->subclass);
 	if(!env->initialized)
 		return -1;	/* error */
 
@@ -1491,13 +1507,6 @@
 		}
 	}
 
-#if HAVE_FFMPEG
-	/* Let's initialize the environment only if a new call arrives */
-	/* Initializations for ffmpeg decoding */
-	/* XXX This should be allocated for each video session */
-	ffmpeg_init(&o->env);
-#endif
-
 	return c;
 }
 
@@ -1673,9 +1682,6 @@
 	if (o->owner)
 		ast_queue_hangup(o->owner);
 	setformat(o, O_CLOSE);
-#if HAVE_FFMPEG
-	ffmpeg_uninit(&o->env);
-#endif
 	return CLI_SUCCESS;
 }
 




More information about the asterisk-commits mailing list