static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,

                           int letter, const char *buf)

{

    RTSPState *rt = s->priv_data;

    char buf1[64], st_type[64];

    const char *p;

    int codec_type, payload_type, i;

    AVStream *st;

    RTSPStream *rtsp_st;

    struct in_addr sdp_ip;

    int ttl;



#ifdef DEBUG

    printf("sdp: %c='%s'\n", letter, buf);

#endif



    p = buf;

    switch(letter) {

    case 'c':

        get_word(buf1, sizeof(buf1), &p);

        if (strcmp(buf1, "IN") != 0)

            return;

        get_word(buf1, sizeof(buf1), &p);

        if (strcmp(buf1, "IP4") != 0)

            return;

        get_word_sep(buf1, sizeof(buf1), "/", &p);

        if (inet_aton(buf1, &sdp_ip) == 0)

            return;

        ttl = 16;

        if (*p == '/') {

            p++;

            get_word_sep(buf1, sizeof(buf1), "/", &p);

            ttl = atoi(buf1);

        }

        if (s->nb_streams == 0) {

            s1->default_ip = sdp_ip;

            s1->default_ttl = ttl;

        } else {

            st = s->streams[s->nb_streams - 1];

            rtsp_st = st->priv_data;

            rtsp_st->sdp_ip = sdp_ip;

            rtsp_st->sdp_ttl = ttl;

        }

        break;

    case 's':

        pstrcpy(s->title, sizeof(s->title), p);

        break;

    case 'i':

        if (s->nb_streams == 0) {

            pstrcpy(s->comment, sizeof(s->comment), p);

            break;

        }

        break;

    case 'm':

        /* new stream */

        get_word(st_type, sizeof(st_type), &p);

        if (!strcmp(st_type, "audio")) {

            codec_type = CODEC_TYPE_AUDIO;

        } else if (!strcmp(st_type, "video")) {

            codec_type = CODEC_TYPE_VIDEO;

        } else {

            return;

        }

        rtsp_st = av_mallocz(sizeof(RTSPStream));

        if (!rtsp_st)

            return;

        rtsp_st->stream_index = -1;

        dynarray_add(&rt->rtsp_streams, &rt->nb_rtsp_streams, rtsp_st);



        rtsp_st->sdp_ip = s1->default_ip;

        rtsp_st->sdp_ttl = s1->default_ttl;



        get_word(buf1, sizeof(buf1), &p); /* port */

        rtsp_st->sdp_port = atoi(buf1);



        get_word(buf1, sizeof(buf1), &p); /* protocol (ignored) */

        

        /* XXX: handle list of formats */

        get_word(buf1, sizeof(buf1), &p); /* format list */

        rtsp_st->sdp_payload_type = atoi(buf1);



        if (rtsp_st->sdp_payload_type == RTP_PT_MPEG2TS) {

            /* no corresponding stream */

        } else {

            st = av_new_stream(s, 0);

            if (!st)

                return;

            st->priv_data = rtsp_st;

            rtsp_st->stream_index = st->index;

            st->codec.codec_type = codec_type;

            if (rtsp_st->sdp_payload_type < 96) {

                /* if standard payload type, we can find the codec right now */

                rtp_get_codec_info(&st->codec, rtsp_st->sdp_payload_type);

            }

        }

        /* put a default control url */

        pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), s->filename);

        break;

    case 'a':

        if (strstart(p, "control:", &p) && s->nb_streams > 0) {

            char proto[32];

            /* get the control url */

            st = s->streams[s->nb_streams - 1];

            rtsp_st = st->priv_data;

            

            /* XXX: may need to add full url resolution */

            url_split(proto, sizeof(proto), NULL, 0, NULL, NULL, 0, p);

            if (proto[0] == '\0') {

                /* relative control URL */

                pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), "/");

                pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), p);

            } else {

                pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), p);

            }

        } else if (strstart(p, "rtpmap:", &p)) {

            /* NOTE: rtpmap is only supported AFTER the 'm=' tag */

            get_word(buf1, sizeof(buf1), &p); 

            payload_type = atoi(buf1);

            for(i = 0; i < s->nb_streams;i++) {

                st = s->streams[i];

                rtsp_st = st->priv_data;

                if (rtsp_st->sdp_payload_type == payload_type) {

                    sdp_parse_rtpmap(&st->codec, p);

                }

            }

        } else if (strstart(p, "fmtp:", &p)) {

            /* NOTE: fmtp is only supported AFTER the 'a=rtpmap:xxx' tag */

            get_word(buf1, sizeof(buf1), &p); 

            payload_type = atoi(buf1);

            for(i = 0; i < s->nb_streams;i++) {

                st = s->streams[i];

                rtsp_st = st->priv_data;

                if (rtsp_st->sdp_payload_type == payload_type) {

                    sdp_parse_fmtp(&st->codec, p);

                }

            }

        }

        break;

    }

}

