예제 #1
0
    def __init__(self, sessionid, audio_format):
        gst.Bin.__init__(self)

        capsfilter = gst.element_factory_make("capsfilter")
        volume = gst.element_factory_make("volume")
        volume.set_property("volume", settings.config["master_volume"])
        shout2send = gst.element_factory_make("shout2send")
        shout2send.set_property("username", "source")
        shout2send.set_property("password", "roundice")
        shout2send.set_property("mount", server.icecast_mount_point(sessionid, audio_format))

        self.add(capsfilter, volume, shout2send)
        capsfilter.link(volume)

        if audio_format.upper() == "MP3":
            capsfilter.set_property(
                "caps",
                gst.caps_from_string("audio/x-raw-int,rate=44100,channels=2,width=16,depth=16,signed=(boolean)true"),
            )
            lame = gst.element_factory_make("lame")
            self.add(lame)
            gst.element_link_many(volume, lame, shout2send)
        elif audio_format.upper() == "OGG":
            capsfilter.set_property("caps", gst.caps_from_string("audio/x-raw-float,rate=44100,channels=2,width=32"))
            vorbisenc = gst.element_factory_make("vorbisenc")
            oggmux = gst.element_factory_make("oggmux")
            self.add(vorbisenc, oggmux)
            gst.element_link_many(volume, vorbisenc, oggmux, shout2send)
        else:
            raise "Invalid format"

        pad = capsfilter.get_pad("sink")
        ghostpad = gst.GhostPad("sink", pad)
        self.add_pad(ghostpad)
예제 #2
0
 def is_anyone_listening(self):
     listeners = self.icecast_admin.get_client_count(server.icecast_mount_point(self.sessionid, self.audio_format))
     # logging.debug("Number of listeners: " + str(listeners))
     if self.last_listener_count == 0 and listeners == 0:
         # logging.info("Detected noone listening.")
         return False
     else:
         self.last_listener_count = listeners
         return True
예제 #3
0
 def is_anyone_listening(self):
     listeners = self.icecast_admin.get_client_count(
         icecast_mount_point(self.sessionid, self.audio_format))
     #logging.debug("Number of listeners: " + str(listeners))
     if self.last_listener_count == 0 and listeners == 0:
         #logging.info("Detected noone listening.")
         return False
     else:
         self.last_listener_count = listeners
         return True
예제 #4
0
    def __init__(self, sessionid, audio_format, bitrate):
        gst.Bin.__init__(self)
        #self.taginjector = gst.element_factory_make("taginject")
        #self.taginjector.set_property("tags","title=\"asset_id=123\"")

        capsfilter = gst.element_factory_make("capsfilter")
        volume = gst.element_factory_make("volume")
        volume.set_property("volume", settings.config["master_volume"])
        shout2send = gst.element_factory_make("shout2send")
        shout2send.set_property("username",
                                settings.config["icecast_source_username"])
        shout2send.set_property("password",
                                settings.config["icecast_source_password"])
        #shout2send.set_property("username", "source")
        #shout2send.set_property("password", "roundice")
        shout2send.set_property("mount",
                                icecast_mount_point(sessionid, audio_format))
        #shout2send.set_property("streamname","initial name")
        #self.add(capsfilter, volume, self.taginjector, shout2send)
        self.add(capsfilter, volume, shout2send)
        capsfilter.link(volume)

        if audio_format.upper() == "MP3":
            capsfilter.set_property(
                "caps",
                gst.caps_from_string(
                    "audio/x-raw-int,rate=44100,channels=2,width=16,depth=16,signed=(boolean)true"
                ))
            lame = gst.element_factory_make("lame")
            lame.set_property("bitrate", int(bitrate))
            logging.debug("roundstreamsink: bitrate: " + str(int(bitrate)))
            self.add(lame)
            #gst.element_link_many(volume, lame, self.taginjector, shout2send)
            gst.element_link_many(volume, lame, shout2send)
        elif audio_format.upper() == "OGG":
            capsfilter.set_property(
                "caps",
                gst.caps_from_string(
                    "audio/x-raw-float,rate=44100,channels=2,width=32"))
            vorbisenc = gst.element_factory_make("vorbisenc")
            oggmux = gst.element_factory_make("oggmux")
            self.add(vorbisenc, oggmux)
            #gst.element_link_many(volume, vorbisenc, oggmux, self.taginjector, shout2send)
            gst.element_link_many(volume, vorbisenc, oggmux, shout2send)
        else:
            raise "Invalid format"

        pad = capsfilter.get_pad("sink")
        ghostpad = gst.GhostPad("sink", pad)
        self.add_pad(ghostpad)