Don't subsequently calculate original_aspect from last movie_aspect.
authorib <ib@b3059339-0415-0410-9bf9-f77b7e298cf2>
Wed, 7 Aug 2013 20:41:34 +0000 (20:41 +0000)
committerib <ib@b3059339-0415-0410-9bf9-f77b7e298cf2>
Wed, 7 Aug 2013 20:41:34 +0000 (20:41 +0000)
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.

git-svn-id: svn://git.mplayerhq.hu/mplayer/trunk@36412 b3059339-0415-0410-9bf9-f77b7e298cf2

18 files changed:
command.c
gui/dialog/menu.c
libmpcodecs/vd.c
libmpcodecs/vd_ffmpeg.c
libmpcodecs/vd_libmpeg2.c
libmpcodecs/vd_mpegpes.c
libmpcodecs/vd_realvid.c
libmpcodecs/vd_theora.c
libmpcodecs/vd_xvid4.c
libmpdemux/asfheader.c
libmpdemux/aviheader.c
libmpdemux/demux_lavf.c
libmpdemux/demux_mkv.c
libmpdemux/demux_mov.c
libmpdemux/demux_nut.c
libmpdemux/demux_real.c
libmpdemux/demux_y4m.c
libmpdemux/demuxer.c

index db069c3..38381ba 100644 (file)
--- a/command.c
+++ b/command.c
@@ -2717,8 +2717,8 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd)
         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);
index 1f17e19..079eb97 100644 (file)
@@ -584,7 +584,7 @@ GtkWidget * CreatePopUpMenu( void )
    {
     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);
index 86bd5f6..e1775d3 100644 (file)
@@ -158,7 +158,6 @@ int mpcodecs_config_vo(sh_video_t *sh, int w, int h,
     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 @@ int mpcodecs_config_vo(sh_video_t *sh, int w, int h,
         vf_add_before_vo(&vf, "flip", NULL);
         sh->vfilter = vf;
     }
-    // time to do aspect ratio corrections (after saving the original aspect ratio)...
+    // time to do aspect ratio corrections...
 
-    if (sh->original_aspect == -1.0) {
-        sh->original_aspect = sh->stream_aspect != 0.0 ? sh->stream_aspect : sh->aspect;
-        last_movie_aspect = -1.0;
-    }
-
-    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;
index dd9e8af..e528c27 100644 (file)
@@ -510,13 +510,13 @@ static void update_configuration(sh_video_t *sh, enum AVPixelFormat pix_fmt) {
         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);
index a138882..7d2dff9 100644 (file)
@@ -196,7 +196,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
        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) {
index f7f575e..c9e3342 100644 (file)
@@ -64,13 +64,13 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
     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;
         }
index b7e166b..e9bd0a0 100644 (file)
@@ -405,7 +405,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
                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;
index 83272ac..51b1f80 100644 (file)
@@ -130,8 +130,8 @@ static int init(sh_video_t *sh)
     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");
index 62eab8c..7848ada 100644 (file)
@@ -278,7 +278,7 @@ static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags)
                /* 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;
 
index 562fbf7..75201a7 100644 (file)
@@ -512,7 +512,7 @@ int read_asf_header(demuxer_t *demuxer,struct asf_priv* asf){
         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;
index 0af0161..daba304 100644 (file)
@@ -364,7 +364,7 @@ while(1){
                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);
index 7abbcfd..2f21cae 100644 (file)
@@ -394,10 +394,10 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) {
             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)
index f88f65e..080891a 100644 (file)
@@ -1618,12 +1618,12 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track,
         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
index 4297fec..272ec84 100644 (file)
@@ -1143,8 +1143,8 @@ static int gen_sh_video(sh_video_t* sh, mov_track_t* trak, int timescale) {
                    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);
                  }
                }
 
index e70ba81..510e9ea 100644 (file)
@@ -166,8 +166,8 @@ static demuxer_t * demux_open_nut(demuxer_t * demuxer) {
                        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
 
index c82451e..b5cbf80 100644 (file)
@@ -1537,7 +1537,7 @@ static demuxer_t* demux_open_real(demuxer_t* demuxer)
                    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;
index 0735afb..b3d9f70 100644 (file)
@@ -232,7 +232,7 @@ static void read_streaminfo(demuxer_t *demuxer)
        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;
     }
index 3800e28..523723e 100644 (file)
@@ -380,7 +380,6 @@ sh_video_t *new_sh_video_vid(demuxer_t *demuxer, int id, int vid)
         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;