static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,

                           int letter, const char *buf)

{

    RTSPState *rt = s->priv_data;

    char buf1[64], st_type[64];

    const char *p;

    int codec_type, payload_type, i;

    AVStream *st;

    RTSPStream *rtsp_st;

    struct in_addr sdp_ip;

    int ttl;



#ifdef DEBUG

    printf("sdp: %c='%s'\n", letter, buf);

#endif



    p = buf;

    switch(letter) {

    case 'c':

        get_word(buf1, sizeof(buf1), &p);

        if (strcmp(buf1, "IN") != 0)

            return;

        get_word(buf1, sizeof(buf1), &p);

        if (strcmp(buf1, "IP4") != 0)

            return;

        get_word_sep(buf1, sizeof(buf1), "/", &p);

        if (inet_aton(buf1, &sdp_ip) == 0)

            return;

        ttl = 16;

        if (*p == '/') {

            p++;

            get_word_sep(buf1, sizeof(buf1), "/", &p);

            ttl = atoi(buf1);

        }

        if (s->nb_streams == 0) {

            s1->default_ip = sdp_ip;

            s1->default_ttl = ttl;

        } else {

            st = s->streams[s->nb_streams - 1];

            rtsp_st = st->priv_data;

            rtsp_st->sdp_ip = sdp_ip;

            rtsp_st->sdp_ttl = ttl;

        }

        break;

    case 's':

        pstrcpy(s->title, sizeof(s->title), p);

        break;

    case 'i':

        if (s->nb_streams == 0) {

            pstrcpy(s->comment, sizeof(s->comment), p);

            break;

        }

        break;

    case 'm':

        

        get_word(st_type, sizeof(st_type), &p);

        if (!strcmp(st_type, "audio")) {

            codec_type = CODEC_TYPE_AUDIO;

        } else if (!strcmp(st_type, "video")) {

            codec_type = CODEC_TYPE_VIDEO;

        } else {

            return;

        }

        rtsp_st = av_mallocz(sizeof(RTSPStream));

        if (!rtsp_st)

            return;

        rtsp_st->stream_index = -1;

        dynarray_add(&rt->rtsp_streams, &rt->nb_rtsp_streams, rtsp_st);



        rtsp_st->sdp_ip = s1->default_ip;

        rtsp_st->sdp_ttl = s1->default_ttl;



        get_word(buf1, sizeof(buf1), &p); 

        rtsp_st->sdp_port = atoi(buf1);



        get_word(buf1, sizeof(buf1), &p); 

        

        

        get_word(buf1, sizeof(buf1), &p); 

        rtsp_st->sdp_payload_type = atoi(buf1);



        if (rtsp_st->sdp_payload_type == RTP_PT_MPEG2TS) {

            

        } else {

            st = av_new_stream(s, 0);

            if (!st)

                return;

            st->priv_data = rtsp_st;

            rtsp_st->stream_index = st->index;

            st->codec.codec_type = codec_type;

            if (rtsp_st->sdp_payload_type < 96) {

                

                rtp_get_codec_info(&st->codec, rtsp_st->sdp_payload_type);

            }

        }

        

        pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), s->filename);

        break;

    case 'a':

        if (strstart(p, "control:", &p) && s->nb_streams > 0) {

            char proto[32];

            

            st = s->streams[s->nb_streams - 1];

            rtsp_st = st->priv_data;

            

            

            url_split(proto, sizeof(proto), NULL, 0, NULL, NULL, 0, p);

            if (proto[0] == '\0') {

                

                pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), "/");

                pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), p);

            } else {

                pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), p);

            }

        } else if (strstart(p, "rtpmap:", &p)) {

            

            get_word(buf1, sizeof(buf1), &p); 

            payload_type = atoi(buf1);

            for(i = 0; i < s->nb_streams;i++) {

                st = s->streams[i];

                rtsp_st = st->priv_data;

                if (rtsp_st->sdp_payload_type == payload_type) {

                    sdp_parse_rtpmap(&st->codec, p);

                }

            }

        } else if (strstart(p, "fmtp:", &p)) {

            

            get_word(buf1, sizeof(buf1), &p); 

            payload_type = atoi(buf1);

            for(i = 0; i < s->nb_streams;i++) {

                st = s->streams[i];

                rtsp_st = st->priv_data;

                if (rtsp_st->sdp_payload_type == payload_type) {

                    sdp_parse_fmtp(&st->codec, p);

                }

            }

        }

        break;

    }

}

