# HG changeset patch # User ib # Date 1375908094 0 # Node ID 139f2b064ef9f737ca9fb89d013a8c64ae4b57d4 # Parent e4ab2ab9eede521e131cbf9f516e10f015f53fd6 Don't subsequently calculate original_aspect from last movie_aspect. Instead, differentiate between the original aspect ratio stored in or determined from the video file and the forced, i.e. current, aspect ratio (e.g. forced by command line override). This enables multiple independent instances of vd.c again which has been broken by introducing a static variable in r36401. Without the subsequent calculation of original_aspect it now contains nothing but the pure video file aspect ratio which makes it possible to use movie_aspect -1 to set the original aspect ratio which explains the changes in command.c and gui/dialog/menu.c. The changes in vd_mpegpes due to the impact of original_aspect will fix a bug there at the same time where the condition in order to call mpcodecs_config_vo() should only trigger once when the encoded aspect changes. So far, the forced, i.e. current, aspect has been checked. The whole is related to enabling special argument -1 to switch_ratio started in r36391. diff -r e4ab2ab9eede -r 139f2b064ef9 command.c --- a/command.c Wed Aug 07 18:21:06 2013 +0000 +++ b/command.c Wed Aug 07 20:41:34 2013 +0000 @@ -2717,8 +2717,8 @@ case MP_CMD_SWITCH_RATIO: if (!sh_video) break; - if (cmd->nargs == 0 || cmd->args[0].v.f == -1) - movie_aspect = sh_video->original_aspect; + if (cmd->nargs == 0) + movie_aspect = -1.0; else movie_aspect = cmd->args[0].v.f; mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0); diff -r e4ab2ab9eede -r 139f2b064ef9 gui/dialog/menu.c --- a/gui/dialog/menu.c Wed Aug 07 18:21:06 2013 +0000 +++ b/gui/dialog/menu.c Wed Aug 07 20:41:34 2013 +0000 @@ -584,7 +584,7 @@ { int a11 = False, a169 = False, a43 = False, a235 = False; - if (!guiInfo.sh_video || (FFABS(guiInfo.sh_video->aspect - guiInfo.sh_video->original_aspect) <= 0.01f)) a11 = True; + if (movie_aspect == -1.0f) a11 = True; else { a169 = (FFABS(movie_aspect - 16.0f / 9.0f) <= 0.01f); diff -r e4ab2ab9eede -r 139f2b064ef9 libmpcodecs/vd.c --- a/libmpcodecs/vd.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpcodecs/vd.c Wed Aug 07 20:41:34 2013 +0000 @@ -158,7 +158,6 @@ vf_instance_t *vf = sh->vfilter, *sc = NULL; int palette = 0; int vocfg_flags = 0; - static float last_movie_aspect; if (w) sh->disp_w = w; @@ -291,25 +290,14 @@ vf_add_before_vo(&vf, "flip", NULL); sh->vfilter = vf; } - // time to do aspect ratio corrections (after saving the original aspect ratio)... - - if (sh->original_aspect == -1.0) { - sh->original_aspect = sh->stream_aspect != 0.0 ? sh->stream_aspect : sh->aspect; - last_movie_aspect = -1.0; - } + // time to do aspect ratio corrections... - if (movie_aspect > -1.0) { - if (sh->aspect != movie_aspect && movie_aspect == last_movie_aspect) - sh->original_aspect = sh->stream_aspect != 0.0 ? sh->stream_aspect : sh->aspect; + if (movie_aspect > -1.0) sh->aspect = movie_aspect; // cmdline overrides autodetect - } else if (sh->stream_aspect != 0.0) - sh->original_aspect = sh->aspect = sh->stream_aspect; + sh->aspect = sh->stream_aspect; else - sh->original_aspect = sh->aspect; -// if(!sh->aspect) sh->aspect=1.0; - - last_movie_aspect = movie_aspect; + sh->aspect = sh->original_aspect; if (opt_screen_size_x || opt_screen_size_y) { screen_size_x = opt_screen_size_x; diff -r e4ab2ab9eede -r 139f2b064ef9 libmpcodecs/vd_ffmpeg.c --- a/libmpcodecs/vd_ffmpeg.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpcodecs/vd_ffmpeg.c Wed Aug 07 20:41:34 2013 +0000 @@ -510,13 +510,13 @@ set_format_params(avctx, pix_fmt); mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] aspect_ratio: %f\n", aspect); - // Do not overwrite s->aspect on the first call, so that a container - // aspect if available is preferred. + // Do not overwrite sh->original_aspect on the first call, + // if a container aspect is available (which is preferred then). // But set it even if the sample aspect did not change, since a // resolution change can cause an aspect change even if the // _sample_ aspect is unchanged. - if (sh->aspect == 0 || ctx->last_sample_aspect_ratio.den) - sh->aspect = aspect; + if (sh->original_aspect == 0 || ctx->last_sample_aspect_ratio.den) + sh->original_aspect = aspect; ctx->last_sample_aspect_ratio = avctx->sample_aspect_ratio; ctx->pix_fmt = pix_fmt; ctx->best_csp = pixfmt2imgfmt(pix_fmt); diff -r e4ab2ab9eede -r 139f2b064ef9 libmpcodecs/vd_libmpeg2.c --- a/libmpcodecs/vd_libmpeg2.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpcodecs/vd_libmpeg2.c Wed Aug 07 20:41:34 2013 +0000 @@ -196,7 +196,7 @@ case STATE_SEQUENCE: pw = info->sequence->display_width * info->sequence->pixel_width; ph = info->sequence->display_height * info->sequence->pixel_height; - if(ph) sh->aspect = (float) pw / (float) ph; + if(ph) sh->original_aspect = (float) pw / (float) ph; // video parameters initialized/changed, (re)init libvo: if (info->sequence->width >> 1 == info->sequence->chroma_width && info->sequence->height >> 1 == info->sequence->chroma_height) { diff -r e4ab2ab9eede -r 139f2b064ef9 libmpcodecs/vd_mpegpes.c --- a/libmpcodecs/vd_mpegpes.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpcodecs/vd_mpegpes.c Wed Aug 07 20:41:34 2013 +0000 @@ -64,13 +64,13 @@ if (len <= 0 && !data) return NULL; // delay flush if(len>10 && !d[0] && !d[1] && d[2]==1 && d[3]==0xB3) { - float old_aspect = sh->aspect; + float old_aspect = sh->original_aspect; int oldw = sh->disp_w, oldh = sh->disp_h; mp_header_process_sequence_header(&picture, &d[4]); - sh->aspect = mpeg12_aspect_info(&picture); + sh->original_aspect = mpeg12_aspect_info(&picture); sh->disp_w = picture.display_picture_width; sh->disp_h = picture.display_picture_height; - if(sh->aspect != old_aspect || sh->disp_w != oldw || sh->disp_h != oldh) { + if(sh->original_aspect != old_aspect || sh->disp_w != oldw || sh->disp_h != oldh) { if(!mpcodecs_config_vo(sh, sh->disp_w,sh->disp_h,IMGFMT_MPEGPES)) return 0; } diff -r e4ab2ab9eede -r 139f2b064ef9 libmpcodecs/vd_realvid.c --- a/libmpcodecs/vd_realvid.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpcodecs/vd_realvid.c Wed Aug 07 20:41:34 2013 +0000 @@ -405,7 +405,7 @@ transform_out, sh->context); if(!initialized){ // rv30 width/height now known - sh->aspect=(float)sh->disp_w/(float)sh->disp_h; + sh->original_aspect=(float)sh->disp_w/(float)sh->disp_h; sh->disp_w=transform_out[3]; sh->disp_h=transform_out[4]; if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_I420)) return 0; diff -r e4ab2ab9eede -r 139f2b064ef9 libmpcodecs/vd_theora.c --- a/libmpcodecs/vd_theora.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpcodecs/vd_theora.c Wed Aug 07 20:41:34 2013 +0000 @@ -130,8 +130,8 @@ th_setup_free(context->tsi); if (sh->aspect == 0.0 && context->ti.aspect_denominator != 0) { - sh->aspect = ((double)context->ti.aspect_numerator * context->ti.frame_width) / - ((double)context->ti.aspect_denominator * context->ti.frame_height); + sh->original_aspect = ((double)context->ti.aspect_numerator * context->ti.frame_width) / + ((double)context->ti.aspect_denominator * context->ti.frame_height); } mp_msg(MSGT_DECVIDEO, MSGL_V, "INFO: Theora video init ok!\n"); diff -r e4ab2ab9eede -r 139f2b064ef9 libmpcodecs/vd_xvid4.c --- a/libmpcodecs/vd_xvid4.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpcodecs/vd_xvid4.c Wed Aug 07 20:41:34 2013 +0000 @@ -278,7 +278,7 @@ /* Found a VOL information stats, if VO plugin is not initialized * yet then do it now */ if (stats.type == XVID_TYPE_VOL && !p->vo_initialized) { - sh->aspect = stats2aspect(&stats); + sh->original_aspect = stats2aspect(&stats); if(!mpcodecs_config_vo(sh, stats.data.vol.width, stats.data.vol.height, IMGFMT_YV12)) return NULL; diff -r e4ab2ab9eede -r 139f2b064ef9 libmpdemux/asfheader.c --- a/libmpdemux/asfheader.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpdemux/asfheader.c Wed Aug 07 20:41:34 2013 +0000 @@ -512,7 +512,7 @@ if (!get_ext_stream_properties(hdr, hdr_len, streamh->stream_no, asf, 1)) goto len_err_out; if (get_meta(hdr, hdr_len, streamh->stream_no, &asp_ratio)) { - sh_video->aspect = asp_ratio * sh_video->bih->biWidth / + sh_video->original_aspect = asp_ratio * sh_video->bih->biWidth / sh_video->bih->biHeight; } sh_video->i_bps = asf->bps; diff -r e4ab2ab9eede -r 139f2b064ef9 libmpdemux/aviheader.c --- a/libmpdemux/aviheader.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpdemux/aviheader.c Wed Aug 07 20:41:34 2013 +0000 @@ -364,7 +364,7 @@ le2me_VIDEO_FIELD_DESC(&vprp->FieldInfo[i]); } if (sh_video) { - sh_video->aspect = GET_AVI_ASPECT(vprp->dwFrameAspectRatio); + sh_video->original_aspect = GET_AVI_ASPECT(vprp->dwFrameAspectRatio); } if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_vprp(vprp,MSGL_V); free(vprp); diff -r e4ab2ab9eede -r 139f2b064ef9 libmpdemux/demux_lavf.c --- a/libmpdemux/demux_lavf.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpdemux/demux_lavf.c Wed Aug 07 20:41:34 2013 +0000 @@ -394,10 +394,10 @@ sh_video->frametime=1/av_q2d(st->r_frame_rate); sh_video->format=bih->biCompression; if(st->sample_aspect_ratio.num) - sh_video->aspect = codec->width * st->sample_aspect_ratio.num + sh_video->original_aspect = codec->width * st->sample_aspect_ratio.num / (float)(codec->height * st->sample_aspect_ratio.den); else - sh_video->aspect=codec->width * codec->sample_aspect_ratio.num + sh_video->original_aspect = codec->width * codec->sample_aspect_ratio.num / (float)(codec->height * codec->sample_aspect_ratio.den); sh_video->i_bps=codec->bit_rate/8; if (title && title->value) diff -r e4ab2ab9eede -r 139f2b064ef9 libmpdemux/demux_mkv.c --- a/libmpdemux/demux_mkv.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpdemux/demux_mkv.c Wed Aug 07 20:41:34 2013 +0000 @@ -1618,12 +1618,12 @@ track->v_frate = 25.0; sh_v->fps = track->v_frate; sh_v->frametime = 1 / track->v_frate; - sh_v->aspect = 0; + sh_v->original_aspect = 0; if (!track->realmedia) { sh_v->disp_w = track->v_width; sh_v->disp_h = track->v_height; if (track->v_dheight) - sh_v->aspect = (float) track->v_dwidth / (float) track->v_dheight; + sh_v->original_aspect = (float) track->v_dwidth / (float) track->v_dheight; } else { // vd_realvid.c will set aspect to disp_w/disp_h and rederive // disp_w and disp_h from the RealVideo stream contents returned diff -r e4ab2ab9eede -r 139f2b064ef9 libmpdemux/demux_mov.c --- a/libmpdemux/demux_mov.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpdemux/demux_mov.c Wed Aug 07 20:41:34 2013 +0000 @@ -1143,8 +1143,8 @@ sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8); } else if(sh->disp_w!=(trak->tkdata[77]|(trak->tkdata[76]<<8))){ // codec and display width differ... use display one for aspect - sh->aspect=trak->tkdata[77]|(trak->tkdata[76]<<8); - sh->aspect/=trak->tkdata[81]|(trak->tkdata[80]<<8); + sh->original_aspect=trak->tkdata[77]|(trak->tkdata[76]<<8); + sh->original_aspect/=trak->tkdata[81]|(trak->tkdata[80]<<8); } } diff -r e4ab2ab9eede -r 139f2b064ef9 libmpdemux/demux_nut.c --- a/libmpdemux/demux_nut.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpdemux/demux_nut.c Wed Aug 07 20:41:34 2013 +0000 @@ -166,8 +166,8 @@ sh_video->format = 0; for (j = 0; j < s[i].fourcc_len && j < 4; j++) sh_video->format |= s[i].fourcc[j]<<(j*8); - if (!s[i].sample_height) sh_video->aspect = 0; - else sh_video->aspect = + if (!s[i].sample_height) sh_video->original_aspect = 0; + else sh_video->original_aspect = s[i].sample_width / (float)s[i].sample_height; sh_video->i_bps = 0; // FIXME diff -r e4ab2ab9eede -r 139f2b064ef9 libmpdemux/demux_real.c --- a/libmpdemux/demux_real.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpdemux/demux_real.c Wed Aug 07 20:41:34 2013 +0000 @@ -1537,7 +1537,7 @@ sh->disp_w = sh->bih->biWidth = stream_read_word(demuxer->stream); sh->disp_h = sh->bih->biHeight = stream_read_word(demuxer->stream); if (sh->disp_w > 0 && sh->disp_h > 0) - sh->aspect = (float)sh->disp_w / sh->disp_h; + sh->original_aspect = (float)sh->disp_w / sh->disp_h; sh->bih->biPlanes = 1; sh->bih->biBitCount = 24; sh->bih->biCompression = sh->format; diff -r e4ab2ab9eede -r 139f2b064ef9 libmpdemux/demux_y4m.c --- a/libmpdemux/demux_y4m.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpdemux/demux_y4m.c Wed Aug 07 20:41:34 2013 +0000 @@ -232,7 +232,7 @@ sh->disp_h = y4m_si_get_height(priv->si); if (ratio.d != 0 && ratio.n != 0) - sh->aspect = (float)(sh->disp_w*ratio.n)/(float)(sh->disp_h*ratio.d); + sh->original_aspect = (float)(sh->disp_w*ratio.n)/(float)(sh->disp_h*ratio.d); demuxer->seekable = 0; } diff -r e4ab2ab9eede -r 139f2b064ef9 libmpdemux/demuxer.c --- a/libmpdemux/demuxer.c Wed Aug 07 18:21:06 2013 +0000 +++ b/libmpdemux/demuxer.c Wed Aug 07 20:41:34 2013 +0000 @@ -380,7 +380,6 @@ mp_msg(MSGT_DEMUXER, MSGL_WARN, MSGTR_VideoStreamRedefined, id); else { sh_video_t *sh = calloc(1, sizeof(sh_video_t)); - sh->original_aspect = -1.0; mp_msg(MSGT_DEMUXER, MSGL_V, "==> Found video stream: %d\n", id); demuxer->v_streams[id] = sh; sh->vid = vid;