2
* Asterisk -- A telephony toolkit for Linux.
4
* JPEG File format support.
6
* Copyright (C) 1999, Mark Spencer
8
* Mark Spencer <markster@linux-support.net>
10
* This program is free software, distributed under the terms of
11
* the GNU General Public License
14
#include <asterisk/channel.h>
15
#include <asterisk/file.h>
16
#include <asterisk/logger.h>
17
#include <asterisk/sched.h>
18
#include <asterisk/module.h>
19
#include <asterisk/image.h>
20
#include <arpa/inet.h>
32
static char *desc = "JPEG (Joint Picture Experts Group) Image Format";
35
static struct ast_frame *jpeg_read_image(int fd, int len)
40
if (len > sizeof(buf)) {
41
ast_log(LOG_WARNING, "JPEG image too large to read\n");
44
res = read(fd, buf, len);
46
ast_log(LOG_WARNING, "Only read %d of %d bytes: %s\n", res, len, strerror(errno));
48
memset(&fr, 0, sizeof(fr));
49
fr.frametype = AST_FRAME_IMAGE;
50
fr.subclass = AST_FORMAT_JPEG;
54
return ast_frisolate(&fr);
57
static int jpeg_identify(int fd)
61
res = read(fd, buf, sizeof(buf));
62
if (res < sizeof(buf))
64
if (memcmp(buf + 6, "JFIF", 4))
69
static int jpeg_write_image(int fd, struct ast_frame *fr)
72
if (fr->frametype != AST_FRAME_IMAGE) {
73
ast_log(LOG_WARNING, "Not an image\n");
76
if (fr->subclass != AST_FORMAT_JPEG) {
77
ast_log(LOG_WARNING, "Not a jpeg image\n");
81
res = write(fd, fr->data, fr->datalen);
82
if (res != fr->datalen) {
83
ast_log(LOG_WARNING, "Only wrote %d of %d bytes: %s\n", res, fr->datalen);
90
static struct ast_imager jpeg_format = {
92
"JPEG (Joint Picture Experts Group)",
102
return ast_image_register(&jpeg_format);
107
ast_image_unregister(&jpeg_format);
113
/* We never really have any users */
125
return ASTERISK_GPL_KEY;