mpeg2

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TS_TID_PAS       PAT_TID = 0x00 // program_association_section
	TS_TID_CAS               = 0x01 // conditional_access_section(CA_section)
	TS_TID_PMS               = 0x02 // TS_program_map_section
	TS_TID_SDS               = 0x03 //TS_description_section
	TS_TID_FORBIDDEN PAT_TID = 0xFF
)
View Source
const (
	TS_PAKCET_SIZE = 188
)

Variables

View Source
var H264_AUD_NALU []byte = []byte{0x00, 0x00, 0x00, 0x01, 0x09, 0xF0} //ffmpeg mpegtsenc.c mpegts_write_packet_internal
View Source
var H265_AUD_NALU []byte = []byte{0x00, 0x00, 0x00, 0x01, 0x46, 0x01, 0x50}

Functions

func NewPESStream

func NewPESStream(pid uint16, cid TS_STREAM_TYPE) *pes_stream

func NewTablePat

func NewTablePat() *table_pat

func NewTablePmt

func NewTablePmt() *table_pmt

func ReadSection

func ReadSection(sectionType PAT_TID, bs *codec.BitStream) (interface{}, error)

Types

type Adaptation_field

type Adaptation_field struct {
	SingleStuffingByte                         bool   // The value 0 is for inserting a single stuffing byte in a Transport Stream packet
	Adaptation_field_length                    uint8  //8   uimsbf
	Discontinuity_indicator                    uint8  //1   bslbf
	Random_access_indicator                    uint8  //1   bslbf
	Elementary_stream_priority_indicator       uint8  //1   bslbf
	PCR_flag                                   uint8  //1   bslbf
	OPCR_flag                                  uint8  //1   bslbf
	Splicing_point_flag                        uint8  //1   bslbf
	Transport_private_data_flag                uint8  //1   bslbf
	Adaptation_field_extension_flag            uint8  //1   bslbf
	Program_clock_reference_base               uint64 //33  uimsbf
	Program_clock_reference_extension          uint16 //9   uimsbf
	Original_program_clock_reference_base      uint64 //33  uimsbf
	Original_program_clock_reference_extension uint16 //9   uimsbf
	Splice_countdown                           uint8  //8   uimsbf
	Transport_private_data_length              uint8  //8   uimsbf
	Adaptation_field_extension_length          uint8  //8   uimsbf
	Ltw_flag                                   uint8  //1   bslbf
	Piecewise_rate_flag                        uint8  //1   bslbf
	Seamless_splice_flag                       uint8  //1   bslbf
	Ltw_valid_flag                             uint8  //1   bslbf
	Ltw_offset                                 uint16 //15  uimsbf
	Piecewise_rate                             uint32 //22  uimsbf
	Splice_type                                uint8  //4   uimsbf
	DTS_next_AU                                uint64
	Stuffing_byte                              uint8
}

func (*Adaptation_field) Decode

func (adaptation *Adaptation_field) Decode(bs *codec.BitStream) error

func (*Adaptation_field) Encode

func (adaptation *Adaptation_field) Encode(bsw *codec.BitStreamWriter)

func (*Adaptation_field) PrettyPrint

func (adaptation *Adaptation_field) PrettyPrint(file *os.File)

type CommonPesPacket

type CommonPesPacket struct {
	Stream_id         uint8
	PES_packet_length uint16
}

func (*CommonPesPacket) Decode

func (compes *CommonPesPacket) Decode(bs *codec.BitStream) error

type Display

type Display interface {
	PrettyPrint(file *os.File)
}

type Elementary_Stream

type Elementary_Stream struct {
	Stream_id                uint8
	P_STD_buffer_bound_scale uint8
	P_STD_buffer_size_bound  uint16
}

func NewElementary_Stream

func NewElementary_Stream(sid uint8) *Elementary_Stream

type Elementary_stream_elem

type Elementary_stream_elem struct {
	Stream_type                   uint8
	Elementary_stream_id          uint8
	Elementary_stream_info_length uint16
}

func NewElementary_stream_elem

func NewElementary_stream_elem(stype uint8, esid uint8) *Elementary_stream_elem

type Error

type Error interface {
	NeedMore() bool
	ParserError() bool
	StreamIdNotFound() bool
}

type PAT_TID

type PAT_TID int

Table id

type PES_STREMA_ID

type PES_STREMA_ID int
const (
	PES_STREAM_END         PES_STREMA_ID = 0xB9
	PES_STREAM_START       PES_STREMA_ID = 0xBA
	PES_STREAM_SYSTEM_HEAD PES_STREMA_ID = 0xBB
	PES_STREAM_MAP         PES_STREMA_ID = 0xBC
	PES_STREAM_PRIVATE     PES_STREMA_ID = 0xBD
	PES_STREAM_AUDIO       PES_STREMA_ID = 0xC0
	PES_STREAM_VIDEO       PES_STREMA_ID = 0xE0
)

type PSDemuxer

