diff options
author | Luca Abeni <lucabe72@email.it> | 2007-11-16 07:59:41 +0000 |
---|---|---|
committer | Luca Abeni <lucabe72@email.it> | 2007-11-16 07:59:41 +0000 |
commit | 7ed19d7fbfc0dda44d401388db06b245f07d206f (patch) | |
tree | 1d834bdda316cba0989eb7481d53829731748f4a /libavformat | |
parent | b5298028b050d8c20d741c5219c1b0d2304c9391 (diff) | |
download | ffmpeg-7ed19d7fbfc0dda44d401388db06b245f07d206f.tar.gz |
Remove the "AVRtpPayloadTypes[i].pt == i" assumption from RTP and RTSP
code (this is needed for supporting MPEG2 video in the RTP muxer)
Originally committed as revision 11046 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/rtp.c | 51 | ||||
-rw-r--r-- | libavformat/rtp_internal.h | 2 | ||||
-rw-r--r-- | libavformat/rtsp.c | 8 |
3 files changed, 44 insertions, 17 deletions
diff --git a/libavformat/rtp.c b/libavformat/rtp.c index a5820d717d..83e7dfb4ed 100644 --- a/libavformat/rtp.c +++ b/libavformat/rtp.c @@ -198,15 +198,20 @@ void av_register_rtp_dynamic_payload_handlers(void) int rtp_get_codec_info(AVCodecContext *codec, int payload_type) { - if (AVRtpPayloadTypes[payload_type].codec_id != CODEC_ID_NONE) { - codec->codec_type = AVRtpPayloadTypes[payload_type].codec_type; - codec->codec_id = AVRtpPayloadTypes[payload_type].codec_id; - if (AVRtpPayloadTypes[payload_type].audio_channels > 0) - codec->channels = AVRtpPayloadTypes[payload_type].audio_channels; - if (AVRtpPayloadTypes[payload_type].clock_rate > 0) - codec->sample_rate = AVRtpPayloadTypes[payload_type].clock_rate; - return 0; - } + int i = 0; + + for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++) + if (AVRtpPayloadTypes[i].pt == payload_type) { + if (AVRtpPayloadTypes[i].codec_id != CODEC_ID_NONE) { + codec->codec_type = AVRtpPayloadTypes[i].codec_type; + codec->codec_id = AVRtpPayloadTypes[i].codec_id; + if (AVRtpPayloadTypes[i].audio_channels > 0) + codec->channels = AVRtpPayloadTypes[i].audio_channels; + if (AVRtpPayloadTypes[i].clock_rate > 0) + codec->sample_rate = AVRtpPayloadTypes[i].clock_rate; + return 0; + } + } return -1; } @@ -225,6 +230,30 @@ int rtp_get_payload_type(AVCodecContext *codec) return payload_type; } +const char *ff_rtp_enc_name(int payload_type) +{ + int i; + + for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++) + if (AVRtpPayloadTypes[i].pt == payload_type) { + return AVRtpPayloadTypes[i].enc_name; + } + + return ""; +} + +enum CodecID ff_rtp_codec_id(const char *buf, enum CodecType codec_type) +{ + int i; + + for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++) + if (!strcmp(buf, AVRtpPayloadTypes[i].enc_name) && (codec_type == AVRtpPayloadTypes[i].codec_type)){ + return AVRtpPayloadTypes[i].codec_id; + } + + return CODEC_ID_NONE; +} + static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len) { if (buf[1] != 200) @@ -448,7 +477,7 @@ RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *r s->st = st; s->rtp_payload_data = rtp_payload_data; rtp_init_statistics(&s->statistics, 0); // do we know the initial sequence from sdp? - if (!strcmp(AVRtpPayloadTypes[payload_type].enc_name, "MP2T")) { + if (!strcmp(ff_rtp_enc_name(payload_type), "MP2T")) { s->ts = mpegts_parse_open(s->ic); if (s->ts == NULL) { av_free(s); @@ -712,7 +741,7 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, void rtp_parse_close(RTPDemuxContext *s) { // TODO: fold this into the protocol specific data fields. - if (!strcmp(AVRtpPayloadTypes[s->payload_type].enc_name, "MP2T")) { + if (!strcmp(ff_rtp_enc_name(s->payload_type), "MP2T")) { mpegts_parse_close(s->ts); } av_free(s); diff --git a/libavformat/rtp_internal.h b/libavformat/rtp_internal.h index 6ef797cb70..fefbaf5504 100644 --- a/libavformat/rtp_internal.h +++ b/libavformat/rtp_internal.h @@ -113,6 +113,8 @@ extern RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler; int rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size); ///< from rtsp.c, but used by rtp dynamic protocol handlers. void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m); +const char *ff_rtp_enc_name(int payload_type); +enum CodecID ff_rtp_codec_id(const char *buf, enum CodecType codec_type); void av_register_rtp_dynamic_payload_handlers(void); diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 3dbb3e3aba..c494ebd3d8 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -167,11 +167,7 @@ static int sdp_parse_rtpmap(AVCodecContext *codec, RTSPStream *rtsp_st, int payl } else { /* We are in a standard case ( from http://www.iana.org/assignments/rtp-parameters) */ /* search into AVRtpPayloadTypes[] */ - for (i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i) - if (!strcmp(buf, AVRtpPayloadTypes[i].enc_name) && (codec->codec_type == AVRtpPayloadTypes[i].codec_type)){ - codec->codec_id = AVRtpPayloadTypes[i].codec_id; - break; - } + codec->codec_id = ff_rtp_codec_id(buf, codec->codec_type); } c = avcodec_find_decoder(codec->codec_id); @@ -443,7 +439,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, get_word(buf1, sizeof(buf1), &p); /* format list */ rtsp_st->sdp_payload_type = atoi(buf1); - if (!strcmp(AVRtpPayloadTypes[rtsp_st->sdp_payload_type].enc_name, "MP2T")) { + if (!strcmp(ff_rtp_enc_name(rtsp_st->sdp_payload_type), "MP2T")) { /* no corresponding stream */ } else { st = av_new_stream(s, 0); |