diff U3wB C:/shared/gstdirectdrawsink.c C:/wl/AVIK/ossbuild/Main/GStreamer/Source/gst-plugins-bad/sys/directdraw/gstdirectdrawsink.c
--- C:/shared/gstdirectdrawsink.c	Thu Feb 10 16:36:39 2011
+++ C:/wl/AVIK/ossbuild/Main/GStreamer/Source/gst-plugins-bad/sys/directdraw/gstdirectdrawsink.c	Thu Feb 10 17:02:02 2011
@@ -539,6 +539,10 @@
   GstStructure *structure = NULL;
   gboolean ret;
   const GValue *fps;
+  gint video_width, video_height;
+  gint video_par_n, video_par_d;            /* video's PAR */
+  gint display_par_n=1, display_par_d=1;    /* display's PAR */
+  guint num, den;
 
   structure = gst_caps_get_structure (caps, 0);
   if (!structure)
@@ -555,9 +559,57 @@
     GST_ELEMENT_ERROR (ddrawsink, CORE, NEGOTIATION,
         ("Failed to get caps properties from caps"), (NULL));
     return FALSE;
+
   }
-  GST_VIDEO_SINK_WIDTH (ddrawsink) = ddrawsink->video_width;
-  GST_VIDEO_SINK_HEIGHT (ddrawsink) = ddrawsink->video_height;
+  if (!gst_video_format_parse_caps (caps, &ddrawsink->format, &video_width, &video_height))
+    goto invalid_format;
+
+  if (!gst_video_parse_caps_pixel_aspect_ratio (caps, &video_par_n, &video_par_d)){ 
+    video_par_n = 1;
+    video_par_d = 1;
+  }  
+
+  if (!gst_video_calculate_display_ratio (&num, &den, video_width,
+          video_height, video_par_n, video_par_d, display_par_n, display_par_d))
+    goto no_disp_ratio;
+  
+  GST_DEBUG_OBJECT (ddrawsink,
+      "video width/height: %dx%d, calculated display ratio: %d/%d",
+      video_width, video_height, num, den);
+
+  /* now find a width x height that respects this display ratio.
+   * prefer those that have one of w/h the same as the incoming video
+   * using wd / hd = num / den */
+
+  /* start with same height, because of interlaced video */
+  /* check hd / den is an integer scale factor, and scale wd with the PAR */
+  if (video_height % den == 0) {
+    GST_DEBUG_OBJECT (ddrawsink, "keeping video height");
+    GST_VIDEO_SINK_WIDTH (ddrawsink) = (guint)
+        gst_util_uint64_scale_int (video_height, num, den);
+    GST_VIDEO_SINK_HEIGHT (ddrawsink) = video_height;
+  } else if (video_width % num == 0) {
+    GST_DEBUG_OBJECT (ddrawsink, "keeping video width");
+    GST_VIDEO_SINK_WIDTH (ddrawsink) = video_width;
+    GST_VIDEO_SINK_HEIGHT (ddrawsink) = (guint)
+        gst_util_uint64_scale_int (video_width, den, num);
+  } else {
+    GST_DEBUG_OBJECT (ddrawsink, "approximating while keeping video height");
+    GST_VIDEO_SINK_WIDTH (ddrawsink) = (guint)
+        gst_util_uint64_scale_int (video_height, num, den);
+    GST_VIDEO_SINK_HEIGHT (ddrawsink) = video_height;
+  }
+  GST_DEBUG_OBJECT (ddrawsink, "scaling to %dx%d",
+      GST_VIDEO_SINK_WIDTH (ddrawsink), GST_VIDEO_SINK_HEIGHT (ddrawsink));
+
+  if (GST_VIDEO_SINK_WIDTH (ddrawsink) <= 0 ||
+      GST_VIDEO_SINK_HEIGHT (ddrawsink) <= 0)
+    goto no_display_size;
+
+  ddrawsink->video_width = video_width;
+  ddrawsink->video_height = video_height;
+  GST_DEBUG("ddrawsink->video_width=%d ddrawsink->video_height=%d",ddrawsink->video_width,ddrawsink->video_height);
+  GST_DEBUG("GST_VIDEO_SINK_WIDTH = %d GST_VIDEO_SINK_HEIGHT = %d",GST_VIDEO_SINK_WIDTH (ddrawsink),GST_VIDEO_SINK_HEIGHT (ddrawsink));
 
   ddrawsink->fps_n = gst_value_get_fraction_numerator (fps);
   ddrawsink->fps_d = gst_value_get_fraction_denominator (fps);
@@ -595,6 +647,27 @@
   }
 
   return ret;
+
+invalid_format:
+  {
+    gchar* caps_txt = gst_caps_to_string (caps);
+    GST_DEBUG_OBJECT (ddrawsink,
+        "Could not locate image format from caps %s", caps_txt);
+    g_free (caps_txt);
+    return FALSE;
+  }
+no_disp_ratio:
+  {
+    GST_ELEMENT_ERROR (ddrawsink, CORE, NEGOTIATION, (NULL),
+        ("Error calculating the output display ratio of the video."));
+    return FALSE;
+  }
+no_display_size:
+  {
+    GST_ELEMENT_ERROR (ddrawsink, CORE, NEGOTIATION, (NULL),
+        ("Error calculating the output display ratio of the video."));
+    return FALSE;
+  }
 }
 
 static GstStateChangeReturn
