more smart handling of another packat index (audio, as example)
This commit is contained in:
parent
0435cfa11a
commit
4f6b86b297
@ -14,8 +14,9 @@ import (
|
||||
var CodecTypes = []av.CodecType{av.H264, av.AAC}
|
||||
|
||||
type Muxer struct {
|
||||
w io.Writer
|
||||
streams []*Stream
|
||||
w io.Writer
|
||||
streams map[int]*Stream
|
||||
|
||||
PaddingToMakeCounterCont bool
|
||||
|
||||
psidata []byte
|
||||
@ -42,7 +43,7 @@ func NewMuxer(w io.Writer) *Muxer {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Muxer) newStream(codec av.CodecData) (err error) {
|
||||
func (self *Muxer) newStream(idx int, codec av.CodecData) (err error) {
|
||||
ok := false
|
||||
for _, c := range CodecTypes {
|
||||
if codec.Type() == c {
|
||||
@ -55,14 +56,14 @@ func (self *Muxer) newStream(codec av.CodecData) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
pid := uint16(len(self.streams) + 0x100)
|
||||
pid := uint16(idx + 0x100)
|
||||
stream := &Stream{
|
||||
muxer: self,
|
||||
CodecData: codec,
|
||||
pid: pid,
|
||||
tsw: tsio.NewTSWriter(pid),
|
||||
}
|
||||
self.streams = append(self.streams, stream)
|
||||
self.streams[idx] = stream
|
||||
return
|
||||
}
|
||||
|
||||
@ -140,10 +141,11 @@ func (self *Muxer) WritePATPMT() (err error) {
|
||||
}
|
||||
|
||||
func (self *Muxer) WriteHeader(streams []av.CodecData) (err error) {
|
||||
self.streams = []*Stream{}
|
||||
for _, stream := range streams {
|
||||
if err = self.newStream(stream); err != nil {
|
||||
return
|
||||
self.streams = map[int]*Stream{}
|
||||
|
||||
for idx, stream := range streams {
|
||||
if err = self.newStream(idx, stream); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,10 +156,14 @@ func (self *Muxer) WriteHeader(streams []av.CodecData) (err error) {
|
||||
}
|
||||
|
||||
func (self *Muxer) WritePacket(pkt av.Packet) (err error) {
|
||||
if int(pkt.Idx) >= len(self.streams) {
|
||||
return fmt.Errorf("Wrong stream index: %d", pkt.Idx)
|
||||
var stream *Stream = nil
|
||||
|
||||
stream, ok := self.streams[int(pkt.Idx)]
|
||||
if !ok {
|
||||
fmt.Printf("Warning, unsupported stream index: %d\n", pkt.Idx)
|
||||
return
|
||||
}
|
||||
stream := self.streams[pkt.Idx]
|
||||
|
||||
pkt.Time += time.Second
|
||||
|
||||
switch stream.Type() {
|
||||
|
Loading…
Reference in New Issue
Block a user