static void FUNC_0(AVFormatContext *VAR_0, SDPParseState *VAR_1,

                           int VAR_2, const char *VAR_3)

{

    RTSPState *rt = VAR_0->priv_data;

    char VAR_4[64], VAR_5[64];

    const char *VAR_6;

    int VAR_7, VAR_8, VAR_9;

    AVStream *st;

    RTSPStream *rtsp_st;

    struct in_addr VAR_10;

    int VAR_11;



#ifdef DEBUG

    printf("sdp: %c='%VAR_0'\n", VAR_2, VAR_3);

#endif



    VAR_6 = VAR_3;

    switch(VAR_2) {

    case 'c':

        get_word(VAR_4, sizeof(VAR_4), &VAR_6);

        if (strcmp(VAR_4, "IN") != 0)

            return;

        get_word(VAR_4, sizeof(VAR_4), &VAR_6);

        if (strcmp(VAR_4, "IP4") != 0)

            return;

        get_word_sep(VAR_4, sizeof(VAR_4), "/", &VAR_6);

        if (inet_aton(VAR_4, &VAR_10) == 0)

            return;

        VAR_11 = 16;

        if (*VAR_6 == '/') {

            VAR_6++;

            get_word_sep(VAR_4, sizeof(VAR_4), "/", &VAR_6);

            VAR_11 = atoi(VAR_4);

        }

        if (VAR_0->nb_streams == 0) {

            VAR_1->default_ip = VAR_10;

            VAR_1->default_ttl = VAR_11;

        } else {

            st = VAR_0->streams[VAR_0->nb_streams - 1];

            rtsp_st = st->priv_data;

            rtsp_st->VAR_10 = VAR_10;

            rtsp_st->sdp_ttl = VAR_11;

        }

        break;

    case 'VAR_0':

        pstrcpy(VAR_0->title, sizeof(VAR_0->title), VAR_6);

        break;

    case 'VAR_9':

        if (VAR_0->nb_streams == 0) {

            pstrcpy(VAR_0->comment, sizeof(VAR_0->comment), VAR_6);

            break;

        }

        break;

    case 'm':

        

        get_word(VAR_5, sizeof(VAR_5), &VAR_6);

        if (!strcmp(VAR_5, "audio")) {

            VAR_7 = CODEC_TYPE_AUDIO;

        } else if (!strcmp(VAR_5, "video")) {

            VAR_7 = CODEC_TYPE_VIDEO;

        } else {

            return;

        }

        rtsp_st = av_mallocz(sizeof(RTSPStream));

        if (!rtsp_st)

            return;

        rtsp_st->stream_index = -1;

        dynarray_add(&rt->rtsp_streams, &rt->nb_rtsp_streams, rtsp_st);



        rtsp_st->VAR_10 = VAR_1->default_ip;

        rtsp_st->sdp_ttl = VAR_1->default_ttl;



        get_word(VAR_4, sizeof(VAR_4), &VAR_6); 

        rtsp_st->sdp_port = atoi(VAR_4);



        get_word(VAR_4, sizeof(VAR_4), &VAR_6); 

        

        

        get_word(VAR_4, sizeof(VAR_4), &VAR_6); 

        rtsp_st->sdp_payload_type = atoi(VAR_4);



        if (rtsp_st->sdp_payload_type == RTP_PT_MPEG2TS) {

            

        } else {

            st = av_new_stream(VAR_0, 0);

            if (!st)

                return;

            st->priv_data = rtsp_st;

            rtsp_st->stream_index = st->index;

            st->codec.VAR_7 = VAR_7;

            if (rtsp_st->sdp_payload_type < 96) {

                

                rtp_get_codec_info(&st->codec, rtsp_st->sdp_payload_type);

            }

        }

        

        pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), VAR_0->filename);

        break;

    case 'a':

        if (strstart(VAR_6, "control:", &VAR_6) && VAR_0->nb_streams > 0) {

            char VAR_12[32];

            

            st = VAR_0->streams[VAR_0->nb_streams - 1];

            rtsp_st = st->priv_data;

            

            

            url_split(VAR_12, sizeof(VAR_12), NULL, 0, NULL, NULL, 0, VAR_6);

            if (VAR_12[0] == '\0') {

                

                pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), "/");

                pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), VAR_6);

            } else {

                pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), VAR_6);

            }

        } else if (strstart(VAR_6, "rtpmap:", &VAR_6)) {

            

            get_word(VAR_4, sizeof(VAR_4), &VAR_6); 

            VAR_8 = atoi(VAR_4);

            for(VAR_9 = 0; VAR_9 < VAR_0->nb_streams;VAR_9++) {

                st = VAR_0->streams[VAR_9];

                rtsp_st = st->priv_data;

                if (rtsp_st->sdp_payload_type == VAR_8) {

                    sdp_parse_rtpmap(&st->codec, VAR_6);

                }

            }

        } else if (strstart(VAR_6, "fmtp:", &VAR_6)) {

            

            get_word(VAR_4, sizeof(VAR_4), &VAR_6); 

            VAR_8 = atoi(VAR_4);

            for(VAR_9 = 0; VAR_9 < VAR_0->nb_streams;VAR_9++) {

                st = VAR_0->streams[VAR_9];

                rtsp_st = st->priv_data;

                if (rtsp_st->sdp_payload_type == VAR_8) {

                    sdp_parse_fmtp(&st->codec, VAR_6);

                }

            }

        }

        break;

    }

}

