Git Product home page Git Product logo

Comments (8)

thesyncim avatar thesyncim commented on July 24, 2024 1

ups..., thanks a lot! this is very powerful !!

from joy4.

nareix avatar nareix commented on July 24, 2024 1

thanks, I'll check it

from joy4.

nareix avatar nareix commented on July 24, 2024

there's a closure bug:

        for i := range streamMap {
            go func(i int) {
                err := pushStream(que, streamMap[i], wait)
                if err != nil {
                    log.Println(err)
                }

            }(i)
        }

from joy4.

nareix avatar nareix commented on July 24, 2024

and wait should start before go func():

        for i := range streamMap {
            wait.Add(1)
            go func(i int) {
                err := pushStream(que, streamMap[i], wait)
                if err != nil {
                    log.Println(err)
                }
            }(i)
        }

from joy4.

thesyncim avatar thesyncim commented on July 24, 2024

Using OBS studio sometimes i get a data race report with -race enabled

WARNING: DATA RACE
Write at 0x00c420078670 by main goroutine:
github.com/nareix/joy4/format/rtmp.(*Server).ListenAndServe()
/home/thesyncim/gocode/src/github.com/nareix/joy4/format/rtmp/rtmp.go:107 +0x2b2
main.proxyServer()
/home/thesyncim/gocode/src/github.com/thesyncim/exp/rtmp/proxy.go:79 +0xa7
main.main()
/home/thesyncim/gocode/src/github.com/thesyncim/exp/rtmp/proxy.go:24 +0x2f

Previous write at 0x00c420078670 by goroutine 6:
github.com/nareix/joy4/format/rtmp.(*Server).ListenAndServe.func1()
/home/thesyncim/gocode/src/github.com/nareix/joy4/format/rtmp/rtmp.go:118 +0x81

Goroutine 6 (finished) created at:
github.com/nareix/joy4/format/rtmp.(*Server).ListenAndServe()
/home/thesyncim/gocode/src/github.com/nareix/joy4/format/rtmp/rtmp.go:122 +0xa6f
main.proxyServer()
/home/thesyncim/gocode/src/github.com/thesyncim/exp/rtmp/proxy.go:79 +0xa7
main.main()

/home/thesyncim/gocode/src/github.com/thesyncim/exp/rtmp/proxy.go:24 +0x2f

from joy4.

thesyncim avatar thesyncim commented on July 24, 2024

using the code from example above i'm unable to push a stream to youtube/srs server (only go-oryx
can handle the stream).

wireshark file:
push_youtube.pcapng.zip

from joy4.

nareix avatar nareix commented on July 24, 2024

fixed datarace 4918d07

from joy4.

thesyncim avatar thesyncim commented on July 24, 2024

you can replicate the issue with:

ffmpeg -re -i bbb_sunflower_1080p_60fps_normal.mp4 -c:v libx264 -b:v 2M -pix_fmt yuv420p -c🅰️0 aac -strict -2 -b🅰️0 480k -f flv rtmp://localhost/live/azorestv

package main

import (
    "log"
    "strings"
    "sync"

    "github.com/nareix/joy4/av/avutil"
    "github.com/nareix/joy4/av/pubsub"
    "github.com/nareix/joy4/format"
    "github.com/nareix/joy4/format/rtmp"

)

func init() {
    format.RegisterAll()
    log.SetFlags(log.Lshortfile|log.Ltime)
}

var sm = map[string][]string{
    "azorestv": []string{"rtmp://opinion.azorestv.com:1936/live/test"},
}

func main() {
    proxyServer()
}

func proxyServer() {
    server := &rtmp.Server{}
    //rtmp.Debug=true

    server.HandlePublish = func(conn *rtmp.Conn) {

        segs := strings.Split(conn.URL.Path, "/")

        key := segs[2]
        streamMap, ok := sm[key]
        if !ok {
            log.Println("invalid key")
            return
        }

        que := &pubsub.Queue{}

        streams, err := conn.Streams()
        if err != nil {
            log.Println(err)
            return
        }

        que = pubsub.NewQueue(streams)

        wait := &sync.WaitGroup{}

        for i := range streamMap {
            wait.Add(1)
            go func(i int,que *pubsub.Queue,wait *sync.WaitGroup) {
                err := pushStream(que, streamMap[i], wait)
                if err != nil {
                    log.Println(err)
                }
            }(i,que,wait)
        }

        go avutil.CopyPackets(que, conn)

        wait.Wait()
    }

    server.ListenAndServe()

}

func pushStream(sub *pubsub.Queue, dsturl string, wait *sync.WaitGroup) error {
    defer wait.Done()

    origin := sub.Latest()

    dst, err := rtmp.Dial(dsturl)
    if err != nil {
        return err
    }

    defer dst.Close()

    return avutil.CopyFile(dst, origin)
}

feel free to use this server(srs 3.0) to debug the issue
thank you

from joy4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.