diff options
author | Liong Sauw Ming <ming@teluu.com> | 2015-03-18 08:25:24 +0000 |
---|---|---|
committer | Liong Sauw Ming <ming@teluu.com> | 2015-03-18 08:25:24 +0000 |
commit | 18061c77b205207a29aeb61414c1040affeeae3b (patch) | |
tree | 51168f9aeb7c4ea275586c7e4c9acbefa571e9aa /pjsip | |
parent | 0266873461cbbaeac7cc5a210fa90bab6c640b65 (diff) |
Re #1823 (PJSUA2 Video API): Add Pjsua2 Video Window API and Pjsua API to set output window
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4996 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua.h | 14 | ||||
-rw-r--r-- | pjsip/include/pjsua2/call.hpp | 7 | ||||
-rw-r--r-- | pjsip/include/pjsua2/media.hpp | 163 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_vid.c | 34 | ||||
-rw-r--r-- | pjsip/src/pjsua2/call.cpp | 2 | ||||
-rw-r--r-- | pjsip/src/pjsua2/media.cpp | 62 |
6 files changed, 282 insertions, 0 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index 1ebde412..e730790c 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -6815,6 +6815,20 @@ PJ_DECL(pj_status_t) pjsua_vid_win_set_size(pjsua_vid_win_id wid, const pjmedia_rect_size *size); /** + * Set output window. This operation is valid only when the underlying + * video device supports PJMEDIA_VIDEO_DEV_CAP_OUTPUT_WINDOW capability AND + * allows the output window to be changed on-the-fly. Currently it is only + * supported on Android. + * + * @param wid The video window ID. + * @param win The new output window. + * + * @return PJ_SUCCESS on success, or the appropriate error code. + */ +PJ_DECL(pj_status_t) pjsua_vid_win_set_win(pjsua_vid_win_id wid, + const pjmedia_vid_dev_hwnd *win); + +/** * Rotate the video window. This function will change the video orientation * and also possibly the video window size (width and height get swapped). * This operation is not valid for native windows (pjsua_vid_win_info.is_native diff --git a/pjsip/include/pjsua2/call.hpp b/pjsip/include/pjsua2/call.hpp index 510ad64d..0614270e 100644 --- a/pjsip/include/pjsua2/call.hpp +++ b/pjsip/include/pjsua2/call.hpp @@ -413,6 +413,13 @@ struct CallMediaInfo pjsua_vid_win_id videoIncomingWindowId; /** + * The video window instance for incoming video. Only valid if + * videoIncomingWindowId is not PJSUA_INVALID_ID and + * the media type is video. + */ + VideoWindow videoWindow; + + /** * The video capture device for outgoing transmission, if any, * or PJMEDIA_VID_INVALID_DEV. Only valid if the media type is video. */ diff --git a/pjsip/include/pjsua2/media.hpp b/pjsip/include/pjsua2/media.hpp index 99dd532e..181001e4 100644 --- a/pjsip/include/pjsua2/media.hpp +++ b/pjsip/include/pjsua2/media.hpp @@ -1325,6 +1325,169 @@ private: friend class Endpoint; }; + +/************************************************************************* +* Video media +*/ + +/** + * Representation of media coordinate. + */ +struct MediaCoordinate +{ + int x; /**< X position of the coordinate */ + int y; /**< Y position of the coordinate */ +}; + +/** + * Representation of media size. + */ +struct MediaSize +{ + unsigned w; /**< The width. */ + unsigned h; /**< The height. */ +}; + +/** + * Window handle. + */ +typedef struct WindowHandle { + void *window; /**< Window */ + void *display; /**< Display */ +} WindowHandle; + +/** + * Video window handle. + */ +struct VideoWindowHandle +{ + /** + * The window handle type. + */ + pjmedia_vid_dev_hwnd_type type; + + /** + * The window handle. + */ + WindowHandle handle; +}; + +/** + * This structure describes video window info. + */ +typedef struct VideoWindowInfo +{ + /** + * Flag to indicate whether this window is a native window, + * such as created by built-in preview device. If this field is + * true, only the video window handle field of this + * structure is valid. + */ + bool isNative; + + /** + * Video window handle. + */ + VideoWindowHandle winHandle; + + /** + * Renderer device ID. + */ + int renderDeviceId; + + /** + * Window show status. The window is hidden if false. + */ + bool show; + + /** + * Window position. + */ + MediaCoordinate pos; + + /** + * Window size. + */ + MediaSize size; + +} VideoWindowInfo; + +/** + * Video window. + */ +class VideoWindow +{ +public: + /** + * Constructor + */ + VideoWindow(int win_id); + + /** + * Get window info. + * + * @return video window info. + */ + VideoWindowInfo getInfo() const throw(Error); + + /** + * Show or hide window. This operation is not valid for native windows + * (VideoWindowInfo.isNative=true), on which native windowing API + * must be used instead. + * + * @param show Set to true to show the window, false to + * hide the window. + * + */ + void Show(bool show) throw(Error); + + /** + * Set video window position. This operation is not valid for native windows + * (VideoWindowInfo.isNative=true), on which native windowing API + * must be used instead. + * + * @param pos The window position. + * + */ + void setPos(const MediaCoordinate &pos) throw(Error); + + /** + * Resize window. This operation is not valid for native windows + * (VideoWindowInfo.isNative=true), on which native windowing API + * must be used instead. + * + * @param size The new window size. + * + */ + void setSize(const MediaSize &size) throw(Error); + + /** + * Rotate the video window. This function will change the video orientation + * and also possibly the video window size (width and height get swapped). + * This operation is not valid for native windows (VideoWindowInfo.isNative + * =true), on which native windowing API must be used instead. + * + * @param angle The rotation angle in degrees, must be + * multiple of 90. + * Specify positive value for clockwise rotation or + * negative value for counter-clockwise rotation. + */ + void rotate(int angle) throw(Error); + + /** + * Set output window. This operation is valid only when the underlying + * video device supports PJMEDIA_VIDEO_DEV_CAP_OUTPUT_WINDOW capability AND + * allows the output window to be changed on-the-fly, otherwise Error will + * be thrown. Currently it is only supported on Android. + * + * @param win The new output window. + */ + void setWindow(const VideoWindowHandle &win) throw(Error); + +private: + pjsua_vid_win_id winId; +}; + /************************************************************************* * Codec management */ diff --git a/pjsip/src/pjsua-lib/pjsua_vid.c b/pjsip/src/pjsua-lib/pjsua_vid.c index 028c7a35..a1f54f34 100644 --- a/pjsip/src/pjsua-lib/pjsua_vid.c +++ b/pjsip/src/pjsua-lib/pjsua_vid.c @@ -1405,6 +1405,40 @@ PJ_DEF(pj_status_t) pjsua_vid_win_set_size( pjsua_vid_win_id wid, } /* + * Set output window. + */ +PJ_DEF(pj_status_t) pjsua_vid_win_set_win( pjsua_vid_win_id wid, + const pjmedia_vid_dev_hwnd *win) +{ + pjsua_vid_win *w; + pjmedia_vid_dev_stream *s; + pj_status_t status; + + PJ_ASSERT_RETURN(wid >= 0 && wid < PJSUA_MAX_VID_WINS && win, PJ_EINVAL); + + PJSUA_LOCK(); + w = &pjsua_var.win[wid]; + if (w->vp_rend == NULL) { + /* Native window */ + PJSUA_UNLOCK(); + return PJ_EINVAL; + } + + s = pjmedia_vid_port_get_stream(w->vp_rend); + if (s == NULL) { + PJSUA_UNLOCK(); + return PJ_EINVAL; + } + + status = pjmedia_vid_dev_stream_set_cap(s, + PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW, win); + + PJSUA_UNLOCK(); + + return status; +} + +/* * Set video orientation. */ PJ_DEF(pj_status_t) pjsua_vid_win_rotate( pjsua_vid_win_id wid, diff --git a/pjsip/src/pjsua2/call.cpp b/pjsip/src/pjsua2/call.cpp index 1e4e72f3..f0bba738 100644 --- a/pjsip/src/pjsua2/call.cpp +++ b/pjsip/src/pjsua2/call.cpp @@ -224,6 +224,7 @@ pjsua_call_setting CallSetting::toPj() const CallMediaInfo::CallMediaInfo() +: videoWindow(PJSUA_INVALID_ID) { } @@ -237,6 +238,7 @@ void CallMediaInfo::fromPj(const pjsua_call_media_info &prm) this->audioConfSlot = (int)prm.stream.aud.conf_slot; } else if (this->type == PJMEDIA_TYPE_VIDEO) { this->videoIncomingWindowId = prm.stream.vid.win_in; + this->videoWindow = VideoWindow(prm.stream.vid.win_in); this->videoCapDev = prm.stream.vid.cap_dev; } } diff --git a/pjsip/src/pjsua2/media.cpp b/pjsip/src/pjsua2/media.cpp index 0a8b7fdb..c08e20aa 100644 --- a/pjsip/src/pjsua2/media.cpp +++ b/pjsip/src/pjsua2/media.cpp @@ -1007,6 +1007,68 @@ int AudDevManager::getActiveDev(bool is_capture) const throw(Error) } /////////////////////////////////////////////////////////////////////////////// +VideoWindow::VideoWindow(pjsua_vid_win_id win_id) +: winId(win_id) +{ +} + +VideoWindowInfo VideoWindow::getInfo() const throw(Error) +{ + VideoWindowInfo vwi; + pjsua_vid_win_info pj_vwi; + + PJSUA2_CHECK_EXPR( pjsua_vid_win_get_info(winId, &pj_vwi) ); + vwi.isNative = pj_vwi.is_native; + vwi.winHandle.type = pj_vwi.hwnd.type; + vwi.winHandle.handle.window = pj_vwi.hwnd.info.window; + vwi.renderDeviceId = pj_vwi.rdr_dev; + vwi.show = pj_vwi.show; + vwi.pos.x = pj_vwi.pos.x; + vwi.pos.y = pj_vwi.pos.y; + vwi.size.w = pj_vwi.size.w; + vwi.size.h = pj_vwi.size.h; + + return vwi; +} + +void VideoWindow::Show(bool show) throw(Error) +{ + PJSUA2_CHECK_EXPR( pjsua_vid_win_set_show(winId, show) ); +} + +void VideoWindow::setPos(const MediaCoordinate &pos) throw(Error) +{ + pjmedia_coord pj_pos; + + pj_pos.x = pos.x; + pj_pos.y = pos.y; + PJSUA2_CHECK_EXPR( pjsua_vid_win_set_pos(winId, &pj_pos) ); +} + +void VideoWindow::setSize(const MediaSize &size) throw(Error) +{ + pjmedia_rect_size pj_size; + + pj_size.w = size.w; + pj_size.h = size.h; + PJSUA2_CHECK_EXPR( pjsua_vid_win_set_size(winId, &pj_size) ); +} + +void VideoWindow::rotate(int angle) throw(Error) +{ + PJSUA2_CHECK_EXPR( pjsua_vid_win_rotate(winId, angle) ); +} + +void VideoWindow::setWindow(const VideoWindowHandle &win) throw(Error) +{ + pjmedia_vid_dev_hwnd vhwnd; + + vhwnd.type = win.type; + vhwnd.info.window = win.handle.window; + PJSUA2_CHECK_EXPR( pjsua_vid_win_set_win(winId, &vhwnd) ); +} + +/////////////////////////////////////////////////////////////////////////////// void CodecInfo::fromPj(const pjsua_codec_info &codec_info) { codecId = pj2Str(codec_info.codec_id); |