#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <sys/time.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "asterisk.h"
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/sched.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
Include dependency graph for format_h263.c:
Go to the source code of this file.
Data Structures | |
struct | ast_filestream |
Functions | |
AST_MUTEX_DEFINE_STATIC (h263_lock) | |
char * | description () |
Provides a description of the module. | |
static void | h263_close (struct ast_filestream *s) |
static char * | h263_getcomment (struct ast_filestream *s) |
static struct ast_filestream * | h263_open (FILE *f) |
static struct ast_frame * | h263_read (struct ast_filestream *s, int *whennext) |
static struct ast_filestream * | h263_rewrite (FILE *f, const char *comment) |
static int | h263_seek (struct ast_filestream *fs, long sample_offset, int whence) |
static long | h263_tell (struct ast_filestream *fs) |
static int | h263_trunc (struct ast_filestream *fs) |
static int | h263_write (struct ast_filestream *fs, struct ast_frame *f) |
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 = "Raw h263 data" |
static char * | exts = "h263" |
static int | glistcnt = 0 |
static char * | name = "h263" |
Definition in file format_h263.c.
|
|
|
Provides a description of the module.
Definition at line 272 of file format_h263.c. References desc. 00273 { 00274 return desc; 00275 }
|
|
Definition at line 128 of file format_h263.c. References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_update_use_count(), ast_filestream::f, free, glistcnt, and LOG_WARNING. Referenced by load_module(). 00129 { 00130 if (ast_mutex_lock(&h263_lock)) { 00131 ast_log(LOG_WARNING, "Unable to lock h263 list\n"); 00132 return; 00133 } 00134 glistcnt--; 00135 ast_mutex_unlock(&h263_lock); 00136 ast_update_use_count(); 00137 fclose(s->f); 00138 free(s); 00139 s = NULL; 00140 }
|
|
Definition at line 219 of file format_h263.c. Referenced by load_module(). 00220 {
00221 return NULL;
00222 }
|
|
Definition at line 72 of file format_h263.c. References AST_FORMAT_H263, AST_FRAME_VIDEO, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_update_use_count(), free, glistcnt, LOG_WARNING, malloc, and name. Referenced by load_module(). 00073 { 00074 /* We don't have any header to read or anything really, but 00075 if we did, it would go here. We also might want to check 00076 and be sure it's a valid file. */ 00077 struct ast_filestream *tmp; 00078 unsigned int ts; 00079 int res; 00080 if ((res = fread(&ts, 1, sizeof(ts), f)) < sizeof(ts)) { 00081 ast_log(LOG_WARNING, "Empty file!\n"); 00082 return NULL; 00083 } 00084 00085 if ((tmp = malloc(sizeof(struct ast_filestream)))) { 00086 memset(tmp, 0, sizeof(struct ast_filestream)); 00087 if (ast_mutex_lock(&h263_lock)) { 00088 ast_log(LOG_WARNING, "Unable to lock h263 list\n"); 00089 free(tmp); 00090 return NULL; 00091 } 00092 tmp->f = f; 00093 tmp->fr.data = tmp->h263; 00094 tmp->fr.frametype = AST_FRAME_VIDEO; 00095 tmp->fr.subclass = AST_FORMAT_H263; 00096 /* datalen will vary for each frame */ 00097 tmp->fr.src = name; 00098 tmp->fr.mallocd = 0; 00099 glistcnt++; 00100 ast_mutex_unlock(&h263_lock); 00101 ast_update_use_count(); 00102 } 00103 return tmp; 00104 }
|
|
Definition at line 142 of file format_h263.c. References AST_FORMAT_H263, AST_FRAME_VIDEO, AST_FRIENDLY_OFFSET, ast_log(), ast_frame::data, ast_frame::datalen, ast_frame::delivery, ast_filestream::f, ast_filestream::fr, ast_frame::frametype, ast_filestream::h263, ast_filestream::lastts, LOG_WARNING, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, and ast_frame::subclass. Referenced by load_module(). 00143 { 00144 int res; 00145 int mark=0; 00146 unsigned short len; 00147 unsigned int ts; 00148 /* Send a frame from the file to the appropriate channel */ 00149 s->fr.frametype = AST_FRAME_VIDEO; 00150 s->fr.subclass = AST_FORMAT_H263; 00151 s->fr.offset = AST_FRIENDLY_OFFSET; 00152 s->fr.mallocd = 0; 00153 s->fr.data = s->h263; 00154 if ((res = fread(&len, 1, sizeof(len), s->f)) < 1) { 00155 return NULL; 00156 } 00157 len = ntohs(len); 00158 if (len & 0x8000) { 00159 mark = 1; 00160 } 00161 len &= 0x7fff; 00162 if (len > sizeof(s->h263)) { 00163 ast_log(LOG_WARNING, "Length %d is too long\n", len); 00164 } 00165 if ((res = fread(s->h263, 1, len, s->f)) != len) { 00166 if (res) 00167 ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); 00168 return NULL; 00169 } 00170 s->fr.samples = s->lastts; 00171 s->fr.datalen = len; 00172 s->fr.subclass |= mark; 00173 s->fr.delivery.tv_sec = 0; 00174 s->fr.delivery.tv_usec = 0; 00175 if ((res = fread(&ts, 1, sizeof(ts), s->f)) == sizeof(ts)) { 00176 s->lastts = ntohl(ts); 00177 *whennext = s->lastts * 4/45; 00178 } else 00179 *whennext = 0; 00180 return &s->fr; 00181 }
|
|
Definition at line 106 of file format_h263.c. References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_update_use_count(), free, glistcnt, LOG_WARNING, and malloc. Referenced by load_module(). 00107 { 00108 /* We don't have any header to read or anything really, but 00109 if we did, it would go here. We also might want to check 00110 and be sure it's a valid file. */ 00111 struct ast_filestream *tmp; 00112 if ((tmp = malloc(sizeof(struct ast_filestream)))) { 00113 memset(tmp, 0, sizeof(struct ast_filestream)); 00114 if (ast_mutex_lock(&h263_lock)) { 00115 ast_log(LOG_WARNING, "Unable to lock h263 list\n"); 00116 free(tmp); 00117 return NULL; 00118 } 00119 tmp->f = f; 00120 glistcnt++; 00121 ast_mutex_unlock(&h263_lock); 00122 ast_update_use_count(); 00123 } else 00124 ast_log(LOG_WARNING, "Out of memory\n"); 00125 return tmp; 00126 }
|
|
Definition at line 224 of file format_h263.c. Referenced by load_module(). 00225 { 00226 /* No way Jose */ 00227 return -1; 00228 }
|
|
Definition at line 238 of file format_h263.c. References ast_filestream::f, and offset. Referenced by load_module(). 00239 { 00240 /* XXX This is totally bogus XXX */ 00241 off_t offset; 00242 offset = ftell(fs->f); 00243 return (offset/20)*160; 00244 }
|
|
Definition at line 230 of file format_h263.c. References ast_filestream::f. Referenced by load_module(). 00231 { 00232 /* Truncate file to current length */ 00233 if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0) 00234 return -1; 00235 return 0; 00236 }
|
|
Definition at line 183 of file format_h263.c. References AST_FORMAT_H263, AST_FRAME_VIDEO, ast_log(), ast_frame::data, ast_frame::datalen, ast_filestream::f, ast_frame::frametype, LOG_WARNING, ast_frame::samples, and ast_frame::subclass. Referenced by load_module(). 00184 { 00185 int res; 00186 unsigned int ts; 00187 unsigned short len; 00188 int subclass; 00189 int mark=0; 00190 if (f->frametype != AST_FRAME_VIDEO) { 00191 ast_log(LOG_WARNING, "Asked to write non-video frame!\n"); 00192 return -1; 00193 } 00194 subclass = f->subclass; 00195 if (subclass & 0x1) 00196 mark=0x8000; 00197 subclass &= ~0x1; 00198 if (subclass != AST_FORMAT_H263) { 00199 ast_log(LOG_WARNING, "Asked to write non-h263 frame (%d)!\n", f->subclass); 00200 return -1; 00201 } 00202 ts = htonl(f->samples); 00203 if ((res = fwrite(&ts, 1, sizeof(ts), fs->f)) != sizeof(ts)) { 00204 ast_log(LOG_WARNING, "Bad write (%d/4): %s\n", res, strerror(errno)); 00205 return -1; 00206 } 00207 len = htons(f->datalen | mark); 00208 if ((res = fwrite(&len, 1, sizeof(len), fs->f)) != sizeof(len)) { 00209 ast_log(LOG_WARNING, "Bad write (%d/2): %s\n", res, strerror(errno)); 00210 return -1; 00211 } 00212 if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) { 00213 ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno)); 00214 return -1; 00215 } 00216 return 0; 00217 }
|
|
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; }
Definition at line 278 of file format_h263.c. References ASTERISK_GPL_KEY. 00279 { 00280 return ASTERISK_GPL_KEY; 00281 }
|
|
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.
Definition at line 246 of file format_h263.c. References AST_FORMAT_H263, ast_format_register(), exts, h263_close(), h263_getcomment(), h263_open(), h263_read(), h263_rewrite(), h263_seek(), h263_tell(), h263_trunc(), h263_write(), and name. 00247 { 00248 return ast_format_register(name, exts, AST_FORMAT_H263, 00249 h263_open, 00250 h263_rewrite, 00251 h263_write, 00252 h263_seek, 00253 h263_trunc, 00254 h263_tell, 00255 h263_read, 00256 h263_close, 00257 h263_getcomment); 00258 00259 00260 }
|
|
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).
Definition at line 262 of file format_h263.c. References ast_format_unregister(), and name. 00263 { 00264 return ast_format_unregister(name); 00265 }
|
|
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.
Definition at line 267 of file format_h263.c. References glistcnt. 00268 { 00269 return glistcnt; 00270 }
|
|
Definition at line 69 of file format_h263.c. |
|
Definition at line 70 of file format_h263.c. |
|
Definition at line 66 of file format_h263.c. |
|
Definition at line 68 of file format_h263.c. |