#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/time.h>#include <sys/stat.h>#include <signal.h>#include <errno.h>#include <unistd.h>#include <asterisk/sched.h>#include <asterisk/options.h>#include <asterisk/channel.h>#include <asterisk/channel_pvt.h>#include <asterisk/logger.h>#include <asterisk/file.h>#include <asterisk/image.h>#include <asterisk/translate.h>#include <asterisk/cli.h>#include <asterisk/lock.h>#include "asterisk.h"#include "astconf.h"Go to the source code of this file.
Defines | |
| #define | FORMAT "%10s %10s %50s %10s\n" |
| #define | FORMAT2 "%10s %10s %50s %10s\n" |
Functions | |
| AST_MUTEX_DEFINE_STATIC (listlock) | |
| int | ast_image_register (struct ast_imager *img) |
| Register image format. | |
| void | ast_image_unregister (struct ast_imager *img) |
| Unregister an image format. | |
| int | ast_supports_images (struct ast_channel *chan) |
| Check for image support on a channel. | |
| ast_frame * | ast_read_image (char *filename, char *preflang, int format) |
| Make an image. | |
| int | ast_send_image (struct ast_channel *chan, char *filename) |
| Sends an image. | |
| int | ast_image_init (void) |
| Initialize image stuff. | |
Variables | |
| ast_cli_entry | show_images |
|
|
|
|
|
|
|
|
Initialize image stuff. Initializes all the various image stuff. Basically just registers the cli stuff Returns 0 all the time Definition at line 201 of file image.c. References ast_cli_register(). Referenced by main(). 00202 {
00203 ast_cli_register(&show_images);
00204 return 0;
00205 }
|
|
|
Register image format.
Definition at line 38 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. 00039 {
00040 if (option_verbose > 1)
00041 ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
00042 ast_mutex_lock(&listlock);
00043 img->next = list;
00044 list = img;
00045 ast_mutex_unlock(&listlock);
00046 return 0;
00047 }
|
|
|
Unregister an image format.
Definition at line 49 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. 00050 {
00051 struct ast_imager *i, *prev = NULL;
00052 ast_mutex_lock(&listlock);
00053 i = list;
00054 while(i) {
00055 if (i == img) {
00056 if (prev)
00057 prev->next = i->next;
00058 else
00059 list = i->next;
00060 break;
00061 }
00062 prev = i;
00063 i = i->next;
00064 }
00065 ast_mutex_unlock(&listlock);
00066 if (i && (option_verbose > 1))
00067 ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc);
00068 }
|
|
|
|
|
||||||||||||||||
|
Make an image.
Definition at line 104 of file image.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_imager::exts, ast_imager::format, ast_imager::identify, LOG_WARNING, ast_imager::name, ast_imager::next, and ast_imager::read_image. Referenced by ast_send_image(). 00105 {
00106 struct ast_imager *i;
00107 char buf[256];
00108 char tmp[80];
00109 char *e;
00110 struct ast_imager *found = NULL;
00111 int fd;
00112 int len=0;
00113 struct ast_frame *f = NULL;
00114 #if 0 /* We need to have some sort of read-only lock */
00115 ast_mutex_lock(&listlock);
00116 #endif
00117 i = list;
00118 while(!found && i) {
00119 if (i->format & format) {
00120 char *stringp=NULL;
00121 strncpy(tmp, i->exts, sizeof(tmp)-1);
00122 stringp=tmp;
00123 e = strsep(&stringp, "|");
00124 while(e) {
00125 make_filename(buf, sizeof(buf), filename, preflang, e);
00126 if ((len = file_exists(buf))) {
00127 found = i;
00128 break;
00129 }
00130 make_filename(buf, sizeof(buf), filename, NULL, e);
00131 if ((len = file_exists(buf))) {
00132 found = i;
00133 break;
00134 }
00135 e = strsep(&stringp, "|");
00136 }
00137 }
00138 i = i->next;
00139 }
00140 if (found) {
00141 fd = open(buf, O_RDONLY);
00142 if (fd > -1) {
00143 if (!found->identify || found->identify(fd)) {
00144 /* Reset file pointer */
00145 lseek(fd, 0, SEEK_SET);
00146 f = found->read_image(fd,len);
00147 } else
00148 ast_log(LOG_WARNING, "%s does not appear to be a %s file\n", buf, i->name);
00149 close(fd);
00150 } else
00151 ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno));
00152 } else
00153 ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
00154 #if 0
00155 ast_mutex_unlock(&listlock);
00156 #endif
00157 return f;
00158 }
|
|
||||||||||||
|
Sends an image.
Definition at line 161 of file image.c. References ast_frfree(), ast_read_image(), ast_channel::language, ast_channel::pvt, and ast_channel_pvt::send_image. 00162 {
00163 struct ast_frame *f;
00164 int res = -1;
00165 if (chan->pvt->send_image) {
00166 f = ast_read_image(filename, chan->language, -1);
00167 if (f) {
00168 res = chan->pvt->send_image(chan, f);
00169 ast_frfree(f);
00170 }
00171 }
00172 return res;
00173 }
|
|
|
Check for image support on a channel.
Definition at line 70 of file image.c. References ast_channel::pvt, and ast_channel_pvt::send_image. 00071 {
00072 if (!chan || !chan->pvt)
00073 return 0;
00074 if (!chan->pvt->send_image)
00075 return 0;
00076 return 1;
00077 }
|
|
|
|
1.4.2