Check if the screen is rotated directly through the sensor.
[Version] 0.3.215
[Issue Type] Improvement
Change-Id: I3067c8ffe651a4b2ac7230ee8adeb91d2f39dc67
SET(dependents "dlog glib-2.0 gstreamer-1.0 gstreamer-webrtc-1.0 gstreamer-video-1.0 gstreamer-audio-1.0 \
gstreamer-allocators-1.0 libpulse json-glib-1.0 iniparser mm-common mm-display-interface capi-media-tool \
- libtbm libwebsockets cynara-client libsmack capi-system-info libsoup-2.4 bundle capi-media-sound-manager mm-fileinfo")
+ libtbm libwebsockets cynara-client libsmack capi-system-info capi-system-sensor libsoup-2.4 bundle capi-media-sound-manager mm-fileinfo")
IF(NOT TIZEN_PROFILE_TV)
SET(dependents "${dependents} mm-resource-manager")
ELSE()
* @brief Sets the crop coordinates of screen source.
* @since_tizen 6.5
* @remarks The base position is always the upper left conner of the UI coordinates.\n
- * If the physical display is rotated and the UI is also rotated according to the rotation, @a portrait_mode and the cropping coordinates must be updated.\n
* The display resolution and video resolution of this screen source are different,
* this function uses the input parameters to crop the screen source based on the display resolution and it changes the video resolution of the screen source as a result.
* @param[in] webrtc WebRTC handle
* @param[in] h Height of UI for cropping
* @param[out] width Cropped video resolution width
* @param[out] height Cropped video resolution height
- * @param[in] portrait_mode Screen is portrait mode or not (@c true = portrait mode, @c false = landscape mode)
* @return @c 0 on success,
* otherwise a negative error value
* @retval #WEBRTC_ERROR_NONE Successful
* @pre @a webrtc state must be set to #WEBRTC_STATE_NEGOTIATING or #WEBRTC_STATE_PLAYING.
* @see webrtc_screen_source_unset_crop()
*/
-int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int w, int h, bool portrait_mode, int *width, int *height);
+int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int w, int h, int *width, int *height);
/**
* @internal
/* screen source */
int _get_screen_resolution(int *width, int *height);
-int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int y, int w, int h, bool portrait_mode, int *width, int *height);
+int _set_screen_rotation_changed_cb(webrtc_gst_slot_s *source);
+int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int y, int w, int h, int *width, int *height);
int _unset_screen_source_crop(webrtc_s *webrtc, unsigned int source_id);
/* source */
Name: capi-media-webrtc
Summary: A WebRTC library in Tizen Native API
-Version: 0.3.214
+Version: 0.3.215
Release: 0
Group: Multimedia/API
License: Apache-2.0
BuildRequires: pkgconfig(cynara-client)
BuildRequires: pkgconfig(libsmack)
BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(capi-system-sensor)
BuildRequires: pkgconfig(capi-media-sound-manager)
BuildRequires: pkgconfig(bundle)
BuildRequires: pkgconfig(mm-fileinfo)
return WEBRTC_ERROR_NONE;
}
-int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int w, int h, bool portrait_mode, int *width, int *height)
+int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int w, int h, int *width, int *height)
{
g_autoptr(GMutexLocker) locker = NULL;
webrtc_s *_webrtc = (webrtc_s *)webrtc;
locker = g_mutex_locker_new(&_webrtc->mutex);
#ifdef TIZEN_FEATURE_UI
- return _set_screen_source_crop(_webrtc, source_id, x, y, w, h, portrait_mode, width, height);
+ return _set_screen_source_crop(_webrtc, source_id, x, y, w, h, width, height);
#else
LOG_ERROR("TIZEN_FEATURE_UI is disabled, skip this function");
return WEBRTC_ERROR_INVALID_OPERATION;
if (!__set_default_video_info(source, ini_source))
return WEBRTC_ERROR_INVALID_OPERATION;
+ if ((ret = _set_screen_rotation_changed_cb(source)) != WEBRTC_ERROR_NONE)
+ return ret;
+
if (!(screensrc = _create_element(_get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_SCREEN), ELEMENT_NAME_SCREENSRC)))
return WEBRTC_ERROR_INVALID_OPERATION;
APPEND_ELEMENT(switch_src_list, screensrc);
if (source->av[av_idx].pt >= MIN_DYNAMIC_PAYLOAD_TYPE)
__return_payload_type(webrtc, source->av[av_idx].pt);
- if((ret = _set_payload_type(webrtc, source, av_idx, payload_info->gst_media_type)) != WEBRTC_ERROR_NONE)
+ if ((ret = _set_payload_type(webrtc, source, av_idx, payload_info->gst_media_type)) != WEBRTC_ERROR_NONE)
return ret;
}
#include "webrtc_private.h"
#include "webrtc_source_private.h"
#include <Elementary.h>
+#include <sensor.h>
+#include <sensor-internal.h>
//LCOV_EXCL_START
-int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int y, int w, int h, bool portrait_mode, int *width, int *height)
+int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int y, int w, int h, int *width, int *height)
{
webrtc_gst_slot_s *source = NULL;
GstElement *screen_source = NULL;
int mirroring_x, mirroring_y, mirroring_width, mirroring_height;
float rw, rh;
int left, right, top, bottom;
+ bool portrait_mode = true;
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0");
videocrop = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VIDEOCROP);
RET_VAL_IF(videocrop == NULL, WEBRTC_ERROR_INVALID_OPERATION, "videocrop is NULL");
+ if (source->video_info.origin_width > source->video_info.origin_height)
+ portrait_mode = false;
+
LOG_INFO("set source crop x:%d, y:%d, width:%d, height:%d, mode:%s", x, y, w, h, (portrait_mode) ? "portrait" : "landscape");
g_object_get(G_OBJECT(screen_source),
top = mirroring_y + ((float)y /rh);
bottom = output_height - (top + (float)h / rh);
- LOG_INFO("Screen source info: source[width:%d, height:%d], output[width:%d, height:%d]"
- "mirroring[x:%d y:%d width:%d, height:%d", src_width, src_height, output_width,
- output_height, mirroring_x, mirroring_y, mirroring_width, mirroring_height);
+ LOG_INFO("Screen source info: source[width:%d, height:%d], output[width:%d, height:%d] mirroring[x:%d y:%d width:%d, height:%d]",
+ src_width, src_height, output_width, output_height, mirroring_x, mirroring_y, mirroring_width, mirroring_height);
g_object_set(G_OBJECT(videocrop),
"left", left,
RET_VAL_IF(width == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "width is NULL");
RET_VAL_IF(height == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "height is NULL");
+ /* This function returns the resolution when the device rotation angle is "0" regardless of the actual rotation direction of the device. */
+
eo = elm_win_add(NULL, "screen_source", ELM_WIN_BASIC);
if (!eo) {
LOG_ERROR("failed to elm_win_add()");
return WEBRTC_ERROR_NONE;
}
-//LCOV_EXCL_STOP
\ No newline at end of file
+static void __screen_rotation_changed_cb(sensor_h sensor, sensor_event_s events[], int events_count, void *user_data)
+{
+ webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)user_data;
+ int width;
+ int height;
+ int type;
+ int event;
+ int angle;
+
+ RET_IF(source == NULL, "source is NULL");
+ RET_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_SCREEN, "invalid source type [%d]", source->type);
+
+ sensor_get_type(sensor, &type);
+ if (type != AUTO_ROTATION_SENSOR)
+ return;
+
+ event = (int)events->values[0];
+
+ switch (event) {
+ case AUTO_ROTATION_DEGREE_0:
+ angle = 0;
+ break;
+ case AUTO_ROTATION_DEGREE_90:
+ angle = 90;
+ break;
+ case AUTO_ROTATION_DEGREE_180:
+ angle = 180;
+ break;
+ case AUTO_ROTATION_DEGREE_270:
+ angle = 270;
+ break;
+ default:
+ LOG_ERROR("invalid event [%d]", event);
+ return;
+ }
+
+ LOG_DEBUG("screen rotation changed [%d]", angle);
+
+ if (_get_screen_resolution(&width, &height) != WEBRTC_ERROR_NONE)
+ return;
+
+ g_mutex_lock(&source->webrtc->mutex);
+ if (angle == 0 || angle == 180) {
+ source->video_info.origin_width = width;
+ source->video_info.origin_height = height;
+ } else {
+ source->video_info.origin_width = height;
+ source->video_info.origin_height = width;
+ }
+ g_mutex_unlock(&source->webrtc->mutex);
+}
+
+int _set_screen_rotation_changed_cb(webrtc_gst_slot_s *source)
+{
+ bool supported;
+ sensor_h *sh;
+ int count;
+ sensor_listener_h lh;
+
+ RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
+
+ sensor_is_supported(AUTO_ROTATION_SENSOR, &supported);
+
+ if (!supported) {
+ LOG_INFO("AUTO_ROTATION_SENSOR is not supported");
+ return WEBRTC_ERROR_NONE;
+ }
+
+ sensor_get_sensor_list(AUTO_ROTATION_SENSOR, &sh, &count);
+
+ sensor_create_listener(sh[0], &lh);
+
+ sensor_listener_set_events_cb(lh, __screen_rotation_changed_cb, source);
+ sensor_listener_set_option(lh, SENSOR_OPTION_ALWAYS_ON);
+ sensor_listener_set_interval(lh, 100);
+
+ if (sensor_listener_start(lh) != SENSOR_ERROR_NONE) {
+ LOG_ERROR("failed to sensor_listener_start()");
+ return WEBRTC_ERROR_INVALID_OPERATION;
+ }
+
+ LOG_INFO("AUTO_ROTATION_SENSOR is supported");
+
+ return WEBRTC_ERROR_NONE;
+}
+//LCOV_EXCL_STOP
source_id, g_webrtc_media_type_str[media_type], bitrate);
}
-static void _webrtc_screen_source_set_crop(int index, unsigned int source_id, int x, int y, int w, int h, int is_vertical, int *width, int *height)
+static void _webrtc_screen_source_set_crop(int index, unsigned int source_id, int x, int y, int w, int h, int *width, int *height)
{
int ret = WEBRTC_ERROR_NONE;
- ret = webrtc_screen_source_set_crop(g_ad.conns[index].webrtc, source_id, x, y, w, h, is_vertical, width, height);
+ ret = webrtc_screen_source_set_crop(g_ad.conns[index].webrtc, source_id, x, y, w, h, width, height);
if (ret != WEBRTC_ERROR_NONE)
g_print("failed to webrtc_screen_source_set_crop(), source_id[%d], ret[0x%x]\n", source_id, ret);
case CURRENT_STATUS_SCREEN_SOURCE_SET_CROP: {
static unsigned int id;
static int x, y, w, h;
- static int is_vertical;
switch (g_ad.input_count) {
case 0:
return;
case 4:
h = value;
- g_ad.input_count++;
- return;
- case 5:
- is_vertical = value;
int width, height;
- _webrtc_screen_source_set_crop(0, id, x, y, w, h, is_vertical, &width, &height);
- x = y = w = h = is_vertical = 0;
+ _webrtc_screen_source_set_crop(0, id, x, y, w, h, &width, &height);
+ x = y = w = h = 0;
g_ad.input_count = 0;
break;
}
g_print("*** input width.\n");
else if (get_appdata()->input_count == 4)
g_print("*** input height.\n");
- else if (get_appdata()->input_count == 5)
- g_print("*** input whether screen rotates (0: horizontal, 1: vertical).\n");
break;
case CURRENT_STATUS_SCREEN_SOURCE_UNSET_CROP:
if (get_appdata()->input_count == 0)