static int rtp_new_av_stream(HTTPContext *c,

                             int stream_index, struct sockaddr_in *dest_addr,

                             HTTPContext *rtsp_c)

{

    AVFormatContext *ctx;

    AVStream *st;

    char *ipaddr;

    URLContext *h = NULL;

    uint8_t *dummy_buf;

    int max_packet_size;



    /* now we can open the relevant output stream */

    ctx = avformat_alloc_context();

    if (!ctx)

        return -1;

    ctx->oformat = av_guess_format("rtp", NULL, NULL);



    st = av_mallocz(sizeof(AVStream));

    if (!st)

        goto fail;

    st->codec= avcodec_alloc_context();

    ctx->nb_streams = 1;

    ctx->streams[0] = st;



    if (!c->stream->feed ||

        c->stream->feed == c->stream)

        memcpy(st, c->stream->streams[stream_index], sizeof(AVStream));

    else

        memcpy(st,

               c->stream->feed->streams[c->stream->feed_streams[stream_index]],

               sizeof(AVStream));

    st->priv_data = NULL;



    /* build destination RTP address */

    ipaddr = inet_ntoa(dest_addr->sin_addr);



    switch(c->rtp_protocol) {

    case RTSP_LOWER_TRANSPORT_UDP:

    case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:

        /* RTP/UDP case */



        /* XXX: also pass as parameter to function ? */

        if (c->stream->is_multicast) {

            int ttl;

            ttl = c->stream->multicast_ttl;

            if (!ttl)

                ttl = 16;

            snprintf(ctx->filename, sizeof(ctx->filename),

                     "rtp://%s:%d?multicast=1&ttl=%d",

                     ipaddr, ntohs(dest_addr->sin_port), ttl);

        } else {

            snprintf(ctx->filename, sizeof(ctx->filename),

                     "rtp://%s:%d", ipaddr, ntohs(dest_addr->sin_port));

        }



        if (url_open(&h, ctx->filename, URL_WRONLY) < 0)

            goto fail;

        c->rtp_handles[stream_index] = h;

        max_packet_size = url_get_max_packet_size(h);

        break;

    case RTSP_LOWER_TRANSPORT_TCP:

        /* RTP/TCP case */

        c->rtsp_c = rtsp_c;

        max_packet_size = RTSP_TCP_MAX_PACKET_SIZE;

        break;

    default:

        goto fail;

    }



    http_log("%s:%d - - \"PLAY %s/streamid=%d %s\"\n",

             ipaddr, ntohs(dest_addr->sin_port),

             c->stream->filename, stream_index, c->protocol);



    /* normally, no packets should be output here, but the packet size may be checked */

    if (url_open_dyn_packet_buf(&ctx->pb, max_packet_size) < 0) {

        /* XXX: close stream */

        goto fail;

    }

    av_set_parameters(ctx, NULL);

    if (av_write_header(ctx) < 0) {

    fail:

        if (h)

            url_close(h);

        av_free(ctx);

        return -1;

    }

    url_close_dyn_buf(ctx->pb, &dummy_buf);

    av_free(dummy_buf);



    c->rtp_ctx[stream_index] = ctx;

    return 0;

}

static int rtp_new_av_stream(HTTPContext *c,

                             int stream_index, struct sockaddr_in *dest_addr,

                             HTTPContext *rtsp_c)

