Documentation
¶
Index ¶
- func AVPacketBytes(pktPtr uintptr) []byte
- func DecoderCodecName(handle uintptr) string
- func DecoderFrameIsKey(framePtr uintptr) bool
- func DecoderFree(handle uintptr)
- func DecoderInit(url, rtspTransport, platform, httpHeaders string) (uintptr, error)
- func DecoderNextFrame(handle uintptr) (uintptr, error)
- func DecoderStreamInfo(handle uintptr) (fps float64, width, height int)
- func DecoderTimeBase(handle uintptr) (num, den int)
- func EncoderCodecCtx(handle uintptr) uintptr
- func EncoderDrain(handle uintptr)
- func EncoderFrameCount(handle uintptr) int64
- func EncoderFree(handle uintptr)
- func EncoderGetFPS(handle uintptr) int
- func EncoderInit(codecName string, width, height, bitrateKbps, fps, iframeIntervalMS int, ...) (uintptr, error)
- func EncoderResetPTSState(handle uintptr)
- func EncoderSetBitrate(handle uintptr, bitrateKbps int) error
- func EncoderSetFrameCount(handle uintptr, count int64)
- func EncoderSetFramerate(handle uintptr, fps int) error
- func EncoderSetInputTimeBase(handle uintptr, num, den int)
- func FramePTS(framePtr uintptr) int64
- func FrameSetPTS(framePtr uintptr, pts int64)
- func FreeAVFrame(framePtr uintptr)
- func RTPFree(handle uintptr)
- func RTPInit(avioPtr uintptr, destHost string, destPort int, encoderCodecCtxPtr uintptr, ...) (uintptr, error)
- func RTPSDP(handle uintptr) string
- func RTPSendPacket(handle, pktPtr uintptr) error
- func RTPUpdateTimeBase(handle, encoderCodecCtxPtr uintptr)
- func SRTPMaxTrailer() int
- func UnrefAVPacket(pktPtr uintptr)
- type DecoderPTSCounters
- type DecoderPerfCounters
- type EncoderEncodeResult
- type RTPIO
- type RTPIOTarget
- type RTPOptions
- type SRTPSession
- func (s *SRTPSession) Free()
- func (s *SRTPSession) ProtectRTCP(buf []byte, inLen int) (int, error)
- func (s *SRTPSession) ProtectRTP(buf []byte, inLen int) (int, error)
- func (s *SRTPSession) UnprotectRTCP(buf []byte, inLen int) (int, error)
- func (s *SRTPSession) UnprotectRTP(buf []byte, inLen int) (int, error)
- type SRTPSuite
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AVPacketBytes ¶
AVPacketBytes повертає копію даних AVPacket як Go byte slice. Використовувати для запису в файл або тестів; для RTP — передавати ptr напряму в C.
func DecoderCodecName ¶
DecoderCodecName повертає ім'я декодера ffmpeg ("hevc", "h264", ...), "" якщо декодер не ініціалізований.
func DecoderFrameIsKey ¶
DecoderFrameIsKey повертає true якщо AVFrame є keyframe (IDR або CRA).
func DecoderInit ¶
DecoderInit повертає opaque handle (*C.DecoderCtx як uintptr). httpHeaders: HTTP заголовки виду "Key: Value\r\n", або "" якщо не потрібні.
func DecoderNextFrame ¶
DecoderNextFrame повертає handle свіжо виділеного AVFrame (uintptr). Caller ОБОВ'ЯЗКОВО звільняє через FreeAVFrame(). Повертає io.EOF при кінці потоку.
func DecoderStreamInfo ¶
DecoderStreamInfo повертає FPS і роздільність потоку.
func DecoderTimeBase ¶
DecoderTimeBase повертає time_base відеопотоку (num/den), в якому записані pts кадрів. Для RTSP/H.264 зазвичай 1/90000. Повертає 0/0 якщо decoder не ініціалізований.
func EncoderCodecCtx ¶
EncoderCodecCtx повертає AVCodecContext* як uintptr (для rtp_init у кроці 5).
func EncoderDrain ¶
func EncoderDrain(handle uintptr)
EncoderDrain зливає залишкові пакети перед перезапуском.
func EncoderFrameCount ¶
EncoderFrameCount повертає поточне значення PTS-лічильника.
func EncoderGetFPS ¶
EncoderGetFPS повертає поточний FPS енкодера (для перерахунку PTS на restart).
func EncoderInit ¶
func EncoderInit(codecName string, width, height, bitrateKbps, fps, iframeIntervalMS int, h264Profile, h264Level string) (uintptr, error)
EncoderInit повертає opaque handle (*C.EncoderCtx як uintptr). h264Profile: "", "baseline", "main", "high". h264Level: "", "3.1", "3.2", "4.0".
func EncoderResetPTSState ¶
func EncoderResetPTSState(handle uintptr)
EncoderResetPTSState помічає PTS-потік для rebase: наступний кадр продовжить timestamps монотонно з last_pts + крок, зберігши відносні інтервали. Викликати після reconnect декодера, коли очікуємо стрибок PTS назад (muxer відхиляє немонотонний dts, тому «просто скинути» не можна).
func EncoderSetBitrate ¶
EncoderSetBitrate динамічно змінює бітрейт.
func EncoderSetFrameCount ¶
EncoderSetFrameCount задає стартовий PTS — для безперервної послідовності після restart зі зміною роздільності.
func EncoderSetFramerate ¶
EncoderSetFramerate динамічно змінює частоту кадрів.
func EncoderSetInputTimeBase ¶
EncoderSetInputTimeBase прокидає time_base декодерного потоку в енкодер, щоб PTS вихідних кадрів масштабувались через av_rescale_q замість монотонного лічильника. Викликати після кожного успішного DecoderInit (включаючи reconnect — time_base може змінитись). den == 0 → reset до fallback на frame_count.
func FrameSetPTS ¶
FrameSetPTS виставляє pts AVFrame. Використовується CFR-апконвертом: дублікат останнього кадру отримує просунутий по wall-clock pts.
func FreeAVFrame ¶
func FreeAVFrame(framePtr uintptr)
FreeAVFrame звільняє AVFrame, виданий DecoderNextFrame.
func RTPInit ¶
func RTPInit(avioPtr uintptr, destHost string, destPort int, encoderCodecCtxPtr uintptr, opts RTPOptions) (uintptr, error)
RTPInit ініціалізує RTP muxer і прив'язує його до custom AVIO (з RTPIOCreate). destHost/destPort використовуються лише для SDP c=/m= ліній.
func RTPSendPacket ¶
func RTPUpdateTimeBase ¶
func RTPUpdateTimeBase(handle, encoderCodecCtxPtr uintptr)
func SRTPMaxTrailer ¶
func SRTPMaxTrailer() int
MaxTrailer — скільки байт зарезервувати після RTP/RTCP-payload для auth tag.
func UnrefAVPacket ¶
func UnrefAVPacket(pktPtr uintptr)
UnrefAVPacket звільняє буфер пакету після відправки (packet struct залишається).
Types ¶
type DecoderPTSCounters ¶
DecoderPTSCounters — телеметрія PTS джерела з часу попереднього виклику (read-and-clear). SumUs/MaxUs/Count — інтервали між ЗРОСТАЮЧИМИ pts (avg = SumUs/Count); NoPTS — кадри без pts; NonMono — кадри з pts <= попереднього. Викликати з одного треда (stats).
func DecoderPTSStats ¶
func DecoderPTSStats(handle uintptr) DecoderPTSCounters
type DecoderPerfCounters ¶
type DecoderPerfCounters struct {
ReadUs int64 // av_read_frame: мережа/демукс (великий = камера тротлить)
DecodeUs int64 // send_packet + receive_frame: CPU/HW декод
XferUs int64 // av_hwframe_transfer_data: download DRM→CPU
Frames int64 // кадрів повернуто
}
DecoderPerfCounters — кумулятивні perf-лічильники decoder_next_frame. Caller рахує дельти між викликами.
func DecoderPerf ¶
func DecoderPerf(handle uintptr) DecoderPerfCounters
DecoderPerf повертає кумулятивні perf-лічильники декодера.
type EncoderEncodeResult ¶
type EncoderEncodeResult struct {
PktPtr uintptr // *C.AVPacket як uintptr; звільнити через UnrefAVPacket
IsKeyframe bool
}
EncoderEncodeResult — результат кодування кадру.
func EncoderEncode ¶
func EncoderEncode(handle, framePtr uintptr, forceKeyframe bool) (EncoderEncodeResult, error)
EncoderEncode кодує один YUV кадр (framePtr з DecoderNextFrame). Після використання пакету ОБОВ'ЯЗКОВО викликати UnrefAVPacket(res.PktPtr).
type RTPIO ¶
type RTPIO struct {
// contains filtered or unexported fields
}
RTPIO — пара (custom AVIOContext, cgo.Handle на target).
func RTPIOCreate ¶
func RTPIOCreate(target RTPIOTarget, bufSize int) (*RTPIO, error)
RTPIOCreate створює custom AVIO. Усі write_packet виклики будуть перетворюватись у target.WritePacket(). Розмір внутрішнього буфера AVIO визначає максимальний розмір одного RTP-пакета.
type RTPIOTarget ¶
RTPIOTarget — куди custom AVIO зливає згенеровані ffmpeg-муксером пакети. Зазвичай реалізується srtp-encrypt + UDP-send wrapper'ом.
type RTPOptions ¶
type RTPOptions struct {
MTU uint16 // 0 = libavformat default (1460)
PayloadType uint8 // 0 = default 96
SSRC uint32 // 0 = random
}
RTPOptions — лише packetization-параметри. SRTP, socket, local-bind — поза muxer'ом (libsrtp2 wrapper + net.UDPConn у Go).
type SRTPSession ¶
type SRTPSession struct {
// contains filtered or unexported fields
}
SRTPSession — обгортка libsrtp2 srtp_t. Один напрям (encrypt або decrypt).
func SRTPCreate ¶
func SRTPCreate(suite SRTPSuite, key, salt []byte, ssrc uint32, outbound bool) (*SRTPSession, error)
SRTPCreate створює одну SRTP-сесію. outbound=true — для відправки (наш SSRC жорстко заданий). outbound=false — для прийому (приймає будь-який incoming SSRC).
func (*SRTPSession) Free ¶
func (s *SRTPSession) Free()
func (*SRTPSession) ProtectRTCP ¶
func (s *SRTPSession) ProtectRTCP(buf []byte, inLen int) (int, error)
func (*SRTPSession) ProtectRTP ¶
func (s *SRTPSession) ProtectRTP(buf []byte, inLen int) (int, error)
func (*SRTPSession) UnprotectRTCP ¶
func (s *SRTPSession) UnprotectRTCP(buf []byte, inLen int) (int, error)
func (*SRTPSession) UnprotectRTP ¶
func (s *SRTPSession) UnprotectRTP(buf []byte, inLen int) (int, error)