Libav 0.7.1
|
00001 /* 00002 * RTP input/output format 00003 * Copyright (c) 2002 Fabrice Bellard 00004 * 00005 * This file is part of Libav. 00006 * 00007 * Libav is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * Libav is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with Libav; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #include "avformat.h" 00023 00024 #include "rtp.h" 00025 00026 //#define DEBUG 00027 00028 /* from http://www.iana.org/assignments/rtp-parameters last updated 05 January 2005 */ 00029 /* payload types >= 96 are dynamic; 00030 * payload types between 72 and 76 are reserved for RTCP conflict avoidance; 00031 * all the other payload types not present in the table are unassigned or 00032 * reserved 00033 */ 00034 static const struct 00035 { 00036 int pt; 00037 const char enc_name[6]; 00038 enum AVMediaType codec_type; 00039 enum CodecID codec_id; 00040 int clock_rate; 00041 int audio_channels; 00042 } AVRtpPayloadTypes[]= 00043 { 00044 {0, "PCMU", AVMEDIA_TYPE_AUDIO, CODEC_ID_PCM_MULAW, 8000, 1}, 00045 {3, "GSM", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, 00046 {4, "G723", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, 00047 {5, "DVI4", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, 00048 {6, "DVI4", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 16000, 1}, 00049 {7, "LPC", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, 00050 {8, "PCMA", AVMEDIA_TYPE_AUDIO, CODEC_ID_PCM_ALAW, 8000, 1}, 00051 {9, "G722", AVMEDIA_TYPE_AUDIO, CODEC_ID_ADPCM_G722, 8000, 1}, 00052 {10, "L16", AVMEDIA_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 2}, 00053 {11, "L16", AVMEDIA_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 1}, 00054 {12, "QCELP", AVMEDIA_TYPE_AUDIO, CODEC_ID_QCELP, 8000, 1}, 00055 {13, "CN", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, 00056 {14, "MPA", AVMEDIA_TYPE_AUDIO, CODEC_ID_MP2, -1, -1}, 00057 {14, "MPA", AVMEDIA_TYPE_AUDIO, CODEC_ID_MP3, -1, -1}, 00058 {15, "G728", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, 00059 {16, "DVI4", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 11025, 1}, 00060 {17, "DVI4", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 22050, 1}, 00061 {18, "G729", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, 00062 {25, "CelB", AVMEDIA_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1}, 00063 {26, "JPEG", AVMEDIA_TYPE_VIDEO, CODEC_ID_MJPEG, 90000, -1}, 00064 {28, "nv", AVMEDIA_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1}, 00065 {31, "H261", AVMEDIA_TYPE_VIDEO, CODEC_ID_H261, 90000, -1}, 00066 {32, "MPV", AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG1VIDEO, 90000, -1}, 00067 {32, "MPV", AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, 90000, -1}, 00068 {33, "MP2T", AVMEDIA_TYPE_DATA, CODEC_ID_MPEG2TS, 90000, -1}, 00069 {34, "H263", AVMEDIA_TYPE_VIDEO, CODEC_ID_H263, 90000, -1}, 00070 {-1, "", AVMEDIA_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1} 00071 }; 00072 00073 int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type) 00074 { 00075 int i = 0; 00076 00077 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++) 00078 if (AVRtpPayloadTypes[i].pt == payload_type) { 00079 if (AVRtpPayloadTypes[i].codec_id != CODEC_ID_NONE) { 00080 codec->codec_type = AVRtpPayloadTypes[i].codec_type; 00081 codec->codec_id = AVRtpPayloadTypes[i].codec_id; 00082 if (AVRtpPayloadTypes[i].audio_channels > 0) 00083 codec->channels = AVRtpPayloadTypes[i].audio_channels; 00084 if (AVRtpPayloadTypes[i].clock_rate > 0) 00085 codec->sample_rate = AVRtpPayloadTypes[i].clock_rate; 00086 return 0; 00087 } 00088 } 00089 return -1; 00090 } 00091 00092 int ff_rtp_get_payload_type(AVCodecContext *codec) 00093 { 00094 int i, payload_type; 00095 00096 /* compute the payload type */ 00097 for (payload_type = -1, i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i) 00098 if (AVRtpPayloadTypes[i].codec_id == codec->codec_id) { 00099 if (codec->codec_id == CODEC_ID_H263) 00100 continue; 00101 if (codec->codec_id == CODEC_ID_PCM_S16BE) 00102 if (codec->channels != AVRtpPayloadTypes[i].audio_channels) 00103 continue; 00104 payload_type = AVRtpPayloadTypes[i].pt; 00105 } 00106 return payload_type; 00107 } 00108 00109 const char *ff_rtp_enc_name(int payload_type) 00110 { 00111 int i; 00112 00113 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++) 00114 if (AVRtpPayloadTypes[i].pt == payload_type) { 00115 return AVRtpPayloadTypes[i].enc_name; 00116 } 00117 00118 return ""; 00119 } 00120 00121 enum CodecID ff_rtp_codec_id(const char *buf, enum AVMediaType codec_type) 00122 { 00123 int i; 00124 00125 for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++) 00126 if (!strcmp(buf, AVRtpPayloadTypes[i].enc_name) && (codec_type == AVRtpPayloadTypes[i].codec_type)){ 00127 return AVRtpPayloadTypes[i].codec_id; 00128 } 00129 00130 return CODEC_ID_NONE; 00131 }