Commit 3ba1b0e8 authored by Aymeric Moizard's avatar Aymeric Moizard
Browse files

Merge branch 'master' of git.linphone.org:mediastreamer2

Conflicts:
	src/pixconv.c
parents be1d2f77 cfcfd58c
......@@ -455,7 +455,7 @@ AC_ARG_ENABLE(gsm,
no) gsm=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --disable-gsm) ;;
esac],[gsm=true])
if test x$gsm = xtrue; then
dnl check for gsm
......@@ -558,15 +558,38 @@ fi
AM_CONDITIONAL(BUILD_V4L, test x$found_v4l = xyes )
AC_ARG_ENABLE(libv4l,
[ --disable-libv4l Disable usage of libv4l, really discouraged],
[case "${enableval}" in
yes) libv4l=true ;;
no) libv4l=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --disable-libv4l) ;;
esac],[libv4l=true])b
PKG_CHECK_MODULES(LIBV4L2, libv4l2,
[AC_DEFINE(HAVE_LIBV4L2,1,[Defined if we have libv4l2])]
[AC_DEFINE(HAVE_LIBV4L2,1,[Defined if we have libv4l2])
have_libv4l2=yes]
,[echo "No libv4l2 found."]
)
PKG_CHECK_MODULES(LIBV4L1, libv4l1,
[AC_DEFINE(HAVE_LIBV4L1,1,[Defined if we have libv4l1])]
[AC_DEFINE(HAVE_LIBV4L1,1,[Defined if we have libv4l1])
have_libv4l1=yes]
,[echo "No libv4l1 found."]
)
if test "$found_v4l" = "yes" && test "$have_libv4l2" != "yes" ; then
if test "$libv4l" = "no" ; then
AC_MSG_ERROR(
[
Missing libv4l2. It is highly recommended to build with
libv4l2 headers and library. Many camera will won't work or will crash
your application if libv4l2 is not installed.
If you know what you are doing, you can use --disable-libv4l to disable
this check.
])
fi
fi
dnl ##################################################
dnl # Check for doxygen
dnl ##################################################
......
......@@ -173,7 +173,7 @@ void ms_sleep(int seconds);
* The max payload size allowed.
* Filters that generate data that can be sent through RTP should make packets
* whose size is below ms_get_payload_max_size().
* The default value is 1440 computed as the standart internet MTU minus IPv6 header,
* The default value is 1440 computed as the standard internet MTU minus IPv6 header,
* UDP header and RTP header. As IPV4 header is smaller than IPv6 header, this
* value works for both.
*
......
......@@ -58,6 +58,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MS_VOLUME_SET_NOISE_GATE_FLOORGAIN MS_FILTER_METHOD(MS_VOLUME_ID,12,float)
/* set a gain in db */
#define MS_VOLUME_SET_DB_GAIN MS_FILTER_METHOD(MS_VOLUME_ID,13,float)
extern MSFilterDesc ms_volume_desc;
#endif
......@@ -8,13 +8,13 @@
%endif
Summary: Audio/Video real-time streaming
Name: mediastreamer2
Version: @MEDIASTREAMER2_PKGCONFIG_VERSION@
Name: mediastreamer
Version: @MEDIASTREAMER_VERSION@
Release: 1
License: LGPL
Group: Applications/Communications
URL: http://linphone.org/mediastreamer2/
Source0: %{name}-@MEDIASTREAMER2_PKGCONFIG_VERSION@.tar.gz
Source0: %{name}-@MEDIASTREAMER_VERSION@.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
%ifarch %ix86
BuildArch: i686
......
......@@ -310,6 +310,14 @@ static int alsa_can_read(snd_pcm_t *dev)
return avail;
}
static void alsa_resume(snd_pcm_t *handle){
int err;
ms_warning("Maybe suspended, trying resume");
if ((err=snd_pcm_resume(handle))!=0){
if (err!=EWOULDBLOCK) ms_warning("snd_pcm_resume() failed: %s",snd_strerror(err));
}
}
static int alsa_read(snd_pcm_t *handle,unsigned char *buf,int nsamples)
{
int err;
......@@ -320,6 +328,8 @@ static int alsa_read(snd_pcm_t *handle,unsigned char *buf,int nsamples)
snd_pcm_prepare(handle);
err=snd_pcm_readi(handle,buf,nsamples);
if (err<0) ms_warning("alsa_read: snd_pcm_readi() failed:%s.",snd_strerror(err));
}else if (err==-ESTRPIPE){
alsa_resume(handle);
}else if (err!=-EWOULDBLOCK){
ms_warning("alsa_read: snd_pcm_readi() failed:%s.",snd_strerror(err));
}
......@@ -341,6 +351,8 @@ static int alsa_write(snd_pcm_t *handle,unsigned char *buf,int nsamples)
#endif
err=snd_pcm_writei(handle,buf,nsamples);
if (err<0) ms_warning("alsa_card_write: Error writing sound buffer (nsamples=%i):%s",nsamples,snd_strerror(err));
}else if (err==-ESTRPIPE){
alsa_resume(handle);
}else if (err!=-EWOULDBLOCK){
ms_warning("alsa_card_write: snd_pcm_writei() failed:%s.",snd_strerror(err));
}
......
......@@ -21,16 +21,45 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <gsm/gsm.h>
#ifdef _MSC_VER
#include <malloc.h>
#define alloca _alloca
#endif
typedef struct EncState{
gsm state;
uint32_t ts;
int ptime;
MSBufferizer *bufferizer;
} EncState;
static int enc_add_fmtp(MSFilter *f, void *arg){
const char *fmtp=(const char *)arg;
EncState *s=(EncState*)f->data;
char tmp[30];
if (fmtp_get_value(fmtp,"ptime",tmp,sizeof(tmp))){
int ptime = atoi(tmp);
switch (ptime) {
case 20:
case 40:
case 60:
case 80:
case 100:
s->ptime = atoi(tmp);
break;
default:
ms_warning("MSGsmEnc: unsupported ptime [%i] using default",ptime);
}
ms_message("MSGsmEnc: got ptime=%i using [%i]",ptime,s->ptime);
}
return 0;
}
static void enc_init(MSFilter *f){
EncState *s=(EncState *)ms_new(EncState,1);
s->state=gsm_create();
s->ts=0;
s->ptime=20;
s->bufferizer=ms_bufferizer_new();
f->data=s;
}
......@@ -47,20 +76,32 @@ static void enc_uninit(MSFilter *f){
static void enc_process(MSFilter *f){
EncState *s=(EncState*)f->data;
mblk_t *im;
int16_t buf[160];
unsigned int unitary_buff_size = sizeof(int16_t)*160;
unsigned int buff_size = unitary_buff_size*s->ptime/20;
int16_t* buff;
int offset;
while((im=ms_queue_get(f->inputs[0]))!=NULL){
ms_bufferizer_put(s->bufferizer,im);
}
while(ms_bufferizer_read(s->bufferizer,(uint8_t*)buf,sizeof(buf))==sizeof(buf)) {
mblk_t *om=allocb(33,0);
gsm_encode(s->state,(gsm_signal*)buf,(gsm_byte*)om->b_wptr);
om->b_wptr+=33;
while(ms_bufferizer_get_avail(s->bufferizer) >= buff_size) {
buff = (int16_t *)alloca(buff_size);
ms_bufferizer_read(s->bufferizer,(uint8_t*)buff,buff_size);
mblk_t *om=allocb(33*s->ptime/20,0);
for (offset=0;offset<buff_size;offset+=unitary_buff_size) {
gsm_encode(s->state,(gsm_signal*)&buff[offset/sizeof(int16_t)],(gsm_byte*)om->b_wptr);
om->b_wptr+=33;
}
mblk_set_timestamp_info(om,s->ts);
ms_queue_put(f->outputs[0],om);
s->ts+=sizeof(buf)/2;
s->ts+=buff_size/sizeof(int16_t)/*sizeof(buf)/2*/;
}
}
static MSFilterMethod enc_methods[]={
{ MS_FILTER_ADD_FMTP , enc_add_fmtp},
{ 0 , NULL }
};
#ifdef _MSC_VER
......@@ -77,7 +118,7 @@ MSFilterDesc ms_gsm_enc_desc={
enc_process,
NULL,
enc_uninit,
NULL
enc_methods
};
#else
......@@ -93,6 +134,7 @@ MSFilterDesc ms_gsm_enc_desc={
.init=enc_init,
.process=enc_process,
.uninit=enc_uninit,
.methods = enc_methods
};
#endif
......@@ -114,13 +156,15 @@ static void dec_process(MSFilter *f){
const int frsz=160*2;
while((im=ms_queue_get(f->inputs[0]))!=NULL){
om=allocb(frsz,0);
if (gsm_decode(s,(gsm_byte*)im->b_rptr,(gsm_signal*)om->b_wptr)<0){
ms_warning("gsm_decode error!");
freemsg(om);
}else{
om->b_wptr+=frsz;
ms_queue_put(f->outputs[0],om);
for (;(im->b_wptr-im->b_rptr)>=33;im->b_rptr+=33) {
om=allocb(frsz,0);
if (gsm_decode(s,(gsm_byte*)im->b_rptr,(gsm_signal*)om->b_wptr)<0){
ms_warning("gsm_decode error!");
freemsg(om);
}else{
om->b_wptr+=frsz;
ms_queue_put(f->outputs[0],om);
}
}
freemsg(im);
}
......
......@@ -421,7 +421,8 @@ static int receiver_set_session(MSFilter * f, void *arg)
d->rate=8000;
else d->rate = pt->clock_rate;
} else {
ms_warning("Receiving undefined payload type ?");
ms_warning("Receiving undefined payload type %i ?",
rtp_session_get_recv_payload_type(s));
}
d->session = s;
......
......@@ -106,7 +106,6 @@ static int volume_get(MSFilter *f, void *arg){
float *farg=(float*)arg;
Volume *v=(Volume*)f->data;
*farg=10*ortp_log10f((v->energy+1)/max_e);
return 0;
}
......@@ -199,6 +198,14 @@ static void volume_noise_gate_process(Volume *v , float energy, mblk_t *om){
}
}
static int volume_set_db_gain(MSFilter *f, void *gain){
float *fgain=(float*)gain;
Volume *v=(Volume*)f->data;
v->gain=v->static_gain=v->target_gain = pow(10,(*fgain)/10);
ms_message("MSVolume set gain to [%f db], [%f] linear",*fgain,v->gain);
return 0;
}
static int volume_set_gain(MSFilter *f, void *arg){
float *farg=(float*)arg;
Volume *v=(Volume*)f->data;
......@@ -391,6 +398,7 @@ static MSFilterMethod methods[]={
{ MS_VOLUME_ENABLE_NOISE_GATE, volume_enable_noise_gate},
{ MS_VOLUME_SET_NOISE_GATE_THRESHOLD, volume_set_noise_gate_threshold},
{ MS_VOLUME_SET_NOISE_GATE_FLOORGAIN, volume_set_noise_gate_floorgain},
{ MS_VOLUME_SET_DB_GAIN , volume_set_db_gain },
{ 0 , NULL }
};
......
......@@ -17,6 +17,10 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef WIN32
#define UNICODE
#endif
#ifdef HAVE_CONFIG_H
#include "mediastreamer-config.h"
#endif
......@@ -1586,24 +1590,70 @@ mblk_t *ms_load_generate_yuv(MSVideoSize *reqsize)
}
mblk_t *ms_load_jpeg_as_yuv(const char *jpgpath, MSVideoSize *reqsize){
#if defined(_MSC_VER)
mblk_t *m=NULL;
DWORD st_sizel;
DWORD st_sizeh;
uint8_t *jpgbuf;
DWORD err;
HANDLE fd;
WCHAR wUnicode[1024];
BOOL res;
MultiByteToWideChar(CP_UTF8, 0, jpgpath, -1, wUnicode, 1024);
fd = CreateFile(wUnicode, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL);
if (fd==INVALID_HANDLE_VALUE){
ms_error("Failed to open %s",jpgpath);
m=ms_load_generate_yuv(reqsize);
return m;
}
st_sizel=0;
st_sizeh=0;
st_sizel = GetFileSize(fd, &st_sizeh);
if (st_sizeh>0 || st_sizel<=0)
{
CloseHandle(fd);
ms_error("Can't load file %s",jpgpath);
m=ms_load_generate_yuv(reqsize);
return m;
}
jpgbuf=(uint8_t*)ms_malloc0(st_sizel);
if (jpgbuf==NULL)
{
CloseHandle(fd);
ms_error("Cannot allocate buffer for %s",jpgpath);
m=ms_load_generate_yuv(reqsize);
return m;
}
err=0;
res = ReadFile(fd, jpgbuf, st_sizel, &err, NULL) ;
if (err!=st_sizel){
ms_error("Could not read as much as wanted !");
}
m=jpeg2yuv(jpgbuf,st_sizel,reqsize);
ms_free(jpgbuf);
if (m==NULL)
{
CloseHandle(fd);
ms_error("Cannot load image from buffer for %s",jpgpath);
m=ms_load_generate_yuv(reqsize);
return m;
}
CloseHandle(fd);
return m;
#else
mblk_t *m=NULL;
struct stat statbuf;
uint8_t *jpgbuf;
int err;
#if !defined(_MSC_VER)
int fd=open(jpgpath,O_RDONLY);
#else
int fd=_open(jpgpath,O_RDONLY);
#endif
if (fd!=-1){
fstat(fd,&statbuf);
if (statbuf.st_size<=0)
{
#if !defined(_MSC_VER)
close(fd);
#else
_close(fd);
#endif
ms_error("Cannot load %s",jpgpath);
m=ms_load_generate_yuv(reqsize);
return m;
......@@ -1611,20 +1661,12 @@ mblk_t *ms_load_jpeg_as_yuv(const char *jpgpath, MSVideoSize *reqsize){
jpgbuf=(uint8_t*)ms_malloc0(statbuf.st_size);
if (jpgbuf==NULL)
{
#if !defined(_MSC_VER)
close(fd);
#else
_close(fd);
#endif
ms_error("Cannot allocate buffer for %s",jpgpath);
m=ms_load_generate_yuv(reqsize);
return m;
}
#if !defined(_MSC_VER)
err=read(fd,jpgbuf,statbuf.st_size);
#else
err=_read(fd,jpgbuf,statbuf.st_size);
#endif
if (err!=statbuf.st_size){
ms_error("Could not read as much as wanted !");
}
......@@ -1632,11 +1674,7 @@ mblk_t *ms_load_jpeg_as_yuv(const char *jpgpath, MSVideoSize *reqsize){
ms_free(jpgbuf);
if (m==NULL)
{
#if !defined(_MSC_VER)
close(fd);
#else
_close(fd);
#endif
ms_error("Cannot load image from buffer for %s",jpgpath);
m=ms_load_generate_yuv(reqsize);
return m;
......@@ -1646,12 +1684,9 @@ mblk_t *ms_load_jpeg_as_yuv(const char *jpgpath, MSVideoSize *reqsize){
ms_error("Cannot load %s",jpgpath);
return m;
}
#if !defined(_MSC_VER)
close(fd);
#else
_close(fd);
#endif
return m;
#endif
}
......
......@@ -127,6 +127,77 @@ HRESULT GetPinCategory(IPin *pPin, GUID *pPinCategory)
return hr;
}
int dump_format(IBaseFilter *m_pDeviceFilter)
{
HRESULT hr=S_OK;
IEnumPins *pEnum=0;
ULONG ulFound;
IPin *pPin;
GUID pPinCategory;
// Verify input
if (!m_pDeviceFilter)
return -1;
// Get pin enumerator
hr = m_pDeviceFilter->EnumPins(&pEnum);
if(FAILED(hr))
return -1;
pEnum->Reset();
// Count every pin on the filter
while(S_OK == pEnum->Next(1, &pPin, &ulFound))
{
PIN_DIRECTION pindir = (PIN_DIRECTION) 3;
hr = pPin->QueryDirection(&pindir);
if(pindir != PINDIR_INPUT)
{
IEnumMediaTypes *ppEnum;
ULONG ulFound2;
GetPinCategory(pPin, &pPinCategory);
if (pPinCategory!=PIN_CATEGORY_CAPTURE
&& pPinCategory!=PIN_CATEGORY_PREVIEW)
continue;
hr = pPin->EnumMediaTypes(&ppEnum);
if(FAILED(hr))
continue;
AM_MEDIA_TYPE *ppMediaTypes;
while(S_OK == ppEnum->Next(1, &ppMediaTypes, &ulFound2))
{
if (ppMediaTypes->formattype != FORMAT_VideoInfo)
continue;
if (ppMediaTypes->majortype != MEDIATYPE_Video)
continue;
VIDEOINFO *pvi = (VIDEOINFO *)ppMediaTypes->pbFormat;
if (pvi->bmiHeader.biCompression==0)
ms_message("camera video format 'RGB' %ix%i/%i planes=%i",
pvi->bmiHeader.biWidth,
pvi->bmiHeader.biHeight,
pvi->bmiHeader.biBitCount,
pvi->bmiHeader.biPlanes);
else
ms_message("camera video format '%.4s' %ix%i/%i planes=%i",
&pvi->bmiHeader.biCompression,
pvi->bmiHeader.biWidth,
pvi->bmiHeader.biHeight,
pvi->bmiHeader.biBitCount,
pvi->bmiHeader.biPlanes);
}
}
pPin->Release();
}
pEnum->Release();
return -1;
}
int try_format(IBaseFilter *m_pDeviceFilter, int format, GUID *pPinCategory)
{
HRESULT hr=S_OK;
......@@ -489,7 +560,7 @@ static int v4w_configure_videodevice(V4wState *s)
if (s->pix_fmt == MS_YUV420P)
ms_message("Driver supports YUV420P, using that format.");
else if (s->pix_fmt == MS_YUY2)
ms_message("Driver supports YUY2 (UYVY), using that format.");
ms_message("Driver supports YUY2 (YUYV), using that format.");
else if (s->pix_fmt == MS_YUYV)
ms_message("Driver supports YUV422, using that format.");
else if (s->pix_fmt == MS_UYVY)
......@@ -684,7 +755,7 @@ static int v4w_open_videodevice(V4wState *s)
if (s->pix_fmt == MS_YUV420P)
ms_message("Driver supports YUV420P, using that format.");
else if (s->pix_fmt == MS_YUY2)
ms_message("Driver supports YUY2 (UYVY), using that format.");
ms_message("Driver supports YUY2 (YUYV), using that format.");
else if (s->pix_fmt == MS_YUYV)
ms_message("Driver supports YUV422, using that format.");
else if (s->pix_fmt == MS_UYVY)
......@@ -1422,6 +1493,8 @@ static void vfw_detect(MSWebCamManager *obj){
GUID pPinCategory;
int fmt_supported = 0;
dump_format(m_pDeviceFilter);
//basic testing for the device.
if (try_format(m_pDeviceFilter,MS_YUV420P, &pPinCategory)==0)
fmt_supported = 1;
......
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