[asterisk-commits] rizzo: branch rizzo/video_v2 r85355 - /team/rizzo/video_v2/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Oct 10 15:59:29 CDT 2007
Author: rizzo
Date: Wed Oct 10 15:59:28 2007
New Revision: 85355
URL: http://svn.digium.com/view/asterisk?view=rev&rev=85355
Log:
prepare to support different inbound and outbound codecs
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=85355&r1=85354&r2=85355
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Wed Oct 10 15:59:28 2007
@@ -171,6 +171,7 @@
int pix_fmt;
};
+struct video_codec_desc; /* forward declaration */
/*
* Descriptor of the local source, made of the following pieces:
* + configuration info (geometry, device name, fps...). These are read
@@ -201,6 +202,7 @@
struct fbuf_t enc_out; /* encoder output buffer */
struct fbuf_t loc_dpy; /* display source buffer */
+ struct video_codec_desc *enc; /* encoder */
AVCodecContext *enc_ctx; /* encoding context */
AVCodec *codec;
AVFrame *frame; /* The initial part is an AVPicture */
@@ -222,6 +224,7 @@
* codec, no memory, etc.) and we must drop all incoming frames.
*/
struct video_in_desc {
+ 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 */
@@ -281,8 +284,6 @@
struct video_in_desc in; /* remote video descriptor */
struct video_out_desc out; /* local video descriptor */
-
- struct video_codec_desc *current_codec;
SDL_Surface *screen;
int sdl_ok;
@@ -1325,7 +1326,7 @@
ast_log(LOG_WARNING, "No local source active\n");
return video_out_uninit(v);
}
- codec = map_video_format(env->current_codec->format, CM_WR);
+ codec = map_video_format(v->enc->format, CM_WR);
v->codec = avcodec_find_encoder(codec);
if (!v->codec) {
ast_log(LOG_WARNING, "Cannot find the encoder for format %d\n",
@@ -1373,7 +1374,7 @@
v->enc_ctx->rtp_payload_size = v->mtu / 2; // mtu/2
v->enc_ctx->bit_rate_tolerance = v->enc_ctx->bit_rate/2;
- env->current_codec->enc_init(v);
+ v->enc->enc_init(v);
v->enc_ctx->time_base = (AVRational){1, v->fps};
if (avcodec_open(v->enc_ctx, v->codec) < 0) {
@@ -1584,26 +1585,28 @@
struct video_desc *env = get_video_desc(chan);
struct video_in_desc *v = &env->in;
+ /* XXX todo: try to allocate the encoder on the first input frame,
+ * if it fails may retry later, but not too often.
+ */
if (v->dec_ctx == NULL) {
ast_log(LOG_WARNING, "cannot decode, dropping frame\n");
return 0; /* error */
}
#if defined(DROP_PACKETS) && DROP_PACKETS > 0
- /* Simulate lost/delayed packets */
+ /* Simulate lost packets */
if ((random() % 10000) <= 100*DROP_PACKETS) {
ast_log(LOG_NOTICE, "Packet lost [%d]\n", f->seqno);
return 0;
}
#endif
if (v->discard) {
- ast_log(LOG_WARNING, "discard mode, drop frame %d\n", f->seqno);
/*
* In discard mode, drop packets until we find one with
* the RTP marker set (which is the end of frame).
- * XXX note that the RTP marker flag is sent as the LSB of the
- * subclass. This is slightly annoying as it goes to overwrite
- * the payload type entry.
+ * Note that the RTP marker flag is sent as the LSB of the
+ * subclass, which is a bitmask of formats. The low bit is
+ * normally used for audio so there is no interference.
*/
if (f->subclass & 0x01) {
v->dec_in.used = 0;
@@ -1618,7 +1621,7 @@
/*
* Only in-order fragments will be accepted. Remember seqno
* has 16 bit so there is wraparound. Also, ideally we could
- * accept a bit of reordering, but at the moment wr don't.
+ * accept a bit of reordering, but at the moment we don't.
*/
if (v->next_seq != f->seqno) {
ast_log(LOG_WARNING, "discarding frame out of order, %d %d\n",
@@ -1632,12 +1635,12 @@
ast_log(LOG_WARNING, "empty video frame, discard\n");
return 0;
}
- if (env->current_codec->dec_decap(&v->dec_in, f->data, f->datalen)) {
+ if (v->dec->dec_decap(&v->dec_in, f->data, f->datalen)) {
ast_log(LOG_WARNING, "error in dec_decap, enter discard\n");
v->discard = 1;
}
if (f->subclass & 0x01) { // RTP Marker
- if (env->current_codec->dec_run(v, &v->dec_in))
+ if (v->dec->dec_run(v, &v->dec_in))
show_frame(env, 0);
v->dec_in.used = 0;
v->dec_in.ebit = 0;
@@ -1682,8 +1685,8 @@
ast_log(LOG_WARNING, "fail, no encbuf\n");
return NULL;
}
- env->current_codec->enc_run(v);
- return env->current_codec->enc_encap(v, tail);
+ v->enc->enc_run(v);
+ return v->enc->enc_encap(v, tail);
}
/*
@@ -1800,14 +1803,17 @@
*/
avcodec_init();
avcodec_register_all();
- env->current_codec = map_config_video_format(env->codec_name);
+ env->out.enc = map_config_video_format(env->codec_name);
+ env->in.dec = env->out.enc;
av_log_set_level(AV_LOG_ERROR); /* only report errors */
- if (video_in_init(&env->in, env->current_codec->format)) {
+#if 1
+ if (video_in_init(&env->in, env->in.dec->format)) {
/* This is not fatal, but we won't have incoming video */
ast_log(LOG_WARNING, "Cannot initialize input decoder - %s\n",
SDL_GetError());
}
+#endif
/*
* initialize the SDL environment
More information about the asterisk-commits
mailing list