blob: 836196e2aa8da885faff4ff8e5d3cf10d2ab18bf [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
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +000081 * specific video capability, by using #pjmedia_vid_dev_stream_get_cap() and
82 * #pjmedia_vid_dev_stream_set_cap() and specifying the desired capability. The
Benny Prijonoc45d9512010-12-10 11:04:30 +000083 * 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
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000157/** Forward declaration for pjmedia_vid_dev_stream */
158typedef struct pjmedia_vid_dev_stream pjmedia_vid_dev_stream;
Benny Prijonoc45d9512010-12-10 11:04:30 +0000159
160typedef enum pjmedia_event_type
161{
162 PJMEDIA_EVENT_NONE,
Sauw Ming4a20bc82011-03-01 15:55:34 +0000163 PJMEDIA_EVENT_FMT_CHANGED,
Benny Prijonoc45d9512010-12-10 11:04:30 +0000164 PJMEDIA_EVENT_MOUSEBUTTONDOWN,
165 PJMEDIA_EVENT_WINDOW_RESIZE,
166 PJMEDIA_EVENT_WINDOW_FULLSCREEN,
167 PJMEDIA_EVENT_WINDOW_CLOSE,
168} pjmedia_event_type;
169
170typedef struct pjmedia_vid_event
171{
Sauw Ming4a20bc82011-03-01 15:55:34 +0000172 pjmedia_event_type event_type;
173 union {
174 struct resize_event {
175 pjmedia_rect_size new_size;
176 } resize;
177 struct fmt_changed_event {
178 pjmedia_format new_format;
179 } fmt_change;
180 } event_desc;
Benny Prijonoc45d9512010-12-10 11:04:30 +0000181} pjmedia_vid_event;
182
183
184typedef struct pjmedia_vid_cb
185{
186 /**
187 * This callback is called by capturer stream when it has captured the
188 * whole packet worth of video samples.
189 *
190 * @param stream The video stream.
191 * @param user_data User data associated with the stream.
192 * @param frame Captured frame.
193 *
194 * @return Returning non-PJ_SUCCESS will cause the video
195 * stream to stop
196 */
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000197 pj_status_t (*capture_cb)(pjmedia_vid_dev_stream *stream,
Benny Prijonoc45d9512010-12-10 11:04:30 +0000198 void *user_data,
199 pjmedia_frame *frame);
200
201 /**
202 * This callback is called by renderer stream when it needs additional
203 * data to be rendered by the device. Application must fill in the whole
204 * of output buffer with video samples.
205 *
206 * The frame argument contains the following values:
207 * - timestamp Rendering timestamp, in samples.
208 * - buf Buffer to be filled out by application.
209 * - size The size requested in bytes, which will be equal
210 * to the size of one whole packet.
211 *
212 * @param stream The video stream.
213 * @param user_data User data associated with the stream.
214 * @param frame Video frame, which buffer is to be filled in by
215 * the application.
216 *
217 * @return Returning non-PJ_SUCCESS will cause the video
218 * stream to stop
219 */
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000220 pj_status_t (*render_cb)(pjmedia_vid_dev_stream *stream,
Benny Prijonoc45d9512010-12-10 11:04:30 +0000221 void *user_data,
222 pjmedia_frame *frame);
223
224 /**
225 * This callback is called by the stream to report the occurence of an
226 * event to the application.
227 *
228 * @param stream The video stream.
229 * @param user_data User data associated with the stream.
230 * @param event The event.
231 *
232 * @return Return PJ_SUCCESS will invoke the video stream's
233 * default event-handler (if any), otherwise the
234 * video stream will ignore the particular event.
235 */
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000236 pj_status_t (*on_event_cb)(pjmedia_vid_dev_stream *stream,
Benny Prijonoc45d9512010-12-10 11:04:30 +0000237 void *user_data,
238 pjmedia_vid_event *event);
239
240} pjmedia_vid_cb;
241
242
243/**
244 * This structure specifies the parameters to open the video stream.
245 */
246typedef struct pjmedia_vid_param
247{
248 /**
249 * The video direction. This setting is mandatory.
250 */
251 pjmedia_dir dir;
252
253 /**
254 * The video capture device ID. This setting is mandatory if the video
255 * direction includes input/capture direction.
256 */
257 pjmedia_vid_dev_index cap_id;
258
259 /**
260 * The video render device ID. This setting is mandatory if the video
261 * direction includes output/render direction.
262 */
263 pjmedia_vid_dev_index rend_id;
264
265 /**
266 * Video clock rate. This setting is mandatory if the video
267 * direction includes input/capture direction
268 */
269 unsigned clock_rate;
270
271 /**
272 * Video frame rate. This setting is mandatory if the video
273 * direction includes input/capture direction
274 */
Sauw Mingb1b17d22010-12-20 11:02:48 +0000275// pjmedia_ratio frame_rate;
Benny Prijonoc45d9512010-12-10 11:04:30 +0000276
277 /**
278 * This flags specifies which of the optional settings are valid in this
279 * structure. The flags is bitmask combination of pjmedia_vid_dev_cap.
280 */
281 unsigned flags;
282
283 /**
284 * Set the video format. This setting is mandatory.
285 */
286 pjmedia_format fmt;
287
288 /**
289 * Window for the renderer to display the video. This setting is optional,
290 * and will only be used if PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW is set in
291 * the flags.
292 */
293 void *window;
294
295 /**
296 * Video display size. This setting is optional, and will only be used
297 * if PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE is set in the flags.
298 */
299 pjmedia_rect_size disp_size;
300
301} pjmedia_vid_param;
302
303
304/** Forward declaration for video device factory */
305typedef struct pjmedia_vid_dev_factory pjmedia_vid_dev_factory;
306
307/* typedef for factory creation function */
308typedef pjmedia_vid_dev_factory*
309(*pjmedia_vid_dev_factory_create_func_ptr)(pj_pool_factory*);
310
311
312/**
313 * Get string info for the specified capability.
314 *
315 * @param cap The capability ID.
316 * @param p_desc Optional pointer which will be filled with longer
317 * description about the capability.
318 *
319 * @return Capability name.
320 */
321PJ_DECL(const char*) pjmedia_vid_dev_cap_name(pjmedia_vid_dev_cap cap,
322 const char **p_desc);
323
324
325/**
326 * Set a capability field value in #pjmedia_vid_param structure. This will
327 * also set the flags field for the specified capability in the structure.
328 *
329 * @param param The structure.
330 * @param cap The video capability which value is to be set.
331 * @param pval Pointer to value. Please see the type of value to
332 * be supplied in the pjmedia_vid_dev_cap documentation.
333 *
334 * @return PJ_SUCCESS on successful operation or the appropriate
335 * error code.
336 */
337PJ_DECL(pj_status_t) pjmedia_vid_param_set_cap(pjmedia_vid_param *param,
338 pjmedia_vid_dev_cap cap,
339 const void *pval);
340
341
342/**
343 * Get a capability field value from #pjmedia_vid_param structure. This
344 * function will return PJMEDIA_EVID_INVCAP error if the flag for that
345 * capability is not set in the flags field in the structure.
346 *
347 * @param param The structure.
348 * @param cap The video capability which value is to be retrieved.
349 * @param pval Pointer to value. Please see the type of value to
350 * be supplied in the pjmedia_vid_dev_cap documentation.
351 *
352 * @return PJ_SUCCESS on successful operation or the appropriate
353 * error code.
354 */
355PJ_DECL(pj_status_t) pjmedia_vid_param_get_cap(const pjmedia_vid_param *param,
356 pjmedia_vid_dev_cap cap,
357 void *pval);
358
359/**
Sauw Minge90ece82011-06-09 04:05:44 +0000360 * Initialize the video device subsystem. This will register all supported
361 * video device factories to the video device subsystem. This function may be
362 * called more than once, but each call to this function must have the
363 * corresponding #pjmedia_vid_dev_subsys_shutdown() call.
Benny Prijonoc45d9512010-12-10 11:04:30 +0000364 *
365 * @param pf The pool factory.
366 *
367 * @return PJ_SUCCESS on successful operation or the appropriate
368 * error code.
369 */
Sauw Minge90ece82011-06-09 04:05:44 +0000370PJ_DECL(pj_status_t) pjmedia_vid_dev_subsys_init(pj_pool_factory *pf);
Benny Prijonoc45d9512010-12-10 11:04:30 +0000371
372
373/**
Sauw Minge90ece82011-06-09 04:05:44 +0000374 * Get the pool factory registered to the video device subsystem.
Benny Prijonoc45d9512010-12-10 11:04:30 +0000375 *
376 * @return The pool factory.
377 */
Sauw Minge90ece82011-06-09 04:05:44 +0000378PJ_DECL(pj_pool_factory*) pjmedia_vid_dev_subsys_get_pool_factory(void);
Benny Prijonoc45d9512010-12-10 11:04:30 +0000379
380
381/**
Sauw Minge90ece82011-06-09 04:05:44 +0000382 * Shutdown the video device subsystem. This will destroy all video device
383 * factories registered in the video device subsystem. Note that currently
384 * opened video streams may or may not be closed, depending on the
385 * implementation of the video device factories.
Benny Prijonoc45d9512010-12-10 11:04:30 +0000386 *
387 * @return PJ_SUCCESS on successful operation or the appropriate
388 * error code.
389 */
Sauw Minge90ece82011-06-09 04:05:44 +0000390PJ_DECL(pj_status_t) pjmedia_vid_dev_subsys_shutdown(void);
Benny Prijonoc45d9512010-12-10 11:04:30 +0000391
392
393/**
Sauw Minge90ece82011-06-09 04:05:44 +0000394 * Register a supported video device factory to the video device subsystem.
395 * This function can only be called after calling
396 * #pjmedia_vid_dev_subsys_init().
Benny Prijonoc45d9512010-12-10 11:04:30 +0000397 *
398 * @param vdf The video device factory.
399 *
400 * @return PJ_SUCCESS on successful operation or the appropriate
401 * error code.
402 */
403PJ_DECL(pj_status_t)
404pjmedia_vid_register_factory(pjmedia_vid_dev_factory_create_func_ptr vdf);
405
406
407/**
Sauw Minge90ece82011-06-09 04:05:44 +0000408 * Unregister a video device factory from the video device subsystem. This
409 * function can only be called after calling #pjmedia_vid_dev_subsys_init().
Benny Prijonoc45d9512010-12-10 11:04:30 +0000410 * Devices from this factory will be unlisted. If a device from this factory
411 * is currently in use, then the behavior is undefined.
412 *
413 * @param vdf The video device factory.
414 *
415 * @return PJ_SUCCESS on successful operation or the appropriate
416 * error code.
417 */
418PJ_DECL(pj_status_t)
419pjmedia_vid_unregister_factory(pjmedia_vid_dev_factory_create_func_ptr vdf);
420
421
422/**
423 * Get the number of video devices installed in the system.
424 *
425 * @return The number of video devices installed in the system.
426 */
427PJ_DECL(unsigned) pjmedia_vid_dev_count(void);
428
429
430/**
431 * Get device information.
432 *
433 * @param id The video device ID.
434 * @param info The device information which will be filled in by this
435 * function once it returns successfully.
436 *
437 * @return PJ_SUCCESS on successful operation or the appropriate
438 * error code.
439 */
440PJ_DECL(pj_status_t) pjmedia_vid_dev_get_info(pjmedia_vid_dev_index id,
441 pjmedia_vid_dev_info *info);
442
443
444/**
445 * Lookup device index based on the driver and device name.
446 *
447 * @param drv_name The driver name.
448 * @param dev_name The device name.
449 * @param id Pointer to store the returned device ID.
450 *
451 * @return PJ_SUCCESS if the device can be found.
452 */
453PJ_DECL(pj_status_t) pjmedia_vid_dev_lookup(const char *drv_name,
454 const char *dev_name,
455 pjmedia_vid_dev_index *id);
456
457
458/**
459 * Initialize the video device parameters with default values for the
460 * specified device.
461 *
462 * @param id The video device ID.
463 * @param param The video device parameters which will be initialized
464 * by this function once it returns successfully.
465 *
466 * @return PJ_SUCCESS on successful operation or the appropriate
467 * error code.
468 */
469PJ_DECL(pj_status_t) pjmedia_vid_dev_default_param(pj_pool_t *pool,
470 pjmedia_vid_dev_index id,
471 pjmedia_vid_param *param);
472
473
474/**
Benny Prijonoe9f70d82011-03-25 08:38:26 +0000475 * Open video stream object using the specified parameters. If stream is
476 * created successfully, this function will return PJ_SUCCESS and the
477 * stream pointer will be returned in the p_strm argument.
478 *
479 * The opened stream may have been opened with different size and fps
480 * than the requested values in the \a param argument. Application should
481 * check the actual size and fps that the stream was opened with by inspecting
482 * the values in the \a param argument and see if they have changed. Also
483 * if the device ID in the \a param specifies default device, it may be
484 * replaced with the actual device ID upon return.
Benny Prijonoc45d9512010-12-10 11:04:30 +0000485 *
486 * @param param Sound device parameters to be used for the stream.
487 * @param cb Pointer to structure containing video stream
488 * callbacks.
489 * @param user_data Arbitrary user data, which will be given back in the
490 * callbacks.
491 * @param p_strm Pointer to receive the video stream.
492 *
493 * @return PJ_SUCCESS on successful operation or the appropriate
494 * error code.
495 */
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000496PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_create(
Benny Prijonoe9f70d82011-03-25 08:38:26 +0000497 pjmedia_vid_param *param,
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000498 const pjmedia_vid_cb *cb,
499 void *user_data,
500 pjmedia_vid_dev_stream **p_strm);
Benny Prijonoc45d9512010-12-10 11:04:30 +0000501
502/**
503 * Get the running parameters for the specified video stream.
504 *
505 * @param strm The video stream.
506 * @param param Video stream parameters to be filled in by this
507 * function once it returns successfully.
508 *
509 * @return PJ_SUCCESS on successful operation or the appropriate
510 * error code.
511 */
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000512PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_get_param(
513 pjmedia_vid_dev_stream *strm,
514 pjmedia_vid_param *param);
Benny Prijonoc45d9512010-12-10 11:04:30 +0000515
516/**
517 * Get the value of a specific capability of the video stream.
518 *
519 * @param strm The video stream.
520 * @param cap The video capability which value is to be retrieved.
521 * @param value Pointer to value to be filled in by this function
522 * once it returns successfully. Please see the type
523 * of value to be supplied in the pjmedia_vid_dev_cap
524 * documentation.
525 *
526 * @return PJ_SUCCESS on successful operation or the appropriate
527 * error code.
528 */
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000529PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_get_cap(
530 pjmedia_vid_dev_stream *strm,
531 pjmedia_vid_dev_cap cap,
532 void *value);
Benny Prijonoc45d9512010-12-10 11:04:30 +0000533
534/**
535 * Set the value of a specific capability of the video stream.
536 *
537 * @param strm The video stream.
538 * @param cap The video capability which value is to be set.
539 * @param value Pointer to value. Please see the type of value to
540 * be supplied in the pjmedia_vid_dev_cap documentation.
541 *
542 * @return PJ_SUCCESS on successful operation or the appropriate
543 * error code.
544 */
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000545PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_set_cap(
546 pjmedia_vid_dev_stream *strm,
547 pjmedia_vid_dev_cap cap,
548 const void *value);
Benny Prijonoc45d9512010-12-10 11:04:30 +0000549
550/**
551 * Start the stream.
552 *
553 * @param strm The video stream.
554 *
555 * @return PJ_SUCCESS on successful operation or the appropriate
556 * error code.
557 */
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000558PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_start(
559 pjmedia_vid_dev_stream *strm);
Benny Prijonoc45d9512010-12-10 11:04:30 +0000560
561/* Get/put frame API for passive stream */
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000562PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_get_frame(
563 pjmedia_vid_dev_stream *strm,
564 pjmedia_frame *frame);
Benny Prijonoc45d9512010-12-10 11:04:30 +0000565
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000566PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_put_frame(
567 pjmedia_vid_dev_stream *strm,
568 const pjmedia_frame *frame);
Benny Prijonoc45d9512010-12-10 11:04:30 +0000569
570/**
571 * Stop the stream.
572 *
573 * @param strm The video stream.
574 *
575 * @return PJ_SUCCESS on successful operation or the appropriate
576 * error code.
577 */
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000578PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_stop(
579 pjmedia_vid_dev_stream *strm);
Benny Prijonoc45d9512010-12-10 11:04:30 +0000580
581/**
582 * Destroy the stream.
583 *
584 * @param strm The video stream.
585 *
586 * @return PJ_SUCCESS on successful operation or the appropriate
587 * error code.
588 */
Nanang Izzuddina9c1cf42011-02-24 07:47:55 +0000589PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_destroy(
590 pjmedia_vid_dev_stream *strm);
Benny Prijonoc45d9512010-12-10 11:04:30 +0000591
592
593/**
594 * @}
595 */
596
597PJ_END_DECL
598
599
600#endif /* __PJMEDIA_VIDEODEV_VIDEODEV_H__ */