fix comment

This commit is contained in:
nareix 2016-07-30 14:36:47 +08:00
parent cb534aa104
commit e90ce45293
4 changed files with 25 additions and 3 deletions

View File

@ -1,5 +1,5 @@
// Package av defines import interfaces and data structures includes container demux/mux and audio encode/decode. // Package av defines basic interfaces and data structures of container demux/mux and audio encode/decode.
package av package av
import ( import (

View File

@ -1,4 +1,5 @@
// Package pktque provides packet Filter interface and structures used by other components.
package pktque package pktque
import ( import (
@ -7,9 +8,11 @@ import (
) )
type Filter interface { type Filter interface {
// Change packet time or drop packet
ModifyPacket(pkt *av.Packet, streams []av.CodecData, videoidx int, audioidx int) (drop bool, err error) ModifyPacket(pkt *av.Packet, streams []av.CodecData, videoidx int, audioidx int) (drop bool, err error)
} }
// Combine multiple Filters into one, ModifyPacket will be called in order.
type Filters []Filter type Filters []Filter
func (self Filters) ModifyPacket(pkt *av.Packet, streams []av.CodecData, videoidx int, audioidx int) (drop bool, err error) { func (self Filters) ModifyPacket(pkt *av.Packet, streams []av.CodecData, videoidx int, audioidx int) (drop bool, err error) {
@ -24,6 +27,7 @@ func (self Filters) ModifyPacket(pkt *av.Packet, streams []av.CodecData, videoid
return return
} }
// Wrap origin Demuxer and Filter into a new Demuxer, when read this Demuxer filters will be called.
type FilterDemuxer struct { type FilterDemuxer struct {
av.Demuxer av.Demuxer
Filter Filter Filter Filter
@ -62,6 +66,7 @@ func (self FilterDemuxer) ReadPacket() (pkt av.Packet, err error) {
return return
} }
// Drop packets until first video key frame arrived.
type WaitKeyFrame struct { type WaitKeyFrame struct {
ok bool ok bool
} }
@ -74,12 +79,13 @@ func (self *WaitKeyFrame) ModifyPacket(pkt *av.Packet, streams []av.CodecData, v
return return
} }
// Fix incorrect packet timestamps.
type FixTime struct { type FixTime struct {
zerobase time.Duration zerobase time.Duration
incrbase time.Duration incrbase time.Duration
lasttime time.Duration lasttime time.Duration
StartFromZero bool StartFromZero bool // make timestamp start from zero
MakeIncrement bool MakeIncrement bool // force timestamp increment
} }
func (self *FixTime) ModifyPacket(pkt *av.Packet, streams []av.CodecData, videoidx int, audioidx int) (drop bool, err error) { func (self *FixTime) ModifyPacket(pkt *av.Packet, streams []av.CodecData, videoidx int, audioidx int) (drop bool, err error) {
@ -105,6 +111,7 @@ func (self *FixTime) ModifyPacket(pkt *av.Packet, streams []av.CodecData, videoi
return return
} }
// Drop incorrect packets to make A/V sync.
type AVSync struct { type AVSync struct {
MaxTimeDiff time.Duration MaxTimeDiff time.Duration
time []time.Duration time []time.Duration
@ -163,6 +170,7 @@ func (self *AVSync) check(i int) (start time.Duration, end time.Duration, correc
return return
} }
// Make packets reading speed as same as walltime, effect like ffmpeg -re option.
type Walltime struct { type Walltime struct {
firsttime time.Time firsttime time.Time
} }

View File

@ -1,3 +1,5 @@
// Packege pubsub implements publisher-subscribers model used in multi-channel streaming.
package pubsub package pubsub
import ( import (
@ -17,6 +19,7 @@ import (
// oldest latest // oldest latest
// //
// One publisher and multiple subscribers thread-safe packet queue buffer.
type Queue struct { type Queue struct {
pkts []av.Packet pkts []av.Packet
head, tail int head, tail int
@ -43,6 +46,7 @@ func NewQueue(streams []av.CodecData) *Queue {
return q return q
} }
// Set max buffered total packets duration.
func (self *Queue) SetMaxDuration(dur time.Duration) { func (self *Queue) SetMaxDuration(dur time.Duration) {
self.lock.Lock() self.lock.Lock()
defer self.lock.Unlock() defer self.lock.Unlock()
@ -55,6 +59,7 @@ func (self *Queue) SetMaxDuration(dur time.Duration) {
return return
} }
// Currently buffered packets total duration.
func (self *Queue) Duration() (dur time.Duration) { func (self *Queue) Duration() (dur time.Duration) {
self.lock.RLock() self.lock.RLock()
defer self.lock.RUnlock() defer self.lock.RUnlock()
@ -65,6 +70,7 @@ func (self *Queue) Duration() (dur time.Duration) {
return return
} }
// After Close() called, all QueueCursor's ReadPacket will return io.EOF.
func (self *Queue) Close() (err error) { func (self *Queue) Close() (err error) {
self.lock.Lock() self.lock.Lock()
defer self.lock.Unlock() defer self.lock.Unlock()
@ -74,6 +80,7 @@ func (self *Queue) Close() (err error) {
return return
} }
// Put packet into buffer, old packets will be discared.
func (self *Queue) WritePacket(pkt av.Packet) (err error) { func (self *Queue) WritePacket(pkt av.Packet) (err error) {
self.lock.Lock() self.lock.Lock()
defer self.lock.Unlock() defer self.lock.Unlock()
@ -101,6 +108,7 @@ func (self *Queue) newCursor() *QueueCursor {
} }
} }
// Create cursor position at latest packet.
func (self *Queue) Latest() *QueueCursor { func (self *Queue) Latest() *QueueCursor {
cursor := self.newCursor() cursor := self.newCursor()
cursor.init = func(pkts []av.Packet, videoidx int) int { cursor.init = func(pkts []av.Packet, videoidx int) int {
@ -109,6 +117,7 @@ func (self *Queue) Latest() *QueueCursor {
return cursor return cursor
} }
// Create cursor position at oldest buffered packet.
func (self *Queue) Oldest() *QueueCursor { func (self *Queue) Oldest() *QueueCursor {
cursor := self.newCursor() cursor := self.newCursor()
cursor.init = func(pkts []av.Packet, videoidx int) int { cursor.init = func(pkts []av.Packet, videoidx int) int {
@ -117,6 +126,7 @@ func (self *Queue) Oldest() *QueueCursor {
return cursor return cursor
} }
// Create cursor position at specific time in buffered packets.
func (self *Queue) DelayedTime(dur time.Duration) *QueueCursor { func (self *Queue) DelayedTime(dur time.Duration) *QueueCursor {
cursor := self.newCursor() cursor := self.newCursor()
cursor.init = func(pkts []av.Packet, videoidx int) int { cursor.init = func(pkts []av.Packet, videoidx int) int {
@ -134,6 +144,7 @@ func (self *Queue) DelayedTime(dur time.Duration) *QueueCursor {
return cursor return cursor
} }
// Create cursor position at specific delayed GOP count in buffered packets.
func (self *Queue) DelayedGopCount(n int) *QueueCursor { func (self *Queue) DelayedGopCount(n int) *QueueCursor {
cursor := self.newCursor() cursor := self.newCursor()
cursor.init = func(pkts []av.Packet, videoidx int) int { cursor.init = func(pkts []av.Packet, videoidx int) int {
@ -159,6 +170,7 @@ func (self *QueueCursor) Streams() (streams []av.CodecData, err error) {
return return
} }
// ReadPacket will not consume packets in Queue, it's just a cursor.
func (self *QueueCursor) ReadPacket() (pkt av.Packet, err error) { func (self *QueueCursor) ReadPacket() (pkt av.Packet, err error) {
self.que.cond.L.Lock() self.que.cond.L.Lock()
if self.pos == -1 { if self.pos == -1 {

View File

@ -1,3 +1,5 @@
// Package transcoder implements Transcoder based on Muxer/Demuxer and AudioEncoder/AudioDecoder interface.
package transcode package transcode
import ( import (