Skip to content

Commit

Permalink
add rtmp UrlMuxer
Browse files Browse the repository at this point in the history
  • Loading branch information
nareix committed Aug 3, 2016
1 parent 4918d07 commit 39d98a7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
16 changes: 15 additions & 1 deletion av/avconv/avconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"
"github.com/nareix/joy4/av/avutil"
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/av/pktque"
"github.com/nareix/joy4/av/transcode"
)

Expand Down Expand Up @@ -123,6 +124,7 @@ func ConvertCmdline(args []string) (err error) {
flagi := false
flagv := false
flagt := false
flagre := false
duration := time.Duration(0)
options := Options{}

Expand All @@ -137,6 +139,9 @@ func ConvertCmdline(args []string) (err error) {
case "-t":
flagt = true

case "-re":
flagre = true

default:
switch {
case flagi:
Expand Down Expand Up @@ -212,9 +217,18 @@ func ConvertCmdline(args []string) (err error) {
return
}

filters := pktque.Filters{}
if flagre {
filters = append(filters, &pktque.Walltime{})
}
filterdemux := &pktque.FilterDemuxer{
Demuxer: convdemux,
Filter: filters,
}

for {
var pkt av.Packet
if pkt, err = convdemux.ReadPacket(); err != nil {
if pkt, err = filterdemux.ReadPacket(); err != nil {
if err == io.EOF {
err = nil
break
Expand Down
8 changes: 8 additions & 0 deletions av/avutil/avutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type RegisterHandler struct {
Ext string
ReaderDemuxer func(io.Reader)av.Demuxer
WriterMuxer func(io.Writer)av.Muxer
UrlMuxer func(string)(bool,av.MuxCloser,error)
UrlDemuxer func(string)(bool,av.DemuxCloser,error)
UrlReader func(string)(bool,io.ReadCloser,error)
Probe func([]byte)bool
Expand Down Expand Up @@ -226,6 +227,13 @@ func (self *Handlers) FindCreate(uri string) (handler RegisterHandler, muxer av.
return
}
}
} else {
if handler.UrlMuxer != nil {
var ok bool
if ok, muxer, err = handler.UrlMuxer(uri); ok {
return
}
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions format/rtmp/rtmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,15 @@ func Handler(h *avutil.RegisterHandler) {
return
}

h.UrlMuxer = func(uri string) (ok bool, muxer av.MuxCloser, err error) {
if !strings.HasPrefix(uri, "rtmp://") {
return
}
ok = true
muxer, err = Dial(uri)
return
}

h.ServerMuxer = func(uri string) (ok bool, muxer av.MuxCloser, err error) {
if !strings.HasPrefix(uri, "rtmp://") {
return
Expand Down

0 comments on commit 39d98a7

Please sign in to comment.