Commit 4e131a18 authored by Simon Morlat's avatar Simon Morlat

* fix aspect ratio problems when camera doesn't deliver exactly the size requested

* fix video format choice for video4linux filter. It was preventing to have fps>=10 with HD formats.
parent 33b42ad4
......@@ -687,6 +687,7 @@ static MSFmtDescriptor * ms_fmt_descriptor_new_copy(const MSFmtDescriptor *orig)
const char *ms_fmt_descriptor_to_string(const MSFmtDescriptor *obj){
MSFmtDescriptor *mutable_fmt=(MSFmtDescriptor*)obj;
if (!obj) return "null";
if (obj->text==NULL){
if (obj->type==MSAudio){
mutable_fmt->text=ms_strdup_printf("type=audio;encoding=%s;rate=%i;channels=%i;fmtp='%s'",
......
......@@ -234,21 +234,20 @@ static MSPixFmt pick_best_format(int fd, const V4L2FormatDescription* format_des
for (i=PREFER_NATIVE; i<=NO_PREFERENCE; i++) {
for (j=0; j<4; j++) {
int candidate = -1;
if (format_desc[j].max_fps >= 15 || format_desc[j].max_fps==-1) {
switch (i) {
case PREFER_NATIVE:
if (format_desc[j].native && !format_desc[j].compressed)
candidate = j;
break;
case PREFER_COMPRESSED:
if (format_desc[j].compressed)
candidate = j;
break;
case NO_PREFERENCE:
default:
switch (i) {
case PREFER_NATIVE:
if (format_desc[j].max_fps >= 15 && format_desc[j].native && !format_desc[j].compressed)
candidate = j;
break;
}
break;
case PREFER_COMPRESSED:
/*usually compressed format allow the biggest picture size*/
if (format_desc[j].compressed)
candidate = j;
break;
case NO_PREFERENCE:
default:
candidate = j;
break;
}
if (candidate != -1) {
......
......@@ -140,7 +140,7 @@ static void enc_preprocess(MSFilter *f) {
EncState *s = (EncState *)f->data;
vpx_codec_err_t res;
vpx_codec_caps_t caps;
int cpuused;
int cpuused=0;
/* Populate encoder configuration */
s->flags = 0;
......@@ -176,9 +176,10 @@ static void enc_preprocess(MSFilter *f) {
s->cfg.g_error_resilient = VPX_ERROR_RESILIENT_DEFAULT|VPX_ERROR_RESILIENT_PARTITIONS;
s->cfg.g_lag_in_frames = 0;
#if defined(ANDROID) || TARGET_OS_IPHONE==1
cpuused = 10 - s->cfg.g_threads; /*cpu/quality tradeoff: positive values decrease CPU usage at the expense of quality*/
if (cpuused < 7) cpuused = 7; /*values beneath 7 consume too much CPU*/
#if (TARGET_OS_IPHONE == 1)
if( s->cfg.g_threads == 1 ){
/* on mono-core iOS devices, we reduce the quality a bit more due to VP8 being slower with new Clang compilers */
cpuused = 16;
......
......@@ -359,16 +359,20 @@ static void configure_av_player(AudioStream *stream, const MSFmtDescriptor *audi
int stream_rate=0;
int stream_channels=0;
if (player->decoder){
if (audiofmt->nchannels>0){
ms_filter_call_method(player->decoder,MS_FILTER_SET_NCHANNELS,(void*)&audiofmt->nchannels);
}
if (audiofmt->rate>0){
ms_filter_call_method(player->decoder,MS_FILTER_SET_SAMPLE_RATE,(void*)&audiofmt->rate);
ms_message("AudioStream [%p] Configure av_player, audiofmt=%s videofmt=%s",stream,ms_fmt_descriptor_to_string(audiofmt),ms_fmt_descriptor_to_string(videofmt));
if (audiofmt){
if (player->decoder){
if (audiofmt->nchannels>0){
ms_filter_call_method(player->decoder,MS_FILTER_SET_NCHANNELS,(void*)&audiofmt->nchannels);
}
if (audiofmt->rate>0){
ms_filter_call_method(player->decoder,MS_FILTER_SET_SAMPLE_RATE,(void*)&audiofmt->rate);
}
}
ms_filter_call_method(player->resampler,MS_FILTER_SET_NCHANNELS,(void*)&audiofmt->nchannels);
ms_filter_call_method(player->resampler,MS_FILTER_SET_SAMPLE_RATE,(void*)&audiofmt->rate);
}
ms_filter_call_method(player->resampler,MS_FILTER_SET_NCHANNELS,(void*)&audiofmt->nchannels);
ms_filter_call_method(player->resampler,MS_FILTER_SET_SAMPLE_RATE,(void*)&audiofmt->rate);
ms_filter_call_method(stream->outbound_mixer,MS_FILTER_GET_SAMPLE_RATE,&stream_rate);
ms_filter_call_method(stream->outbound_mixer,MS_FILTER_GET_NCHANNELS,&stream_channels);
......@@ -425,7 +429,7 @@ static int open_av_player(AudioStream *stream, const char *filename){
ms_filter_call_method(player->player,MS_FILTER_GET_OUTPUT_FMT,&fmt1);
fmt2.pin=1;
ms_filter_call_method(player->player,MS_FILTER_GET_OUTPUT_FMT,&fmt2);
if (fmt1.fmt==NULL){
if (fmt1.fmt==NULL && fmt2.fmt==NULL){
/*assume PCM*/
int sr=8000;
int channels=1;
......@@ -434,7 +438,7 @@ static int open_av_player(AudioStream *stream, const char *filename){
fmt1.fmt=ms_factory_get_audio_format(ms_factory_get_fallback(),"pcm", sr, channels, NULL);
audiofmt=&fmt1;
}else{
if (fmt1.fmt->type==MSAudio) {
if (fmt1.fmt && fmt1.fmt->type==MSAudio) {
audiofmt=&fmt1;
videofmt=&fmt2;
player->audiopin=0;
......@@ -446,7 +450,7 @@ static int open_av_player(AudioStream *stream, const char *filename){
player->videopin=0;
}
}
if (strcasecmp(audiofmt->fmt->encoding,"pcm")!=0){
if (audiofmt && audiofmt->fmt && strcasecmp(audiofmt->fmt->encoding,"pcm")!=0){
player->decoder=ms_filter_create_decoder(audiofmt->fmt->encoding);
if (player->decoder==NULL){
ms_warning("AudioStream[%p]: no way to decode [%s]",stream,filename);
......@@ -455,9 +459,9 @@ static int open_av_player(AudioStream *stream, const char *filename){
}
}
player->resampler=ms_filter_new(MS_RESAMPLE_ID);
if (videofmt) player->video_output=ms_filter_new(MS_ITC_SINK_ID);
if (videofmt && videofmt->fmt) player->video_output=ms_filter_new(MS_ITC_SINK_ID);
else player->videopin=-1;
configure_av_player(stream,audiofmt->fmt,videofmt ? videofmt->fmt : NULL);
configure_av_player(stream,audiofmt ? audiofmt->fmt : NULL ,videofmt ? videofmt->fmt : NULL);
plumb_av_player(stream);
return 0;
}
......
......@@ -398,11 +398,10 @@ static void configure_video_source(VideoStream *stream){
ms_filter_call_method(stream->source,MS_FILTER_SET_VIDEO_SIZE,&preview_vsize);
/*the camera may not support the target size and suggest a one close to the target */
ms_filter_call_method(stream->source,MS_FILTER_GET_VIDEO_SIZE,&cam_vsize);
if (cam_vsize.width*cam_vsize.height<=vsize.width*vsize.height &&
cam_vsize.width != vsize.width){
if (cam_vsize.width*cam_vsize.height<=vsize.width*vsize.height){
vsize=cam_vsize;
ms_message("Output video size adjusted to match camera resolution (%ix%i)\n",vsize.width,vsize.height);
} else if (cam_vsize.width*cam_vsize.height>vsize.width*vsize.height){
} else {
#if TARGET_IPHONE_SIMULATOR || defined(__arm__)
ms_error("Camera is proposing a size bigger than encoder's suggested size (%ix%i > %ix%i) "
"Using the camera size as fallback because cropping or resizing is not implemented for arm.",
......
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