@@ -5,7 +5,10 @@ functions to determine capabilities and manage media files and devices.
55*/
66package media
77
8- import "io"
8+ import (
9+ "context"
10+ "io"
11+ )
912
1013// Manager represents a manager for media formats and devices.
1114// Create a new manager object using the NewManager function.
@@ -34,36 +37,36 @@ type Manager interface {
3437 // specified, then the format will be used to open the file. Close the
3538 // media object when done. It is the responsibility of the caller to
3639 // also close the reader when done.
37- // Read(io.Reader, Format, ...string) (Media, error)
40+ Read (io.Reader , Format , ... string ) (Media , error )
3841
3942 // Create a media file or device for writing, from a path. If a format is
4043 // specified, then the format will be used to create the file or else
4144 // the format is guessed from the path. If no parameters are provided,
4245 // then the default parameters for the format are used.
43- // Create(string, Format, []Metadata, ...Parameters ) (Media, error)
46+ Create (string , Format , []Metadata , ... Par ) (Media , error )
4447
4548 // Create a media stream for writing. The format will be used to
4649 // determine the format and one or more CodecParameters used to
4750 // create the streams. If no parameters are provided, then the
4851 // default parameters for the format are used. It is the responsibility
4952 // of the caller to also close the writer when done.
50- //Write(io.Writer, Format, []Metadata, ...Parameters ) (Media, error)
53+ //Write(io.Writer, Format, []Metadata, ...Par ) (Media, error)
5154
5255 // Return audio parameters for encoding
5356 // ChannelLayout, SampleFormat, Samplerate
54- //AudioParameters (string, string, int) (Parameters , error)
57+ //AudioPar (string, string, int) (Par , error)
5558
5659 // Return video parameters for encoding
5760 // Width, Height, PixelFormat
58- //VideoParameters (int, int, string) (Parameters , error)
61+ //VideoPar (int, int, string) (Par , error)
5962
6063 // Return codec parameters for audio encoding
6164 // Codec name and AudioParameters
62- //AudioCodecParameters(string, AudioParameters ) (Parameters , error)
65+ //AudioCodecParameters(string, AudioPar ) (Par , error)
6366
6467 // Return codec parameters for video encoding
6568 // Codec name, Profile name, Framerate (fps) and VideoParameters
66- //VideoCodecParameters(string, string, float64, VideoParameters ) (Parameters , error)
69+ //VideoCodecParameters(string, string, float64, VideoPar ) (Par , error)
6770
6871 // Return supported input and output container formats which match any filter,
6972 // which can be a name, extension (with preceeding period) or mimetype. The Type
@@ -95,9 +98,30 @@ type Manager interface {
9598
9699 // Log info messages with arguments
97100 Infof (string , ... any )
101+
102+ // Decode an input stream, determining the streams to be decoded
103+ // and the function to accept the decoded frames. If MapFunc is nil,
104+ // all streams are passed through (demultiplexing).
105+ Decode (context.Context , Media , MapFunc , FrameFunc ) error
98106}
99107
100- // A container format for a media file or stream
108+ // MapFunc return parameters if a stream should be decoded,
109+ // resampled (for audio streams) or resized (for video streams).
110+ // Return nil if you want to ignore the stream, or pass back the
111+ // stream parameters if you want to copy the stream without any changes.
112+ type MapFunc func (int , Par ) (Par , error )
113+
114+ // FrameFunc is a function which is called to send a frame after decoding. It should
115+ // return nil to continue decoding or io.EOF to stop.
116+ type FrameFunc func (int , Frame ) error
117+
118+ // Parameters for a stream or frame
119+ type Par interface {}
120+
121+ // A frame of decoded data
122+ type Frame interface {}
123+
124+ // A container format for a media file
101125type Format interface {
102126 // The type of the format, which can be combinations of
103127 // INPUT, OUTPUT, DEVICE, AUDIO, VIDEO and SUBTITLE
0 commit comments