Asterisk - The Open Source Telephony Project GIT-master-f36a736
mod_format.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2006, Digium, Inc.
5 *
6 * Mark Spencer <markster@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 * \brief Header for providers of file and format handling routines.
21 * Clients of these routines should include "asterisk/file.h" instead.
22 */
23
24#ifndef _ASTERISK_MOD_FORMAT_H
25#define _ASTERISK_MOD_FORMAT_H
26
27#include "asterisk/file.h"
28#include "asterisk/frame.h"
29
30#if defined(__cplusplus) || defined(c_plusplus)
31extern "C" {
32#endif
33
34/*! \brief
35 * Each supported file format is described by the following structure.
36 *
37 * Not all are necessary, the support routine implement default
38 * values for some of them.
39 * A handler typically fills a structure initializing the desired
40 * fields, and then calls ast_format_def_register() with the (readonly)
41 * structure as an argument.
42 */
44 char name[80]; /*!< Name of format */
45 char exts[80]; /*!< Extensions (separated by | if more than one)
46 * this format can read. First is assumed for writing (e.g. .mp3) */
47 char mime_types[80]; /*!< MIME Types related to the format (separated by | if more than one)*/
48 struct ast_format *format; /*!< Format of frames it uses/provides (one only) */
49 /*!
50 * \brief Prepare an input stream for playback.
51 * \return 0 on success, -1 on error.
52 * The FILE is already open (in s->f) so this function only needs to perform
53 * any applicable validity checks on the file. If none is required, the
54 * function can be omitted.
55 */
56 int (*open)(struct ast_filestream *s);
57 /*!
58 * \brief Prepare a stream for output, and comment it appropriately if applicable.
59 * \return 0 on success, -1 on error.
60 * Same as the open, the FILE is already open so the function just needs to
61 * prepare any header and other fields, if any.
62 * The function can be omitted if nothing is needed.
63 */
64 int (*rewrite)(struct ast_filestream *s, const char *comment);
65 /*! Write a frame to a channel */
66 int (*write)(struct ast_filestream *, struct ast_frame *);
67 /*! seek num samples into file, whence - like a normal seek but with offset in samples */
68 int (*seek)(struct ast_filestream *, off_t, int);
69 int (*trunc)(struct ast_filestream *fs); /*!< trunc file to current position */
70 off_t (*tell)(struct ast_filestream *fs); /*!< tell current position */
71 /*! Read the next frame from the filestream (if available) and report
72 * when to get next frame (in samples)
73 */
74 struct ast_frame * (*read)(struct ast_filestream *, int *whennext);
75 /*! Do any closing actions, if any. The descriptor and structure are closed
76 * and destroyed by the generic routines, so they must not be done here. */
77 void (*close)(struct ast_filestream *);
78 char * (*getcomment)(struct ast_filestream *); /*!< Retrieve file comment */
79
81
82 /*!
83 * If the handler needs a buffer (for read, typically)
84 * and/or a private descriptor, put here the
85 * required size (in bytes) and the support routine will allocate them
86 * for you, pointed by s->buf and s->private, respectively.
87 * When allocating a buffer, remember to leave AST_FRIENDLY_OFFSET
88 * spare bytes at the bginning.
89 */
90 int buf_size; /*!< size of frame buffer, if any, aligned to 8 bytes. */
91 int desc_size; /*!< size of private descriptor, if any */
92
94};
95
96/*! \brief
97 * This structure is allocated by file.c in one chunk,
98 * together with buf_size and desc_size bytes of memory
99 * to be used for private purposes (e.g. buffers etc.)
100 */
102 /*! Everybody reserves a block of AST_RESERVED_POINTERS pointers for us */
103 struct ast_format_def *fmt; /* need to write to the lock and usecnt */
104 int flags;
105 mode_t mode;
107 char *filename;
109 /*! Video file stream */
111 /*! Transparently translate from another format -- just once */
113 struct ast_translator_pvt *tr;
117 FILE *f;
118 /*!
119 * \brief frame produced by read, typically
120 * \note This frame holds a fr.subclass.format ref.
121 */
122 struct ast_frame fr;
123 char *buf; /*!< buffer pointed to by ast_frame; */
124 void *_private; /*!< pointer to private buffer */
125 const char *orig_chan_name;
127};
128
129/*!
130 * \brief Register a new file format capability.
131 * Adds a format to Asterisk's format abilities.
132 * \retval 0 on success
133 * \retval -1 on failure
134 */
135int __ast_format_def_register(const struct ast_format_def *f, struct ast_module *mod);
136#define ast_format_def_register(f) __ast_format_def_register(f, AST_MODULE_SELF)
137
138/*!
139 * \brief Unregisters a file format
140 * \param name the name of the format you wish to unregister
141 * Unregisters a format based on the name of the format.
142 * \retval 0 on success
143 * \retval -1 on failure to unregister
144 */
145int ast_format_def_unregister(const char *name);
146
147#if defined(__cplusplus) || defined(c_plusplus)
148}
149#endif
150
151#endif /* _ASTERISK_MOD_FORMAT_H */
#define comment
Definition: ael_lex.c:965
Generic File Format Support. Should be included by clients of the file handling routines....
static const char name[]
Definition: format_mp3.c:68
Asterisk internal frame definitions.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:410
int ast_format_def_unregister(const char *name)
Unregisters a file format.
Definition: file.c:162
int __ast_format_def_register(const struct ast_format_def *f, struct ast_module *mod)
Register a new file format capability. Adds a format to Asterisk's format abilities.
Definition: file.c:124
Main Channel structure associated with a channel.
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
Definition: mod_format.h:101
struct ast_filestream * vfs
Definition: mod_format.h:110
struct ast_frame fr
frame produced by read, typically
Definition: mod_format.h:122
char * realfilename
Definition: mod_format.h:108
void * _private
Definition: mod_format.h:124
char * open_filename
Definition: mod_format.h:106
char * write_buffer
Definition: mod_format.h:126
struct ast_format_def * fmt
Definition: mod_format.h:103
struct ast_channel * owner
Definition: mod_format.h:116
struct ast_format * lastwriteformat
Definition: mod_format.h:114
struct ast_trans_pvt * trans
Definition: mod_format.h:112
struct ast_translator_pvt * tr
Definition: mod_format.h:113
char * filename
Definition: mod_format.h:107
const char * orig_chan_name
Definition: mod_format.h:125
Each supported file format is described by the following structure.
Definition: mod_format.h:43
int(* trunc)(struct ast_filestream *fs)
Definition: mod_format.h:69
int(* seek)(struct ast_filestream *, off_t, int)
Definition: mod_format.h:68
int(* write)(struct ast_filestream *, struct ast_frame *)
Definition: mod_format.h:66
int(* rewrite)(struct ast_filestream *s, const char *comment)
Prepare a stream for output, and comment it appropriately if applicable.
Definition: mod_format.h:64
char name[80]
Definition: mod_format.h:44
struct ast_module * module
Definition: mod_format.h:93
char mime_types[80]
Definition: mod_format.h:47
off_t(* tell)(struct ast_filestream *fs)
Definition: mod_format.h:70
int(* open)(struct ast_filestream *s)
Prepare an input stream for playback.
Definition: mod_format.h:56
struct ast_format * format
Definition: mod_format.h:48
void(* close)(struct ast_filestream *)
Definition: mod_format.h:77
struct ast_format_def::@239 list
char exts[80]
Definition: mod_format.h:45
Definition of a media format.
Definition: format.c:43
Data structure associated with a single frame of data.
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
Definition: translate.h:213