Exemplo n.º 1
0
    def test_Iteration_Empty(self):
        """Attempts to iterate over no items returns no items"""
        x = ForwardIteratingChooser([])

        try:
            x.getCurrentChoice()
            self.fail()
        except IndexError:
            self.assert_(True, "Can't iterate over empty")
    def test_Iteration_Empty(self):
        """Attempts to iterate over no items returns no items"""
        x = ForwardIteratingChooser([])

        try:
            x.getCurrentChoice()
            self.fail()
        except IndexError:
            self.assert_(True, "Can't iterate over empty")
Exemplo n.º 3
0
def PassThroughAudioSegment(tmpFilePath, edit, backplane_name):
    """\
    Prefab.
    
    For a particular edit decision; reads in the audio frames corresponding to
    the video frames referred to in the reframing instructions in sequence.
    Outputs the audio frames out of the "outbox" outbox.
    
    Arguments:
    
    - edlfile      -- full filepathname of the EDL xml file
    - tmpFilePath  -- temp directory into which video frames have been saved
    
    Inboxes:
    
    - "inbox"    -- NOT USED
    - "control"  -- Shutdown signalling
    
    Outboxes:
    
    - "outbox"  -- raw audio data, chunked by frames
    - "signal"  -- Shutdown signalling
    """
    print " Audio segment: ", edit
    filenames = [
        tmpFilePath + "%08d.wav" % i
        for i in range(edit["start"], edit["end"] + 1)
    ]

    return Graphline( \
        FILENAMES = ForwardIteratingChooser(filenames),
        FRAME_LOADER = Carousel( lambda filename :
                                 Graphline(
                                     READ = MaxSpeedFileReader(filename),
                                     PARS = WAVParser(),
                                     META = PublishTo(backplane_name),
                                     linkages = {
                                         ("READ","outbox") : ("PARS","inbox"),
                                         ("PARS","outbox") : ("","outbox"),

                                         ("PARS","all_meta") : ("META","inbox"),

                                         ("","control") : ("READ","control"),
                                         ("READ","signal") : ("PARS","control"),
                                         ("PARS","signal") : ("META","control"),
                                         ("META","signal") : ("","signal"),
                                     },
                                     boxsizes = { ("PARS","inbox") : 2 },
                                 ),
                                 make1stRequest=False ),
        linkages = {
            ("FRAME_LOADER", "requestNext") : ("FILENAMES", "inbox"),

            ("FILENAMES",    "outbox") : ("FRAME_LOADER", "next"),
            ("FRAME_LOADER", "outbox") : ("", "outbox"),

            ("FILENAMES",    "signal") : ("FRAME_LOADER", "control"),
            ("FRAME_LOADER", "signal") : ("", "signal"),
        },
    )
 def protocolFactory(*argv, **argd):
     return JoinChooserToCarousel(
         ForwardIteratingChooser(filenames),
         FixedRateControlledReusableFileReader(readmode="bytes",
                                            rate=bitrate/8,
                                            chunksize=chunksizebytes)
       )
Exemplo n.º 5
0
def ProcessEditDecision(tmpFilePath, edit, width, height):
    """\
    Prefab.
    
    Applies an edit decision - reading in the relevant video frames and applying
    the reframing. Outputs the reframed video frames out of the "outbox" outbox.
    
    Arguments:
    
    - tmpFilePath  -- temp directory into which video frames have been saved
    - edit         -- the edit instruction (dictionary containing: "start","end","left","top","right","bottom")
    - width        -- width (in pixels) for output video frames
    - height       -- height (in pixels) for output video frames
    
    Inboxes:
    
    - "inbox"    -- NOT USED
    - "control"  -- Shutdown signalling
    
    Outboxes:
    
    - "outbox"  -- NOT USED
    - "signal"  -- Shutdown signalling
    """
    print " Video segment: ", edit
    filenames = [
        tmpFilePath + "%08d.yuv" % i
        for i in range(edit["start"], edit["end"] + 1)
    ]
    newsize = (width, height)
    cropbounds = (edit["left"], edit["top"], edit["right"], edit["bottom"])

    return Graphline( \
        FILENAMES = ForwardIteratingChooser(filenames),
        FRAME_LOADER = Carousel( lambda filename :
                                 Pipeline(
                                     2, MaxSpeedFileReader(filename,chunksize=1024*1024),
                                     2, YUV4MPEGToFrame(),
                                     ),
                                 make1stRequest=False ),
        REFRAMING = Pipeline( 2, ToRGB_interleaved(),
                              2, CropAndScale(newsize, cropbounds),
                              2, ToYUV420_planar(),
                            ),
        linkages = {
            ("FRAME_LOADER", "requestNext") : ("FILENAMES", "inbox"),

            ("FILENAMES",    "outbox") : ("FRAME_LOADER", "next"),
            ("FRAME_LOADER", "outbox") : ("REFRAMING", "inbox"),
            ("REFRAMING",    "outbox") : ("", "outbox"),

            ("FILENAMES",    "signal") : ("FRAME_LOADER", "control"),
            ("FRAME_LOADER", "signal") : ("REFRAMING", "control"),
            ("REFRAMING",    "signal") : ("", "signal"),
        },
        boxsizes = {
        },
    )
