Mercurial > libavformat.hg
comparison rtpdec_mpeg4.c @ 6176:5708c6d4223d libavformat
RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c
Patch by Josh Allmann, joshua dot allmann at gmail
author | mstorsjo |
---|---|
date | Fri, 25 Jun 2010 07:58:38 +0000 |
parents | |
children | 3a0c63aea9e9 |
comparison
equal
deleted
inserted
replaced
6175:0e737c9247fd | 6176:5708c6d4223d |
---|---|
1 /** | |
2 * Common code for the RTP depacketization of MPEG-4 formats. | |
3 * Copyright (c) 2010 Fabrice Bellard | |
4 * Romain Degez | |
5 * | |
6 * This file is part of FFmpeg. | |
7 * | |
8 * FFmpeg is free software; you can redistribute it and/or | |
9 * modify it under the terms of the GNU Lesser General Public | |
10 * License as published by the Free Software Foundation; either | |
11 * version 2.1 of the License, or (at your option) any later version. | |
12 * | |
13 * FFmpeg is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
19 * License along with FFmpeg; if not, write to the Free Software | |
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
21 */ | |
22 | |
23 /** | |
24 * @file | |
25 * @brief MPEG4 / RTP Code | |
26 * @author Fabrice Bellard | |
27 * @author Romain Degez | |
28 */ | |
29 | |
30 #include "rtpdec_mpeg4.h" | |
31 #include "internal.h" | |
32 #include "libavutil/avstring.h" | |
33 | |
34 /* return the length and optionally the data */ | |
35 static int hex_to_data(uint8_t *data, const char *p) | |
36 { | |
37 int c, len, v; | |
38 | |
39 len = 0; | |
40 v = 1; | |
41 for (;;) { | |
42 p += strspn(p, SPACE_CHARS); | |
43 if (*p == '\0') | |
44 break; | |
45 c = toupper((unsigned char) *p++); | |
46 if (c >= '0' && c <= '9') | |
47 c = c - '0'; | |
48 else if (c >= 'A' && c <= 'F') | |
49 c = c - 'A' + 10; | |
50 else | |
51 break; | |
52 v = (v << 4) | c; | |
53 if (v & 0x100) { | |
54 if (data) | |
55 data[len] = v; | |
56 len++; | |
57 v = 1; | |
58 } | |
59 } | |
60 return len; | |
61 } | |
62 | |
63 static int parse_fmtp_config(AVCodecContext * codec, char *value) | |
64 { | |
65 /* decode the hexa encoded parameter */ | |
66 int len = hex_to_data(NULL, value); | |
67 if (codec->extradata) | |
68 av_free(codec->extradata); | |
69 codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); | |
70 if (!codec->extradata) | |
71 return AVERROR(ENOMEM); | |
72 codec->extradata_size = len; | |
73 hex_to_data(codec->extradata, value); | |
74 return 0; | |
75 } | |
76 | |
77 static int parse_sdp_line(AVFormatContext *s, int st_index, | |
78 PayloadContext *data, const char *line) | |
79 { | |
80 const char *p; | |
81 char value[4096], attr[25]; | |
82 int res = 0; | |
83 AVCodecContext* codec = s->streams[st_index]->codec; | |
84 | |
85 if (av_strstart(line, "fmtp:", &p)) { | |
86 // remove protocol identifier | |
87 while (*p && *p == ' ') p++; // strip spaces | |
88 while (*p && *p != ' ') p++; // eat protocol identifier | |
89 while (*p && *p == ' ') p++; // strip trailing spaces | |
90 | |
91 while (ff_rtsp_next_attr_and_value(&p, | |
92 attr, sizeof(attr), | |
93 value, sizeof(value))) { | |
94 if (!strcmp(attr, "config")) { | |
95 res = parse_fmtp_config(codec, value); | |
96 | |
97 if (res < 0) | |
98 return res; | |
99 } | |
100 } | |
101 } | |
102 | |
103 return 0; | |
104 | |
105 } | |
106 | |
107 RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler = { | |
108 .enc_name = "MP4V-ES", | |
109 .codec_type = AVMEDIA_TYPE_VIDEO, | |
110 .codec_id = CODEC_ID_MPEG4, | |
111 .parse_sdp_a_line = parse_sdp_line, | |
112 .open = NULL, | |
113 .close = NULL, | |
114 .parse_packet = NULL | |
115 }; | |
116 | |
117 RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler = { | |
118 .enc_name = "mpeg4-generic", | |
119 .codec_type = AVMEDIA_TYPE_AUDIO, | |
120 .codec_id = CODEC_ID_AAC, | |
121 .parse_sdp_a_line = parse_sdp_line, | |
122 .open = NULL, | |
123 .close = NULL, | |
124 .parse_packet = NULL | |
125 }; |