diff options
author | Josh Allmann <joshua.allmann@gmail.com> | 2010-07-01 20:12:58 +0000 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2010-07-01 20:12:58 +0000 |
commit | 4449df6baf245465715844ce96886600128b3a83 (patch) | |
tree | 4da520ade0f75dc8a90eb213bc0c9cde1c006ddf /libavformat | |
parent | 2b4abbd6f5f065a41d48622154cb7fd045247f2f (diff) | |
download | ffmpeg-streaming-4449df6baf245465715844ce96886600128b3a83.zip ffmpeg-streaming-4449df6baf245465715844ce96886600128b3a83.tar.gz |
Add RTP depacketization of SVQ3
Patch by Josh Allmann, joshua dot allmann at gmail
Originally committed as revision 23941 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/Makefile | 1 | ||||
-rw-r--r-- | libavformat/avformat.h | 2 | ||||
-rw-r--r-- | libavformat/rtpdec.c | 2 | ||||
-rw-r--r-- | libavformat/rtpdec_svq3.c | 138 | ||||
-rw-r--r-- | libavformat/rtpdec_svq3.h | 33 |
5 files changed, 175 insertions, 1 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile index 2977673..5291fe3 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -229,6 +229,7 @@ OBJS-$(CONFIG_SDP_DEMUXER) += rtsp.o \ rtpdec_h263.o \ rtpdec_h264.o \ rtpdec_mpeg4.o \ + rtpdec_svq3.o \ rtpdec_xiph.o OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o OBJS-$(CONFIG_SHORTEN_DEMUXER) += raw.o id3v2.o diff --git a/libavformat/avformat.h b/libavformat/avformat.h index a7204fc..49397ce 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -22,7 +22,7 @@ #define AVFORMAT_AVFORMAT_H #define LIBAVFORMAT_VERSION_MAJOR 52 -#define LIBAVFORMAT_VERSION_MINOR 71 +#define LIBAVFORMAT_VERSION_MINOR 72 #define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index 38a4c5b..ca06bff 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -35,6 +35,7 @@ #include "rtpdec_h263.h" #include "rtpdec_h264.h" #include "rtpdec_mpeg4.h" +#include "rtpdec_svq3.h" #include "rtpdec_xiph.h" //#define DEBUG @@ -68,6 +69,7 @@ void av_register_rtp_dynamic_payload_handlers(void) ff_register_dynamic_payload_handler(&ff_h264_dynamic_handler); ff_register_dynamic_payload_handler(&ff_vorbis_dynamic_handler); ff_register_dynamic_payload_handler(&ff_theora_dynamic_handler); + ff_register_dynamic_payload_handler(&ff_svq3_dynamic_handler); ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfv_handler); ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfa_handler); diff --git a/libavformat/rtpdec_svq3.c b/libavformat/rtpdec_svq3.c new file mode 100644 index 0000000..a285036 --- /dev/null +++ b/libavformat/rtpdec_svq3.c @@ -0,0 +1,138 @@ +/* + * Sorenson-3 (SVQ3/SV3V) payload for RTP + * Copyright (c) 2010 Ronald S. Bultje + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * @brief RTP support for the SV3V (SVQ3) payload + * (http://wiki.multimedia.cx/index.php?title=Sorenson_Video_3#Packetization) + * @author Ronald S. Bultje <rbultje@ronald.bitfreak.net> + */ + +#include <string.h> +#include <libavcodec/get_bits.h> +#include "rtp.h" +#include "rtpdec.h" +#include "rtpdec_svq3.h" + +struct PayloadContext { + ByteIOContext *pktbuf; + int64_t timestamp; + int is_keyframe; +}; + +/** return 0 on packet, <0 on partial packet or error... */ +static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv, + AVStream *st, AVPacket *pkt, + uint32_t *timestamp, + const uint8_t *buf, int len, int flags) +{ + int config_packet, start_packet, end_packet; + + if (len < 2) + return AVERROR_INVALIDDATA; + + config_packet = buf[0] & 0x40; + start_packet = buf[0] & 0x20; + end_packet = buf[0] & 0x10; + buf += 2; // ignore buf[1] + len -= 2; + + if (config_packet) { + + av_freep(&st->codec->extradata); + st->codec->extradata_size = 0; + + if (len < 2 || !(st->codec->extradata = + av_malloc(len + 8 + FF_INPUT_BUFFER_PADDING_SIZE))) + return AVERROR_INVALIDDATA; + + st->codec->extradata_size = len + 8; + memcpy(st->codec->extradata, "SEQH", 4); + AV_WB32(st->codec->extradata + 4, len); + memcpy(st->codec->extradata + 8, buf, len); + + /* We set codec_id to CODEC_ID_NONE initially to + * delay decoder initialization since extradata is + * carried within the RTP stream, not SDP. Here, + * by setting codec_id to CODEC_ID_SVQ3, we are signalling + * to the decoder that it is OK to initialize. */ + st->codec->codec_id = CODEC_ID_SVQ3; + + return AVERROR(EAGAIN); + } + + if (start_packet) { + int res; + + if (sv->pktbuf) { + uint8_t *tmp; + url_close_dyn_buf(sv->pktbuf, &tmp); + av_free(tmp); + } + if ((res = url_open_dyn_buf(&sv->pktbuf)) < 0) + return res; + sv->timestamp = *timestamp; + sv->is_keyframe = flags & RTP_FLAG_KEY; + } + + if (!sv->pktbuf) + return AVERROR_INVALIDDATA; + + put_buffer(sv->pktbuf, buf, len); + + if (end_packet) { + av_init_packet(pkt); + pkt->stream_index = st->index; + pkt->pts = sv->timestamp; + pkt->flags = sv->is_keyframe ? AV_PKT_FLAG_KEY : 0; + pkt->size = url_close_dyn_buf(sv->pktbuf, &pkt->data); + pkt->destruct = av_destruct_packet; + sv->pktbuf = NULL; + return 0; + } + + return AVERROR(EAGAIN); +} + +static PayloadContext *svq3_extradata_new(void) +{ + return av_mallocz(sizeof(PayloadContext)); +} + +static void svq3_extradata_free(PayloadContext *sv) +{ + if (sv->pktbuf) { + uint8_t *buf; + url_close_dyn_buf(sv->pktbuf, &buf); + av_free(buf); + } + av_free(sv); +} + +RTPDynamicProtocolHandler ff_svq3_dynamic_handler = { + "X-SV3V-ES", + CODEC_TYPE_VIDEO, + CODEC_ID_NONE, // see if (config_packet) above + NULL, // parse sdp line + svq3_extradata_new, + svq3_extradata_free, + svq3_parse_packet, +}; diff --git a/libavformat/rtpdec_svq3.h b/libavformat/rtpdec_svq3.h new file mode 100644 index 0000000..267d4d9 --- /dev/null +++ b/libavformat/rtpdec_svq3.h @@ -0,0 +1,33 @@ +/* + * Sorenson-3 (SVQ3/SV3V) payload for RTP + * Copyright (c) 2010 Ronald S. Bultje + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFORMAT_RTPDEC_SVQ3_H +#define AVFORMAT_RTPDEC_SVQ3_H + +#include "libavcodec/avcodec.h" +#include "rtpdec.h" + +/** + * Sorenson-3 RTP callbacks. + */ +extern RTPDynamicProtocolHandler ff_svq3_dynamic_handler; + +#endif /* AVFORMAT_RTPDEC_SVQ3_H */ |