This commit is contained in:
Ingo Oppermann 2022-07-28 18:31:52 +02:00
parent 7098ea1efd
commit 01b5cd703f
38 changed files with 717 additions and 725 deletions

View File

@ -1,4 +1,3 @@
// Package av defines basic interfaces and data structures of 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
@ -294,12 +293,12 @@ type AudioEncoder interface {
CodecData() (AudioCodecData, error) // encoder's codec data can put into container CodecData() (AudioCodecData, error) // encoder's codec data can put into container
Encode(AudioFrame) ([][]byte, error) // encode raw audio frame into compressed pakcet(s) Encode(AudioFrame) ([][]byte, error) // encode raw audio frame into compressed pakcet(s)
Close() // close encoder, free cgo contexts Close() // close encoder, free cgo contexts
SetSampleRate(int) (error) // set encoder sample rate SetSampleRate(int) error // set encoder sample rate
SetChannelLayout(ChannelLayout) (error) // set encoder channel layout SetChannelLayout(ChannelLayout) error // set encoder channel layout
SetSampleFormat(SampleFormat) (error) // set encoder sample format SetSampleFormat(SampleFormat) error // set encoder sample format
SetBitrate(int) (error) // set encoder bitrate SetBitrate(int) error // set encoder bitrate
SetOption(string,interface{}) (error) // encoder setopt, in ffmpeg is av_opt_set_dict() SetOption(string, interface{}) error // encoder setopt, in ffmpeg is av_opt_set_dict()
GetOption(string,interface{}) (error) // encoder getopt GetOption(string, interface{}) error // encoder getopt
} }
// AudioDecoder can decode compressed audio packets into raw audio frame. // AudioDecoder can decode compressed audio packets into raw audio frame.
@ -313,4 +312,3 @@ type AudioDecoder interface {
type AudioResampler interface { type AudioResampler interface {
Resample(AudioFrame) (AudioFrame, error) // convert raw audio frames Resample(AudioFrame) (AudioFrame, error) // convert raw audio frames
} }

View File

@ -2,12 +2,12 @@ package avconv
import ( import (
"fmt" "fmt"
"io"
"time"
"github.com/datarhei/joy4/av/avutil"
"github.com/datarhei/joy4/av" "github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/av/avutil"
"github.com/datarhei/joy4/av/pktque" "github.com/datarhei/joy4/av/pktque"
"github.com/datarhei/joy4/av/transcode" "github.com/datarhei/joy4/av/transcode"
"io"
"time"
) )
var Debug bool var Debug bool
@ -252,4 +252,3 @@ func ConvertCmdline(args []string) (err error) {
return return
} }

View File

@ -1,14 +1,15 @@
package avutil package avutil
import ( import (
"io"
"strings"
"fmt"
"bytes" "bytes"
"github.com/datarhei/joy4/av" "fmt"
"io"
"net/url" "net/url"
"os" "os"
"path" "path"
"strings"
"github.com/datarhei/joy4/av"
) )
type HandlerDemuxer struct { type HandlerDemuxer struct {
@ -108,7 +109,7 @@ func (self *Handlers) NewAudioEncoder(typ av.CodecType) (enc av.AudioEncoder, er
} }
} }
} }
err = fmt.Errorf("avutil: encoder", typ, "not found") err = fmt.Errorf("avutil: encoder %s not found", typ)
return return
} }
@ -120,7 +121,7 @@ func (self *Handlers) NewAudioDecoder(codec av.AudioCodecData) (dec av.AudioDeco
} }
} }
} }
err = fmt.Errorf("avutil: decoder", codec.Type(), "not found") err = fmt.Errorf("avutil: decoder %s not found", codec.Type())
return return
} }

View File

