Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:49:00 2009

## 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)
int | ast_image_register (struct ast_imager *imgdrv)
void | ast_image_unregister (struct ast_imager *imgdrv)
struct ast_frame * | ast_read_image (char *filename, char *preflang, int format)
int | ast_send_image (struct ast_channel *chan, char *filename)
int | ast_supports_images (struct ast_channel *chan)

## 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 214 of file image.c.

References ast_cli_register().

Referenced by main().

    00215 {
    00216    ast_cli_register(&show_images);
    00217    return 0;
    00218 }

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 51 of file image.c.

References ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), ast_imager::desc, ast_imager::name, ast_imager::next, option_verbose, and VERBOSE_PREFIX_2.

Referenced by load_module().

    00052 {
    00053    if (option_verbose > 1)
    00054       ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
    00055    ast_mutex_lock(&listlock);
    00056    img->next = list;
    00057    list = img;
    00058    ast_mutex_unlock(&listlock);
    00059    return 0;
    00060 }

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 62 of file image.c.

References ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), ast_imager::desc, ast_imager::name, ast_imager::next, option_verbose, and VERBOSE_PREFIX_2.

Referenced by unload_module().

    00063 {
    00064    struct ast_imager *i, *prev = NULL;
    00065    ast_mutex_lock(&listlock);
    00066    i = list;
    00067    while(i) {
    00068       if (i == img) {
    00069          if (prev)
    00070             prev->next = i->next;
    00071          else
    00072             list = i->next;
    00073          break;
    00074       }
    00075       prev = i;
    00076       i = i->next;
    00077    }
    00078    ast_mutex_unlock(&listlock);
    00079    if (i && (option_verbose > 1))
    00080       ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc);
    00081 }

struct ast_frame* ast_read_image | ( | char * | filename,
|  | char * | preflang,
|  | int | 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 Make an image from a filename ??? No estoy positivo Returns an ast_frame on success, NULL on failure

Definition at line 117 of file image.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_imager::exts, file_exists(), ast_imager::format, ast_imager::identify, LOG_WARNING, make_filename(), ast_imager::name, ast_imager::next, ast_imager::read_image, and strsep().

Referenced by ast_send_image().

    00118 {
    00119    struct ast_imager *i;
    00120    char buf[256];
    00121    char tmp[80];
    00122    char *e;
    00123    struct ast_imager *found = NULL;
    00124    int fd;
    00125    int len=0;
    00126    struct ast_frame *f = NULL;
    00127 #if 0 /* We need to have some sort of read-only lock */
    00128    ast_mutex_lock(&listlock);
    00129 #endif
    00130    i = list;
    00131    while(!found && i) {
    00132       if (i->format & format) {
    00133          char *stringp=NULL;
    00134          strncpy(tmp, i->exts, sizeof(tmp)-1);
    00135          stringp=tmp;
    00136          e = strsep(&stringp, "|");
    00137          while(e) {
    00138             make_filename(buf, sizeof(buf), filename, preflang, e);
    00139             if ((len = file_exists(buf))) {
    00140                found = i;
    00141                break;
    00142             }
    00143             make_filename(buf, sizeof(buf), filename, NULL, e);
    00144             if ((len = file_exists(buf))) {
    00145                found = i;
    00146                break;
    00147             }
    00148             e = strsep(&stringp, "|");
    00149          }
    00150       }
    00151       i = i->next;
    00152    }
    00153    if (found) {
    00154       fd = open(buf, O_RDONLY);
    00155       if (fd > -1) {
    00156          if (!found->identify || found->identify(fd)) {
    00157             /* Reset file pointer */
    00158             lseek(fd, 0, SEEK_SET);
    00159             f = found->read_image(fd,len);
    00160          } else
    00161             ast_log(LOG_WARNING, "%s does not appear to be a %s file\n", buf, found->name);
    00162          close(fd);
    00163       } else
    00164          ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno));
    00165    } else
    00166       ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
    00167 #if 0
    00168    ast_mutex_unlock(&listlock);
    00169 #endif
    00170    return f;
    00171 }

int ast_send_image | ( | struct ast_channel * | chan,
|  | 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. Returns 0 on success, -1 on error

Definition at line 174 of file image.c.

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

Referenced by handle_sendimage(), and sendimage_exec().

    00175 {
    00176    struct ast_frame *f;
    00177    int res = -1;
    00178    if (chan->tech->send_image) {
    00179       f = ast_read_image(filename, chan->language, -1);
    00180       if (f) {
    00181          res = chan->tech->send_image(chan, f);
    00182          ast_frfree(f);
    00183       }
    00184    }
    00185    return res;
    00186 }

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 83 of file image.c.

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

Referenced by sendimage_exec().

    00084 {
    00085    if (!chan || !chan->tech)
    00086       return 0;
    00087    if (!chan->tech->send_image)
    00088       return 0;
    00089    return 1;
    00090 }