예제 #1
0
파일: frame.go 프로젝트: davidoram/gmf
func NewAudioFrame(sampleFormat int32, channels, nb_samples int) (*Frame, error) {
	this := NewFrame()
	this.mediaType = AVMEDIA_TYPE_AUDIO
	this.SetNbSamples(nb_samples)
	this.SetFormat(sampleFormat)
	this.SetChannelLayout(channels)

	//the codec gives us the frame size, in samples,
	//we calculate the size of the samples buffer in bytes
	size := C.av_samples_get_buffer_size(nil, C.int(channels), C.int(nb_samples),
		sampleFormat, 0)
	if size < 0 {
		return nil, errors.New("Could not get sample buffer size")
	}
	samples := (*_Ctype_uint8_t)(C.av_malloc(C.size_t(size)))
	if samples == nil {
		return nil, errors.New(fmt.Sprintf("Could not allocate %d bytes for samples buffer", size))
	}

	//setup the data pointers in the AVFrame
	ret := int(C.avcodec_fill_audio_frame(this.avFrame, C.int(channels), sampleFormat,
		samples, C.int(size), 0))
	if ret < 0 {
		return nil, errors.New("Could not setup audio frame")
	}
	return this, nil
}
예제 #2
0
파일: avcodec.go 프로젝트: hbdlb/goav
//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)))
}