Skip to content

Commit

Permalink
fix: rename self
Browse files Browse the repository at this point in the history
  • Loading branch information
halwu(吴浩麟) committed May 29, 2017
1 parent 00771b3 commit ce1c318
Show file tree
Hide file tree
Showing 41 changed files with 921 additions and 961 deletions.
8 changes: 4 additions & 4 deletions av/av.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ type Info struct {
Inter bool
}

func (self Info) IsInterval() bool {
return self.Inter
func (info Info) IsInterval() bool {
return info.Inter
}

func (i Info) String() string {
func (info Info) String() string {
return fmt.Sprintf("<key: %s, URL: %s, UID: %s, Inter: %v>",
i.Key, i.URL, i.UID, i.Inter)
info.Key, info.URL, info.UID, info.Inter)
}

type ReadCloser interface {
Expand Down
34 changes: 17 additions & 17 deletions av/rwbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,35 @@ func NewRWBaser(duration time.Duration) RWBaser {
}
}

func (self *RWBaser) BaseTimeStamp() uint32 {
return self.BaseTimestamp
func (rw *RWBaser) BaseTimeStamp() uint32 {
return rw.BaseTimestamp
}

func (self *RWBaser) CalcBaseTimestamp() {
if self.LastAudioTimestamp > self.LastVideoTimestamp {
self.BaseTimestamp = self.LastAudioTimestamp
func (rw *RWBaser) CalcBaseTimestamp() {
if rw.LastAudioTimestamp > rw.LastVideoTimestamp {
rw.BaseTimestamp = rw.LastAudioTimestamp
} else {
self.BaseTimestamp = self.LastVideoTimestamp
rw.BaseTimestamp = rw.LastVideoTimestamp
}
}

func (self *RWBaser) RecTimeStamp(timestamp, typeID uint32) {
func (rw *RWBaser) RecTimeStamp(timestamp, typeID uint32) {
if typeID == TAG_VIDEO {
self.LastVideoTimestamp = timestamp
rw.LastVideoTimestamp = timestamp
} else if typeID == TAG_AUDIO {
self.LastAudioTimestamp = timestamp
rw.LastAudioTimestamp = timestamp
}
}

func (self *RWBaser) SetPreTime() {
self.lock.Lock()
self.PreTime = time.Now()
self.lock.Unlock()
func (rw *RWBaser) SetPreTime() {
rw.lock.Lock()
rw.PreTime = time.Now()
rw.lock.Unlock()
}

func (self *RWBaser) Alive() bool {
self.lock.Lock()
b := !(time.Now().Sub(self.PreTime) >= self.timeout)
self.lock.Unlock()
func (rw *RWBaser) Alive() bool {
rw.lock.Lock()
b := !(time.Now().Sub(rw.PreTime) >= rw.timeout)
rw.lock.Unlock()
return b
}
4 changes: 2 additions & 2 deletions container/flv/demuxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewDemuxer() *Demuxer {
return &Demuxer{}
}

func (self *Demuxer) DemuxH(p *av.Packet) error {
func (d *Demuxer) DemuxH(p *av.Packet) error {
var tag Tag
_, err := tag.ParseMeidaTagHeader(p.Data, p.IsVideo)
if err != nil {
Expand All @@ -27,7 +27,7 @@ func (self *Demuxer) DemuxH(p *av.Packet) error {
return nil
}

func (self *Demuxer) Demux(p *av.Packet) error {
func (d *Demuxer) Demux(p *av.Packet) error {
var tag Tag
n, err := tag.ParseMeidaTagHeader(p.Data, p.IsVideo)
if err != nil {
Expand Down
39 changes: 18 additions & 21 deletions container/flv/muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import (

var (
flvHeader = []byte{0x46, 0x4c, 0x56, 0x01, 0x05, 0x00, 0x00, 0x00, 0x09}
)

var (
flvFile = flag.String("filFile", "./out.flv", "output flv file name")
flvFile = flag.String("filFile", "./out.flv", "output flv file name")
)

func NewFlv(handler av.Handler, info av.Info) {
Expand Down Expand Up @@ -75,9 +72,9 @@ func NewFLVWriter(app, title, url string, ctx *os.File) *FLVWriter {
return ret
}

func (self *FLVWriter) Write(p av.Packet) error {
self.RWBaser.SetPreTime()
h := self.buf[:headerLen]
func (writer *FLVWriter) Write(p av.Packet) error {
writer.RWBaser.SetPreTime()
h := writer.buf[:headerLen]
typeID := av.TAG_VIDEO
if !p.IsVideo {
if p.IsMetadata {
Expand All @@ -93,8 +90,8 @@ func (self *FLVWriter) Write(p av.Packet) error {
}
dataLen := len(p.Data)
timestamp := p.TimeStamp
timestamp += self.BaseTimeStamp()
self.RWBaser.RecTimeStamp(timestamp, uint32(typeID))
timestamp += writer.BaseTimeStamp()
writer.RWBaser.RecTimeStamp(timestamp, uint32(typeID))

preDataLen := dataLen + headerLen
timestampbase := timestamp & 0xffffff
Expand All @@ -105,37 +102,37 @@ func (self *FLVWriter) Write(p av.Packet) error {
pio.PutI24BE(h[4:7], int32(timestampbase))
pio.PutU8(h[7:8], uint8(timestampExt))

if _, err := self.ctx.Write(h); err != nil {
if _, err := writer.ctx.Write(h); err != nil {
return err
}

if _, err := self.ctx.Write(p.Data); err != nil {
if _, err := writer.ctx.Write(p.Data); err != nil {
return err
}

pio.PutI32BE(h[:4], int32(preDataLen))
if _, err := self.ctx.Write(h[:4]); err != nil {
if _, err := writer.ctx.Write(h[:4]); err != nil {
return err
}

return nil
}

func (self *FLVWriter) Wait() {
func (writer *FLVWriter) Wait() {
select {
case <-self.closed:
case <-writer.closed:
return
}
}

func (self *FLVWriter) Close(error) {
self.ctx.Close()
close(self.closed)
func (writer *FLVWriter) Close(error) {
writer.ctx.Close()
close(writer.closed)
}

func (self *FLVWriter) Info() (ret av.Info) {
ret.UID = self.Uid
ret.URL = self.url
ret.Key = self.app + "/" + self.title
func (writer *FLVWriter) Info() (ret av.Info) {
ret.UID = writer.Uid
ret.URL = writer.url
ret.Key = writer.app + "/" + writer.title
return
}
58 changes: 29 additions & 29 deletions container/flv/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,74 +105,74 @@ type Tag struct {
mediat mediaTag
}

func (self *Tag) SoundFormat() uint8 {
return self.mediat.soundFormat
func (tag *Tag) SoundFormat() uint8 {
return tag.mediat.soundFormat
}

func (self *Tag) AACPacketType() uint8 {
return self.mediat.aacPacketType
func (tag *Tag) AACPacketType() uint8 {
return tag.mediat.aacPacketType
}

func (self *Tag) IsKeyFrame() bool {
return self.mediat.frameType == av.FRAME_KEY
func (tag *Tag) IsKeyFrame() bool {
return tag.mediat.frameType == av.FRAME_KEY
}

func (self *Tag) IsSeq() bool {
return self.mediat.frameType == av.FRAME_KEY &&
self.mediat.avcPacketType == av.AVC_SEQHDR
func (tag *Tag) IsSeq() bool {
return tag.mediat.frameType == av.FRAME_KEY &&
tag.mediat.avcPacketType == av.AVC_SEQHDR
}

func (self *Tag) CodecID() uint8 {
return self.mediat.codecID
func (tag *Tag) CodecID() uint8 {
return tag.mediat.codecID
}

func (self *Tag) CompositionTime() int32 {
return self.mediat.compositionTime
func (tag *Tag) CompositionTime() int32 {
return tag.mediat.compositionTime
}

// ParseMeidaTagHeader, parse video, audio, tag header
func (self *Tag) ParseMeidaTagHeader(b []byte, isVideo bool) (n int, err error) {
func (tag *Tag) ParseMeidaTagHeader(b []byte, isVideo bool) (n int, err error) {
switch isVideo {
case false:
n, err = self.parseAudioHeader(b)
n, err = tag.parseAudioHeader(b)
case true:
n, err = self.parseVideoHeader(b)
n, err = tag.parseVideoHeader(b)
}
return
}

func (self *Tag) parseAudioHeader(b []byte) (n int, err error) {
func (tag *Tag) parseAudioHeader(b []byte) (n int, err error) {
if len(b) < n+1 {
err = fmt.Errorf("invalid audiodata len=%d", len(b))
return
}
flags := b[0]
self.mediat.soundFormat = flags >> 4
self.mediat.soundRate = (flags >> 2) & 0x3
self.mediat.soundSize = (flags >> 1) & 0x1
self.mediat.soundType = flags & 0x1
tag.mediat.soundFormat = flags >> 4
tag.mediat.soundRate = (flags >> 2) & 0x3
tag.mediat.soundSize = (flags >> 1) & 0x1
tag.mediat.soundType = flags & 0x1
n++
switch self.mediat.soundFormat {
switch tag.mediat.soundFormat {
case av.SOUND_AAC:
self.mediat.aacPacketType = b[1]
tag.mediat.aacPacketType = b[1]
n++
}
return
}

func (self *Tag) parseVideoHeader(b []byte) (n int, err error) {
func (tag *Tag) parseVideoHeader(b []byte) (n int, err error) {
if len(b) < n+5 {
err = fmt.Errorf("invalid videodata len=%d", len(b))
return
}
flags := b[0]
self.mediat.frameType = flags >> 4
self.mediat.codecID = flags & 0xf
tag.mediat.frameType = flags >> 4
tag.mediat.codecID = flags & 0xf
n++
if self.mediat.frameType == av.FRAME_INTER || self.mediat.frameType == av.FRAME_KEY {
self.mediat.avcPacketType = b[1]
if tag.mediat.frameType == av.FRAME_INTER || tag.mediat.frameType == av.FRAME_KEY {
tag.mediat.avcPacketType = b[1]
for i := 2; i < 5; i++ {
self.mediat.compositionTime = self.mediat.compositionTime<<8 + int32(b[i])
tag.mediat.compositionTime = tag.mediat.compositionTime<<8 + int32(b[i])
}
n += 4
}
Expand Down
1 change: 0 additions & 1 deletion container/mp4/muxer.go

This file was deleted.

2 changes: 1 addition & 1 deletion container/ts/crc32.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func GenCrc32(src []byte) uint32 {
j := byte(0)
crc32 := uint32(0xFFFFFFFF)
for i := 0; i < len(src); i++ {
j = ((byte(crc32>>24) ^ src[i]) & 0xff)
j = (byte(crc32>>24) ^ src[i]) & 0xff
crc32 = uint32(uint32(crc32<<8) ^ uint32(crcTable[j]))
}

Expand Down
Loading

0 comments on commit ce1c318

Please sign in to comment.