type PSDemuxer struct {
	OnFrame func(frame []byte, cid PS_STREAM_TYPE, pts uint64, dts uint64)
	//解ps包过程中,解码回调psm,system header,pes包等
	//decodeResult 解码ps包时的产生的错误
	//这个回调主要用于debug,查看是否ps包存在问题
	OnPacket func(pkg Display, decodeResult error)
	// contains filtered or unexported fields
}

func NewPSDemuxer

func NewPSDemuxer() *PSDemuxer

func (*PSDemuxer) Flush

func (psdemuxer *PSDemuxer) Flush()

func (*PSDemuxer) Input

func (psdemuxer *PSDemuxer) Input(data []byte) error

type PSMuxer

type PSMuxer struct {
	OnPacket func(pkg []byte)
	// contains filtered or unexported fields
}

func NewPsMuxer

func NewPsMuxer() *PSMuxer

func (*PSMuxer) AddStream

func (muxer *PSMuxer) AddStream(cid PS_STREAM_TYPE) uint8

func (*PSMuxer) Write

func (muxer *PSMuxer) Write(sid uint8, frame []byte, pts uint64, dts uint64) error

type PSPackHeader

type PSPackHeader struct {
	IsMpeg1                          bool
	System_clock_reference_base      uint64 //33 bits
	System_clock_reference_extension uint16 //9 bits
	Program_mux_rate                 uint32 //22 bits
	Pack_stuffing_length             uint8  //3 bitss
}

func (*PSPackHeader) Decode

func (ps_pkg_hdr *PSPackHeader) Decode(bs *codec.BitStream) error

func (*PSPackHeader) Encode

func (ps_pkg_hdr *PSPackHeader) Encode(bsw *codec.BitStreamWriter)

func (*PSPackHeader) PrettyPrint

func (ps_pkg_hdr *PSPackHeader) PrettyPrint(file *os.File)

type PSPacket

type PSPacket struct {
	Header  *PSPackHeader
	System  *System_header
	Psm     *Program_stream_map
	Psd     *Program_stream_directory
	CommPes *CommonPesPacket
	Pes     *PesPacket
}

type PS_STREAM_TYPE

type PS_STREAM_TYPE int
const (
	PS_STREAM_UNKNOW PS_STREAM_TYPE = 0xFF
	PS_STREAM_AAC    PS_STREAM_TYPE = 0x0F
	PS_STREAM_H264   PS_STREAM_TYPE = 0x1B
	PS_STREAM_H265   PS_STREAM_TYPE = 0x24
	PS_STREAM_G711A  PS_STREAM_TYPE = 0x90
	PS_STREAM_G711U  PS_STREAM_TYPE = 0x91
)

type Pat

type Pat struct {
	Table_id                 uint8  //8  uimsbf
	Section_syntax_indicator uint8  //1  bslbf
	Section_length           uint16 //12 uimsbf
	Transport_stream_id      uint16 //16 uimsbf
	Version_number           uint8  //5  uimsbf
	Current_next_indicator   uint8  //1  bslbf
	Section_number           uint8  //8  uimsbf
	Last_section_number      uint8  //8  uimsbf
	Pmts                     []PmtPair
}

func NewPat

func NewPat() *Pat

func (*Pat) Decode

func (pat *Pat) Decode(bs *codec.BitStream) error

func (*Pat) Encode

func (pat *Pat) Encode(bsw *codec.BitStreamWriter)

func (*Pat) PrettyPrint

func (pat *Pat) PrettyPrint(file *os.File)

type PesPacket

type PesPacket struct {
	Stream_id                 uint8
	PES_packet_length         uint16
	PES_scrambling_control    uint8
	PES_priority              uint8
	Data_alignment_indicator  uint8
	Copyright                 uint8
	Original_or_copy          uint8
	PTS_DTS_flags             uint8
	ESCR_flag                 uint8
	ES_rate_flag              uint8
	DSM_trick_mode_flag       uint8
	Additional_copy_info_flag uint8
	PES_CRC_flag              uint8
	PES_extension_flag        uint8
	PES_header_data_length    uint8
	Pts                       uint64
	Dts                       uint64
	ESCR_base                 uint64
	ESCR_extension            uint16
	ES_rate                   uint32
	Trick_mode_control        uint8
	Trick_value               uint8
	Additional_copy_info      uint8
	Previous_PES_packet_CRC   uint16
	Pes_payload               []byte
}

func NewPesPacket

func NewPesPacket() *PesPacket

func (*PesPacket) Decode

func (pkg *PesPacket) Decode(bs *codec.BitStream) error

func (*PesPacket) DecodeMpeg1

func (pkg *PesPacket) DecodeMpeg1(bs *codec.BitStream) error

func (*PesPacket) Encode

func (pkg *PesPacket) Encode(bsw *codec.BitStreamWriter)

func (*PesPacket) PrettyPrint

func (pkg *PesPacket) PrettyPrint(file *os.File)

type Pmt

