Add example zoom support

parent 8ccf96ab
......@@ -58,6 +58,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MS_VIDEO_DISPLAY_SHOW_VIDEO \
MS_FILTER_METHOD(MSFilterVideoDisplayInterface,9,int)
#define MS_VIDEO_DISPLAY_ZOOM \
MS_FILTER_METHOD(MSFilterVideoDisplayInterface,9,int[4])
/**
* Interface definitions for players
......
......@@ -91,6 +91,9 @@ struct opengles_display {
/* runtime data */
float uvx[2], uvy[2];
MSVideoSize yuv_size[2];
/* coordinates of for zoom-in */
int top, left, bottom, right;
};
struct opengles_display* ogl_display_new() {
......@@ -227,11 +230,28 @@ static void ogl_display_render_type(struct opengles_display* gldisp, enum ImageT
}
ms_mutex_unlock(&gldisp->yuv_mutex);
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];
}
GLfloat squareUvs[] = {
0.0f, gldisp->uvy[type],
gldisp->uvx[type], gldisp->uvy[type],
0.0f, 0.0f,
gldisp->uvx[type], 0.0f
uLeft, vTop,
uRight, vTop,
uLeft, vBottom,
uRight, vBottom
};
if (clear) {
......@@ -453,6 +473,13 @@ 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;
}
#ifdef ANDROID
JNIEXPORT void JNICALL Java_org_linphone_mediastream_video_display_OpenGLESDisplay_init(JNIEnv * env, jobject obj, jint ptr, jint width, jint height) {
struct opengles_display* d = (struct opengles_display*) ptr;
......
......@@ -66,6 +66,8 @@ void ogl_display_set_preview_yuv_to_display(struct opengles_display* gldisp, mbl
void ogl_display_render(struct opengles_display* gldisp);
void ogl_display_zoom(struct opengles_display* gldisp, int top, int left, int bottom, int right);
#ifdef ANDROID
#include <jni.h>
JNIEXPORT void JNICALL Java_org_linphone_mediastream_video_display_OpenGLESDisplay_init(JNIEnv * env, jobject obj, jint ptr, jint width, jint height);
......
......@@ -551,6 +551,18 @@ static int x11video_show_video(MSFilter *f, void *arg){
return 0;
}
static int x11video_zoom(MSFilter *f, void *arg){
X11Video *s=(X11Video*)f->data;
#if HAVE_GL
ms_filter_lock(f);
ogl_display_zoom(s->glhelper, ((int*)arg)[0], ((int*)arg)[1], ((int*)arg)[2], ((int*)arg)[3]);
ms_filter_unlock(f);
#endif
return 0;
}
static int x11video_set_corner(MSFilter *f,void *arg){
X11Video *s=(X11Video*)f->data;
#ifdef HAVE_XV
......@@ -735,6 +747,7 @@ static MSFilterMethod methods[]={
{ MS_VIDEO_DISPLAY_SET_LOCAL_VIEW_SCALEFACTOR , x11video_set_scalefactor },
{ MS_VIDEO_DISPLAY_SET_BACKGROUND_COLOR , x11video_set_background_color},
{ MS_VIDEO_DISPLAY_SHOW_VIDEO , x11video_show_video },
{ MS_VIDEO_DISPLAY_ZOOM, x11video_zoom },
{ 0 ,NULL}
};
......
......@@ -111,6 +111,7 @@ typedef struct _MediastreamDatas {
char* srtp_local_master_key;
char* srtp_remote_master_key;
int netsim_bw;
float zoom;
AudioStream *audio;
PayloadType *pt;
......@@ -174,6 +175,7 @@ const char *usage="mediastream --local <port> --remote <ip:port> \n"
"[ --video-windows-id <video surface:preview surface>]\n"
"[ --srtp <local master_key> <remote master_key> (enable srtp, master key is generated if absent from comand line)\n"
"[ --netsim-bandwidth <bandwidth limit in bits/s> (simulates a network download bandwidth limit)\n"
"[ --zoom zoomfactor]\n"
;
......@@ -246,6 +248,7 @@ MediastreamDatas* init_default_args() {
args->ec_len_ms=args->ec_delay_ms=args->ec_framesize=0;
args->enable_srtp = FALSE;
args->srtp_local_master_key = args->srtp_remote_master_key = NULL;
args->zoom = 1.0;
args->audio = NULL;
args->session = NULL;
......@@ -389,6 +392,9 @@ bool_t parse_args(int argc, char** argv, MediastreamDatas* out) {
} else if (strcmp(argv[i],"--netsim-bandwidth")==0){
i++;
out->netsim_bw=atoi(argv[i]);
}else if (strcmp(argv[i],"--zoom")==0){
i++;
out->zoom=atof(argv[i]);
} else if (strcmp(argv[i],"--help")==0){
printf("%s",usage);
return FALSE;
......@@ -572,6 +578,16 @@ void setup_media_streams(MediastreamDatas* args) {
);
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);
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