annotate rtpdec_mpeg4.c @ 6178:7aca26f37b02 libavformat

rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler Patch by Josh Allmann, joshua dot allmann at gmail
author mstorsjo
date Fri, 25 Jun 2010 08:01:20 +0000
parents 3a0c63aea9e9
children 736165b749f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
1 /**
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
2 * Common code for the RTP depacketization of MPEG-4 formats.
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
3 * Copyright (c) 2010 Fabrice Bellard
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
4 * Romain Degez
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
5 *
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
6 * This file is part of FFmpeg.
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
7 *
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
12 *
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
16 * Lesser General Public License for more details.
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
17 *
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
21 */
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
22
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
23 /**
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
24 * @file
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
25 * @brief MPEG4 / RTP Code
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
26 * @author Fabrice Bellard
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
27 * @author Romain Degez
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
28 */
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
29
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
30 #include "rtpdec_mpeg4.h"
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
31 #include "internal.h"
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
32 #include "libavutil/avstring.h"
6178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
33 #include "libavcodec/get_bits.h"
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
34 #include <strings.h>
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
35
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
36 #include "rtsp.h" //XXX remove this dependency
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
37
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
38 /* return the length and optionally the data */
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
39 static int hex_to_data(uint8_t *data, const char *p)
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
40 {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
41 int c, len, v;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
42
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
43 len = 0;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
44 v = 1;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
45 for (;;) {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
46 p += strspn(p, SPACE_CHARS);
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
47 if (*p == '\0')
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
48 break;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
49 c = toupper((unsigned char) *p++);
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
50 if (c >= '0' && c <= '9')
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
51 c = c - '0';
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
52 else if (c >= 'A' && c <= 'F')
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
53 c = c - 'A' + 10;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
54 else
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
55 break;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
56 v = (v << 4) | c;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
57 if (v & 0x100) {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
58 if (data)
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
59 data[len] = v;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
60 len++;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
61 v = 1;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
62 }
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
63 }
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
64 return len;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
65 }
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
66
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
67 typedef struct {
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
68 const char *str;
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
69 uint16_t type;
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
70 uint32_t offset;
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
71 } AttrNameMap;
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
72
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
73 /* All known fmtp parameters and the corresponding RTPAttrTypeEnum */
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
74 #define ATTR_NAME_TYPE_INT 0
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
75 #define ATTR_NAME_TYPE_STR 1
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
76 static const AttrNameMap attr_names[]=
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
77 {
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
78 { "SizeLength", ATTR_NAME_TYPE_INT,
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
79 offsetof(RTPPayloadData, sizelength) },
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
80 { "IndexLength", ATTR_NAME_TYPE_INT,
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
81 offsetof(RTPPayloadData, indexlength) },
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
82 { "IndexDeltaLength", ATTR_NAME_TYPE_INT,
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
83 offsetof(RTPPayloadData, indexdeltalength) },
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
84 { "profile-level-id", ATTR_NAME_TYPE_INT,
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
85 offsetof(RTPPayloadData, profile_level_id) },
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
86 { "StreamType", ATTR_NAME_TYPE_INT,
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
87 offsetof(RTPPayloadData, streamtype) },
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
88 { "mode", ATTR_NAME_TYPE_STR,
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
89 offsetof(RTPPayloadData, mode) },
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
90 { NULL, -1, -1 },
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
91 };
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
92
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
93 static int parse_fmtp_config(AVCodecContext * codec, char *value)
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
94 {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
95 /* decode the hexa encoded parameter */
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
96 int len = hex_to_data(NULL, value);
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
97 if (codec->extradata)
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
98 av_free(codec->extradata);
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
99 codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE);
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
100 if (!codec->extradata)
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
101 return AVERROR(ENOMEM);
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
102 codec->extradata_size = len;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
103 hex_to_data(codec->extradata, value);
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
104 return 0;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
105 }
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
106
6178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
107 static int rtp_parse_mp4_au(RTSPStream *rtsp_st, const uint8_t *buf)
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
108 {
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
109 int au_headers_length, au_header_size, i;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
110 GetBitContext getbitcontext;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
111 RTPPayloadData *infos;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
112
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
113 infos = &rtsp_st->rtp_payload_data;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
114 if (infos == NULL)
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
115 return -1;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
116
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
117 /* decode the first 2 bytes where the AUHeader sections are stored
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
118 length in bits */
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
119 au_headers_length = AV_RB16(buf);
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
120
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
121 if (au_headers_length > RTP_MAX_PACKET_LENGTH)
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
122 return -1;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
123
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
124 infos->au_headers_length_bytes = (au_headers_length + 7) / 8;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
125
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
126 /* skip AU headers length section (2 bytes) */
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
127 buf += 2;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
128
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
129 init_get_bits(&getbitcontext, buf, infos->au_headers_length_bytes * 8);
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
130
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
131 /* XXX: Wrong if optionnal additional sections are present (cts, dts etc...) */
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
132 au_header_size = infos->sizelength + infos->indexlength;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
133 if (au_header_size <= 0 || (au_headers_length % au_header_size != 0))
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
134 return -1;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
135
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
136 infos->nb_au_headers = au_headers_length / au_header_size;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
137 if (!infos->au_headers || infos->au_headers_allocated < infos->nb_au_headers) {
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
138 av_free(infos->au_headers);
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
139 infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers);
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
140 infos->au_headers_allocated = infos->nb_au_headers;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
141 }
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
142
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
143 /* XXX: We handle multiple AU Section as only one (need to fix this for interleaving)
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
144 In my test, the FAAD decoder does not behave correctly when sending each AU one by one
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
145 but does when sending the whole as one big packet... */
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
146 infos->au_headers[0].size = 0;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
147 infos->au_headers[0].index = 0;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
148 for (i = 0; i < infos->nb_au_headers; ++i) {
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
149 infos->au_headers[0].size += get_bits_long(&getbitcontext, infos->sizelength);
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
150 infos->au_headers[0].index = get_bits_long(&getbitcontext, infos->indexlength);
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
151 }
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
152
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
153 infos->nb_au_headers = 1;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
154
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
155 return 0;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
156 }
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
157
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
158
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
159 /* Follows RFC 3640 */
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
160 static int aac_parse_packet(AVFormatContext *ctx,
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
161 PayloadContext *data,
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
162 AVStream *st,
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
163 AVPacket *pkt,
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
164 uint32_t *timestamp,
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
165 const uint8_t *buf, int len, int flags)
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
166 {
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
167 RTSPStream *rtsp_st = st->priv_data;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
168 RTPPayloadData *infos;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
169
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
170 if (rtp_parse_mp4_au(rtsp_st, buf))
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
171 return -1;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
172
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
173 infos = &rtsp_st->rtp_payload_data;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
174 if (infos == NULL)
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
175 return -1;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
176 buf += infos->au_headers_length_bytes + 2;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
177 len -= infos->au_headers_length_bytes + 2;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
179 /* XXX: Fixme we only handle the case where rtp_parse_mp4_au define
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
180 one au_header */
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
181 av_new_packet(pkt, infos->au_headers[0].size);
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
182 memcpy(pkt->data, buf, infos->au_headers[0].size);
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
183
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
184 pkt->stream_index = st->index;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
185 return 0;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
186 }
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
187
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
188 static int parse_sdp_line(AVFormatContext *s, int st_index,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
189 PayloadContext *data, const char *line)
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
190 {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
191 const char *p;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
192 char value[4096], attr[25];
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
193 int res = 0, i;
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
194 AVStream *st = s->streams[st_index];
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
195 RTSPStream *rtsp_st = st->priv_data;
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
196 AVCodecContext* codec = st->codec;
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
197 RTPPayloadData *rtp_payload_data = &rtsp_st->rtp_payload_data;
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
198
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
199 if (av_strstart(line, "fmtp:", &p)) {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
200 // remove protocol identifier
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
201 while (*p && *p == ' ') p++; // strip spaces
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
202 while (*p && *p != ' ') p++; // eat protocol identifier
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
203 while (*p && *p == ' ') p++; // strip trailing spaces
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
204
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
205 while (ff_rtsp_next_attr_and_value(&p,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
206 attr, sizeof(attr),
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
207 value, sizeof(value))) {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
208 if (!strcmp(attr, "config")) {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
209 res = parse_fmtp_config(codec, value);
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
210
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
211 if (res < 0)
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
212 return res;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
213 }
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
214
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
215 if (codec->codec_id == CODEC_ID_AAC) {
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
216 /* Looking for a known attribute */
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
217 for (i = 0; attr_names[i].str; ++i) {
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
218 if (!strcasecmp(attr, attr_names[i].str)) {
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
219 if (attr_names[i].type == ATTR_NAME_TYPE_INT) {
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
220 *(int *)((char *)rtp_payload_data +
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
221 attr_names[i].offset) = atoi(value);
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
222 } else if (attr_names[i].type == ATTR_NAME_TYPE_STR)
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
223 *(char **)((char *)rtp_payload_data +
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
224 attr_names[i].offset) = av_strdup(value);
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
225 }
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
226 }
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
227 }
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
228 }
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
229 }
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
230
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
231 return 0;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
232
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
233 }
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
234
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
235 RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler = {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
236 .enc_name = "MP4V-ES",
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
237 .codec_type = AVMEDIA_TYPE_VIDEO,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
238 .codec_id = CODEC_ID_MPEG4,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
239 .parse_sdp_a_line = parse_sdp_line,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
240 .open = NULL,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
241 .close = NULL,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
242 .parse_packet = NULL
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
243 };
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
244
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
245 RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler = {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
246 .enc_name = "mpeg4-generic",
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
247 .codec_type = AVMEDIA_TYPE_AUDIO,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
248 .codec_id = CODEC_ID_AAC,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
249 .parse_sdp_a_line = parse_sdp_line,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
250 .open = NULL,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
251 .close = NULL,
6178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
252 .parse_packet = aac_parse_packet
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
253 };