blob: f9766f6557e02641a0b41d9a8e65307811c6b73b [file] [log] [blame]
Benny Prijonoc45d9512010-12-10 11:04:30 +00001/* $Id$ */
2/*
3 * Copyright (C) 2008-2010 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_VIDEODEV_VIDEODEV_H__
20#define __PJMEDIA_VIDEODEV_VIDEODEV_H__
21
22/**
23 * @file videodev.h
24 * @brief Video device API.
25 */
26#include <pjmedia-videodev/config.h>
27#include <pjmedia-videodev/errno.h>
28#include <pjmedia/frame.h>
29#include <pjmedia/format.h>
30#include <pj/pool.h>
31
32
33PJ_BEGIN_DECL
34
35/**
36 * @defgroup video_device_reference Video Device API Reference
37 * @ingroup video_device_api
38 * @brief API Reference
39 * @{
40 */
41
42/**
43 * Type for device index.
44 */
45typedef pj_int32_t pjmedia_vid_dev_index;
46
47/**
48 * Device index constants.
49 */
50enum
51{
52 /**
53 * Constant to denote default capture device
54 */
55 PJMEDIA_VID_DEFAULT_CAPTURE_DEV = -1,
56
57 /**
58 * Constant to denote default render device
59 */
60 PJMEDIA_VID_DEFAULT_RENDER_DEV = -2,
61
62 /**
63 * Constant to denote invalid device index.
64 */
65 PJMEDIA_VID_INVALID_DEV = -3
66};
67
68
69/**
70 * This enumeration identifies various video device capabilities. These video
71 * capabilities indicates what features are supported by the underlying
72 * video device implementation.
73 *
74 * Applications get these capabilities in the #pjmedia_vid_dev_info structure.
75 *
76 * Application can also set the specific features/capabilities when opening
77 * the video stream by setting the \a flags member of #pjmedia_vid_param
78 * structure.
79 *
80 * Once video stream is running, application can also retrieve or set some
81 * specific video capability, by using #pjmedia_vid_stream_get_cap() and
82 * #pjmedia_vid_stream_set_cap() and specifying the desired capability. The
83 * value of the capability is specified as pointer, and application needs to
84 * supply the pointer with the correct value, according to the documentation
85 * of each of the capability.
86 */
87typedef enum pjmedia_vid_dev_cap
88{
89 /**
90 * Support for video formats. The value of this capability
91 * is represented by #pjmedia_format structure.
92 */
93 PJMEDIA_VID_DEV_CAP_FORMAT = 1,
94
95 /**
96 * Support for video input scaling
97 */
98 PJMEDIA_VID_DEV_CAP_INPUT_SCALE = 2,
99
100 /**
101 * The application can provide a window for the renderer to
102 * display the video.
103 */
104 PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW = 4,
105
106 /**
107 * Support for resizing video output. This capability SHOULD be
108 * implemented by renderer, to alter the video output dimension on the fly.
109 * Value is pjmedia_rect_size.
110 */
111 PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE = 8,
112
113 /**
114 * End of capability
115 */
116 PJMEDIA_VID_DEV_CAP_MAX = 16384
117
118} pjmedia_vid_dev_cap;
119
120/**
121 * Device information structure returned by #pjmedia_vid_dev_get_info().
122 */
123typedef struct pjmedia_vid_dev_info
124{
125 /** The device name */
126 char name[64];
127
128 /** The underlying driver name */
129 char driver[32];
130
131 /**
132 * The supported direction of the video device, i.e. whether it supports
133 * capture only, render only, or both.
134 */
135 pjmedia_dir dir;
136
137 /** Specify whether the device supports callback */
138 pj_bool_t has_callback;
139
140 /** Device capabilities, as bitmask combination of #pjmedia_vid_dev_cap */
141 unsigned caps;
142
143 /** Number of video formats supported by this device */
144 unsigned fmt_cnt;
145
146 /**
147 * Array of supported video formats. Some fields in each supported video
148 * format may be set to zero or of "unknown" value, to indicate that the
149 * value is unknown or should be ignored. When these value are not set
150 * to zero, it indicates that the exact format combination is being used.
151 */
152 pjmedia_format *fmt;
153
154} pjmedia_vid_dev_info;
155
156
157/** Forward declaration for pjmedia_vid_stream */
158typedef struct pjmedia_vid_stream pjmedia_vid_stream;
159
160typedef enum pjmedia_event_type
161{
162 PJMEDIA_EVENT_NONE,
163 PJMEDIA_EVENT_MOUSEBUTTONDOWN,
164 PJMEDIA_EVENT_WINDOW_RESIZE,
165 PJMEDIA_EVENT_WINDOW_FULLSCREEN,
166 PJMEDIA_EVENT_WINDOW_CLOSE,
167} pjmedia_event_type;
168
169typedef struct pjmedia_vid_event
170{
171 pjmedia_event_type event_type;
172 long lparam;
173 void *pparam;
174} pjmedia_vid_event;
175
176
177typedef struct pjmedia_vid_cb
178{
179 /**
180 * This callback is called by capturer stream when it has captured the
181 * whole packet worth of video samples.
182 *
183 * @param stream The video stream.
184 * @param user_data User data associated with the stream.
185 * @param frame Captured frame.
186 *
187 * @return Returning non-PJ_SUCCESS will cause the video
188 * stream to stop
189 */
190 pj_status_t (*capture_cb)(pjmedia_vid_stream *stream,
191 void *user_data,
192 pjmedia_frame *frame);
193
194 /**
195 * This callback is called by renderer stream when it needs additional
196 * data to be rendered by the device. Application must fill in the whole
197 * of output buffer with video samples.
198 *
199 * The frame argument contains the following values:
200 * - timestamp Rendering timestamp, in samples.
201 * - buf Buffer to be filled out by application.
202 * - size The size requested in bytes, which will be equal
203 * to the size of one whole packet.
204 *
205 * @param stream The video stream.
206 * @param user_data User data associated with the stream.
207 * @param frame Video frame, which buffer is to be filled in by
208 * the application.
209 *
210 * @return Returning non-PJ_SUCCESS will cause the video
211 * stream to stop
212 */
213 pj_status_t (*render_cb)(pjmedia_vid_stream *stream,
214 void *user_data,
215 pjmedia_frame *frame);
216
217 /**
218 * This callback is called by the stream to report the occurence of an
219 * event to the application.
220 *
221 * @param stream The video stream.
222 * @param user_data User data associated with the stream.
223 * @param event The event.
224 *
225 * @return Return PJ_SUCCESS will invoke the video stream's
226 * default event-handler (if any), otherwise the
227 * video stream will ignore the particular event.
228 */
229 pj_status_t (*on_event_cb)(pjmedia_vid_stream *stream,
230 void *user_data,
231 pjmedia_vid_event *event);
232
233} pjmedia_vid_cb;
234
235
236/**
237 * This structure specifies the parameters to open the video stream.
238 */
239typedef struct pjmedia_vid_param
240{
241 /**
242 * The video direction. This setting is mandatory.
243 */
244 pjmedia_dir dir;
245
246 /**
247 * The video capture device ID. This setting is mandatory if the video
248 * direction includes input/capture direction.
249 */
250 pjmedia_vid_dev_index cap_id;
251
252 /**
253 * The video render device ID. This setting is mandatory if the video
254 * direction includes output/render direction.
255 */
256 pjmedia_vid_dev_index rend_id;
257
258 /**
259 * Video clock rate. This setting is mandatory if the video
260 * direction includes input/capture direction
261 */
262 unsigned clock_rate;
263
264 /**
265 * Video frame rate. This setting is mandatory if the video
266 * direction includes input/capture direction
267 */
Sauw Mingb1b17d22010-12-20 11:02:48 +0000268// pjmedia_ratio frame_rate;
Benny Prijonoc45d9512010-12-10 11:04:30 +0000269
270 /**
271 * This flags specifies which of the optional settings are valid in this
272 * structure. The flags is bitmask combination of pjmedia_vid_dev_cap.
273 */
274 unsigned flags;
275
276 /**
277 * Set the video format. This setting is mandatory.
278 */
279 pjmedia_format fmt;
280
281 /**
282 * Window for the renderer to display the video. This setting is optional,
283 * and will only be used if PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW is set in
284 * the flags.
285 */
286 void *window;
287
288 /**
289 * Video display size. This setting is optional, and will only be used
290 * if PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE is set in the flags.
291 */
292 pjmedia_rect_size disp_size;
293
294} pjmedia_vid_param;
295
296
297/** Forward declaration for video device factory */
298typedef struct pjmedia_vid_dev_factory pjmedia_vid_dev_factory;
299
300/* typedef for factory creation function */
301typedef pjmedia_vid_dev_factory*
302(*pjmedia_vid_dev_factory_create_func_ptr)(pj_pool_factory*);
303
304
305/**
306 * Get string info for the specified capability.
307 *
308 * @param cap The capability ID.
309 * @param p_desc Optional pointer which will be filled with longer
310 * description about the capability.
311 *
312 * @return Capability name.
313 */
314PJ_DECL(const char*) pjmedia_vid_dev_cap_name(pjmedia_vid_dev_cap cap,
315 const char **p_desc);
316
317
318/**
319 * Set a capability field value in #pjmedia_vid_param structure. This will
320 * also set the flags field for the specified capability in the structure.
321 *
322 * @param param The structure.
323 * @param cap The video capability which value is to be set.
324 * @param pval Pointer to value. Please see the type of value to
325 * be supplied in the pjmedia_vid_dev_cap documentation.
326 *
327 * @return PJ_SUCCESS on successful operation or the appropriate
328 * error code.
329 */
330PJ_DECL(pj_status_t) pjmedia_vid_param_set_cap(pjmedia_vid_param *param,
331 pjmedia_vid_dev_cap cap,
332 const void *pval);
333
334
335/**
336 * Get a capability field value from #pjmedia_vid_param structure. This
337 * function will return PJMEDIA_EVID_INVCAP error if the flag for that
338 * capability is not set in the flags field in the structure.
339 *
340 * @param param The structure.
341 * @param cap The video capability which value is to be retrieved.
342 * @param pval Pointer to value. Please see the type of value to
343 * be supplied in the pjmedia_vid_dev_cap documentation.
344 *
345 * @return PJ_SUCCESS on successful operation or the appropriate
346 * error code.
347 */
348PJ_DECL(pj_status_t) pjmedia_vid_param_get_cap(const pjmedia_vid_param *param,
349 pjmedia_vid_dev_cap cap,
350 void *pval);
351
352/**
353 * Initialize the video subsystem. This will register all supported video
354 * device factories to the video subsystem. This function may be called
355 * more than once, but each call to this function must have the
356 * corresponding #pjmedia_vid_subsys_shutdown() call.
357 *
358 * @param pf The pool factory.
359 *
360 * @return PJ_SUCCESS on successful operation or the appropriate
361 * error code.
362 */
363PJ_DECL(pj_status_t) pjmedia_vid_subsys_init(pj_pool_factory *pf);
364
365
366/**
367 * Get the pool factory registered to the video subsystem.
368 *
369 * @return The pool factory.
370 */
371PJ_DECL(pj_pool_factory*) pjmedia_vid_subsys_get_pool_factory(void);
372
373
374/**
375 * Shutdown the video subsystem. This will destroy all video device factories
376 * registered in the video subsystem. Note that currently opened video streams
377 * may or may not be closed, depending on the implementation of the video
378 * device factories.
379 *
380 * @return PJ_SUCCESS on successful operation or the appropriate
381 * error code.
382 */
383PJ_DECL(pj_status_t) pjmedia_vid_subsys_shutdown(void);
384
385
386/**
387 * Register a supported video device factory to the video subsystem. This
388 * function can only be called after calling #pjmedia_vid_subsys_init().
389 *
390 * @param vdf The video device factory.
391 *
392 * @return PJ_SUCCESS on successful operation or the appropriate
393 * error code.
394 */
395PJ_DECL(pj_status_t)
396pjmedia_vid_register_factory(pjmedia_vid_dev_factory_create_func_ptr vdf);
397
398
399/**
400 * Unregister an video device factory from the video subsystem. This
401 * function can only be called after calling #pjmedia_vid_subsys_init().
402 * Devices from this factory will be unlisted. If a device from this factory
403 * is currently in use, then the behavior is undefined.
404 *
405 * @param vdf The video device factory.
406 *
407 * @return PJ_SUCCESS on successful operation or the appropriate
408 * error code.
409 */
410PJ_DECL(pj_status_t)
411pjmedia_vid_unregister_factory(pjmedia_vid_dev_factory_create_func_ptr vdf);
412
413
414/**
415 * Get the number of video devices installed in the system.
416 *
417 * @return The number of video devices installed in the system.
418 */
419PJ_DECL(unsigned) pjmedia_vid_dev_count(void);
420
421
422/**
423 * Get device information.
424 *
425 * @param id The video device ID.
426 * @param info The device information which will be filled in by this
427 * function once it returns successfully.
428 *
429 * @return PJ_SUCCESS on successful operation or the appropriate
430 * error code.
431 */
432PJ_DECL(pj_status_t) pjmedia_vid_dev_get_info(pjmedia_vid_dev_index id,
433 pjmedia_vid_dev_info *info);
434
435
436/**
437 * Lookup device index based on the driver and device name.
438 *
439 * @param drv_name The driver name.
440 * @param dev_name The device name.
441 * @param id Pointer to store the returned device ID.
442 *
443 * @return PJ_SUCCESS if the device can be found.
444 */
445PJ_DECL(pj_status_t) pjmedia_vid_dev_lookup(const char *drv_name,
446 const char *dev_name,
447 pjmedia_vid_dev_index *id);
448
449
450/**
451 * Initialize the video device parameters with default values for the
452 * specified device.
453 *
454 * @param id The video device ID.
455 * @param param The video device parameters which will be initialized
456 * by this function once it returns successfully.
457 *
458 * @return PJ_SUCCESS on successful operation or the appropriate
459 * error code.
460 */
461PJ_DECL(pj_status_t) pjmedia_vid_dev_default_param(pj_pool_t *pool,
462 pjmedia_vid_dev_index id,
463 pjmedia_vid_param *param);
464
465
466/**
467 * Open video stream object using the specified parameters.
468 *
469 * @param param Sound device parameters to be used for the stream.
470 * @param cb Pointer to structure containing video stream
471 * callbacks.
472 * @param user_data Arbitrary user data, which will be given back in the
473 * callbacks.
474 * @param p_strm Pointer to receive the video stream.
475 *
476 * @return PJ_SUCCESS on successful operation or the appropriate
477 * error code.
478 */
479PJ_DECL(pj_status_t) pjmedia_vid_stream_create(const pjmedia_vid_param *param,
480 const pjmedia_vid_cb *cb,
481 void *user_data,
482 pjmedia_vid_stream **p_strm);
483
484/**
485 * Get the running parameters for the specified video stream.
486 *
487 * @param strm The video stream.
488 * @param param Video stream parameters to be filled in by this
489 * function once it returns successfully.
490 *
491 * @return PJ_SUCCESS on successful operation or the appropriate
492 * error code.
493 */
494PJ_DECL(pj_status_t) pjmedia_vid_stream_get_param(pjmedia_vid_stream *strm,
495 pjmedia_vid_param *param);
496
497/**
498 * Get the value of a specific capability of the video stream.
499 *
500 * @param strm The video stream.
501 * @param cap The video capability which value is to be retrieved.
502 * @param value Pointer to value to be filled in by this function
503 * once it returns successfully. Please see the type
504 * of value to be supplied in the pjmedia_vid_dev_cap
505 * documentation.
506 *
507 * @return PJ_SUCCESS on successful operation or the appropriate
508 * error code.
509 */
510PJ_DECL(pj_status_t) pjmedia_vid_stream_get_cap(pjmedia_vid_stream *strm,
511 pjmedia_vid_dev_cap cap,
512 void *value);
513
514/**
515 * Set the value of a specific capability of the video stream.
516 *
517 * @param strm The video stream.
518 * @param cap The video capability which value is to be set.
519 * @param value Pointer to value. Please see the type of value to
520 * be supplied in the pjmedia_vid_dev_cap documentation.
521 *
522 * @return PJ_SUCCESS on successful operation or the appropriate
523 * error code.
524 */
525PJ_DECL(pj_status_t) pjmedia_vid_stream_set_cap(pjmedia_vid_stream *strm,
526 pjmedia_vid_dev_cap cap,
527 const void *value);
528
529/**
530 * Start the stream.
531 *
532 * @param strm The video stream.
533 *
534 * @return PJ_SUCCESS on successful operation or the appropriate
535 * error code.
536 */
537PJ_DECL(pj_status_t) pjmedia_vid_stream_start(pjmedia_vid_stream *strm);
538
539/* Get/put frame API for passive stream */
540PJ_DECL(pj_status_t) pjmedia_vid_stream_get_frame(pjmedia_vid_stream *strm,
541 pjmedia_frame *frame);
542
543PJ_DECL(pj_status_t) pjmedia_vid_stream_put_frame(pjmedia_vid_stream *strm,
544 const pjmedia_frame *frame);
545
546/**
547 * Stop the stream.
548 *
549 * @param strm The video stream.
550 *
551 * @return PJ_SUCCESS on successful operation or the appropriate
552 * error code.
553 */
554PJ_DECL(pj_status_t) pjmedia_vid_stream_stop(pjmedia_vid_stream *strm);
555
556/**
557 * Destroy the stream.
558 *
559 * @param strm The video stream.
560 *
561 * @return PJ_SUCCESS on successful operation or the appropriate
562 * error code.
563 */
564PJ_DECL(pj_status_t) pjmedia_vid_stream_destroy(pjmedia_vid_stream *strm);
565
566
567/**
568 * @}
569 */
570
571PJ_END_DECL
572
573
574#endif /* __PJMEDIA_VIDEODEV_VIDEODEV_H__ */