static int rtsp_read_packet(AVFormatContext *s,

                            AVPacket *pkt)

{

    RTSPState *rt = s->priv_data;

    int ret;

    RTSPMessageHeader reply1, *reply = &reply1;

    char cmd[1024];



    if (rt->server_type == RTSP_SERVER_REAL) {

        int i;

        enum AVDiscard cache[MAX_STREAMS];



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

            cache[i] = s->streams[i]->discard;



        if (!rt->need_subscription) {

            if (memcmp (cache, rt->real_setup_cache,

                        sizeof(enum AVDiscard) * s->nb_streams)) {

                av_strlcatf(cmd, sizeof(cmd),

                            "SET_PARAMETER %s RTSP/1.0\r\n"

                            "Unsubscribe: %s\r\n",

                            s->filename, rt->last_subscription);

                rtsp_send_cmd(s, cmd, reply, NULL);

                if (reply->status_code != RTSP_STATUS_OK)

                    return AVERROR_INVALIDDATA;

                rt->need_subscription = 1;

            }

        }



        if (rt->need_subscription) {

            int r, rule_nr, first = 1;



            memcpy(rt->real_setup_cache, cache,

                   sizeof(enum AVDiscard) * s->nb_streams);

            rt->last_subscription[0] = 0;



            snprintf(cmd, sizeof(cmd),

                     "SET_PARAMETER %s RTSP/1.0\r\n"

                     "Subscribe: ",

                     s->filename);

            for (i = 0; i < rt->nb_rtsp_streams; i++) {

                rule_nr = 0;

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

                    if (s->streams[r]->priv_data == rt->rtsp_streams[i]) {

                        if (s->streams[r]->discard != AVDISCARD_ALL) {

                            if (!first)

                                av_strlcat(rt->last_subscription, ",",

                                           sizeof(rt->last_subscription));

                            ff_rdt_subscribe_rule(

                                rt->last_subscription,

                                sizeof(rt->last_subscription), i, rule_nr);

                            first = 0;

                        }

                        rule_nr++;

                    }

                }

            }

            av_strlcatf(cmd, sizeof(cmd), "%s\r\n", rt->last_subscription);

            rtsp_send_cmd(s, cmd, reply, NULL);

            if (reply->status_code != RTSP_STATUS_OK)

                return AVERROR_INVALIDDATA;

            rt->need_subscription = 0;



            if (rt->state == RTSP_STATE_PLAYING)

                rtsp_read_play (s);

        }

    }



    ret = rtsp_fetch_packet(s, pkt);

    if (ret < 0) {

        return ret;

    }



    /* send dummy request to keep TCP connection alive */

    if ((rt->server_type == RTSP_SERVER_WMS ||

         rt->server_type == RTSP_SERVER_REAL) &&

        (av_gettime() - rt->last_cmd_time) / 1000000 >= rt->timeout / 2) {

        if (rt->server_type == RTSP_SERVER_WMS) {

            snprintf(cmd, sizeof(cmd) - 1,

                     "GET_PARAMETER %s RTSP/1.0\r\n",

                     s->filename);

            rtsp_send_cmd_async(s, cmd, reply, NULL);

        } else {

            rtsp_send_cmd_async(s, "OPTIONS * RTSP/1.0\r\n",

                                reply, NULL);

        }

    }



    return 0;

}

static int rtsp_read_packet(AVFormatContext *s,

                            AVPacket *pkt)