type Pmt struct {
	Table_id                 uint8  //8  uimsbf
	Section_syntax_indicator uint8  //1  bslbf
	Section_length           uint16 //12 uimsbf
	Program_number           uint16 //16 uimsbf
	Version_number           uint8  //5  uimsbf
	Current_next_indicator   uint8  //1  bslbf
	Section_number           uint8  //8  uimsbf
	Last_section_number      uint8  //8  uimsbf
	PCR_PID                  uint16 //13 uimsbf
	Program_info_length      uint16 //12 uimsbf
	Streams                  []StreamPair
}

func NewPmt

func NewPmt() *Pmt

func (*Pmt) Decode

func (pmt *Pmt) Decode(bs *codec.BitStream) error

func (*Pmt) Encode

func (pmt *Pmt) Encode(bsw *codec.BitStreamWriter)

func (*Pmt) PrettyPrint

func (pmt *Pmt) PrettyPrint(file *os.File)

type PmtPair

type PmtPair struct {
	Program_number uint16
	PID            uint16
}

type Program_stream_directory

type Program_stream_directory struct {
	PES_packet_length uint16
}

func (*Program_stream_directory) Decode

func (psd *Program_stream_directory) Decode(bs *codec.BitStream) error

type Program_stream_map

type Program_stream_map struct {
	Map_stream_id                uint8
	Program_stream_map_length    uint16
	Current_next_indicator       uint8
	Program_stream_map_version   uint8
	Program_stream_info_length   uint16
	Elementary_stream_map_length uint16
	Stream_map                   []*Elementary_stream_elem
}

func (*Program_stream_map) Decode

func (psm *Program_stream_map) Decode(bs *codec.BitStream) error

func (*Program_stream_map) Encode

func (psm *Program_stream_map) Encode(bsw *codec.BitStreamWriter)

func (*Program_stream_map) PrettyPrint

func (psm *Program_stream_map) PrettyPrint(file *os.File)

type StreamPair

type StreamPair struct {
	StreamType     uint8  //8 uimsbf
	Elementary_PID uint16 //13 uimsbf
	ES_Info_Length uint16 //12 uimsbf
}

type System_header

type System_header struct {
	Header_length                uint16
	Rate_bound                   uint32
	Audio_bound                  uint8
	Fixed_flag                   uint8
	CSPS_flag                    uint8
	System_audio_lock_flag       uint8
	System_video_lock_flag       uint8
	Video_bound                  uint8
	Packet_rate_restriction_flag uint8
	Streams                      []*Elementary_Stream
}

func (*System_header) Decode

func (sh *System_header) Decode(bs *codec.BitStream) error

func (*System_header) Encode

func (sh *System_header) Encode(bsw *codec.BitStreamWriter)

func (*System_header) PrettyPrint

func (sh *System_header) PrettyPrint(file *os.File)

type TSDemuxer

type TSDemuxer struct {
	OnFrame    func(cid TS_STREAM_TYPE, frame []byte, pts uint64, dts uint64)
	OnTSPacket func(pkg *TSPacket)
	// contains filtered or unexported fields
}

func NewTSDemuxer

func NewTSDemuxer() *TSDemuxer

func (*TSDemuxer) Input

func (demuxer *TSDemuxer) Input(r io.Reader) error

type TSMuxer

type TSMuxer struct {
	OnPacket func(pkg []byte)
	// contains filtered or unexported fields
}

func NewTSMuxer

func NewTSMuxer() *TSMuxer

func (*TSMuxer) AddStream

func (mux *TSMuxer) AddStream(cid TS_STREAM_TYPE) uint16

func (*TSMuxer) Write

func (mux *TSMuxer) Write(pid uint16, data []byte, pts uint64, dts uint64) error

/ Muxer audio/video stream data / pid: stream id by AddStream / pts: audio/video stream timestamp in ms / dts: audio/video stream timestamp in ms

type TSPacket

type TSPacket struct {
	Transport_error_indicator    uint8
	Payload_unit_start_indicator uint8
	Transport_priority           uint8
	PID                          uint16
	Transport_scrambling_control uint8
	Adaptation_field_control     uint8
	Continuity_counter           uint8
	Field                        *Adaptation_field
	Payload                      interface{}
}

func (*TSPacket) DecodeHeader

func (pkg *TSPacket) DecodeHeader(bs *codec.BitStream) error

func (*TSPacket) EncodeHeader

func (pkg *TSPacket) EncodeHeader(bsw *codec.BitStreamWriter)

func (*TSPacket) PrettyPrint

func (pkg *TSPacket) PrettyPrint(file *os.File)

type TS_PID

type TS_PID int

PID

const (
	TS_PID_PAT TS_PID = 0x0000
	TS_PID_CAT
	TS_PID_TSDT
	TS_PID_IPMP
	TS_PID_Nil = 0x1FFF
)

type TS_STREAM_TYPE

type TS_STREAM_TYPE int
const (
	TS_STREAM_AUDIO_MPEG1 TS_STREAM_TYPE = 0x03
	TS_STREAM_AUDIO_MPEG2 TS_STREAM_TYPE = 0x04
	TS_STREAM_AAC         TS_STREAM_TYPE = 0x0F
	TS_STREAM_H264        TS_STREAM_TYPE = 0x1B
	TS_STREAM_H265        TS_STREAM_TYPE = 0x24
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL