[FFmpeg-devel] [PATCH] RTP depacketizer for QCELP

Stefano Sabatini stefano.sabatini-lala
Wed Dec 1 00:19:44 CET 2010


On date Monday 2010-11-29 19:19:02 +0200, Martin Storsj? encoded:
> On Mon, 29 Nov 2010, Martin Storsj? wrote:
> 
> > On Mon, 29 Nov 2010, Ronald S. Bultje wrote:
> > 
> > > On Mon, Nov 29, 2010 at 4:24 AM, Martin Storsj? <martin at martin.st> wrote:
> > > [..]
> > > 4 duplicates code, I think, can you somehow extract that?
> > 
> > Ok, I'll try to clean this up a bit.
> 
> I refactored this a bit, making both this code path and the old one much 
> cleaner, see attached. The actual depacketizer is unchanged from the 
> previous patchset.
> 
> // Martin

> From 6e6ffe120a6b14d0c0730a18149e562dc9532ce4 Mon Sep 17 00:00:00 2001
> From: Martin Storsjo <martin at martin.st>
> Date: Sun, 28 Nov 2010 14:19:48 +0200
> Subject: [PATCH 1/6] rtpdec: Add a dynamic payload handler for the x-Purevoice format, RFC 2658
> 
> This fixes roundup issue 2390.
> ---
>  Changelog                    |    1 +
>  libavformat/Makefile         |    1 +
>  libavformat/avformat.h       |    4 +-
>  libavformat/rtpdec.c         |    1 +
>  libavformat/rtpdec_formats.h |    1 +
>  libavformat/rtpdec_qcelp.c   |  232 ++++++++++++++++++++++++++++++++++++++++++
>  6 files changed, 238 insertions(+), 2 deletions(-)
>  create mode 100644 libavformat/rtpdec_qcelp.c
> 
> diff --git a/Changelog b/Changelog
> index 486978f..2ed1d10 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -60,6 +60,7 @@ version <next>:
>  - rename aspect filter to setdar, and pixelaspect to setsar
>  - IEC 61937 demuxer
>  - Mobotix .mxg demuxer
> +- RTP depacketization of QCELP
>  
>  
>  version 0.6:
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 0e450db..c65f91f 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -239,6 +239,7 @@ OBJS-$(CONFIG_RTPDEC)                    += rdt.o         \
>                                              rtpdec_h264.o \
>                                              rtpdec_latm.o \
>                                              rtpdec_mpeg4.o \
> +                                            rtpdec_qcelp.o \
>                                              rtpdec_qdm2.o \
>                                              rtpdec_qt.o   \
>                                              rtpdec_svq3.o \
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 86ef13a..3079b38 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -22,8 +22,8 @@
>  #define AVFORMAT_AVFORMAT_H
>  
>  #define LIBAVFORMAT_VERSION_MAJOR 52
> -#define LIBAVFORMAT_VERSION_MINOR 87
> -#define LIBAVFORMAT_VERSION_MICRO  1
> +#define LIBAVFORMAT_VERSION_MINOR 88
> +#define LIBAVFORMAT_VERSION_MICRO  0
>  
>  #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
>                                                 LIBAVFORMAT_VERSION_MINOR, \
> diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
> index 8311e4c..2524139 100644
> --- a/libavformat/rtpdec.c
> +++ b/libavformat/rtpdec.c
> @@ -67,6 +67,7 @@ void av_register_rtp_dynamic_payload_handlers(void)
>      ff_register_dynamic_payload_handler(&ff_svq3_dynamic_handler);
>      ff_register_dynamic_payload_handler(&ff_mp4a_latm_dynamic_handler);
>      ff_register_dynamic_payload_handler(&ff_vp8_dynamic_handler);
> +    ff_register_dynamic_payload_handler(&ff_qcelp_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_formats.h b/libavformat/rtpdec_formats.h
> index aab189e..16f5a9d 100644
> --- a/libavformat/rtpdec_formats.h
> +++ b/libavformat/rtpdec_formats.h
> @@ -41,6 +41,7 @@ extern RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler;
>  extern RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler;
>  extern RTPDynamicProtocolHandler ff_ms_rtp_asf_pfa_handler;
>  extern RTPDynamicProtocolHandler ff_ms_rtp_asf_pfv_handler;
> +extern RTPDynamicProtocolHandler ff_qcelp_dynamic_handler;
>  extern RTPDynamicProtocolHandler ff_qdm2_dynamic_handler;
>  extern RTPDynamicProtocolHandler ff_qt_rtp_aud_handler;
>  extern RTPDynamicProtocolHandler ff_qt_rtp_vid_handler;
> diff --git a/libavformat/rtpdec_qcelp.c b/libavformat/rtpdec_qcelp.c
> new file mode 100644
> index 0000000..a0e525b
> --- /dev/null
> +++ b/libavformat/rtpdec_qcelp.c
> @@ -0,0 +1,232 @@
> +/**
> + * RTP Depacketization of QCELP/PureVoice, RFC 2658
> + * Copyright (c) 2010 Martin Storsjo
> + *
> + * 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
> + */
> +
> +#include "rtpdec_formats.h"
> +#include "internal.h"
> +#include "libavutil/avstring.h"
> +#include "libavcodec/get_bits.h"
> +#include <strings.h>
> +
> +static const uint8_t frame_sizes[] = {
> +    1, 4, 8, 17, 35
> +};
> +
> +struct InterleavePacket {
> +    int pos;
> +    int size;
> +    /* The largest frame is 35 bytes, only 10 frames are allowed per
> +     * packet, and we return the first one immediately, so allocate
> +     * space for 9 frames */
> +    uint8_t data[35*9];
> +};
> +
> +struct PayloadContext {
> +    int interleave_size;
> +    int interleave_index;
> +    struct InterleavePacket group[6];
> +    int group_finished;
> +
> +    /* The maximum packet size, 10 frames of 35 bytes each, and one
> +     * packet header byte. */
> +    uint8_t  next_data[1 + 35*10];
> +    int      next_size;
> +    uint32_t next_timestamp;
> +};
> +
> +static PayloadContext *qcelp_new_context(void)
> +{
> +    return av_mallocz(sizeof(PayloadContext));
> +}
> +
> +static void qcelp_free_context(PayloadContext *data)
> +{
> +    av_free(data);
> +}
> +
> +static int return_stored_frame(AVFormatContext *ctx, PayloadContext *data,
> +                               AVStream *st, AVPacket *pkt, uint32_t *timestamp,
> +                               const uint8_t *buf, int len);
> +
> +static int store_packet(AVFormatContext *ctx, PayloadContext *data,
> +                        AVStream *st, AVPacket *pkt, uint32_t *timestamp,
> +                        const uint8_t *buf, int len)
> +{
> +    int interleave_size, interleave_index;
> +    int frame_size, ret;
> +    struct InterleavePacket* ip;
> +

> +    if (len < 2)
> +        return AVERROR_INVALIDDATA;
> +
> +    interleave_size  = (buf[0] >> 3) & 7;
> +    interleave_index =  buf[0]       & 7;
> +
> +    if (interleave_size > 5) {
> +        av_log(ctx, AV_LOG_ERROR, "Invalid interleave size %d\n",
> +                                   interleave_size);
> +        return AVERROR_INVALIDDATA;
> +    }
> +    if (interleave_index > interleave_size) {
> +        av_log(ctx, AV_LOG_ERROR, "Invalid interleave index %d/%d\n",
> +                                   interleave_index, interleave_size);
> +        return AVERROR_INVALIDDATA;

AVERROR_INVALIDDATA is deprecated -> AVERROR(INVALIDDATA).

Ciao
-- 
FFmpeg = Fancy and Fascinating Mournful Purposeless Eretic Genius



More information about the ffmpeg-devel mailing list