liquidsoap icon indicating copy to clipboard operation
liquidsoap copied to clipboard

Issue with source.shutdown() with dynamic streams example

Open theotherjenkutler opened this issue 4 years ago • 0 comments

Describe the bug source.shutdown() appears to do nothing when called.

To Reproduce This is a basic example to play an audio file at random from a local folder and then shutdown the source after one track is played.

#!/home/jenkutler/.opam/4.10.0/bin/liquidsoap

settings.init.force_start.set(true) #this will allow LS to start w/o an active source
settings.server.telnet.set(true) #starts telnet server

set("log.file",false)
#set("log.file.path", "/home/jenkutler/ls_logs/measures.log")
set("log.stdout",true)
set("log.level",5)

# First, we create a list referencing the dynamic sources:
dyn_sources = ref([])


def on_telconnect(m)
    identifierstring = ""
    i = ref(identifierstring)
    i := (m)
    log.debug(!i)
    # The playlist source 
    uri = "/home/jenkutler/audio/"
    s = playlist(uri)
    # The output
    out = output.icecast(%mp3(samplerate = 44100, internal_quality=1),
    host = "localhost", port = 8000,
    password = "measures", mount = !i,
    s,
    fallible = true)

    # We register both source and output 
    # in the list of sources
    dyn_sources := 
        list.append( [(uri,s)],
                    !dyn_sources)

    list.iter(fun(n) -> print(newline = true, n), !dyn_sources)
    
    trackbool = true
    trackplayed = ref(trackbool)


    def handlemetadata(m)
        log.debug("handling metadata")
        if !trackplayed then
            log.debug("print info to file")
            trackplayed := false
        else
            log.debug("handling the end")
            def parse_list(ret, current_element) = 
                log.debug("parse_list called")
                # ret is of the form: (matching_sources, remaining_sources)
                # We extract those two:
                matching_sources = fst(ret)
                remaining_sources = snd(ret)

                # current_element is of the form: ("uri", source) so 
                # we check the first element
                current_uri = fst(current_element)
                if current_uri == uri then
                    # In this case, we add the source to the list of
                    # matched sources
                    (list.append( [snd(current_element)], 
                             matching_sources),
                            remaining_sources)
                else
                    # In this case, we put the element in the list of remaining
                    # sources
                    (matching_sources,
                    list.append([current_element], 
                                remaining_sources))
                end
            end    
    
            # Now we execute the function:
            result = list.fold(parse_list, ([], []), !dyn_sources)
            matching_sources = fst(result)
            remaining_sources = snd(result)

            # We store the remaining sources in dyn_sources
            dyn_sources := remaining_sources

            # If no source matched, we return an error
            if list.length(matching_sources) == 0 then
                log.debug("Error: no matching sources!")
            else
                # We stop all sources
                log.debug("We stop all sources")
                list.iter(source.shutdown, matching_sources)
                # And return
            
            end
        end       
    end
    source.on_metadata(s, handlemetadata)

    "Done"
end
server.register(usage= "mac <mac>",
                "mac", on_telconnect)




Expected behavior For the source to be shutdown, and the client(s) to be disconnected from the stream.

Version details

  • OS: Ubuntu 20.04
  • Version 2.0.2

Install method Opam

theotherjenkutler avatar Mar 05 '22 15:03 theotherjenkutler