diff options
-rw-r--r-- | pjmedia/include/pjmedia-videodev/config.h | 19 | ||||
-rw-r--r-- | pjmedia/include/pjmedia-videodev/videodev.h | 11 | ||||
-rw-r--r-- | pjmedia/src/pjmedia-videodev/videodev.c | 4 | ||||
-rw-r--r-- | pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m | 9 | ||||
-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 |
7 files changed, 174 insertions, 37 deletions
diff --git a/pjmedia/include/pjmedia-videodev/config.h b/pjmedia/include/pjmedia-videodev/config.h index 1e097cd7..fcb0b0c8 100644 --- a/pjmedia/include/pjmedia-videodev/config.h +++ b/pjmedia/include/pjmedia-videodev/config.h @@ -55,6 +55,25 @@ PJ_BEGIN_DECL #if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0) /** + * This setting controls the maximum number of supported video device drivers. + * + * Default: 8 + */ +#ifndef PJMEDIA_VID_DEV_MAX_DRIVERS +# define PJMEDIA_VID_DEV_MAX_DRIVERS 8 +#endif + +/** + * This setting controls the maximum number of supported video devices. + * + * Default: 16 + */ +#ifndef PJMEDIA_VID_DEV_MAX_DEVS +# define PJMEDIA_VID_DEV_MAX_DEVS 16 +#endif + + +/** * This setting controls whether OpenGL for iOS should be included. * * Default: 0 (or detected by configure) diff --git a/pjmedia/include/pjmedia-videodev/videodev.h b/pjmedia/include/pjmedia-videodev/videodev.h index f1f08b63..21fba158 100644 --- a/pjmedia/include/pjmedia-videodev/videodev.h +++ b/pjmedia/include/pjmedia-videodev/videodev.h @@ -240,12 +240,11 @@ typedef enum pjmedia_vid_dev_cap PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW = 64, /** - * Support for changing video orientation in renderer and querying - * video orientation info in capture. Changing video orientation in - * a renderer will potentially affect the size of render window, - * i.e: width and height swap. When a capture device supports this - * capability, it will generate event PJMEDIA_EVENT_ORIENT_CHANGED - * (see #pjmedia_event) everytime the capture orientation is changed. + * Support for changing video orientation. For a renderer device, + * changing video orientation in will potentially affect the size of + * render window, i.e: width and height swap. For a capture device, + * the video will be rotated but the size of the video frame + * will stay the same, so the video may be resized or stretched. * * The value of this capability is pjmedia_orient. */ diff --git a/pjmedia/src/pjmedia-videodev/videodev.c b/pjmedia/src/pjmedia-videodev/videodev.c index 185f2171..8558588d 100644 --- a/pjmedia/src/pjmedia-videodev/videodev.c +++ b/pjmedia/src/pjmedia-videodev/videodev.c @@ -105,8 +105,8 @@ pjmedia_vid_dev_factory* pjmedia_opengl_factory(pj_pool_factory *pf); pjmedia_vid_dev_factory* pjmedia_and_factory(pj_pool_factory *pf); #endif -#define MAX_DRIVERS 16 -#define MAX_DEVS 64 +#define MAX_DRIVERS PJMEDIA_VID_DEV_MAX_DRIVERS +#define MAX_DEVS PJMEDIA_VID_DEV_MAX_DEVS /* driver structure */ diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m index c00c1ff7..18d3557e 100644 --- a/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m +++ b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m @@ -181,7 +181,7 @@ static void pjsuaOnAppConfigCb(pjsua_app_config *cfg) static UIDeviceOrientation prev_ori = 0; UIDeviceOrientation dev_ori = [[UIDevice currentDevice] orientation]; - if (dev_ori == prev_ori && !note) return; + if (dev_ori == prev_ori) return; NSLog(@"Device orientation changed: %d", (prev_ori = dev_ori)); @@ -192,8 +192,9 @@ static void pjsuaOnAppConfigCb(pjsua_app_config *cfg) pj_thread_register("ipjsua", a_thread_desc, &a_thread); } - pjsua_vid_dev_set_orient(PJMEDIA_VID_DEFAULT_CAPTURE_DEV, - pj_ori[dev_ori-1]); + pjsua_vid_dev_set_setting(PJMEDIA_VID_DEFAULT_CAPTURE_DEV, + PJMEDIA_VID_DEV_CAP_ORIENTATION, + &pj_ori[dev_ori-1], PJ_TRUE); } #endif } @@ -272,8 +273,6 @@ void displayWindow(pjsua_vid_win_id wid) i = (wid == PJSUA_INVALID_ID) ? 0 : wid; last = (wid == PJSUA_INVALID_ID) ? PJSUA_MAX_VID_WINS : wid+1; - [app orientationChanged:NULL]; - for (;i < last; ++i) { pjsua_vid_win_info wi; 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) |