Use the correct size for the enc_name field (removing the arbitrary "50" size)
[libav.git] / libavformat / rtp.c
CommitLineData
e309128f
FB
1/*
2 * RTP input/output format
3 * Copyright (c) 2002 Fabrice Bellard.
4 *
b78e7197
DB
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
e309128f
FB
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
b78e7197 10 * version 2.1 of the License, or (at your option) any later version.
e309128f 11 *
b78e7197 12 * FFmpeg is distributed in the hope that it will be useful,
e309128f
FB
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
b78e7197 18 * License along with FFmpeg; if not, write to the Free Software
5509bffa 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e309128f
FB
20 */
21#include "avformat.h"
d1ccf0e0 22#include "bitstream.h"
e309128f
FB
23
24#include <unistd.h>
42572ef5 25#include "network.h"
e309128f 26
4934884a 27#include "rtp_internal.h"
4934884a 28
e309128f
FB
29//#define DEBUG
30
d1ccf0e0 31/* from http://www.iana.org/assignments/rtp-parameters last updated 05 January 2005 */
7d51eddd
DP
32static const struct
33{
34 int pt;
87cb0643 35 const char enc_name[6];
7d51eddd
DP
36 enum CodecType codec_type;
37 enum CodecID codec_id;
38 int clock_rate;
39 int audio_channels;
40} AVRtpPayloadTypes[]=
d1ccf0e0
RD
41{
42 {0, "PCMU", CODEC_TYPE_AUDIO, CODEC_ID_PCM_MULAW, 8000, 1},
d1ccf0e0
RD
43 {3, "GSM", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
44 {4, "G723", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
45 {5, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
46 {6, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 16000, 1},
47 {7, "LPC", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
48 {8, "PCMA", CODEC_TYPE_AUDIO, CODEC_ID_PCM_ALAW, 8000, 1},
49 {9, "G722", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
50 {10, "L16", CODEC_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 2},
51 {11, "L16", CODEC_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 1},
6c496518 52 {12, "QCELP", CODEC_TYPE_AUDIO, CODEC_ID_QCELP, 8000, 1},
d1ccf0e0
RD
53 {13, "CN", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
54 {14, "MPA", CODEC_TYPE_AUDIO, CODEC_ID_MP2, 90000, -1},
e4ed1fbf 55 {14, "MPA", CODEC_TYPE_AUDIO, CODEC_ID_MP3, 90000, -1},
d1ccf0e0
RD
56 {15, "G728", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
57 {16, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 11025, 1},
58 {17, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 22050, 1},
59 {18, "G729", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
d1ccf0e0
RD
60 {25, "CelB", CODEC_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1},
61 {26, "JPEG", CODEC_TYPE_VIDEO, CODEC_ID_MJPEG, 90000, -1},
d1ccf0e0 62 {28, "nv", CODEC_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1},
d1ccf0e0
RD
63 {31, "H261", CODEC_TYPE_VIDEO, CODEC_ID_H261, 90000, -1},
64 {32, "MPV", CODEC_TYPE_VIDEO, CODEC_ID_MPEG1VIDEO, 90000, -1},
db628029 65 {32, "MPV", CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, 90000, -1},
d1ccf0e0
RD
66 {33, "MP2T", CODEC_TYPE_DATA, CODEC_ID_MPEG2TS, 90000, -1},
67 {34, "H263", CODEC_TYPE_VIDEO, CODEC_ID_H263, 90000, -1},
d1ccf0e0
RD
68 {-1, "", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}
69};
70
e309128f
FB
71int rtp_get_codec_info(AVCodecContext *codec, int payload_type)
72{
7ed19d7f
LA
73 int i = 0;
74
75 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++)
76 if (AVRtpPayloadTypes[i].pt == payload_type) {
77 if (AVRtpPayloadTypes[i].codec_id != CODEC_ID_NONE) {
78 codec->codec_type = AVRtpPayloadTypes[i].codec_type;
79 codec->codec_id = AVRtpPayloadTypes[i].codec_id;
80 if (AVRtpPayloadTypes[i].audio_channels > 0)
81 codec->channels = AVRtpPayloadTypes[i].audio_channels;
82 if (AVRtpPayloadTypes[i].clock_rate > 0)
83 codec->sample_rate = AVRtpPayloadTypes[i].clock_rate;
84 return 0;
85 }
86 }
d1ccf0e0 87 return -1;
e309128f
FB
88}
89
e309128f
FB
90int rtp_get_payload_type(AVCodecContext *codec)
91{
d1ccf0e0 92 int i, payload_type;
e309128f
FB
93
94 /* compute the payload type */
d1ccf0e0
RD
95 for (payload_type = -1, i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i)
96 if (AVRtpPayloadTypes[i].codec_id == codec->codec_id) {
97 if (codec->codec_id == CODEC_ID_PCM_S16BE)
98 if (codec->channels != AVRtpPayloadTypes[i].audio_channels)
99 continue;
100 payload_type = AVRtpPayloadTypes[i].pt;
e309128f 101 }
e309128f
FB
102 return payload_type;
103}
104
7ed19d7f
LA
105const char *ff_rtp_enc_name(int payload_type)
106{
107 int i;
108
109 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++)
110 if (AVRtpPayloadTypes[i].pt == payload_type) {
111 return AVRtpPayloadTypes[i].enc_name;
112 }
113
114 return "";
115}
116
117enum CodecID ff_rtp_codec_id(const char *buf, enum CodecType codec_type)
118{
119 int i;
120
121 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++)
122 if (!strcmp(buf, AVRtpPayloadTypes[i].enc_name) && (codec_type == AVRtpPayloadTypes[i].codec_type)){
123 return AVRtpPayloadTypes[i].codec_id;
124 }
125
126 return CODEC_ID_NONE;
127}