@ -1,10 +1,9 @@
// Package pktque provides packet Filter interface and structures used by other components. // Package pktque provides packet Filter interface and structures used by other components.
package pktque package pktque
import ( import (
"time"
"github.com/datarhei/joy4/av" "github.com/datarhei/joy4/av"
"time"
) )
type Filter interface { type Filter interface {
@ -188,4 +187,3 @@ func (self *Walltime) ModifyPacket(pkt *av.Packet, streams []av.CodecData, video
} }
return return
} }

View File

@ -58,4 +58,3 @@ func (self *Timeline) Pop(dur time.Duration) (tm time.Duration) {
return return
} }

View File

@ -2,11 +2,12 @@
package pubsub package pubsub
import ( import (
"github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/av/pktque"
"io" "io"
"sync" "sync"
"time" "time"
"github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/av/pktque"
) )
// time // time
@ -97,7 +98,6 @@ func (self *Queue) WritePacket(pkt av.Packet) (err error) {
break break
} }
} }
//println("shrink", self.curgopcount, self.maxgopcount, self.buf.Head, self.buf.Tail, "count", self.buf.Count, "size", self.buf.Size)
self.cond.Broadcast() self.cond.Broadcast()

View File

@ -1,12 +1,11 @@
// Package transcoder implements Transcoder based on Muxer/Demuxer and AudioEncoder/AudioDecoder interface. // Package transcoder implements Transcoder based on Muxer/Demuxer and AudioEncoder/AudioDecoder interface.
package transcode package transcode
import ( import (
"fmt" "fmt"
"time"
"github.com/datarhei/joy4/av" "github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/av/pktque" "github.com/datarhei/joy4/av/pktque"
"time"
) )
var Debug bool var Debug bool

View File

@ -1,12 +1,12 @@
package aacparser package aacparser
import ( import (
"github.com/datarhei/joy4/utils/bits"
"github.com/datarhei/joy4/av"
"time"
"fmt"
"bytes" "bytes"
"fmt"
"github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/utils/bits"
"io" "io"
"time"
) )
// copied from libavcodec/mpeg4audio.h // copied from libavcodec/mpeg4audio.h
@ -308,4 +308,3 @@ func NewCodecDataFromMPEG4AudioConfigBytes(config []byte) (self CodecData, err e
} }
return return
} }

View File

@ -61,4 +61,3 @@ func NewSpeexCodecData(sr int, cl av.ChannelLayout) SpeexCodecData {
codec.ChannelLayout_ = cl codec.ChannelLayout_ = cl
return codec return codec
} }

View File

