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;
    uint8_t *dummy_buf;
    char buf2[32];
    int max_packet_size;
    ctx = av_alloc_format_context();
    if (!ctx)
        return -1;
    ctx->oformat = 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_PROTOCOL_RTP_UDP:
    case RTSP_PROTOCOL_RTP_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://%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_PROTOCOL_RTP_TCP:
        c->rtsp_c = rtsp_c;
        max_packet_size = RTSP_TCP_MAX_PACKET_SIZE;
        break;
    default:
        goto fail;
    }
    http_log("%s:%d - - [%s] \"PLAY %s/streamid=%d %s\"\n",
             ipaddr, ntohs(dest_addr->sin_port),
             ctime1(buf2),
             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;
}
['static int rtp_new_av_stream(HTTPContext *c,\n                             int stream_index, struct sockaddr_in *dest_addr,\n                             HTTPContext *rtsp_c)\n{\n    AVFormatContext *ctx;\n    AVStream *st;\n    char *ipaddr;\n    URLContext *h;\n    uint8_t *dummy_buf;\n    char buf2[32];\n    int max_packet_size;\n    ctx = av_alloc_format_context();\n    if (!ctx)\n        return -1;\n    ctx->oformat = guess_format("rtp", NULL, NULL);\n    st = av_mallocz(sizeof(AVStream));\n    if (!st)\n        goto fail;\n    st->codec= avcodec_alloc_context();\n    ctx->nb_streams = 1;\n    ctx->streams[0] = st;\n    if (!c->stream->feed ||\n        c->stream->feed == c->stream)\n        memcpy(st, c->stream->streams[stream_index], sizeof(AVStream));\n    else\n        memcpy(st,\n               c->stream->feed->streams[c->stream->feed_streams[stream_index]],\n               sizeof(AVStream));\n    st->priv_data = NULL;\n    ipaddr = inet_ntoa(dest_addr->sin_addr);\n    switch(c->rtp_protocol) {\n    case RTSP_PROTOCOL_RTP_UDP:\n    case RTSP_PROTOCOL_RTP_UDP_MULTICAST:\n        if (c->stream->is_multicast) {\n            int ttl;\n            ttl = c->stream->multicast_ttl;\n            if (!ttl)\n                ttl = 16;\n            snprintf(ctx->filename, sizeof(ctx->filename),\n                     "rtp://%s:%d?multicast=1&ttl=%d",\n                     ipaddr, ntohs(dest_addr->sin_port), ttl);\n        } else {\n            snprintf(ctx->filename, sizeof(ctx->filename),\n                     "rtp://%s:%d", ipaddr, ntohs(dest_addr->sin_port));\n        }\n        if (url_open(&h, ctx->filename, URL_WRONLY) < 0)\n            goto fail;\n        c->rtp_handles[stream_index] = h;\n        max_packet_size = url_get_max_packet_size(h);\n        break;\n    case RTSP_PROTOCOL_RTP_TCP:\n        c->rtsp_c = rtsp_c;\n        max_packet_size = RTSP_TCP_MAX_PACKET_SIZE;\n        break;\n    default:\n        goto fail;\n    }\n    http_log("%s:%d - - [%s] \\"PLAY %s/streamid=%d %s\\"\\n",\n             ipaddr, ntohs(dest_addr->sin_port),\n             ctime1(buf2),\n             c->stream->filename, stream_index, c->protocol);\n    if (url_open_dyn_packet_buf(&ctx->pb, max_packet_size) < 0) {\n        goto fail;\n    }\n    av_set_parameters(ctx, NULL);\n    if (av_write_header(ctx) < 0) {\n    fail:\n        if (h)\n            url_close(h);\n        av_free(ctx);\n        return -1;\n    }\n    url_close_dyn_buf(ctx->pb, &dummy_buf);\n    av_free(dummy_buf);\n    c->rtp_ctx[stream_index] = ctx;\n    return 0;\n}']