Fri Feb 10 06:36:37 2012

Asterisk developer's documentation


image.h File Reference

General Asterisk channel definitions for image handling. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_imager
 structure associated with registering an image format More...

Functions

int ast_image_init (void)
 Initialize image stuff Initializes all the various image stuff. Basically just registers the cli stuff.
int ast_image_register (struct ast_imager *imgdrv)
 Register image format.
void ast_image_unregister (struct ast_imager *imgdrv)
 Unregister an image format.
struct ast_frameast_read_image (const char *filename, const char *preflang, struct ast_format *format)
 Make an image.
int ast_send_image (struct ast_channel *chan, const char *filename)
 Sends an image.
int ast_supports_images (struct ast_channel *chan)
 Check for image support on a channel.


Detailed Description

General Asterisk channel definitions for image handling.

Definition in file image.h.


Function Documentation

int ast_image_init ( void   ) 

Initialize image stuff Initializes all the various image stuff. Basically just registers the cli stuff.

Returns:
0 all the time

Definition at line 205 of file image.c.

References ARRAY_LEN, and ast_cli_register_multiple().

Referenced by main().

00206 {
00207    ast_cli_register_multiple(cli_image, ARRAY_LEN(cli_image));
00208    return 0;
00209 }

int ast_image_register ( struct ast_imager imgdrv  ) 

Register image format.

Parameters:
imgdrv Populated ast_imager structure with info to register Registers an image format
Returns:
0 regardless

Definition at line 46 of file image.c.

References AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_imager::desc, and ast_imager::name.

Referenced by load_module().

00047 {
00048    AST_RWLIST_WRLOCK(&imagers);
00049    AST_RWLIST_INSERT_HEAD(&imagers, img, list);
00050    AST_RWLIST_UNLOCK(&imagers);
00051    ast_verb(2, "Registered format '%s' (%s)\n", img->name, img->desc);
00052    return 0;
00053 }

void ast_image_unregister ( struct ast_imager imgdrv  ) 

Unregister an image format.

Parameters:
imgdrv pointer to the ast_imager structure you wish to unregister Unregisters the image format passed in. Returns nothing

Definition at line 55 of file image.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_imager::desc, and ast_imager::name.

Referenced by unload_module().

00056 {
00057    AST_RWLIST_WRLOCK(&imagers);
00058    img = AST_RWLIST_REMOVE(&imagers, img, list);
00059    AST_RWLIST_UNLOCK(&imagers);
00060 
00061    if (img)
00062       ast_verb(2, "Unregistered format '%s' (%s)\n", img->name, img->desc);
00063 }

struct ast_frame* ast_read_image ( const char *  filename,
const char *  preflang,
struct ast_format format 
) [read]

Make an image.

Parameters:
filename filename of image to prepare
preflang preferred language to get the image...?
format the format of the file, NULL for any image format Make an image from a filename ??? No estoy positivo
Return values:
an ast_frame on success
NULL on failure

Definition at line 99 of file image.c.

References ast_copy_string(), ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, errno, ast_imager::exts, f, file_exists(), ast_imager::format, ast_imager::identify, len(), LOG_WARNING, make_filename(), ast_imager::name, ast_imager::read_image, and strsep().

Referenced by ast_send_image().

00100 {
00101    struct ast_imager *i;
00102    char buf[256];
00103    char tmp[80];
00104    char *e;
00105    struct ast_imager *found = NULL;
00106    int fd;
00107    int len=0;
00108    struct ast_frame *f = NULL;
00109    
00110    AST_RWLIST_RDLOCK(&imagers);
00111    AST_RWLIST_TRAVERSE(&imagers, i, list) {
00112       /* if NULL image format, just pick the first one, otherwise match it. */
00113       if (!format || (ast_format_cmp(&i->format, format) == AST_FORMAT_CMP_EQUAL)) {
00114          char *stringp=NULL;
00115          ast_copy_string(tmp, i->exts, sizeof(tmp));
00116          stringp = tmp;
00117          e = strsep(&stringp, "|");
00118          while (e) {
00119             make_filename(buf, sizeof(buf), filename, preflang, e);
00120             if ((len = file_exists(buf))) {
00121                found = i;
00122                break;
00123             }
00124             make_filename(buf, sizeof(buf), filename, NULL, e);
00125             if ((len = file_exists(buf))) {
00126                found = i;
00127                break;
00128             }
00129             e = strsep(&stringp, "|");
00130          }
00131       }
00132       if (found)
00133          break;   
00134    }
00135 
00136    if (found) {
00137       fd = open(buf, O_RDONLY);
00138       if (fd > -1) {
00139          if (!found->identify || found->identify(fd)) {
00140             /* Reset file pointer */
00141             lseek(fd, 0, SEEK_SET);
00142             f = found->read_image(fd, len); 
00143          } else
00144             ast_log(LOG_WARNING, "%s does not appear to be a %s file\n", buf, found->name);
00145          close(fd);
00146       } else
00147          ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno));
00148    } else
00149       ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
00150    
00151    AST_RWLIST_UNLOCK(&imagers);
00152    
00153    return f;
00154 }

int ast_send_image ( struct ast_channel chan,
const char *  filename 
)

Sends an image.

Parameters:
chan channel to send image on
filename filename of image to send (minus extension) Sends an image on the given channel.
Return values:
0 on success
-1 on error

Definition at line 156 of file image.c.

References ast_channel_language(), ast_frfree, ast_read_image(), f, ast_channel_tech::send_image, and ast_channel::tech.

Referenced by handle_sendimage(), and sendimage_exec().

00157 {
00158    struct ast_frame *f;
00159    int res = -1;
00160    if (chan->tech->send_image) {
00161       f = ast_read_image(filename, ast_channel_language(chan), NULL);
00162       if (f) {
00163          res = chan->tech->send_image(chan, f);
00164          ast_frfree(f);
00165       }
00166    }
00167    return res;
00168 }

int ast_supports_images ( struct ast_channel chan  ) 

Check for image support on a channel.

Parameters:
chan channel to check Checks the channel to see if it supports the transmission of images
Returns:
non-zero if image transmission is supported

Definition at line 65 of file image.c.

References ast_channel_tech::send_image, and ast_channel::tech.

Referenced by sendimage_exec().

00066 {
00067    if (!chan || !chan->tech)
00068       return 0;
00069    if (!chan->tech->send_image)
00070       return 0;
00071    return 1;
00072 }


Generated on Fri Feb 10 06:36:38 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6