mirror of
https://github.com/Danile71/go-rtsp.git
synced 2025-09-26 20:21:15 +08:00
Removed use of av_init_packet as it is deprecated in new FFMPEG version (#7)
* Removed use of av_init_packet as it is deprecated in new FFMPEG version Changed LogLevel to AV_LOG_QUIET Added socket TCP I/O timeout value 10s * Fix type layout in swr_alloc_set_opts
This commit is contained in:
@@ -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
|
||||
|
||||
|
4
ffmpeg.c
4
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) {
|
||||
|
22
stream.go
22
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)
|
||||
packet := C.av_packet_alloc()
|
||||
defer C.av_packet_free(&packet)
|
||||
|
||||
defer C.av_packet_unref(&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))
|
||||
|
Reference in New Issue
Block a user