cstring() 처리 추가

master v1.0.27
Baik S. Hyun 2 years ago
parent 8ac9773f82
commit 9fa99c538a

@ -78,12 +78,34 @@ func (self *Resampler) Resample(in av.AudioFrame) (out av.AudioFrame, err error)
self.inSampleRate = in.SampleRate
self.inChannelLayout = in.ChannelLayout
avr := C.swr_alloc()
cs1 := C.CString("in_channel_layout")
cs2 := C.CString("out_channel_layout")
cs3 := C.CString("in_sample_rate")
cs4 := C.CString("out_sample_rate")
cs5 := C.CString("in_sample_fmt")
cs6 := C.CString("out_sample_fmt")
defer C.free(unsafe.Pointer(cs1))
defer C.free(unsafe.Pointer(cs2))
defer C.free(unsafe.Pointer(cs3))
defer C.free(unsafe.Pointer(cs4))
defer C.free(unsafe.Pointer(cs5))
defer C.free(unsafe.Pointer(cs6))
C.av_opt_set_int(unsafe.Pointer(avr), cs1, C.int64_t(channelLayoutAV2FF(self.inChannelLayout)), 0)
C.av_opt_set_int(unsafe.Pointer(avr), cs2, C.int64_t(channelLayoutAV2FF(self.OutChannelLayout)), 0)
C.av_opt_set_int(unsafe.Pointer(avr), cs3, C.int64_t(self.inSampleRate), 0)
C.av_opt_set_int(unsafe.Pointer(avr), cs4, C.int64_t(self.OutSampleRate), 0)
C.av_opt_set_int(unsafe.Pointer(avr), cs5, C.int64_t(sampleFormatAV2FF(self.inSampleFormat)), 0)
C.av_opt_set_int(unsafe.Pointer(avr), cs6, C.int64_t(sampleFormatAV2FF(self.OutSampleFormat)), 0)
/*
C.av_opt_set_int(unsafe.Pointer(avr), C.CString("in_channel_layout"), C.int64_t(channelLayoutAV2FF(self.inChannelLayout)), 0)
C.av_opt_set_int(unsafe.Pointer(avr), C.CString("out_channel_layout"), C.int64_t(channelLayoutAV2FF(self.OutChannelLayout)), 0)
C.av_opt_set_int(unsafe.Pointer(avr), C.CString("in_sample_rate"), C.int64_t(self.inSampleRate), 0)
C.av_opt_set_int(unsafe.Pointer(avr), C.CString("out_sample_rate"), C.int64_t(self.OutSampleRate), 0)
C.av_opt_set_int(unsafe.Pointer(avr), C.CString("in_sample_fmt"), C.int64_t(sampleFormatAV2FF(self.inSampleFormat)), 0)
C.av_opt_set_int(unsafe.Pointer(avr), C.CString("out_sample_fmt"), C.int64_t(sampleFormatAV2FF(self.OutSampleFormat)), 0)
*/
C.swr_init(avr)
self.avr = avr
}
@ -238,7 +260,10 @@ func (self *AudioEncoder) SetOption(key string, val interface{}) (err error) {
sval := fmt.Sprint(val)
if key == "profile" {
ff.profile = C.avcodec_profile_name_to_int(ff.codec, C.CString(sval))
cs1 := C.CString(sval)
defer C.free(unsafe.Pointer(cs1))
ff.profile = C.avcodec_profile_name_to_int(ff.codec, cs1)
//ff.profile = C.avcodec_profile_name_to_int(ff.codec, C.CString(sval))
if ff.profile == C.FF_PROFILE_UNKNOWN {
err = fmt.Errorf("ffmpeg: profile `%s` invalid", sval)
return
@ -246,13 +271,19 @@ func (self *AudioEncoder) SetOption(key string, val interface{}) (err error) {
return
}
C.av_dict_set(&ff.options, C.CString(key), C.CString(sval), 0)
cs2 := C.CString(sval)
defer C.free(unsafe.Pointer(cs2))
C.av_dict_set(&ff.options, C.CString(key), cs2, 0)
//C.av_dict_set(&ff.options, C.CString(key), C.CString(sval), 0)
return
}
func (self *AudioEncoder) GetOption(key string, val interface{}) (err error) {
ff := &self.ff.ff
entry := C.av_dict_get(ff.options, C.CString(key), nil, 0)
cs1 := C.CString(key)
defer C.free(unsafe.Pointer(cs1))
entry := C.av_dict_get(ff.options, cs1, nil, 0)
//entry := C.av_dict_get(ff.options, C.CString(key), nil, 0)
if entry == nil {
err = fmt.Errorf("ffmpeg: GetOption failed: `%s` not exists", key)
return
@ -650,7 +681,10 @@ func NewAudioEncoderByCodecType(typ av.CodecType) (enc *AudioEncoder, err error)
func NewAudioEncoderByName(name string) (enc *AudioEncoder, err error) {
_enc := &AudioEncoder{}
codec := C.avcodec_find_encoder_by_name(C.CString(name))
cs1 := C.CString(name)
defer C.free(unsafe.Pointer(cs1))
codec := C.avcodec_find_encoder_by_name(cs1)
//codec := C.avcodec_find_encoder_by_name(C.CString(name))
if codec == nil || C.avcodec_get_type(codec.id) != C.AVMEDIA_TYPE_AUDIO {
err = fmt.Errorf("ffmpeg: cannot find audio encoder name=%s", name)
return

@ -28,11 +28,17 @@ const (
)
func HasEncoder(name string) bool {
return C.avcodec_find_encoder_by_name(C.CString(name)) != nil
cs1 := C.CString(name)
defer C.free(unsafe.Pointer(cs1))
return C.avcodec_find_encoder_by_name(cs1) != nil
//return C.avcodec_find_encoder_by_name(C.CString(name)) != nil
}
func HasDecoder(name string) bool {
return C.avcodec_find_decoder_by_name(C.CString(name)) != nil
cs1 := C.CString(name)
defer C.free(unsafe.Pointer(cs1))
return C.avcodec_find_decoder_by_name(cs1) != nil
//return C.avcodec_find_decoder_by_name(C.CString(name)) != nil
}
//func EncodersList() []string

@ -183,7 +183,10 @@ func NewVideoDecoder(stream av.CodecData) (dec *VideoDecoder, err error) {
return
}
c := C.avcodec_find_decoder_by_name(C.CString("h264_cuvid"))
cs1 := C.CString("h264_cuvid")
defer C.free(unsafe.Pointer(cs1))
c := C.avcodec_find_decoder_by_name(cs1)
//c := C.avcodec_find_decoder_by_name(C.CString("h264_cuvid"))
if c == nil || C.avcodec_get_type(id) != C.AVMEDIA_TYPE_VIDEO {
c = C.avcodec_find_decoder(id)
if c == nil || C.avcodec_get_type(id) != C.AVMEDIA_TYPE_VIDEO {

Loading…
Cancel
Save