Rewrite stream info API
This commit is contained in:
+10
-7
@@ -4,13 +4,16 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
JSONType = "type"
|
||||
JSONRemoteAddr = "remote_addr"
|
||||
JSONUserAgent = "user_agent"
|
||||
JSONReceive = "receive"
|
||||
JSONSend = "send"
|
||||
)
|
||||
type Info struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
RemoteAddr string `json:"remote_addr,omitempty"`
|
||||
UserAgent string `json:"user_agent,omitempty"`
|
||||
Medias []*Media `json:"medias,omitempty"`
|
||||
Tracks []*Track `json:"tracks,omitempty"`
|
||||
Recv uint32 `json:"recv,omitempty"`
|
||||
Send uint32 `json:"send,omitempty"`
|
||||
}
|
||||
|
||||
func Between(s, sub1, sub2 string) string {
|
||||
i := strings.Index(s, sub1)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package streamer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pion/sdp/v3"
|
||||
"strconv"
|
||||
@@ -70,6 +71,10 @@ func (m *Media) String() string {
|
||||
return s
|
||||
}
|
||||
|
||||
func (m *Media) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(m.String())
|
||||
}
|
||||
|
||||
func (m *Media) Clone() *Media {
|
||||
clone := *m
|
||||
return &clone
|
||||
|
||||
+11
-3
@@ -1,6 +1,7 @@
|
||||
package streamer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pion/rtp"
|
||||
"sync"
|
||||
@@ -22,12 +23,19 @@ func NewTrack(codec *Codec, direction string) *Track {
|
||||
|
||||
func (t *Track) String() string {
|
||||
s := t.Codec.String()
|
||||
t.sinkMu.RLock()
|
||||
s += fmt.Sprintf(", sinks=%d", len(t.sink))
|
||||
t.sinkMu.RUnlock()
|
||||
if t.sinkMu.TryRLock() {
|
||||
s += fmt.Sprintf(", sinks=%d", len(t.sink))
|
||||
t.sinkMu.RUnlock()
|
||||
} else {
|
||||
s += fmt.Sprintf(", sinks=?")
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (t *Track) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(t.String())
|
||||
}
|
||||
|
||||
func (t *Track) WriteRTP(p *rtp.Packet) error {
|
||||
t.sinkMu.RLock()
|
||||
for _, f := range t.sink {
|
||||
|
||||
Reference in New Issue
Block a user