{

    RTSPState *rt = s->priv_data;

    int ret;

    RTSPMessageHeader reply1, *reply = &reply1;

    char cmd[1024];



    if (rt->server_type == RTSP_SERVER_REAL) {

        int i;

        enum AVDiscard cache[MAX_STREAMS];



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

            cache[i] = s->streams[i]->discard;



        if (!rt->need_subscription) {

            if (memcmp (cache, rt->real_setup_cache,

                        sizeof(enum AVDiscard) * s->nb_streams)) {

                av_strlcatf(cmd, sizeof(cmd),

                            "SET_PARAMETER %s RTSP/1.0\r\n"

                            "Unsubscribe: %s\r\n",

                            s->filename, rt->last_subscription);

                rtsp_send_cmd(s, cmd, reply, NULL);

                if (reply->status_code != RTSP_STATUS_OK)

                    return AVERROR_INVALIDDATA;

                rt->need_subscription = 1;

            }

        }



        if (rt->need_subscription) {

            int r, rule_nr, first = 1;



            memcpy(rt->real_setup_cache, cache,

                   sizeof(enum AVDiscard) * s->nb_streams);

            rt->last_subscription[0] = 0;



            snprintf(cmd, sizeof(cmd),

                     "SET_PARAMETER %s RTSP/1.0\r\n"

                     "Subscribe: ",

                     s->filename);

            for (i = 0; i < rt->nb_rtsp_streams; i++) {

                rule_nr = 0;

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

                    if (s->streams[r]->priv_data == rt->rtsp_streams[i]) {

                        if (s->streams[r]->discard != AVDISCARD_ALL) {

                            if (!first)

                                av_strlcat(rt->last_subscription, ",",

                                           sizeof(rt->last_subscription));

                            ff_rdt_subscribe_rule(

                                rt->last_subscription,

                                sizeof(rt->last_subscription), i, rule_nr);

                            first = 0;

                        }

                        rule_nr++;

                    }

                }

            }

            av_strlcatf(cmd, sizeof(cmd), "%s\r\n", rt->last_subscription);

            rtsp_send_cmd(s, cmd, reply, NULL);

            if (reply->status_code != RTSP_STATUS_OK)

                return AVERROR_INVALIDDATA;

            rt->need_subscription = 0;



            if (rt->state == RTSP_STATE_PLAYING)

                rtsp_read_play (s);

        }

    }



    ret = rtsp_fetch_packet(s, pkt);

    if (ret < 0) {

        return ret;

    }



    

    if ((rt->server_type == RTSP_SERVER_WMS ||

         rt->server_type == RTSP_SERVER_REAL) &&

        (av_gettime() - rt->last_cmd_time) / 1000000 >= rt->timeout / 2) {

        if (rt->server_type == RTSP_SERVER_WMS) {

            snprintf(cmd, sizeof(cmd) - 1,

                     "GET_PARAMETER %s RTSP/1.0\r\n",

                     s->filename);

            rtsp_send_cmd_async(s, cmd, reply, NULL);

        } else {

            rtsp_send_cmd_async(s, "OPTIONS * RTSP/1.0\r\n",

                                reply, NULL);

        }

    }



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0,

                            AVPacket *VAR_1)

