diff --git a/decoder.go b/decoder.go index 5187d6d..e842648 100644 --- a/decoder.go +++ b/decoder.go @@ -127,11 +127,11 @@ func (decoder *decoder) Decode(packet *C.AVPacket) (pkt *Packet, err error) { layout := uint64(frame.channel_layout) decoder.swrContext = C.swr_alloc_set_opts(nil, // we're allocating a new context - C.long(layout), // out_ch_layout + C.longlong(layout), // out_ch_layout C.AV_SAMPLE_FMT_S16, // out_sample_fmt frame.sample_rate, // out_sample_rate - C.long(layout), // in_ch_layout + C.longlong(layout), // in_ch_layout decoder.codecCtx.sample_fmt, // in_sample_fmt frame.sample_rate, // in_sample_rate @@ -169,11 +169,11 @@ func (decoder *decoder) Decode(packet *C.AVPacket) (pkt *Packet, err error) { layout := uint64(frame.channel_layout) decoder.swrContext = C.swr_alloc_set_opts(nil, // we're allocating a new context - C.long(layout), // out_ch_layout + C.longlong(layout), // out_ch_layout C.AV_SAMPLE_FMT_S16, // out_sample_fmt frame.sample_rate, // out_sample_rate - C.long(layout), // in_ch_layout + C.longlong(layout), // in_ch_layout decoder.codecCtx.sample_fmt, // in_sample_fmt frame.sample_rate, // in_sample_rate diff --git a/ffmpeg.c b/ffmpeg.c index 4814001..22e83f8 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -37,7 +37,7 @@ int rtsp_encode(AVCodecContext *avctx, AVPacket *pkt, int *got_packet, AVFrame * } int rtsp_avcodec_encode_wav(AVCodecContext *pCodecCtx, AVFrame *pFrame,AVPacket *packet) { - AVCodec *wavCodec = avcodec_find_encoder(AV_CODEC_ID_PCM_S16LE ); + const AVCodec *wavCodec = avcodec_find_encoder(AV_CODEC_ID_PCM_S16LE ); int ret = -1; if (!wavCodec) { @@ -76,7 +76,7 @@ int rtsp_avcodec_encode_wav(AVCodecContext *pCodecCtx, AVFrame *pFrame,AVPacket } int rtsp_avcodec_encode_jpeg(AVCodecContext *pCodecCtx, AVFrame *pFrame,AVPacket *packet) { - AVCodec *jpegCodec = avcodec_find_encoder(AV_CODEC_ID_MJPEG); + const AVCodec *jpegCodec = avcodec_find_encoder(AV_CODEC_ID_MJPEG); int ret = -1; if (!jpegCodec) { diff --git a/stream.go b/stream.go index d6cb004..a512a29 100644 --- a/stream.go +++ b/stream.go @@ -35,6 +35,8 @@ func New(uri string) (stream *Stream) { stream.decoders = make(map[int]*decoder) stream.formatCtx = C.avformat_alloc_context() + C.av_log_set_level(C.AV_LOG_QUIET) + runtime.SetFinalizer(stream, free) return } @@ -63,7 +65,7 @@ func (e ErrTimeout) Error() string { func CErr2Str(code C.int) string { buf := make([]byte, 64) - C.av_strerror(code, (*C.char)(unsafe.Pointer(&buf[0])), C.ulong(len(buf))) + C.av_strerror(code, (*C.char)(unsafe.Pointer(&buf[0])), C.ulonglong(len(buf))) return string(buf) } @@ -79,6 +81,14 @@ func (stream *Stream) Setup(t Type) (err error) { udp := C.CString("udp") defer C.free(unsafe.Pointer(udp)) + timeoutKey := C.CString("timeout") + defer C.free(unsafe.Pointer(timeoutKey)) + + timeout := C.CString("10000000") + defer C.free(unsafe.Pointer(timeout)) + + C.av_dict_set(&stream.dictionary, timeoutKey, timeout, 0) + switch t { case Tcp: C.av_dict_set(&stream.dictionary, transport, tcp, 0) @@ -127,12 +137,10 @@ func (stream *Stream) Setup(t Type) (err error) { } func (stream *Stream) ReadPacket() (pkt *Packet, err error) { - var packet C.AVPacket - C.av_init_packet(&packet) - - defer C.av_packet_unref(&packet) + packet := C.av_packet_alloc() + defer C.av_packet_free(&packet) - if cerr := C.av_read_frame(stream.formatCtx, &packet); int(cerr) != 0 { + if cerr := C.av_read_frame(stream.formatCtx, packet); int(cerr) != 0 { if cerr == C.AVERROR_EOF { err = io.EOF } else if cerr == -C.ETIMEDOUT { @@ -147,7 +155,7 @@ func (stream *Stream) ReadPacket() (pkt *Packet, err error) { defer stream.mu.RUnlock() if decoder, ok := stream.decoders[int(packet.stream_index)]; ok { - return decoder.Decode(&packet) + return decoder.Decode(packet) } err = fmt.Errorf("ffmpeg: decoder not found %d", int(packet.stream_index))