00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <libavutil/opt.h>
00023 #include "avformat.h"
00024
00025 #include "rtp.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 static const struct
00036 {
00037 int pt;
00038 const char enc_name[6];
00039 enum AVMediaType codec_type;
00040 enum AVCodecID codec_id;
00041 int clock_rate;
00042 int audio_channels;
00043 } AVRtpPayloadTypes[]=
00044 {
00045 {0, "PCMU", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_PCM_MULAW, 8000, 1},
00046 {3, "GSM", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_NONE, 8000, 1},
00047 {4, "G723", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_G723_1, 8000, 1},
00048 {5, "DVI4", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_NONE, 8000, 1},
00049 {6, "DVI4", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_NONE, 16000, 1},
00050 {7, "LPC", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_NONE, 8000, 1},
00051 {8, "PCMA", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_PCM_ALAW, 8000, 1},
00052 {9, "G722", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_ADPCM_G722, 8000, 1},
00053 {10, "L16", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_PCM_S16BE, 44100, 2},
00054 {11, "L16", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_PCM_S16BE, 44100, 1},
00055 {12, "QCELP", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_QCELP, 8000, 1},
00056 {13, "CN", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_NONE, 8000, 1},
00057 {14, "MPA", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_MP2, -1, -1},
00058 {14, "MPA", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_MP3, -1, -1},
00059 {15, "G728", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_NONE, 8000, 1},
00060 {16, "DVI4", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_NONE, 11025, 1},
00061 {17, "DVI4", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_NONE, 22050, 1},
00062 {18, "G729", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_NONE, 8000, 1},
00063 {25, "CelB", AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_NONE, 90000, -1},
00064 {26, "JPEG", AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_MJPEG, 90000, -1},
00065 {28, "nv", AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_NONE, 90000, -1},
00066 {31, "H261", AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_H261, 90000, -1},
00067 {32, "MPV", AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_MPEG1VIDEO, 90000, -1},
00068 {32, "MPV", AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_MPEG2VIDEO, 90000, -1},
00069 {33, "MP2T", AVMEDIA_TYPE_DATA, AV_CODEC_ID_MPEG2TS, 90000, -1},
00070 {34, "H263", AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_H263, 90000, -1},
00071 {-1, "", AVMEDIA_TYPE_UNKNOWN, AV_CODEC_ID_NONE, -1, -1}
00072 };
00073
00074 int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type)
00075 {
00076 int i = 0;
00077
00078 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++)
00079 if (AVRtpPayloadTypes[i].pt == payload_type) {
00080 if (AVRtpPayloadTypes[i].codec_id != AV_CODEC_ID_NONE) {
00081 codec->codec_type = AVRtpPayloadTypes[i].codec_type;
00082 codec->codec_id = AVRtpPayloadTypes[i].codec_id;
00083 if (AVRtpPayloadTypes[i].audio_channels > 0)
00084 codec->channels = AVRtpPayloadTypes[i].audio_channels;
00085 if (AVRtpPayloadTypes[i].clock_rate > 0)
00086 codec->sample_rate = AVRtpPayloadTypes[i].clock_rate;
00087 return 0;
00088 }
00089 }
00090 return -1;
00091 }
00092
00093 int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecContext *codec)
00094 {
00095 int i;
00096 AVOutputFormat *ofmt = fmt ? fmt->oformat : NULL;
00097
00098
00099 if (ofmt && ofmt->priv_class) {
00100 int64_t payload_type;
00101 if (av_opt_get_int(fmt->priv_data, "payload_type", 0, &payload_type) >= 0 &&
00102 payload_type >= 0)
00103 return (int)payload_type;
00104 }
00105
00106
00107 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i)
00108 if (AVRtpPayloadTypes[i].codec_id == codec->codec_id) {
00109 if (codec->codec_id == AV_CODEC_ID_H263 && (!fmt ||
00110 !fmt->oformat->priv_class ||
00111 !av_opt_flag_is_set(fmt->priv_data, "rtpflags", "rfc2190")))
00112 continue;
00113
00114
00115 if (codec->codec_id == AV_CODEC_ID_ADPCM_G722 &&
00116 codec->sample_rate == 16000 && codec->channels == 1)
00117 return AVRtpPayloadTypes[i].pt;
00118 if (codec->codec_type == AVMEDIA_TYPE_AUDIO &&
00119 ((AVRtpPayloadTypes[i].clock_rate > 0 &&
00120 codec->sample_rate != AVRtpPayloadTypes[i].clock_rate) ||
00121 (AVRtpPayloadTypes[i].audio_channels > 0 &&
00122 codec->channels != AVRtpPayloadTypes[i].audio_channels)))
00123 continue;
00124 return AVRtpPayloadTypes[i].pt;
00125 }
00126
00127
00128 return RTP_PT_PRIVATE + (codec->codec_type == AVMEDIA_TYPE_AUDIO);
00129 }
00130
00131 const char *ff_rtp_enc_name(int payload_type)
00132 {
00133 int i;
00134
00135 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++)
00136 if (AVRtpPayloadTypes[i].pt == payload_type) {
00137 return AVRtpPayloadTypes[i].enc_name;
00138 }
00139
00140 return "";
00141 }
00142
00143 enum AVCodecID ff_rtp_codec_id(const char *buf, enum AVMediaType codec_type)
00144 {
00145 int i;
00146
00147 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++)
00148 if (!strcmp(buf, AVRtpPayloadTypes[i].enc_name) && (codec_type == AVRtpPayloadTypes[i].codec_type)){
00149 return AVRtpPayloadTypes[i].codec_id;
00150 }
00151
00152 return AV_CODEC_ID_NONE;
00153 }