static void FUNC_0(AVFormatContext *VAR_0, SDPParseState *VAR_1,
int VAR_2, const char *VAR_3)
{ RTSPState *rt = VAR_0->priv_data; char VAR_4[64], VAR_5[64]; const char *VAR_6; int VAR_7, VAR_8, VAR_9; AVStream *st; RTSPStream *rtsp_st; struct in_addr VAR_10; int VAR_11; #ifdef DEBUG
printf("sdp: %c='%VAR_0'\n", VAR_2, VAR_3); #endif
VAR_6 = VAR_3; switch(VAR_2) { case 'c':
get_word(VAR_4, sizeof(VAR_4), &VAR_6); if (strcmp(VAR_4, "IN") != 0)
return; get_word(VAR_4, sizeof(VAR_4), &VAR_6); if (strcmp(VAR_4, "IP4") != 0)
return; get_word_sep(VAR_4, sizeof(VAR_4), "/", &VAR_6); if (inet_aton(VAR_4, &VAR_10) == 0)
return; VAR_11 = 16; if (*VAR_6 == '/') { VAR_6++; get_word_sep(VAR_4, sizeof(VAR_4), "/", &VAR_6); VAR_11 = atoi(VAR_4); } if (VAR_0->nb_streams == 0) { VAR_1->default_ip = VAR_10; VAR_1->default_ttl = VAR_11; } else { st = VAR_0->streams[VAR_0->nb_streams - 1]; rtsp_st = st->priv_data; rtsp_st->VAR_10 = VAR_10; rtsp_st->sdp_ttl = VAR_11; } break; case 'VAR_0':
pstrcpy(VAR_0->title, sizeof(VAR_0->title), VAR_6); break; case 'VAR_9':
if (VAR_0->nb_streams == 0) { pstrcpy(VAR_0->comment, sizeof(VAR_0->comment), VAR_6); break; } break; case 'm':
get_word(VAR_5, sizeof(VAR_5), &VAR_6); if (!strcmp(VAR_5, "audio")) { VAR_7 = CODEC_TYPE_AUDIO; } else if (!strcmp(VAR_5, "video")) { VAR_7 = CODEC_TYPE_VIDEO; } else { return; } rtsp_st = av_mallocz(sizeof(RTSPStream)); if (!rtsp_st)
return; rtsp_st->stream_index = -1; dynarray_add(&rt->rtsp_streams, &rt->nb_rtsp_streams, rtsp_st); rtsp_st->VAR_10 = VAR_1->default_ip; rtsp_st->sdp_ttl = VAR_1->default_ttl; get_word(VAR_4, sizeof(VAR_4), &VAR_6); rtsp_st->sdp_port = atoi(VAR_4); get_word(VAR_4, sizeof(VAR_4), &VAR_6); get_word(VAR_4, sizeof(VAR_4), &VAR_6); rtsp_st->sdp_payload_type = atoi(VAR_4); if (rtsp_st->sdp_payload_type == RTP_PT_MPEG2TS) { } else { st = av_new_stream(VAR_0, 0); if (!st)
return; st->priv_data = rtsp_st; rtsp_st->stream_index = st->index; st->codec.VAR_7 = VAR_7; if (rtsp_st->sdp_payload_type < 96) { rtp_get_codec_info(&st->codec, rtsp_st->sdp_payload_type); } } pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), VAR_0->filename); break; case 'a':
if (strstart(VAR_6, "control:", &VAR_6) && VAR_0->nb_streams > 0) { char VAR_12[32]; st = VAR_0->streams[VAR_0->nb_streams - 1]; rtsp_st = st->priv_data; url_split(VAR_12, sizeof(VAR_12), NULL, 0, NULL, NULL, 0, VAR_6); if (VAR_12[0] == '\0') { pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), "/"); pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), VAR_6); } else { pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), VAR_6); } } else if (strstart(VAR_6, "rtpmap:", &VAR_6)) { get_word(VAR_4, sizeof(VAR_4), &VAR_6); VAR_8 = atoi(VAR_4); for(VAR_9 = 0; VAR_9 < VAR_0->nb_streams;VAR_9++) { st = VAR_0->streams[VAR_9]; rtsp_st = st->priv_data; if (rtsp_st->sdp_payload_type == VAR_8) { sdp_parse_rtpmap(&st->codec, VAR_6); } } } else if (strstart(VAR_6, "fmtp:", &VAR_6)) { get_word(VAR_4, sizeof(VAR_4), &VAR_6); VAR_8 = atoi(VAR_4); for(VAR_9 = 0; VAR_9 < VAR_0->nb_streams;VAR_9++) { st = VAR_0->streams[VAR_9]; rtsp_st = st->priv_data; if (rtsp_st->sdp_payload_type == VAR_8) { sdp_parse_fmtp(&st->codec, VAR_6); } } } break; } }