2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief JPEG File format support.
23 * \arg File name extension: jpeg, jpg
27 #include <sys/types.h>
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
39 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
41 #include "asterisk/channel.h"
42 #include "asterisk/file.h"
43 #include "asterisk/logger.h"
44 #include "asterisk/sched.h"
45 #include "asterisk/module.h"
46 #include "asterisk/image.h"
47 #include "asterisk/lock.h"
48 #include "asterisk/endian.h"
50 static char *desc = "JPEG (Joint Picture Experts Group) Image Format";
53 static struct ast_frame *jpeg_read_image(int fd, int len)
58 if (len > sizeof(buf) || len < 0) {
59 ast_log(LOG_WARNING, "JPEG image too large to read\n");
62 res = read(fd, buf, len);
64 ast_log(LOG_WARNING, "Only read %d of %d bytes: %s\n", res, len, strerror(errno));
66 memset(&fr, 0, sizeof(fr));
67 fr.frametype = AST_FRAME_IMAGE;
68 fr.subclass = AST_FORMAT_JPEG;
72 return ast_frisolate(&fr);
75 static int jpeg_identify(int fd)
79 res = read(fd, buf, sizeof(buf));
80 if (res < sizeof(buf))
82 if (memcmp(buf + 6, "JFIF", 4))
87 static int jpeg_write_image(int fd, struct ast_frame *fr)
90 if (fr->frametype != AST_FRAME_IMAGE) {
91 ast_log(LOG_WARNING, "Not an image\n");
94 if (fr->subclass != AST_FORMAT_JPEG) {
95 ast_log(LOG_WARNING, "Not a jpeg image\n");
99 res = write(fd, fr->data, fr->datalen);
100 if (res != fr->datalen) {
101 ast_log(LOG_WARNING, "Only wrote %d of %d bytes: %s\n", res, fr->datalen, strerror(errno));
108 static struct ast_imager jpeg_format = {
110 "JPEG (Joint Picture Experts Group)",
118 static int load_module(void *mod)
120 return ast_image_register(&jpeg_format);
123 static int unload_module(void *mod)
125 ast_image_unregister(&jpeg_format);
129 static const char *description(void)
134 static const char *key(void)
136 return ASTERISK_GPL_KEY;
139 STD_MOD(MOD_1 | NO_USECOUNT, NULL, NULL, NULL);