video: add zoom support to ios display

parent da89da8f
......@@ -221,7 +221,7 @@ static int glxvideo_zoom(MSFilter *f, void *arg){
GLXVideo *s=(GLXVideo*)f->data;
ms_filter_lock(f);
ogl_display_zoom(s->glhelper, ((int*)arg)[0], ((int*)arg)[1], ((int*)arg)[2], ((int*)arg)[3]);
ogl_display_zoom(s->glhelper, arg);
ms_filter_unlock(f);
return 0;
......
......@@ -265,11 +265,17 @@ static int iosdisplay_set_device_orientation(MSFilter* f, void* arg) {
return 0;
}
static int iosdisplay_set_zoom(MSFilter* f, void* arg) {
IOSDisplay* thiz=(IOSDisplay*)f->data;
ogl_display_zoom(thiz->helper, arg);
}
static MSFilterMethod iosdisplay_methods[]={
{ MS_VIDEO_DISPLAY_SET_NATIVE_WINDOW_ID , iosdisplay_set_native_window },
{ MS_VIDEO_DISPLAY_GET_NATIVE_WINDOW_ID , iosdisplay_get_native_window },
{ MS_VIDEO_DISPLAY_SET_DEVICE_ORIENTATION, iosdisplay_set_device_orientation },
{ MS_VIDEO_DISPLAY_ZOOM, iosdisplay_set_zoom},
{ 0, NULL}
};
@end
......
......@@ -88,7 +88,9 @@ struct opengles_display {
MSVideoSize yuv_size[2];
/* coordinates of for zoom-in */
int top, left, bottom, right;
float zoom_factor;
float zoom_cx;
float zoom_cy;
};
struct opengles_display* ogl_display_new() {
......@@ -99,6 +101,8 @@ struct opengles_display* ogl_display_new() {
return 0;
}
memset(result, 0, sizeof(struct opengles_display));
result->zoom_factor = 1;
result->zoom_cx = result->zoom_cy = 0;
ms_mutex_init(&result->yuv_mutex, NULL);
ms_message("%s : %p\n", __FUNCTION__, result);
......@@ -231,20 +235,9 @@ static void ogl_display_render_type(struct opengles_display* gldisp, enum ImageT
float uLeft, uRight, vTop, vBottom;
if (type == REMOTE_IMAGE && (gldisp->top != 0 || gldisp->bottom != 0 || gldisp->left != 0 || gldisp->right != 0)) {
MSPicture yuvbuf;
ms_yuv_buf_init_from_mblk(&yuvbuf, gldisp->yuv[type]);
// zoom in
uLeft = gldisp->uvx[type] * gldisp->left / (float)yuvbuf.w;
uRight = gldisp->uvx[type] * gldisp->right / (float)yuvbuf.w;
vTop = gldisp->uvy[type] * gldisp->top / (float)yuvbuf.h;
vBottom = gldisp->uvy[type] * gldisp->bottom / (float)yuvbuf.h;
} else {
uLeft = vBottom = 0.0f;
uRight = gldisp->uvx[type];
vTop = gldisp->uvy[type];
}
uLeft = vBottom = 0.0f;
uRight = gldisp->uvx[type];
vTop = gldisp->uvy[type];
GLfloat squareUvs[] = {
uLeft, vTop,
......@@ -305,7 +298,20 @@ static void ogl_display_render_type(struct opengles_display* gldisp, enum ImageT
GL_OPERATION(glViewport(0, 0, gldisp->backingWidth, gldisp->backingHeight))
GLfloat mat[16];
load_orthographic_matrix(-0.5, 0.5, -0.5, 0.5, 0, 0.5, mat);
#define VP_SIZE 1.0f
if (type == REMOTE_IMAGE) {
float scale_factor = 1.0 / gldisp->zoom_factor;
float vpDim = (VP_SIZE * scale_factor) / 2;
load_orthographic_matrix(
gldisp->zoom_cx - vpDim,
gldisp->zoom_cx + vpDim,
gldisp->zoom_cy - vpDim,
gldisp->zoom_cy + vpDim,
0, 0.5, mat);
} else {
load_orthographic_matrix(- VP_SIZE * 0.5, VP_SIZE * 0.5, - VP_SIZE * 0.5, VP_SIZE * 0.5, 0, 0.5, mat);
}
GL_OPERATION(glUniformMatrix4fv(gldisp->uniforms[UNIFORM_PROJ_MATRIX], 1, GL_FALSE, mat))
#define degreesToRadians(d) (2.0 * 3.14157 * d / 360.0)
......@@ -511,11 +517,10 @@ static bool_t update_textures_with_yuv(struct opengles_display* gldisp, enum Ima
return TRUE;
}
void ogl_display_zoom(struct opengles_display* gldisp, int top, int left, int bottom, int right) {
gldisp->top = top;
gldisp->left = left;
gldisp->bottom = bottom;
gldisp->right = right;
void ogl_display_zoom(struct opengles_display* gldisp, float* params) {
gldisp->zoom_factor = params[0];
gldisp->zoom_cx = params[1] - 0.5;
gldisp->zoom_cy = params[2] - 0.5;
}
#ifdef ANDROID
......
......@@ -66,7 +66,10 @@ void ogl_display_set_preview_yuv_to_display(struct opengles_display* gldisp, mbl
void ogl_display_render(struct opengles_display* gldisp, int deviceAngleFromPortrait);
void ogl_display_zoom(struct opengles_display* gldisp, int top, int left, int bottom, int right);
/**
* @params contains the zoom parameters: [0] = zoom_factor, [1][2] = zoom center x/y (between [0,1], relative coords to the gl surface. 0.5/0.5 = center)
*/
void ogl_display_zoom(struct opengles_display* gldisp, float* params);
#ifdef ANDROID
#include <jni.h>
......
......@@ -113,6 +113,7 @@ typedef struct _MediastreamDatas {
char* srtp_remote_master_key;
int netsim_bw;
float zoom;
float zoom_cx, zoom_cy;
AudioStream *audio;
PayloadType *pt;
......@@ -277,6 +278,7 @@ MediastreamDatas* init_default_args() {
args->enable_srtp = FALSE;
args->srtp_local_master_key = args->srtp_remote_master_key = NULL;
args->zoom = 1.0;
args->zoom_cx = args->zoom_cy = 0.5;
args->audio = NULL;
args->session = NULL;
......@@ -422,7 +424,10 @@ bool_t parse_args(int argc, char** argv, MediastreamDatas* out) {
out->netsim_bw=atoi(argv[i]);
}else if (strcmp(argv[i],"--zoom")==0){
i++;
out->zoom=atof(argv[i]);
if (sscanf(argv[i], "%f,%f,%f", &out->zoom, &out->zoom_cx, &out->zoom_cy) != 3) {
ms_error("Invalid zoom triplet");
return FALSE;
}
} else if (strcmp(argv[i],"--help")==0){
printf("%s",usage);
return FALSE;
......@@ -605,17 +610,11 @@ void setup_media_streams(MediastreamDatas* args) {
args->jitter,cam
);
args->session=args->video->session;
float scale = 1.0 / args->zoom;
int cx = args->vs.width * 0.5;
int cy = args->vs.height * 0.5;
int zoom[] = {
cy + args->vs.height * scale * 0.5,
cx - args->vs.width * scale * 0.5,
cy - args->vs.height * scale * 0.5,
cx + args->vs.width * scale * 0.5};
ms_filter_call_method(args->video->output,MS_VIDEO_DISPLAY_ZOOM,&zoom);
float zoom[] = {
args->zoom,
args->zoom_cx, args->zoom_cy };
ms_filter_call_method(args->video->output,MS_VIDEO_DISPLAY_ZOOM, zoom);
if (args->enable_srtp) {
ms_message("SRTP enabled: %d",
video_stream_enable_strp(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment