def testMatchStreamNoMatch(self): s1 = AudioStream(gst.Caps("audio/x-vorbis")) s2 = VideoStream(gst.Caps("video/x-theora")) stream, rank = match_stream(s1, []) self.failUnlessEqual(stream, None) self.failUnlessEqual(rank, STREAM_MATCH_NONE) stream, rank = match_stream(s1, [s2]) self.failUnlessEqual(stream, None) self.failUnlessEqual(rank, STREAM_MATCH_NONE)
def testMatchStreamSameNameAndCompatibleCaps(self): s1 = AudioStream(gst.Caps("audio/x-vorbis, a={1, 2}"), pad_name="src0") s2 = AudioStream(gst.Caps("audio/x-vorbis, a={2, 3}"), pad_name="src0") stream, rank = match_stream(s1, [s2]) self.failUnlessEqual(id(s2), id(stream)) self.failUnlessEqual(rank, STREAM_MATCH_SAME_PAD_NAME + STREAM_MATCH_COMPATIBLE_CAPS)
def testMatchSamePadName(self): s1 = AudioStream(gst.Caps("audio/x-vorbis"), pad_name="src0") s2 = AudioStream(gst.Caps("audio/x-speex"), pad_name="src0") stream, rank = match_stream(s1, [s2]) self.failUnlessEqual(id(s2), id(stream)) self.failUnlessEqual(rank, STREAM_MATCH_SAME_PAD_NAME + STREAM_MATCH_SAME_TYPE)
def testMatchStreamSameNameAndSameCaps(self): s1 = AudioStream(gst.Caps("audio/x-vorbis"), pad_name="src0") s2 = AudioStream(gst.Caps("audio/x-vorbis"), pad_name="src0") stream, rank = match_stream(s1, [s2]) self.failUnlessEqual(id(s2), id(stream)) self.failUnlessEqual( rank, STREAM_MATCH_SAME_PAD_NAME + STREAM_MATCH_SAME_CAPS) self.failUnlessEqual(rank, STREAM_MATCH_MAXIMUM)
def testMatchStreamSameNameAndSameCaps(self): s1 = AudioStream(gst.Caps("audio/x-vorbis"), pad_name="src0") s2 = AudioStream(gst.Caps("audio/x-vorbis"), pad_name="src0") stream, rank = match_stream(s1, [s2]) self.failUnlessEqual(id(s2), id(stream)) self.failUnlessEqual(rank, STREAM_MATCH_SAME_PAD_NAME + STREAM_MATCH_SAME_CAPS) self.failUnlessEqual(rank, STREAM_MATCH_MAXIMUM)
def getTeeForFactoryStream(self, factory, stream=None, automake=False): """ Fetches the C{Tee} currently used in the C{gst.Pipeline} for the given L{SourceFactory}. @param factory: The factory to search. @type factory: L{SourceFactory} @param stream: The stream of the factory to use. If not specified, then a random stream from that factory will be used. @type stream: L{MultimediaStream} @param automake: If set to True, then if there is not a C{Tee} already created for the given factory/stream, one will be created, added to the list of controlled tees and added to the C{gst.Pipeline}. @raise PipelineError: If the factory isn't used in this pipeline. @raise PipelineError: If the factory isn't a L{SourceFactory}. @raise PipelineError: If a C{Tee} needed to be created but the creation of that C{Tee} failed. @return: The C{Tee} corresponding to the given factory/stream or None if there are none for the given factory. @rtype: C{gst.Element} """ self.debug("factory:%r , stream:%r, automake:%r", factory, stream, automake) if not isinstance(factory, SourceFactory): raise PipelineError("Given ObjectFactory isn't a SourceFactory") stream_entry = self._getStreamEntryForFactoryStream(factory, stream) bin_stream_entry = stream_entry.findBinEntry() if bin_stream_entry is None: raise PipelineError("couldn't find bin entry") bin = bin_stream_entry.bin if stream_entry.tee is not None: stream_entry.tee_use_count += 1 # have an existing tee, return it return stream_entry.tee if not automake: raise PipelineError("no automake") self.debug("Really creating a tee") # get the source pads pads = get_src_pads_for_stream(bin, None) # get the corresponding streams streams = [get_stream_for_pad(pad, store_pad=True) for pad in pads] # find the pad that matches the given stream best if stream is None: if len(streams) == 1: stream = streams[0] else: raise PipelineError("bin has multiple compatible pads") stream, rank = match_stream(stream, streams) if stream is None: raise PipelineError("bin has no compatible source pads") srcpad = stream.pad self.debug("Using pad %r", srcpad) stream_entry.tee = gst.element_factory_make("tee") self._pipeline.add(stream_entry.tee) stream_entry.tee_use_count += 1 stream_entry.tee.set_state(STATE_PAUSED) self.debug("Linking pad %r to tee", pads[0]) srcpad.link_full(stream_entry.tee.get_pad("sink"), gst.PAD_LINK_CHECK_NOTHING) return stream_entry.tee
def testMatchStreamCompatibleCaps(self): s1 = AudioStream(gst.Caps("audio/x-vorbis, a={1, 2}")) s2 = AudioStream(gst.Caps("audio/x-vorbis, a={2, 3}")) stream, rank = match_stream(s1, [s2]) self.failUnlessEqual(id(s2), id(stream)) self.failUnlessEqual(rank, STREAM_MATCH_COMPATIBLE_CAPS)
def testMatchStreamSameCaps(self): s1 = AudioStream(gst.Caps("audio/x-vorbis, a=1")) s2 = AudioStream(gst.Caps("audio/x-vorbis, a=2")) stream, rank = match_stream(s1, [s1, s2]) self.failUnlessEqual(id(s1), id(stream)) self.failUnlessEqual(rank, STREAM_MATCH_SAME_CAPS)
def getTeeForFactoryStream(self, factory, stream=None, automake=False): """ Fetches the C{Tee} currently used in the C{gst.Pipeline} for the given L{SourceFactory}. @param factory: The factory to search. @type factory: L{SourceFactory} @param stream: The stream of the factory to use. If not specified, then a random stream from that factory will be used. @type stream: L{MultimediaStream} @param automake: If set to True, then if there is not a C{Tee} already created for the given factory/stream, one will be created, added to the list of controlled tees and added to the C{gst.Pipeline}. @raise PipelineError: If the factory isn't used in this pipeline. @raise PipelineError: If the factory isn't a L{SourceFactory}. @raise PipelineError: If a C{Tee} needed to be created but the creation of that C{Tee} failed. @return: The C{Tee} corresponding to the given factory/stream or None if there are none for the given factory. @rtype: C{gst.Element} """ self.debug("factory:%r , stream:%r, automake:%r", factory, stream, automake) if not isinstance(factory, SourceFactory): raise PipelineError("Given ObjectFactory isn't a SourceFactory") stream_entry = self._getStreamEntryForFactoryStream(factory, stream) bin_stream_entry = stream_entry.findBinEntry() if bin_stream_entry is None: raise PipelineError("couldn't find bin entry") bin = bin_stream_entry.bin if stream_entry.tee is not None: stream_entry.tee_use_count += 1 # have an existing tee, return it return stream_entry.tee if not automake: raise PipelineError("no automake") self.debug("Really creating a tee") # get the source pads pads = get_src_pads_for_stream(bin, None) # get the corresponding streams streams = [get_stream_for_pad(pad, store_pad=True) for pad in pads] # find the pad that matches the given stream best if stream is None: if len(streams) == 1: stream = streams[0] else: raise PipelineError("bin has multiple compatible pads") stream, rank = match_stream(stream, streams) if stream is None: raise PipelineError("bin has no compatible source pads") srcpad = stream.pad self.debug("Using pad %r", srcpad) stream_entry.tee = gst.element_factory_make("tee") self._pipeline.add(stream_entry.tee) stream_entry.tee_use_count += 1 stream_entry.tee.set_state(STATE_PAUSED) self.debug("Linking pad %r to tee", pads[0]) srcpad.link(stream_entry.tee.get_pad("sink")) return stream_entry.tee