|
|
|
|
@ -23,11 +23,8 @@ type clientVideoProcessor struct {
@@ -23,11 +23,8 @@ type clientVideoProcessor struct {
|
|
|
|
|
onData func(time.Duration, [][]byte) |
|
|
|
|
logger ClientLogger |
|
|
|
|
|
|
|
|
|
trackInitialized bool |
|
|
|
|
queue chan clientVideoProcessorData |
|
|
|
|
sps []byte |
|
|
|
|
pps []byte |
|
|
|
|
clockStartRTC time.Time |
|
|
|
|
queue chan clientVideoProcessorData |
|
|
|
|
clockStartRTC time.Time |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func newClientVideoProcessor( |
|
|
|
|
@ -48,6 +45,16 @@ func newClientVideoProcessor(
@@ -48,6 +45,16 @@ func newClientVideoProcessor(
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (p *clientVideoProcessor) run() error { |
|
|
|
|
track, err := gortsplib.NewTrackH264(96, nil, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err = p.onTrack(track) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for { |
|
|
|
|
select { |
|
|
|
|
case item := <-p.queue: |
|
|
|
|
@ -87,40 +94,7 @@ func (p *clientVideoProcessor) doProcess(
@@ -87,40 +94,7 @@ func (p *clientVideoProcessor) doProcess(
|
|
|
|
|
for _, nalu := range nalus { |
|
|
|
|
typ := h264.NALUType(nalu[0] & 0x1F) |
|
|
|
|
|
|
|
|
|
switch typ { |
|
|
|
|
case h264.NALUTypeSPS: |
|
|
|
|
if p.sps == nil { |
|
|
|
|
p.sps = append([]byte(nil), nalu...) |
|
|
|
|
|
|
|
|
|
if !p.trackInitialized && p.pps != nil { |
|
|
|
|
p.trackInitialized = true |
|
|
|
|
err := p.initializeTrack() |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// remove since it's not needed
|
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
case h264.NALUTypePPS: |
|
|
|
|
if p.pps == nil { |
|
|
|
|
p.pps = append([]byte(nil), nalu...) |
|
|
|
|
|
|
|
|
|
if !p.trackInitialized && p.sps != nil { |
|
|
|
|
p.trackInitialized = true |
|
|
|
|
err := p.initializeTrack() |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// remove since it's not needed
|
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
case h264.NALUTypeAccessUnitDelimiter: |
|
|
|
|
if typ == h264.NALUTypeAccessUnitDelimiter { |
|
|
|
|
// remove since it's not needed
|
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
@ -132,10 +106,6 @@ func (p *clientVideoProcessor) doProcess(
@@ -132,10 +106,6 @@ func (p *clientVideoProcessor) doProcess(
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if !p.trackInitialized { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
p.onData(pts, outNALUs) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
@ -150,12 +120,3 @@ func (p *clientVideoProcessor) process(
@@ -150,12 +120,3 @@ func (p *clientVideoProcessor) process(
|
|
|
|
|
case <-p.ctx.Done(): |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (p *clientVideoProcessor) initializeTrack() error { |
|
|
|
|
track, err := gortsplib.NewTrackH264(96, p.sps, p.pps, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return p.onTrack(track) |
|
|
|
|
} |
|
|
|
|
|