Exemplo n.º 6
0
    def test_Iteration_iteratePastEnd(self):
        """Advancing past the end of the set still returns the last item"""
        fruitlist = ["apple", "banana", "cherry"]
        x = ForwardIteratingChooser(fruitlist)

        x.gotoNext()
        x.gotoNext()

        result = x.getCurrentChoice()
        # print result
        self.assert_(result == fruitlist[2], "Current choice is 3rd item")

        x.gotoNext()

        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[2], "Current choice is 3rd item")
    def test_Iteration_iteratePastEnd(self):
        """Advancing past the end of the set still returns the last item"""
        fruitlist = ["apple", "banana", "cherry"]
        x = ForwardIteratingChooser(fruitlist)

        x.gotoNext()
        x.gotoNext()

        result = x.getCurrentChoice()
        # print result
        self.assert_(result == fruitlist[2], "Current choice is 3rd item")

        x.gotoNext()

        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[2], "Current choice is 3rd item")
Exemplo n.º 8
0
                  metadata["format"])


def makePlayer(mp3filename):
    print mp3filename
    return Graphline(READ=RateControlledFileReader(mp3filename,
                                                   readmode="bytes",
                                                   rate=256000 / 8),
                     DECODE=Decoder("mp3"),
                     OUTPUT=Carousel(makeAudioOutput),
                     linkages={
                         ("READ", "outbox"): ("DECODE", "inbox"),
                         ("DECODE", "outbox"): ("OUTPUT", "inbox"),
                         ("DECODE", "format"): ("OUTPUT", "next"),
                         ("", "control"): ("READ", "control"),
                         ("READ", "signal"): ("DECODE", "control"),
                         ("DECODE", "signal"): ("OUTPUT", "control"),
                         ("OUTPUT", "signal"): ("", "signal"),
                     })


from Kamaelia.Util.Chooser import ForwardIteratingChooser

Graphline(PLAYLIST=ForwardIteratingChooser(filenames),
          PLAYER=Carousel(makePlayer, make1stRequest=False),
          linkages={
              ("PLAYER", "requestNext"): ("PLAYLIST", "inbox"),
              ("PLAYLIST", "outbox"): ("PLAYER", "next"),
              ("PLAYLIST", "signal"): ("PLAYER", "control"),
          }).run()
Exemplo n.º 9
0
    def test_Iteration_iterateForwards(self):
        """Iterating forwards advances forwards through the set"""
        fruitlist = ["apple", "banana", "cherry"]
        x = ForwardIteratingChooser(fruitlist)

        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[0], "Current choice is first item")
        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[0],
                     "Current choice is still first item")

        x.gotoNext()

        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[1], "Current choice is second item")
        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[1],
                     "Current choice is still second item")

        x.gotoNext()

        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[2], "Current choice is 3rd item")
        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[2],
                     "Current choice is still 3rd item")
Exemplo n.º 10
0
 def test_Instantiate_ArgIterator(self):
     "__init__ - Creating, passing iterator is fine"
     x = ForwardIteratingChooser(xrange(0, 5))
     self.assert_(iter_eq(x.items, xrange(1, 5)),
                  "__init__ right number of items")
Exemplo n.º 11
0
 def test_Instantiate_ArgList(self):
     "__init__ - Creating, passing list is fine"
     fruitlist = ["apple", "banana", "cherry"]
     x = ForwardIteratingChooser(fruitlist)
     self.assert_(iter_eq(x.items, fruitlist[1:]),
                  "__init__ list of items stored internally")
Exemplo n.º 12
0
 def test_Instantiate_NoArgs(self):
     "__init__ - Creating empty ForwardIteratingChooser is fine"
     x = ForwardIteratingChooser()
     self.assert_(iter_eq(x.items, []),
                  "__init__ list of items stored internally")
    def test_Iteration_iterateForwards(self):
        """Iterating forwards advances forwards through the set"""
        fruitlist = ["apple", "banana", "cherry"]
        x = ForwardIteratingChooser(fruitlist)

        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[0], "Current choice is first item")
        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[0], "Current choice is still first item")

        x.gotoNext()

        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[1], "Current choice is second item")
        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[1], "Current choice is still second item")

        x.gotoNext()

        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[2], "Current choice is 3rd item")
        result = x.getCurrentChoice()
        self.assert_(result == fruitlist[2], "Current choice is still 3rd item")