Heim  >  Artikel  >  Backend-Entwicklung  >  Warum generiert pion/webrtc eine Kandidatenliste ohne TCP-Adresse?

Warum generiert pion/webrtc eine Kandidatenliste ohne TCP-Adresse?

王林
王林nach vorne
2024-02-08 20:48:13529Durchsuche

Warum generiert pion/webrtc eine Kandidatenliste ohne TCP-Adresse?

Frageninhalt

Ich möchte golang pion/webrtc verwenden, um lokale Videodateien auf einem Videoserver zu veröffentlichen. Wenn ich Angebots-SDP über pion/webrtc-Code erzeuge, funktioniert dies in der Kandidatenliste Ich habe keinen TCP-Kandidaten, daher ist die Ice-Verbindung fehlgeschlagen. Wenn ich Chrome als WebRTC-Client zum Posten von Kameravideos verwende, funktioniert es. Ich weiß nicht, wie ich Chrome dazu bringen kann, TCP-Kandidaten zu deaktivieren. Ich habe die Kandidaten für Chrome und Pion/WebRTC überprüft und festgestellt, dass der Unterschied in der TCP-Adresse des Kandidaten liegt. Ich habe versucht, mein Bestes zu geben, um pion/webrtc TCP-Kandidatenadressen generieren zu lassen, aber sie sind alle fehlgeschlagen. Bitte helfen Sie mir.

Das ist mein Code:

package main

import (
    "fmt"
    "io"
    "os"
    "path/filepath"
    "sync"
    "time"

    "github.com/google/uuid"
    "github.com/pion/webrtc/v3"
    "github.com/pion/webrtc/v3/pkg/media"
    "github.com/pion/webrtc/v3/pkg/media/h264reader"
)

func main() {

    // 创建peerconnection配置
    config := webrtc.configuration{
        iceservers: []webrtc.iceserver{
            {
                urls: []string{"stun:stun.l.google.com:19302"},
            },
        },
        icetransportpolicy: webrtc.icetransportpolicyall,
    }

    // 创建peerconnection
    peerconnection, err := webrtc.newpeerconnection(config)
    if err != nil {
        panic(err)
    }

    videotrack, err := newh264localstaticsamplevideotrack("test.h264", 25)
    if err != nil {
        panic(err)
    }

    if rtpsender, err := peerconnection.addtrack(videotrack); err != nil {
        panic(err)
    } else {
        go func() {
            for {

                buf := make([]byte, 1024*1024)
                var rtcperr error
                if _, _, rtcperr = rtpsender.read(buf); rtcperr != nil {
                    fmt.printf("read error: %v", rtcperr.error())
                    return
                }
            }
        }()
    }

    offer, err := peerconnection.createoffer(nil)
    if err != nil {
        panic(err)
    }
    err = peerconnection.setlocaldescription(offer)
    if err != nil {
        panic(err)
    }

    wait := webrtc.gatheringcompletepromise(peerconnection)
    <-wait

    fmt.printf("local sdp: %v", peerconnection.localdescription().sdp)
}

func newh264localstaticsamplevideotrack(videofile string, fps int) (videotrack *webrtc.tracklocalstaticsample, err error) {
    if videofile == "" {
        err = fmt.errorf("videofile is empty")
        return
    }

    var videofileabs string
    videofileabs, err = filepath.abs(videofile)
    if err != nil {
        return
    }

    _, err = os.stat(videofileabs)
    if err != nil {
        return
    }

    videotrack, err = webrtc.newtracklocalstaticsample(webrtc.rtpcodeccapability{
        mimetype: webrtc.mimetypeh264,
    }, "video", fmt.sprintf("rtckit/%s", uuid.new().string()))
    if err != nil {
        return
    }

    go h264videofileconsumer(videotrack, videofileabs, time.duration(1000/fps)*time.millisecond)

    return
}