{

    AVFormatContext *ctx;

    AVStream *st;

    char *ipaddr;

    URLContext *h = NULL;

    uint8_t *dummy_buf;

    int max_packet_size;



    

    ctx = avformat_alloc_context();

    if (!ctx)

        return -1;

    ctx->oformat = av_guess_format("rtp", NULL, NULL);



    st = av_mallocz(sizeof(AVStream));

    if (!st)

        goto fail;

    st->codec= avcodec_alloc_context();

    ctx->nb_streams = 1;

    ctx->streams[0] = st;



    if (!c->stream->feed ||

        c->stream->feed == c->stream)

        memcpy(st, c->stream->streams[stream_index], sizeof(AVStream));

    else

        memcpy(st,

               c->stream->feed->streams[c->stream->feed_streams[stream_index]],

               sizeof(AVStream));

    st->priv_data = NULL;



    

    ipaddr = inet_ntoa(dest_addr->sin_addr);



    switch(c->rtp_protocol) {

    case RTSP_LOWER_TRANSPORT_UDP:

    case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:

        



        

        if (c->stream->is_multicast) {

            int ttl;

            ttl = c->stream->multicast_ttl;

            if (!ttl)

                ttl = 16;

            snprintf(ctx->filename, sizeof(ctx->filename),

                     "rtp:

                     ipaddr, ntohs(dest_addr->sin_port), ttl);

        } else {

            snprintf(ctx->filename, sizeof(ctx->filename),

                     "rtp:

        }



        if (url_open(&h, ctx->filename, URL_WRONLY) < 0)

            goto fail;

        c->rtp_handles[stream_index] = h;

        max_packet_size = url_get_max_packet_size(h);

        break;

    case RTSP_LOWER_TRANSPORT_TCP:

        

        c->rtsp_c = rtsp_c;

        max_packet_size = RTSP_TCP_MAX_PACKET_SIZE;

        break;

    default:

        goto fail;

    }



    http_log("%s:%d - - \"PLAY %s/streamid=%d %s\"\n",

             ipaddr, ntohs(dest_addr->sin_port),

             c->stream->filename, stream_index, c->protocol);



    

    if (url_open_dyn_packet_buf(&ctx->pb, max_packet_size) < 0) {

        

        goto fail;

    }

    av_set_parameters(ctx, NULL);

    if (av_write_header(ctx) < 0) {

    fail:

        if (h)

            url_close(h);

        av_free(ctx);

        return -1;

    }

    url_close_dyn_buf(ctx->pb, &dummy_buf);

    av_free(dummy_buf);



    c->rtp_ctx[stream_index] = ctx;

    return 0;

}

    st->codec= avcodec_alloc_context();
static int FUNC_0(HTTPContext *VAR_0,

                             int VAR_1, struct sockaddr_in *VAR_2,

                             HTTPContext *VAR_3)

{

    AVFormatContext *ctx;

    AVStream *st;

    char *VAR_4;

    URLContext *h = NULL;

    uint8_t *dummy_buf;

    int VAR_5;



    

    ctx = avformat_alloc_context();

    if (!ctx)

        return -1;

    ctx->oformat = av_guess_format("rtp", NULL, NULL);



    st = av_mallocz(sizeof(AVStream));

    if (!st)

        goto fail;

    st->codec= avcodec_alloc_context();

    ctx->nb_streams = 1;

    ctx->streams[0] = st;



    if (!VAR_0->stream->feed ||

        VAR_0->stream->feed == VAR_0->stream)

        memcpy(st, VAR_0->stream->streams[VAR_1], sizeof(AVStream));

    else

        memcpy(st,

               VAR_0->stream->feed->streams[VAR_0->stream->feed_streams[VAR_1]],

               sizeof(AVStream));

    st->priv_data = NULL;



    

    VAR_4 = inet_ntoa(VAR_2->sin_addr);



    switch(VAR_0->rtp_protocol) {

    case RTSP_LOWER_TRANSPORT_UDP:

    case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:

        



        

        if (VAR_0->stream->is_multicast) {

            int VAR_6;

            VAR_6 = VAR_0->stream->multicast_ttl;

            if (!VAR_6)

                VAR_6 = 16;

            snprintf(ctx->filename, sizeof(ctx->filename),

                     "rtp:

                     VAR_4, ntohs(VAR_2->sin_port), VAR_6);

        } else {

            snprintf(ctx->filename, sizeof(ctx->filename),

                     "rtp:

        }



        if (url_open(&h, ctx->filename, URL_WRONLY) < 0)

            goto fail;

        VAR_0->rtp_handles[VAR_1] = h;

        VAR_5 = url_get_max_packet_size(h);

        break;

    case RTSP_LOWER_TRANSPORT_TCP:

        

        VAR_0->VAR_3 = VAR_3;

        VAR_5 = RTSP_TCP_MAX_PACKET_SIZE;

        break;

    default:

        goto fail;

    }



    http_log("%s:%d - - \"PLAY %s/streamid=%d %s\"\n",

             VAR_4, ntohs(VAR_2->sin_port),

             VAR_0->stream->filename, VAR_1, VAR_0->protocol);



    

    if (url_open_dyn_packet_buf(&ctx->pb, VAR_5) < 0) {

        

        goto fail;

    }

    av_set_parameters(ctx, NULL);

    if (av_write_header(ctx) < 0) {

    fail:

        if (h)

            url_close(h);

        av_free(ctx);

        return -1;

    }

    url_close_dyn_buf(ctx->pb, &dummy_buf);

    av_free(dummy_buf);



    VAR_0->rtp_ctx[VAR_1] = ctx;

    return 0;

}

static int FUNC_0(HTTPContext *VAR_0,
int VAR_1, struct sockaddr_in *VAR_2,
HTTPContext *VAR_3)
{ AVFormatContext *ctx; AVStream *st; char *VAR_4; URLContext *h = NULL; uint8_t *dummy_buf; int VAR_5; ctx = avformat_alloc_context(); if (!ctx)
return -1; ctx->oformat = av_guess_format("rtp", NULL, NULL); st = av_mallocz(sizeof(AVStream)); if (!st)
goto fail; st->codec= avcodec_alloc_context(); ctx->nb_streams = 1; ctx->streams[0] = st; if (!VAR_0->stream->feed ||
VAR_0->stream->feed == VAR_0->stream)
memcpy(st, VAR_0->stream->streams[VAR_1], sizeof(AVStream)); else
memcpy(st,
VAR_0->stream->feed->streams[VAR_0->stream->feed_streams[VAR_1]],
sizeof(AVStream)); st->priv_data = NULL; VAR_4 = inet_ntoa(VAR_2->sin_addr); switch(VAR_0->rtp_protocol) { case RTSP_LOWER_TRANSPORT_UDP:
case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:
if (VAR_0->stream->is_multicast) { int VAR_6; VAR_6 = VAR_0->stream->multicast_ttl; if (!VAR_6)
VAR_6 = 16; snprintf(ctx->filename, sizeof(ctx->filename),
"rtp:
VAR_4, ntohs(VAR_2->sin_port), VAR_6); } else { snprintf(ctx->filename, sizeof(ctx->filename),
"rtp:
} if (url_open(&h, ctx->filename, URL_WRONLY) < 0)
goto fail; VAR_0->rtp_handles[VAR_1] = h; VAR_5 = url_get_max_packet_size(h); break; case RTSP_LOWER_TRANSPORT_TCP:
VAR_0->VAR_3 = VAR_3; VAR_5 = RTSP_TCP_MAX_PACKET_SIZE; break; default:
goto fail; } http_log("%s:%d - - \"PLAY %s/streamid=%d %s\"\n",
VAR_4, ntohs(VAR_2->sin_port),
VAR_0->stream->filename, VAR_1, VAR_0->protocol); if (url_open_dyn_packet_buf(&ctx->pb, VAR_5) < 0) { goto fail; } av_set_parameters(ctx, NULL); if (av_write_header(ctx) < 0) { fail:
if (h)
url_close(h); av_free(ctx); return -1; } url_close_dyn_buf(ctx->pb, &dummy_buf); av_free(dummy_buf); VAR_0->rtp_ctx[VAR_1] = ctx; return 0; }