Tue Sep 30 01:19:57 2008

Asterisk developer's documentation


format_jpeg.c File Reference

JPEG File format support. More...

#include "asterisk.h"
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "asterisk/channel.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/sched.h"
#include "asterisk/module.h"
#include "asterisk/image.h"
#include "asterisk/lock.h"
#include "asterisk/endian.h"

Include dependency graph for format_jpeg.c:

Go to the source code of this file.

Functions

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"JPEG (Joint Picture Experts Group) Image Format")
static int jpeg_identify (int fd)
static struct ast_framejpeg_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_STANDARD ( ASTERISK_GPL_KEY  ,
"JPEG (Joint Picture Experts Group) Image Format"   
)

static int jpeg_identify ( int  fd  )  [static]

Definition at line 72 of file format_jpeg.c.

00073 {
00074    char buf[10];
00075    int res;
00076    res = read(fd, buf, sizeof(buf));
00077    if (res < sizeof(buf))
00078       return 0;
00079    if (memcmp(buf + 6, "JFIF", 4))
00080       return 0;
00081    return 1;
00082 }

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

Definition at line 50 of file format_jpeg.c.

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

00051 {
00052    struct ast_frame fr;
00053    int res;
00054    char buf[65536];
00055    if (len > sizeof(buf) || len < 0) {
00056       ast_log(LOG_WARNING, "JPEG image too large to read\n");
00057       return NULL;
00058    }
00059    res = read(fd, buf, len);
00060    if (res < len) {
00061       ast_log(LOG_WARNING, "Only read %d of %d bytes: %s\n", res, len, strerror(errno));
00062    }
00063    memset(&fr, 0, sizeof(fr));
00064    fr.frametype = AST_FRAME_IMAGE;
00065    fr.subclass = AST_FORMAT_JPEG;
00066    fr.data = buf;
00067    fr.src = "JPEG Read";
00068    fr.datalen = len;
00069    return ast_frisolate(&fr);
00070 }

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

Definition at line 84 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, and ast_frame::subclass.

00085 {
00086    int res=0;
00087    if (fr->frametype != AST_FRAME_IMAGE) {
00088       ast_log(LOG_WARNING, "Not an image\n");
00089       return -1;
00090    }
00091    if (fr->subclass != AST_FORMAT_JPEG) {
00092       ast_log(LOG_WARNING, "Not a jpeg image\n");
00093       return -1;
00094    }
00095    if (fr->datalen) {
00096       res = write(fd, fr->data, fr->datalen);
00097       if (res != fr->datalen) {
00098          ast_log(LOG_WARNING, "Only wrote %d of %d bytes: %s\n", res, fr->datalen, strerror(errno));
00099          return -1;
00100       }
00101    }
00102    return res;
00103 }

static int load_module ( void   )  [static]

Definition at line 115 of file format_jpeg.c.

References ast_image_register().

00116 {
00117    return ast_image_register(&jpeg_format);
00118 }

static int unload_module ( void   )  [static]

Definition at line 120 of file format_jpeg.c.

References ast_image_unregister().

00121 {
00122    ast_image_unregister(&jpeg_format);
00123 
00124    return 0;
00125 }  


Variable Documentation

struct ast_imager jpeg_format [static]

Definition at line 105 of file format_jpeg.c.


Generated on Tue Sep 30 01:19:57 2008 for Asterisk - the Open Source PBX by  doxygen 1.5.6