@ -26,4 +26,3 @@ func (self CodecData) ChannelLayout() av.ChannelLayout {
func (self CodecData) SampleRate() int { func (self CodecData) SampleRate() int {
return self.SampleRate_ return self.SampleRate_
} }

View File

@ -1,12 +1,11 @@
package h264parser package h264parser
import ( import (
"bytes"
"fmt"
"github.com/datarhei/joy4/av" "github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/utils/bits" "github.com/datarhei/joy4/utils/bits"
"github.com/datarhei/joy4/utils/bits/pio" "github.com/datarhei/joy4/utils/bits/pio"
"fmt"
"bytes"
) )
const ( const (
@ -740,4 +739,3 @@ func ParseSliceHeaderFromNALU(packet []byte) (sliceType SliceType, err error) {
return return
} }

View File

@ -1,9 +1,8 @@
package h264parser package h264parser
import ( import (
"testing"
"encoding/hex" "encoding/hex"
"testing"
) )
func TestParser(t *testing.T) { func TestParser(t *testing.T) {
@ -20,4 +19,3 @@ func TestParser(t *testing.T) {
nalus, ok = SplitNALUs(avccFrame) nalus, ok = SplitNALUs(avccFrame)
t.Log(ok, len(nalus)) t.Log(ok, len(nalus))
} }

1
doc.go
View File

@ -1,4 +1,3 @@
// Package joy4 is a Golang audio/video library and streaming server. // Package joy4 is a Golang audio/video library and streaming server.
// JOY4 is powerful library written in golang, well-designed interface makes a few lines // JOY4 is powerful library written in golang, well-designed interface makes a few lines
// of code can do a lot of things such as reading, writing, transcoding among // of code can do a lot of things such as reading, writing, transcoding among

View File

@ -1,14 +1,13 @@
package aac package aac
import ( import (
"github.com/datarhei/joy4/av/avutil"
"github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/codec/aacparser"
"time"
"fmt"
"io"
"bufio" "bufio"
"fmt"
"github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/av/avutil"
"github.com/datarhei/joy4/codec/aacparser"
"io"
"time"
) )
type Muxer struct { type Muxer struct {

View File

@ -3,7 +3,6 @@ package flv
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/datarhei/joy4/utils/bits/pio"
"github.com/datarhei/joy4/av" "github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/av/avutil" "github.com/datarhei/joy4/av/avutil"
"github.com/datarhei/joy4/codec" "github.com/datarhei/joy4/codec"
@ -11,6 +10,7 @@ import (
"github.com/datarhei/joy4/codec/fake" "github.com/datarhei/joy4/codec/fake"
"github.com/datarhei/joy4/codec/h264parser" "github.com/datarhei/joy4/codec/h264parser"
"github.com/datarhei/joy4/format/flv/flvio" "github.com/datarhei/joy4/format/flv/flvio"
"github.com/datarhei/joy4/utils/bits/pio"
"io" "io"
) )

View File

@ -1,11 +1,11 @@
package flvio package flvio
import ( import (
"strings"
"math"
"fmt" "fmt"
"time"
"github.com/datarhei/joy4/utils/bits/pio" "github.com/datarhei/joy4/utils/bits/pio"
"math"
"strings"
"time"
) )
type AMF0ParseError struct { type AMF0ParseError struct {
@ -278,7 +278,6 @@ func FillAMF0Val(b []byte, _val interface{}) (n int) {
return return
} }
func ParseAMF0Val(b []byte) (val interface{}, n int, err error) { func ParseAMF0Val(b []byte) (val interface{}, n int, err error) {
return parseAMF0Val(b, 0) return parseAMF0Val(b, 0)
} }
@ -465,4 +464,3 @@ func parseAMF0Val(b []byte, offset int) (val interface{}, n int, err error) {
return return
} }

View File

@ -2,8 +2,8 @@ package flvio
import ( import (
"fmt" "fmt"
"github.com/datarhei/joy4/utils/bits/pio"
"github.com/datarhei/joy4/av" "github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/utils/bits/pio"
"io" "io"
"time" "time"
) )

View File

@ -1,13 +1,13 @@
package format package format
import ( import (
"github.com/datarhei/joy4/av/avutil"
"github.com/datarhei/joy4/format/aac"
"github.com/datarhei/joy4/format/flv"
"github.com/datarhei/joy4/format/mp4" "github.com/datarhei/joy4/format/mp4"
"github.com/datarhei/joy4/format/ts"
"github.com/datarhei/joy4/format/rtmp" "github.com/datarhei/joy4/format/rtmp"
"github.com/datarhei/joy4/format/rtsp" "github.com/datarhei/joy4/format/rtsp"
"github.com/datarhei/joy4/format/flv" "github.com/datarhei/joy4/format/ts"
"github.com/datarhei/joy4/format/aac"
"github.com/datarhei/joy4/av/avutil"
) )
func RegisterAll() { func RegisterAll() {
@ -18,4 +18,3 @@ func RegisterAll() {
avutil.DefaultHandlers.Add(flv.Handler) avutil.DefaultHandlers.Add(flv.Handler)
avutil.DefaultHandlers.Add(aac.Handler) avutil.DefaultHandlers.Add(aac.Handler)
} }

View File

@ -1,9 +1,9 @@
package mp4 package mp4
import ( import (
"io"
"github.com/datarhei/joy4/av" "github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/av/avutil" "github.com/datarhei/joy4/av/avutil"
"io"
) )
var CodecTypes = []av.CodecType{av.H264, av.AAC} var CodecTypes = []av.CodecType{av.H264, av.AAC}
@ -29,4 +29,3 @@ func Handler(h *avutil.RegisterHandler) {
h.CodecTypes = CodecTypes h.CodecTypes = CodecTypes
} }

View File

@ -1,14 +1,13 @@
package main package main
import ( import (
"strings"
"fmt" "fmt"
"os"
"go/ast" "go/ast"
"go/parser" "go/parser"
"go/token"
"go/printer" "go/printer"
"go/token"
"os"
"strings"
) )
func getexprs(e ast.Expr) string { func getexprs(e ast.Expr) string {
@ -1054,4 +1053,3 @@ func main() {
genatoms(os.Args[2], os.Args[3]) genatoms(os.Args[2], os.Args[3])
} }
} }

View File

@ -434,4 +434,3 @@ func tfdt_TrackFragDecodeTime() {
} }
})) }))
} }