{

    RTSPState *rt = VAR_0->priv_data;

    int VAR_2;

    RTSPMessageHeader reply1, *reply = &reply1;

    char VAR_3[1024];



    if (rt->server_type == RTSP_SERVER_REAL) {

        int VAR_4;

        enum AVDiscard VAR_5[MAX_STREAMS];



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

            VAR_5[VAR_4] = VAR_0->streams[VAR_4]->discard;



        if (!rt->need_subscription) {

            if (memcmp (VAR_5, rt->real_setup_cache,

                        sizeof(enum AVDiscard) * VAR_0->nb_streams)) {

                av_strlcatf(VAR_3, sizeof(VAR_3),

                            "SET_PARAMETER %VAR_0 RTSP/1.0\VAR_6\n"

                            "Unsubscribe: %VAR_0\VAR_6\n",

                            VAR_0->filename, rt->last_subscription);

                rtsp_send_cmd(VAR_0, VAR_3, reply, NULL);

                if (reply->status_code != RTSP_STATUS_OK)

                    return AVERROR_INVALIDDATA;

                rt->need_subscription = 1;

            }

        }



        if (rt->need_subscription) {

            int VAR_6, VAR_7, VAR_8 = 1;



            memcpy(rt->real_setup_cache, VAR_5,

                   sizeof(enum AVDiscard) * VAR_0->nb_streams);

            rt->last_subscription[0] = 0;



            snprintf(VAR_3, sizeof(VAR_3),

                     "SET_PARAMETER %VAR_0 RTSP/1.0\VAR_6\n"

                     "Subscribe: ",

                     VAR_0->filename);

            for (VAR_4 = 0; VAR_4 < rt->nb_rtsp_streams; VAR_4++) {

                VAR_7 = 0;

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

                    if (VAR_0->streams[VAR_6]->priv_data == rt->rtsp_streams[VAR_4]) {

                        if (VAR_0->streams[VAR_6]->discard != AVDISCARD_ALL) {

                            if (!VAR_8)

                                av_strlcat(rt->last_subscription, ",",

                                           sizeof(rt->last_subscription));

                            ff_rdt_subscribe_rule(

                                rt->last_subscription,

                                sizeof(rt->last_subscription), VAR_4, VAR_7);

                            VAR_8 = 0;

                        }

                        VAR_7++;

                    }

                }

            }

            av_strlcatf(VAR_3, sizeof(VAR_3), "%VAR_0\VAR_6\n", rt->last_subscription);

            rtsp_send_cmd(VAR_0, VAR_3, reply, NULL);

            if (reply->status_code != RTSP_STATUS_OK)

                return AVERROR_INVALIDDATA;

            rt->need_subscription = 0;



            if (rt->state == RTSP_STATE_PLAYING)

                rtsp_read_play (VAR_0);

        }

    }



    VAR_2 = rtsp_fetch_packet(VAR_0, VAR_1);

    if (VAR_2 < 0) {

        return VAR_2;

    }



    

    if ((rt->server_type == RTSP_SERVER_WMS ||

         rt->server_type == RTSP_SERVER_REAL) &&

        (av_gettime() - rt->last_cmd_time) / 1000000 >= rt->timeout / 2) {

        if (rt->server_type == RTSP_SERVER_WMS) {

            snprintf(VAR_3, sizeof(VAR_3) - 1,

                     "GET_PARAMETER %VAR_0 RTSP/1.0\VAR_6\n",

                     VAR_0->filename);

            rtsp_send_cmd_async(VAR_0, VAR_3, reply, NULL);

        } else {

            rtsp_send_cmd_async(VAR_0, "OPTIONS * RTSP/1.0\VAR_6\n",

                                reply, NULL);

        }

    }



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0,
AVPacket *VAR_1)
{ RTSPState *rt = VAR_0->priv_data; int VAR_2; RTSPMessageHeader reply1, *reply = &reply1; char VAR_3[1024]; if (rt->server_type == RTSP_SERVER_REAL) { int VAR_4; enum AVDiscard VAR_5[MAX_STREAMS]; for (VAR_4 = 0; VAR_4 < VAR_0->nb_streams; VAR_4++) VAR_5[VAR_4] = VAR_0->streams[VAR_4]->discard; if (!rt->need_subscription) { if (memcmp (VAR_5, rt->real_setup_cache,
sizeof(enum AVDiscard) * VAR_0->nb_streams)) { av_strlcatf(VAR_3, sizeof(VAR_3),
"SET_PARAMETER %VAR_0 RTSP/1.0\VAR_6\n"
"Unsubscribe: %VAR_0\VAR_6\n",
VAR_0->filename, rt->last_subscription); rtsp_send_cmd(VAR_0, VAR_3, reply, NULL); if (reply->status_code != RTSP_STATUS_OK)
return AVERROR_INVALIDDATA; rt->need_subscription = 1; } } if (rt->need_subscription) { int VAR_6, VAR_7, VAR_8 = 1; memcpy(rt->real_setup_cache, VAR_5,
sizeof(enum AVDiscard) * VAR_0->nb_streams); rt->last_subscription[0] = 0; snprintf(VAR_3, sizeof(VAR_3),
"SET_PARAMETER %VAR_0 RTSP/1.0\VAR_6\n"
"Subscribe: ",
VAR_0->filename); for (VAR_4 = 0; VAR_4 < rt->nb_rtsp_streams; VAR_4++) { VAR_7 = 0; for (VAR_6 = 0; VAR_6 < VAR_0->nb_streams; VAR_6++) { if (VAR_0->streams[VAR_6]->priv_data == rt->rtsp_streams[VAR_4]) { if (VAR_0->streams[VAR_6]->discard != AVDISCARD_ALL) { if (!VAR_8)
av_strlcat(rt->last_subscription, ",",
sizeof(rt->last_subscription)); ff_rdt_subscribe_rule(
rt->last_subscription,
sizeof(rt->last_subscription), VAR_4, VAR_7); VAR_8 = 0; } VAR_7++; } } } av_strlcatf(VAR_3, sizeof(VAR_3), "%VAR_0\VAR_6\n", rt->last_subscription); rtsp_send_cmd(VAR_0, VAR_3, reply, NULL); if (reply->status_code != RTSP_STATUS_OK)
return AVERROR_INVALIDDATA; rt->need_subscription = 0; if (rt->state == RTSP_STATE_PLAYING)
rtsp_read_play (VAR_0); } } VAR_2 = rtsp_fetch_packet(VAR_0, VAR_1); if (VAR_2 < 0) { return VAR_2; } if ((rt->server_type == RTSP_SERVER_WMS ||
rt->server_type == RTSP_SERVER_REAL) &&
(av_gettime() - rt->last_cmd_time) / 1000000 >= rt->timeout / 2) { if (rt->server_type == RTSP_SERVER_WMS) { snprintf(VAR_3, sizeof(VAR_3) - 1,
"GET_PARAMETER %VAR_0 RTSP/1.0\VAR_6\n",
VAR_0->filename); rtsp_send_cmd_async(VAR_0, VAR_3, reply, NULL); } else { rtsp_send_cmd_async(VAR_0, "OPTIONS * RTSP/1.0\VAR_6\n",
reply, NULL); } } return 0; }