blob: 77f236de8ec82d7a392b30c434f6dc1922277214 [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001/* $Id$ */
2/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#ifndef __PJMEDIA_MEM_PORT_H__
21#define __PJMEDIA_MEM_PORT_H__
22
23/**
24 * @file mem_port.h
25 * @brief Memory based media playback/capture port
26 */
27#include <pjmedia/port.h>
28
29PJ_BEGIN_DECL
30
31
32/**
33 * @defgroup PJMEDIA_MEM_PLAYER Memory/Buffer-based Playback Port
34 * @ingroup PJMEDIA_PORT
35 * @brief Media playback from a fixed size memory buffer
36 * @{
37 *
38 * A memory/buffer based playback port is used to play media from a fixed
39 * size buffer. This is useful over @ref PJMEDIA_FILE_PLAY for
40 * situation where filesystems are not available in the target system.
41 */
42
43
44/**
45 * Memory player options.
46 */
47enum pjmedia_mem_player_option
48{
49 /**
50 * Tell the memory player to return NULL frame when the whole
51 * buffer has been played instead of rewinding the buffer back
52 * to start position.
53 */
54 PJMEDIA_MEM_NO_LOOP = 1
55};
56
57
58/**
59 * Create the buffer based playback to play the media from the specified
60 * buffer.
61 *
62 * @param pool Pool to allocate memory for the port structure.
63 * @param buffer The buffer to play the media from, which should
64 * be available throughout the life time of the port.
65 * The player plays the media directly from this
66 * buffer (i.e. no copying is done).
67 * @param size The size of the buffer, in bytes.
68 * @param clock_rate Sampling rate.
69 * @param channel_count Number of channels.
70 * @param samples_per_frame Number of samples per frame.
71 * @param bits_per_sample Number of bits per sample.
72 * @param options Option flags, see #pjmedia_mem_player_option
73 * @param p_port Pointer to receive the port instance.
74 *
75 * @return PJ_SUCCESS on success, or the appropriate
76 * error code.
77 */
78PJ_DECL(pj_status_t) pjmedia_mem_player_create(pj_pool_t *pool,
79 const void *buffer,
80 pj_size_t size,
81 unsigned clock_rate,
82 unsigned channel_count,
83 unsigned samples_per_frame,
84 unsigned bits_per_sample,
85 unsigned options,
86 pjmedia_port **p_port );
87
88
89/**
90 * Register a callback to be called when the buffer reading has reached the
91 * end of buffer. If the player is set to play repeatedly, then the callback
92 * will be called multiple times. Note that only one callback can be
93 * registered for each player port.
94 *
95 * @param port The memory player port.
96 * @param user_data User data to be specified in the callback
97 * @param cb Callback to be called. If the callback returns non-
98 * PJ_SUCCESS, the playback will stop. Note that if
99 * application destroys the player port in the callback,
100 * it must return non-PJ_SUCCESS here.
101 *
102 * @return PJ_SUCCESS on success.
103 */
104PJ_DECL(pj_status_t)
105pjmedia_mem_player_set_eof_cb( pjmedia_port *port,
106 void *user_data,
107 pj_status_t (*cb)(pjmedia_port *port,
108 void *usr_data));
109
110
111/**
112 * @}
113 */
114
115/**
116 * @defgroup PJMEDIA_MEM_CAPTURE Memory/Buffer-based Capture Port
117 * @ingroup PJMEDIA_PORT
118 * @brief Media capture to fixed size memory buffer
119 * @{
120 *
121 * A memory based capture is used to save media streams to a fixed size
122 * buffer. This is useful over @ref PJMEDIA_FILE_REC for
123 * situation where filesystems are not available in the target system.
124 */
125
126/**
127 * Create media port to capture/record media into a fixed size buffer.
128 *
129 * @param pool Pool to allocate memory for the port structure.
130 * @param buffer The buffer to record the media to, which should
131 * be available throughout the life time of the port.
132 * @param size The maximum size of the buffer, in bytes.
133 * @param clock_rate Sampling rate.
134 * @param channel_count Number of channels.
135 * @param samples_per_frame Number of samples per frame.
136 * @param bits_per_sample Number of bits per sample.
137 * @param options Option flags.
138 * @param p_port Pointer to receive the port instance.
139 *
140 * @return PJ_SUCCESS on success, or the appropriate
141 * error code.
142 */
143PJ_DECL(pj_status_t) pjmedia_mem_capture_create(pj_pool_t *pool,
144 void *buffer,
145 pj_size_t size,
146 unsigned clock_rate,
147 unsigned channel_count,
148 unsigned samples_per_frame,
149 unsigned bits_per_sample,
150 unsigned options,
151 pjmedia_port **p_port);
152
153
154/**
155 * Register a callback to be called when no space left in the buffer.
156 * Note that when a callback is registered, this callback will also be
157 * called when application destroys the port and the callback has not
158 * been called before.
159 *
160 * @param port The memory recorder port.
161 * @param user_data User data to be specified in the callback
162 * @param cb Callback to be called. If the callback returns non-
163 * PJ_SUCCESS, the recording will stop. In other cases
164 * recording will be restarted and the rest of the frame
165 * will be stored starting from the beginning of the
166 * buffer. Note that if application destroys the capture
167 * port in the callback, it must return non-PJ_SUCCESS
168 * here.
169 *
170 * @return PJ_SUCCESS on success.
171 */
172PJ_DECL(pj_status_t)
173pjmedia_mem_capture_set_eof_cb(pjmedia_port *port,
174 void *user_data,
175 pj_status_t (*cb)(pjmedia_port *port,
176 void *usr_data));
177
178/**
179 * Return the current size of the recorded data in the buffer.
180 *
181 * @param port The memory recorder port.
182 * @return The size of buffer data..
183 */
184PJ_DECL(pj_size_t)
185pjmedia_mem_capture_get_size(pjmedia_port *port);
186
187
188/**
189 * @}
190 */
191
192PJ_END_DECL
193
194
195#endif /* __PJMEDIA_MEM_PORT_H__ */