func h264videofileconsumer(videotrack *webrtc.tracklocalstaticsample, videofile string, videofps time.duration) {
    for {
        file, h264err := os.open(videofile)
        if h264err != nil {

            continue
        }

        h264, h264err := h264reader.newreader(file)
        if h264err != nil {

            continue
        }

        buf := make(chan []byte, 1024*1024) // 1mb?

        var wg sync.waitgroup

        wg.add(2)
        go func() {
            defer wg.done()
            for data := range buf {
                sample := media.sample{data: data, duration: videofps}

                if h264err1 := videotrack.writesample(sample); h264err1 != nil {

                    continue
                }
            }
        }()

        go func() {
            defer wg.done()
            ticker := time.newticker(videofps)
            for ; true; <-ticker.c {
                nal, h264err := h264.nextnal()
                if h264err == io.eof {

                    break
                }
                if h264err != nil {

                    break
                }

                buf <- nal.data
            }

            close(buf)
        }()

        wg.wait()
        _ = file.close()
    }
}

Das ist das Zitat, das ich bekommen habe:

offer2: v=0
o=- 3976125905671053001 1681720949 IN IP4 0.0.0.0
s=-
t=0 0
a=fingerprint:sha-256 31:A1:C7:4B:05:14:A3:7E:FE:CA:9C:4D:91:F0:29:6C:01:BF:20:67:DF:AA:EA:06:29:A4:DD:3F:F0:AA:5B:BD
a=extmap-allow-mixed
a=group:BUNDLE 0
m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 121 127 120 125 107 108 109 123 118 116
c=IN IP4 0.0.0.0
a=setup:actpass
a=mid:0
a=ice-ufrag:ZjDGAGZtPHgWMfWa
a=ice-pwd:bJJRYUMfPcshoPCHTSfkyfrzwiJIiQkm
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:96 VP8/90000
a=rtcp-fb:96 goog-remb 
a=rtcp-fb:96 ccm fir
a=rtcp-fb:96 nack 
a=rtcp-fb:96 nack pli
a=rtcp-fb:96 nack 
a=rtcp-fb:96 nack pli
a=rtcp-fb:96 transport-cc 
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtcp-fb:97 nack 
a=rtcp-fb:97 nack pli
a=rtcp-fb:97 transport-cc 
a=rtpmap:98 VP9/90000
a=fmtp:98 profile-id=0
a=rtcp-fb:98 goog-remb 
a=rtcp-fb:98 ccm fir
a=rtcp-fb:98 nack 
a=rtcp-fb:98 nack pli
a=rtcp-fb:98 nack 
a=rtcp-fb:98 nack pli
a=rtcp-fb:98 transport-cc 
a=rtpmap:99 rtx/90000
a=fmtp:99 apt=98
a=rtcp-fb:99 nack 
a=rtcp-fb:99 nack pli
a=rtcp-fb:99 transport-cc 
a=rtpmap:100 VP9/90000
a=fmtp:100 profile-id=1
a=rtcp-fb:100 goog-remb 
a=rtcp-fb:100 ccm fir
a=rtcp-fb:100 nack 
a=rtcp-fb:100 nack pli
a=rtcp-fb:100 nack 
a=rtcp-fb:100 nack pli
a=rtcp-fb:100 transport-cc 
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=rtcp-fb:101 nack 
a=rtcp-fb:101 nack pli
a=rtcp-fb:101 transport-cc 
a=rtpmap:102 H264/90000
a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f
a=rtcp-fb:102 goog-remb 
a=rtcp-fb:102 ccm fir
a=rtcp-fb:102 nack 
a=rtcp-fb:102 nack pli
a=rtcp-fb:102 nack 
a=rtcp-fb:102 nack pli
a=rtcp-fb:102 transport-cc 
a=rtpmap:121 rtx/90000
a=fmtp:121 apt=102
a=rtcp-fb:121 nack 
a=rtcp-fb:121 nack pli
a=rtcp-fb:121 transport-cc 
a=rtpmap:127 H264/90000
a=fmtp:127 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f
a=rtcp-fb:127 goog-remb 
a=rtcp-fb:127 ccm fir
a=rtcp-fb:127 nack 
a=rtcp-fb:127 nack pli
a=rtcp-fb:127 nack 
a=rtcp-fb:127 nack pli
a=rtcp-fb:127 transport-cc 
a=rtpmap:120 rtx/90000
a=fmtp:120 apt=127
a=rtcp-fb:120 nack 
a=rtcp-fb:120 nack pli
a=rtcp-fb:120 transport-cc 
a=rtpmap:125 H264/90000
a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
a=rtcp-fb:125 goog-remb 
a=rtcp-fb:125 ccm fir
a=rtcp-fb:125 nack 
a=rtcp-fb:125 nack pli
a=rtcp-fb:125 nack 
a=rtcp-fb:125 nack pli
a=rtcp-fb:125 transport-cc 
a=rtpmap:107 rtx/90000
a=fmtp:107 apt=125
a=rtcp-fb:107 nack 
a=rtcp-fb:107 nack pli
a=rtcp-fb:107 transport-cc 
a=rtpmap:108 H264/90000
a=fmtp:108 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f
a=rtcp-fb:108 goog-remb 
a=rtcp-fb:108 ccm fir
a=rtcp-fb:108 nack 
a=rtcp-fb:108 nack pli
a=rtcp-fb:108 nack 
a=rtcp-fb:108 nack pli
a=rtcp-fb:108 transport-cc 
a=rtpmap:109 rtx/90000
a=fmtp:109 apt=108
a=rtcp-fb:109 nack 
a=rtcp-fb:109 nack pli
a=rtcp-fb:109 transport-cc 
a=rtpmap:123 H264/90000
a=fmtp:123 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640032
a=rtcp-fb:123 goog-remb 
a=rtcp-fb:123 ccm fir
a=rtcp-fb:123 nack 
a=rtcp-fb:123 nack pli
a=rtcp-fb:123 nack 
a=rtcp-fb:123 nack pli
a=rtcp-fb:123 transport-cc 
a=rtpmap:118 rtx/90000
a=fmtp:118 apt=123
a=rtcp-fb:118 nack 
a=rtcp-fb:118 nack pli
a=rtcp-fb:118 transport-cc 
a=rtpmap:116 ulpfec/90000
a=rtcp-fb:116 nack 
a=rtcp-fb:116 nack pli
a=rtcp-fb:116 transport-cc 
a=extmap:1 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=ssrc:554659860 cname:rtckit/53bd9691-40c4-4a58-9165-c7579c4b5031
a=ssrc:554659860 msid:rtckit/53bd9691-40c4-4a58-9165-c7579c4b5031 video
a=ssrc:554659860 mslabel:rtckit/53bd9691-40c4-4a58-9165-c7579c4b5031
a=ssrc:554659860 label:video
a=msid:rtckit/53bd9691-40c4-4a58-9165-c7579c4b5031 video
a=sendrecv
a=candidate:4113284106 1 udp 2130706431 101.4.122.16 41267 typ host
a=candidate:4113284106 2 udp 2130706431 101.4.122.16 41267 typ host
a=candidate:3528925834 1 udp 2130706431 172.18.0.1 33655 typ host
a=candidate:3528925834 2 udp 2130706431 172.18.0.1 33655 typ host
a=candidate:233762139 1 udp 2130706431 172.17.0.1 53508 typ host
a=candidate:233762139 2 udp 2130706431 172.17.0.1 53508 typ host
a=candidate:300762037 1 udp 1694498815 178.173.224.70 56107 typ srflx raddr 0.0.0.0 rport 56107
a=candidate:300762037 2 udp 1694498815 178.173.224.70 56107 typ srflx raddr 0.0.0.0 rport 56107
a=end-of-candidates

Die beste Kombination~

Ich habe versucht, einen Ice-Server in localhost hinzuzufügen und stun:stun.l.google.com:19302 zu verwenden und chatgpt zu fragen, nichts davon hat funktioniert.


Richtige Antwort


Standardmäßig aktiviert Pion keine ICE-TCP-Kandidaten.

Sie können SettingEngine.SetICETCPMux一个>

übergeben

Unter examples/ice-tcp finden Sie vollständige Informationen zu ausgewählten Beispielen für die Verwendung dieser API.

Viel Glück und vielen Dank, dass Sie Pion nutzen!

Das obige ist der detaillierte Inhalt vonWarum generiert pion/webrtc eine Kandidatenliste ohne TCP-Adresse?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Dieser Artikel ist reproduziert unter:stackoverflow.com. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen