Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 50 additions & 45 deletions av/av.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@

// Package av defines basic interfaces and data structures of container demux/mux and audio encode/decode.
package av

import (
"fmt"
"time"

"github.com/jinleileiking/joy4/common"
)

// Audio sample format.
type SampleFormat uint8

const (
U8 = SampleFormat(iota + 1) // 8-bit unsigned integer
S16 // signed 16-bit integer
S32 // signed 32-bit integer
FLT // 32-bit float
DBL // 64-bit float
U8P // 8-bit unsigned integer in planar
S16P // signed 16-bit integer in planar
S32P // signed 32-bit integer in planar
FLTP // 32-bit float in planar
DBLP // 64-bit float in planar
U32 // unsigned 32-bit integer
U8 = SampleFormat(iota + 1) // 8-bit unsigned integer
S16 // signed 16-bit integer
S32 // signed 32-bit integer
FLT // 32-bit float
DBL // 64-bit float
U8P // 8-bit unsigned integer in planar
S16P // signed 16-bit integer in planar
S32P // signed 32-bit integer in planar
FLTP // 32-bit float in planar
DBLP // 64-bit float in planar
U32 // unsigned 32-bit integer
)

func (self SampleFormat) BytesPerSample() int {
Expand Down Expand Up @@ -116,11 +117,11 @@ func (self ChannelLayout) Count() (n int) {
type CodecType uint32

var (
H264 = MakeVideoCodecType(avCodecTypeMagic + 1)
AAC = MakeAudioCodecType(avCodecTypeMagic + 1)
PCM_MULAW = MakeAudioCodecType(avCodecTypeMagic + 2)
PCM_ALAW = MakeAudioCodecType(avCodecTypeMagic + 3)
SPEEX = MakeAudioCodecType(avCodecTypeMagic + 4)
H264 = MakeVideoCodecType(avCodecTypeMagic + 1)
AAC = MakeAudioCodecType(avCodecTypeMagic + 1)
PCM_MULAW = MakeAudioCodecType(avCodecTypeMagic + 2)
PCM_ALAW = MakeAudioCodecType(avCodecTypeMagic + 3)
SPEEX = MakeAudioCodecType(avCodecTypeMagic + 4)
NELLYMOSER = MakeAudioCodecType(avCodecTypeMagic + 5)
)

Expand Down Expand Up @@ -171,23 +172,23 @@ const avCodecTypeMagic = 233333
// can be converted to VideoCodecData or AudioCodecData using:
//
// codecdata.(AudioCodecData) or codecdata.(VideoCodecData)
//
//
// for H264, CodecData is AVCDecoderConfigure bytes, includes SPS/PPS.
type CodecData interface {
Type() CodecType // Video/Audio codec type
}

type VideoCodecData interface {
CodecData
Width() int // Video height
Width() int // Video height
Height() int // Video width
}

type AudioCodecData interface {
CodecData
SampleFormat() SampleFormat // audio sample format
SampleRate() int // audio sample rate
ChannelLayout() ChannelLayout // audio channel layout
SampleFormat() SampleFormat // audio sample format
SampleRate() int // audio sample rate
ChannelLayout() ChannelLayout // audio channel layout
PacketDuration([]byte) (time.Duration, error) // get audio compressed packet duration
}

Expand All @@ -196,16 +197,16 @@ type PacketWriter interface {
}

type PacketReader interface {
ReadPacket() (Packet,error)
ReadPacket() (Packet, error)
}

// Muxer describes the steps of writing compressed audio/video packets into container formats like MP4/FLV/MPEG-TS.
//
//
// Container formats, rtmp.Conn, and transcode.Muxer implements Muxer interface.
type Muxer interface {
WriteHeader([]CodecData) error // write the file header
PacketWriter // write compressed audio/video packets
WriteTrailer() error // finish writing file, this func can be called only once
PacketWriter // write compressed audio/video packets
WriteTrailer() error // finish writing file, this func can be called only once
}

// Muxer with Close() method
Expand All @@ -216,7 +217,7 @@ type MuxCloser interface {

// Demuxer can read compressed audio/video packets from container formats like MP4/FLV/MPEG-TS.
type Demuxer interface {
PacketReader // read compressed audio/video packets
PacketReader // read compressed audio/video packets
Streams() ([]CodecData, error) // reads the file header, contains video/audio meta infomations
}

Expand All @@ -228,20 +229,25 @@ type DemuxCloser interface {

// Packet stores compressed audio/video data.
type Packet struct {
IsKeyFrame bool // video packet is key frame
Idx int8 // stream index in container format
IsKeyFrame bool // video packet is key frame
Idx int8 // stream index in container format
CompositionTime time.Duration // packet presentation time minus decode time for H264 B-Frame
Timestamp int32
AVCPacketType string
NALUFormat string
NALUInfos []common.TNALUInfo

Time time.Duration // packet decode time
Data []byte // packet data
Data []byte // packet data
}

// Raw audio frame.
type AudioFrame struct {
SampleFormat SampleFormat // audio sample format, e.g: S16,FLTP,...
SampleFormat SampleFormat // audio sample format, e.g: S16,FLTP,...
ChannelLayout ChannelLayout // audio channel layout, e.g: CH_MONO,CH_STEREO,...
SampleCount int // sample count in this frame
SampleRate int // sample rate
Data [][]byte // data array for planar format len(Data) > 1
SampleCount int // sample count in this frame
SampleRate int // sample rate
Data [][]byte // data array for planar format len(Data) > 1
}

func (self AudioFrame) Duration() time.Duration {
Expand Down Expand Up @@ -291,26 +297,25 @@ func (self AudioFrame) Concat(in AudioFrame) (out AudioFrame) {
// AudioEncoder can encode raw audio frame into compressed audio packets.
// cgo/ffmpeg inplements AudioEncoder, using ffmpeg.NewAudioEncoder to create it.
type AudioEncoder interface {
CodecData() (AudioCodecData, error) // encoder's codec data can put into container
Encode(AudioFrame) ([][]byte, error) // encode raw audio frame into compressed pakcet(s)
Close() // close encoder, free cgo contexts
SetSampleRate(int) (error) // set encoder sample rate
SetChannelLayout(ChannelLayout) (error) // set encoder channel layout
SetSampleFormat(SampleFormat) (error) // set encoder sample format
SetBitrate(int) (error) // set encoder bitrate
SetOption(string,interface{}) (error) // encoder setopt, in ffmpeg is av_opt_set_dict()
GetOption(string,interface{}) (error) // encoder getopt
CodecData() (AudioCodecData, error) // encoder's codec data can put into container
Encode(AudioFrame) ([][]byte, error) // encode raw audio frame into compressed pakcet(s)
Close() // close encoder, free cgo contexts
SetSampleRate(int) error // set encoder sample rate
SetChannelLayout(ChannelLayout) error // set encoder channel layout
SetSampleFormat(SampleFormat) error // set encoder sample format
SetBitrate(int) error // set encoder bitrate
SetOption(string, interface{}) error // encoder setopt, in ffmpeg is av_opt_set_dict()
GetOption(string, interface{}) error // encoder getopt
}

// AudioDecoder can decode compressed audio packets into raw audio frame.
// use ffmpeg.NewAudioDecoder to create it.
type AudioDecoder interface {
Decode([]byte) (bool, AudioFrame, error) // decode one compressed audio packet
Close() // close decode, free cgo contexts
Close() // close decode, free cgo contexts
}

// AudioResampler can convert raw audio frames in different sample rate/format/channel layout.
type AudioResampler interface {
Resample(AudioFrame) (AudioFrame, error) // convert raw audio frames
}

8 changes: 4 additions & 4 deletions av/avconv/avconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"io"
"time"
"github.com/nareix/joy4/av/avutil"
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/av/pktque"
"github.com/nareix/joy4/av/transcode"
"github.com/jinleileiking/joy4/av/avutil"
"github.com/jinleileiking/joy4/av"
"github.com/jinleileiking/joy4/av/pktque"
"github.com/jinleileiking/joy4/av/transcode"
)

var Debug bool
Expand Down
2 changes: 1 addition & 1 deletion av/avutil/avutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"fmt"
"bytes"
"github.com/nareix/joy4/av"
"github.com/jinleileiking/joy4/av"
"net/url"
"os"
"path"
Expand Down
2 changes: 1 addition & 1 deletion av/pktque/buf.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pktque

import (
"github.com/nareix/joy4/av"
"github.com/jinleileiking/joy4/av"
)

type Buf struct {
Expand Down
2 changes: 1 addition & 1 deletion av/pktque/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package pktque

import (
"time"
"github.com/nareix/joy4/av"
"github.com/jinleileiking/joy4/av"
)

type Filter interface {
Expand Down
4 changes: 2 additions & 2 deletions av/pubsub/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
package pubsub

import (
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/av/pktque"
"github.com/jinleileiking/joy4/av"
"github.com/jinleileiking/joy4/av/pktque"
"io"
"sync"
"time"
Expand Down
4 changes: 2 additions & 2 deletions av/transcode/transcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package transcode
import (
"fmt"
"time"
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/av/pktque"
"github.com/jinleileiking/joy4/av"
"github.com/jinleileiking/joy4/av/pktque"
)

var Debug bool
Expand Down
6 changes: 3 additions & 3 deletions cgo/ffmpeg/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"runtime"
"fmt"
"time"
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/av/avutil"
"github.com/nareix/joy4/codec/aacparser"
"github.com/jinleileiking/joy4/av"
"github.com/jinleileiking/joy4/av/avutil"
"github.com/jinleileiking/joy4/codec/aacparser"
)

const debug = false
Expand Down
4 changes: 2 additions & 2 deletions cgo/ffmpeg/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"fmt"
"image"
"reflect"
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/codec/h264parser"
"github.com/jinleileiking/joy4/av"
"github.com/jinleileiking/joy4/codec/h264parser"
)

type VideoDecoder struct {
Expand Down
4 changes: 2 additions & 2 deletions codec/aacparser/parser.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package aacparser

import (
"github.com/nareix/joy4/utils/bits"
"github.com/nareix/joy4/av"
"github.com/jinleileiking/joy4/utils/bits"
"github.com/jinleileiking/joy4/av"
"time"
"fmt"
"bytes"
Expand Down
4 changes: 2 additions & 2 deletions codec/codec.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package codec

import (
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/codec/fake"
"github.com/jinleileiking/joy4/av"
"github.com/jinleileiking/joy4/codec/fake"
"time"
)

Expand Down
2 changes: 1 addition & 1 deletion codec/fake/fake.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fake

import (
"github.com/nareix/joy4/av"
"github.com/jinleileiking/joy4/av"
)

type CodecData struct {
Expand Down
Loading