[asterisk-commits] rizzo: branch rizzo/video_v2 r86872 - /team/rizzo/video_v2/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 23 07:24:31 CDT 2007


Author: rizzo
Date: Tue Oct 23 07:24:31 2007
New Revision: 86872

URL: http://svn.digium.com/view/asterisk?view=rev&rev=86872
Log:
better splitting of incoming data, in case the received data
covers multiple video frames.

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=86872&r1=86871&r2=86872
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Tue Oct 23 07:24:31 2007
@@ -228,7 +228,7 @@
 	struct video_codec_desc *dec;	/* decoder */
 	AVCodecContext          *dec_ctx;	/* information about the codec in the stream */
 	AVCodec                 *codec;		/* reference to the codec */
-	AVFrame                 *frame;		/* place to store the frame */
+	AVFrame                 *d_frame;	/* place to store the decoded frame */
 	AVCodecParserContext    *parser;
 	uint16_t 		next_seq;	/* must be 16 bit */
 	int                     discard;	/* flag for discard status */
@@ -697,16 +697,16 @@
 {
 	uint8_t *src = b->data;
 	int srclen = b->used;
-	int retval = 0;
-
-	if (!srclen)
+	int full_frame = 0;
+
+	if (srclen == 0)	/* no data */
 		return 0;
 	if (0)
 		check_h261(b);
 	// ast_log(LOG_WARNING, "rx size %d\n", srclen);
 	while (srclen) {
 		uint8_t *data;
-		int datalen, ret, dummy = 0;
+		int datalen, ret;
 		int len = av_parser_parse(v->parser, v->dec_ctx, &data, &datalen, src, srclen, 0, 0);
 
 		src += len;
@@ -716,14 +716,19 @@
 		 */
 		if (data == NULL || datalen == 0)
 			continue;
-		ret = avcodec_decode_video(v->dec_ctx, v->frame, &dummy, data, datalen);
+		ret = avcodec_decode_video(v->dec_ctx, v->d_frame, &full_frame, data, datalen);
+		if (full_frame == 1)	/* full frame */
+			break;
 		if (ret < 0) {
 			ast_log(LOG_NOTICE, "Error decoding\n");
-			return 0;
-		}
-		retval = 1;
-	}
-	return retval;
+			break;
+		}
+	}
+	if (srclen != 0)	/* update b with leftover data */
+		bcopy(src, b->data, srclen);
+	b->used = srclen;
+	b->ebit = 0;
+	return full_frame;
 }
 
 static struct video_codec_desc h263p_codec = {
@@ -1112,14 +1117,19 @@
 
 static int mpeg4_decode(struct video_in_desc *v, struct fbuf_t *b)
 {
-	int dummy;
-	int ret = avcodec_decode_video(v->dec_ctx, v->frame, &dummy,
-		b->data, b->used);
+	int full_frame = 0, datalen = b->used;
+	int ret = avcodec_decode_video(v->dec_ctx, v->d_frame, &full_frame,
+		b->data, datalen);
 	if (ret < 0) {
 		ast_log(LOG_NOTICE, "Error decoding\n");
-		return 0;
-	}
-	return 1;
+		ret = datalen; /* assume we used everything. */
+	}
+	datalen -= ret;
+	if (datalen > 0)	/* update b with leftover bytes */
+		bcopy(b->data + ret, b->data, datalen);
+	b->used = datalen;
+	b->ebit = 0;
+	return full_frame;
 }
 
 static struct video_codec_desc mpeg4_codec = {
@@ -1638,9 +1648,9 @@
 		av_free(v->dec_ctx);
 		v->dec_ctx = NULL;
 	}
-	if (v->frame) {
-		av_free(v->frame);
-		v->frame = NULL;
+	if (v->d_frame) {
+		av_free(v->d_frame);
+		v->d_frame = NULL;
 	}
 	v->codec = NULL;	/* only a reference */
 	v->dec = NULL;		/* forget the decoder */
@@ -1661,7 +1671,7 @@
 	/* XXX should check that these are already set */
 	v->codec = NULL;
 	v->dec_ctx = NULL;
-	v->frame = NULL;
+	v->d_frame = NULL;
 	v->parser = NULL;
 	v->discard = 1;
 
@@ -1689,8 +1699,8 @@
 		return video_in_uninit(v);
 	}
 
-	v->frame = avcodec_alloc_frame();
-	if (!v->frame) {
+	v->d_frame = avcodec_alloc_frame();
+	if (!v->d_frame) {
 		ast_log(LOG_WARNING, "Cannot allocate decoding video frame\n");
 		return video_in_uninit(v);
 	}
@@ -1972,7 +1982,7 @@
                 b_in->h = c->height;
 
 		b_out = &env->in.rem_dpy;
-		p_in = (AVPicture *)env->in.frame;
+		p_in = (AVPicture *)env->in.d_frame;
 	}
 	bmp = env->bmp[out];
 	SDL_LockYUVOverlay(bmp);
@@ -2078,8 +2088,6 @@
 	if (f->subclass & 0x01) {	// RTP Marker
 		if (v->dec->dec_run(v, &v->dec_in))
 			show_frame(env, 0);
-		v->dec_in.used = 0;
-		v->dec_in.ebit = 0;
 	}
 	return 0;
 }




More information about the asterisk-commits mailing list