Commit 6701e074 authored by Simon Morlat's avatar Simon Morlat

XvXshm display works

+ big cleanups
parent e13dd416
......@@ -125,11 +125,7 @@ AC_DEFUN([MS_CHECK_VIDEO],[
sdl_found=no
if test "$enable_sdl" = "true"; then
PKG_CHECK_MODULES(SDL, [sdl >= 1.2.0 ],sdl_found=yes,sdl_found=no)
if test "$sdl_found" = "no" && test "$mingw_found" != "yes"; then
AC_MSG_ERROR([Could not find libsdl headers and library. This is mandatory for video support])
fi
PKG_CHECK_MODULES(SDL, [sdl >= 1.2.0 ],sdl_found=true,sdl_found=false)
fi
AC_ARG_ENABLE(x11,
......@@ -145,17 +141,23 @@ AC_DEFUN([MS_CHECK_VIDEO],[
fi
AC_ARG_ENABLE(xv,
[ --enable-xv Enable xv support - experimental],
[ --enable-xv Enable xv supportl],
[case "${enableval}" in
yes) enable_xv=true ;;
no) enable_xv=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-xv) ;;
esac],[enable_xv=false])
esac],[enable_xv=true])
if test "$enable_xv" = "true"; then
AC_CHECK_HEADERS(X11/extensions/Xv.h)
AC_CHECK_HEADERS(X11/extensions/Xv.h,[] ,[enable_xv=false])
AC_CHECK_LIB(Xv,XvCreateImage,[LIBS="$LIBS -lXv"])
fi
fi
fi
if ! test "$mingw_found" = "yes" ; then
if test "$enable_xv$sdl_found" == "nono" ; then
AC_MSG_ERROR([No video output API found. Install either X11+Xv headers or SDL library.])
fi
fi
AC_ARG_ENABLE(theora,
......@@ -178,7 +180,7 @@ AC_DEFUN([MS_CHECK_VIDEO],[
VIDEO_CFLAGS=" $FFMPEG_CFLAGS -DVIDEO_ENABLED"
VIDEO_LIBS=" $FFMPEG_LIBS $SWSCALE_LIBS"
if test "$sdl_found" = "yes" ; then
if test "$sdl_found" = "true" ; then
VIDEO_CFLAGS="$VIDEO_CFLAGS $SDL_CFLAGS -DHAVE_SDL"
VIDEO_LIBS="$VIDEO_LIBS $SDL_LIBS"
fi
......
dnl Process this file with autoconf to produce a configure script.
AC_INIT([mediastreamer],[2.6.0])
AC_INIT([mediastreamer],[2.7.0])
AC_MSG_NOTICE([$PACKAGE_NAME-$PACKAGE_VERSION A mediastreaming library for telephony application.])
AC_MSG_NOTICE([licensed under the terms of the General Public License (GPL)])
......@@ -12,8 +12,8 @@ MEDIASTREAMER_MINOR_VERSION=$(echo $PACKAGE_VERSION | cut -d. -f2)
MEDIASTREAMER_MICRO_VERSION=$(echo $PACKAGE_VERSION | cut -d. -f3)
MEDIASTREAMER_EXTRA_VERSION=$(echo $PACKAGE_VERSION | cut -d. -f4)
LIBMEDIASTREAMER_SO_CURRENT=0 dnl increment this number when you add/change/remove an interface
LIBMEDIASTREAMER_SO_REVISION=1 dnl increment this number when you change source code, without changing interfaces; set to 0 when incrementing CURRENT
LIBMEDIASTREAMER_SO_CURRENT=1 dnl increment this number when you add/change/remove an interface
LIBMEDIASTREAMER_SO_REVISION=0 dnl increment this number when you change source code, without changing interfaces; set to 0 when incrementing CURRENT
LIBMEDIASTREAMER_SO_AGE=0 dnl increment this number when you add an interface, set to 0 if you remove an interface
LIBMEDIASTREAMER_SO_VERSION=$LIBMEDIASTREAMER_SO_CURRENT:$LIBMEDIASTREAMER_SO_REVISION:$LIBMEDIASTREAMER_SO_AGE
......@@ -519,6 +519,8 @@ AM_CONDITIONAL(BUILD_THEORA, test "$have_theora" = "yes")
AM_CONDITIONAL(BUILD_WIN32, test "$mingw_found" = "yes")
AM_CONDITIONAL(BUILD_WIN32_WCE, test "$mingw32ce_found" = "yes")
AM_CONDITIONAL(BUILD_FFMPEG, test "$ffmpeg" = "true")
AM_CONDITIONAL(BUILD_SDL,test "$sdl_found" = "true" )
AM_CONDITIONAL(BUILD_X11_XV, test "$enable_xv" = "true" )
dnl *********************************************
dnl setup oRTP dependency
......
......@@ -102,7 +102,8 @@ typedef enum MSFilterId{
MS_IOUNIT_WRITE_ID,
MS_ANDROID_SOUND_READ_ID,
MS_ANDROID_SOUND_WRITE_ID,
MS_JPEG_WRITER_ID
MS_JPEG_WRITER_ID,
MS_X11VIDEO_ID
} MSFilterId;
......
......@@ -50,15 +50,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MS_VIDEO_DISPLAY_SET_LOCAL_VIEW_SCALEFACTOR \
MS_FILTER_METHOD(MSFilterVideoDisplayInterface,5,float)
/**scale factor of the local view */
#define MS_VIDEO_DISPLAY_SET_SELFVIEW_POS \
MS_FILTER_METHOD(MSFilterVideoDisplayInterface,6,float[3])
/**scale factor of the local view */
#define MS_VIDEO_DISPLAY_GET_SELFVIEW_POS \
MS_FILTER_METHOD(MSFilterVideoDisplayInterface,7,float[3])
/**scale factor of the local view */
/**Set the background colour for video window */
#define MS_VIDEO_DISPLAY_SET_BACKGROUND_COLOR \
MS_FILTER_METHOD(MSFilterVideoDisplayInterface,8,int[3])
......
......@@ -185,9 +185,9 @@ int ms_pix_fmt_to_ffmpeg(MSPixFmt fmt);
MSPixFmt ffmpeg_pix_fmt_to_ms(int fmt);
MSPixFmt ms_fourcc_to_pix_fmt(uint32_t fourcc);
void ms_ffmpeg_check_init(void);
int yuv_buf_init_from_mblk(MSPicture *buf, mblk_t *m);
void yuv_buf_init_from_mblk_with_size(MSPicture *buf, mblk_t *m, int w, int h);
mblk_t * yuv_buf_alloc(MSPicture *buf, int w, int h);
int ms_yuv_buf_init_from_mblk(MSPicture *buf, mblk_t *m);
void ms_yuv_buf_init_from_mblk_with_size(MSPicture *buf, mblk_t *m, int w, int h);
mblk_t * ms_yuv_buf_alloc(MSPicture *buf, int w, int h);
void ms_yuv_buf_copy(uint8_t *src_planes[], const int src_strides[],
uint8_t *dst_planes[], const int dst_strides[3], MSVideoSize roi);
void ms_yuv_buf_mirror(YuvBuf *buf);
......@@ -196,6 +196,8 @@ void rgb24_revert(uint8_t *buf, int w, int h, int linesize);
void rgb24_copy_revert(uint8_t *dstbuf, int dstlsz,
const uint8_t *srcbuf, int srclsz, MSVideoSize roi);
void ms_rgb_to_yuv(const uint8_t rgb[3], uint8_t yuv[3]);
static inline bool_t ms_video_size_greater_than(MSVideoSize vs1, MSVideoSize vs2){
return (vs1.width>=vs2.width) && (vs1.height>=vs2.height);
}
......@@ -262,6 +264,5 @@ void ms_video_set_video_func(struct ms_swscaleDesc *_ms_swscale_desc);
/* request a video-fast-update (=I frame for H263,MP4V-ES) to a video encoder*/
#define MS_FILTER_REQ_VFU MS_FILTER_BASE_METHOD_NO_ARG(106)
#define MS_FILTER_SET_IMAGE MS_FILTER_BASE_METHOD(107,char)
#endif
......@@ -24,89 +24,5 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <mediastreamer2/msvideo.h>
struct _MSDisplay;
typedef enum _MSDisplayEventType{
MS_DISPLAY_RESIZE_EVENT
}MSDisplayEventType;
typedef struct _MSDisplayEvent{
MSDisplayEventType evtype;
int w,h;
}MSDisplayEvent;
typedef struct _MSDisplayDesc{
/*init requests setup of the display window at the proper size, given
in frame_buffer argument. Memory buffer (data,strides) must be fulfilled
at return. init() might be called several times upon screen resize*/
bool_t (*init)(struct _MSDisplay *, struct _MSFilter *f, MSPicture *frame_buffer, MSPicture *selfview_buffer);
void (*lock)(struct _MSDisplay *);/*lock before writing to the framebuffer*/
void (*unlock)(struct _MSDisplay *);/*unlock after writing to the framebuffer*/
void (*update)(struct _MSDisplay *, int new_image, int new_selfview); /*display the picture to the screen*/
void (*uninit)(struct _MSDisplay *);
int (*pollevent)(struct _MSDisplay *, MSDisplayEvent *ev);
long default_window_id;
}MSDisplayDesc;
typedef struct _MSDisplay{
MSDisplayDesc *desc;
long window_id; /*window id if the display should use an existing window*/
void *data;
bool_t use_external_window;
} MSDisplay;
#define ms_display_init(d,f,fbuf,fbuf_selfview) (d)->desc->init(d,f,fbuf,fbuf_selfview)
#define ms_display_lock(d) if ((d)->desc->lock) (d)->desc->lock(d)
#define ms_display_unlock(d) if ((d)->desc->unlock) (d)->desc->unlock(d)
#define ms_display_update(d, A, B) if ((d)->desc->update) (d)->desc->update(d, A, B)
int ms_display_poll_event(MSDisplay *d, MSDisplayEvent *ev);
extern MSDisplayDesc ms_sdl_display_desc;
#if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(MEDIASTREAMER_STATIC)
#if defined(MEDIASTREAMER2_EXPORTS) && defined(INVIDEOUT_C)
#define MSVAR_DECLSPEC __declspec(dllexport)
#else
#define MSVAR_DECLSPEC __declspec(dllimport)
#endif
#else
#define MSVAR_DECLSPEC extern
#endif
#ifdef __cplusplus
extern "C"{
#endif
/*plugins can set their own display using this method:*/
void ms_display_desc_set_default(MSDisplayDesc *desc);
MSDisplayDesc * ms_display_desc_get_default(void);
void ms_display_desc_set_default_window_id(MSDisplayDesc *desc, long id);
MSVAR_DECLSPEC MSDisplayDesc ms_win_display_desc;
MSDisplay *ms_display_new(MSDisplayDesc *desc);
void ms_display_set_window_id(MSDisplay *d, long window_id);
void ms_display_destroy(MSDisplay *d);
#define MS_VIDEO_OUT_SET_DISPLAY MS_FILTER_METHOD(MS_VIDEO_OUT_ID,0,MSDisplay*)
#define MS_VIDEO_OUT_HANDLE_RESIZING MS_FILTER_METHOD_NO_ARG(MS_VIDEO_OUT_ID,1)
#define MS_VIDEO_OUT_SET_CORNER MS_FILTER_METHOD(MS_VIDEO_OUT_ID,2,int)
#define MS_VIDEO_OUT_AUTO_FIT MS_FILTER_METHOD(MS_VIDEO_OUT_ID,3,int)
#define MS_VIDEO_OUT_ENABLE_MIRRORING MS_FILTER_METHOD(MS_VIDEO_OUT_ID,4,int)
#define MS_VIDEO_OUT_GET_NATIVE_WINDOW_ID MS_FILTER_METHOD(MS_VIDEO_OUT_ID,5,unsigned long)
#define MS_VIDEO_OUT_GET_CORNER MS_FILTER_METHOD(MS_VIDEO_OUT_ID,6,int)
#define MS_VIDEO_OUT_SET_SCALE_FACTOR MS_FILTER_METHOD(MS_VIDEO_OUT_ID,7,float)
#define MS_VIDEO_OUT_GET_SCALE_FACTOR MS_FILTER_METHOD(MS_VIDEO_OUT_ID,8,float)
#define MS_VIDEO_OUT_SET_SELFVIEW_POS MS_FILTER_METHOD(MS_VIDEO_OUT_ID,9,float[3])
#define MS_VIDEO_OUT_GET_SELFVIEW_POS MS_FILTER_METHOD(MS_VIDEO_OUT_ID,10,float[3])
#define MS_VIDEO_OUT_SET_BACKGROUND_COLOR MS_FILTER_METHOD(MS_VIDEO_OUT_ID,11,int[3])
#define MS_VIDEO_OUT_GET_BACKGROUND_COLOR MS_FILTER_METHOD(MS_VIDEO_OUT_ID,12,int[3])
#ifdef __cplusplus
}
#endif
#endif
......@@ -224,6 +224,10 @@ const char *ms_web_cam_get_string_id(MSWebCam *obj);
void ms_static_image_set_default_image(const char *path);
/** method for the "nowebcam" filter */
#define MS_STATIC_IMAGE_SET_IMAGE \
MS_FILTER_METHOD(MS_STATIC_IMAGE_ID,0,const char)
#ifdef __cplusplus
}
#endif
......
......@@ -125,17 +125,25 @@ libmediastreamer_la_SOURCES+= videoenc.c \
pixconv.c \
sizeconv.c \
nowebcam.c nowebcam.h \
videoout.c \
swscale.h ffmpeg-priv.h \
h264dec.c \
jpegwriter.c
endif
if BUILD_SDL
libmediastreamer_la_SOURCES+=videoout.c
endif
if BUILD_X11_XV
libmediastreamer_la_SOURCES+=x11video.c
endif
libmediastreamer_la_SOURCES+= rfc2429.h \
msvideo.c \
rfc3984.c \
mire.c \
extdisplay.c
extdisplay.c \
layouts.c layouts.h
libmediastreamer_la_SOURCES+=videostream.c
......
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006 Simon MORLAT (simon.morlat@linphone.org)
Copyright (C) 2010 Belledonne Communications SARL, Grenoble France.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -271,133 +271,6 @@ static void dd_display_preprocess(MSFilter *f){
}
/* compute the ideal placement of the video within a window of size wsize,
given that the original video has size vsize. Put the result in rect*/
static void center_with_ratio(MSVideoSize wsize, MSVideoSize vsize, MSRect *rect){
int w,h;
w=wsize.width & ~0x3;
h=((w*vsize.height)/vsize.width) & ~0x1;
if (h>wsize.height){
/*the height doesn't fit, so compute the width*/
h=wsize.height & ~0x1;
w=((h*vsize.width)/vsize.height) & ~0x3;
}
rect->x=(wsize.width-w)/2;
rect->y=(wsize.height-h)/2;
rect->w=w;
rect->h=h;
}
#define LOCAL_BORDER_SIZE 2
#define LOCAL_POS_OFFSET 10
static void compute_layout(MSVideoSize wsize, MSVideoSize vsize, MSVideoSize orig_psize, MSRect *mainrect, MSRect *localrect, int localrect_pos, float scalefactor){
MSVideoSize psize;
center_with_ratio(wsize,vsize,mainrect);
if (localrect_pos!=-1){
psize.width=(int)(wsize.width/scalefactor);
psize.height=(int)(wsize.height/scalefactor);
center_with_ratio(psize,orig_psize,localrect);
if ((wsize.height - mainrect->h < mainrect->h/scalefactor && wsize.width - mainrect->w < mainrect->w/scalefactor) || localrect_pos<=3)
{
int x_sv;
int y_sv;
if (localrect_pos%4==1)
{
/* top left corner */
x_sv = LOCAL_POS_OFFSET;
y_sv = LOCAL_POS_OFFSET;
}
else if (localrect_pos%4==2)
{
/* top right corner */
x_sv = (wsize.width-localrect->w-LOCAL_POS_OFFSET);
y_sv = LOCAL_POS_OFFSET;
}
else if (localrect_pos%4==3)
{
/* bottom left corner */
x_sv = LOCAL_POS_OFFSET;
y_sv = (wsize.height-localrect->h-LOCAL_POS_OFFSET);
}
else /* corner = 0: default */
{
/* bottom right corner */
x_sv = (wsize.width-localrect->w-LOCAL_POS_OFFSET);
y_sv = (wsize.height-localrect->h-LOCAL_POS_OFFSET);
}
localrect->x=x_sv; //wsize.width-localrect->w-LOCAL_POS_OFFSET;
localrect->y=y_sv; //wsize.height-localrect->h-LOCAL_POS_OFFSET;
}
else
{
int x_sv;
int y_sv;
if (wsize.width - mainrect->w < mainrect->w/scalefactor)
{
// recalculate so we have a selfview taking as
// much available space as possible
psize.width=wsize.width;
psize.height=wsize.height-mainrect->h;
center_with_ratio(psize,orig_psize,localrect);
if (localrect_pos%4==1 || localrect_pos%4==2)
{
//Self View on Top
x_sv = (wsize.width-localrect->w)/2;
y_sv = LOCAL_POS_OFFSET;
mainrect->y = wsize.height-mainrect->h-LOCAL_POS_OFFSET;
}
else
{
//Self View on Bottom
x_sv = (wsize.width-localrect->w)/2;
y_sv = (wsize.height-localrect->h-LOCAL_POS_OFFSET);
mainrect->y = LOCAL_POS_OFFSET;
}
}
else
{
// recalculate so we have a selfview taking as
// much available space as possible
psize.width=wsize.width-mainrect->w;
psize.height=wsize.height;
center_with_ratio(psize,orig_psize,localrect);
if (localrect_pos%4==1 || localrect_pos%4==3)
{
//Self View on left
x_sv = LOCAL_POS_OFFSET;
y_sv = (wsize.height-localrect->h)/2;
mainrect->x = wsize.width-mainrect->w-LOCAL_POS_OFFSET;
}
else
{
//Self View on right
x_sv = (wsize.width-localrect->w-LOCAL_POS_OFFSET);
y_sv = (wsize.height-localrect->h)/2;
mainrect->x = LOCAL_POS_OFFSET;
}
}
localrect->x=x_sv; //wsize.width-localrect->w-LOCAL_POS_OFFSET;
localrect->y=y_sv; //wsize.height-localrect->h-LOCAL_POS_OFFSET;
}
}
/*
ms_message("Compute layout result for\nwindow size=%ix%i\nvideo orig size=%ix%i\nlocal size=%ix%i\nlocal orig size=%ix%i\n"
"mainrect=%i,%i,%i,%i\tlocalrect=%i,%i,%i,%i",
wsize.width,wsize.height,vsize.width,vsize.height,psize.width,psize.height,orig_psize.width,orig_psize.height,
mainrect->x,mainrect->y,mainrect->w,mainrect->h,
localrect->x,localrect->y,localrect->w,localrect->h);
*/
}
static void draw_local_view_frame(HDC hdc, MSVideoSize wsize, MSRect localrect){
Rectangle(hdc, localrect.x-LOCAL_BORDER_SIZE, localrect.y-LOCAL_BORDER_SIZE,
......@@ -503,7 +376,7 @@ static void dd_display_process(MSFilter *f){
}
if (main_im!=NULL || local_im!=NULL || obj->need_repaint){
compute_layout(wsize,obj->vsize,obj->lsize,&mainrect,&localrect,corner, scalefactor);
ms_layout_compute(wsize,obj->vsize,obj->lsize,corner,scalefactor,&mainrect,&localrect);
vsize.width=mainrect.w;
vsize.height=mainrect.h;
lsize.width=localrect.w;
......
......@@ -36,12 +36,12 @@ static void ext_display_process(MSFilter *f){
/*get most recent message and draw it*/
if ( f->inputs[1]!=NULL && (local_im=ms_queue_peek_last(f->inputs[1]))!=NULL) {
if (yuv_buf_init_from_mblk(&output.local_view,local_im)==0){
if (ms_yuv_buf_init_from_mblk(&output.local_view,local_im)==0){
}
}
if (f->inputs[0]!=NULL && (main_im=ms_queue_peek_last(f->inputs[0]))!=NULL) {
if (yuv_buf_init_from_mblk(&output.remote_view,main_im)==0){
if (ms_yuv_buf_init_from_mblk(&output.remote_view,main_im)==0){
}
}
......
......@@ -103,7 +103,7 @@ static mblk_t *get_as_yuvmsg(MSFilter *f, DecData *s, AVFrame *orig){
s->yuv_msg=NULL;
}
ms_message("Getting yuv picture of %ix%i",ctx->width,ctx->height);
s->yuv_msg=yuv_buf_alloc(&s->outbuf,ctx->width,ctx->height);
s->yuv_msg=ms_yuv_buf_alloc(&s->outbuf,ctx->width,ctx->height);
s->outbuf.w=ctx->width;
s->outbuf.h=ctx->height;
s->sws_ctx=ms_sws_getContext(ctx->width,ctx->height,ctx->pix_fmt,
......
......@@ -75,7 +75,7 @@ static void jpg_process(MSFilter *f){
if (s->file!=NULL && s->codec!=NULL){
MSPicture yuvbuf, yuvjpeg;
mblk_t *m=ms_queue_peek_last(f->inputs[0]);
if (yuv_buf_init_from_mblk(&yuvbuf,m)==0){
if (ms_yuv_buf_init_from_mblk(&yuvbuf,m)==0){
int error;
int comp_buf_sz=msgdsize(m);
uint8_t *comp_buf=(uint8_t*)alloca(comp_buf_sz);
......@@ -105,7 +105,7 @@ static void jpg_process(MSFilter *f){
cleanup(s,avctx);
goto end;
}
jpegm=yuv_buf_alloc (&yuvjpeg,avctx->width, avctx->height);
jpegm=ms_yuv_buf_alloc (&yuvjpeg,avctx->width, avctx->height);
if (ms_sws_scale(sws_ctx,yuvbuf.planes,yuvbuf.strides,0,avctx->height,yuvjpeg.planes,yuvjpeg.strides)<0){
ms_error("ms_sws_scale() failed.");
ms_sws_freeContext(sws_ctx);
......
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2010 Belledonne Communications SARL, Grenoble France.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "layouts.h"
/* compute the ideal placement of the video within a window of size wsize,
given that the original video has size vsize. Put the result in rect*/
static void center_rectangle(MSVideoSize wsize, MSVideoSize vsize, MSRect *rect){
int w,h;
w=wsize.width & ~0x3;
h=((w*vsize.height)/vsize.width) & ~0x1;
if (h>wsize.height){
/*the height doesn't fit, so compute the width*/
h=wsize.height & ~0x1;
w=((h*vsize.width)/vsize.height) & ~0x3;
}
rect->x=(wsize.width-w)/2;
rect->y=(wsize.height-h)/2;
rect->w=w;
rect->h=h;
}
#define LOCAL_BORDER_SIZE 2
#define LOCAL_POS_OFFSET 10
/**
* This function is used to compute placement of video and local preview video within a window.
* It is used by display filters such as MSDrawDibDisplay and MSX11Video.
* @arg wsize the size of the window
* @arg vsize the size of the main video to display
* @arg orig_psize the size of the preview video
* @arg localrect_pos tells which corner is to be used to preview placement
* @arg scalefactor ratio of the window size over the whished preview video size , ex: 4.0
* @arg mainrect is a return value describing the main video placement
* @arg localrect is a return value describing the preview video placement
* @arg localrect_pos
**/
void ms_layout_compute(MSVideoSize wsize, MSVideoSize vsize, MSVideoSize orig_psize, int localrect_pos, float scalefactor, MSRect *mainrect, MSRect *localrect){
MSVideoSize psize;
center_rectangle(wsize,vsize,mainrect);
if (localrect_pos!=-1){
psize.width=(int)(wsize.width/scalefactor);
psize.height=(int)(wsize.height/scalefactor);
center_rectangle(psize,orig_psize,localrect);
if ((wsize.height - mainrect->h < mainrect->h/scalefactor && wsize.width - mainrect->w < mainrect->w/scalefactor) || localrect_pos<=3)
{
int x_sv;
int y_sv;
if (localrect_pos%4==1)
{
/* top left corner */
x_sv = LOCAL_POS_OFFSET;
y_sv = LOCAL_POS_OFFSET;
}
else if (localrect_pos%4==2)
{
/* top right corner */
x_sv = (wsize.width-localrect->w-LOCAL_POS_OFFSET);
y_sv = LOCAL_POS_OFFSET;
}
else if (localrect_pos%4==3)
{
/* bottom left corner */
x_sv = LOCAL_POS_OFFSET;
y_sv = (wsize.height-localrect->h-LOCAL_POS_OFFSET);
}
else /* corner = 0: default */
{
/* bottom right corner */
x_sv = (wsize.width-localrect->w-LOCAL_POS_OFFSET);
y_sv = (wsize.height-localrect->h-LOCAL_POS_OFFSET);
}
localrect->x=x_sv; //wsize.width-localrect->w-LOCAL_POS_OFFSET;
localrect->y=y_sv; //wsize.height-localrect->h-LOCAL_POS_OFFSET;
}
else
{
int x_sv;
int y_sv;
if (wsize.width - mainrect->w < mainrect->w/scalefactor)
{
// recalculate so we have a selfview taking as
// much available space as possible
psize.width=wsize.width;
psize.height=wsize.height-mainrect->h;
center_rectangle(psize,orig_psize,localrect);
if (localrect_pos%4==1 || localrect_pos%4==2)
{
//Self View on Top
x_sv = (wsize.width-localrect->w)/2;
y_sv = LOCAL_POS_OFFSET;
mainrect->y = wsize.height-mainrect->h-LOCAL_POS_OFFSET;
}
else
{
//Self View on Bottom
x_sv = (wsize.width-localrect->w)/2;
y_sv = (wsize.height-localrect->h-LOCAL_POS_OFFSET);
mainrect->y = LOCAL_POS_OFFSET;
}
}
else
{
// recalculate so we have a selfview taking as
// much available space as possible
psize.width=wsize.width-mainrect->w;
psize.height=wsize.height;
center_rectangle(psize,orig_psize,localrect);
if (localrect_pos%4==1 || localrect_pos%4==3)
{
//Self View on left
x_sv = LOCAL_POS_OFFSET;
y_sv = (wsize.height-localrect->h)/2;
mainrect->x = wsize.width-mainrect->w-LOCAL_POS_OFFSET;
}
else
{
//Self View on right
x_sv = (wsize.width-localrect->w-LOCAL_POS_OFFSET);
y_sv = (wsize.height-localrect->h)/2;
mainrect->x = LOCAL_POS_OFFSET;
}
}
localrect->x=x_sv; //wsize.width-localrect->w-LOCAL_POS_OFFSET;
localrect->y=y_sv; //wsize.height-localrect->h-LOCAL_POS_OFFSET;
}
}
/*
ms_message("Compute layout result for\nwindow size=%ix%i\nvideo orig size=%ix%i\nlocal size=%ix%i\nlocal orig size=%ix%i\n"
"mainrect=%i,%i,%i,%i\tlocalrect=%i,%i,%i,%i",
wsize.width,wsize.height,vsize.width,vsize.height,psize.width,psize.height,orig_psize.width,orig_psize.height,
mainrect->x,mainrect->y,mainrect->w,mainrect->h,
localrect->x,localrect->y,localrect->w,localrect->h);
*/
}
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2010 Belledonne Communications SARL, Grenoble France.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef mslayouts_hh
#define mslayouts_hh
#include "mediastreamer2/msvideo.h"
#ifdef __cplusplus
extern "C" {
#endif
void ms_layout_compute(MSVideoSize wsize, MSVideoSize vsize, MSVideoSize orig_psize,
int localrect_pos, float scalefactor, MSRect *mainrect, MSRect *localrect);
#ifdef __cplusplus
}
#endif
#endif
......@@ -54,7 +54,7 @@ void mire_uninit(MSFilter *f){
void mire_preprocess(MSFilter *f){
MireData *d=(MireData*)f->data;
d->pic=yuv_buf_alloc(&d->pict,d->vsize.width,d->vsize.height);
d->pic=ms_yuv_buf_alloc(&d->pict,d->vsize.width,d->vsize.height);
memset(d->pic->b_rptr,0,d->pic->b_wptr-d->pic->b_rptr);
d->starttime=f->ticker->time;
}
......
......@@ -38,7 +38,7 @@ static void yuv_buf_init(YuvBuf *buf, int w, int h, uint8_t *ptr){
buf->strides[3]=0;
}
int yuv_buf_init_from_mblk(YuvBuf *buf, mblk_t *m){
int ms_yuv_buf_init_from_mblk(YuvBuf *buf, mblk_t *m){
int size=m->b_wptr-m->b_rptr;
int w,h;
if (size==(MS_VIDEO_SIZE_QCIF_W*MS_VIDEO_SIZE_QCIF_H*3)/2){
......@@ -133,11 +133,11 @@ int yuv_buf_init_from_mblk(YuvBuf *buf, mblk_t *m){
return 0;
}
void yuv_buf_init_from_mblk_with_size(YuvBuf *buf, mblk_t *m, int w, int h){
void ms_yuv_buf_init_from_mblk_with_size(YuvBuf *buf, mblk_t *m, int w, int h){
yuv_buf_init(buf,w,h,m->b_rptr);
}
mblk_t * yuv_buf_alloc(YuvBuf *buf, int w, int h){
mblk_t * ms_yuv_buf_alloc(YuvBuf *buf, int w, int h){
int size=(w*h*3)/2;
const int padding=16;
mblk_t *msg=allocb(size+padding,0);
......@@ -290,6 +290,12 @@ MSVideoSize ms_video_size_get_just_lower_than(MSVideoSize vs){
return ret;
}
void ms_rgb_to_yuv(const uint8_t rgb[3], uint8_t yuv[3]){
yuv[0]=(uint8_t)(0.257*rgb[0] + 0.504*rgb[1] + 0.098*rgb[2] + 16);
yuv[1]=(uint8_t)(-0.148*rgb[0] - 0.291*rgb[1] + 0.439*rgb[2] + 128);
yuv[2]=(uint8_t)(0.439*rgb[0] - 0.368*rgb[1] - 0.071*rgb[2] + 128);
}
#if !defined(NO_FFMPEG)
struct ms_swscaleDesc ms_swscale_desc = {
......
......@@ -62,7 +62,7 @@ static mblk_t *jpeg2yuv(uint8_t *jpgbuf, int bufsize, MSVideoSize *reqsize){
avcodec_close(&av_context);
return NULL;
}
ret=yuv_buf_alloc(&dest, reqsize->width,reqsize->height);
ret=ms_yuv_buf_alloc(&dest, reqsize->width,reqsize->height);
sws_ctx=ms_sws_getContext(av_context.width,av_context.height,av_context.pix_fmt,
reqsize->width,reqsize->height,PIX_FMT_YUV420P,SWS_FAST_BILINEAR,
......@@ -1577,7 +1577,7 @@ mblk_t *ms_load_generate_yuv(MSVideoSize *reqsize)
}
#endif
m = yuv_buf_alloc(&buf, reqsize->width, reqsize->height);
m = ms_yuv_buf_alloc(&buf, reqsize->width, reqsize->height);
ysize=buf.strides[0]*buf.h;
memset(buf.planes[0],16,ysize);
memset(buf.planes[1],128,ysize/4);
......@@ -1838,7 +1838,7 @@ MSFilterMethod static_image_methods[]={
{ MS_FILTER_SET_VIDEO_SIZE, static_image_set_vsize },
{ MS_FILTER_GET_VIDEO_SIZE, static_image_get_vsize },
{ MS_FILTER_GET_PIX_FMT, static_image_get_pix_fmt },
{ MS_FILTER_SET_IMAGE, static_image_set_image },
{ MS_STATIC_IMAGE_SET_IMAGE, static_image_set_image },
{ 0,0 }
};
......
......@@ -115,7 +115,7 @@ static mblk_t * pixconv_alloc_mblk(PixConvState *s){
s->yuv_msg=NULL;
}