Beispiel #1
0
def request_stream(request):
    session_id = request.GET.get("session_id", None)
    if not session_id:
        raise RoundException("Must supply session_id.")

    log_event("request_stream", int(session_id), request.GET)

    session = models.Session.objects.select_related("project").get(id=session_id)
    project = session.project

    # Get the value 'example.com' from the host 'example.com:8888'
    http_host = request.get_host().split(":")[0]

    if session.demo_stream_enabled:
        msg = t("demo_stream_message", project.demo_stream_message_loc, session.language)

        if project.demo_stream_url:
            url = project.demo_stream_url
        else:
            url = "http://%s:%s/demo_stream.mp3" % (http_host, settings.ICECAST_PORT)
        return {"stream_url": url, "demo_stream_message": msg}

    elif is_listener_in_range_of_stream(request.GET, project):
        # TODO: audio_format.upper() should be handled when the project is saved.
        audio_format = project.audio_format.upper()
        # Make the audio stream if it doesn't exist.
        if not stream_exists(session.id, audio_format):
            command = [
                settings.PROJECT_ROOT + "/roundwared/rwstreamd.py",
                "--session_id",
                str(session.id),
                "--project_id",
                str(project.id),
            ]
            for p in ["latitude", "longitude", "audio_format"]:
                if p in request.GET and request.GET[p]:
                    command.extend(["--" + p, request.GET[p].replace("\t", ",")])
            if "audio_stream_bitrate" in request.GET:
                command.extend(["--audio_stream_bitrate", str(request.GET["audio_stream_bitrate"])])

            apache_safe_daemon_subprocess(command)
            wait_for_stream(session.id, audio_format)

        return {
            "stream_url": "http://%s:%s%s"
            % (http_host, settings.ICECAST_PORT, icecast2.mount_point(session.id, audio_format))
        }
    else:
        msg = t(
            "This application is designed to be used in specific geographic"
            " locations. Apparently your phone thinks you are not at one of"
            " those locations, so you will hear a sample audio stream"
            " instead of the real deal. If you think your phone is"
            " incorrect, please restart Scapes and it will probably work."
            " Thanks for checking it out!",
            project.out_of_range_message_loc,
            session.language,
        )

        return {"stream_url": project.out_of_range_url, "user_message": msg}
Beispiel #2
0
    def is_anyone_listening(self):
        mount_point = icecast2.mount_point(self.sessionid, self.audio_format)
        listeners = self.icecast_admin.get_client_count(mount_point)
        logger.debug("Number of listeners: %d " % listeners)
        if self.last_listener_count == 0 and listeners == 0:
            # logger.info("Detected noone listening.")
            return False

        self.last_listener_count = listeners
        return True
Beispiel #3
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.MASTER_VOLUME)
        shout2send = gst.element_factory_make("shout2send")
        shout2send.set_property("username", settings.ICECAST_SOURCE_USERNAME)
        shout2send.set_property("password", settings.ICECAST_SOURCE_PASSWORD)
        shout2send.set_property("mount",
                                icecast2.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))
            logger.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)
Beispiel #4
0
def stream_exists(sessionid, audio_format):
    admin = icecast2.Admin()
    return admin.stream_exists(icecast2.mount_point(sessionid, audio_format))
Beispiel #5
0
def request_stream(request):
    session_id = request.GET.get('session_id', None)
    if not session_id:
        raise RoundException("Must supply session_id.")

    log_event("request_stream", int(session_id), request.GET)

    session = models.Session.objects.select_related('project').get(
        id=session_id)
    project = session.project

    # Get the value 'example.com' from the host 'example.com:8888'
    http_host = request.get_host().split(':')[0]

    if session.demo_stream_enabled:
        msg = t("demo_stream_message", project.demo_stream_message_loc,
                session.language)

        if project.demo_stream_url:
            url = project.demo_stream_url
        else:
            url = "http://%s:%s/demo_stream.mp3" % (http_host,
                                                    settings.ICECAST_PORT)
        return {'stream_url': url, 'demo_stream_message': msg}

    elif is_listener_in_range_of_stream(request.GET, project):
        # TODO: audio_format.upper() should be handled when the project is saved.
        audio_format = project.audio_format.upper()
        # Make the audio stream if it doesn't exist.
        if not stream_exists(session.id, audio_format):
            command = [
                settings.PROJECT_ROOT + '/roundwared/rwstreamd.py',
                '--session_id',
                str(session.id), '--project_id',
                str(project.id)
            ]
            for p in ['latitude', 'longitude', 'audio_format']:
                if p in request.GET and request.GET[p]:
                    command.extend(
                        ['--' + p, request.GET[p].replace("\t", ",")])
            if 'audio_stream_bitrate' in request.GET:
                command.extend([
                    '--audio_stream_bitrate',
                    str(request.GET['audio_stream_bitrate'])
                ])

            apache_safe_daemon_subprocess(command)
            wait_for_stream(session.id, audio_format)

        return {
            "stream_url":
            "http://%s:%s%s" % (http_host, settings.ICECAST_PORT,
                                icecast2.mount_point(session.id, audio_format))
        }
    else:
        msg = t(
            "This application is designed to be used in specific geographic"
            " locations. Apparently your phone thinks you are not at one of"
            " those locations, so you will hear a sample audio stream"
            " instead of the real deal. If you think your phone is"
            " incorrect, please restart Scapes and it will probably work."
            " Thanks for checking it out!", project.out_of_range_message_loc,
            session.language)

        return {'stream_url': project.out_of_range_url, 'user_message': msg}
Beispiel #6
0
def stream_exists(sessionid, audio_format):
    admin = icecast2.Admin()
    return admin.stream_exists(icecast2.mount_point(sessionid, audio_format))