[pitivi] smartvideoscale: Use videoscale add-border property instead of smartvideoscale



commit 6a6af3e213cf60d462458f7ce3f8a141cf42f50c
Author: Robert Swain <robert swain collabora co uk>
Date:   Mon Jul 26 19:17:00 2010 +0200

    smartvideoscale: Use videoscale add-border property instead of smartvideoscale
    
    The videoscale GStreamer element now has black border padding capability that
    is enabled through the add-borders property so the smartvideoscale calculations
    are no longer needed.

 pitivi/elements/smartscale.py |   79 +++++++---------------------------------
 1 files changed, 14 insertions(+), 65 deletions(-)
---
diff --git a/pitivi/elements/smartscale.py b/pitivi/elements/smartscale.py
index f30f186..32da20a 100644
--- a/pitivi/elements/smartscale.py
+++ b/pitivi/elements/smartscale.py
@@ -49,15 +49,14 @@ class SmartVideoScale(gst.Bin):
         # future, or ask the user which method he wants to use
         # FIXME : Instead of having the set_caps() method, use proper caps negotiation
         self.videoscale.props.method = 1
-        self.videobox = gst.element_factory_make("videobox", "smart-videobox")
-        self.videobox.props.border_alpha = 0.0
+        self.videoscale.props.add_borders = True
         self.capsfilter = gst.element_factory_make("capsfilter", "smart-capsfilter")
-        self.add(self.videoscale, self.capsfilter, self.videobox)
-        gst.element_link_many(self.videoscale, self.capsfilter, self.videobox)
+        self.add(self.videoscale, self.capsfilter)
+        gst.element_link_many(self.videoscale, self.capsfilter)
 
         self._sinkpad = gst.GhostPad("sink", self.videoscale.get_pad("sink"))
         self._sinkpad.set_active(True)
-        self._srcpad = gst.GhostPad("src", self.videobox.get_pad("src"))
+        self._srcpad = gst.GhostPad("src", self.capsfilter.get_pad("src"))
         self._srcpad.set_active(True)
 
         self.add_pad(self._sinkpad)
@@ -81,18 +80,20 @@ class SmartVideoScale(gst.Bin):
     def set_caps(self, caps):
         """ set the outgoing caps, because gst.BaseTransform is full of CRACK ! """
         self.widthout, self.heightout, self.parout, self.darout = self._getValuesFromCaps(caps, True)
+        self.caps_copy = gst.Caps(caps)
+        del self.caps_copy[0]["format"]
+        del self.caps_copy[0]["framerate"]
 
     def _sinkSetCaps(self, unused_pad, caps):
         self.log("caps:%s" % caps.to_string())
         self.widthin, self.heightin, self.parin, self.darin = self._getValuesFromCaps(caps)
         self._computeAndSetValues()
-        res = self.videoscale.get_pad("sink").set_caps(caps)
-        return res
+        return True
 
     def _srcSetCaps(self, unused_pad, caps):
         self.log("caps:%s" % caps.to_string())
         self.widthout, self.heightout, self.parout, self.darout = self._getValuesFromCaps(caps)
-        res = self.videobox.get_pad("src").set_caps(caps)
+        res = self.capsfilter.get_pad("src").set_caps(caps)
         if res:
             self.capsout = caps
             self._computeAndSetValues()
@@ -134,67 +135,15 @@ class SmartVideoScale(gst.Bin):
         return (width, height, par, dar)
 
     def _computeAndSetValues(self):
-        """ Calculate the new values to set on capsfilter and videobox. """
-        if self.widthin == -1 or self.heightin == -1 or self.widthout == -1 or self.heightout == -1:
+        """ Calculate the new values to set on capsfilter. """
+        if self.widthout == -1 or self.heightout == -1:
             # FIXME : should we reset videobox/capsfilter properties here ?
-            self.error("We don't have input and output caps, we can't calculate videobox values")
+            self.error("We don't have output caps, we can't fix values for videoscale")
             return
 
-        self.log("incoming width/height/PAR/DAR : %d/%d/%r/%r" % (self.widthin, self.heightin,
-                                                                  self.parin, self.darin))
-        self.log("outgoing width/height/PAR/DAR : %d/%d/%r/%r" % (self.widthout, self.heightout,
-                                                                  self.parout, self.darout))
-
-
-        # for core <= 0.10.22 we always set caps != any, see 574805 for the
-        # details
-        if self.darin == self.darout and gst.version() >= (0, 10, 23):
-            self.log("We have same input and output caps, resetting capsfilter and videobox settings")
-            # same DAR, set inputcaps on capsfilter, reset videobox values
-            astr = "width=%d,height=%d" % (self.widthout, self.heightout)
-            caps = gst.caps_from_string("video/x-raw-yuv,%s;video/x-raw-rgb,%s" % (astr, astr))
-
-            left = 0
-            right = 0
-            top = 0
-            bottom = 0
-        else:
-            par = self.parout
-            dar = self.darin
-            if float(self.darin) > float(self.darout):
-                self.log("incoming DAR is greater that ougoing DAR. Adding top/bottom borders")
-                # width, PAR stays the same as output
-                # calculate newheight = (PAR * widthout) / DAR
-                newheight = (par.num * self.widthout * dar.denom) / (par.denom * dar.num)
-                self.log("newheight should be %d" % newheight)
-                extra = self.heightout - newheight
-                top = extra / 2
-                bottom = extra - top # compensate for odd extra
-                left = right = 0
-                # calculate filter caps
-                astr = "width=%d,height=%d" % (self.widthout, newheight)
-            else:
-                self.log("incoming DAR is smaller than outgoing DAR. Adding left/right borders")
-                # height, PAR stays the same as output
-                # calculate newwidth = (DAR * heightout) / PAR
-                newwidth = (dar.num * self.heightout * par.denom) / (dar.denom * par.num)
-                self.log("newwidth should be %d" % newwidth)
-                extra = self.widthout - newwidth
-                left = extra / 2
-                right = extra - left # compensate for odd extra
-                top = bottom = 0
-                # calculate filter caps
-                astr = "width=%d,height=%d" % (newwidth, self.heightout)
-            caps = gst.caps_from_string("video/x-raw-yuv,%s;video/x-raw-rgb,%s" % (astr, astr))
-
         # set properties on elements
-        self.debug("About to set left/right/top/bottom : %d/%d/%d/%d" % (-left, -right, -top, -bottom))
-        self.videobox.props.left = -left
-        self.videobox.props.right = -right
-        self.videobox.props.top = -top
-        self.videobox.props.bottom = -bottom
-        self.debug("Settings filter caps %s" % caps.to_string())
-        self.capsfilter.props.caps = caps
+        self.debug("Settings filter caps %s" % self.caps_copy.to_string())
+        self.capsfilter.props.caps = self.caps_copy
         self.debug("done")
 
 gobject.type_register(SmartVideoScale)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]