On 24 June 2010 12:53, Luca Barbato <[email protected]> wrote: > On 06/24/2010 10:31 AM, Josh Allmann wrote: >> On 24 June 2010 00:14, Martin Storsjö <[email protected]> wrote: >>> >>> Except that, this looks good to me. Ronald, Luca, any other opinions, or >>> is this good to go? >>> >> >> Sweeet. Updated patchset is properly numbered. >> > > Two nits > > 0002 > > + * MPEG-4 Video RTP callbacks. > > Might be nice adding the rfc number there as well >
Added reference to RFC 3016. > 0004 > > +#include <strings.h> > > string_s_ ? > Needed for strcasecmp, apparently. Also fixed a related issue; strings.h is now included in patch 003 rather than 004. Josh
From e1aa2e662bc2257adc14e2aeffe1d71888177094 Mon Sep 17 00:00:00 2001 From: Josh Allmann <[email protected]> Date: Sun, 20 Jun 2010 12:25:59 -0700 Subject: [PATCH 2/6] Decouple MPEG-4 and AAC specific parts from rtsp.c. --- libavformat/Makefile | 1 + libavformat/rtpdec.c | 8 +-- libavformat/rtpdec_mpeg4.c | 125 ++++++++++++++++++++++++++++++++++++++++++++ libavformat/rtpdec_mpeg4.h | 39 ++++++++++++++ libavformat/rtsp.c | 58 -------------------- 5 files changed, 168 insertions(+), 63 deletions(-) create mode 100644 libavformat/rtpdec_mpeg4.c create mode 100644 libavformat/rtpdec_mpeg4.h diff --git a/libavformat/Makefile b/libavformat/Makefile index 156cd14..2977673 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -228,6 +228,7 @@ OBJS-$(CONFIG_SDP_DEMUXER) += rtsp.o \ rtpdec_asf.o \ rtpdec_h263.o \ rtpdec_h264.o \ + rtpdec_mpeg4.o \ rtpdec_xiph.o OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o OBJS-$(CONFIG_SHORTEN_DEMUXER) += raw.o id3v2.o diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index 0d2df59..0b316e3 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -34,6 +34,7 @@ #include "rtpdec_asf.h" #include "rtpdec_h263.h" #include "rtpdec_h264.h" +#include "rtpdec_mpeg4.h" #include "rtpdec_xiph.h" //#define DEBUG @@ -50,9 +51,6 @@ /* statistics functions */ RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler= NULL; -static RTPDynamicProtocolHandler mp4v_es_handler= {"MP4V-ES", AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG4}; -static RTPDynamicProtocolHandler mpeg4_generic_handler= {"mpeg4-generic", AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC}; - void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler) { handler->next= RTPFirstDynamicPayloadHandler; @@ -61,8 +59,8 @@ void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler) void av_register_rtp_dynamic_payload_handlers(void) { - ff_register_dynamic_payload_handler(&mp4v_es_handler); - ff_register_dynamic_payload_handler(&mpeg4_generic_handler); + ff_register_dynamic_payload_handler(&ff_mp4v_es_dynamic_handler); + ff_register_dynamic_payload_handler(&ff_mpeg4_generic_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_h263_1998_dynamic_handler); diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c new file mode 100644 index 0000000..a765f3a --- /dev/null +++ b/libavformat/rtpdec_mpeg4.c @@ -0,0 +1,125 @@ +/** + * Common code for the RTP depacketization of MPEG-4 formats. + * Copyright (c) 2010 Fabrice Bellard + * Romain Degez + * + * 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 MPEG4 / RTP Code + * @author Fabrice Bellard + * @author Romain Degez + */ + +#include "rtpdec_mpeg4.h" +#include "internal.h" +#include "libavutil/avstring.h" + +/* return the length and optionally the data */ +static int hex_to_data(uint8_t *data, const char *p) +{ + int c, len, v; + + len = 0; + v = 1; + for (;;) { + p += strspn(p, SPACE_CHARS); + if (*p == '\0') + break; + c = toupper((unsigned char) *p++); + if (c >= '0' && c <= '9') + c = c - '0'; + else if (c >= 'A' && c <= 'F') + c = c - 'A' + 10; + else + break; + v = (v << 4) | c; + if (v & 0x100) { + if (data) + data[len] = v; + len++; + v = 1; + } + } + return len; +} + +static int parse_fmtp_config(AVCodecContext * codec, char *value) +{ + /* decode the hexa encoded parameter */ + int len = hex_to_data(NULL, value); + if (codec->extradata) + av_free(codec->extradata); + codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); + if (!codec->extradata) + return AVERROR(ENOMEM); + codec->extradata_size = len; + hex_to_data(codec->extradata, value); + return 0; +} + +static int parse_sdp_line(AVFormatContext *s, int st_index, + PayloadContext *data, const char *line) +{ + const char *p; + char value[4096], attr[25]; + int res = 0; + AVCodecContext* codec = s->streams[st_index]->codec; + + if (av_strstart(line, "fmtp:", &p)) { + // remove protocol identifier + while (*p && *p == ' ') p++; // strip spaces + while (*p && *p != ' ') p++; // eat protocol identifier + while (*p && *p == ' ') p++; // strip trailing spaces + + while (ff_rtsp_next_attr_and_value(&p, + attr, sizeof(attr), + value, sizeof(value))) { + if (!strcmp(attr, "config")) { + res = parse_fmtp_config(codec, value); + + if (res < 0) + return res; + } + } + } + + return 0; + +} + +RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler = { + .enc_name = "MP4V-ES", + .codec_type = AVMEDIA_TYPE_VIDEO, + .codec_id = CODEC_ID_MPEG4, + .parse_sdp_a_line = parse_sdp_line, + .open = NULL, + .close = NULL, + .parse_packet = NULL +}; + +RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler = { + .enc_name = "mpeg4-generic", + .codec_type = AVMEDIA_TYPE_AUDIO, + .codec_id = CODEC_ID_AAC, + .parse_sdp_a_line = parse_sdp_line, + .open = NULL, + .close = NULL, + .parse_packet = NULL +}; diff --git a/libavformat/rtpdec_mpeg4.h b/libavformat/rtpdec_mpeg4.h new file mode 100644 index 0000000..06d9e57 --- /dev/null +++ b/libavformat/rtpdec_mpeg4.h @@ -0,0 +1,39 @@ +/** + * Common code for the RTP depacketization of MPEG-4 formats. + * Copyright (c) 2010 Fabrice Bellard + * Romain Degez + * + * 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_MPEG4_H +#define AVFORMAT_RTPDEC_MPEG4_H + +#include "rtpdec.h" + +/** + * MPEG-4 Video RTP callbacks. (RFC 3016) + */ +extern RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler; + +/** + * AAC RTP callbacks. (RFC 3640) + */ +extern RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler; + +#endif /* AVFORMAT_RTPDEC_MPEG4_H */ + diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index f29d727..11a9d53 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -158,59 +158,6 @@ static int sdp_parse_rtpmap(AVFormatContext *s, return 0; } -/* return the length and optionally the data */ -static int hex_to_data(uint8_t *data, const char *p) -{ - int c, len, v; - - len = 0; - v = 1; - for (;;) { - p += strspn(p, SPACE_CHARS); - if (*p == '\0') - break; - c = toupper((unsigned char) *p++); - if (c >= '0' && c <= '9') - c = c - '0'; - else if (c >= 'A' && c <= 'F') - c = c - 'A' + 10; - else - break; - v = (v << 4) | c; - if (v & 0x100) { - if (data) - data[len] = v; - len++; - v = 1; - } - } - return len; -} - -static void sdp_parse_fmtp_config(AVCodecContext * codec, void *ctx, - char *attr, char *value) -{ - switch (codec->codec_id) { - case CODEC_ID_MPEG4: - case CODEC_ID_AAC: - if (!strcmp(attr, "config")) { - /* decode the hexa encoded parameter */ - int len = hex_to_data(NULL, value); - if (codec->extradata) - av_free(codec->extradata); - codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); - if (!codec->extradata) - return; - codec->extradata_size = len; - hex_to_data(codec->extradata, value); - } - break; - default: - break; - } - return; -} - typedef struct { const char *str; uint16_t type; @@ -263,16 +210,11 @@ static void sdp_parse_fmtp(AVStream *st, const char *p) char value[4096]; int i; RTSPStream *rtsp_st = st->priv_data; - AVCodecContext *codec = st->codec; RTPPayloadData *rtp_payload_data = &rtsp_st->rtp_payload_data; /* loop on each attribute */ while (ff_rtsp_next_attr_and_value(&p, attr, sizeof(attr), value, sizeof(value))) { - /* grab the codec extra_data from the config parameter of the fmtp - * line */ - sdp_parse_fmtp_config(codec, rtsp_st->dynamic_protocol_context, - attr, value); /* Looking for a known attribute */ for (i = 0; attr_names[i].str; ++i) { if (!strcasecmp(attr, attr_names[i].str)) { -- 1.7.0.4
From 12618b39e7c7fa6cb0f711422c82488671eea466 Mon Sep 17 00:00:00 2001 From: Josh Allmann <[email protected]> Date: Mon, 21 Jun 2010 13:38:17 -0700 Subject: [PATCH 3/6] Moved more SDP/FMTP stuff from rtsp.c to mpeg4.c --- libavformat/rtpdec_mpeg4.c | 50 ++++++++++++++++++++++++++++++- libavformat/rtsp.c | 69 +------------------------------------------ 2 files changed, 50 insertions(+), 69 deletions(-) diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c index a765f3a..39c344a 100644 --- a/libavformat/rtpdec_mpeg4.c +++ b/libavformat/rtpdec_mpeg4.c @@ -30,6 +30,9 @@ #include "rtpdec_mpeg4.h" #include "internal.h" #include "libavutil/avstring.h" +#include <strings.h> + +#include "rtsp.h" //XXX remove this dependency /* return the length and optionally the data */ static int hex_to_data(uint8_t *data, const char *p) @@ -60,6 +63,32 @@ static int hex_to_data(uint8_t *data, const char *p) return len; } +typedef struct { + const char *str; + uint16_t type; + uint32_t offset; +} AttrNameMap; + +/* All known fmtp parameters and the corresponding RTPAttrTypeEnum */ +#define ATTR_NAME_TYPE_INT 0 +#define ATTR_NAME_TYPE_STR 1 +static const AttrNameMap attr_names[]= +{ + { "SizeLength", ATTR_NAME_TYPE_INT, + offsetof(RTPPayloadData, sizelength) }, + { "IndexLength", ATTR_NAME_TYPE_INT, + offsetof(RTPPayloadData, indexlength) }, + { "IndexDeltaLength", ATTR_NAME_TYPE_INT, + offsetof(RTPPayloadData, indexdeltalength) }, + { "profile-level-id", ATTR_NAME_TYPE_INT, + offsetof(RTPPayloadData, profile_level_id) }, + { "StreamType", ATTR_NAME_TYPE_INT, + offsetof(RTPPayloadData, streamtype) }, + { "mode", ATTR_NAME_TYPE_STR, + offsetof(RTPPayloadData, mode) }, + { NULL, -1, -1 }, +}; + static int parse_fmtp_config(AVCodecContext * codec, char *value) { /* decode the hexa encoded parameter */ @@ -79,8 +108,11 @@ static int parse_sdp_line(AVFormatContext *s, int st_index, { const char *p; char value[4096], attr[25]; - int res = 0; - AVCodecContext* codec = s->streams[st_index]->codec; + int res = 0, i; + AVStream *st = s->streams[st_index]; + RTSPStream *rtsp_st = st->priv_data; + AVCodecContext* codec = st->codec; + RTPPayloadData *rtp_payload_data = &rtsp_st->rtp_payload_data; if (av_strstart(line, "fmtp:", &p)) { // remove protocol identifier @@ -97,6 +129,20 @@ static int parse_sdp_line(AVFormatContext *s, int st_index, if (res < 0) return res; } + + if (codec->codec_id == CODEC_ID_AAC) { + /* Looking for a known attribute */ + for (i = 0; attr_names[i].str; ++i) { + if (!strcasecmp(attr, attr_names[i].str)) { + if (attr_names[i].type == ATTR_NAME_TYPE_INT) { + *(int *)((char *)rtp_payload_data + + attr_names[i].offset) = atoi(value); + } else if (attr_names[i].type == ATTR_NAME_TYPE_STR) + *(char **)((char *)rtp_payload_data + + attr_names[i].offset) = av_strdup(value); + } + } + } } } diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 11a9d53..964144b 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -158,32 +158,6 @@ static int sdp_parse_rtpmap(AVFormatContext *s, return 0; } -typedef struct { - const char *str; - uint16_t type; - uint32_t offset; -} AttrNameMap; - -/* All known fmtp parameters and the corresponding RTPAttrTypeEnum */ -#define ATTR_NAME_TYPE_INT 0 -#define ATTR_NAME_TYPE_STR 1 -static const AttrNameMap attr_names[]= -{ - { "SizeLength", ATTR_NAME_TYPE_INT, - offsetof(RTPPayloadData, sizelength) }, - { "IndexLength", ATTR_NAME_TYPE_INT, - offsetof(RTPPayloadData, indexlength) }, - { "IndexDeltaLength", ATTR_NAME_TYPE_INT, - offsetof(RTPPayloadData, indexdeltalength) }, - { "profile-level-id", ATTR_NAME_TYPE_INT, - offsetof(RTPPayloadData, profile_level_id) }, - { "StreamType", ATTR_NAME_TYPE_INT, - offsetof(RTPPayloadData, streamtype) }, - { "mode", ATTR_NAME_TYPE_STR, - offsetof(RTPPayloadData, mode) }, - { NULL, -1, -1 }, -}; - /* parse the attribute line from the fmtp a line of an sdp response. This * is broken out as a function because it is used in rtp_h264.c, which is * forthcoming. */ @@ -203,32 +177,6 @@ int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, return 0; } -/* parse a SDP line and save stream attributes */ -static void sdp_parse_fmtp(AVStream *st, const char *p) -{ - char attr[256]; - char value[4096]; - int i; - RTSPStream *rtsp_st = st->priv_data; - RTPPayloadData *rtp_payload_data = &rtsp_st->rtp_payload_data; - - /* loop on each attribute */ - while (ff_rtsp_next_attr_and_value(&p, attr, sizeof(attr), - value, sizeof(value))) { - /* Looking for a known attribute */ - for (i = 0; attr_names[i].str; ++i) { - if (!strcasecmp(attr, attr_names[i].str)) { - if (attr_names[i].type == ATTR_NAME_TYPE_INT) { - *(int *)((char *)rtp_payload_data + - attr_names[i].offset) = atoi(value); - } else if (attr_names[i].type == ATTR_NAME_TYPE_STR) - *(char **)((char *)rtp_payload_data + - attr_names[i].offset) = av_strdup(value); - } - } - } -} - /** Parse a string p in the form of Range:npt=xx-xx, and determine the start * and end time. * Used for seeking in the rtp stream. @@ -399,22 +347,9 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, st = s->streams[s->nb_streams - 1]; rtsp_st = st->priv_data; sdp_parse_rtpmap(s, st->codec, rtsp_st, payload_type, p); - } else if (av_strstart(p, "fmtp:", &p)) { + } else if (av_strstart(p, "fmtp:", &p) || + av_strstart(p, "framesize:", &p)) { /* NOTE: fmtp is only supported AFTER the 'a=rtpmap:xxx' tag */ - get_word(buf1, sizeof(buf1), &p); - payload_type = atoi(buf1); - for (i = 0; i < s->nb_streams; i++) { - st = s->streams[i]; - rtsp_st = st->priv_data; - if (rtsp_st->sdp_payload_type == payload_type) { - if (!(rtsp_st->dynamic_handler && - rtsp_st->dynamic_handler->parse_sdp_a_line && - rtsp_st->dynamic_handler->parse_sdp_a_line(s, - i, rtsp_st->dynamic_protocol_context, buf))) - sdp_parse_fmtp(st, p); - } - } - } else if (av_strstart(p, "framesize:", &p)) { // let dynamic protocol handlers have a stab at the line. get_word(buf1, sizeof(buf1), &p); payload_type = atoi(buf1); -- 1.7.0.4
From 97c605b2c1922646bd513f0345b2471403bf3529 Mon Sep 17 00:00:00 2001 From: Josh Allmann <[email protected]> Date: Mon, 21 Jun 2010 14:49:41 -0700 Subject: [PATCH 4/6] Move AAC depacketization code in rtpdec to a proper payload handler. --- libavformat/rtpdec.c | 75 --------------------------------------- libavformat/rtpdec_mpeg4.c | 84 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 76 deletions(-) diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index 0b316e3..5c73ef8 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -370,58 +370,6 @@ rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx, s->parse_packet = handler->parse_packet; } -static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf) -{ - int au_headers_length, au_header_size, i; - GetBitContext getbitcontext; - RTPPayloadData *infos; - - infos = s->rtp_payload_data; - - if (infos == NULL) - return -1; - - /* decode the first 2 bytes where the AUHeader sections are stored - length in bits */ - au_headers_length = AV_RB16(buf); - - if (au_headers_length > RTP_MAX_PACKET_LENGTH) - return -1; - - infos->au_headers_length_bytes = (au_headers_length + 7) / 8; - - /* skip AU headers length section (2 bytes) */ - buf += 2; - - init_get_bits(&getbitcontext, buf, infos->au_headers_length_bytes * 8); - - /* XXX: Wrong if optionnal additional sections are present (cts, dts etc...) */ - au_header_size = infos->sizelength + infos->indexlength; - if (au_header_size <= 0 || (au_headers_length % au_header_size != 0)) - return -1; - - infos->nb_au_headers = au_headers_length / au_header_size; - if (!infos->au_headers || infos->au_headers_allocated < infos->nb_au_headers) { - av_free(infos->au_headers); - infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers); - infos->au_headers_allocated = infos->nb_au_headers; - } - - /* XXX: We handle multiple AU Section as only one (need to fix this for interleaving) - In my test, the FAAD decoder does not behave correctly when sending each AU one by one - but does when sending the whole as one big packet... */ - infos->au_headers[0].size = 0; - infos->au_headers[0].index = 0; - for (i = 0; i < infos->nb_au_headers; ++i) { - infos->au_headers[0].size += get_bits_long(&getbitcontext, infos->sizelength); - infos->au_headers[0].index = get_bits_long(&getbitcontext, infos->indexlength); - } - - infos->nb_au_headers = 1; - - return 0; -} - /** * This was the second switch in rtp_parse packet. Normalizes time, if required, sets stream_index, etc. */ @@ -563,29 +511,6 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, av_new_packet(pkt, len); memcpy(pkt->data, buf, len); break; - // moved from below, verbatim. this is because this section handles packets, and the lower switch handles - // timestamps. - // TODO: Put this into a dynamic packet handler... - case CODEC_ID_AAC: - if (rtp_parse_mp4_au(s, buf)) - return -1; - { - RTPPayloadData *infos = s->rtp_payload_data; - if (infos == NULL) - return -1; - buf += infos->au_headers_length_bytes + 2; - len -= infos->au_headers_length_bytes + 2; - - /* XXX: Fixme we only handle the case where rtp_parse_mp4_au define - one au_header */ - av_new_packet(pkt, infos->au_headers[0].size); - memcpy(pkt->data, buf, infos->au_headers[0].size); - buf += infos->au_headers[0].size; - len -= infos->au_headers[0].size; - } - s->read_buf_size = len; - rv= 0; - break; default: av_new_packet(pkt, len); memcpy(pkt->data, buf, len); diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c index 39c344a..363af6f 100644 --- a/libavformat/rtpdec_mpeg4.c +++ b/libavformat/rtpdec_mpeg4.c @@ -30,6 +30,7 @@ #include "rtpdec_mpeg4.h" #include "internal.h" #include "libavutil/avstring.h" +#include "libavcodec/get_bits.h" #include <strings.h> #include "rtsp.h" //XXX remove this dependency @@ -103,6 +104,87 @@ static int parse_fmtp_config(AVCodecContext * codec, char *value) return 0; } +static int rtp_parse_mp4_au(RTSPStream *rtsp_st, const uint8_t *buf) +{ + int au_headers_length, au_header_size, i; + GetBitContext getbitcontext; + RTPPayloadData *infos; + + infos = &rtsp_st->rtp_payload_data; + if (infos == NULL) + return -1; + + /* decode the first 2 bytes where the AUHeader sections are stored + length in bits */ + au_headers_length = AV_RB16(buf); + + if (au_headers_length > RTP_MAX_PACKET_LENGTH) + return -1; + + infos->au_headers_length_bytes = (au_headers_length + 7) / 8; + + /* skip AU headers length section (2 bytes) */ + buf += 2; + + init_get_bits(&getbitcontext, buf, infos->au_headers_length_bytes * 8); + + /* XXX: Wrong if optionnal additional sections are present (cts, dts etc...) */ + au_header_size = infos->sizelength + infos->indexlength; + if (au_header_size <= 0 || (au_headers_length % au_header_size != 0)) + return -1; + + infos->nb_au_headers = au_headers_length / au_header_size; + if (!infos->au_headers || infos->au_headers_allocated < infos->nb_au_headers) { + av_free(infos->au_headers); + infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers); + infos->au_headers_allocated = infos->nb_au_headers; + } + + /* XXX: We handle multiple AU Section as only one (need to fix this for interleaving) + In my test, the FAAD decoder does not behave correctly when sending each AU one by one + but does when sending the whole as one big packet... */ + infos->au_headers[0].size = 0; + infos->au_headers[0].index = 0; + for (i = 0; i < infos->nb_au_headers; ++i) { + infos->au_headers[0].size += get_bits_long(&getbitcontext, infos->sizelength); + infos->au_headers[0].index = get_bits_long(&getbitcontext, infos->indexlength); + } + + infos->nb_au_headers = 1; + + return 0; +} + + +/* Follows RFC 3640 */ +static int aac_parse_packet(AVFormatContext *ctx, + PayloadContext *data, + AVStream *st, + AVPacket *pkt, + uint32_t *timestamp, + const uint8_t *buf, int len, int flags) +{ + RTSPStream *rtsp_st = st->priv_data; + RTPPayloadData *infos; + + if (rtp_parse_mp4_au(rtsp_st, buf)) + return -1; + + infos = &rtsp_st->rtp_payload_data; + if (infos == NULL) + return -1; + buf += infos->au_headers_length_bytes + 2; + len -= infos->au_headers_length_bytes + 2; + + /* XXX: Fixme we only handle the case where rtp_parse_mp4_au define + one au_header */ + av_new_packet(pkt, infos->au_headers[0].size); + memcpy(pkt->data, buf, infos->au_headers[0].size); + + pkt->stream_index = st->index; + return 0; +} + static int parse_sdp_line(AVFormatContext *s, int st_index, PayloadContext *data, const char *line) { @@ -167,5 +249,5 @@ RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler = { .parse_sdp_a_line = parse_sdp_line, .open = NULL, .close = NULL, - .parse_packet = NULL + .parse_packet = aac_parse_packet }; -- 1.7.0.4
_______________________________________________ FFmpeg-soc mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc
