Asterisk - The Open Source Telephony Project GIT-master-f36a736
console_video.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright 2007-2008, Marta Carbone, Sergio Fadda, Luigi Rizzo
5 *
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
11 *
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
15 */
16
17/*
18 * Experimental support for video sessions. We use SDL for rendering, ffmpeg
19 * as the codec library for encoding and decoding, and Video4Linux and X11
20 * to generate the local video stream.
21 *
22 * If one of these pieces is not available, either at compile time or at
23 * runtime, we do our best to run without it. Of course, no codec library
24 * means we can only deal with raw data, no SDL means we cannot do rendering,
25 * no V4L or X11 means we cannot generate data (but in principle we could
26 * stream from or record to a file).
27 *
28 * We need a recent (2007.07.12 or newer) version of ffmpeg to avoid warnings.
29 * Older versions might give 'deprecated' messages during compilation,
30 * thus not compiling in AST_DEVMODE, or don't have swscale, in which case
31 * you can try to compile #defining OLD_FFMPEG here.
32 *
33 * $Revision$
34 */
35
36//#define DROP_PACKETS 5 /* if set, drop this % of video packets */
37//#define OLD_FFMPEG 1 /* set for old ffmpeg with no swscale */
38
39/*** MODULEINFO
40 <support_level>extended</support_level>
41 ***/
42
43#include "asterisk.h"
44#include <sys/ioctl.h>
45#include "asterisk/cli.h"
46#include "asterisk/file.h"
47#include "asterisk/channel.h"
48
49#include "console_video.h"
50
51/*
52The code is structured as follows.
53
54When a new console channel is created, we call console_video_start()
55to initialize SDL, the source, and the encoder/ decoder for the
56formats in use (XXX the latter two should be done later, once the
57codec negotiation is complete). Also, a thread is created to handle
58the video source and generate frames.
59
60While communication is on, the local source is generated by the
61video thread, which wakes up periodically, generates frames and
62enqueues them in chan->readq. Incoming rtp frames are passed to
63console_write_video(), decoded and passed to SDL for display.
64
65For as unfortunate and confusing as it can be, we need to deal with a
66number of different video representations (size, codec/pixel format,
67codec parameters), as follows:
68
69 loc_src is the data coming from the camera/X11/etc.
70 The format is typically constrained by the video source.
71
72 enc_in is the input required by the encoder.
73 Typically constrained in size by the encoder type.
74
75 enc_out is the bitstream transmitted over RTP.
76 Typically negotiated while the call is established.
77
78 loc_dpy is the format used to display the local video source.
79 Depending on user preferences this can have the same size as
80 loc_src_fmt, or enc_in_fmt, or thumbnail size (e.g. PiP output)
81
82 dec_in is the incoming RTP bitstream. Negotiated
83 during call establishment, it is not necessarily the same as
84 enc_in_fmt
85
86 dec_out the output of the decoder.
87 The format is whatever the other side sends, and the
88 buffer is allocated by avcodec_decode_... so we only
89 copy the data here.
90
91 rem_dpy the format used to display the remote stream
92
93 src_dpy is the format used to display the local video source streams
94 The number of these fbuf_t is determined at run time, with dynamic allocation
95
96We store the format info together with the buffer storing the data.
97As a future optimization, a format/buffer may reference another one
98if the formats are equivalent. This will save some unnecessary format
99conversion.
100
101
102In order to handle video you need to add the following to the endpoint in
103pjsip.conf
104
105 allow=h263 ; this or other video formats
106 allow=h263p ; this or other video formats
107
108(Presumably, iax.conf would require):
109
110 [general](+)
111 videosupport=yes
112 allow=h263 ; this or other video formats
113 allow=h263p ; this or other video formats
114
115
116 */
117
118/*
119 * Codecs are absolutely necessary or we cannot do anything.
120 * SDL is optional (used for rendering only), so that we can still
121 * stream video without displaying it.
122 */
123#if !defined(HAVE_VIDEO_CONSOLE) || !defined(HAVE_FFMPEG)
124/* stubs if required pieces are missing */
125int console_write_video(struct ast_channel *chan, struct ast_frame *f)
126{
127 return 0; /* writing video not supported */
128}
129
130int console_video_cli(struct video_desc *env, const char *var, int fd)
131{
132 return 1; /* nothing matched */
133}
134
135int console_video_config(struct video_desc **penv, const char *var, const char *val)
136{
137 return 1; /* no configuration */
138}
139
140void console_video_start(struct video_desc *env, struct ast_channel *owner)
141{
142 ast_log(LOG_NOTICE, "voice only, console video support not present\n");
143}
144
145void console_video_uninit(struct video_desc *env)
146{
147}
148
149int get_gui_startup(struct video_desc* env)
150{
151 return 0; /* no gui here */
152}
153
155
156#else /* defined(HAVE_FFMPEG) && defined(HAVE_SDL) */
157
158/*! The list of video formats we support. */
160 AST_FORMAT_H263_PLUS | AST_FORMAT_H263 |
161 AST_FORMAT_MP4_VIDEO | AST_FORMAT_H264 | AST_FORMAT_H261 ;
162
163
164
165/* function to scale and encode buffers */
166static void my_scale(struct fbuf_t *in, AVPicture *p_in,
167 struct fbuf_t *out, AVPicture *p_out);
168
169/*
170 * this structure will be an entry in the table containing
171 * every device specified in the file oss.conf, it contains various information
172 * about the device
173 */
174struct video_device {
175 char *name; /* name of the device */
176 /* allocated dynamically (see fill_table function) */
177 struct grab_desc *grabber; /* the grabber for the device type */
178 void *grabber_data; /* device's private data structure */
179 struct fbuf_t *dev_buf; /* buffer for incoming data */
180 struct timeval last_frame; /* when we read the last frame ? */
181 int status_index; /* what is the status of the device (source) */
182 /* status index is set using the IS_ON, IS_PRIMARY and IS_SECONDARY constants */
183 /* status_index is the index of the status message in the src_msgs array in console_gui.c */
184};
185
186struct video_codec_desc; /* forward declaration */
187/*
188 * Descriptor of the local source, made of the following pieces:
189 * + configuration info (geometry, device name, fps...). These are read
190 * from the config file and copied here before calling video_out_init();
191 * + the frame buffer (buf) and source pixel format, allocated at init time;
192 * + the encoding and RTP info, including timestamps to generate
193 * frames at the correct rate;
194 * + source-specific info, i.e. fd for /dev/video, dpy-image for x11, etc,
195 * filled in by grabber_open, part of source_specific information are in
196 * the device table (devices member), others are shared;
197 * NOTE: loc_src.data == NULL means the rest of the struct is invalid, and
198 * the video source is not available.
199 */
200struct video_out_desc {
201 /* video device support.
202 * videodevice and geometry are read from the config file.
203 * At the right time we try to open it and allocate a buffer.
204 * If we are successful, webcam_bufsize > 0 and we can read.
205 */
206 /* all the following is config file info copied from the parent */
207 int fps;
208 int bitrate;
209 int qmin;
210
211 int sendvideo;
212
213 struct fbuf_t loc_src_geometry; /* local source geometry only (from config file) */
214 struct fbuf_t enc_out; /* encoder output buffer, allocated in video_out_init() */
215
216 struct video_codec_desc *enc; /* encoder */
217 void *enc_ctx; /* encoding context */
218 AVCodec *codec;
219 AVFrame *enc_in_frame; /* enc_in mapped into avcodec format. */
220 /* The initial part of AVFrame is an AVPicture */
221 int mtu;
222
223 /* Table of devices specified with "videodevice=" in oss.conf.
224 * Static size as we have a limited number of entries.
225 */
226 struct video_device devices[MAX_VIDEO_SOURCES];
227 int device_num; /*number of devices in table*/
228 int device_primary; /*index of the actual primary device in the table*/
229 int device_secondary; /*index of the actual secondary device in the table*/
230
231 int picture_in_picture; /*Is the PiP mode activated? 0 = NO | 1 = YES*/
232
233 /* these are the coordinates of the picture inside the picture (visible if PiP mode is active)
234 these coordinates are valid considering the containing buffer with cif geometry*/
235 int pip_x;
236 int pip_y;
237};
238
239/*
240 * The overall descriptor, with room for config info, video source and
241 * received data descriptors, SDL info, etc.
242 * This should be globally visible to all modules (grabber, vcodecs, gui)
243 * and contain all configurtion info.
244 */
245struct video_desc {
246 char codec_name[64]; /* the codec we use */
247
248 int stayopen; /* set if gui starts manually */
249 pthread_t vthread; /* video thread */
250 ast_mutex_t dec_lock; /* sync decoder and video thread */
251 int shutdown; /* set to shutdown vthread */
252 struct ast_channel *owner; /* owner channel */
253
254
255 struct fbuf_t enc_in; /* encoder input buffer, allocated in video_out_init() */
256
257 char keypad_file[256]; /* image for the keypad */
258 char keypad_font[256]; /* font for the keypad */
259
260 char sdl_videodriver[256];
261
262 struct fbuf_t rem_dpy; /* display remote video, no buffer (it is in win[WIN_REMOTE].bmp) */
263 struct fbuf_t loc_dpy; /* display local source, no buffer (managed by SDL in bmp[1]) */
264
265 /* geometry of the thumbnails for all video sources. */
266 struct fbuf_t src_dpy[MAX_VIDEO_SOURCES]; /* no buffer allocated here */
267
268 int frame_freeze; /* flag to freeze the incoming frame */
269
270 /* local information for grabbers, codecs, gui */
271 struct gui_info *gui;
272 struct video_dec_desc *in; /* remote video descriptor */
273 struct video_out_desc out; /* local video descriptor */
274};
275
276static AVPicture *fill_pict(struct fbuf_t *b, AVPicture *p);
277
278void fbuf_free(struct fbuf_t *b)
279{
280 struct fbuf_t x = *b;
281
282 if (b->data && b->size)
283 ast_free(b->data);
284 memset(b, '\0', sizeof(*b));
285 /* restore some fields */
286 b->w = x.w;
287 b->h = x.h;
288 b->pix_fmt = x.pix_fmt;
289}
290
291/* return the status of env->stayopen to chan_oss, as the latter
292 * does not have access to fields of struct video_desc
293 */
294int get_gui_startup(struct video_desc* env)
295{
296 return env ? env->stayopen : 0;
297}
298
299#if 0
300/* helper function to print the amount of memory used by the process.
301 * Useful to track memory leaks, unfortunately this code is OS-specific
302 * so we keep it commented out.
303 */
304static int
305used_mem(const char *msg)
306{
307 char in[128];
308
309 pid_t pid = getpid();
310 sprintf(in, "ps -o vsz= -o rss= %d", pid);
311 ast_log(LOG_WARNING, "used mem (vsize, rss) %s ", msg);
312 system(in);
313 return 0;
314}
315#endif
316
317#include "vcodecs.c"
318#include "console_gui.c"
319
320/*! \brief Try to open video sources, return 0 on success, 1 on error
321 * opens all video sources found in the oss.conf configuration files.
322 * Saves the grabber and the datas in the device table (in the devices field
323 * of the descriptor referenced by v).
324 * Initializes the device_primary and device_secondary
325 * fields of v with the first devices that was
326 * successfully opened.
327 *
328 * \param v = video out environment descriptor
329 *
330 * returns 0 on success, 1 on error
331*/
332static int grabber_open(struct video_out_desc *v)
333{
334 struct grab_desc *g;
335 void *g_data;
336 int i, j;
337
338 /* for each device in the device table... */
339 for (i = 0; i < v->device_num; i++) {
340 /* device already open */
341 if (v->devices[i].grabber)
342 continue;
343 /* for each type of grabber supported... */
344 for (j = 0; (g = console_grabbers[j]); j++) {
345 /* the grabber is opened and the informations saved in the device table */
346 g_data = g->open(v->devices[i].name, &v->loc_src_geometry, v->fps);
347 if (!g_data)
348 continue;
349 v->devices[i].grabber = g;
350 v->devices[i].grabber_data = g_data;
351 v->devices[i].status_index |= IS_ON;
352 }
353 }
354 /* the first working device is selected as the primary one and the secondary one */
355 for (i = 0; i < v->device_num; i++) {
356 if (!v->devices[i].grabber)
357 continue;
358 v->device_primary = i;
359 v->device_secondary = i;
360 return 0; /* source found */
361 }
362 return 1; /* no source found */
363}
364
365
366/*! \brief complete a buffer from the specified local video source.
367 * Called by get_video_frames(), in turn called by the video thread.
368 *
369 * \param dev = video environment descriptor
370 * \param fps = frame per seconds, for every device
371 *
372 * returns:
373 * - NULL on falure
374 * - reference to the device buffer on success
375 */
376static struct fbuf_t *grabber_read(struct video_device *dev, int fps)
377{
378 struct timeval now = ast_tvnow();
379
380 if (dev->grabber == NULL) /* not initialized */
381 return NULL;
382
383 /* the last_frame field in this row of the device table (dev)
384 is always initialized, it is set during the parsing of the config
385 file, and never unset, function fill_device_table(). */
386 /* check if it is time to read */
387 if (ast_tvdiff_ms(now, dev->last_frame) < 1000/fps)
388 return NULL; /* too early */
389 dev->last_frame = now; /* XXX actually, should correct for drift */
390 return dev->grabber->read(dev->grabber_data);
391}
392
393/*! \brief handler run when dragging with the left button on
394 * the local source window - the effect is to move the offset
395 * of the captured area.
396 */
397static void grabber_move(struct video_device *dev, int dx, int dy)
398{
399 if (dev->grabber && dev->grabber->move) {
400 dev->grabber->move(dev->grabber_data, dx, dy);
401 }
402}
403
404/*
405 * Map the codec name to the library. If not recognised, use a default.
406 * This is useful in the output path where we decide by name, presumably.
407 */
408static struct video_codec_desc *map_config_video_format(char *name)
409{
410 int i;
411
412 for (i = 0; supported_codecs[i]; i++)
413 if (!strcasecmp(name, supported_codecs[i]->name))
414 break;
415 if (supported_codecs[i] == NULL) {
416 ast_log(LOG_WARNING, "Cannot find codec for '%s'\n", name);
417 i = 0;
418 strcpy(name, supported_codecs[i]->name);
419 }
420 ast_log(LOG_WARNING, "Using codec '%s'\n", name);
421 return supported_codecs[i];
422}
423
424
425/*! \brief uninitialize the descriptor for local video stream */
426static int video_out_uninit(struct video_desc *env)
427{
428 struct video_out_desc *v = &env->out;
429 int i; /* integer variable used as iterator */
430
431 /* XXX this should be a codec callback */
432 if (v->enc_ctx) {
433 AVCodecContext *enc_ctx = (AVCodecContext *)v->enc_ctx;
434 avcodec_close(enc_ctx);
435 av_free(enc_ctx);
436 v->enc_ctx = NULL;
437 }
438 if (v->enc_in_frame) {
439 av_free(v->enc_in_frame);
440 v->enc_in_frame = NULL;
441 }
442 v->codec = NULL; /* nothing to free, this is only a reference */
443 /* release the buffers */
444 fbuf_free(&env->enc_in);
445 fbuf_free(&v->enc_out);
446 /* close the grabbers */
447 for (i = 0; i < v->device_num; i++) {
448 if (v->devices[i].grabber){
449 v->devices[i].grabber_data =
450 v->devices[i].grabber->close(v->devices[i].grabber_data);
451 v->devices[i].grabber = NULL;
452 /* dev_buf is already freed by grabber->close() */
453 v->devices[i].dev_buf = NULL;
454 }
455 v->devices[i].status_index = 0;
456 }
457 v->picture_in_picture = 0;
458 env->frame_freeze = 0;
459 return -1;
460}
461
462/*
463 * Initialize the encoder for the local source:
464 * - enc_ctx, codec, enc_in_frame are used by ffmpeg for encoding;
465 * - enc_out is used to store the encoded frame (to be sent)
466 * - mtu is used to determine the max size of video fragment
467 * NOTE: we enter here with the video source already open.
468 */
469static int video_out_init(struct video_desc *env)
470{
471 int codec;
472 int size;
473 struct fbuf_t *enc_in;
474 struct video_out_desc *v = &env->out;
475
476 v->enc_ctx = NULL;
477 v->codec = NULL;
478 v->enc_in_frame = NULL;
479 v->enc_out.data = NULL;
480
481 codec = map_video_format(v->enc->format, CM_WR);
482 v->codec = avcodec_find_encoder(codec);
483 if (!v->codec) {
484 ast_log(LOG_WARNING, "Cannot find the encoder for format %d\n",
485 codec);
486 return -1; /* error, but nothing to undo yet */
487 }
488
489 v->mtu = 1400; /* set it early so the encoder can use it */
490
491 /* allocate the input buffer for encoding.
492 * ffmpeg only supports PIX_FMT_YUV420P for the encoding.
493 */
494 enc_in = &env->enc_in;
495 enc_in->pix_fmt = PIX_FMT_YUV420P;
496 enc_in->size = (enc_in->w * enc_in->h * 3)/2;
497 enc_in->data = ast_calloc(1, enc_in->size);
498 if (!enc_in->data) {
499 ast_log(LOG_WARNING, "Cannot allocate encoder input buffer\n");
500 return video_out_uninit(env);
501 }
502 /* construct an AVFrame that points into buf_in */
503 v->enc_in_frame = avcodec_alloc_frame();
504 if (!v->enc_in_frame) {
505 ast_log(LOG_WARNING, "Unable to allocate the encoding video frame\n");
506 return video_out_uninit(env);
507 }
508
509 /* parameters for PIX_FMT_YUV420P */
510 size = enc_in->w * enc_in->h;
511 v->enc_in_frame->data[0] = enc_in->data;
512 v->enc_in_frame->data[1] = v->enc_in_frame->data[0] + size;
513 v->enc_in_frame->data[2] = v->enc_in_frame->data[1] + size/4;
514 v->enc_in_frame->linesize[0] = enc_in->w;
515 v->enc_in_frame->linesize[1] = enc_in->w/2;
516 v->enc_in_frame->linesize[2] = enc_in->w/2;
517
518 /* now setup the parameters for the encoder.
519 * XXX should be codec-specific
520 */
521 {
522 AVCodecContext *enc_ctx = avcodec_alloc_context();
523 v->enc_ctx = enc_ctx;
524 enc_ctx->pix_fmt = enc_in->pix_fmt;
525 enc_ctx->width = enc_in->w;
526 enc_ctx->height = enc_in->h;
527 /* XXX rtp_callback ?
528 * rtp_mode so ffmpeg inserts as many start codes as possible.
529 */
530 enc_ctx->rtp_mode = 1;
531 enc_ctx->rtp_payload_size = v->mtu / 2; // mtu/2
532 enc_ctx->bit_rate = v->bitrate;
533 enc_ctx->bit_rate_tolerance = enc_ctx->bit_rate/2;
534 enc_ctx->qmin = v->qmin; /* should be configured */
535 enc_ctx->time_base = (AVRational){1, v->fps};
536 enc_ctx->gop_size = v->fps*5; // emit I frame every 5 seconds
537
538 v->enc->enc_init(v->enc_ctx);
539
540 if (avcodec_open(enc_ctx, v->codec) < 0) {
541 ast_log(LOG_WARNING, "Unable to initialize the encoder %d\n", codec);
542 av_free(enc_ctx);
543 v->enc_ctx = NULL;
544 return video_out_uninit(env);
545 }
546 }
547 /*
548 * Allocate enough for the encoded bitstream. As we are compressing,
549 * we hope that the output is never larger than the input size.
550 */
551 v->enc_out.data = ast_calloc(1, enc_in->size);
552 v->enc_out.size = enc_in->size;
553 v->enc_out.used = 0;
554
555 return 0;
556}
557
558/*! \brief possibly uninitialize the video console.
559 * Called at the end of a call, should reset the 'owner' field,
560 * then possibly terminate the video thread if the gui has
561 * not been started manually.
562 * In practice, signal the thread and give it a bit of time to
563 * complete, giving up if it gets stuck. Because uninit
564 * is called from hangup with the channel locked, and the thread
565 * uses the chan lock, we need to unlock here. This is unsafe,
566 * and we should really use refcounts for the channels.
567 */
568void console_video_uninit(struct video_desc *env)
569{
570 int i, t = 100; /* initial wait is shorter, than make it longer */
571 if (env->stayopen == 0) { /* gui opened by a call, do the shutdown */
572 env->shutdown = 1;
573 for (i=0; env->shutdown && i < 10; i++) {
574 if (env->owner)
575 ast_channel_unlock(env->owner);
576 usleep(t);
577 t = 1000000;
578 if (env->owner)
579 ast_channel_lock(env->owner);
580 }
581 env->vthread = NULL;
582 }
583 env->owner = NULL; /* this is unconditional */
584}
585
586/*! fill an AVPicture from our fbuf info, as it is required by
587 * the image conversion routines in ffmpeg. Note that the pointers
588 * are recalculated if the fbuf has an offset (and so represents a picture in picture)
589 * XXX This depends on the format.
590 */
591static AVPicture *fill_pict(struct fbuf_t *b, AVPicture *p)
592{
593 /* provide defaults for commonly used formats */
594 int l4 = b->w * b->h/4; /* size of U or V frame */
595 int len = b->w; /* Y linesize, bytes */
596 int luv = b->w/2; /* U/V linesize, bytes */
597 int sample_size = 1;
598
599 memset(p, '\0', sizeof(*p));
600 switch (b->pix_fmt) {
601 case PIX_FMT_RGB555:
602 case PIX_FMT_RGB565:
603 sample_size = 2;
604 luv = 0;
605 break;
606 case PIX_FMT_RGBA32:
607 sample_size = 4;
608 luv = 0;
609 break;
610 case PIX_FMT_YUYV422: /* Packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr */
611 sample_size = 2; /* all data in first plane, probably */
612 luv = 0;
613 break;
614 }
615 len *= sample_size;
616
617 p->data[0] = b->data;
618 p->linesize[0] = len;
619 /* these are only valid for component images */
620 p->data[1] = luv ? b->data + 4*l4 : b->data+len;
621 p->data[2] = luv ? b->data + 5*l4 : b->data+len;
622 p->linesize[1] = luv;
623 p->linesize[2] = luv;
624
625 /* add the offsets to the pointers previously calculated,
626 it is necessary for the picture in picture mode */
627 p->data[0] += len*b->win_y + b->win_x*sample_size;
628 if (luv) {
629 p->data[1] += luv*(b->win_y/2) + (b->win_x/2) * sample_size;
630 p->data[2] += luv*(b->win_y/2) + (b->win_x/2) * sample_size;
631 }
632 return p;
633}
634
635/*! convert/scale between an input and an output format.
636 * Old version of ffmpeg only have img_convert, which does not rescale.
637 * New versions use sws_scale which does both.
638 */
639static void my_scale(struct fbuf_t *in, AVPicture *p_in,
640 struct fbuf_t *out, AVPicture *p_out)
641{
642 AVPicture my_p_in, my_p_out;
643 int eff_w=out->w, eff_h=out->h;
644
645 if (p_in == NULL)
646 p_in = fill_pict(in, &my_p_in);
647 if (p_out == NULL)
648 p_out = fill_pict(out, &my_p_out);
649
650 /*if win_w is different from zero then we must change
651 the size of the scaled buffer (the position is already
652 encoded into the out parameter)*/
653 if (out->win_w) { /* picture in picture enabled */
654 eff_w=out->win_w;
655 eff_h=out->win_h;
656 }
657#ifdef OLD_FFMPEG
658 /* XXX img_convert is deprecated, and does not do rescaling, PiP not supported */
659 img_convert(p_out, out->pix_fmt,
660 p_in, in->pix_fmt, in->w, in->h);
661#else /* XXX replacement */
662 {
663 struct SwsContext *convert_ctx;
664
665 convert_ctx = sws_getContext(in->w, in->h, in->pix_fmt,
666 eff_w, eff_h, out->pix_fmt,
667 SWS_BICUBIC, NULL, NULL, NULL);
668 if (convert_ctx == NULL) {
669 ast_log(LOG_ERROR, "FFMPEG::convert_cmodel : swscale context initialization failed\n");
670 return;
671 }
672 if (0)
673 ast_log(LOG_WARNING, "in %d %dx%d out %d %dx%d\n",
674 in->pix_fmt, in->w, in->h, out->pix_fmt, eff_w, eff_h);
675 sws_scale(convert_ctx,
676 p_in->data, p_in->linesize,
677 in->w, in->h, /* src slice */
678 p_out->data, p_out->linesize);
679
680 sws_freeContext(convert_ctx);
681 }
682#endif /* XXX replacement */
683}
684
685struct video_desc *get_video_desc(struct ast_channel *c);
686
687/*
688 * This function is called (by asterisk) for each video packet
689 * coming from the network (the 'in' path) that needs to be processed.
690 * We need to reconstruct the entire video frame before we can decode it.
691 * After a video packet is received we have to:
692 * - extract the bitstream with pre_process_data()
693 * - append the bitstream to a buffer
694 * - if the fragment is the last (RTP Marker) we decode it with decode_video()
695 * - after the decoding is completed we display the decoded frame with show_frame()
696 */
697int console_write_video(struct ast_channel *chan, struct ast_frame *f);
698int console_write_video(struct ast_channel *chan, struct ast_frame *f)
699{
700 struct video_desc *env = get_video_desc(chan);
701 struct video_dec_desc *v = env->in;
702
703 if (!env->gui) /* no gui, no rendering */
704 return 0;
705 if (v == NULL)
706 env->in = v = dec_init(f->subclass & ~1);
707 if (v == NULL) {
708 /* This is not fatal, but we won't have incoming video */
709 ast_log(LOG_WARNING, "Cannot initialize input decoder\n");
710 return 0;
711 }
712
713 if (v->dec_in_cur == NULL) /* no buffer for incoming frames, drop */
714 return 0;
715#if defined(DROP_PACKETS) && DROP_PACKETS > 0
716 /* Simulate lost packets */
717 if ((random() % 10000) <= 100*DROP_PACKETS) {
718 ast_log(LOG_NOTICE, "Packet lost [%d]\n", f->seqno);
719 return 0;
720 }
721#endif
722 if (v->discard) {
723 /*
724 * In discard mode, drop packets until we find one with
725 * the RTP marker set (which is the end of frame).
726 * Note that the RTP marker flag is sent as the LSB of the
727 * subclass, which is a bitmask of formats. The low bit is
728 * normally used for audio so there is no interference.
729 */
730 if (f->subclass & 0x01) {
731 v->dec_in_cur->used = 0;
732 v->dec_in_cur->ebit = 0;
733 v->next_seq = f->seqno + 1; /* wrap at 16 bit */
734 v->discard = 0;
735 ast_log(LOG_WARNING, "out of discard mode, frame %d\n", f->seqno);
736 }
737 return 0;
738 }
739
740 /*
741 * Only in-order fragments will be accepted. Remember seqno
742 * has 16 bit so there is wraparound. Also, ideally we could
743 * accept a bit of reordering, but at the moment we don't.
744 */
745 if (v->next_seq != f->seqno) {
746 ast_log(LOG_WARNING, "discarding frame out of order, %d %d\n",
747 v->next_seq, f->seqno);
748 v->discard = 1;
749 return 0;
750 }
751 v->next_seq++;
752
753 if (f->data.ptr == NULL || f->datalen < 2) {
754 ast_log(LOG_WARNING, "empty video frame, discard\n");
755 return 0;
756 }
757 if (v->d_callbacks->dec_decap(v->dec_in_cur, f->data.ptr, f->datalen)) {
758 ast_log(LOG_WARNING, "error in dec_decap, enter discard\n");
759 v->discard = 1;
760 }
761 if (f->subclass & 0x01) { // RTP Marker
762 /* prepare to decode: advance the buffer so the video thread knows. */
763 struct fbuf_t *tmp = v->dec_in_cur; /* store current pointer */
764 ast_mutex_lock(&env->dec_lock);
765 if (++v->dec_in_cur == &v->dec_in[N_DEC_IN]) /* advance to next, circular */
766 v->dec_in_cur = &v->dec_in[0];
767 if (v->dec_in_dpy == NULL) { /* were not displaying anything, so set it */
768 v->dec_in_dpy = tmp;
769 } else if (v->dec_in_dpy == v->dec_in_cur) { /* current slot is busy */
770 v->dec_in_cur = NULL;
771 }
772 ast_mutex_unlock(&env->dec_lock);
773 }
774 return 0;
775}
776
777
778/*! \brief refreshes the buffers of all the device by calling the
779 * grabber_read on each device in the device table.
780 * it encodes the primary source buffer, if the picture in picture mode is
781 * enabled it encodes (in the buffer to split) the secondary source buffer too.
782 * The encoded buffer is splitted to build the local and the remote view.
783 * Return a list of ast_frame representing the video fragments.
784 * The head pointer is returned by the function, the tail pointer
785 * is returned as an argument.
786 *
787 * \param env = video environment descriptor
788 * \param tail = tail ponter (practically a return value)
789 */
790static struct ast_frame *get_video_frames(struct video_desc *env, struct ast_frame **tail)
791{
792 struct video_out_desc *v = &env->out;
793 struct ast_frame *dummy;
794 struct fbuf_t *loc_src_primary = NULL, *p_read;
795 int i;
796 /* if no device was found in the config file */
797 if (!env->out.device_num)
798 return NULL;
799 /* every time this function is called we refresh the buffers of every device,
800 updating the private device buffer in the device table */
801 for (i = 0; i < env->out.device_num; i++) {
802 p_read = grabber_read(&env->out.devices[i], env->out.fps);
803 /* it is used only if different from NULL, we maintain last good buffer otherwise */
804 if (p_read)
805 env->out.devices[i].dev_buf = p_read;
806 }
807 /* select the primary device buffer as the one to encode */
808 loc_src_primary = env->out.devices[env->out.device_primary].dev_buf;
809 /* loc_src_primary can be NULL if the device has been turned off during
810 execution of it is read too early */
811 if (loc_src_primary) {
812 /* Scale the video for the encoder, then use it for local rendering
813 so we will see the same as the remote party */
814 my_scale(loc_src_primary, NULL, &env->enc_in, NULL);
815 }
816 if (env->out.picture_in_picture) { /* the picture in picture mode is enabled */
817 struct fbuf_t *loc_src_secondary;
818 /* reads from the secondary source */
819 loc_src_secondary = env->out.devices[env->out.device_secondary].dev_buf;
820 if (loc_src_secondary) {
821 env->enc_in.win_x = env->out.pip_x;
822 env->enc_in.win_y = env->out.pip_y;
823 env->enc_in.win_w = env->enc_in.w/3;
824 env->enc_in.win_h = env->enc_in.h/3;
825 /* scales to the correct geometry and inserts in
826 the enc_in buffer the picture in picture */
827 my_scale(loc_src_secondary, NULL, &env->enc_in, NULL);
828 /* returns to normal parameters (not picture in picture) */
829 env->enc_in.win_x = 0;
830 env->enc_in.win_y = 0;
831 env->enc_in.win_w = 0;
832 env->enc_in.win_h = 0;
833 }
834 else {
835 /* loc_src_secondary can be NULL if the device has been turned off during
836 execution of it is read too early */
837 env->out.picture_in_picture = 0; /* disable picture in picture */
838 }
839 }
840 show_frame(env, WIN_LOCAL); /* local rendering */
841 for (i = 0; i < env->out.device_num; i++)
842 show_frame(env, i+WIN_SRC1); /* rendering of every source device in thumbnails */
843 if (tail == NULL)
844 tail = &dummy;
845 *tail = NULL;
846 /* if no reason for encoding, do not encode */
847 if (!env->owner || !loc_src_primary || !v->sendvideo)
848 return NULL;
849 if (v->enc_out.data == NULL) {
850 static volatile int a = 0;
851 if (a++ < 2)
852 ast_log(LOG_WARNING, "fail, no encoder output buffer\n");
853 return NULL;
854 }
855 v->enc->enc_run(v);
856 return v->enc->enc_encap(&v->enc_out, v->mtu, tail);
857}
858
859/*
860 * Helper thread to periodically poll the video sources and enqueue the
861 * generated frames directed to the remote party to the channel's queue.
862 * Using a separate thread also helps because the encoding can be
863 * computationally expensive so we don't want to starve the main thread.
864 */
865static void *video_thread(void *arg)
866{
867 struct video_desc *env = arg;
868 int count = 0;
869 char save_display[128] = "";
870 int i; /* integer variable used as iterator */
871
872 /* if sdl_videodriver is set, override the environment. Also,
873 * if it contains 'console' override DISPLAY around the call to SDL_Init
874 * so we use the console as opposed to the x11 version of aalib
875 */
876 if (!ast_strlen_zero(env->sdl_videodriver)) { /* override */
877 const char *s = getenv("DISPLAY");
878 setenv("SDL_VIDEODRIVER", env->sdl_videodriver, 1);
879 if (s && !strcasecmp(env->sdl_videodriver, "aalib-console")) {
880 ast_copy_string(save_display, s, sizeof(save_display));
881 unsetenv("DISPLAY");
882 }
883 }
884 sdl_setup(env);
885 if (!ast_strlen_zero(save_display)) {
886 setenv("DISPLAY", save_display, 1);
887 }
888
889 ast_mutex_init(&env->dec_lock); /* used to sync decoder and renderer */
890
891 if (grabber_open(&env->out)) {
892 ast_log(LOG_WARNING, "cannot open local video source\n");
893 }
894
895 if (env->out.device_num) {
896 env->out.devices[env->out.device_primary].status_index |= IS_PRIMARY | IS_SECONDARY;
897 }
898
899 /* even if no device is connected, we must call video_out_init,
900 * as some of the data structures it initializes are
901 * used in get_video_frames()
902 */
903 video_out_init(env);
904
905 /* Writes intial status of the sources. */
906 if (env->gui) {
907 for (i = 0; i < env->out.device_num; i++) {
908 print_message(env->gui->thumb_bd_array[i].board,
909 src_msgs[env->out.devices[i].status_index]);
910 }
911 }
912
913 for (;;) {
914 struct timespec t = { 0, 50000000 }; /* XXX 20 times/sec */
915 struct ast_frame *p, *f;
916 struct ast_channel *chan;
917 int fd;
918 char *caption = NULL, buf[160];
919
920 /* determine if video format changed */
921 if (count++ % 10 == 0) {
922 if (env->out.sendvideo && env->out.devices) {
923 snprintf(buf, sizeof(buf), "%s %s %dx%d @@ %dfps %dkbps",
924 env->out.devices[env->out.device_primary].name, env->codec_name,
925 env->enc_in.w, env->enc_in.h,
926 env->out.fps, env->out.bitrate / 1000);
927 } else {
928 sprintf(buf, "hold");
929 }
930 caption = buf;
931 }
932
933 /* manage keypad events */
934 /* XXX here we should always check for events,
935 * otherwise the drag will not work */
936 if (env->gui)
937 eventhandler(env, caption);
938
939 /* sleep for a while */
940 nanosleep(&t, NULL);
941
942 if (env->in) {
943 struct video_dec_desc *v = env->in;
944
945 /*
946 * While there is something to display, call the decoder and free
947 * the buffer, possibly enabling the receiver to store new data.
948 */
949 while (v->dec_in_dpy) {
950 struct fbuf_t *tmp = v->dec_in_dpy; /* store current pointer */
951
952 /* decode the frame, but show it only if not frozen */
953 if (v->d_callbacks->dec_run(v, tmp) && !env->frame_freeze)
955 tmp->used = 0; /* mark buffer as free */
956 tmp->ebit = 0;
957 ast_mutex_lock(&env->dec_lock);
958 if (++v->dec_in_dpy == &v->dec_in[N_DEC_IN]) /* advance to next, circular */
959 v->dec_in_dpy = &v->dec_in[0];
960
961 if (v->dec_in_cur == NULL) /* receiver was idle, enable it... */
962 v->dec_in_cur = tmp; /* using the slot just freed */
963 else if (v->dec_in_dpy == v->dec_in_cur) /* this was the last slot */
964 v->dec_in_dpy = NULL; /* nothing more to display */
965 ast_mutex_unlock(&env->dec_lock);
966 }
967 }
968
969 if (env->shutdown)
970 break;
971 f = get_video_frames(env, &p); /* read and display */
972 if (!f)
973 continue;
974 chan = env->owner;
975 if (chan == NULL) {
976 /* drop the chain of frames, nobody uses them */
977 while (f) {
978 struct ast_frame *g = AST_LIST_NEXT(f, frame_list);
979 ast_frfree(f);
980 f = g;
981 }
982 continue;
983 }
984 ast_channel_lock(chan);
985
986 /* AST_LIST_INSERT_TAIL is only good for one frame, cannot use here */
987 if (ast_channel_readq(chan).first == NULL) {
988 ast_channel_readq(chan).first = f;
989 } else {
991 }
992 ast_channel_readq(chan).last = p;
993 /*
994 * more or less same as ast_queue_frame, but extra
995 * write on the alertpipe to signal frames.
996 */
997 if (ast_channel_alertable(chan)) {
998 for (p = f; p; p = AST_LIST_NEXT(p, frame_list)) {
999 if (ast_channel_alert(chan)) {
1000 ast_log(LOG_WARNING, "Unable to write to alert pipe on %s, frametype/subclass %d/%d: %s!\n",
1001 ast_channel_name(chan), f->frametype, f->subclass, strerror(errno));
1002 }
1003 }
1004 ast_channel_unlock(chan);
1005 }
1006 /* thread terminating, here could call the uninit */
1007 /* uninitialize the local and remote video environments */
1008 env->in = dec_uninit(env->in);
1009 video_out_uninit(env);
1010
1011 if (env->gui)
1012 env->gui = cleanup_sdl(env->gui, env->out.device_num);
1013 ast_mutex_destroy(&env->dec_lock);
1014 env->shutdown = 0;
1015 return NULL;
1016}
1017
1018static void copy_geometry(struct fbuf_t *src, struct fbuf_t *dst)
1019{
1020 if (dst->w == 0)
1021 dst->w = src->w;
1022 if (dst->h == 0)
1023 dst->h = src->h;
1024}
1025
1026/*! initialize the video environment.
1027 * Apart from the formats (constant) used by sdl and the codec,
1028 * we use enc_in as the basic geometry.
1029 */
1030static void init_env(struct video_desc *env)
1031{
1032 struct fbuf_t *c = &(env->out.loc_src_geometry); /* local source */
1033 struct fbuf_t *ei = &(env->enc_in); /* encoder input */
1034 struct fbuf_t *ld = &(env->loc_dpy); /* local display */
1035 struct fbuf_t *rd = &(env->rem_dpy); /* remote display */
1036 int i; /* integer working as iterator */
1037
1038 c->pix_fmt = PIX_FMT_YUV420P; /* default - camera format */
1039 ei->pix_fmt = PIX_FMT_YUV420P; /* encoder input */
1040 if (ei->w == 0 || ei->h == 0) {
1041 ei->w = 352;
1042 ei->h = 288;
1043 }
1044 ld->pix_fmt = rd->pix_fmt = PIX_FMT_YUV420P; /* sdl format */
1045 /* inherit defaults */
1046 copy_geometry(ei, c); /* camera inherits from encoder input */
1047 copy_geometry(ei, rd); /* remote display inherits from encoder input */
1048 copy_geometry(rd, ld); /* local display inherits from remote display */
1049
1050 /* fix the size of buffers for small windows */
1051 for (i = 0; i < env->out.device_num; i++) {
1052 env->src_dpy[i].pix_fmt = PIX_FMT_YUV420P;
1053 env->src_dpy[i].w = SRC_WIN_W;
1054 env->src_dpy[i].h = SRC_WIN_H;
1055 }
1056 /* now we set the default coordinates for the picture in picture
1057 frames inside the env_in buffers, those can be changed by dragging the
1058 picture in picture with left click */
1059 env->out.pip_x = ei->w - ei->w/3;
1060 env->out.pip_y = ei->h - ei->h/3;
1061}
1062
1063/*!
1064 * The first call to the video code, called by oss_new() or similar.
1065 * Here we initialize the various components we use, namely SDL for display,
1066 * ffmpeg for encoding/decoding, and a local video source.
1067 * We do our best to progress even if some of the components are not
1068 * available.
1069 */
1070void console_video_start(struct video_desc *env, struct ast_channel *owner)
1071{
1072 ast_log(LOG_WARNING, "env %p chan %p\n", env, owner);
1073 if (env == NULL) /* video not initialized */
1074 return;
1075 env->owner = owner; /* work even if no owner is specified */
1076 if (env->vthread)
1077 return; /* already initialized, nothing to do */
1078 init_env(env);
1079 env->out.enc = map_config_video_format(env->codec_name);
1080
1081 ast_log(LOG_WARNING, "start video out %s %dx%d\n",
1082 env->codec_name, env->enc_in.w, env->enc_in.h);
1083 /*
1084 * Register all codecs supported by the ffmpeg library.
1085 * We only need to do it once, but probably doesn't
1086 * harm to do it multiple times.
1087 */
1088 avcodec_init();
1089 avcodec_register_all();
1090 av_log_set_level(AV_LOG_ERROR); /* only report errors */
1091
1092 if (env->out.fps == 0) {
1093 env->out.fps = 15;
1094 ast_log(LOG_WARNING, "fps unset, forcing to %d\n", env->out.fps);
1095 }
1096 if (env->out.bitrate == 0) {
1097 env->out.bitrate = 65000;
1098 ast_log(LOG_WARNING, "bitrate unset, forcing to %d\n", env->out.bitrate);
1099 }
1100 /* create the thread as detached so memory is freed on termination */
1102 NULL, video_thread, env);
1103}
1104
1105/*
1106 * Parse a geometry string, accepting also common names for the formats.
1107 * Trick: if we have a leading > or < and a numeric geometry,
1108 * return the larger or smaller one.
1109 * E.g. <352x288 gives the smaller one, 320x240
1110 */
1111static int video_geom(struct fbuf_t *b, const char *s)
1112{
1113 int w = 0, h = 0;
1114
1115 static struct {
1116 const char *s; int w; int h;
1117 } *fp, formats[] = {
1118 {"16cif", 1408, 1152 },
1119 {"xga", 1024, 768 },
1120 {"4cif", 704, 576 },
1121 {"vga", 640, 480 },
1122 {"cif", 352, 288 },
1123 {"qvga", 320, 240 },
1124 {"qcif", 176, 144 },
1125 {"sqcif", 128, 96 },
1126 {NULL, 0, 0 },
1127 };
1128 if (*s == '<' || *s == '>')
1129 sscanf(s+1,"%dx%d", &w, &h);
1130 for (fp = formats; fp->s; fp++) {
1131 if (*s == '>') { /* look for a larger one */
1132 if (fp->w <= w) {
1133 if (fp > formats)
1134 fp--; /* back one step if possible */
1135 break;
1136 }
1137 } else if (*s == '<') { /* look for a smaller one */
1138 if (fp->w < w)
1139 break;
1140 } else if (!strcasecmp(s, fp->s)) { /* look for a string */
1141 break;
1142 }
1143 }
1144 if (*s == '<' && fp->s == NULL) /* smallest */
1145 fp--;
1146 if (fp->s) {
1147 b->w = fp->w;
1148 b->h = fp->h;
1149 } else if (sscanf(s, "%dx%d", &b->w, &b->h) != 2) {
1150 ast_log(LOG_WARNING, "Invalid video_size %s, using 352x288\n", s);
1151 b->w = 352;
1152 b->h = 288;
1153 }
1154 return 0;
1155}
1156
1157
1158/*! \brief add an entry to the video_device table,
1159 * ignoring duplicate names.
1160 * The table is a static array of 9 elements.
1161 * The last_frame field of each entry of the table is initialized to
1162 * the current time (we need a value inside this field, on stop of the
1163 * GUI the last_frame value is not changed, to avoid checking if it is 0 we
1164 * set the initial value on current time) XXX
1165 *
1166 * PARAMETERS:
1167 * \param devices_p = pointer to the table of devices
1168 * \param device_num_p = pointer to the number of devices
1169 * \param s = name of the new device to insert
1170 *
1171 * returns 0 on success, 1 on error
1172 */
1173static int device_table_fill(struct video_device *devices, int *device_num_p, const char *s)
1174{
1175 int i;
1176 struct video_device *p;
1177
1178 /* with the current implementation, we support a maximum of 9 devices.*/
1179 if (*device_num_p >= 9)
1180 return 0; /* more devices will be ignored */
1181 /* ignore duplicate names */
1182 for (i = 0; i < *device_num_p; i++) {
1183 if (!strcmp(devices[i].name, s))
1184 return 0;
1185 }
1186 /* inserts the new video device */
1187 p = &devices[*device_num_p];
1188 /* XXX the string is allocated but NEVER deallocated,
1189 the good time to do that is when the module is unloaded, now we skip the problem */
1190 p->name = ast_strdup(s); /* copy the name */
1191 /* other fields initially NULL */
1192 p->grabber = NULL;
1193 p->grabber_data = NULL;
1194 p->dev_buf = NULL;
1195 p->last_frame = ast_tvnow();
1196 p->status_index = 0;
1197 (*device_num_p)++; /* one device added */
1198 return 0;
1199}
1200
1201/* extend ast_cli with video commands. Called by console_video_config */
1202int console_video_cli(struct video_desc *env, const char *var, int fd)
1203{
1204 if (env == NULL)
1205 return 1; /* unrecognised */
1206
1207 if (!strcasecmp(var, "videodevice")) {
1208 ast_cli(fd, "videodevice is [%s]\n", env->out.devices[env->out.device_primary].name);
1209 } else if (!strcasecmp(var, "videocodec")) {
1210 ast_cli(fd, "videocodec is [%s]\n", env->codec_name);
1211 } else if (!strcasecmp(var, "sendvideo")) {
1212 ast_cli(fd, "sendvideo is [%s]\n", env->out.sendvideo ? "on" : "off");
1213 } else if (!strcasecmp(var, "video_size")) {
1214 int in_w = 0, in_h = 0;
1215 if (env->in) {
1216 in_w = env->in->dec_out.w;
1217 in_h = env->in->dec_out.h;
1218 }
1219 ast_cli(fd, "sizes: video %dx%d camera %dx%d local %dx%d remote %dx%d in %dx%d\n",
1220 env->enc_in.w, env->enc_in.h,
1221 env->out.loc_src_geometry.w, env->out.loc_src_geometry.h,
1222 env->loc_dpy.w, env->loc_dpy.h,
1223 env->rem_dpy.w, env->rem_dpy.h,
1224 in_w, in_h);
1225 } else if (!strcasecmp(var, "bitrate")) {
1226 ast_cli(fd, "bitrate is [%d]\n", env->out.bitrate);
1227 } else if (!strcasecmp(var, "qmin")) {
1228 ast_cli(fd, "qmin is [%d]\n", env->out.qmin);
1229 } else if (!strcasecmp(var, "fps")) {
1230 ast_cli(fd, "fps is [%d]\n", env->out.fps);
1231 } else if (!strcasecmp(var, "startgui")) {
1232 env->stayopen = 1;
1234 } else if (!strcasecmp(var, "stopgui") && env->stayopen != 0) {
1235 env->stayopen = 0;
1236 if (env->gui && env->owner)
1237 ast_cli_command(-1, "console hangup");
1238 else /* not in a call */
1240 } else {
1241 return 1; /* unrecognised */
1242 }
1243 return 0; /* recognised */
1244}
1245
1246/*! parse config command for video support. */
1247int console_video_config(struct video_desc **penv,
1248 const char *var, const char *val)
1249{
1250 struct video_desc *env;
1251
1252 if (penv == NULL) {
1253 ast_log(LOG_WARNING, "bad argument penv=NULL\n");
1254 return 1; /* error */
1255 }
1256 /* allocate the video descriptor first time we get here */
1257 env = *penv;
1258 if (env == NULL) {
1259 env = *penv = ast_calloc(1, sizeof(struct video_desc));
1260 if (env == NULL) {
1261 ast_log(LOG_WARNING, "fail to allocate video_desc\n");
1262 return 1; /* error */
1263
1264 }
1265 /* set default values - 0's are already there */
1266 env->out.device_primary = 0;
1267 env->out.device_secondary = 0;
1268 env->out.fps = 5;
1269 env->out.bitrate = 65000;
1270 env->out.sendvideo = 1;
1271 env->out.qmin = 3;
1272 env->out.device_num = 0;
1273 }
1274 CV_START(var, val);
1275 CV_F("videodevice", device_table_fill(env->out.devices, &env->out.device_num, val));
1276 CV_BOOL("sendvideo", env->out.sendvideo);
1277 CV_F("video_size", video_geom(&env->enc_in, val));
1278 CV_F("camera_size", video_geom(&env->out.loc_src_geometry, val));
1279 CV_F("local_size", video_geom(&env->loc_dpy, val));
1280 CV_F("remote_size", video_geom(&env->rem_dpy, val));
1281 CV_STR("keypad", env->keypad_file);
1282 CV_F("region", keypad_cfg_read(env->gui, val));
1283 CV_UINT("startgui", env->stayopen); /* enable gui at startup */
1284 CV_STR("keypad_font", env->keypad_font);
1285 CV_STR("sdl_videodriver", env->sdl_videodriver);
1286 CV_UINT("fps", env->out.fps);
1287 CV_UINT("bitrate", env->out.bitrate);
1288 CV_UINT("qmin", env->out.qmin);
1289 CV_STR("videocodec", env->codec_name);
1290 return 1; /* nothing found */
1291
1292 CV_END; /* the 'nothing found' case */
1293 return 0; /* found something */
1294}
1295
1296#endif /* video support */
struct sla_ringing_trunk * first
Definition: app_sla.c:332
#define var
Definition: ast_expr2f.c:605
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_log
Definition: astobj2.c:42
static int tmp()
Definition: bt_open.c:389
static void dummy(char *unused,...)
Definition: chan_unistim.c:220
General Asterisk PBX channel definitions.
const char * ast_channel_name(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2968
struct ast_readq_list * ast_channel_readq(struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2969
Standard Command Line Interface.
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
ast_cli_command
calling arguments for new-style handlers.
Definition: cli.h:151
static void sdl_setup(struct video_desc *env)
Definition: console_gui.c:99
static void eventhandler(struct video_desc *env, const char *caption)
Definition: console_gui.c:101
static struct gui_info * cleanup_sdl(struct gui_info *g, int n)
Definition: console_gui.c:100
static int keypad_cfg_read(struct gui_info *gui, const char *val)
Definition: console_gui.c:102
static void show_frame(struct video_desc *env, int out)
Definition: console_gui.c:98
@ WIN_SRC1
Definition: console_gui.c:93
@ WIN_REMOTE
Definition: console_gui.c:93
@ WIN_LOCAL
Definition: console_gui.c:93
void console_video_start(struct video_desc *env, struct ast_channel *owner)
void console_video_uninit(struct video_desc *env)
int console_write_video(struct ast_channel *chan, struct ast_frame *f)
int console_video_cli(struct video_desc *env, const char *var, int fd)
int console_video_formats
int get_gui_startup(struct video_desc *env)
int console_video_config(struct video_desc **penv, const char *var, const char *val)
struct video_desc * get_video_desc(struct ast_channel *c)
struct grab_desc * console_grabbers[]
void fbuf_free(struct fbuf_t *)
#define SRC_WIN_W
Definition: console_video.h:46
#define SRC_WIN_H
Definition: console_video.h:47
#define MAX_VIDEO_SOURCES
Definition: console_video.h:51
int print_message(struct board *b, const char *s)
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
Generic File Format Support. Should be included by clients of the file handling routines....
static const char name[]
Definition: format_mp3.c:68
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int unsetenv(const char *name)
int setenv(const char *name, const char *value, int overwrite)
#define CV_START(__in_var, __in_val)
the macro to open a block for variable parsing
#define CV_END
close a variable parsing block
#define CV_STR(__x, __dst)
#define CV_F(__pattern, __body)
call a generic function if the name matches.
#define CV_BOOL(__x, __dst)
helper macros to assign the value to a BOOL, UINT, static string and dynamic string
#define CV_UINT(__x, __dst)
#define ast_frfree(fr)
#define LOG_ERROR
#define LOG_NOTICE
#define LOG_WARNING
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439
#define ast_mutex_init(pmutex)
Definition: lock.h:186
#define ast_mutex_unlock(a)
Definition: lock.h:190
#define ast_mutex_destroy(a)
Definition: lock.h:188
#define ast_mutex_lock(a)
Definition: lock.h:189
int errno
Definition: cdr/env.py:1
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Main Channel structure associated with a channel.
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
union ast_frame::@226 data
enum ast_frame_type frametype
struct ast_frame * next
struct ast_frame::@227 frame_list
const char * src
Structure for mutex and tracking information.
Definition: lock.h:135
struct ast_frame * first
Definition: channel.h:917
struct ast_frame * last
Definition: channel.h:917
int size
Definition: console_video.h:62
int used
Definition: console_video.h:63
int pix_fmt
Definition: console_video.h:69
uint8_t * data
Definition: console_video.h:60
int ebit
Definition: console_video.h:64
Definition: file.c:69
void *(* open)(const char *name, struct fbuf_t *geom, int fps)
Definition: console_video.h:82
Definition: ast_expr2.c:325
decoder_decap_f dec_decap
Definition: vcodecs.c:66
decoder_decode_f dec_run
Definition: vcodecs.c:67
struct fbuf_t * dec_in_cur
Definition: vcodecs.c:93
struct video_codec_desc * d_callbacks
Definition: vcodecs.c:85
uint16_t next_seq
Definition: vcodecs.c:90
struct fbuf_t * dec_in_dpy
Definition: vcodecs.c:94
struct fbuf_t dec_in[N_DEC_IN]
Definition: vcodecs.c:95
static struct test_val b
static struct test_val a
static struct test_val c
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159
FILE * out
Definition: utils/frame.c:33
FILE * in
Definition: utils/frame.c:33
#define ast_pthread_create_detached_background(a, b, c, d)
Definition: utils.h:597
static enum CodecID map_video_format(uint32_t ast_format, int rw)
map an asterisk format into an ffmpeg one
Definition: vcodecs.c:1133
static struct video_dec_desc * dec_init(uint32_t the_ast_format)
Definition: vcodecs.c:1204
static const struct video_codec_desc * supported_codecs[]
Definition: vcodecs.c:1145
#define N_DEC_IN
Definition: vcodecs.c:92
static struct video_dec_desc * dec_uninit(struct video_dec_desc *v)
uninitialize the descriptor for remote video stream
Definition: vcodecs.c:1172