diff options
author | Liong Sauw Ming <ming@teluu.com> | 2015-07-03 06:21:30 +0000 |
---|---|---|
committer | Liong Sauw Ming <ming@teluu.com> | 2015-07-03 06:21:30 +0000 |
commit | b08aa5cd83bb7d435cb9b59ab3c4c197d353c40b (patch) | |
tree | eee8c44809065d7166dd2ae21add0b5c56dbb41d /pjsip | |
parent | a4bd5dd01062c3f5f78227f3da46d79d39d0e1df (diff) |
Re #1861: Changed pjsua API for setting the orientation using a more generic API, pjsua_vid_dev_set_setting() instead
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5125 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua.h | 60 | ||||
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua_internal.h | 3 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_vid.c | 105 |
3 files changed, 144 insertions, 24 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index 8cc91f28..e6e0507c 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -6611,19 +6611,61 @@ PJ_DECL(pj_status_t) pjsua_vid_dev_get_info(pjmedia_vid_dev_index id, PJ_DECL(pj_bool_t) pjsua_vid_dev_is_active(pjmedia_vid_dev_index id); /** - * Set the orientation of the video device. The function only works - * for video capture device and if the device is currently active (i.e. - * a video preview has been started or there is a video call using the device). - * Application can check if a video device is active by calling - * #pjsua_vid_dev_is_active(). + * Configure the capability of a video capture device. If the device is + * currently active (i.e. if there is a video call using the device or + * a video preview has been started), the function will forward the setting + * to the video device instance to be applied immediately, if it supports it. + * + * The setting will be saved for future opening of the video device, if the + * "keep" argument is set to non-zero. If the video device is currently + * inactive, and the "keep" argument is false, this function will return + * error. + * + * Note: This function will only works for video capture devices. To + * configure the setting of video renderer device instances, use + * pjsua_vid_win API instead. + * + * Warning: If application refreshes the video device list, it needs to + * manually update the settings to reflect the newly updated video device + * indexes. See #pjmedia_vid_dev_refresh() for more information. + * + * See also #pjmedia_vid_stream_set_cap() for more information about setting + * a video device capability. * * @param id The video device index. - * @param orient Video device orientation. + * @param cap The video device capability to change. + * @param pval Pointer to value. Please see #pjmedia_vid_dev_cap + * documentation about the type of value to be + * supplied for each setting. * - * @return PJ_SUCCESS on success, or the appropriate error code. + * @return PJ_SUCCESS on success or the appropriate error code. + */ +PJ_DECL(pj_status_t) pjsua_vid_dev_set_setting(pjmedia_vid_dev_index id, + pjmedia_vid_dev_cap cap, + const void *pval, + pj_bool_t keep); + +/** + * Retrieve the value of a video capture device setting. If the device is + * currently active (i.e. if there is a video call using the device or + * a video preview has been started), the function will forward the request + * to the video device. If video device is currently inactive, and if + * application had previously set the setting and mark the setting as kept, + * then that setting will be returned. Otherwise, this function will return + * error. + * The function only works for video capture device. + * + * @param id The video device index. + * @param cap The video device capability to retrieve. + * @param pval Pointer to receive the value. + * Please see #pjmedia_vid_dev_cap documentation about + * the type of value to be supplied for each setting. + * + * @return PJ_SUCCESS on success or the appropriate error code. */ -PJ_DECL(pj_status_t) pjsua_vid_dev_set_orient(pjmedia_vid_dev_index id, - pjmedia_orient orient); +PJ_DECL(pj_status_t) pjsua_vid_dev_get_setting(pjmedia_vid_dev_index id, + pjmedia_vid_dev_cap cap, + void *pval); /** * Enum all video devices installed in the system. diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h index 91b68d50..91d1c646 100644 --- a/pjsip/include/pjsua-lib/pjsua_internal.h +++ b/pjsip/include/pjsua-lib/pjsua_internal.h @@ -482,6 +482,9 @@ struct pjsua_data /* Video device */ pjmedia_vid_dev_index vcap_dev; /**< Capture device ID. */ pjmedia_vid_dev_index vrdr_dev; /**< Playback device ID. */ + /* For keeping video device settings */ + pj_uint32_t vid_caps[PJMEDIA_VID_DEV_MAX_DEVS]; + pjmedia_vid_dev_param vid_param[PJMEDIA_VID_DEV_MAX_DEVS]; /* File players: */ unsigned player_cnt;/**< Number of file players. */ diff --git a/pjsip/src/pjsua-lib/pjsua_vid.c b/pjsip/src/pjsua-lib/pjsua_vid.c index 54d23ad2..b8082676 100644 --- a/pjsip/src/pjsua-lib/pjsua_vid.c +++ b/pjsip/src/pjsua-lib/pjsua_vid.c @@ -226,28 +226,86 @@ PJ_DEF(pj_bool_t) pjsua_vid_dev_is_active(pjmedia_vid_dev_index id) } /* - * Set the orientation of the video device. + * Set the capability of the video device. */ -PJ_DEF(pj_status_t) pjsua_vid_dev_set_orient( pjmedia_vid_dev_index id, - pjmedia_orient orient) +PJ_DEF(pj_status_t) pjsua_vid_dev_set_setting( pjmedia_vid_dev_index id, + pjmedia_vid_dev_cap cap, + const void *pval, + pj_bool_t keep) { - pjsua_vid_win *w; - pjmedia_vid_dev_stream *cap_dev; + pj_status_t status = PJ_SUCCESS; pjsua_vid_win_id wid = vid_preview_get_win(id, PJ_FALSE); - if (wid == PJSUA_INVALID_ID) { - PJ_LOG(3, (THIS_FILE, "Unable to set orientation for video dev %d: " - "device not active", id)); - return PJ_ENOTFOUND; + if (wid != PJSUA_INVALID_ID) { + pjsua_vid_win *w; + pjmedia_vid_dev_stream *cap_dev; + + w = &pjsua_var.win[wid]; + cap_dev = pjmedia_vid_port_get_stream(w->vp_cap); + + status = pjmedia_vid_dev_stream_set_cap(cap_dev, cap, pval); + if (status != PJ_SUCCESS) + return status; + } else { + status = PJ_ENOTFOUND; } - w = &pjsua_var.win[wid]; + if (keep) { + pjmedia_vid_dev_info info; + + status = pjmedia_vid_dev_get_info(id, &info); + if (status != PJ_SUCCESS || (info.dir & PJMEDIA_DIR_CAPTURE) == 0) + return status; - cap_dev = pjmedia_vid_port_get_stream(w->vp_cap); + /* Get real capture ID, if set to PJMEDIA_VID_DEFAULT_CAPTURE_DEV */ + id = info.id; + status = pjmedia_vid_dev_param_set_cap(&pjsua_var.vid_param[id], + cap, pval); + if (status == PJ_SUCCESS) { + pjsua_var.vid_caps[id] |= cap; + } + } + + return status; +} - return pjmedia_vid_dev_stream_set_cap(cap_dev, - PJMEDIA_VID_DEV_CAP_ORIENTATION, - &orient); +/* + * Get the value of the video device capability. + */ +PJ_DEF(pj_status_t) pjsua_vid_dev_get_setting( pjmedia_vid_dev_index id, + pjmedia_vid_dev_cap cap, + void *pval) +{ + pj_status_t status = PJ_SUCCESS; + pjsua_vid_win_id wid = vid_preview_get_win(id, PJ_FALSE); + + if (wid != PJSUA_INVALID_ID) { + pjsua_vid_win *w; + pjmedia_vid_dev_stream *cap_dev; + + w = &pjsua_var.win[wid]; + cap_dev = pjmedia_vid_port_get_stream(w->vp_cap); + + status = pjmedia_vid_dev_stream_get_cap(cap_dev, cap, pval); + } else { + pjmedia_vid_dev_info info; + + status = pjmedia_vid_dev_get_info(id, &info); + if (status != PJ_SUCCESS) + return status; + + /* Get real device ID, if set to default device */ + id = info.id; + + if ((pjsua_var.vid_caps[id] & cap) != 0) { + status = pjmedia_vid_dev_param_get_cap(&pjsua_var.vid_param[id], + cap, pval); + } else { + status = PJ_ENOTFOUND; + } + } + + return status; } /* @@ -613,8 +671,25 @@ static pj_status_t create_vid_win(pjsua_vid_win_type type, /* Create capture video port */ vp_param.active = PJ_TRUE; vp_param.vidparam.dir = PJMEDIA_DIR_CAPTURE; - if (fmt) + + /* Update the video setting with user preference */ +#define update_param(cap, field) \ + if ((pjsua_var.vid_caps[cap_id] & cap) && (vdi.caps & cap)) { \ + vp_param.vidparam.flags |= cap; \ + pj_memcpy(&vp_param.vidparam.field, \ + &pjsua_var.vid_param[cap_id].field, \ + sizeof(vp_param.vidparam.field)); \ + } + + if (fmt) { vp_param.vidparam.fmt = *fmt; + } else { + update_param(PJMEDIA_VID_DEV_CAP_FORMAT, fmt); + } + + update_param(PJMEDIA_VID_DEV_CAP_ORIENTATION, orient); + +#undef update_param status = pjmedia_vid_port_create(w->pool, &vp_param, &w->vp_cap); if (status != PJ_SUCCESS) |