diff options
author | Riza Sulistyo <riza@teluu.com> | 2015-05-28 07:14:24 +0000 |
---|---|---|
committer | Riza Sulistyo <riza@teluu.com> | 2015-05-28 07:14:24 +0000 |
commit | 5bb6d872c7bd5a258152fcb57b16acaf3012385f (patch) | |
tree | 15286090bc713fcb91b856059fcc5474517a7a52 /pjsip | |
parent | 1f5cf04d6dad8d08da58b086aad46cee580ea8d3 (diff) |
Re #1855 (Pjsua2 Video Preview API): Add Pjsua2 Preview API and sample usage in pjsua2 app for android.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5102 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r-- | pjsip/include/pjsua2/media.hpp | 99 | ||||
-rw-r--r-- | pjsip/src/pjsua2/media.cpp | 82 |
2 files changed, 181 insertions, 0 deletions
diff --git a/pjsip/include/pjsua2/media.hpp b/pjsip/include/pjsua2/media.hpp index 181001e4..16df4ca5 100644 --- a/pjsip/include/pjsua2/media.hpp +++ b/pjsip/include/pjsua2/media.hpp @@ -1488,6 +1488,105 @@ private: pjsua_vid_win_id winId; }; +/** + * This structure contains parameters for VideoPreview::start() + */ +struct VideoPreviewOpParam { + /** + * Device ID for the video renderer to be used for rendering the + * capture stream for preview. This parameter is ignored if native + * preview is being used. + * + * Default: PJMEDIA_VID_DEFAULT_RENDER_DEV + */ + pjmedia_vid_dev_index rendId; + + /** + * Show window initially. + * + * Default: PJ_TRUE. + */ + bool show; + + /** + * Window flags. The value is a bitmask combination of + * \a pjmedia_vid_dev_wnd_flag. + * + * Default: 0. + */ + unsigned windowFlags; + + /** + * Media format. If left unitialized, this parameter will not be used. + */ + MediaFormat format; + + /** + * Optional output window to be used to display the video preview. + * This parameter will only be used if the video device supports + * PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW capability and the capability + * is not read-only. + */ + VideoWindowHandle window; + +public: + /** + * Default constructor initializes with default values. + */ + VideoPreviewOpParam(); + + /** + * Convert from pjsip + */ + void fromPj(const pjsua_vid_preview_param &prm); + + /** + * Convert to pjsip + */ + pjsua_vid_preview_param toPj() const; +}; + +/** + * Video Preview + */ +class VideoPreview { +public: + /** + * Constructor + */ + VideoPreview(int dev_id); + + /** + * Determine if the specified video input device has built-in native + * preview capability. This is a convenience function that is equal to + * querying device's capability for PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW + * capability. + * + * @return true if it has. + */ + bool hasNative(); + + /** + * Start video preview window for the specified capture device. + * + * @param p Video preview parameters. + */ + void start(const VideoPreviewOpParam ¶m) throw(Error); + + /** + * Stop video preview. + */ + void stop() throw(Error); + + /* + * Get the preview window handle associated with the capture device,if any. + */ + VideoWindow getVideoWindow(); + +private: + pjmedia_vid_dev_index devId; +}; + /************************************************************************* * Codec management */ diff --git a/pjsip/src/pjsua2/media.cpp b/pjsip/src/pjsua2/media.cpp index 18b75f13..12e67f52 100644 --- a/pjsip/src/pjsua2/media.cpp +++ b/pjsip/src/pjsua2/media.cpp @@ -1093,6 +1093,88 @@ void VideoWindow::setWindow(const VideoWindowHandle &win) throw(Error) PJ_UNUSED_ARG(win); #endif } +/////////////////////////////////////////////////////////////////////////////// + +VideoPreviewOpParam::VideoPreviewOpParam() +{ +#if PJSUA_HAS_VIDEO + pjsua_vid_preview_param vid_prev_param; + + pjsua_vid_preview_param_default(&vid_prev_param); + fromPj(vid_prev_param); +#endif +} + +void VideoPreviewOpParam::fromPj(const pjsua_vid_preview_param &prm) +{ +#if PJSUA_HAS_VIDEO + this->rendId = prm.rend_id; + this->show = PJ2BOOL(prm.show); + this->windowFlags = prm.wnd_flags; + this->format.id = prm.format.id; + this->format.type = prm.format.type; + this->window.type = prm.wnd.type; + this->window.handle.window = prm.wnd.info.window; +#else + PJ_UNUSED_ARG(prm); +#endif +} + +pjsua_vid_preview_param VideoPreviewOpParam::toPj() const +{ + pjsua_vid_preview_param param; +#if PJSUA_HAS_VIDEO + param.rend_id = this->rendId; + param.show = this->show; + param.wnd_flags = this->windowFlags; + param.format.id = this->format.id; + param.format.type = this->format.type; + param.wnd.type = this->window.type; + param.wnd.info.window = this->window.handle.window; +#endif + return param; +} + +VideoPreview::VideoPreview(int dev_id) +: devId(dev_id) +{ + +} + +bool VideoPreview::hasNative() +{ +#if PJSUA_HAS_VIDEO + return(PJ2BOOL(pjsua_vid_preview_has_native(devId))); +#else + return false; +#endif +} + +void VideoPreview::start(const VideoPreviewOpParam ¶m) throw(Error) +{ +#if PJSUA_HAS_VIDEO + pjsua_vid_preview_param prm = param.toPj(); + PJSUA2_CHECK_EXPR(pjsua_vid_preview_start(devId, &prm)); +#else + PJ_UNUSED_ARG(param); +#endif +} + +void VideoPreview::stop() throw(Error) +{ +#if PJSUA_HAS_VIDEO + pjsua_vid_preview_stop(devId); +#endif +} + +VideoWindow VideoPreview::getVideoWindow() +{ +#if PJSUA_HAS_VIDEO + return (VideoWindow(pjsua_vid_preview_get_win(devId))); +#else + return (VideoWindow(PJSUA_INVALID_ID)); +#endif +} /////////////////////////////////////////////////////////////////////////////// void CodecInfo::fromPj(const pjsua_codec_info &codec_info) |