Documentation
¶
Overview ¶
Package sdl provides SDL2-based audio and video output for go-media.
This package requires SDL2 to be installed.
The package provides:
- Context: SDL initialization and event loop management
- Window: Video rendering using SDL windows and textures
- Audio: Audio playback using SDL audio devices
- Player: High-level player combining video and audio
Example usage:
ctx, err := sdl.New(sdl.INIT_VIDEO | sdl.INIT_AUDIO)
if err != nil {
log.Fatal(err)
}
defer ctx.Close()
window, err := ctx.NewWindow("Video Player", 1920, 1080)
if err != nil {
log.Fatal(err)
}
defer window.Close()
ctx.Run(context.Background())
Index ¶
- type Audio
- type Context
- func (c *Context) Close() error
- func (c *Context) NewAudio(sampleRate int32, channels uint8, samples uint16) (*Audio, error)
- func (c *Context) NewPlayer() *Player
- func (c *Context) NewWindow(title string, width, height int32) (*Window, error)
- func (c *Context) Post(evt uint32, userInfo interface{}) error
- func (c *Context) Register(fn func(userInfo interface{})) uint32
- func (c *Context) Run(ctx context.Context) error
- type FrameLoop
- type FrameLoopOpt
- type FrameWriter
- type Player
- type Window
- func (w *Window) Close() error
- func (w *Window) Render() error
- func (w *Window) SetTitle(title string)
- func (w *Window) Size() (width, height int32)
- func (w *Window) Update(y, u, v []byte, yPitch, uPitch, vPitch int, width, height int32) error
- func (w *Window) UpdateRGB(pixels []byte, pitch int, width, height int32) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Audio ¶
type Audio struct {
// contains filtered or unexported fields
}
Audio represents an SDL audio device for playback.
func (*Audio) Queue ¶ added in v1.8.1
Queue queues audio data for playback. The data should be in the format specified when creating the device (float32).
func (*Audio) QueuedSize ¶ added in v1.8.1
QueuedSize returns the number of bytes currently queued for playback.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context manages SDL initialization and the event loop.
func New ¶
New creates a new SDL context with the specified initialization flags. Common flags are sdl.INIT_VIDEO, sdl.INIT_AUDIO, or combine them.
func (*Context) NewAudio ¶
NewAudio creates a new SDL audio device with the specified parameters. sampleRate is in Hz (e.g., 44100, 48000) channels is the number of audio channels (1 for mono, 2 for stereo) samples is the audio buffer size in samples (power of 2, e.g., 4096)
func (*Context) NewPlayer ¶ added in v1.8.1
NewPlayer creates a new player for displaying video and playing audio. It will auto-setup when the first frame is received.
func (*Context) NewWindow ¶ added in v1.8.1
NewWindow creates a new SDL window with the specified title and dimensions. The window is created with a renderer and texture ready for video display.
type FrameLoop ¶ added in v1.8.1
type FrameLoop struct {
// contains filtered or unexported fields
}
FrameLoop runs an SDL event that pulls frames from a channel and hands them to a handler on the main thread. It keeps posting events with small delays to avoid busy looping while still staying responsive.
func NewFrameLoop ¶ added in v1.8.1
func NewFrameLoop(ctx *Context, handler func(*ffmpeg.Frame) error, buffer int, opts ...FrameLoopOpt) (*FrameLoop, error)
NewFrameLoop creates a frame loop with the given buffer size and handler. Use Start to begin posting events.
func (*FrameLoop) CloseInput ¶ added in v1.8.1
func (l *FrameLoop) CloseInput()
CloseInput signals that no more frames will arrive and triggers final processing.
func (*FrameLoop) Done ¶ added in v1.8.1
func (l *FrameLoop) Done() <-chan struct{}
Done is closed when the loop stops after input closes.
type FrameLoopOpt ¶ added in v1.8.1
type FrameLoopOpt func(*FrameLoop)
FrameLoopOpt configures a FrameLoop.
func WithFrameDelayFunc ¶ added in v1.8.1
func WithFrameDelayFunc(fn func(*ffmpeg.Frame) time.Duration) FrameLoopOpt
WithFrameDelayFunc uses a custom delay calculator per frame (e.g., based on PTS).
type FrameWriter ¶ added in v1.8.1
type FrameWriter struct {
// contains filtered or unexported fields
}
FrameWriter adapts a FrameLoop to the ffmpeg task writer interface.
func NewFrameWriter ¶ added in v1.8.1
func NewFrameWriter(loop *FrameLoop) *FrameWriter
NewFrameWriter creates a writer that forwards frames into the loop.
func (*FrameWriter) Write ¶ added in v1.8.1
func (w *FrameWriter) Write(p []byte) (n int, err error)
Write satisfies io.Writer but discards data; decoding writes frames via WriteFrame.
func (*FrameWriter) WriteFrame ¶ added in v1.8.1
func (w *FrameWriter) WriteFrame(streamIndex int, frame interface{}) error
WriteFrame queues ffmpeg frames into the loop.
type Player ¶ added in v1.8.1
type Player struct {
// contains filtered or unexported fields
}
Player combines window and audio for easy playback of decoded frames.
func (*Player) Audio ¶ added in v1.8.1
Audio returns the player's audio device (may be nil if no audio frames yet).
func (*Player) PlayFrame ¶ added in v1.8.1
PlayFrame plays a decoded frame. For video frames, displays them in the window. For audio frames, queues them for playback. Auto-creates window/audio on first frame.
func (*Player) VideoDelay ¶ added in v1.8.1
VideoDelay returns how long to wait before presenting the next frame. Implements A/V sync following the FFmpeg tutorial algorithm. Returns 0 for audio frames (never delay audio).
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window represents an SDL window with renderer and texture for video display.