Sat Aug 6 00:39:56 2011

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"

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
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_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_FIRST | AST_MODFLAG_BUILDSUM, .description = "JPEG (Joint Picture Experts Group) Image Format" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, }
static const struct ast_module_infoast_module_info = &__mod_info
static struct ast_imager jpeg_format


Detailed Description

JPEG File format support.

Definition in file format_jpeg.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 130 of file format_jpeg.c.

static void __unreg_module ( void   )  [static]

Definition at line 130 of file format_jpeg.c.

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]

Definition at line 50 of file format_jpeg.c.

References AST_FORMAT_JPEG, AST_FRAME_IMAGE, ast_frisolate(), ast_log(), errno, and LOG_WARNING.

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(), and jpeg_format.

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(), and jpeg_format.

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


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_FIRST | AST_MODFLAG_BUILDSUM, .description = "JPEG (Joint Picture Experts Group) Image Format" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 130 of file format_jpeg.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 130 of file format_jpeg.c.

struct ast_imager jpeg_format [static]

Definition at line 105 of file format_jpeg.c.

Referenced by load_module(), and unload_module().


Generated on Sat Aug 6 00:39:56 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7