1
/* $Id: videodev.h 4704 2014-01-16 05:30:46Z ming $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
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.
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.
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
19
#ifndef __PJMEDIA_VIDEODEV_VIDEODEV_H__
20
#define __PJMEDIA_VIDEODEV_VIDEODEV_H__
24
* @brief Video device API.
26
#include <pjmedia-videodev/config.h>
27
#include <pjmedia-videodev/errno.h>
28
#include <pjmedia/event.h>
29
#include <pjmedia/frame.h>
30
#include <pjmedia/format.h>
37
* @defgroup video_device_reference Video Device API Reference
38
* @ingroup video_device_api
39
* @brief API Reference
44
* Type for device index.
46
typedef pj_int32_t pjmedia_vid_dev_index;
49
* Enumeration of window handle type.
51
typedef enum pjmedia_vid_dev_hwnd_type
56
PJMEDIA_VID_DEV_HWND_TYPE_NONE,
59
* Native window handle on Windows.
61
PJMEDIA_VID_DEV_HWND_TYPE_WINDOWS
63
} pjmedia_vid_dev_hwnd_type;
66
* Type for window handle.
68
typedef struct pjmedia_vid_dev_hwnd
71
* The window handle type.
73
pjmedia_vid_dev_hwnd_type type;
81
void *hwnd; /**< HWND */
84
void *window; /**< Window */
85
void *display; /**< Display */
88
void *window; /**< Window */
91
void *window; /**< Window */
96
} pjmedia_vid_dev_hwnd;
99
* Parameter for switching device with PJMEDIA_VID_DEV_CAP_SWITCH capability.
100
* Initialize this with pjmedia_vid_dev_switch_param_default()
102
typedef struct pjmedia_vid_dev_switch_param
105
* Target device ID to switch to. Once the switching is successful, the
106
* video stream will use this device and the old device will be closed.
108
pjmedia_vid_dev_index target_id;
110
} pjmedia_vid_dev_switch_param;
114
* Enumeration of window flags.
116
typedef enum pjmedia_vid_dev_wnd_flag
119
* Window with border.
121
PJMEDIA_VID_DEV_WND_BORDER = 1,
124
* Window can be resized.
126
PJMEDIA_VID_DEV_WND_RESIZABLE = 2
128
} pjmedia_vid_dev_wnd_flag;
132
* Device index constants.
134
enum pjmedia_vid_dev_std_index
137
* Constant to denote default capture device
139
PJMEDIA_VID_DEFAULT_CAPTURE_DEV = -1,
142
* Constant to denote default render device
144
PJMEDIA_VID_DEFAULT_RENDER_DEV = -2,
147
* Constant to denote invalid device index.
149
PJMEDIA_VID_INVALID_DEV = -3
154
* This enumeration identifies various video device capabilities. These video
155
* capabilities indicates what features are supported by the underlying
156
* video device implementation.
158
* Applications get these capabilities in the #pjmedia_vid_dev_info structure.
160
* Application can also set the specific features/capabilities when opening
161
* the video stream by setting the \a flags member of #pjmedia_vid_dev_param
164
* Once video stream is running, application can also retrieve or set some
165
* specific video capability, by using #pjmedia_vid_dev_stream_get_cap() and
166
* #pjmedia_vid_dev_stream_set_cap() and specifying the desired capability. The
167
* value of the capability is specified as pointer, and application needs to
168
* supply the pointer with the correct value, according to the documentation
169
* of each of the capability.
171
typedef enum pjmedia_vid_dev_cap
174
* Support for video formats. The value of this capability
175
* is represented by #pjmedia_format structure.
177
PJMEDIA_VID_DEV_CAP_FORMAT = 1,
180
* Support for video input scaling
182
PJMEDIA_VID_DEV_CAP_INPUT_SCALE = 2,
185
* Support for returning the native window handle of the video window.
186
* For renderer, this means the window handle of the renderer window,
187
* while for capture, this means the window handle of the native preview,
188
* only if the device supports PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW
191
* The value of this capability is pointer to pjmedia_vid_dev_hwnd
194
PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW = 4,
197
* Support for resizing video output. This capability SHOULD be
198
* implemented by renderer, to alter the video output dimension on the fly.
199
* Value is pjmedia_rect_size.
201
PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE = 8,
204
* Support for setting the video window's position.
205
* Value is pjmedia_coord specifying the window's new coordinate.
207
PJMEDIA_VID_DEV_CAP_OUTPUT_POSITION = 16,
210
* Support for setting the video output's visibility.
211
* The value of this capability is a pj_bool_t containing boolean
212
* PJ_TRUE or PJ_FALSE.
214
PJMEDIA_VID_DEV_CAP_OUTPUT_HIDE = 32,
217
* Support for native preview capability in capture devices. Value is
218
* pj_bool_t. With native preview, capture device can be instructed to
219
* show or hide a preview window showing video directly from the camera
220
* by setting this capability to PJ_TRUE or PJ_FALSE. Once the preview
221
* is started, application may use PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW
222
* capability to query the vidow window.
224
* The value of this capability is a pj_bool_t containing boolean
225
* PJ_TRUE or PJ_FALSE.
227
PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW = 64,
230
* Support for changing video orientation in renderer and querying
231
* video orientation info in capture. Changing video orientation in
232
* a renderer will potentially affect the size of render window,
233
* i.e: width and height swap. When a capture device supports this
234
* capability, it will generate event PJMEDIA_EVENT_ORIENT_CHANGED
235
* (see #pjmedia_event) everytime the capture orientation is changed.
237
* The value of this capability is pjmedia_orient.
239
PJMEDIA_VID_DEV_CAP_ORIENTATION = 128,
242
* Support for fast switching to another device. A video stream with this
243
* capability allows replacing of its underlying device with another
244
* device, saving the user from opening a new video stream and gets a much
245
* faster and smoother switching action.
247
* Note that even when this capability is supported by a device, it may
248
* not be able to switch to arbitrary device. Application must always
249
* check the return value of the operation to verify that switching has
252
* This capability is currently write-only (i.e. set-only).
254
* The value of this capability is pointer to pjmedia_vid_dev_switch_param
257
PJMEDIA_VID_DEV_CAP_SWITCH = 256,
260
* Support for setting the output video window's flags.
261
* The value of this capability is a bitmask combination of
262
* #pjmedia_vid_dev_wnd_flag.
264
PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW_FLAGS = 512,
267
* End of standard capability
269
PJMEDIA_VID_DEV_CAP_MAX = 16384
271
} pjmedia_vid_dev_cap;
274
* Device information structure returned by #pjmedia_vid_dev_get_info().
276
typedef struct pjmedia_vid_dev_info
279
pjmedia_vid_dev_index id;
281
/** The device name */
284
/** The underlying driver name */
288
* The supported direction of the video device, i.e. whether it supports
289
* capture only, render only, or both.
294
* Specify whether the device supports callback. Devices that implement
295
* "active interface" will actively call the callbacks to give or ask for
296
* video frames. If the device doesn't support callback, application
297
* must actively request or give video frames from/to the device by using
298
* pjmedia_vid_dev_stream_get_frame()/pjmedia_vid_dev_stream_put_frame().
300
pj_bool_t has_callback;
302
/** Device capabilities, as bitmask combination of #pjmedia_vid_dev_cap */
305
/** Number of video formats supported by this device */
309
* Array of supported video formats. Some fields in each supported video
310
* format may be set to zero or of "unknown" value, to indicate that the
311
* value is unknown or should be ignored. When these value are not set
312
* to zero, it indicates that the exact format combination is being used.
314
pjmedia_format fmt[PJMEDIA_VID_DEV_INFO_FMT_CNT];
316
} pjmedia_vid_dev_info;
319
/** Forward declaration for pjmedia_vid_dev_stream */
320
typedef struct pjmedia_vid_dev_stream pjmedia_vid_dev_stream;
322
typedef struct pjmedia_vid_dev_cb
325
* This callback is called by capturer stream when it has captured the
326
* whole packet worth of video samples.
328
* @param stream The video stream.
329
* @param user_data User data associated with the stream.
330
* @param frame Captured frame.
332
* @return Returning non-PJ_SUCCESS will cause the video
335
pj_status_t (*capture_cb)(pjmedia_vid_dev_stream *stream,
337
pjmedia_frame *frame);
340
* This callback is called by renderer stream when it needs additional
341
* data to be rendered by the device. Application must fill in the whole
342
* of output buffer with video samples.
344
* The frame argument contains the following values:
345
* - timestamp Rendering timestamp, in samples.
346
* - buf Buffer to be filled out by application.
347
* - size The size requested in bytes, which will be equal
348
* to the size of one whole packet.
350
* @param stream The video stream.
351
* @param user_data User data associated with the stream.
352
* @param frame Video frame, which buffer is to be filled in by
355
* @return Returning non-PJ_SUCCESS will cause the video
358
pj_status_t (*render_cb)(pjmedia_vid_dev_stream *stream,
360
pjmedia_frame *frame);
362
} pjmedia_vid_dev_cb;
366
* This structure specifies the parameters to open the video stream.
368
typedef struct pjmedia_vid_dev_param
371
* The video direction. This setting is mandatory.
376
* The video capture device ID. This setting is mandatory if the video
377
* direction includes input/capture direction.
379
pjmedia_vid_dev_index cap_id;
382
* The video render device ID. This setting is mandatory if the video
383
* direction includes output/render direction.
385
pjmedia_vid_dev_index rend_id;
388
* Video clock rate. This setting is mandatory if the video
389
* direction includes input/capture direction
394
* Video frame rate. This setting is mandatory if the video
395
* direction includes input/capture direction
397
// pjmedia_ratio frame_rate;
400
* This flags specifies which of the optional settings are valid in this
401
* structure. The flags is bitmask combination of pjmedia_vid_dev_cap.
406
* Set the video format. This setting is mandatory.
411
* Window for the renderer to display the video. This setting is optional,
412
* and will only be used if PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW is set in
415
pjmedia_vid_dev_hwnd window;
418
* Video display size. This setting is optional, and will only be used
419
* if PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE is set in the flags.
421
pjmedia_rect_size disp_size;
424
* Video window position. This setting is optional, and will only be used
425
* if PJMEDIA_VID_DEV_CAP_OUTPUT_POSITION is set in the flags.
427
pjmedia_coord window_pos;
430
* Video window's visibility. This setting is optional, and will only be
431
* used if PJMEDIA_VID_DEV_CAP_OUTPUT_HIDE is set in the flags.
433
pj_bool_t window_hide;
436
* Enable built-in preview. This setting is optional and is only used
437
* if PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW capability is supported and
440
pj_bool_t native_preview;
443
* Video orientation. This setting is optional and is only used if
444
* PJMEDIA_VID_DEV_CAP_ORIENTATION capability is supported and is
447
pjmedia_orient orient;
450
* Video window flags. This setting is optional, and will only be used
451
* if PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW_FLAGS is set in the flags.
453
unsigned window_flags;
455
} pjmedia_vid_dev_param;
458
/** Forward declaration for video device factory */
459
typedef struct pjmedia_vid_dev_factory pjmedia_vid_dev_factory;
461
/* typedef for factory creation function */
462
typedef pjmedia_vid_dev_factory*
463
(*pjmedia_vid_dev_factory_create_func_ptr)(pj_pool_factory*);
466
* Initialize pjmedia_vid_dev_switch_param.
468
* @param p Parameter to be initialized.
471
pjmedia_vid_dev_switch_param_default(pjmedia_vid_dev_switch_param *p)
473
pj_bzero(p, sizeof(*p));
474
p->target_id = PJMEDIA_VID_INVALID_DEV;
478
* Get string info for the specified capability.
480
* @param cap The capability ID.
481
* @param p_desc Optional pointer which will be filled with longer
482
* description about the capability.
484
* @return Capability name.
486
PJ_DECL(const char*) pjmedia_vid_dev_cap_name(pjmedia_vid_dev_cap cap,
487
const char **p_desc);
491
* Set a capability field value in #pjmedia_vid_dev_param structure. This will
492
* also set the flags field for the specified capability in the structure.
494
* @param param The structure.
495
* @param cap The video capability which value is to be set.
496
* @param pval Pointer to value. Please see the type of value to
497
* be supplied in the pjmedia_vid_dev_cap documentation.
499
* @return PJ_SUCCESS on successful operation or the appropriate
503
pjmedia_vid_dev_param_set_cap(pjmedia_vid_dev_param *param,
504
pjmedia_vid_dev_cap cap,
509
* Get a capability field value from #pjmedia_vid_dev_param structure. This
510
* function will return PJMEDIA_EVID_INVCAP error if the flag for that
511
* capability is not set in the flags field in the structure.
513
* @param param The structure.
514
* @param cap The video capability which value is to be retrieved.
515
* @param pval Pointer to value. Please see the type of value to
516
* be supplied in the pjmedia_vid_dev_cap documentation.
518
* @return PJ_SUCCESS on successful operation or the appropriate
522
pjmedia_vid_dev_param_get_cap(const pjmedia_vid_dev_param *param,
523
pjmedia_vid_dev_cap cap,
527
* Initialize the video device subsystem. This will register all supported
528
* video device factories to the video device subsystem. This function may be
529
* called more than once, but each call to this function must have the
530
* corresponding #pjmedia_vid_dev_subsys_shutdown() call.
532
* @param pf The pool factory.
534
* @return PJ_SUCCESS on successful operation or the appropriate
537
PJ_DECL(pj_status_t) pjmedia_vid_dev_subsys_init(pj_pool_factory *pf);
541
* Get the pool factory registered to the video device subsystem.
543
* @return The pool factory.
545
PJ_DECL(pj_pool_factory*) pjmedia_vid_dev_subsys_get_pool_factory(void);
549
* Shutdown the video device subsystem. This will destroy all video device
550
* factories registered in the video device subsystem. Note that currently
551
* opened video streams may or may not be closed, depending on the
552
* implementation of the video device factories.
554
* @return PJ_SUCCESS on successful operation or the appropriate
557
PJ_DECL(pj_status_t) pjmedia_vid_dev_subsys_shutdown(void);
561
* Register a supported video device factory to the video device subsystem.
562
* Application can either register a function to create the factory, or
563
* an instance of an already created factory.
565
* This function can only be called after calling
566
* #pjmedia_vid_dev_subsys_init().
568
* @param vdf The factory creation function. Either vdf or factory
569
* argument must be specified.
570
* @param factory Factory instance. Either vdf or factory
571
* argument must be specified.
573
* @return PJ_SUCCESS on successful operation or the appropriate
577
pjmedia_vid_register_factory(pjmedia_vid_dev_factory_create_func_ptr vdf,
578
pjmedia_vid_dev_factory *factory);
582
* Unregister a video device factory from the video device subsystem. This
583
* function can only be called after calling #pjmedia_vid_dev_subsys_init().
584
* Devices from this factory will be unlisted. If a device from this factory
585
* is currently in use, then the behavior is undefined.
587
* @param vdf The video device factory. Either vdf or factory argument
589
* @param factory The factory instance. Either vdf or factory argument
592
* @return PJ_SUCCESS on successful operation or the appropriate
596
pjmedia_vid_unregister_factory(pjmedia_vid_dev_factory_create_func_ptr vdf,
597
pjmedia_vid_dev_factory *factory);
601
* Refresh the list of video devices installed in the system. This function
602
* will only refresh the list of videoo device so all active video streams will
603
* be unaffected. After refreshing the device list, application MUST make sure
604
* to update all index references to video devices (i.e. all variables of type
605
* pjmedia_vid_dev_index) before calling any function that accepts video device
606
* index as its parameter.
608
* @return PJ_SUCCESS on successful operation or the appropriate
611
PJ_DECL(pj_status_t) pjmedia_vid_dev_refresh(void);
615
* Get the number of video devices installed in the system.
617
* @return The number of video devices installed in the system.
619
PJ_DECL(unsigned) pjmedia_vid_dev_count(void);
623
* Get device information.
625
* @param id The video device ID.
626
* @param info The device information which will be filled in by this
627
* function once it returns successfully.
629
* @return PJ_SUCCESS on successful operation or the appropriate
632
PJ_DECL(pj_status_t) pjmedia_vid_dev_get_info(pjmedia_vid_dev_index id,
633
pjmedia_vid_dev_info *info);
637
* Lookup device index based on the driver and device name.
639
* @param drv_name The driver name.
640
* @param dev_name The device name.
641
* @param id Pointer to store the returned device ID.
643
* @return PJ_SUCCESS if the device can be found.
645
PJ_DECL(pj_status_t) pjmedia_vid_dev_lookup(const char *drv_name,
646
const char *dev_name,
647
pjmedia_vid_dev_index *id);
651
* Initialize the video device parameters with default values for the
654
* @param id The video device ID.
655
* @param param The video device parameters which will be initialized
656
* by this function once it returns successfully.
658
* @return PJ_SUCCESS on successful operation or the appropriate
662
pjmedia_vid_dev_default_param(pj_pool_t *pool,
663
pjmedia_vid_dev_index id,
664
pjmedia_vid_dev_param *param);
668
* Open video stream object using the specified parameters. If stream is
669
* created successfully, this function will return PJ_SUCCESS and the
670
* stream pointer will be returned in the p_strm argument.
672
* The opened stream may have been opened with different size and fps
673
* than the requested values in the \a param argument. Application should
674
* check the actual size and fps that the stream was opened with by inspecting
675
* the values in the \a param argument and see if they have changed. Also
676
* if the device ID in the \a param specifies default device, it may be
677
* replaced with the actual device ID upon return.
679
* @param param On input, it specifies the video device parameters
680
* to be used for the stream. On output, this will be
681
* set to the actual video device parameters used to
683
* @param cb Pointer to structure containing video stream
685
* @param user_data Arbitrary user data, which will be given back in the
687
* @param p_strm Pointer to receive the video stream.
689
* @return PJ_SUCCESS on successful operation or the appropriate
692
PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_create(
693
pjmedia_vid_dev_param *param,
694
const pjmedia_vid_dev_cb *cb,
696
pjmedia_vid_dev_stream **p_strm);
699
* Get the running parameters for the specified video stream.
701
* @param strm The video stream.
702
* @param param Video stream parameters to be filled in by this
703
* function once it returns successfully.
705
* @return PJ_SUCCESS on successful operation or the appropriate
708
PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_get_param(
709
pjmedia_vid_dev_stream *strm,
710
pjmedia_vid_dev_param *param);
713
* Get the value of a specific capability of the video stream.
715
* @param strm The video stream.
716
* @param cap The video capability which value is to be retrieved.
717
* @param value Pointer to value to be filled in by this function
718
* once it returns successfully. Please see the type
719
* of value to be supplied in the pjmedia_vid_dev_cap
722
* @return PJ_SUCCESS on successful operation or the appropriate
725
PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_get_cap(
726
pjmedia_vid_dev_stream *strm,
727
pjmedia_vid_dev_cap cap,
731
* Set the value of a specific capability of the video stream.
733
* @param strm The video stream.
734
* @param cap The video capability which value is to be set.
735
* @param value Pointer to value. Please see the type of value to
736
* be supplied in the pjmedia_vid_dev_cap documentation.
738
* @return PJ_SUCCESS on successful operation or the appropriate
741
PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_set_cap(
742
pjmedia_vid_dev_stream *strm,
743
pjmedia_vid_dev_cap cap,
749
* @param strm The video stream.
751
* @return PJ_SUCCESS on successful operation or the appropriate
754
PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_start(
755
pjmedia_vid_dev_stream *strm);
758
* Query whether the stream has been started.
760
* @param strm The video stream
762
* @return PJ_TRUE if the video stream has been started.
764
PJ_DECL(pj_bool_t) pjmedia_vid_dev_stream_is_running(pjmedia_vid_dev_stream *strm);
768
* Request one frame from the stream. Application needs to call this function
769
* periodically only if the stream doesn't support "active interface", i.e.
770
* the pjmedia_vid_dev_info.has_callback member is PJ_FALSE.
772
* @param strm The video stream.
773
* @param frame The video frame to be filled by the device.
775
* @return PJ_SUCCESS on successful operation or the appropriate
778
PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_get_frame(
779
pjmedia_vid_dev_stream *strm,
780
pjmedia_frame *frame);
783
* Put one frame to the stream. Application needs to call this function
784
* periodically only if the stream doesn't support "active interface", i.e.
785
* the pjmedia_vid_dev_info.has_callback member is PJ_FALSE.
787
* @param strm The video stream.
788
* @param frame The video frame to put to the device.
790
* @return PJ_SUCCESS on successful operation or the appropriate
793
PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_put_frame(
794
pjmedia_vid_dev_stream *strm,
795
const pjmedia_frame *frame);
800
* @param strm The video stream.
802
* @return PJ_SUCCESS on successful operation or the appropriate
805
PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_stop(
806
pjmedia_vid_dev_stream *strm);
809
* Destroy the stream.
811
* @param strm The video stream.
813
* @return PJ_SUCCESS on successful operation or the appropriate
816
PJ_DECL(pj_status_t) pjmedia_vid_dev_stream_destroy(
817
pjmedia_vid_dev_stream *strm);
827
#endif /* __PJMEDIA_VIDEODEV_VIDEODEV_H__ */