Mercurial > libavformat.hg
changeset 5921:f8d4cc91c798 libavformat
Merge Vorbis / Theora depayloaders.
Patch by Josh Allmann <joshua DOT allmann AT gmail DOT com>.
author | rbultje |
---|---|
date | Thu, 01 Apr 2010 21:43:22 +0000 |
parents | c07680f39362 |
children | 1141ba6decd2 |
files | Makefile rtpdec_vorbis.c rtpdec_vorbis.h rtpdec_xiph.c rtpdec_xiph.h rtsp.c |
diffstat | 6 files changed, 18 insertions(+), 268 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Thu Apr 01 21:42:10 2010 +0000 +++ b/Makefile Thu Apr 01 21:43:22 2010 +0000 @@ -225,7 +225,6 @@ rtpdec_asf.o \ rtpdec_h263.o \ rtpdec_h264.o \ - rtpdec_vorbis.o \ rtpdec_xiph.o OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o OBJS-$(CONFIG_SHORTEN_DEMUXER) += raw.o id3v2.o
--- a/rtpdec_vorbis.c Thu Apr 01 21:42:10 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,218 +0,0 @@ -/* - * RTP Vorbis Protocol (RFC5215) - * Copyright (c) 2009 Colin McQuillan - * - * 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 libavformat/rtpdec_vorbis.c - * @brief Vorbis / RTP Code (RFC 5215) - * @author Colin McQuillan <m.niloc@gmail.com> - */ - -#include "libavutil/base64.h" -#include "libavutil/avstring.h" -#include "libavcodec/bytestream.h" - -#include <assert.h> - -#include "rtpdec.h" -#include "rtpdec_vorbis.h" - -/** - * RTP/Vorbis specific private data. - */ -struct PayloadContext { - unsigned ident; ///< 24-bit stream configuration identifier -}; - -/** - * Length encoding described in RFC5215 section 3.1.1. - */ -static int get_base128(const uint8_t ** buf, const uint8_t * buf_end) -{ - int n = 0; - for (; *buf < buf_end; ++*buf) { - n <<= 7; - n += **buf & 0x7f; - if (!(**buf & 0x80)) { - ++*buf; - return n; - } - } - return 0; -} - -/** - * Out-of-band headers, described in RFC 5251 section 3.2.1 - */ -static unsigned int -parse_packed_headers(const uint8_t * packed_headers, - const uint8_t * packed_headers_end, - AVCodecContext * codec, PayloadContext * vorbis_data) -{ - unsigned num_packed, num_headers, length, length1, length2; - uint8_t *ptr; - - num_packed = bytestream_get_be32(&packed_headers); - vorbis_data->ident = bytestream_get_be24(&packed_headers); - length = bytestream_get_be16(&packed_headers); - num_headers = get_base128(&packed_headers, packed_headers_end); - length1 = get_base128(&packed_headers, packed_headers_end); - length2 = get_base128(&packed_headers, packed_headers_end); - - if (num_packed != 1 || num_headers > 3) { - av_log(codec, AV_LOG_ERROR, - "Unimplemented number of headers: %d packed headers, %d headers\n", - num_packed, num_headers); - return AVERROR_PATCHWELCOME; - } - - if (packed_headers_end - packed_headers != length || - length1 > length || length2 > length - length1) { - av_log(codec, AV_LOG_ERROR, - "Bad packed header lengths (%d,%d,%d,%d)\n", length1, - length2, packed_headers_end - packed_headers, length); - return AVERROR_INVALIDDATA; - } - - ptr = codec->extradata = av_mallocz(length + length / 255 + 64); - if (!ptr) { - av_log(codec, AV_LOG_ERROR, "Out of memory"); - return AVERROR_NOMEM; - } - *ptr++ = 2; - ptr += av_xiphlacing(ptr, length1); - ptr += av_xiphlacing(ptr, length2); - memcpy(ptr, packed_headers, length); - ptr += length; - codec->extradata_size = ptr - codec->extradata; - - return 0; -} - -int -ff_vorbis_parse_fmtp_config(AVCodecContext * codec, - void *vorbis_data, char *attr, char *value) -{ - int result = 0; - assert(codec->codec_id == CODEC_ID_VORBIS); - assert(vorbis_data); - - // The configuration value is a base64 encoded packed header - if (!strcmp(attr, "configuration")) { - uint8_t *decoded_packet = NULL; - int packet_size; - size_t decoded_alloc = strlen(value) / 4 * 3 + 4; - - if (decoded_alloc <= INT_MAX) { - decoded_packet = av_malloc(decoded_alloc); - if (decoded_packet) { - packet_size = - av_base64_decode(decoded_packet, value, decoded_alloc); - - result = parse_packed_headers - (decoded_packet, decoded_packet + packet_size, codec, - vorbis_data); - } else { - av_log(codec, AV_LOG_ERROR, - "Out of memory while decoding SDP configuration.\n"); - result = AVERROR_NOMEM; - } - } else { - av_log(codec, AV_LOG_ERROR, "Packet too large\n"); - result = AVERROR_INVALIDDATA; - } - av_free(decoded_packet); - } - return result; -} - -static PayloadContext *vorbis_new_context(void) -{ - return av_mallocz(sizeof(PayloadContext)); -} - -static void vorbis_free_context(PayloadContext * data) -{ - av_free(data); -} - -/** - * Handle payload as described in RFC 5215 section 2.2 - */ -static int -vorbis_handle_packet(AVFormatContext * ctx, - PayloadContext * data, - AVStream * st, - AVPacket * pkt, - uint32_t * timestamp, - const uint8_t * buf, int len, int flags) -{ - int ident, fragmented, vdt, num_pkts, pkt_len; - - if (len < 6) { - av_log(ctx, AV_LOG_ERROR, "Invalid %d byte packet\n", len); - return AVERROR_INVALIDDATA; - } - - ident = AV_RB24(buf); - fragmented = buf[3] >> 6; - vdt = (buf[3] >> 4) & 3; - num_pkts = buf[3] & 7; - pkt_len = AV_RB16(buf + 4); - - if (pkt_len > len - 6) { - av_log(ctx, AV_LOG_ERROR, - "Invalid packet length %d in %d byte packet\n", pkt_len, - len); - return AVERROR_INVALIDDATA; - } - - if (ident != data->ident) { - av_log(ctx, AV_LOG_ERROR, - "Unimplemented Vorbis SDP configuration change detected\n"); - return AVERROR_PATCHWELCOME; - } - - if (fragmented != 0 || vdt != 0 || num_pkts != 1) { - av_log(ctx, AV_LOG_ERROR, - "Unimplemented RTP Vorbis packet settings (%d,%d,%d)\n", - fragmented, vdt, num_pkts); - return AVERROR_PATCHWELCOME; - } - - if (av_new_packet(pkt, pkt_len)) { - av_log(ctx, AV_LOG_ERROR, "Out of memory.\n"); - return AVERROR_NOMEM; - } - - memcpy(pkt->data, buf + 6, pkt_len); - pkt->stream_index = st->index; - return 0; -} - -RTPDynamicProtocolHandler ff_vorbis_dynamic_handler = { - .enc_name = "vorbis", - .codec_type = AVMEDIA_TYPE_AUDIO, - .codec_id = CODEC_ID_VORBIS, - .parse_sdp_a_line = NULL, - .open = vorbis_new_context, - .close = vorbis_free_context, - .parse_packet = vorbis_handle_packet -};
--- a/rtpdec_vorbis.h Thu Apr 01 21:42:10 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * RTP Vorbis Protocol (RFC 5215) - * Copyright (c) 2009 Colin McQuillan - * - * 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_VORBIS_H -#define AVFORMAT_RTPDEC_VORBIS_H - -#include "libavcodec/avcodec.h" -#include "rtpdec.h" - -/** - * Handle a Vorbis-specific FMTP parameter - * - * @param codec The context of the codec - * @param ctx Private Vorbis RTP context - * @param attr Format-specific parameter name - * @param value Format-specific paremeter value - */ -int -ff_vorbis_parse_fmtp_config(AVCodecContext * codec, - void *ctx, char *attr, char *value); - -/** - * Vorbis RTP callbacks. - */ -extern RTPDynamicProtocolHandler ff_vorbis_dynamic_handler; - -#endif /* AVFORMAT_RTPDEC_VORBIS_H */
--- a/rtpdec_xiph.c Thu Apr 01 21:42:10 2010 +0000 +++ b/rtpdec_xiph.c Thu Apr 01 21:43:22 2010 +0000 @@ -1,5 +1,6 @@ /* * Xiph RTP Protocols + * Copyright (c) 2009 Colin McQuillian * Copyright (c) 2010 Josh Allmann * * This file is part of FFmpeg. @@ -22,6 +23,7 @@ /** * @file libavformat/rtpdec_xiph.c * @brief Xiph / RTP Code + * @author Colin McQuillan <m.niloc@gmail.com> * @author Josh Allmann <joshua.allmann@gmail.com> */ @@ -385,3 +387,13 @@ .close = xiph_free_context, .parse_packet = xiph_handle_packet }; + +RTPDynamicProtocolHandler ff_vorbis_dynamic_handler = { + .enc_name = "vorbis", + .codec_type = CODEC_TYPE_AUDIO, + .codec_id = CODEC_ID_VORBIS, + .parse_sdp_a_line = xiph_parse_sdp_line, + .open = xiph_new_context, + .close = xiph_free_context, + .parse_packet = xiph_handle_packet +};
--- a/rtpdec_xiph.h Thu Apr 01 21:42:10 2010 +0000 +++ b/rtpdec_xiph.h Thu Apr 01 21:43:22 2010 +0000 @@ -1,6 +1,7 @@ /* * Xiph RTP Protocols * Based off RFC 5215 (Vorbis RTP) and the Theora RTP draft. + * Copyright (c) 2009 Colin McQuillian * Copyright (c) 2010 Josh Allmann * * This file is part of FFmpeg. @@ -31,4 +32,9 @@ */ extern RTPDynamicProtocolHandler ff_theora_dynamic_handler; +/** + * Vorbis RTP callbacks. + */ +extern RTPDynamicProtocolHandler ff_vorbis_dynamic_handler; + #endif /* AVFORMAT_RTPDEC_XIPH_H */
--- a/rtsp.c Thu Apr 01 21:42:10 2010 +0000 +++ b/rtsp.c Thu Apr 01 21:43:22 2010 +0000 @@ -37,7 +37,6 @@ #include "rtpdec.h" #include "rdt.h" #include "rtpdec_asf.h" -#include "rtpdec_vorbis.h" //#define DEBUG //#define DEBUG_RTP_TCP @@ -217,9 +216,6 @@ hex_to_data(codec->extradata, value); } break; - case CODEC_ID_VORBIS: - ff_vorbis_parse_fmtp_config(codec, ctx, attr, value); - break; default: break; }