Documentation ¶
Index ¶
- Constants
- Variables
- func CalcCrc32(crc uint32, buf []byte) uint32
- func PackPat() []byte
- func PackPmt(videoCodecId, audioCodecId int) []byte
- type Descriptor
- type DescriptorExtension
- type DescriptorExtensionSupplementaryAudio
- type DescriptorRegistration
- type FileWriter
- type Frame
- type Pat
- type PatProgramElement
- type PatSpecificData
- type Pes
- type Pmt
- type PmtProgramElement
- type PmtSpecificData
- type PsiSection
- type PsiSectionData
- type PsiTableHeader
- type PsiTableSyntaxSection
- type TsPacketAdaptation
- type TsPacketHeader
Constants ¶
const ( PidPat uint16 = 0 PidPmt uint16 = 0x1001 PidVideo uint16 = 0x100 PidAudio uint16 = 0x101 // AdaptationFieldControlReserved ------------------------------------------ // <iso13818-1.pdf> <Table 2-5> <page 38/174> // ------------------------------------------ AdaptationFieldControlReserved uint8 = 0 // Reserved for future use by ISO/IEC AdaptationFieldControlNo uint8 = 1 // No adaptation_field, payload only AdaptationFieldControlOnly uint8 = 2 // Adaptation_field only, no payload AdaptationFieldControlFollowed uint8 = 3 // Adaptation_field followed by payload )
TS Packet Header
const ( // StreamTypeUnknown ... ----------------------------------------------------------------------------- // <iso13818-1.pdf> <Table 2-29 Stream type assignments> <page 66/174> // 0x0F AAC (ISO/IEC 13818-7 Audio with ADTS transport syntax) // 0x1B AVC (video stream as defined in ITU-T Rec. H.264 | ISO/IEC 14496-10 Video) // 0x24 HEVC (HEVC video stream as defined in Rec. ITU-T H.265 | ISO/IEC 23008-2 MPEG-H Part 2) // ----------------------------------------------------------------------------- StreamTypeUnknown uint8 = 0x00 StreamTypePrivate uint8 = 0x06 StreamTypeAac uint8 = 0x0F StreamTypeAvc uint8 = 0x1B StreamTypeHevc uint8 = 0x24 )
PMT
const ( // StreamIdAudio ... ----------------------------------------------------------------- // <iso13818-1.pdf> <Table 2-18-Stream_id assignments> <page 52/174> // ----------------------------------------------------------------- StreamIdAudio uint8 = 192 // 110x xxxx 0xC0 StreamIdVideo uint8 = 224 // 1110 xxxx // PtsDtsFlags0 ------------------------------ // <iso13818-1.pdf> <page 53/174> // ------------------------------ PtsDtsFlags0 uint8 = 0 // no PTS no DTS PtsDtsFlags1 uint8 = 1 // forbidden PtsDtsFlags2 uint8 = 2 // only PTS PtsDtsFlags3 uint8 = 3 // both PTS and DTS )
PES
const ( TsPsiIdPas = 0x00 // program_association_section TsPsiIdCas = 0x01 // conditional_access_section (CA_section) TsPsiIdPms = 0x02 // TS_program_map_section TsPsiIdDs = 0x03 // TS_description_section TsPsiIdSds = 0x04 // ISO_IEC_14496_scene_description_section TsPsiIdOds = 0x05 // ISO_IEC_14496_object_descriptor_section TsPsiIdIso138181Start = 0x06 // ITU-T Rec. H.222.0 | ISO/IEC 13818-1 reserved TsPsiIdIso138181End = 0x37 TsPsiIdIso138186Start = 0x38 // Defined in ISO/IEC 13818-6 TsPsiIdIso138186End = 0x3F TsPsiIdUserStart = 0x40 // User private TsPsiIdUserEnd = 0xFE TsPsiIdForbidden = 0xFF // forbidden )
PsiId
const ( DescriptorTagAC3 = 0x6a DescriptorTagAVCVideo = 0x28 DescriptorTagComponent = 0x50 DescriptorTagContent = 0x54 DescriptorTagDataStreamAlignment = 0x6 DescriptorTagEnhancedAC3 = 0x7a DescriptorTagExtendedEvent = 0x4e DescriptorTagExtension = 0x7f DescriptorTagISO639LanguageAndAudioType = 0xa DescriptorTagLocalTimeOffset = 0x58 DescriptorTagMaximumBitrate = 0xe DescriptorTagNetworkName = 0x40 DescriptorTagParentalRating = 0x55 DescriptorTagPrivateDataIndicator = 0xf DescriptorTagPrivateDataSpecifier = 0x5f DescriptorTagRegistration = 0x5 DescriptorTagService = 0x48 DescriptorTagShortEvent = 0x4d DescriptorTagStreamIdentifier = 0x52 DescriptorTagSubtitling = 0x59 DescriptorTagTeletext = 0x56 DescriptorTagVBIData = 0x45 DescriptorTagVBITeletext = 0x46 )
Variables ¶
var Log = nazalog.GetGlobalLogger()
Functions ¶
Types ¶
type Descriptor ¶
type Descriptor struct { Length uint8 Tag uint8 Registration DescriptorRegistration Extension DescriptorExtension }
type DescriptorExtension ¶
type DescriptorExtension struct { SupplementaryAudio DescriptorExtensionSupplementaryAudio Tag uint8 Unknown []byte }
type DescriptorRegistration ¶
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
func (*FileWriter) Create ¶
func (fw *FileWriter) Create(filename string) (err error)
func (*FileWriter) Dispose ¶
func (fw *FileWriter) Dispose() error
func (*FileWriter) Name ¶
func (fw *FileWriter) Name() string
func (*FileWriter) Write ¶
func (fw *FileWriter) Write(b []byte) (err error)
type Frame ¶
type Frame struct { Pts uint64 // =(毫秒 * 90) Cts uint32 Dts uint64 Cc uint8 // continuity_counter of TS Header // PID of PES Header // 音频 mpegts.PidAudio // 视频 mpegts.PidVideo Pid uint16 // stream_id of PES Header // 音频 mpegts.StreamIdAudio // 视频 mpegts.StreamIdVideo Sid uint8 // 音频 全部为false // 视频 关键帧为true,非关键帧为false Key bool // 音频AAC 格式为2字节ADTS头加raw frame // 视频AVC 格式为Annexb Raw []byte }
Frame 帧数据,用于打包成mpegts格式的数据
func (*Frame) DebugString ¶
type Pat ¶
type Pat struct {
// contains filtered or unexported fields
}
Pat --------------------------------------------------------------------------------------------------- Program association section <iso13818-1.pdf> <2.4.4.3> <page 61/174> table_id [8b] * section_syntax_indicator [1b] '0' [1b] reserved [2b] section_length [12b] ** transport_stream_id [16b] ** reserved [2b] version_number [5b] current_next_indicator [1b] * section_number [8b] * last_section_number [8b] * -----loop----- program_number [16b] ** reserved [3b] program_map_PID [13b] ** if program_number == 0 then network_PID else then program_map_PID -------------- CRC_32 [32b] **** ---------------------------------------------------------------------------------------------------
type PatProgramElement ¶
type PatProgramElement struct {
// contains filtered or unexported fields
}
type PatSpecificData ¶
type PatSpecificData struct {
// contains filtered or unexported fields
}
type Pes ¶
type Pes struct {
// contains filtered or unexported fields
}
Pes ----------------------------------------------------------- <iso13818-1.pdf> <2.4.3.6 PES packet> <page 49/174> <Table E.1 - PES packet header example> <page 142/174> <F.0.2 PES packet> <page 144/174> packet_start_code_prefix [24b] *** always 0x00, 0x00, 0x01 stream_id [8b] * PES_packet_length [16b] ** '10' [2b] PES_scrambling_control [2b] PES_priority [1b] data_alignment_indicator [1b] copyright [1b] original_or_copy [1b] * PTS_DTS_flags [2b] ESCR_flag [1b] ES_rate_flag [1b] DSM_trick_mode_flag [1b] additional_copy_info_flag [1b] PES_CRC_flag [1b] PES_extension_flag [1b] * PES_header_data_length [8b] * -----------------------------------------------------------
type Pmt ¶
type Pmt struct { ProgramElements []PmtProgramElement // contains filtered or unexported fields }
Pmt
---------------------------------------- Program Map Table <iso13818-1.pdf> <2.4.4.8> <page 64/174> table_id [8b] * section_syntax_indicator [1b] 0 [1b] reserved [2b] section_length [12b] ** program_number [16b] ** reserved [2b] version_number [5b] current_next_indicator [1b] * section_number [8b] * last_section_number [8b] * reserved [3b] PCR_PID [13b] ** reserved [4b] program_info_length [12b] ** -----loop----- stream_type [8b] * reserved [3b] elementary_PID [13b] ** reserved [4b] ES_info_length_length [12b] ** -------------- CRC32 [32b] **** ----------------------------------------
func (*Pmt) SearchPid ¶
func (pmt *Pmt) SearchPid(pid uint16) *PmtProgramElement
type PmtProgramElement ¶
type PmtProgramElement struct { StreamType uint8 Pid uint16 Length uint16 Descriptors []Descriptor }
type PmtSpecificData ¶
type PmtSpecificData struct {
// contains filtered or unexported fields
}
type PsiSection ¶
type PsiSection struct {
// contains filtered or unexported fields
}
func NewPsi ¶
func NewPsi() *PsiSection
func (*PsiSection) Pack ¶
func (psi *PsiSection) Pack() (int, []byte)
type PsiSectionData ¶
type PsiSectionData struct {
// contains filtered or unexported fields
}
type PsiTableHeader ¶
type PsiTableHeader struct {
// contains filtered or unexported fields
}
type PsiTableSyntaxSection ¶
type PsiTableSyntaxSection struct {
// contains filtered or unexported fields
}
type TsPacketAdaptation ¶
type TsPacketAdaptation struct {
Length uint8
}
TsPacketAdaptation ---------------------------------------------------------- <iso13818-1.pdf> <Table 2-6> <page 40/174> adaptation_field_length [8b] * 不包括自己这1字节 discontinuity_indicator [1b] random_access_indicator [1b] elementary_stream_priority_indicator [1b] PCR_flag [1b] OPCR_flag [1b] splicing_point_flag [1b] transport_private_data_flag [1b] adaptation_field_extension_flag [1b] * -----if PCR_flag == 1----- program_clock_reference_base [33b] reserved [6b] program_clock_reference_extension [9b] ****** ----------------------------------------------------------
func ParseTsPacketAdaptation ¶
func ParseTsPacketAdaptation(b []byte) (f TsPacketAdaptation)
ParseTsPacketAdaptation TODO chef
type TsPacketHeader ¶
type TsPacketHeader struct { Sync uint8 Err uint8 PayloadUnitStart uint8 Prio uint8 Pid uint16 Scra uint8 Adaptation uint8 Cc uint8 }
TsPacketHeader ------------------------------------------------ <iso13818-1.pdf> <2.4.3.2> <page 36/174> sync_byte [8b] * always 0x47 transport_error_indicator [1b] payload_unit_start_indicator [1b] transport_priority [1b] PID [13b] ** transport_scrambling_control [2b] adaptation_field_control [2b] continuity_counter [4b] * ------------------------------------------------
func ParseTsPacketHeader ¶
func ParseTsPacketHeader(b []byte) (h TsPacketHeader)
ParseTsPacketHeader 解析4字节TS Packet header