summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Volkert <thomas@homer-conferencing.com>2015-02-21 18:35:50 +0100
committerMartin Storsjö <martin@martin.st>2015-02-22 23:01:55 +0200
commitc99915f7c74ce1249d8633cb6fd09035b8d84db7 (patch)
tree3ba03194d80b2ba1ad3a5084057bd45d5974ff6b
parent44dc138ed29c4dfbaf57ebc774da4c75ef113ca4 (diff)
rtpdec: DV depacketizer (RFC 6469)
(tested with live555 RTSP server) Signed-off-by: Martin Storsjö <martin@martin.st>
-rw-r--r--Changelog1
-rw-r--r--libavformat/Makefile1
-rw-r--r--libavformat/rtpdec.c1
-rw-r--r--libavformat/rtpdec_dv.c169
-rw-r--r--libavformat/rtpdec_formats.h1
-rw-r--r--libavformat/version.h2
6 files changed, 174 insertions, 1 deletions
diff --git a/Changelog b/Changelog
index 66789824de..b63a8b74c6 100644
--- a/Changelog
+++ b/Changelog
@@ -18,6 +18,7 @@ version <next>:
- DSS SP decoder and DSS demuxer
- RTP depacketizer for AC3 payload format (RFC 4184)
- RTP depacketizer for loss tolerant payload format for MP3 audio (RFC 5219)
+- RTP depacketizer for DV (RFC 6469)
version 11:
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 1be16263f9..387926f0d2 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -31,6 +31,7 @@ OBJS-$(CONFIG_RTPDEC) += rdt.o \
rtpdec_ac3.o \
rtpdec_amr.o \
rtpdec_asf.o \
+ rtpdec_dv.o \
rtpdec_g726.o \
rtpdec_h261.o \
rtpdec_h263.o \
diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index ee11bf9028..8858b133e8 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -63,6 +63,7 @@ void ff_register_rtp_dynamic_payload_handlers(void)
ff_register_dynamic_payload_handler(&ff_ac3_dynamic_handler);
ff_register_dynamic_payload_handler(&ff_amr_nb_dynamic_handler);
ff_register_dynamic_payload_handler(&ff_amr_wb_dynamic_handler);
+ ff_register_dynamic_payload_handler(&ff_dv_dynamic_handler);
ff_register_dynamic_payload_handler(&ff_g726_16_dynamic_handler);
ff_register_dynamic_payload_handler(&ff_g726_24_dynamic_handler);
ff_register_dynamic_payload_handler(&ff_g726_32_dynamic_handler);
diff --git a/libavformat/rtpdec_dv.c b/libavformat/rtpdec_dv.c
new file mode 100644
index 0000000000..f64b06fcfc
--- /dev/null
+++ b/libavformat/rtpdec_dv.c
@@ -0,0 +1,169 @@
+/*
+ * RTP parser for DV payload format (RFC 6469)
+ * Copyright (c) 2015 Thomas Volkert <thomas@homer-conferencing.com>
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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 Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/avstring.h"
+
+#include "libavcodec/bytestream.h"
+
+#include "rtpdec_formats.h"
+
+struct PayloadContext {
+ AVIOContext *buf;
+ uint32_t timestamp;
+ int bundled_audio;
+};
+
+static av_cold PayloadContext *dv_new_context(void)
+{
+ return av_mallocz(sizeof(PayloadContext));
+}
+
+static void dv_free_dyn_buffer(AVIOContext **dyn_buf)
+{
+ uint8_t *ptr_dyn_buffer;
+ avio_close_dyn_buf(*dyn_buf, &ptr_dyn_buffer);
+ av_free(ptr_dyn_buffer);
+ *dyn_buf = NULL;
+}
+
+static av_cold void dv_free_context(PayloadContext *data)
+{
+ dv_free_dyn_buffer(&data->buf);
+ av_free(data);
+}
+
+static av_cold int dv_init(AVFormatContext *ctx, int st_index,
+ PayloadContext *data)
+{
+ av_dlog(ctx, "dv_init() for stream %d\n", st_index);
+
+ if (st_index < 0)
+ return 0;
+
+ ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
+
+ return 0;
+}
+
+static av_cold int dv_sdp_parse_fmtp_config(AVFormatContext *s,
+ AVStream *stream,
+ PayloadContext *dv_data,
+ char *attr, char *value)
+{
+ /* does the DV stream include audio? */
+ if (!strcmp(attr, "audio") && !strcmp(value, "bundled"))
+ dv_data->bundled_audio = 1;
+
+ /* extract the DV profile */
+ if (!strcmp(attr, "encode")) {
+ /* SD-VCR/525-60 */
+ /* SD-VCR/625-50 */
+ /* HD-VCR/1125-60 */
+ /* HD-VCR/1250-50 */
+ /* SDL-VCR/525-60 */
+ /* SDL-VCR/625-50 */
+ /* 314M-25/525-60 */
+ /* 314M-25/625-50 */
+ /* 314M-50/525-60 */
+ /* 314M-50/625-50 */
+ /* 370M/1080-60i */
+ /* 370M/1080-50i */
+ /* 370M/720-60p */
+ /* 370M/720-50p */
+ /* 306M/525-60 (for backward compatibility) */
+ /* 306M/625-50 (for backward compatibility) */
+ }
+
+ return 0;
+}
+
+static av_cold int dv_parse_sdp_line(AVFormatContext *ctx, int st_index,
+ PayloadContext *dv_data, const char *line)
+{
+ AVStream *current_stream;
+ const char *sdp_line_ptr = line;
+
+ if (st_index < 0)
+ return 0;
+
+ current_stream = ctx->streams[st_index];
+
+ if (av_strstart(sdp_line_ptr, "fmtp:", &sdp_line_ptr)) {
+ return ff_parse_fmtp(ctx, current_stream, dv_data, sdp_line_ptr,
+ dv_sdp_parse_fmtp_config);
+ }
+
+ return 0;
+}
+
+static int dv_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_dv_ctx,
+ AVStream *st, AVPacket *pkt, uint32_t *timestamp,
+ const uint8_t *buf, int len, uint16_t seq,
+ int flags)
+{
+ int res = 0;
+
+ /* drop data of previous packets in case of non-continuous (lossy) packet stream */
+ if (rtp_dv_ctx->buf && rtp_dv_ctx->timestamp != *timestamp) {
+ dv_free_dyn_buffer(&rtp_dv_ctx->buf);
+ }
+
+ /* sanity check for size of input packet: 1 byte payload at least */
+ if (len < 1) {
+ av_log(ctx, AV_LOG_ERROR, "Too short RTP/DV packet, got %d bytes\n", len);
+ return AVERROR_INVALIDDATA;
+ }
+
+ /* start frame buffering with new dynamic buffer */
+ if (!rtp_dv_ctx->buf) {
+ res = avio_open_dyn_buf(&rtp_dv_ctx->buf);
+ if (res < 0)
+ return res;
+ /* update the timestamp in the frame packet with the one from the RTP packet */
+ rtp_dv_ctx->timestamp = *timestamp;
+ }
+
+ /* write the fragment to the dyn. buffer */
+ avio_write(rtp_dv_ctx->buf, buf, len);
+
+ /* RTP marker bit means: last fragment of current frame was received;
+ otherwise, an additional fragment is needed for the current frame */
+ if (!(flags & RTP_FLAG_MARKER))
+ return AVERROR(EAGAIN);
+
+ /* close frame buffering and create resulting A/V packet */
+ res = ff_rtp_finalize_packet(pkt, &rtp_dv_ctx->buf, st->index);
+ if (res < 0)
+ return res;
+
+ return 0;
+}
+
+RTPDynamicProtocolHandler ff_dv_dynamic_handler = {
+ .enc_name = "DV",
+ .codec_type = AVMEDIA_TYPE_VIDEO,
+ .codec_id = AV_CODEC_ID_DVVIDEO,
+ .init = dv_init,
+ .parse_sdp_a_line = dv_parse_sdp_line,
+ .alloc = dv_new_context,
+ .free = dv_free_context,
+ .parse_packet = dv_handle_packet
+};
diff --git a/libavformat/rtpdec_formats.h b/libavformat/rtpdec_formats.h
index d484192d85..1cc3bab38b 100644
--- a/libavformat/rtpdec_formats.h
+++ b/libavformat/rtpdec_formats.h
@@ -46,6 +46,7 @@ int ff_h264_handle_aggregated_packet(AVFormatContext *ctx, AVPacket *pkt,
extern RTPDynamicProtocolHandler ff_ac3_dynamic_handler;
extern RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler;
extern RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler;
+extern RTPDynamicProtocolHandler ff_dv_dynamic_handler;
extern RTPDynamicProtocolHandler ff_g726_16_dynamic_handler;
extern RTPDynamicProtocolHandler ff_g726_24_dynamic_handler;
extern RTPDynamicProtocolHandler ff_g726_32_dynamic_handler;
diff --git a/libavformat/version.h b/libavformat/version.h
index 3ec378ea65..d99f75d74d 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@
#include "libavutil/version.h"
#define LIBAVFORMAT_VERSION_MAJOR 56
-#define LIBAVFORMAT_VERSION_MINOR 14
+#define LIBAVFORMAT_VERSION_MINOR 15
#define LIBAVFORMAT_VERSION_MICRO 0
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \