Tue Aug 24 20:35:19 2010

Asterisk developer's documentation


format_jpeg.c File Reference

JPEG File format support. More...

#include "asterisk.h"
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/image.h"
#include "asterisk/endian.h"
Include dependency graph for format_jpeg.c:

Go to the source code of this file.

Functions

 AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,"jpeg (joint picture experts group) image format",.load=load_module,.unload=unload_module,.load_pri=10,)
static int jpeg_identify (int fd)
static struct ast_frame * jpeg_read_image (int fd, int len)
static int jpeg_write_image (int fd, struct ast_frame *fr)
static int load_module (void)
static int unload_module (void)

Variables

static struct ast_imager jpeg_format

Detailed Description

JPEG File format support.

Definition in file format_jpeg.c.


Function Documentation

AST_MODULE_INFO ( ASTERISK_GPL_KEY  ,
AST_MODFLAG_LOAD_ORDER  ,
"jpeg (joint picture experts group) image format"  ,
.  load = load_module,
.  unload = unload_module,
.  load_pri = 10 
)
static int jpeg_identify ( int  fd  )  [static]

Definition at line 58 of file format_jpeg.c.

References buf.

00059 {
00060    char buf[10];
00061    int res;
00062    res = read(fd, buf, sizeof(buf));
00063    if (res < sizeof(buf))
00064       return 0;
00065    if (memcmp(buf + 6, "JFIF", 4))
00066       return 0;
00067    return 1;
00068 }

static struct ast_frame* jpeg_read_image ( int  fd,
int  len 
) [static, read]

Definition at line 36 of file format_jpeg.c.

References AST_FORMAT_JPEG, AST_FRAME_IMAGE, ast_frisolate(), ast_log(), buf, ast_frame::data, ast_frame::datalen, errno, ast_frame::frametype, LOG_WARNING, ast_frame::ptr, ast_frame::src, and ast_frame::subclass.

00037 {
00038    struct ast_frame fr;
00039    int res;
00040    char buf[65536];
00041    if (len > sizeof(buf) || len < 0) {
00042       ast_log(LOG_WARNING, "JPEG image too large to read\n");
00043       return NULL;
00044    }
00045    res = read(fd, buf, len);
00046    if (res < len) {
00047       ast_log(LOG_WARNING, "Only read %d of %d bytes: %s\n", res, len, strerror(errno));
00048    }
00049    memset(&fr, 0, sizeof(fr));
00050    fr.frametype = AST_FRAME_IMAGE;
00051    fr.subclass = AST_FORMAT_JPEG;
00052    fr.data.ptr = buf;
00053    fr.src = "JPEG Read";
00054    fr.datalen = len;
00055    return ast_frisolate(&fr);
00056 }

static int jpeg_write_image ( int  fd,
struct ast_frame *  fr 
) [static]

Definition at line 70 of file format_jpeg.c.

References AST_FORMAT_JPEG, AST_FRAME_IMAGE, ast_log(), ast_frame::data, ast_frame::datalen, errno, ast_frame::frametype, LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.

00071 {
00072    int res=0;
00073    if (fr->frametype != AST_FRAME_IMAGE) {
00074       ast_log(LOG_WARNING, "Not an image\n");
00075       return -1;
00076    }
00077    if (fr->subclass != AST_FORMAT_JPEG) {
00078       ast_log(LOG_WARNING, "Not a jpeg image\n");
00079       return -1;
00080    }
00081    if (fr->datalen) {
00082       res = write(fd, fr->data.ptr, fr->datalen);
00083       if (res != fr->datalen) {
00084          ast_log(LOG_WARNING, "Only wrote %d of %d bytes: %s\n", res, fr->datalen, strerror(errno));
00085          return -1;
00086       }
00087    }
00088    return res;
00089 }

static int load_module ( void   )  [static]

Definition at line 101 of file format_jpeg.c.

References ast_image_register(), AST_MODULE_LOAD_FAILURE, and AST_MODULE_LOAD_SUCCESS.

00102 {
00103    if (ast_image_register(&jpeg_format))
00104       return AST_MODULE_LOAD_FAILURE;
00105    return AST_MODULE_LOAD_SUCCESS;
00106 }

static int unload_module ( void   )  [static]

Definition at line 108 of file format_jpeg.c.

References ast_image_unregister().

00109 {
00110    ast_image_unregister(&jpeg_format);
00111 
00112    return 0;
00113 }  


Variable Documentation

struct ast_imager jpeg_format [static]

Definition at line 91 of file format_jpeg.c.


Generated on 24 Aug 2010 for Asterisk - the Open Source PBX by  doxygen 1.6.1