From afa3e66e765060ff6eac2e521bbde6819b158114 Mon Sep 17 00:00:00 2001 From: "H.G. Giorgis" Date: Fri, 4 Sep 2015 01:35:53 -0400 Subject: [PATCH] go receivers; formatting; and restructuring --- avcodec/avcodec.go | 81 ++++++++++------------------ avcodec/bitstreamfilter.go | 36 +++++++++++++ avdevice/avdevice.go | 34 ------------ avdevice/format.go | 33 ++++++++++++ avformat/avformat.go | 36 ++++++------- avformat/context.go | 24 ++++----- swresample/context.go | 95 ++++++++++++++++++++++++++++++++ swresample/swresample.go | 107 +------------------------------------ 8 files changed, 223 insertions(+), 223 deletions(-) create mode 100644 avcodec/bitstreamfilter.go create mode 100644 avdevice/format.go create mode 100644 swresample/context.go diff --git a/avcodec/avcodec.go b/avcodec/avcodec.go index ebe6148..35b1ff9 100644 --- a/avcodec/avcodec.go +++ b/avcodec/avcodec.go @@ -67,6 +67,34 @@ func (c *Codec) AvCodecNext() *Codec { return (*Codec)(C.av_codec_next((*C.struct_AVCodec)(c))) } +//Register the codec codec and initialize libavcodec. +func (c *Codec) AvcodecRegister() { + C.avcodec_register((*C.struct_AVCodec)(c)) +} + +//Return a name for the specified profile, if available. +func (c *Codec) AvGetProfileName(p int) string { + return C.GoString(C.av_get_profile_name((*C.struct_AVCodec)(c), C.int(p))) +} + +//Allocate an Context and set its fields to default values. +func (c *Codec) AvcodecAllocContext3() *Context { + return (*Context)(C.avcodec_alloc_context3((*C.struct_AVCodec)(c))) +} + +func (c *Codec) AvCodecIsEncoder() int { + return int(C.av_codec_is_encoder((*C.struct_AVCodec)(c))) +} + +func (c *Codec) AvCodecIsDecoder() int { + return int(C.av_codec_is_decoder((*C.struct_AVCodec)(c))) +} + +//Same behaviour av_fast_malloc but the buffer has additional FF_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0. +func AvFastPaddedMalloc(p unsafe.Pointer, s *uint, t uintptr) { + C.av_fast_padded_malloc(p, (*C.uint)(unsafe.Pointer(s)), (C.size_t)(t)) +} + //Return the LIBAvCODEC_VERSION_INT constant. func AvcodecVersion() uint { return uint(C.avcodec_version()) @@ -83,21 +111,11 @@ func AvcodecLicense() string { return C.GoString(C.avcodec_license()) } -//Register the codec codec and initialize libavcodec. -func (c *Codec) AvcodecRegister() { - C.avcodec_register((*C.struct_AVCodec)(c)) -} - //Register all the codecs, parsers and bitstream filters which were enabled at configuration time. func AvcodecRegisterAll() { C.avcodec_register_all() } -//Allocate an Context and set its fields to default values. -func (c *Codec) AvcodecAllocContext3() *Context { - return (*Context)(C.avcodec_alloc_context3((*C.struct_AVCodec)(c))) -} - //Get the Class for Context. func AvcodecGetClass() *Class { return (*Class)(C.avcodec_get_class()) @@ -167,11 +185,6 @@ func AvcodecString(b string, bs int, ctxt *Context, e int) { C.avcodec_string(C.CString(b), C.int(bs), (*C.struct_AVCodecContext)(ctxt), C.int(e)) } -//Return a name for the specified profile, if available. -func (c *Codec) AvGetProfileName(p int) string { - return C.GoString(C.av_get_profile_name((*C.struct_AVCodec)(c), C.int(p))) -} - //Fill Frame audio data and linesize pointers. func AvcodecFillAudioFrame(f *Frame, c int, s AvSampleFormat, b *uint8, bs, a int) int { return int(C.avcodec_fill_audio_frame((*C.struct_AVFrame)(f), C.int(c), (C.enum_AVSampleFormat)(s), (*C.uint8_t)(b), C.int(bs), C.int(a))) @@ -192,36 +205,6 @@ func AvGetExactBitsPerSample(c CodecId) int { return int(C.av_get_exact_bits_per_sample((C.enum_AVCodecID)(c))) } -//Register a bitstream filter. -func (b *BitStreamFilter) AvRegisterBitstreamFilter() { - C.av_register_bitstream_filter((*C.struct_AVBitStreamFilter)(b)) -} - -//Create and initialize a bitstream filter context given a bitstream filter name. -func AvBitstreamFilterInit(n string) *BitStreamFilterContext { - return (*BitStreamFilterContext)(C.av_bitstream_filter_init(C.CString(n))) -} - -//Filter bitstream. -func (bfx *BitStreamFilterContext) AvBitstreamFilterFilter(ctxt *Context, a string, p **uint8, ps *int, b *uint8, bs, k int) int { - return int(C.av_bitstream_filter_filter((*C.struct_AVBitStreamFilterContext)(bfx), (*C.struct_AVCodecContext)(ctxt), C.CString(a), (**C.uint8_t)(unsafe.Pointer(p)), (*C.int)(unsafe.Pointer(ps)), (*C.uint8_t)(b), C.int(bs), C.int(k))) -} - -//Release bitstream filter context. -func (bfx *BitStreamFilterContext) AvBitstreamFilterClose() { - C.av_bitstream_filter_close((*C.struct_AVBitStreamFilterContext)(bfx)) -} - -//BitStreamFilter *av_bitstream_filter_next (const BitStreamFilter *f) -func (f *BitStreamFilter) AvBitstreamFilterNext() *BitStreamFilter { - return (*BitStreamFilter)(C.av_bitstream_filter_next((*C.struct_AVBitStreamFilter)(f))) -} - -//Same behaviour av_fast_malloc but the buffer has additional FF_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0. -func AvFastPaddedMalloc(p unsafe.Pointer, s *uint, t uintptr) { - C.av_fast_padded_malloc(p, (*C.uint)(unsafe.Pointer(s)), (C.size_t)(t)) -} - //Same behaviour av_fast_padded_malloc except that buffer will always be 0-initialized after call. func AvFastPaddedMallocz(p unsafe.Pointer, s *uint, t uintptr) { C.av_fast_padded_mallocz(p, (*C.uint)(unsafe.Pointer(s)), (C.size_t)(t)) @@ -248,14 +231,6 @@ func AvcodecGetName(d CodecId) string { return C.GoString(C.avcodec_get_name((C.enum_AVCodecID)(d))) } -func (c *Codec) AvCodecIsEncoder() int { - return int(C.av_codec_is_encoder((*C.struct_AVCodec)(c))) -} - -func (c *Codec) AvCodecIsDecoder() int { - return int(C.av_codec_is_decoder((*C.struct_AVCodec)(c))) -} - //const Descriptor *avcodec_descriptor_get (enum CodecId id) func AvcodecDescriptorGet(id CodecId) *Descriptor { return (*Descriptor)(C.avcodec_descriptor_get((C.enum_AVCodecID)(id))) diff --git a/avcodec/bitstreamfilter.go b/avcodec/bitstreamfilter.go new file mode 100644 index 0000000..a0815e1 --- /dev/null +++ b/avcodec/bitstreamfilter.go @@ -0,0 +1,36 @@ +/* + AvPicture +*/ +package avcodec + +//#cgo pkg-config: libavcodec +//#include +import "C" +import ( + "unsafe" +) + +//Register a bitstream filter. +func (b *BitStreamFilter) AvRegisterBitstreamFilter() { + C.av_register_bitstream_filter((*C.struct_AVBitStreamFilter)(b)) +} + +//BitStreamFilter *av_bitstream_filter_next (const BitStreamFilter *f) +func (f *BitStreamFilter) AvBitstreamFilterNext() *BitStreamFilter { + return (*BitStreamFilter)(C.av_bitstream_filter_next((*C.struct_AVBitStreamFilter)(f))) +} + +//Filter bitstream. +func (bfx *BitStreamFilterContext) AvBitstreamFilterFilter(ctxt *Context, a string, p **uint8, ps *int, b *uint8, bs, k int) int { + return int(C.av_bitstream_filter_filter((*C.struct_AVBitStreamFilterContext)(bfx), (*C.struct_AVCodecContext)(ctxt), C.CString(a), (**C.uint8_t)(unsafe.Pointer(p)), (*C.int)(unsafe.Pointer(ps)), (*C.uint8_t)(b), C.int(bs), C.int(k))) +} + +//Release bitstream filter context. +func (bfx *BitStreamFilterContext) AvBitstreamFilterClose() { + C.av_bitstream_filter_close((*C.struct_AVBitStreamFilterContext)(bfx)) +} + +//Create and initialize a bitstream filter context given a bitstream filter name. +func AvBitstreamFilterInit(n string) *BitStreamFilterContext { + return (*BitStreamFilterContext)(C.av_bitstream_filter_init(C.CString(n))) +} diff --git a/avdevice/avdevice.go b/avdevice/avdevice.go index 0c1c029..2b5b377 100644 --- a/avdevice/avdevice.go +++ b/avdevice/avdevice.go @@ -32,84 +32,50 @@ type ( ) //unsigned avdevice_version (void) -//Return the LIBAvDEVICE_VERSION_INT constant. func Avdevice_version() uint { return uint(C.avdevice_version()) } -//const char * avdevice_configuration (void) //Return the libavdevice build-time configuration. func Avdevice_configuration() string { return C.GoString(C.avdevice_configuration()) } -//const char * avdevice_license (void) //Return the libavdevice license. func Avdevice_license() string { return C.GoString(C.avdevice_license()) } -//void avdevice_register_all (void) //Initialize libavdevice and register all the input and output devices. func Avdevice_register_all() { C.avdevice_register_all() } -//InputFormat * av_input_audio_device_next (InputFormat *d) -//Audio input devices iterator. -func Av_input_audio_device_next(d *InputFormat) *InputFormat { - return (*InputFormat)(C.av_input_audio_device_next((*C.struct_AVInputFormat)(d))) -} - -//InputFormat * av_input_video_device_next (InputFormat *d) -//Video input devices iterator. -func Av_input_video_device_next(d *InputFormat) *InputFormat { - return (*InputFormat)(C.av_input_video_device_next((*C.struct_AVInputFormat)(d))) -} - -//OutputFormat * av_output_audio_device_next (OutputFormat *d) -//Audio output devices iterator. -func Av_output_audio_device_next(d *OutputFormat) *OutputFormat { - return (*OutputFormat)(C.av_output_audio_device_next((*C.struct_AVOutputFormat)(d))) -} - -//OutputFormat * av_output_video_device_next (OutputFormat *d) -//Video output devices iterator. -func Av_output_video_device_next(d *OutputFormat) *OutputFormat { - return (*OutputFormat)(C.av_output_video_device_next((*C.struct_AVOutputFormat)(d))) -} - -//int avdevice_app_to_dev_control_message (struct AvFormatContext *s, enum AvAppToDevMessageType type, void *data, size_t data_size) //Send control message from application to device. func Avdevice_app_to_dev_control_message(s *AvFormatContext, m AvAppToDevMessageType, da int, d uintptr) int { return int(C.avdevice_app_to_dev_control_message((*C.struct_AVFormatContext)(s), (C.enum_AVAppToDevMessageType)(m), unsafe.Pointer(&da), C.size_t(d))) } -//int avdevice_dev_to_app_control_message (struct AvFormatContext *s, enum AvDevToAppMessageType type, void *data, size_t data_size) //Send control message from device to application. func Avdevice_dev_to_app_control_message(fcxt *AvFormatContext, m AvDevToAppMessageType, da int, d uintptr) int { return int(C.avdevice_dev_to_app_control_message((*C.struct_AVFormatContext)(fcxt), (C.enum_AVDevToAppMessageType)(m), unsafe.Pointer(&da), C.size_t(d))) } -//int avdevice_capabilities_create (AvDeviceCapabilitiesQuery **caps, AvFormatContext *s, Dictionary **device_options) //Initialize capabilities probing API based on AvOption API. func Avdevice_capabilities_create(c **AvDeviceCapabilitiesQuery, s *AvFormatContext, d **Dictionary) int { return int(C.avdevice_capabilities_create((**C.struct_AVDeviceCapabilitiesQuery)(unsafe.Pointer(c)), (*C.struct_AVFormatContext)(s), (**C.struct_AVDictionary)(unsafe.Pointer(d)))) } -//void avdevice_capabilities_free (AvDeviceCapabilitiesQuery **caps, AvFormatContext *s) //Free resources created by avdevice_capabilities_create() func Avdevice_capabilities_free(c **AvDeviceCapabilitiesQuery, s *AvFormatContext) { C.avdevice_capabilities_free((**C.struct_AVDeviceCapabilitiesQuery)(unsafe.Pointer(c)), (*C.struct_AVFormatContext)(s)) } -//int avdevice_list_devices (struct AvFormatContext *s, AvDeviceInfoList **device_list) //List devices. func Avdevice_list_devices(s *AvFormatContext, d **AvDeviceInfoList) int { return int(C.avdevice_list_devices((*C.struct_AVFormatContext)(s), (**C.struct_AVDeviceInfoList)(unsafe.Pointer(d)))) } -//void avdevice_free_list_devices (AvDeviceInfoList **device_list) //Convenient function to free result of avdevice_list_devices(). func Avdevice_free_list_devices(d **AvDeviceInfoList) { C.avdevice_free_list_devices((**C.struct_AVDeviceInfoList)(unsafe.Pointer(d))) diff --git a/avdevice/format.go b/avdevice/format.go new file mode 100644 index 0000000..cf98c63 --- /dev/null +++ b/avdevice/format.go @@ -0,0 +1,33 @@ +/* + Format +*/ +package avdevice + +/* + #cgo pkg-config: libavdevice + #include +*/ +import "C" +import ( + "unsafe" +) + +//Audio input devices iterator. +func (d *InputFormat) Av_input_audio_device_next() *InputFormat { + return (*InputFormat)(C.av_input_audio_device_next((*C.struct_AVInputFormat)(d))) +} + +//Video input devices iterator. +func (d *InputFormat) Av_input_video_device_next() *InputFormat { + return (*InputFormat)(C.av_input_video_device_next((*C.struct_AVInputFormat)(d))) +} + +//Audio output devices iterator. +func (d *OutputFormat) Av_output_audio_device_next() *OutputFormat { + return (*OutputFormat)(C.av_output_audio_device_next((*C.struct_AVOutputFormat)(d))) +} + +//Video output devices iterator. +func (d *OutputFormat) Av_output_video_device_next() *OutputFormat { + return (*OutputFormat)(C.av_output_video_device_next((*C.struct_AVOutputFormat)(d))) +} diff --git a/avformat/avformat.go b/avformat/avformat.go index 2ab5682..2124b25 100644 --- a/avformat/avformat.go +++ b/avformat/avformat.go @@ -70,6 +70,24 @@ func (ctxt *AvIOContext) AvAppendPacket(pkt *Packet, s int) int { return int(C.av_append_packet((*C.struct_AVIOContext)(ctxt), (*C.struct_AVPacket)(pkt), C.int(s))) } +func (f *InputFormat) AvRegisterInputFormat() { + C.av_register_input_format((*C.struct_AVInputFormat)(f)) +} + +func (f *OutputFormat) AvRegisterOutputFormat() { + C.av_register_output_format((*C.struct_AVOutputFormat)(f)) +} + +//If f is NULL, returns the first registered input format, if f is non-NULL, returns the next registered input format after f or NULL if f is the last one. +func (f *InputFormat) AvIformatNext() *InputFormat { + return (*InputFormat)(C.av_iformat_next((*C.struct_AVInputFormat)(f))) +} + +//If f is NULL, returns the first registered output format, if f is non-NULL, returns the next registered output format after f or NULL if f is the last one. +func (f *OutputFormat) AvOformatNext() *OutputFormat { + return (*OutputFormat)(C.av_oformat_next((*C.struct_AVOutputFormat)(f))) +} + //Return the LIBAvFORMAT_VERSION_INT constant. func AvformatVersion() uint { return uint(C.avformat_version()) @@ -90,14 +108,6 @@ func AvRegisterAll() { C.av_register_all() } -func AvRegisterInputFormat(f *InputFormat) { - C.av_register_input_format((*C.struct_AVInputFormat)(f)) -} - -func (f *OutputFormat) AvRegisterOutputFormat() { - C.av_register_output_format((*C.struct_AVOutputFormat)(f)) -} - //Do global initialization of network components. func AvformatNetworkInit() int { return int(C.avformat_network_init()) @@ -108,16 +118,6 @@ func AvformatNetworkDeinit() int { return int(C.avformat_network_deinit()) } -//If f is NULL, returns the first registered input format, if f is non-NULL, returns the next registered input format after f or NULL if f is the last one. -func (f *InputFormat) AvIformatNext() *InputFormat { - return (*InputFormat)(C.av_iformat_next((*C.struct_AVInputFormat)(f))) -} - -//If f is NULL, returns the first registered output format, if f is non-NULL, returns the next registered output format after f or NULL if f is the last one. -func (f *OutputFormat) AvOformatNext() *OutputFormat { - return (*OutputFormat)(C.av_oformat_next((*C.struct_AVOutputFormat)(f))) -} - //Allocate an Context. func AvformatAllocContext() *Context { return (*Context)(C.avformat_alloc_context()) diff --git a/avformat/context.go b/avformat/context.go index bf7dea5..bc652ec 100644 --- a/avformat/context.go +++ b/avformat/context.go @@ -94,8 +94,8 @@ func (s *Context) AvFormatInjectGlobalSideData() { //enum AvDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method (const Context *ctx) //Returns the method used to set ctx->duration. -func (ctx *Context) AvFmtCtxGetDurationEstimationMethod() AvDurationEstimationMethod { - return (AvDurationEstimationMethod)(C.av_fmt_ctx_get_duration_estimation_method((*C.struct_AVFormatContext)(ctx))) +func (s *Context) AvFmtCtxGetDurationEstimationMethod() AvDurationEstimationMethod { + return (AvDurationEstimationMethod)(C.av_fmt_ctx_get_duration_estimation_method((*C.struct_AVFormatContext)(s))) } //void avformat_free_context (Context *s) @@ -117,14 +117,14 @@ func (s *Context) AvNewProgram(id int) *AvProgram { //int avformat_find_stream_info (Context *ic, Dictionary **options) //Read packets of a media file to get stream information. -func (ic *Context) AvformatFindStreamInfo(d **Dictionary) int { - return int(C.avformat_find_stream_info((*C.struct_AVFormatContext)(ic), (**C.struct_AVDictionary)(unsafe.Pointer(d)))) +func (s *Context) AvformatFindStreamInfo(d **Dictionary) int { + return int(C.avformat_find_stream_info((*C.struct_AVFormatContext)(s), (**C.struct_AVDictionary)(unsafe.Pointer(d)))) } //AvProgram * av_find_program_from_stream (Context *ic, AvProgram *last, int s) //Find the programs which belong to a given stream. -func (ic *Context) AvFindProgramFromStream(l *AvProgram, s int) *AvProgram { - return (*AvProgram)(C.av_find_program_from_stream((*C.struct_AVFormatContext)(ic), (*C.struct_AVProgram)(l), C.int(s))) +func (s *Context) AvFindProgramFromStream(l *AvProgram, su int) *AvProgram { + return (*AvProgram)(C.av_find_program_from_stream((*C.struct_AVFormatContext)(s), (*C.struct_AVProgram)(l), C.int(su))) } //int av_find_best_stream (Context *ic, enum MediaType type, int wanted_stream_nb, int related_stream, AvCodec **decoder_ret, int flags) @@ -224,20 +224,20 @@ func (s *Context) AvFindDefaultStreamIndex() int { //void av_dump_format (Context *ic, int index, const char *url, int is_output) //Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base. -func (ic *Context) AvDumpFormat(i int, url string, io int) { - C.av_dump_format((*C.struct_AVFormatContext)(unsafe.Pointer(ic)), C.int(i), C.CString(url), C.int(io)) +func (s *Context) AvDumpFormat(i int, url string, io int) { + C.av_dump_format((*C.struct_AVFormatContext)(unsafe.Pointer(s)), C.int(i), C.CString(url), C.int(io)) } //Rational av_guess_sample_aspect_ratio (Context *format, Stream *stream, Frame *frame) //Guess the sample aspect ratio of a frame, based on both the stream and the frame aspect ratio. -func (f *Context) AvGuessSampleAspectRatio(st *Stream, fr *Frame) Rational { - return (Rational)(C.av_guess_sample_aspect_ratio((*C.struct_AVFormatContext)(f), (*C.struct_AVStream)(st), (*C.struct_AVFrame)(fr))) +func (s *Context) AvGuessSampleAspectRatio(st *Stream, fr *Frame) Rational { + return (Rational)(C.av_guess_sample_aspect_ratio((*C.struct_AVFormatContext)(s), (*C.struct_AVStream)(st), (*C.struct_AVFrame)(fr))) } //Rational av_guess_frame_rate (Context *ctx, Stream *stream, Frame *frame) //Guess the frame rate, based on both the container and codec information. -func (ctx *Context) AvGuessFrameRate(st *Stream, fr *Frame) Rational { - return (Rational)(C.av_guess_frame_rate((*C.struct_AVFormatContext)(ctx), (*C.struct_AVStream)(st), (*C.struct_AVFrame)(fr))) +func (s *Context) AvGuessFrameRate(st *Stream, fr *Frame) Rational { + return (Rational)(C.av_guess_frame_rate((*C.struct_AVFormatContext)(s), (*C.struct_AVStream)(st), (*C.struct_AVFrame)(fr))) } //int avformat_match_stream_specifier (Context *s, Stream *st, const char *spec) diff --git a/swresample/context.go b/swresample/context.go new file mode 100644 index 0000000..d293abe --- /dev/null +++ b/swresample/context.go @@ -0,0 +1,95 @@ +/* + Use of this source code is governed by a MIT license that can be found in the LICENSE file. + by Giorgis (habtom@giorgis.io) + + The process of changing the sampling rate of a discrete signal to obtain + a new discrete representation of the underlying continuous signal. + resampler provides a high-level interface to the libswresample library audio resampling utilities +*/ +package swresample + +/* + #cgo pkg-config: libswresample + #include +*/ +import "C" +import ( + "unsafe" +) + +//Initialize context after user parameters have been set. +func (s *Context) Swr_init() int { + return int(C.swr_init((*C.struct_SwrContext)(s))) +} + +//Check whether an swr context has been initialized or not. +func (s *Context) Swr_is_initialized() int { + return int(C.swr_is_initialized((*C.struct_SwrContext)(s))) +} + +//Allocate Context if needed and set/reset common parameters. +func (s *Context) Swr_alloc_set_opts(ocl int64, osf AvSampleFormat, osr int, icl int64, isf AvSampleFormat, isr, lo, lc int) *Context { + return (*Context)(C.swr_alloc_set_opts((*C.struct_SwrContext)(s), C.int64_t(ocl), (C.enum_AVSampleFormat)(osf), C.int(osr), C.int64_t(icl), (C.enum_AVSampleFormat)(isf), C.int(isr), C.int(lo), unsafe.Pointer(&lc))) +} + +//Context destructor functions. Free the given Context and set the pointer to NULL. +func (s *Context) Swr_free() { + C.swr_free((**C.struct_SwrContext)(unsafe.Pointer(s))) +} + +//Closes the context so that swr_is_initialized() returns 0. +func (s *Context) Swr_close() { + C.swr_close((*C.struct_SwrContext)(s)) +} + +//Core conversion functions. Convert audio +func (s *Context) Swr_convert(out **uint8, oc int, in **uint8, ic int) int { + return int(C.swr_convert((*C.struct_SwrContext)(s), (**C.uint8_t)(unsafe.Pointer(out)), C.int(oc), (**C.uint8_t)(unsafe.Pointer(in)), C.int(ic))) +} + +//Convert the next timestamp from input to output timestamps are in 1/(in_sample_rate * out_sample_rate) units. +func (s *Context) Swr_next_pts(pts int64) int64 { + return int64(C.swr_next_pts((*C.struct_SwrContext)(s), C.int64_t(pts))) +} + +//Low-level option setting functions +//These functons provide a means to set low-level options that is not possible with the AvOption API. +//Activate resampling compensation ("soft" compensation). +func (s *Context) Swr_set_compensation(sd, cd int) int { + return int(C.swr_set_compensation((*C.struct_SwrContext)(s), C.int(sd), C.int(cd))) +} + +//Set a customized input channel mapping. +func (s *Context) Swr_set_channel_mapping(cm *int) int { + return int(C.swr_set_channel_mapping((*C.struct_SwrContext)(s), (*C.int)(unsafe.Pointer(cm)))) +} + +//Set a customized remix matrix. +func (s *Context) Swr_set_matrix(m *int, t int) int { + return int(C.swr_set_matrix((*C.struct_SwrContext)(s), (*C.double)(unsafe.Pointer(m)), C.int(t))) +} + +//Sample handling functions. Drops the specified number of output samples. +func (s *Context) Swr_drop_output(c int) int { + return int(C.swr_drop_output((*C.struct_SwrContext)(s), C.int(c))) +} + +//Injects the specified number of silence samples. +func (s *Context) Swr_inject_silence(c int) int { + return int(C.swr_inject_silence((*C.struct_SwrContext)(s), C.int(c))) +} + +//Gets the delay the next input sample will experience relative to the next output sample. +func (s *Context) Swr_get_delay(b int64) int64 { + return int64(C.swr_get_delay((*C.struct_SwrContext)(s), C.int64_t(b))) +} + +//Frame based API. Convert the samples in the input Frame and write them to the output Frame. +func (s *Context) Swr_convert_frame(o, i *Frame) int { + return int(C.swr_convert_frame((*C.struct_SwrContext)(s), (*C.struct_AVFrame)(o), (*C.struct_AVFrame)(i))) +} + +//Configure or reconfigure the Context using the information provided by the AvFrames. +func (s *Context) Swr_config_frame(o, i *Frame) int { + return int(C.swr_config_frame((*C.struct_SwrContext)(s), (*C.struct_AVFrame)(o), (*C.struct_AVFrame)(i))) +} diff --git a/swresample/swresample.go b/swresample/swresample.go index 7f05566..f97724a 100644 --- a/swresample/swresample.go +++ b/swresample/swresample.go @@ -24,130 +24,25 @@ type ( AvSampleFormat C.enum_AVSampleFormat ) -//const Class * swr_get_class (void) //Get the Class for Context. func Swr_get_class() *Class { return (*Class)(C.swr_get_class()) } -//Context constructor functions -//struct Context * swr_alloc (void) -//Allocate Context. +//Context constructor functions.Allocate Context. func Swr_alloc() *Context { return (*Context)(C.swr_alloc()) } -//int swr_init (struct Context *s) -//Initialize context after user parameters have been set. -func Swr_init(s *Context) int { - return int(C.swr_init((*C.struct_SwrContext)(s))) -} - -//int swr_is_initialized (struct Context *s) -//Check whether an swr context has been initialized or not. -func Swr_is_initialized(s *Context) int { - return int(C.swr_is_initialized((*C.struct_SwrContext)(s))) -} - -//struct Context * swr_alloc_set_opts (struct Context *s, int64_t out_ch_layout, enum AvSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AvSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx) -//Allocate Context if needed and set/reset common parameters. -func Swr_alloc_set_opts(s *Context, ocl int64, osf AvSampleFormat, osr int, icl int64, isf AvSampleFormat, isr, lo, lc int) *Context { - return (*Context)(C.swr_alloc_set_opts((*C.struct_SwrContext)(s), C.int64_t(ocl), (C.enum_AVSampleFormat)(osf), C.int(osr), C.int64_t(icl), (C.enum_AVSampleFormat)(isf), C.int(isr), C.int(lo), unsafe.Pointer(&lc))) -} - -//Context destructor functions -//void swr_free (struct Context **s) -//Free the given Context and set the pointer to NULL. -func Swr_free(s **Context) { - C.swr_free((**C.struct_SwrContext)(unsafe.Pointer(s))) -} - -//void swr_close (struct Context *s) -//Closes the context so that swr_is_initialized() returns 0. -func Swr_close(s *Context) { - C.swr_close((*C.struct_SwrContext)(s)) -} - -//Core conversion functions -//int swr_convert (struct Context *s, uint8_t **out, int out_count, const uint8_t **in, int in_count) -//Convert audio. -func Swr_convert(s *Context, out **uint8, oc int, in **uint8, ic int) int { - return int(C.swr_convert((*C.struct_SwrContext)(s), (**C.uint8_t)(unsafe.Pointer(out)), C.int(oc), (**C.uint8_t)(unsafe.Pointer(in)), C.int(ic))) -} - -//int64_t swr_next_pts (struct Context *s, int64_t pts) -//Convert the next timestamp from input to output timestamps are in 1/(in_sample_rate * out_sample_rate) units. -func Swr_next_pts(s *Context, pts int64) int64 { - return int64(C.swr_next_pts((*C.struct_SwrContext)(s), C.int64_t(pts))) -} - -//Low-level option setting functions -//These functons provide a means to set low-level options that is not possible with the AvOption API. -//int swr_set_compensation (struct Context *s, int sample_delta, int compensation_distance) -//Activate resampling compensation ("soft" compensation). -func Swr_set_compensation(s *Context, sd, cd int) int { - return int(C.swr_set_compensation((*C.struct_SwrContext)(s), C.int(sd), C.int(cd))) -} - -//int swr_set_channel_mapping (struct Context *s, const int *channel_map) -//Set a customized input channel mapping. -func Swr_set_channel_mapping(s *Context, cm *int) int { - return int(C.swr_set_channel_mapping((*C.struct_SwrContext)(s), (*C.int)(unsafe.Pointer(cm)))) -} - -//int swr_set_matrix (struct Context *s, const double *matrix, int stride) -//Set a customized remix matrix. -func Swr_set_matrix(s *Context, m *int, t int) int { - return int(C.swr_set_matrix((*C.struct_SwrContext)(s), (*C.double)(unsafe.Pointer(m)), C.int(t))) -} - -//Sample handling functions -//int swr_drop_output (struct Context *s, int count) -//Drops the specified number of output samples. -func Swr_drop_output(s *Context, c int) int { - return int(C.swr_drop_output((*C.struct_SwrContext)(s), C.int(c))) -} - -//int swr_inject_silence (struct Context *s, int count) -//Injects the specified number of silence samples. -func Swr_inject_silence(s *Context, c int) int { - return int(C.swr_inject_silence((*C.struct_SwrContext)(s), C.int(c))) -} - -//int64_t swr_get_delay (struct Context *s, int64_t base) -//Gets the delay the next input sample will experience relative to the next output sample. -func Swr_get_delay(s *Context, b int64) int64 { - return int64(C.swr_get_delay((*C.struct_SwrContext)(s), C.int64_t(b))) -} - //Configuration accessors -//unsigned swresample_version (void) -//Return the LIBSWRESAMPLE_VERSION_INT constant. func Swresample_version() uint { return uint(C.swresample_version()) } -//const char * swresample_configuration (void) -//Return the swr build-time configuration. func Swresample_configuration() string { return C.GoString(C.swresample_configuration()) } -//const char * swresample_license (void) -//Return the swr license. func Swresample_license() string { return C.GoString(C.swresample_license()) } - -//Frame based API -//int swr_convert_frame (Context *swr, Frame *output, const Frame *input) -//Convert the samples in the input Frame and write them to the output Frame. -func Swr_convert_frame(s *Context, o, i *Frame) int { - return int(C.swr_convert_frame((*C.struct_SwrContext)(s), (*C.struct_AVFrame)(o), (*C.struct_AVFrame)(i))) -} - -//int swr_config_frame (Context *swr, const Frame *out, const Frame *in) -//Configure or reconfigure the Context using the information provided by the AvFrames. -func Swr_config_frame(s *Context, o, i *Frame) int { - return int(C.swr_config_frame((*C.struct_SwrContext)(s), (*C.struct_AVFrame)(o), (*C.struct_AVFrame)(i))) -}