Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


image.h File Reference

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

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. More...
 
int ast_image_register (struct ast_imager *imgdrv)
 Register image format. More...
 
void ast_image_unregister (struct ast_imager *imgdrv)
 Unregister an image format. More...
 
struct ast_frameast_read_image (const char *filename, const char *preflang, int format)
 Make an image. More...
 
int ast_send_image (struct ast_channel *chan, const char *filename)
 Sends an image. More...
 
int ast_supports_images (struct ast_channel *chan)
 Check for image support on a channel. More...
 

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

References ARRAY_LEN, ast_cli_register_multiple(), ast_register_atexit(), and image_shutdown().

Referenced by main().

214 {
217  return 0;
218 }
static void image_shutdown(void)
Definition: image.c:208
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct ast_cli_entry cli_image[]
Definition: image.c:204
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
Definition: asterisk.c:998
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
int ast_image_register ( struct ast_imager imgdrv)

Register image format.

Parameters
imgdrvPopulated ast_imager structure with info to register Registers an image format
Returns
0 regardless

Definition at line 50 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().

51 {
53  AST_RWLIST_INSERT_HEAD(&imagers, img, list);
55  ast_verb(2, "Registered format '%s' (%s)\n", img->name, img->desc);
56  return 0;
57 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define ast_verb(level,...)
Definition: logger.h:243
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:703
Definition: image.c:48
void ast_image_unregister ( struct ast_imager imgdrv)

Unregister an image format.

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

Definition at line 59 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().

60 {
62  img = AST_RWLIST_REMOVE(&imagers, img, list);
64 
65  if (img)
66  ast_verb(2, "Unregistered format '%s' (%s)\n", img->name, img->desc);
67 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define ast_verb(level,...)
Definition: logger.h:243
Definition: image.c:48
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:870
struct ast_frame* ast_read_image ( const char *  filename,
const char *  preflang,
int  format 
)

Make an image.

Parameters
filenamefilename of image to prepare
preflangpreferred language to get the image...?
formatthe format of the file Make an image from a filename ??? No estoy positivo
Return values
anast_frame on success
NULLon failure

Definition at line 103 of file image.c.

References ast_copy_string(), 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().

104 {
105  struct ast_imager *i;
106  char buf[256];
107  char tmp[80];
108  char *e;
109  struct ast_imager *found = NULL;
110  int fd;
111  int len=0;
112  struct ast_frame *f = NULL;
113 
115  AST_RWLIST_TRAVERSE(&imagers, i, list) {
116  if (i->format & format) {
117  char *stringp=NULL;
118  ast_copy_string(tmp, i->exts, sizeof(tmp));
119  stringp = tmp;
120  e = strsep(&stringp, "|");
121  while (e) {
122  make_filename(buf, sizeof(buf), filename, preflang, e);
123  if ((len = file_exists(buf))) {
124  found = i;
125  break;
126  }
127  make_filename(buf, sizeof(buf), filename, NULL, e);
128  if ((len = file_exists(buf))) {
129  found = i;
130  break;
131  }
132  e = strsep(&stringp, "|");
133  }
134  }
135  if (found)
136  break;
137  }
138 
139  if (found) {
140  fd = open(buf, O_RDONLY);
141  if (fd > -1) {
142  if (!found->identify || found->identify(fd)) {
143  /* Reset file pointer */
144  lseek(fd, 0, SEEK_SET);
145  f = found->read_image(fd, len);
146  } else
147  ast_log(LOG_WARNING, "%s does not appear to be a %s file\n", buf, found->name);
148  close(fd);
149  } else
150  ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno));
151  } else
152  ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
153 
155 
156  return f;
157 }
structure associated with registering an image format
Definition: image.h:27
static int file_exists(char *filename)
Definition: image.c:78
char * strsep(char **str, const char *delims)
int(* identify)(int fd)
Definition: image.h:33
#define LOG_WARNING
Definition: logger.h:144
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
static void make_filename(char *buf, int len, const char *filename, const char *preflang, char *ext)
Definition: image.c:88
int format
Definition: image.h:31
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_frame *(* read_image)(int fd, int len)
Definition: image.h:32
int errno
static struct ast_format f[]
Definition: format_g726.c:181
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
Data structure associated with a single frame of data.
Definition: frame.h:142
char * name
Definition: image.h:28
Definition: image.c:48
static snd_pcm_format_t format
Definition: chan_alsa.c:93
char * exts
Definition: image.h:30
int ast_send_image ( struct ast_channel chan,
const char *  filename 
)

Sends an image.

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

Definition at line 159 of file image.c.

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

Referenced by handle_sendimage(), and sendimage_exec().

160 {
161  struct ast_frame *f;
162  int res = -1;
163  if (chan->tech->send_image) {
164  f = ast_read_image(filename, chan->language, -1);
165  if (f) {
166  res = chan->tech->send_image(chan, f);
167  ast_frfree(f);
168  }
169  }
170  return res;
171 }
int(*const send_image)(struct ast_channel *chan, struct ast_frame *frame)
Display or send an image.
Definition: channel.h:560
struct ast_frame * ast_read_image(const char *filename, const char *preflang, int format)
Make an image.
Definition: image.c:103
static struct ast_format f[]
Definition: format_g726.c:181
Data structure associated with a single frame of data.
Definition: frame.h:142
#define ast_frfree(fr)
Definition: frame.h:583
struct ast_channel_tech * tech
Definition: channel.h:743
const ast_string_field language
Definition: channel.h:787
int ast_supports_images ( struct ast_channel chan)

Check for image support on a channel.

Parameters
chanchannel 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 69 of file image.c.

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

Referenced by sendimage_exec().

70 {
71  if (!chan || !chan->tech)
72  return 0;
73  if (!chan->tech->send_image)
74  return 0;
75  return 1;
76 }
int(*const send_image)(struct ast_channel *chan, struct ast_frame *frame)
Display or send an image.
Definition: channel.h:560
struct ast_channel_tech * tech
Definition: channel.h:743