View File

@ -1,14 +1,13 @@
package mp4io package mp4io
import ( import (
"github.com/datarhei/joy4/utils/bits/pio"
"os"
"io"
"fmt" "fmt"
"time" "github.com/datarhei/joy4/utils/bits/pio"
"io"
"math" "math"
"os"
"strings" "strings"
"time"
) )
type ParseError struct { type ParseError struct {
@ -500,4 +499,3 @@ func (self *Track) GetElemStreamDesc() (esds *ElemStreamDesc) {
esds, _ = atom.(*ElemStreamDesc) esds, _ = atom.(*ElemStreamDesc)
return return
} }

View File

@ -1,15 +1,15 @@
package mp4 package mp4
import ( import (
"bufio"
"fmt" "fmt"
"time"
"github.com/datarhei/joy4/av" "github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/codec/aacparser" "github.com/datarhei/joy4/codec/aacparser"
"github.com/datarhei/joy4/codec/h264parser" "github.com/datarhei/joy4/codec/h264parser"
"github.com/datarhei/joy4/format/mp4/mp4io" "github.com/datarhei/joy4/format/mp4/mp4io"
"github.com/datarhei/joy4/utils/bits/pio" "github.com/datarhei/joy4/utils/bits/pio"
"io" "io"
"bufio" "time"
) )
type Muxer struct { type Muxer struct {

View File

@ -8,13 +8,13 @@ import (
"encoding/binary" "encoding/binary"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/datarhei/joy4/utils/bits/pio"
"github.com/datarhei/joy4/av" "github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/av/avutil" "github.com/datarhei/joy4/av/avutil"
"github.com/datarhei/joy4/codec" "github.com/datarhei/joy4/codec"
"github.com/datarhei/joy4/codec/aacparser" "github.com/datarhei/joy4/codec/aacparser"
"github.com/datarhei/joy4/codec/h264parser" "github.com/datarhei/joy4/codec/h264parser"
"github.com/datarhei/joy4/format/rtsp/sdp" "github.com/datarhei/joy4/format/rtsp/sdp"
"github.com/datarhei/joy4/utils/bits/pio"
"io" "io"
"net" "net"
"net/textproto" "net/textproto"
@ -1236,4 +1236,3 @@ func Handler(h *avutil.RegisterHandler) {
return return
} }
} }

View File

@ -26,4 +26,3 @@ type Stream struct {
lasttime time.Duration lasttime time.Duration
} }

View File

