00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavcodec/bitstream.h"
00023 #include "avformat.h"
00024
00025 #include <unistd.h>
00026 #include "network.h"
00027
00028 #include "rtp.h"
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 static const struct
00039 {
00040 int pt;
00041 const char enc_name[6];
00042 enum CodecType codec_type;
00043 enum CodecID codec_id;
00044 int clock_rate;
00045 int audio_channels;
00046 } AVRtpPayloadTypes[]=
00047 {
00048 {0, "PCMU", CODEC_TYPE_AUDIO, CODEC_ID_PCM_MULAW, 8000, 1},
00049 {3, "GSM", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
00050 {4, "G723", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
00051 {5, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
00052 {6, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 16000, 1},
00053 {7, "LPC", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
00054 {8, "PCMA", CODEC_TYPE_AUDIO, CODEC_ID_PCM_ALAW, 8000, 1},
00055 {9, "G722", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
00056 {10, "L16", CODEC_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 2},
00057 {11, "L16", CODEC_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 1},
00058 {12, "QCELP", CODEC_TYPE_AUDIO, CODEC_ID_QCELP, 8000, 1},
00059 {13, "CN", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
00060 {14, "MPA", CODEC_TYPE_AUDIO, CODEC_ID_MP2, -1, -1},
00061 {14, "MPA", CODEC_TYPE_AUDIO, CODEC_ID_MP3, -1, -1},
00062 {15, "G728", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
00063 {16, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 11025, 1},
00064 {17, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 22050, 1},
00065 {18, "G729", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
00066 {25, "CelB", CODEC_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1},
00067 {26, "JPEG", CODEC_TYPE_VIDEO, CODEC_ID_MJPEG, 90000, -1},
00068 {28, "nv", CODEC_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1},
00069 {31, "H261", CODEC_TYPE_VIDEO, CODEC_ID_H261, 90000, -1},
00070 {32, "MPV", CODEC_TYPE_VIDEO, CODEC_ID_MPEG1VIDEO, 90000, -1},
00071 {32, "MPV", CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, 90000, -1},
00072 {33, "MP2T", CODEC_TYPE_DATA, CODEC_ID_MPEG2TS, 90000, -1},
00073 {34, "H263", CODEC_TYPE_VIDEO, CODEC_ID_H263, 90000, -1},
00074 {-1, "", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}
00075 };
00076
00077 int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type)
00078 {
00079 int i = 0;
00080
00081 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++)
00082 if (AVRtpPayloadTypes[i].pt == payload_type) {
00083 if (AVRtpPayloadTypes[i].codec_id != CODEC_ID_NONE) {
00084 codec->codec_type = AVRtpPayloadTypes[i].codec_type;
00085 codec->codec_id = AVRtpPayloadTypes[i].codec_id;
00086 if (AVRtpPayloadTypes[i].audio_channels > 0)
00087 codec->channels = AVRtpPayloadTypes[i].audio_channels;
00088 if (AVRtpPayloadTypes[i].clock_rate > 0)
00089 codec->sample_rate = AVRtpPayloadTypes[i].clock_rate;
00090 return 0;
00091 }
00092 }
00093 return -1;
00094 }
00095
00096 int ff_rtp_get_payload_type(AVCodecContext *codec)
00097 {
00098 int i, payload_type;
00099
00100
00101 for (payload_type = -1, i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i)
00102 if (AVRtpPayloadTypes[i].codec_id == codec->codec_id) {
00103 if (codec->codec_id == CODEC_ID_PCM_S16BE)
00104 if (codec->channels != AVRtpPayloadTypes[i].audio_channels)
00105 continue;
00106 payload_type = AVRtpPayloadTypes[i].pt;
00107 }
00108 return payload_type;
00109 }
00110
00111 const char *ff_rtp_enc_name(int payload_type)
00112 {
00113 int i;
00114
00115 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++)
00116 if (AVRtpPayloadTypes[i].pt == payload_type) {
00117 return AVRtpPayloadTypes[i].enc_name;
00118 }
00119
00120 return "";
00121 }
00122
00123 enum CodecID ff_rtp_codec_id(const char *buf, enum CodecType codec_type)
00124 {
00125 int i;
00126
00127 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++)
00128 if (!strcmp(buf, AVRtpPayloadTypes[i].enc_name) && (codec_type == AVRtpPayloadTypes[i].codec_type)){
00129 return AVRtpPayloadTypes[i].codec_id;
00130 }
00131
00132 return CODEC_ID_NONE;
00133 }