[asterisk-commits] rizzo: branch rizzo/video_console r125701 - /team/rizzo/video_console/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jun 26 23:20:41 CDT 2008
Author: rizzo
Date: Thu Jun 26 23:20:41 2008
New Revision: 125701
URL: http://svn.digium.com/view/asterisk?view=rev&rev=125701
Log:
change comments to C style, plus other minor cleanup of the formatting.
Modified:
team/rizzo/video_console/channels/console_gui.c
team/rizzo/video_console/channels/console_video.c
Modified: team/rizzo/video_console/channels/console_gui.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/video_console/channels/console_gui.c?view=diff&rev=125701&r1=125700&r2=125701
==============================================================================
--- team/rizzo/video_console/channels/console_gui.c (original)
+++ team/rizzo/video_console/channels/console_gui.c Thu Jun 26 23:20:41 2008
@@ -10,7 +10,7 @@
For the GUI we use SDL to create a large surface (gui->screen)
containing four sections: remote video on the left, local video
on the right, the keypad with all controls and text windows
-in the center, and above these three sections, the source windows section
+in the center, and above these three sections, the source device thumbnails section
(including the relative message boards).
The fourth section may even not be displayed if no devices are specified
in the configuration file oss.conf
@@ -192,15 +192,21 @@
/* messages to be displayed in the sources message boards
* below the source windows
*/
+
+/* costants defined to describe status of devices */
+#define IS_PRIMARY 1
+#define IS_SECONDARY 2
+#define IS_ON 4
+
char* src_msgs[] = {
- " OFF",
- "1 OFF",
- " 2 OFF",
+ " OFF",
+ "1 OFF",
+ " 2 OFF",
"1+2 OFF",
- " ON ",
- "1 ON ",
- " 2 ON ",
- "1+2 ON ",
+ " ON",
+ "1 ON",
+ " 2 ON",
+ "1+2 ON",
};
/*
* Display video frames (from local or remote stream) using the SDL library.
@@ -240,9 +246,9 @@
b_out = &env->rem_dpy;
p_in = (AVPicture *)env->in->d_frame;
} else {
- int i = out-3;
+ int i = out-WIN_SRC1;
b_in = env->out.devices[i].dev_buf;
- if(b_in == NULL)
+ if (b_in == NULL)
return;
p_in = NULL;
b_out = &env->src_dpy[i];
@@ -301,9 +307,9 @@
/* video source switching key(s) */
KEY_PIP = 230,
/*indexes between 231 and 239 have been reserved for the "keys"
- associated with the little windows below the keypad, clicking on these pictures
+ associated with the device thumbnails, clicking on these pictures
will change the source device for primary or secondary (PiP) video output*/
- KEY_SRCS_WIN = 231, //till 239
+ KEY_SRCS_WIN = 231, /* till 239 */
/* areas outside the keypad - simulated */
KEY_OUT_OF_KEYPAD = 241,
KEY_REM_DPY = 242,
@@ -336,22 +342,17 @@
/* function used to toggle on/off the status of some variables */
static char *keypad_toggle(struct video_desc *env, int index)
{
- static int audio_state = 1; // variable used to mute or unmute audio
ast_log(LOG_WARNING, "keypad_toggle(%i) called\n", index);
switch (index) {
- case KEY_SENDVIDEO: // send or do not send video
+ case KEY_SENDVIDEO: /* send or do not send video */
env->out.sendvideo = !env->out.sendvideo;
break;
- case KEY_PIP: // enable or disable Picture in Picture
+ case KEY_PIP: /* enable or disable Picture in Picture */
env->out.picture_in_picture = !env->out.picture_in_picture;
break;
- case KEY_MUTE: // send or do not send audio
- if (audio_state)
- ast_cli_command(env->gui->outfd, "console mute");
- else
- ast_cli_command(env->gui->outfd, "console unmute");
- audio_state = !audio_state;
+ case KEY_MUTE: /* send or do not send audio */
+ ast_cli_command(env->gui->outfd, "console mute toggle");
break;
#ifdef notyet
case KEY_AUTOANSWER: {
@@ -437,78 +438,67 @@
* and switching the correct fields of env->out.
* grabbers are always open and saved in the device table.
* The secondary or the primary device can be changed,
- * concording with the parameter "secondary":
- * the secondary device is changed if secondary = 1;
- * the primary device is changed if secondary = 0;
+ * according to the "button" parameter:
+ * the primary device is changed if button = SDL_BUTTON_LEFT;
+ * the secondary device is changed if button = not SDL_BUTTON_LEFT;
*
* the correct message boards of the sources are also updated
* with the new status
*
* \param env = pointer to the video environment descriptor
* \param index = index of the device the caller wants to use are primary or secondary device
- * \param secondary = integer value, working as described above
+ * \param button = button clicked on the mouse
*
* returns 0 on success,
* returns 1 on error
*/
-static int switch_video_out(struct video_desc *env, int index, int secondary)
-{
- int* p = &env->out.device_primary; //pointer to the index of the primary device
- p += secondary; //pointer to the index to change (primary or secondary)
- //controls if the device is already selected
- if(index == *p) {
+static int switch_video_out(struct video_desc *env, int index, Uint8 button)
+{
+ int *p = &env->out.device_secondary; /* pointer to the index of the secondary device */
+ /* the default switching is of the secondary device */
+ /* device not found */
+ if (index >= env->out.device_num) {
+ ast_log(LOG_WARNING, "no devices\n");
+ return 1;
+ }
+ /* we have to switch the primary source if the left button is clicked */
+ if (button == SDL_BUTTON_LEFT)
+ p--;
+ /* p becomes a pointer to the index to change (primary or secondary) */
+ /* controls if the device is already selected */
+ if (index == *p) {
ast_log(LOG_WARNING, "device %s already selected\n", env->out.devices[index].name);
return 0;
}
ast_log(LOG_WARNING, "switching to %s...\n", env->out.devices[index].name);
- // already open
- if(env->out.devices[index].grabber) {
+ /* already open */
+ if (env->out.devices[index].grabber) {
/* we also have to update the messages in the source
message boards below the source windows */
- // first we update the board of the previous source
- env->out.devices[*p].status_index -= 1+secondary;
+ /* first we update the board of the previous source */
+ if (p == &env->out.device_primary)
+ env->out.devices[*p].status_index &= ~IS_PRIMARY;
+ else
+ env->out.devices[*p].status_index &= ~IS_SECONDARY;
reset_board(env->gui->bd_srcs_msg[*p]);
print_message(env->gui->bd_srcs_msg[*p],
src_msgs[env->out.devices[*p].status_index]);
- // update the index used as primary or secondary
+ /* update the index used as primary or secondary */
*p = index;
ast_log(LOG_WARNING, "done\n");
- // then we update the board of the new primary or secondary source
- env->out.devices[index].status_index += 1+secondary;
+ /* then we update the board of the new primary or secondary source */
+ if (p == &env->out.device_primary)
+ env->out.devices[*p].status_index |= IS_PRIMARY;
+ else
+ env->out.devices[*p].status_index |= IS_SECONDARY;
reset_board(env->gui->bd_srcs_msg[index]);
print_message(env->gui->bd_srcs_msg[index],
src_msgs[env->out.devices[index].status_index]);
return 0;
}
- // device is off, just do nothing
+ /* device is off, just do nothing */
ast_log(LOG_WARNING, "device is down\n");
return 1;
-}
-
-/*! \brief Calls switch_video_out() with the correct parameters
- * This functions controls if the device is in the table,
- * and calls the switch_video_out function with the correct parameters depending on the
- * button of the mouse that was clicked
- *
- * \param index = index of the device the caller wants to use
- * \param env = pointer to the video environment descriptor
- * \param button = button clicked on the mouse
- *
- * returns 0 on success,
- * returns 1 on error
-*/
-static int switch_video_caller(int index, struct video_desc *env, Uint8 button) {
- int secondary = 1; //default switching of the secondary source
- //device not found
- if(index >= env->out.device_num) {
- ast_log(LOG_WARNING, "no devices\n");
- return 1;
- }
- // we have to switch the primary source if the left button is clicked
- if(button == SDL_BUTTON_LEFT)
- secondary = 0;
- //to the switching function
- return switch_video_out(env, index, secondary);
}
/*! \brief tries to switch the state of a device from on to off or off to on
@@ -523,43 +513,45 @@
* - 2 on success in switching from on to off
*/
static int turn_on_off(int index, struct video_desc *env){
- if (!env->out.devices[index].grabber) { // device off
- void *g_data; // container for the result of the open function on the grabber
- struct grab_desc *g; // sequentially we try all the defined types of grabber
- int i; // integer variable used as iterator
+ struct video_device *p = &env->out.devices[index];
+ if (!p->grabber) { /* device off */
+ void *g_data; /* container for the result of the open function on the grabber */
+ struct grab_desc *g; /* sequentially we try all the defined types of grabber */
+ int i; /* integer variable used as iterator */
for (i = 0; (g = console_grabbers[i]); i++) {
- if(g == NULL)
+ if (g == NULL)
break;
- // the grabber is opened and the informations saved in the device table
- g_data = g->open(env->out.devices[index].name,
- &env->out.loc_src_geometry, env->out.fps);
+ /* the grabber is opened and the informations saved in the device table */
+ g_data = g->open(p->name, &env->out.loc_src_geometry, env->out.fps);
if (!g_data)
continue;
- env->out.devices[index].grabber = g;
- env->out.devices[index].grabber_data = g_data;
- // update the status of the source
- env->out.devices[index].status_index += 4;
- // print the new message in the message board
+ p->grabber = g;
+ p->grabber_data = g_data;
+ /* update the status of the source */
+ p->status_index |= IS_ON;
+ /* print the new message in the message board */
reset_board(env->gui->bd_srcs_msg[index]);
print_message(env->gui->bd_srcs_msg[index],
- src_msgs[env->out.devices[index].status_index]);
- return 1; // open succeded
- }
- return 0; // falure
+ src_msgs[p->status_index]);
+ return 1; /* open succeded */
+ }
+ return 0; /* falure */
} else {
- // the grabber must be closed
- env->out.devices[index].grabber_data =
- env->out.devices[index].grabber->close(env->out.devices[index].grabber_data);
- env->out.devices[index].grabber = NULL;
- fbuf_free(env->out.devices[index].dev_buf);
- env->out.devices[index].dev_buf = NULL;
- // update the status of the source
- env->out.devices[index].status_index -= 4;
- // print the new message in the message board
+ /* the grabber must be closed */
+ p->grabber_data =
+ p->grabber->close(p->grabber_data);
+ p->grabber = NULL;
+ if (p->dev_buf) { /* free the buffer if necessary */
+ fbuf_free(p->dev_buf);
+ p->dev_buf = NULL;
+ }
+ /* update the status of the source */
+ p->status_index &= ~IS_ON;
+ /* print the new message in the message board */
reset_board(env->gui->bd_srcs_msg[index]);
print_message(env->gui->bd_srcs_msg[index],
- src_msgs[env->out.devices[index].status_index]);
- return 2; // closed
+ src_msgs[p->status_index]);
+ return 2; /* closed */
}
}
@@ -574,14 +566,14 @@
uint8_t index = KEY_OUT_OF_KEYPAD; /* the key or region of the display we clicked on */
struct gui_info *gui = env->gui;
- int i; // integer variable used as iterator
-
- int x; // integer variable usable as a container
+ int i; /* integer variable used as iterator */
+
+ int x; /* integer variable usable as a container */
- // cumulative total width of additional source windows
+ /* total width of source device thumbnails */
int src_wins_tot_w = env->out.device_num*(SRC_WIN_W+BORDER)+BORDER;
- //from middle keypad to left border
+ /* x coordinate of the center of the keypad */
int x0 = MAX(env->rem_dpy.w+gui->keypad->w/2+2*BORDER, src_wins_tot_w/2);
#if 0
@@ -595,29 +587,29 @@
if (button.y >= (env->out.devices ? SRC_WIN_H+2*BORDER+SRC_MSG_BD_H : 0)) {
/* if control reaches this point this means that the clicked point is
below the row of the additional sources windows*/
- // adjust the y coordinate as if additional devices windows were not present
+ /* adjust the y coordinate as if additional devices windows were not present */
button.y -= (env->out.devices ? SRC_WIN_H+2*BORDER+SRC_MSG_BD_H : 0);
if (button.y < BORDER)
index = KEY_OUT_OF_KEYPAD;
else if (button.y >= MAX(MAX(env->rem_dpy.h, env->loc_dpy.h), gui->keypad->h))
index = KEY_OUT_OF_KEYPAD;
- else if (button.x < x0-gui->keypad->w/2-BORDER-env->rem_dpy.w)
+ else if (button.x < x0 - gui->keypad->w/2 - BORDER - env->rem_dpy.w)
index = KEY_OUT_OF_KEYPAD;
- else if (button.x < x0-gui->keypad->w/2-BORDER)
+ else if (button.x < x0 - gui->keypad->w/2 - BORDER)
index = KEY_REM_DPY;
- else if (button.x < x0-gui->keypad->w/2)
+ else if (button.x < x0 - gui->keypad->w/2)
index = KEY_OUT_OF_KEYPAD;
- else if (button.x >= x0+gui->keypad->w/2+BORDER+env->loc_dpy.w)
+ else if (button.x >= x0 + gui->keypad->w/2 + BORDER + env->loc_dpy.w)
index = KEY_OUT_OF_KEYPAD;
- else if (button.x >= x0+gui->keypad->w/2+BORDER)
+ else if (button.x >= x0 + gui->keypad->w/2 + BORDER)
index = KEY_LOC_DPY;
- else if (button.x >= x0+gui->keypad->w/2)
+ else if (button.x >= x0 + gui->keypad->w/2)
index = KEY_OUT_OF_KEYPAD;
else if (gui->kp) {
/* we have to calculate the first coordinate
inside the keypad before calling the kp_match_area*/
int x_keypad = button.x - (x0 - gui->keypad->w/2);
- // find the key clicked (if one was clicked)
+ /* find the key clicked (if one was clicked) */
for (i = 0; i < gui->kp_used; i++) {
if (kp_match_area(&gui->kp[i],x_keypad, button.y - BORDER)) {
index = gui->kp[i].c;
@@ -629,8 +621,8 @@
index = KEY_OUT_OF_KEYPAD;
else {
x = x0 - src_wins_tot_w/2 + BORDER;
- //in the area of the small device windows
- if (button.y >= BORDER+SRC_WIN_H)
+ /* in the area of the small device windows */
+ if (button.y >= BORDER + SRC_WIN_H)
index = KEY_OUT_OF_KEYPAD;
else if (button.x < x)
index = KEY_OUT_OF_KEYPAD;
@@ -659,17 +651,17 @@
}
else if (index >= KEY_SRCS_WIN && index < KEY_SRCS_WIN+env->out.device_num) {
- index -= KEY_SRCS_WIN; //index of the window, equal to the device index in the table
+ index -= KEY_SRCS_WIN; /* index of the window, equal to the device index in the table */
/* if one of the additional device windows is clicked with
left or right mouse button, we have to switch to that device */
if (button.button == SDL_BUTTON_RIGHT || button.button == SDL_BUTTON_LEFT) {
- switch_video_caller(index, env, button.button);
+ switch_video_out(env, index, button.button);
return;
}
/* turn on or off the devices selectively with other mouse buttons */
else {
int ret = turn_on_off(index, env);
- // print a message according to what happened
+ /* print a message according to what happened */
if (!ret)
ast_log(LOG_WARNING, "unable to turn on device %s\n",
env->out.devices[index].name);
@@ -693,10 +685,10 @@
break;
/* other functions */
- case KEY_MUTE: //send or not send the audio
+ case KEY_MUTE: /* send or not send the audio */
case KEY_AUTOANSWER:
- case KEY_SENDVIDEO: // send or not send the video
- case KEY_PIP: // activate/deactivate picture in picture mode
+ case KEY_SENDVIDEO: /* send or not send the video */
+ case KEY_PIP: /* activate/deactivate picture in picture mode */
keypad_toggle(env, index);
break;
@@ -714,24 +706,24 @@
case KEY_LOC_DPY:
case KEY_REM_DPY:
if (button.button == SDL_BUTTON_LEFT) {
- // values used to find the position of the picture in picture (if present)
- int pip_loc_x = (float)env->out.pip_x/env->enc_in.w * env->loc_dpy.w;
- int pip_loc_y = (float)env->out.pip_y/env->enc_in.h * env->loc_dpy.h;
- // check if picture in picture is active and the click was on it
+ /* values used to find the position of the picture in picture (if present) */
+ int pip_loc_x = (double)env->out.pip_x/env->enc_in.w * env->loc_dpy.w;
+ int pip_loc_y = (double)env->out.pip_y/env->enc_in.h * env->loc_dpy.h;
+ /* check if picture in picture is active and the click was on it */
if (index == KEY_LOC_DPY && env->out.picture_in_picture &&
button.x >= x0+gui->keypad->w/2+BORDER+pip_loc_x &&
button.x < x0+gui->keypad->w/2+BORDER+pip_loc_x+env->loc_dpy.w/3 &&
button.y >= BORDER+pip_loc_y &&
button.y < BORDER+pip_loc_y+env->loc_dpy.h/3) {
- // set the y cordinate to his previous value
+ /* set the y cordinate to his previous value */
button.y += (env->out.devices ? SRC_WIN_H+2*BORDER+SRC_MSG_BD_H : 0);
- //starts dragging the picture inside the picture
+ /* starts dragging the picture inside the picture */
set_drag(&gui->drag, button.x, button.y, DRAG_PIP);
}
else if (index == KEY_LOC_DPY) {
- // set the y cordinate to his previous value
+ /* set the y cordinate to his previous value */
button.y += (env->out.devices ? SRC_WIN_H+2*BORDER+SRC_MSG_BD_H : 0);
- // click in the local display, but not on the PiP
+ /* click in the local display, but not on the PiP */
set_drag(&gui->drag, button.x, button.y, DRAG_LOCAL);
}
break;
@@ -745,7 +737,7 @@
/* writes messages in the source boards, those can be
modified during the execution, because of the events
this must be done here, otherwise the status of sources will not be
- shown after sdl_setup*/
+ shown after sdl_setup */
for (i = 0; i < env->out.device_num; i++) {
reset_board(gui->bd_srcs_msg[i]);
print_message(gui->bd_srcs_msg[i],
@@ -868,16 +860,16 @@
static void pip_move(struct video_desc* env, int dx, int dy) {
int new_pip_x = env->out.pip_x+dx;
int new_pip_y = env->out.pip_y+dy;
- // going beyond the left borders
+ /* going beyond the left borders */
if (new_pip_x < 0)
new_pip_x = 0;
- // going beyond the right borders
+ /* going beyond the right borders */
else if (new_pip_x > env->enc_in.w - env->enc_in.w/3)
new_pip_x = env->enc_in.w - env->enc_in.w/3;
- // going beyond the top borders
+ /* going beyond the top borders */
if (new_pip_y < 0)
new_pip_y = 0;
- // going beyond the bottom borders
+ /* going beyond the bottom borders */
else if (new_pip_y > env->enc_in.h - env->enc_in.h/3)
new_pip_y = env->enc_in.h - env->enc_in.h/3;
env->out.pip_x = new_pip_x;
@@ -949,12 +941,12 @@
int dy = ev[i].motion.y - drag->y_start;
/* dx and dy value are directly applied to env->out.pip_x and
env->out.pip_y, so they must work as if the format was cif */
- dx = (float)dx*env->enc_in.w/env->loc_dpy.w;
- dy = (float)dy*env->enc_in.h/env->loc_dpy.h;
+ dx = (double)dx*env->enc_in.w/env->loc_dpy.w;
+ dy = (double)dy*env->enc_in.h/env->loc_dpy.h;
/* sets starts to a new value */
drag->x_start = ev[i].motion.x;
drag->y_start = ev[i].motion.y;
- //ast_log(LOG_WARNING, "moving: %d, %d\n", dx, dy);
+ /* ast_log(LOG_WARNING, "moving: %d, %d\n", dx, dy); */
pip_move(env, dx, dy);
} else if (drag->drag_window == DRAG_MESSAGE) {
/* scroll up/down the window */
@@ -1166,15 +1158,15 @@
const SDL_VideoInfo *info;
int kp_w = 0, kp_h = 0; /* keypad width and height */
struct gui_info *gui = env->gui;
-
+
/* Some helper variables used for filling the SDL window */
- int x0; /* x coordinate of the center of the keypad */
- int y0; /* y coordinate of the top of keypad, remote and local window */
- int src_wins_tot_w; /* total width of thumbnails for sources */
+ int x0; /* the x coordinate of the center of the keypad */
+ int x1; /* userful for calculating of the size of the parent window */
+ int y0; /* y coordinate of the keypad, the remote window and the local window */
+ int src_wins_tot_w; /* total width of the source windows */
int i;
- int x; // useful for the creation of the source windows;
- int maxw_half1, maxw_half2; /* support in calculating the size of the parent window */
-
+ int x; /* useful for the creation of the source windows; */
+
#ifdef HAVE_X11
const char *e = getenv("SDL_WINDOWID");
@@ -1237,23 +1229,23 @@
kp_h = gui->keypad->h;
}
}
-
+
/* total width of the thumbnails */
src_wins_tot_w = env->out.device_num*(SRC_WIN_W+BORDER)+BORDER;
-
+
/* x coordinate of the center of the keypad */
- maxw_half1 = MAX(env->rem_dpy.w+kp_w/2+2*BORDER, src_wins_tot_w/2);
-
+ x0 = MAX(env->rem_dpy.w+kp_w/2+2*BORDER, src_wins_tot_w/2);
+
/* from center of the keypad to right border */
- maxw_half2 = MAX(env->loc_dpy.w+kp_w/2+2*BORDER, src_wins_tot_w/2);
-
+ x1 = MAX(env->loc_dpy.w+kp_w/2+2*BORDER, src_wins_tot_w/2);
+
/* total width of the SDL window to create */
- maxw = maxw_half1+maxw_half2;
-
- /* total height of the SDL window to create */
+ maxw = x0+x1;
+
+ /* total height of the mother window to create */
maxh = MAX( MAX(env->rem_dpy.h, env->loc_dpy.h), kp_h)+2*BORDER;
maxh += env->out.devices ? (2*BORDER+SRC_WIN_H+SRC_MSG_BD_H) : 0;
-
+
gui->screen = SDL_SetVideoMode(maxw, maxh, depth, 0);
if (!gui->screen) {
ast_log(LOG_ERROR, "SDL: could not set video mode - exiting\n");
@@ -1353,11 +1345,10 @@
} while (0);
#endif /* HAVE_X11 */
- x0 = maxw_half1;
y0 = env->out.devices ? (3*BORDER+SRC_WIN_H+SRC_MSG_BD_H) : BORDER;
-
+
SDL_WM_SetCaption("Asterisk console Video Output", NULL);
-
+
/* intialize the windows for local and remote video */
if (set_win(gui->screen, &gui->win[WIN_REMOTE], dpy_fmt,
env->rem_dpy.w, env->rem_dpy.h, x0-kp_w/2-BORDER-env->rem_dpy.w, y0))
@@ -1366,7 +1357,7 @@
env->loc_dpy.w, env->loc_dpy.h,
x0+kp_w/2+BORDER, y0))
goto no_sdl;
-
+
/* if necessary, allocate memory space for rects that will contain messages
relative to the state of every single source */
if (!gui->rect_srcs_msg) {
@@ -1377,8 +1368,8 @@
goto no_sdl;
}
}
- /* if necessary, allocate memory space for the array of pointers to the message boards of the
- additional sources */
+ /* if necessary, allocate memory space for the array of pointers
+ to the message boards of the sources */
if (!gui->bd_srcs_msg) {
gui->bd_srcs_msg = (struct board**)ast_calloc(env->out.device_num, sizeof(struct board*));
if (!gui->bd_srcs_msg) {
@@ -1387,28 +1378,28 @@
}
}
- /* initialize device_num additional src windows and boards
+ /* initialize device_num source windows (thumbnails) and boards
(for a maximum of 9 additional windows and boards) */
x = x0 - src_wins_tot_w/2 + BORDER;
for (i = 0; i < env->out.device_num; i++){
- if (set_win(gui->screen, &gui->win[i+3], dpy_fmt,
+ if (set_win(gui->screen, &gui->win[i+WIN_SRC1], dpy_fmt,
SRC_WIN_W, SRC_WIN_H, x+i*(BORDER+SRC_WIN_W), BORDER))
- goto no_sdl;
- // set geometry for the rect for the message board of the device
+ goto no_sdl;
+ /* set geometry for the rect for the message board of the device */
gui->rect_srcs_msg[i].w = SRC_WIN_W;
gui->rect_srcs_msg[i].h = SRC_MSG_BD_H;
gui->rect_srcs_msg[i].x = x+i*(BORDER+SRC_WIN_W);
gui->rect_srcs_msg[i].y = 2*BORDER+SRC_WIN_H;
- // the white color is used as background
+ /* the white color is used as background */
SDL_FillRect(gui->screen, &gui->rect_srcs_msg[i],
SDL_MapRGB(gui->screen->format, 255, 255, 255));
- // if necessary, initialize boards for the sources
+ /* if necessary, initialize boards for the sources */
if (!gui->bd_srcs_msg[i])
- gui->bd_srcs_msg[i] =
+ gui->bd_srcs_msg[i] =
board_setup(gui->screen, &gui->rect_srcs_msg[i],
- gui->font, gui->font_rects);
- }
- // update new rects
+ gui->font, gui->font_rects);
+ }
+ /* update new rects */
SDL_UpdateRects(gui->screen, env->out.device_num, gui->rect_srcs_msg);
/* display the skin, but do not free it as we need it later to
Modified: team/rizzo/video_console/channels/console_video.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/video_console/channels/console_video.c?view=diff&rev=125701&r1=125700&r2=125701
==============================================================================
--- team/rizzo/video_console/channels/console_video.c (original)
+++ team/rizzo/video_console/channels/console_video.c Thu Jun 26 23:20:41 2008
@@ -87,6 +87,9 @@
rem_dpy the format used to display the remote stream
+ src_dpy is the format used to display the local video source streams
+ The number of these fbuf_t is determined at run time, with dynamic allocation
+
We store the format info together with the buffer storing the data.
As a future optimization, a format/buffer may reference another one
if the formats are equivalent. This will save some unnecessary format
@@ -155,13 +158,14 @@
* about the device
*/
struct video_device {
- char *name; //name of the device
- struct grab_desc *grabber; //the grabber for the device type
- void *grabber_data; //device's private data structure
- struct fbuf_t *dev_buf; //buffer for incoming data
- struct timeval last_frame; //when we read the last frame ?
- int status_index; //what is the status of the device (source) [from 0 to 7]
- //status_index is the index of the status message in the src_msgs array in console_gui.c
+ char *name; /* name of the device */
+ struct grab_desc *grabber; /* the grabber for the device type */
+ void *grabber_data; /* device's private data structure */
+ struct fbuf_t *dev_buf; /* buffer for incoming data */
+ struct timeval last_frame; /* when we read the last frame ? */
+ int status_index; /* what is the status of the device (source) */
+ /* status index is set using the IS_ON, IS_PRIMARY and IS_SECONDARY costants */
+ /* status_index is the index of the status message in the src_msgs array in console_gui.c */
};
struct video_codec_desc; /* forward declaration */
@@ -287,40 +291,47 @@
void *g_data;
int i, j;
- //for each device in the device table...
- for(i = 0; i < v->device_num; i++) {
- //device already open
- if(v->devices[i].grabber)
+ /* for each device in the device table... */
+ for (i = 0; i < v->device_num; i++) {
+ /* device already open */
+ if (v->devices[i].grabber)
continue;
- //for each type of grabber supported...
+ /* for each type of grabber supported... */
for (j = 0; (g = console_grabbers[j]); j++) {
- if(g == NULL)
+ if (g == NULL)
break;
- //the grabber is opened and the informations saved in the device table
+ /* the grabber is opened and the informations saved in the device table */
g_data = g->open(v->devices[i].name, &v->loc_src_geometry, v->fps);
if (!g_data)
continue;
v->devices[i].grabber = g;
v->devices[i].grabber_data = g_data;
- v->devices[i].status_index += 4;
- }
- }
- //the first working device is selected as the primary one and the secondary one
- for(i = 0; i < v->device_num; i++) {
- if(!v->devices[i].grabber)
+ v->devices[i].status_index |= IS_ON;
+ }
+ }
+ /* the first working device is selected as the primary one and the secondary one */
+ for (i = 0; i < v->device_num; i++) {
+ if (!v->devices[i].grabber)
continue;
v->device_primary = i;
v->device_secondary = i;
- return 0; //source found
- }
- return 1; // no source found
+ return 0; /* source found */
+ }
+ return 1; /* no source found */
}
/*! \brief complete a buffer from the specified local video source.
* Called by get_video_frames(), in turn called by the video thread.
- */
-static struct fbuf_t *grabber_read(struct video_device *dev, struct video_out_desc *v)
+ *
+ * \param dev = video environment descriptor
+ * \param fps = frame per seconds, for every device
+ *
+ * returns:
+ * - NULL on falure
+ * - reference to the device buffer on success
+ */
+static struct fbuf_t *grabber_read(struct video_device *dev, int fps)
{
struct timeval now = ast_tvnow();
@@ -331,7 +342,7 @@
is always initialized, it is set during the parsing of the config
file, and never unset, function fill_device_table(). */
/* check if it is time to read */
- if (ast_tvdiff_ms(now, dev->last_frame) < 1000/v->fps)
+ if (ast_tvdiff_ms(now, dev->last_frame) < 1000/fps)
return NULL; /* too early */
dev->last_frame = now; /* XXX actually, should correct for drift */
return dev->grabber->read(dev->grabber_data);
@@ -373,7 +384,7 @@
static int video_out_uninit(struct video_desc *env)
{
struct video_out_desc *v = &env->out;
- int i; // integer variable used as iterator
+ int i; /* integer variable used as iterator */
/* XXX this should be a codec callback */
if (v->enc_ctx) {
@@ -392,7 +403,7 @@
fbuf_free(&v->enc_out);
/* close the grabbers */
for (i = 0; i < v->device_num; i++) {
- if(v->devices[i].grabber){
+ if (v->devices[i].grabber){
v->devices[i].grabber_data=
v->devices[i].grabber->close(v->devices[i].grabber_data);
v->devices[i].grabber=NULL;
@@ -582,7 +593,8 @@
* Old version of ffmpeg only have img_convert, which does not rescale.
* New versions use sws_scale which does both.
*/
-static void my_scale(struct fbuf_t *in, AVPicture *p_in, struct fbuf_t *out, AVPicture *p_out)
+static void my_scale(struct fbuf_t *in, AVPicture *p_in,
+ struct fbuf_t *out, AVPicture *p_out)
{
AVPicture my_p_in, my_p_out;
int eff_w=out->w, eff_h=out->h;
@@ -595,7 +607,7 @@
/*if win_w is different from zero then we must change
the size of the scaled buffer (the position is already
encoded into the out parameter)*/
- if(out->win_w) { //picture in picture enabled
+ if (out->win_w) { /* picture in picture enabled */
eff_w=out->win_w;
eff_h=out->win_h;
}
@@ -744,12 +756,12 @@
/* every time this function is called we refresh the buffers of every device,
updating the private device buffer in the device table */
for (i = 0; i < env->out.device_num; i++) {
- p_read = grabber_read(&env->out.devices[i], &env->out);
- // it is used only if different from NULL, we mantain last good buffer otherwise
+ p_read = grabber_read(&env->out.devices[i], env->out.fps);
+ /* it is used only if different from NULL, we mantain last good buffer otherwise */
if (p_read)
env->out.devices[i].dev_buf = p_read;
}
- // select the primary device buffer as the one to encode
+ /* select the primary device buffer as the one to encode */
loc_src_primary = env->out.devices[env->out.device_primary].dev_buf;
/* loc_src_primary can be NULL if the device has been turned off during
execution of it is read too early */
@@ -758,9 +770,9 @@
so we will see the same as the remote party */
my_scale(loc_src_primary, NULL, &env->enc_in, NULL);
}
- if (env->out.picture_in_picture) { // the picture in picture mode is enabled
+ if (env->out.picture_in_picture) { /* the picture in picture mode is enabled */
struct fbuf_t *loc_src_secondary;
- // reads from the secondary source
+ /* reads from the secondary source */
loc_src_secondary = env->out.devices[env->out.device_secondary].dev_buf;
if (loc_src_secondary) {
env->enc_in.win_x = env->out.pip_x;
@@ -770,7 +782,7 @@
/* scales to the correct geometry and inserts in
the enc_in buffer the picture in picture */
my_scale(loc_src_secondary, NULL, &env->enc_in, NULL);
- // returns to normal parameters (not picture in picture)
+ /* returns to normal parameters (not picture in picture) */
env->enc_in.win_x = 0;
env->enc_in.win_y = 0;
env->enc_in.win_w = 0;
@@ -779,13 +791,13 @@
else {
/* loc_src_secondary can be NULL if the device has been turned off during
execution of it is read too early */
- env->out.picture_in_picture = 0; // disable picture in picture
- }
- }
- show_frame(env, WIN_LOCAL); // local rendering
+ env->out.picture_in_picture = 0; /* disable picture in picture */
+ }
+ }
+ show_frame(env, WIN_LOCAL); /* local rendering */
if (env->src_dpy)
for (i = 0; i < env->out.device_num; i++)
- show_frame(env, i+3); // rendering of every source device in small windows
+ show_frame(env, i+WIN_SRC1); /* rendering of every source device in thumbnails */
if (tail == NULL)
tail = &dummy;
*tail = NULL;
@@ -812,7 +824,7 @@
struct video_desc *env = arg;
int count = 0;
char save_display[128] = "";
- int i; // integer variable used as iterator
+ int i; /* integer variable used as iterator */
/* if sdl_videodriver is set, override the environment. Also,
* if it contains 'console' override DISPLAY around the call to SDL_Init
@@ -840,8 +852,8 @@
ast_log(LOG_WARNING, "cannot open local video source\n");
}
- if(env->out.devices)
- env->out.devices[env->out.device_primary].status_index += 3;
+ if (env->out.devices)
+ env->out.devices[env->out.device_primary].status_index |= IS_PRIMARY | IS_SECONDARY;
/* even if no device is connected, we must initialize the video_out_init,
infact it is used in the get_video_frames function */
@@ -966,7 +978,7 @@
struct fbuf_t *ei = &(env->enc_in); /* encoder input */
struct fbuf_t *ld = &(env->loc_dpy); /* local display */
struct fbuf_t *rd = &(env->rem_dpy); /* remote display */
- int i; //integer working as iterator
+ int i; /* integer working as iterator */
c->pix_fmt = PIX_FMT_YUV420P; /* default - camera format */
ei->pix_fmt = PIX_FMT_YUV420P; /* encoder input */
@@ -979,14 +991,16 @@
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 */
- // allocate the array for the buffers of the additional sources
- env->src_dpy = (struct fbuf_t*) ast_calloc(env->out.device_num, sizeof(struct fbuf_t));
+ /* allocate the array for the buffers for the thumbnail of each source device */
if (!env->src_dpy) {
- ast_log(LOG_ERROR, "no memory for additional device display buffers\n");
- return;
- }
- // fix the size of buffers for small windows
- for(i = 0; i < env->out.device_num; i++) {
+ env->src_dpy = (struct fbuf_t*) ast_calloc(env->out.device_num, sizeof(struct fbuf_t));
+ if (!env->src_dpy) {
+ ast_log(LOG_ERROR, "no memory for additional device display buffers\n");
+ return;
+ }
+ }
+ /* fix the size of buffers for small windows */
+ for (i = 0; i < env->out.device_num; i++) {
env->src_dpy[i].pix_fmt = PIX_FMT_YUV420P;
env->src_dpy[i].w = SRC_WIN_W;
env->src_dpy[i].h = SRC_WIN_H;
@@ -1112,30 +1126,32 @@
static int device_table_fill (struct video_device **devices_p, int *device_num_p, const char *s)
{
int i;
- void* temp;
- // with the current implementation, we support a maximum of 9 devices.
+ void *temp;
+ struct video_device *p;
+ /* with the current implementation, we support a maximum of 9 devices.*/
if ((*device_num_p) >= 9)
- return 0; //more devices will be ignored
- // check if the entry has already been inserted
- for(i = 0; i < *device_num_p; i++)
- if(!strcmp((*devices_p)[i].name, s))
+ return 0; /* more devices will be ignored */
+ /* check if the entry has already been inserted */
+ for (i = 0; i < *device_num_p; i++)
+ if (!strcmp((*devices_p)[i].name, s))
return 0;
- // inserts the new video device, changing the size of the table
+ /* inserts the new video device, changing the size of the table */
temp = ast_realloc(*devices_p, (*device_num_p+1)*sizeof(struct video_device));
if (temp == NULL) {
ast_log(LOG_WARNING, "cannot reallocate devices, maximum size reached\n");
return 1;
}
*devices_p = (struct video_device*) temp;
- // copy the name
- (*devices_p)[*device_num_p].name = ast_strdup(s);
- // other fields initially NULL
- (*devices_p)[*device_num_p].grabber = NULL;
- (*devices_p)[*device_num_p].grabber_data = NULL;
- (*devices_p)[*device_num_p].dev_buf = NULL;
- (*devices_p)[*device_num_p].last_frame = ast_tvnow();
- (*devices_p)[*device_num_p].status_index = 0;
- // one device added
+ p = &(*devices_p)[*device_num_p];
+ /* copy the name */
+ p->name = ast_strdup(s);
+ /* other fields initially NULL */
+ p->grabber = NULL;
+ p->grabber_data = NULL;
+ p->dev_buf = NULL;
+ p->last_frame = ast_tvnow();
+ p->status_index = 0;
+ /* one device added */
(*device_num_p)++;
return 0;
}
More information about the asterisk-commits
mailing list