@ -3,13 +3,13 @@ package ts
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"time"
"github.com/datarhei/joy4/utils/bits/pio"
"github.com/datarhei/joy4/av" "github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/format/ts/tsio"
"github.com/datarhei/joy4/codec/aacparser" "github.com/datarhei/joy4/codec/aacparser"
"github.com/datarhei/joy4/codec/h264parser" "github.com/datarhei/joy4/codec/h264parser"
"github.com/datarhei/joy4/format/ts/tsio"
"github.com/datarhei/joy4/utils/bits/pio"
"io" "io"
"time"
) )
type Demuxer struct { type Demuxer struct {

View File

@ -1,9 +1,9 @@
package ts package ts
import ( import (
"io"
"github.com/datarhei/joy4/av" "github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/av/avutil" "github.com/datarhei/joy4/av/avutil"
"io"
) )
func Handler(h *avutil.RegisterHandler) { func Handler(h *avutil.RegisterHandler) {
@ -23,4 +23,3 @@ func Handler(h *avutil.RegisterHandler) {
h.CodecTypes = CodecTypes h.CodecTypes = CodecTypes
} }

View File

@ -1,9 +1,9 @@
package ts package ts
import ( import (
"time"
"github.com/datarhei/joy4/av" "github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/format/ts/tsio" "github.com/datarhei/joy4/format/ts/tsio"
"time"
) )
type Stream struct { type Stream struct {
@ -24,4 +24,3 @@ type Stream struct {
data []byte data []byte
datalen int datalen int
} }

View File

@ -52,4 +52,3 @@ func calcCRC32(crc uint32, data []byte) uint32 {
} }
return crc return crc
} }

View File

@ -1,11 +1,10 @@
package tsio package tsio
import ( import (
"io"
"time"
"fmt" "fmt"
"github.com/datarhei/joy4/utils/bits/pio" "github.com/datarhei/joy4/utils/bits/pio"
"io"
"time"
) )
const ( const (
@ -587,4 +586,3 @@ func ParseTSHeader(tshdr []byte) (pid uint16, start bool, iskeyframe bool, hdrle
} }
return return
} }

View File

