Sun Aug 6 15:11:02 2006

Asterisk developer's documentation


Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

format_jpeg.c File Reference

JPEG File format support. More...

#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.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

char * description ()
 Provides a description of the module.
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)
char * key ()
 Returns the ASTERISK_GPL_KEY.
int load_module ()
 Initialize the module.
int unload_module ()
 Cleanup all module structures, sockets, etc.
int usecount ()
 Provides a usecount.

Variables

static char * desc = "JPEG (Joint Picture Experts Group) Image Format"
static struct ast_imager jpeg_format


Detailed Description

JPEG File format support.

Definition in file format_jpeg.c.


Function Documentation

char* description void   ) 
 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 135 of file format_jpeg.c.

References desc.

00136 {
00137    return desc;
00138 }

static int jpeg_identify int  fd  )  [static]
 

Definition at line 75 of file format_jpeg.c.

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

static struct ast_frame* jpeg_read_image int  fd,
int  len
[static]
 

Definition at line 53 of file format_jpeg.c.

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

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

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

Definition at line 87 of file format_jpeg.c.

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

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

char* key void   ) 
 

Returns the ASTERISK_GPL_KEY.

This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:

 char *key(void) {
         return ASTERISK_GPL_KEY;
 }

Returns:
ASTERISK_GPL_KEY

Definition at line 141 of file format_jpeg.c.

References ASTERISK_GPL_KEY.

00142 {
00143    return ASTERISK_GPL_KEY;
00144 }

int load_module void   ) 
 

Initialize the module.

Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.

Returns:
int Always 0.

Definition at line 118 of file format_jpeg.c.

References ast_image_register().

00119 {
00120    return ast_image_register(&jpeg_format);
00121 }

int unload_module void   ) 
 

Cleanup all module structures, sockets, etc.

This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).

Returns:
Zero on success, or non-zero on error.

Definition at line 123 of file format_jpeg.c.

References ast_image_unregister().

00124 {
00125    ast_image_unregister(&jpeg_format);
00126    return 0;
00127 }  

int usecount void   ) 
 

Provides a usecount.

This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.

Returns:
The module's usecount.

Definition at line 129 of file format_jpeg.c.

00130 {
00131    /* We never really have any users */
00132    return 0;
00133 }


Variable Documentation

char* desc = "JPEG (Joint Picture Experts Group) Image Format" [static]
 

Definition at line 50 of file format_jpeg.c.

struct ast_imager jpeg_format [static]
 

Definition at line 108 of file format_jpeg.c.


Generated on Sun Aug 6 15:11:03 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.2