1 /* $Id$ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19 #ifndef __PJMEDIA_AVI_STREAM_H__
20 #define __PJMEDIA_AVI_STREAM_H__
21 
22 /**
23  * @file avi_stream.h
24  * @brief AVI file player.
25  */
26 #include <pjmedia/port.h>
27 
28 
29 
30 PJ_BEGIN_DECL
31 
32 
33 /**
34  * @defgroup PJMEDIA_FILE_PLAY AVI File Player
35  * @ingroup PJMEDIA_PORT
36  * @brief Video and audio playback from AVI file
37  * @{
38  */
39 
40 /**
41  * AVI file player options.
42  */
43 enum pjmedia_avi_file_player_option
44 {
45     /**
46      * Tell the file player to return NULL frame when the whole
47      * file has been played.
48      */
49     PJMEDIA_AVI_FILE_NO_LOOP = 1
50 };
51 
52 /**
53  * AVI stream data type.
54  */
55 typedef pjmedia_port pjmedia_avi_stream;
56 
57 /**
58  * Opaque data type for AVI streams. AVI streams is a collection of
59  * zero or more AVI stream.
60  */
61 typedef struct pjmedia_avi_streams pjmedia_avi_streams;
62 
63 /**
64  * Create avi streams to play an AVI file. AVI player supports
65  * reading AVI file with uncompressed video format and
66  * 16 bit PCM or compressed G.711 A-law/U-law audio format.
67  *
68  * @param pool		Pool to create the streams.
69  * @param filename	File name to open.
70  * @param flags		Avi streams creation flags.
71  * @param p_streams	Pointer to receive the avi streams instance.
72  *
73  * @return		PJ_SUCCESS on success.
74  */
75 PJ_DECL(pj_status_t)
76 pjmedia_avi_player_create_streams(pj_pool_t *pool,
77                                   const char *filename,
78                                   unsigned flags,
79                                   pjmedia_avi_streams **p_streams);
80 
81 /**
82  * Get the number of AVI stream.
83  *
84  * @param streams	The AVI streams.
85  *
86  * @return		The number of AVI stream.
87  */
88 PJ_DECL(unsigned)
89 pjmedia_avi_streams_get_num_streams(pjmedia_avi_streams *streams);
90 
91 /**
92  * Return the idx-th stream of the AVI streams.
93  *
94  * @param streams	The AVI streams.
95  * @param idx	        The stream index.
96  *
97  * @return		The AVI stream or NULL if it does not exist.
98  */
99 PJ_DECL(pjmedia_avi_stream *)
100 pjmedia_avi_streams_get_stream(pjmedia_avi_streams *streams,
101                                unsigned idx);
102 
103 /**
104  * Return an AVI stream with a certain media type from the AVI streams.
105  *
106  * @param streams	The AVI streams.
107  * @param start_idx     The starting index.
108  * @param media_type    The media type of the stream.
109  *
110  * @return		The AVI stream or NULL if it does not exist.
111  */
112 PJ_DECL(pjmedia_avi_stream *)
113 pjmedia_avi_streams_get_stream_by_media(pjmedia_avi_streams *streams,
114                                         unsigned start_idx,
115                                         pjmedia_type media_type);
116 
117 /**
118  * Return the media port of an AVI stream.
119  *
120  * @param stream	The AVI stream.
121  *
122  * @return		The media port.
123  */
124 PJ_INLINE(pjmedia_port *)
pjmedia_avi_stream_get_port(pjmedia_avi_stream * stream)125 pjmedia_avi_stream_get_port(pjmedia_avi_stream *stream)
126 {
127     return (pjmedia_port *)stream;
128 }
129 
130 /**
131  * Get the data length, in bytes.
132  *
133  * @param stream        The AVI stream.
134  *
135  * @return		The length of the data, in bytes. Upon error it will
136  *			return negative value.
137  */
138 PJ_DECL(pj_ssize_t) pjmedia_avi_stream_get_len(pjmedia_avi_stream *stream);
139 
140 
141 #if !DEPRECATED_FOR_TICKET_2251
142 /**
143  * Register a callback to be called when the file reading has reached the
144  * end of file. If the file is set to play repeatedly, then the callback
145  * will be called multiple times. Note that only one callback can be
146  * registered for each AVI stream.
147  *
148  * @param stream	The AVI stream.
149  * @param user_data	User data to be specified in the callback
150  * @param cb		Callback to be called. If the callback returns non-
151  *			PJ_SUCCESS, the playback will stop. Note that if
152  *			application destroys the file port in the callback,
153  *			it must return non-PJ_SUCCESS here.
154  *
155  * @return		PJ_SUCCESS on success.
156  */
157 PJ_DECL(pj_status_t)
158 pjmedia_avi_stream_set_eof_cb(pjmedia_avi_stream *stream,
159 			      void *user_data,
160 			      pj_status_t (*cb)(pjmedia_avi_stream *stream,
161 					        void *usr_data));
162 #endif
163 
164 
165 /**
166  * Register a callback to be called when the file reading has reached the
167  * end of file. If the file is set to play repeatedly, then the callback
168  * will be called multiple times. Note that only one callback can be
169  * registered for each AVI stream.
170  *
171  * @param stream	The AVI stream.
172  * @param user_data	User data to be specified in the callback
173  * @param cb		Callback to be called. Note that if
174  *			application wishes to stop the playback, it
175  *			can disconnect the port in the callback, and
176  *			only after all connections have been removed
177  *			could the application safely destroy the port.
178  *
179  * @return		PJ_SUCCESS on success.
180  */
181 PJ_DECL(pj_status_t)
182 pjmedia_avi_stream_set_eof_cb2(pjmedia_avi_stream *stream,
183 			       void *user_data,
184 			       void (*cb)(pjmedia_avi_stream *stream,
185 					  void *usr_data));
186 
187 
188 /**
189  * @}
190  */
191 
192 
193 PJ_END_DECL
194 
195 
196 #endif	/* __PJMEDIA_AVI_STREAM_H__ */
197