annotate rtpdec_mpeg4.c @ 6449:3a28e6827095 libavformat

Solving memory leak and initialization problem with prev_pkt / pkt.
author bindhammer
date Tue, 31 Aug 2010 07:15:11 +0000
parents 3f938b3a355a
children
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
6339
491eea5c52d6 Remove mostly unnecessary rtpdec_*.h files, store the declarations in one file
mstorsjo
parents: 6262
diff changeset
30 #include "rtpdec_formats.h"
6262
7b8b71ff9a76 Move SPACE_CHARS back to libavformat/internal.h
mstorsjo
parents: 6192
diff changeset
31 #include "internal.h"
6176
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
6179
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
36 /** Structure listing useful vars to parse RTP packet payload*/
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
37 struct PayloadContext
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
38 {
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
39 int sizelength;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
40 int indexlength;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
41 int indexdeltalength;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
42 int profile_level_id;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
43 int streamtype;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
44 int objecttype;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
45 char *mode;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
46
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
47 /** mpeg 4 AU headers */
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
48 struct AUHeaders {
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
49 int size;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
50 int index;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
51 int cts_flag;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
52 int cts;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
53 int dts_flag;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
54 int dts;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
55 int rap_flag;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
56 int streamstate;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
57 } *au_headers;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
58 int au_headers_allocated;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
59 int nb_au_headers;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
60 int au_headers_length_bytes;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
61 int cur_au_index;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
62 };
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
63
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
64 typedef struct {
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
65 const char *str;
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
66 uint16_t type;
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
67 uint32_t offset;
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
68 } AttrNameMap;
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
69
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
70 /* 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
71 #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
72 #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
73 static const AttrNameMap attr_names[]=
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
74 {
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
75 { "SizeLength", ATTR_NAME_TYPE_INT,
6179
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
76 offsetof(PayloadContext, sizelength) },
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
77 { "IndexLength", ATTR_NAME_TYPE_INT,
6179
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
78 offsetof(PayloadContext, indexlength) },
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
79 { "IndexDeltaLength", ATTR_NAME_TYPE_INT,
6179
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
80 offsetof(PayloadContext, indexdeltalength) },
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
81 { "profile-level-id", ATTR_NAME_TYPE_INT,
6179
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
82 offsetof(PayloadContext, profile_level_id) },
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
83 { "StreamType", ATTR_NAME_TYPE_INT,
6179
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
84 offsetof(PayloadContext, streamtype) },
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
85 { "mode", ATTR_NAME_TYPE_STR,
6179
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
86 offsetof(PayloadContext, mode) },
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
87 { NULL, -1, -1 },
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
88 };
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
89
6179
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
90 static PayloadContext *new_context(void)
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
91 {
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
92 return av_mallocz(sizeof(PayloadContext));
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
93 }
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
94
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
95 static void free_context(PayloadContext * data)
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
96 {
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
97 int i;
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
98 for (i = 0; i < data->nb_au_headers; i++) {
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
99 /* according to rtp_parse_mp4_au, we treat multiple
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
100 * au headers as one, so nb_au_headers is always 1.
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
101 * loop anyway in case this changes.
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
102 * (note: changes done carelessly might lead to a double free)
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
103 */
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
104 av_free(&data->au_headers[i]);
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
105 }
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
106 av_free(data->mode);
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
107 av_free(data);
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
108 }
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
109
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
110 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
111 {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
112 /* decode the hexa encoded parameter */
6353
3f938b3a355a Make hex_to_data a lavf internal function
mstorsjo
parents: 6339
diff changeset
113 int len = ff_hex_to_data(NULL, value);
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
114 if (codec->extradata)
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
115 av_free(codec->extradata);
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
116 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
117 if (!codec->extradata)
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
118 return AVERROR(ENOMEM);
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
119 codec->extradata_size = len;
6353
3f938b3a355a Make hex_to_data a lavf internal function
mstorsjo
parents: 6339
diff changeset
120 ff_hex_to_data(codec->extradata, value);
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
121 return 0;
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
122 }
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
123
6180
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
124 static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf)
6178
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 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
127 GetBitContext getbitcontext;
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 /* 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
130 length in bits */
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
131 au_headers_length = AV_RB16(buf);
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
132
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
133 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
134 return -1;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
135
6180
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
136 data->au_headers_length_bytes = (au_headers_length + 7) / 8;
6178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
137
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
138 /* 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
139 buf += 2;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
140
6180
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
141 init_get_bits(&getbitcontext, buf, data->au_headers_length_bytes * 8);
6178
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: Wrong if optionnal additional sections are present (cts, dts etc...) */
6180
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
144 au_header_size = data->sizelength + data->indexlength;
6178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
145 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
146 return -1;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
147
6180
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
148 data->nb_au_headers = au_headers_length / au_header_size;
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
149 if (!data->au_headers || data->au_headers_allocated < data->nb_au_headers) {
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
150 av_free(data->au_headers);
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
151 data->au_headers = av_malloc(sizeof(struct AUHeaders) * data->nb_au_headers);
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
152 data->au_headers_allocated = data->nb_au_headers;
6178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
153 }
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 /* 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
156 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
157 but does when sending the whole as one big packet... */
6180
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
158 data->au_headers[0].size = 0;
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
159 data->au_headers[0].index = 0;
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
160 for (i = 0; i < data->nb_au_headers; ++i) {
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
161 data->au_headers[0].size += get_bits_long(&getbitcontext, data->sizelength);
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
162 data->au_headers[0].index = get_bits_long(&getbitcontext, data->indexlength);
6178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
163 }
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
164
6180
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
165 data->nb_au_headers = 1;
6178
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 return 0;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
168 }
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
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
171 /* Follows RFC 3640 */
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
172 static int aac_parse_packet(AVFormatContext *ctx,
6180
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
173 PayloadContext *data,
6178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
174 AVStream *st,
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
175 AVPacket *pkt,
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
176 uint32_t *timestamp,
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
177 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
178 {
6180
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
179 if (rtp_parse_mp4_au(data, buf))
6178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
180 return -1;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
181
6180
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
182 buf += data->au_headers_length_bytes + 2;
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
183 len -= data->au_headers_length_bytes + 2;
6178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
184
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
185 /* 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
186 one au_header */
6180
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
187 av_new_packet(pkt, data->au_headers[0].size);
5c977bb6aea7 rtpdec_mpeg4: Rename PayloadContext to be consistently 'data'
mstorsjo
parents: 6179
diff changeset
188 memcpy(pkt->data, buf, data->au_headers[0].size);
6178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
189
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
190 pkt->stream_index = st->index;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
191 return 0;
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
192 }
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
193
6191
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
194 static int parse_fmtp(AVStream *stream, PayloadContext *data,
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
195 char *attr, char *value)
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
196 {
6191
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
197 AVCodecContext *codec = stream->codec;
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
198 int res, i;
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
199
6192
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
200 if (!strcmp(attr, "config")) {
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
201 res = parse_fmtp_config(codec, value);
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
202
6192
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
203 if (res < 0)
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
204 return res;
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
205 }
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
206
6192
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
207 if (codec->codec_id == CODEC_ID_AAC) {
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
208 /* Looking for a known attribute */
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
209 for (i = 0; attr_names[i].str; ++i) {
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
210 if (!strcasecmp(attr, attr_names[i].str)) {
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
211 if (attr_names[i].type == ATTR_NAME_TYPE_INT) {
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
212 *(int *)((char *)data+
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
213 attr_names[i].offset) = atoi(value);
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
214 } else if (attr_names[i].type == ATTR_NAME_TYPE_STR)
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
215 *(char **)((char *)data+
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
216 attr_names[i].offset) = av_strdup(value);
6177
3a0c63aea9e9 RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c
mstorsjo
parents: 6176
diff changeset
217 }
6192
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
218 }
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
219 }
6191
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
220 return 0;
6192
b93d7a25cd6b Reindent
mstorsjo
parents: 6191
diff changeset
221 }
6191
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
222
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
223 static int parse_sdp_line(AVFormatContext *s, int st_index,
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
224 PayloadContext *data, const char *line)
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
225 {
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
226 const char *p;
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
227
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
228 if (av_strstart(line, "fmtp:", &p))
7884ec350d88 rtpdec: Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer
mstorsjo
parents: 6186
diff changeset
229 return ff_parse_fmtp(s->streams[st_index], data, p, parse_fmtp);
6176
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 RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler = {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
235 .enc_name = "MP4V-ES",
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
236 .codec_type = AVMEDIA_TYPE_VIDEO,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
237 .codec_id = CODEC_ID_MPEG4,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
238 .parse_sdp_a_line = parse_sdp_line,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
239 .open = NULL,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
240 .close = NULL,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
241 .parse_packet = NULL
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
242 };
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 RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler = {
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
245 .enc_name = "mpeg4-generic",
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
246 .codec_type = AVMEDIA_TYPE_AUDIO,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
247 .codec_id = CODEC_ID_AAC,
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
248 .parse_sdp_a_line = parse_sdp_line,
6179
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
249 .open = new_context,
736165b749f8 RTSP, rtpdec: Move RTPPayloadData into rtpdec_mpeg4 and remove all references to rtp_payload_data in rtpdec and rtsp
mstorsjo
parents: 6178
diff changeset
250 .close = free_context,
6178
7aca26f37b02 rtpdec: Move AAC depacketization code in rtpdec to a proper payload handler
mstorsjo
parents: 6177
diff changeset
251 .parse_packet = aac_parse_packet
6176
5708c6d4223d RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
mstorsjo
parents:
diff changeset
252 };