@ -20,4 +20,3 @@ func NewReaderSize(r io.ReadSeeker, size int) *Reader {
func (self *Reader) ReadAt(b []byte, off int64) (n int, err error) { func (self *Reader) ReadAt(b []byte, off int64) (n int, err error) {
return return
} }

View File

@ -1,5 +1,3 @@
package pio package pio
var RecommendBufioSize = 1024 * 64 var RecommendBufioSize = 1024 * 64

View File

@ -1,4 +1,3 @@
package pio package pio
func U8(b []byte) (i uint8) { func U8(b []byte) (i uint8) {
@ -7,85 +6,116 @@ func U8(b []byte) (i uint8) {
func U16BE(b []byte) (i uint16) { func U16BE(b []byte) (i uint16) {
i = uint16(b[0]) i = uint16(b[0])
i <<= 8; i |= uint16(b[1]) i <<= 8
i |= uint16(b[1])
return return
} }
func I16BE(b []byte) (i int16) { func I16BE(b []byte) (i int16) {
i = int16(b[0]) i = int16(b[0])
i <<= 8; i |= int16(b[1]) i <<= 8
i |= int16(b[1])
return return
} }
func I24BE(b []byte) (i int32) { func I24BE(b []byte) (i int32) {
i = int32(int8(b[0])) i = int32(int8(b[0]))
i <<= 8; i |= int32(b[1]) i <<= 8
i <<= 8; i |= int32(b[2]) i |= int32(b[1])
i <<= 8
i |= int32(b[2])
return return
} }
func U24BE(b []byte) (i uint32) { func U24BE(b []byte) (i uint32) {
i = uint32(b[0]) i = uint32(b[0])
i <<= 8; i |= uint32(b[1]) i <<= 8
i <<= 8; i |= uint32(b[2]) i |= uint32(b[1])
i <<= 8
i |= uint32(b[2])
return return
} }
func I32BE(b []byte) (i int32) { func I32BE(b []byte) (i int32) {
i = int32(int8(b[0])) i = int32(int8(b[0]))
i <<= 8; i |= int32(b[1]) i <<= 8
i <<= 8; i |= int32(b[2]) i |= int32(b[1])
i <<= 8; i |= int32(b[3]) i <<= 8
i |= int32(b[2])
i <<= 8
i |= int32(b[3])
return return
} }
func U32LE(b []byte) (i uint32) { func U32LE(b []byte) (i uint32) {
i = uint32(b[3]) i = uint32(b[3])
i <<= 8; i |= uint32(b[2]) i <<= 8
i <<= 8; i |= uint32(b[1]) i |= uint32(b[2])
i <<= 8; i |= uint32(b[0]) i <<= 8
i |= uint32(b[1])
i <<= 8
i |= uint32(b[0])
return return
} }
func U32BE(b []byte) (i uint32) { func U32BE(b []byte) (i uint32) {
i = uint32(b[0]) i = uint32(b[0])
i <<= 8; i |= uint32(b[1]) i <<= 8
i <<= 8; i |= uint32(b[2]) i |= uint32(b[1])
i <<= 8; i |= uint32(b[3]) i <<= 8
i |= uint32(b[2])
i <<= 8
i |= uint32(b[3])
return return
} }
func U40BE(b []byte) (i uint64) { func U40BE(b []byte) (i uint64) {
i = uint64(b[0]) i = uint64(b[0])
i <<= 8; i |= uint64(b[1]) i <<= 8
i <<= 8; i |= uint64(b[2]) i |= uint64(b[1])
i <<= 8; i |= uint64(b[3]) i <<= 8
i <<= 8; i |= uint64(b[4]) i |= uint64(b[2])
i <<= 8
i |= uint64(b[3])
i <<= 8
i |= uint64(b[4])
return return
} }
func U64BE(b []byte) (i uint64) { func U64BE(b []byte) (i uint64) {
i = uint64(b[0]) i = uint64(b[0])
i <<= 8; i |= uint64(b[1]) i <<= 8
i <<= 8; i |= uint64(b[2]) i |= uint64(b[1])
i <<= 8; i |= uint64(b[3]) i <<= 8
i <<= 8; i |= uint64(b[4]) i |= uint64(b[2])
i <<= 8; i |= uint64(b[5]) i <<= 8
i <<= 8; i |= uint64(b[6]) i |= uint64(b[3])
i <<= 8; i |= uint64(b[7]) i <<= 8
i |= uint64(b[4])
i <<= 8
i |= uint64(b[5])
i <<= 8
i |= uint64(b[6])
i <<= 8
i |= uint64(b[7])
return return
} }
func I64BE(b []byte) (i int64) { func I64BE(b []byte) (i int64) {
i = int64(int8(b[0])) i = int64(int8(b[0]))
i <<= 8; i |= int64(b[1]) i <<= 8
i <<= 8; i |= int64(b[2]) i |= int64(b[1])
i <<= 8; i |= int64(b[3]) i <<= 8
i <<= 8; i |= int64(b[4]) i |= int64(b[2])
i <<= 8; i |= int64(b[5]) i <<= 8
i <<= 8; i |= int64(b[6]) i |= int64(b[3])
i <<= 8; i |= int64(b[7]) i <<= 8
i |= int64(b[4])
i <<= 8
i |= int64(b[5])
i <<= 8
i |= int64(b[6])
i <<= 8
i |= int64(b[7])
return return
} }

View File

@ -66,4 +66,3 @@ func VecSlice(in [][]byte, s int, e int) (out [][]byte) {
out = out[:n] out = out[:n]
return return
} }

View File

@ -1,4 +1,3 @@
package pio package pio
import ( import (

View File

@ -1,4 +1,3 @@
package pio package pio
func PutU8(b []byte, v uint8) { func PutU8(b []byte, v uint8) {
@ -86,4 +85,3 @@ func PutI64BE(b []byte, v int64) {
b[6] = byte(v >> 8) b[6] = byte(v >> 8)
b[7] = byte(v) b[7] = byte(v)
} }