X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffserver.c;h=3ad40e9bfbef34e215aa3c17b062f2c84b161777;hb=6cc7f1398257d4ffa89f79d52f10b2cabd9ad232;hp=cbf04aa4a542994bc0101283a8accd013381edbd;hpb=737eb5976f6a37703923ce3c3d5e6ca8eeabb43a;p=ffmpeg diff --git a/ffserver.c b/ffserver.c index cbf04aa4a54..3ad40e9bfbe 100644 --- a/ffserver.c +++ b/ffserver.c @@ -2,20 +2,20 @@ * Multiple format streaming server * Copyright (c) 2000, 2001, 2002 Fabrice Bellard * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -33,6 +33,8 @@ #include "libavformat/os_support.h" #include "libavformat/rtpdec.h" #include "libavformat/rtsp.h" +// XXX for ffio_open_dyn_packet_buffer, to be removed +#include "libavformat/avio_internal.h" #include "libavutil/avstring.h" #include "libavutil/lfg.h" #include "libavutil/random_seed.h" @@ -163,7 +165,7 @@ typedef struct HTTPContext { /* RTSP state specific */ uint8_t *pb_buffer; /* XXX: use that in all the code */ - ByteIOContext *pb; + AVIOContext *pb; int seq; /* RTSP sequence number */ /* RTP state specific */ @@ -692,8 +694,8 @@ static int http_server(void) second to handle timeouts */ do { ret = poll(poll_table, poll_entry - poll_table, delay); - if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) && - ff_neterrno() != FF_NETERROR(EINTR)) + if (ret < 0 && ff_neterrno() != AVERROR(EAGAIN) && + ff_neterrno() != AVERROR(EINTR)) return -1; } while (ret < 0); @@ -869,10 +871,10 @@ static void close_connection(HTTPContext *c) if (!c->last_packet_sent && c->state == HTTPSTATE_SEND_DATA_TRAILER) { if (ctx->oformat) { /* prepare header */ - if (url_open_dyn_buf(&ctx->pb) >= 0) { + if (avio_open_dyn_buf(&ctx->pb) >= 0) { av_write_trailer(ctx); av_freep(&c->pb_buffer); - url_close_dyn_buf(ctx->pb, &c->pb_buffer); + avio_close_dyn_buf(ctx->pb, &c->pb_buffer); } } } @@ -916,8 +918,8 @@ static int handle_connection(HTTPContext *c) read_loop: len = recv(c->fd, c->buffer_ptr, 1, 0); if (len < 0) { - if (ff_neterrno() != FF_NETERROR(EAGAIN) && - ff_neterrno() != FF_NETERROR(EINTR)) + if (ff_neterrno() != AVERROR(EAGAIN) && + ff_neterrno() != AVERROR(EINTR)) return -1; } else if (len == 0) { return -1; @@ -952,8 +954,8 @@ static int handle_connection(HTTPContext *c) return 0; len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0); if (len < 0) { - if (ff_neterrno() != FF_NETERROR(EAGAIN) && - ff_neterrno() != FF_NETERROR(EINTR)) { + if (ff_neterrno() != AVERROR(EAGAIN) && + ff_neterrno() != AVERROR(EINTR)) { /* error : close connection */ av_freep(&c->pb_buffer); return -1; @@ -1022,8 +1024,8 @@ static int handle_connection(HTTPContext *c) return 0; len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0); if (len < 0) { - if (ff_neterrno() != FF_NETERROR(EAGAIN) && - ff_neterrno() != FF_NETERROR(EINTR)) { + if (ff_neterrno() != AVERROR(EAGAIN) && + ff_neterrno() != AVERROR(EINTR)) { /* error : close connection */ av_freep(&c->pb_buffer); return -1; @@ -1049,8 +1051,8 @@ static int handle_connection(HTTPContext *c) len = send(c->fd, c->packet_buffer_ptr, c->packet_buffer_end - c->packet_buffer_ptr, 0); if (len < 0) { - if (ff_neterrno() != FF_NETERROR(EAGAIN) && - ff_neterrno() != FF_NETERROR(EINTR)) { + if (ff_neterrno() != AVERROR(EAGAIN) && + ff_neterrno() != AVERROR(EINTR)) { /* error : close connection */ av_freep(&c->packet_buffer); return -1; @@ -1854,14 +1856,14 @@ static int http_parse_request(HTTPContext *c) return 0; } -static void fmt_bytecount(ByteIOContext *pb, int64_t count) +static void fmt_bytecount(AVIOContext *pb, int64_t count) { static const char *suffix = " kMGTP"; const char *s; for (s = suffix; count >= 100000 && s[1]; count /= 1000, s++); - url_fprintf(pb, "%"PRId64"%c", count, *s); + avio_printf(pb, "%"PRId64"%c", count, *s); } static void compute_status(HTTPContext *c) @@ -1871,29 +1873,29 @@ static void compute_status(HTTPContext *c) char *p; time_t ti; int i, len; - ByteIOContext *pb; + AVIOContext *pb; - if (url_open_dyn_buf(&pb) < 0) { + if (avio_open_dyn_buf(&pb) < 0) { /* XXX: return an error ? */ c->buffer_ptr = c->buffer; c->buffer_end = c->buffer; return; } - url_fprintf(pb, "HTTP/1.0 200 OK\r\n"); - url_fprintf(pb, "Content-type: %s\r\n", "text/html"); - url_fprintf(pb, "Pragma: no-cache\r\n"); - url_fprintf(pb, "\r\n"); + avio_printf(pb, "HTTP/1.0 200 OK\r\n"); + avio_printf(pb, "Content-type: %s\r\n", "text/html"); + avio_printf(pb, "Pragma: no-cache\r\n"); + avio_printf(pb, "\r\n"); - url_fprintf(pb, "%s Status\n", program_name); + avio_printf(pb, "%s Status\n", program_name); if (c->stream->feed_filename[0]) - url_fprintf(pb, "\n", c->stream->feed_filename); - url_fprintf(pb, "\n"); - url_fprintf(pb, "

%s Status

\n", program_name); + avio_printf(pb, "\n", c->stream->feed_filename); + avio_printf(pb, "\n"); + avio_printf(pb, "

%s Status

\n", program_name); /* format status */ - url_fprintf(pb, "

Available Streams

\n"); - url_fprintf(pb, "\n"); - url_fprintf(pb, "
PathServed
Conns

bytes
FormatBit rate
kbits/s
Video
kbits/s

Codec
Audio
kbits/s

Codec
Feed\n"); + avio_printf(pb, "

Available Streams

\n"); + avio_printf(pb, "\n"); + avio_printf(pb, "
PathServed
Conns

bytes
FormatBit rate
kbits/s
Video
kbits/s

Codec
Audio
kbits/s

Codec
Feed\n"); stream = first_stream; while (stream != NULL) { char sfilename[1024]; @@ -1921,9 +1923,9 @@ static void compute_status(HTTPContext *c) } } - url_fprintf(pb, "
%s ", + avio_printf(pb, "
%s ", sfilename, stream->filename); - url_fprintf(pb, " %d ", + avio_printf(pb, " %d ", stream->conns_served); fmt_bytecount(pb, stream->bytes_served); switch(stream->stream_type) { @@ -1962,33 +1964,33 @@ static void compute_status(HTTPContext *c) abort(); } } - url_fprintf(pb, " %s %d %d %s %s %d %s %s", + avio_printf(pb, " %s %d %d %s %s %d %s %s", stream->fmt->name, stream->bandwidth, video_bit_rate / 1000, video_codec_name, video_codec_name_extra, audio_bit_rate / 1000, audio_codec_name, audio_codec_name_extra); if (stream->feed) - url_fprintf(pb, "%s", stream->feed->filename); + avio_printf(pb, "%s", stream->feed->filename); else - url_fprintf(pb, "%s", stream->feed_filename); - url_fprintf(pb, "\n"); + avio_printf(pb, "%s", stream->feed_filename); + avio_printf(pb, "\n"); } break; default: - url_fprintf(pb, " - - - - \n"); + avio_printf(pb, " - - - - \n"); break; } } stream = stream->next; } - url_fprintf(pb, "
\n"); + avio_printf(pb, "
\n"); stream = first_stream; while (stream != NULL) { if (stream->feed == stream) { - url_fprintf(pb, "

Feed %s

", stream->filename); + avio_printf(pb, "

Feed %s

", stream->filename); if (stream->pid) { - url_fprintf(pb, "Running as pid %d.\n", stream->pid); + avio_printf(pb, "Running as pid %d.\n", stream->pid); #if defined(linux) && !defined(CONFIG_NOCUTILS) { @@ -2007,7 +2009,7 @@ static void compute_status(HTTPContext *c) if (fscanf(pid_stat, "%10s %64s", cpuperc, cpuused) == 2) { - url_fprintf(pb, "Currently using %s%% of the cpu. Total time used %s.\n", + avio_printf(pb, "Currently using %s%% of the cpu. Total time used %s.\n", cpuperc, cpuused); } fclose(pid_stat); @@ -2015,9 +2017,9 @@ static void compute_status(HTTPContext *c) } #endif - url_fprintf(pb, "

"); + avio_printf(pb, "

"); } - url_fprintf(pb, "
Streamtypekbits/scodecParameters\n"); + avio_printf(pb, "
Streamtypekbits/scodecParameters\n"); for (i = 0; i < stream->nb_streams; i++) { AVStream *st = stream->streams[i]; @@ -2040,26 +2042,26 @@ static void compute_status(HTTPContext *c) default: abort(); } - url_fprintf(pb, "
%d%s%d%s%s\n", + avio_printf(pb, "
%d%s%d%s%s\n", i, type, st->codec->bit_rate/1000, codec ? codec->name : "", parameters); } - url_fprintf(pb, "
\n"); + avio_printf(pb, "
\n"); } stream = stream->next; } /* connection status */ - url_fprintf(pb, "

Connection Status

\n"); + avio_printf(pb, "

Connection Status

\n"); - url_fprintf(pb, "Number of connections: %d / %d
\n", + avio_printf(pb, "Number of connections: %d / %d
\n", nb_connections, nb_max_connections); - url_fprintf(pb, "Bandwidth in use: %"PRIu64"k / %"PRIu64"k
\n", + avio_printf(pb, "Bandwidth in use: %"PRIu64"k / %"PRIu64"k
\n", current_bandwidth, max_bandwidth); - url_fprintf(pb, "\n"); - url_fprintf(pb, "
#FileIPProtoStateTarget bits/secActual bits/secBytes transferred\n"); + avio_printf(pb, "\n"); + avio_printf(pb, "
#FileIPProtoStateTarget bits/secActual bits/secBytes transferred\n"); c1 = first_http_ctx; i = 0; while (c1 != NULL) { @@ -2078,7 +2080,7 @@ static void compute_status(HTTPContext *c) i++; p = inet_ntoa(c1->from_addr.sin_addr); - url_fprintf(pb, "
%d%s%s%s%s%s", + avio_printf(pb, "
%d%s%s%s%s%s", i, c1->stream ? c1->stream->filename : "", c1->state == HTTPSTATE_RECEIVE_DATA ? "(input)" : "", @@ -2086,22 +2088,22 @@ static void compute_status(HTTPContext *c) c1->protocol, http_state[c1->state]); fmt_bytecount(pb, bitrate); - url_fprintf(pb, ""); + avio_printf(pb, ""); fmt_bytecount(pb, compute_datarate(&c1->datarate, c1->data_count) * 8); - url_fprintf(pb, ""); + avio_printf(pb, ""); fmt_bytecount(pb, c1->data_count); - url_fprintf(pb, "\n"); + avio_printf(pb, "\n"); c1 = c1->next; } - url_fprintf(pb, "
\n"); + avio_printf(pb, "
\n"); /* date */ ti = time(NULL); p = ctime(&ti); - url_fprintf(pb, "
Generated at %s", p); - url_fprintf(pb, "\n\n"); + avio_printf(pb, "
Generated at %s", p); + avio_printf(pb, "\n\n"); - len = url_close_dyn_buf(pb, &c->pb_buffer); + len = avio_close_dyn_buf(pb, &c->pb_buffer); c->buffer_ptr = c->pb_buffer; c->buffer_end = c->pb_buffer + len; } @@ -2135,11 +2137,10 @@ static int open_input_stream(HTTPContext *c, const char *info) strcpy(input_filename, c->stream->feed->feed_filename); buf_size = FFM_PACKET_SIZE; /* compute position (absolute time) */ - if (find_info_tag(buf, sizeof(buf), "date", info)) { - stream_pos = parse_date(buf, 0); - if (stream_pos == INT64_MIN) - return -1; - } else if (find_info_tag(buf, sizeof(buf), "buffer", info)) { + if (av_find_info_tag(buf, sizeof(buf), "date", info)) { + if ((ret = av_parse_time(&stream_pos, buf, 0)) < 0) + return ret; + } else if (av_find_info_tag(buf, sizeof(buf), "buffer", info)) { int prebuffer = strtol(buf, 0, 10); stream_pos = av_gettime() - prebuffer * (int64_t)1000000; } else @@ -2148,10 +2149,9 @@ static int open_input_stream(HTTPContext *c, const char *info) strcpy(input_filename, c->stream->feed_filename); buf_size = 0; /* compute position (relative time) */ - if (find_info_tag(buf, sizeof(buf), "date", info)) { - stream_pos = parse_date(buf, 1); - if (stream_pos == INT64_MIN) - return -1; + if (av_find_info_tag(buf, sizeof(buf), "date", info)) { + if ((ret = av_parse_time(&stream_pos, buf, 1)) < 0) + return ret; } else stream_pos = 0; } @@ -2258,11 +2258,11 @@ static int http_prepare_data(HTTPContext *c) c->got_key_frame = 0; /* prepare header and save header data in a stream */ - if (url_open_dyn_buf(&c->fmt_ctx.pb) < 0) { + if (avio_open_dyn_buf(&c->fmt_ctx.pb) < 0) { /* XXX: potential leak */ return -1; } - c->fmt_ctx.pb->is_streamed = 1; + c->fmt_ctx.pb->seekable = 0; /* * HACK to avoid mpeg ps muxer to spit many underflow errors @@ -2279,7 +2279,7 @@ static int http_prepare_data(HTTPContext *c) } av_metadata_free(&c->fmt_ctx.metadata); - len = url_close_dyn_buf(c->fmt_ctx.pb, &c->pb_buffer); + len = avio_close_dyn_buf(c->fmt_ctx.pb, &c->pb_buffer); c->buffer_ptr = c->pb_buffer; c->buffer_end = c->pb_buffer + len; @@ -2391,9 +2391,9 @@ static int http_prepare_data(HTTPContext *c) max_packet_size = RTSP_TCP_MAX_PACKET_SIZE; else max_packet_size = url_get_max_packet_size(c->rtp_handles[c->packet_stream_index]); - ret = url_open_dyn_packet_buf(&ctx->pb, max_packet_size); + ret = ffio_open_dyn_packet_buf(&ctx->pb, max_packet_size); } else { - ret = url_open_dyn_buf(&ctx->pb); + ret = avio_open_dyn_buf(&ctx->pb); } if (ret < 0) { /* XXX: potential leak */ @@ -2401,7 +2401,7 @@ static int http_prepare_data(HTTPContext *c) } ost = ctx->streams[pkt.stream_index]; - ctx->pb->is_streamed = 1; + ctx->pb->seekable = 0; if (pkt.dts != AV_NOPTS_VALUE) pkt.dts = av_rescale_q(pkt.dts, ist->time_base, ost->time_base); if (pkt.pts != AV_NOPTS_VALUE) @@ -2412,7 +2412,7 @@ static int http_prepare_data(HTTPContext *c) c->state = HTTPSTATE_SEND_DATA_TRAILER; } - len = url_close_dyn_buf(ctx->pb, &c->pb_buffer); + len = avio_close_dyn_buf(ctx->pb, &c->pb_buffer); c->cur_frame_bytes = len; c->buffer_ptr = c->pb_buffer; c->buffer_end = c->pb_buffer + len; @@ -2434,13 +2434,13 @@ static int http_prepare_data(HTTPContext *c) return -1; ctx = &c->fmt_ctx; /* prepare header */ - if (url_open_dyn_buf(&ctx->pb) < 0) { + if (avio_open_dyn_buf(&ctx->pb) < 0) { /* XXX: potential leak */ return -1; } - c->fmt_ctx.pb->is_streamed = 1; + c->fmt_ctx.pb->seekable = 0; av_write_trailer(ctx); - len = url_close_dyn_buf(ctx->pb, &c->pb_buffer); + len = avio_close_dyn_buf(ctx->pb, &c->pb_buffer); c->buffer_ptr = c->pb_buffer; c->buffer_end = c->pb_buffer + len; @@ -2493,7 +2493,7 @@ static int http_send_data(HTTPContext *c) if (c->rtp_protocol == RTSP_LOWER_TRANSPORT_TCP) { /* RTP packets are sent inside the RTSP TCP connection */ - ByteIOContext *pb; + AVIOContext *pb; int interleaved_index, size; uint8_t header[4]; HTTPContext *rtsp_c; @@ -2505,7 +2505,7 @@ static int http_send_data(HTTPContext *c) /* if already sending something, then wait. */ if (rtsp_c->state != RTSPSTATE_WAIT_REQUEST) break; - if (url_open_dyn_buf(&pb) < 0) + if (avio_open_dyn_buf(&pb) < 0) goto fail1; interleaved_index = c->packet_stream_index * 2; /* RTCP packets are sent at odd indexes */ @@ -2516,11 +2516,11 @@ static int http_send_data(HTTPContext *c) header[1] = interleaved_index; header[2] = len >> 8; header[3] = len; - put_buffer(pb, header, 4); + avio_write(pb, header, 4); /* write RTP packet data */ c->buffer_ptr += 4; - put_buffer(pb, c->buffer_ptr, len); - size = url_close_dyn_buf(pb, &c->packet_buffer); + avio_write(pb, c->buffer_ptr, len); + size = avio_close_dyn_buf(pb, &c->packet_buffer); /* prepare asynchronous TCP sending */ rtsp_c->packet_buffer_ptr = c->packet_buffer; rtsp_c->packet_buffer_end = c->packet_buffer + size; @@ -2552,8 +2552,8 @@ static int http_send_data(HTTPContext *c) /* TCP data output */ len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0); if (len < 0) { - if (ff_neterrno() != FF_NETERROR(EAGAIN) && - ff_neterrno() != FF_NETERROR(EINTR)) + if (ff_neterrno() != AVERROR(EAGAIN) && + ff_neterrno() != AVERROR(EINTR)) /* error : close connection */ return -1; else @@ -2626,8 +2626,8 @@ static int http_receive_data(HTTPContext *c) len = recv(c->fd, c->buffer_ptr, 1, 0); if (len < 0) { - if (ff_neterrno() != FF_NETERROR(EAGAIN) && - ff_neterrno() != FF_NETERROR(EINTR)) + if (ff_neterrno() != AVERROR(EAGAIN) && + ff_neterrno() != AVERROR(EINTR)) /* error : close connection */ goto fail; return 0; @@ -2653,8 +2653,8 @@ static int http_receive_data(HTTPContext *c) len = recv(c->fd, c->buffer_ptr, FFMIN(c->chunk_size, c->buffer_end - c->buffer_ptr), 0); if (len < 0) { - if (ff_neterrno() != FF_NETERROR(EAGAIN) && - ff_neterrno() != FF_NETERROR(EINTR)) + if (ff_neterrno() != AVERROR(EAGAIN) && + ff_neterrno() != AVERROR(EINTR)) /* error : close connection */ goto fail; } else if (len == 0) @@ -2714,7 +2714,7 @@ static int http_receive_data(HTTPContext *c) } else { /* We have a header in our hands that contains useful data */ AVFormatContext *s = NULL; - ByteIOContext *pb; + AVIOContext *pb; AVInputFormat *fmt_in; int i; @@ -2723,8 +2723,9 @@ static int http_receive_data(HTTPContext *c) if (!fmt_in) goto fail; - url_open_buf(&pb, c->buffer, c->buffer_end - c->buffer, URL_RDONLY); - pb->is_streamed = 1; + pb = avio_alloc_context(c->buffer, c->buffer_end - c->buffer, + 0, NULL, NULL, NULL, NULL); + pb->seekable = 0; if (av_open_input_stream(&s, pb, c->stream->feed_filename, fmt_in, NULL) < 0) { av_free(pb); @@ -2814,20 +2815,20 @@ static void rtsp_reply_header(HTTPContext *c, enum RTSPStatusCode error_number) break; } - url_fprintf(c->pb, "RTSP/1.0 %d %s\r\n", error_number, str); - url_fprintf(c->pb, "CSeq: %d\r\n", c->seq); + avio_printf(c->pb, "RTSP/1.0 %d %s\r\n", error_number, str); + avio_printf(c->pb, "CSeq: %d\r\n", c->seq); /* output GMT time */ ti = time(NULL); tm = gmtime(&ti); strftime(buf2, sizeof(buf2), "%a, %d %b %Y %H:%M:%S", tm); - url_fprintf(c->pb, "Date: %s GMT\r\n", buf2); + avio_printf(c->pb, "Date: %s GMT\r\n", buf2); } static void rtsp_reply_error(HTTPContext *c, enum RTSPStatusCode error_number) { rtsp_reply_header(c, error_number); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "\r\n"); } static int rtsp_parse_request(HTTPContext *c) @@ -2851,7 +2852,7 @@ static int rtsp_parse_request(HTTPContext *c) av_strlcpy(c->url, url, sizeof(c->url)); av_strlcpy(c->protocol, protocol, sizeof(c->protocol)); - if (url_open_dyn_buf(&c->pb) < 0) { + if (avio_open_dyn_buf(&c->pb) < 0) { /* XXX: cannot do more */ c->pb = NULL; /* safety */ return -1; @@ -2908,7 +2909,7 @@ static int rtsp_parse_request(HTTPContext *c) rtsp_reply_error(c, RTSP_STATUS_METHOD); the_end: - len = url_close_dyn_buf(c->pb, &c->pb_buffer); + len = avio_close_dyn_buf(c->pb, &c->pb_buffer); c->pb = NULL; /* safety */ if (len < 0) { /* XXX: cannot do more */ @@ -2972,10 +2973,10 @@ static int prepare_sdp_description(FFStream *stream, uint8_t **pbuffer, static void rtsp_cmd_options(HTTPContext *c, const char *url) { // rtsp_reply_header(c, RTSP_STATUS_OK); - url_fprintf(c->pb, "RTSP/1.0 %d %s\r\n", RTSP_STATUS_OK, "OK"); - url_fprintf(c->pb, "CSeq: %d\r\n", c->seq); - url_fprintf(c->pb, "Public: %s\r\n", "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE"); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "RTSP/1.0 %d %s\r\n", RTSP_STATUS_OK, "OK"); + avio_printf(c->pb, "CSeq: %d\r\n", c->seq); + avio_printf(c->pb, "Public: %s\r\n", "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE"); + avio_printf(c->pb, "\r\n"); } static void rtsp_cmd_describe(HTTPContext *c, const char *url) @@ -3016,11 +3017,11 @@ static void rtsp_cmd_describe(HTTPContext *c, const char *url) return; } rtsp_reply_header(c, RTSP_STATUS_OK); - url_fprintf(c->pb, "Content-Base: %s/\r\n", url); - url_fprintf(c->pb, "Content-Type: application/sdp\r\n"); - url_fprintf(c->pb, "Content-Length: %d\r\n", content_length); - url_fprintf(c->pb, "\r\n"); - put_buffer(c->pb, content, content_length); + avio_printf(c->pb, "Content-Base: %s/\r\n", url); + avio_printf(c->pb, "Content-Type: application/sdp\r\n"); + avio_printf(c->pb, "Content-Length: %d\r\n", content_length); + avio_printf(c->pb, "\r\n"); + avio_write(c->pb, content, content_length); av_free(content); } @@ -3165,30 +3166,30 @@ static void rtsp_cmd_setup(HTTPContext *c, const char *url, /* now everything is OK, so we can send the connection parameters */ rtsp_reply_header(c, RTSP_STATUS_OK); /* session ID */ - url_fprintf(c->pb, "Session: %s\r\n", rtp_c->session_id); + avio_printf(c->pb, "Session: %s\r\n", rtp_c->session_id); switch(rtp_c->rtp_protocol) { case RTSP_LOWER_TRANSPORT_UDP: rtp_port = rtp_get_local_rtp_port(rtp_c->rtp_handles[stream_index]); rtcp_port = rtp_get_local_rtcp_port(rtp_c->rtp_handles[stream_index]); - url_fprintf(c->pb, "Transport: RTP/AVP/UDP;unicast;" + avio_printf(c->pb, "Transport: RTP/AVP/UDP;unicast;" "client_port=%d-%d;server_port=%d-%d", th->client_port_min, th->client_port_max, rtp_port, rtcp_port); break; case RTSP_LOWER_TRANSPORT_TCP: - url_fprintf(c->pb, "Transport: RTP/AVP/TCP;interleaved=%d-%d", + avio_printf(c->pb, "Transport: RTP/AVP/TCP;interleaved=%d-%d", stream_index * 2, stream_index * 2 + 1); break; default: break; } if (setup.transport_option[0] != '\0') - url_fprintf(c->pb, ";%s", setup.transport_option); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, ";%s", setup.transport_option); + avio_printf(c->pb, "\r\n"); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "\r\n"); } @@ -3201,7 +3202,7 @@ static HTTPContext *find_rtp_session_with_url(const char *url, char path1[1024]; const char *path; char buf[1024]; - int s; + int s, len; rtp_c = find_rtp_session(session_id); if (!rtp_c) @@ -3221,6 +3222,10 @@ static HTTPContext *find_rtp_session_with_url(const char *url, return rtp_c; } } + len = strlen(path); + if (len > 0 && path[len - 1] == '/' && + !strncmp(path, rtp_c->stream->filename, len - 1)) + return rtp_c; return NULL; } @@ -3246,8 +3251,8 @@ static void rtsp_cmd_play(HTTPContext *c, const char *url, RTSPMessageHeader *h) /* now everything is OK, so we can send the connection parameters */ rtsp_reply_header(c, RTSP_STATUS_OK); /* session ID */ - url_fprintf(c->pb, "Session: %s\r\n", rtp_c->session_id); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "Session: %s\r\n", rtp_c->session_id); + avio_printf(c->pb, "\r\n"); } static void rtsp_cmd_pause(HTTPContext *c, const char *url, RTSPMessageHeader *h) @@ -3271,8 +3276,8 @@ static void rtsp_cmd_pause(HTTPContext *c, const char *url, RTSPMessageHeader *h /* now everything is OK, so we can send the connection parameters */ rtsp_reply_header(c, RTSP_STATUS_OK); /* session ID */ - url_fprintf(c->pb, "Session: %s\r\n", rtp_c->session_id); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "Session: %s\r\n", rtp_c->session_id); + avio_printf(c->pb, "\r\n"); } static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPMessageHeader *h) @@ -3294,8 +3299,8 @@ static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPMessageHeader /* now everything is OK, so we can send the connection parameters */ rtsp_reply_header(c, RTSP_STATUS_OK); /* session ID */ - url_fprintf(c->pb, "Session: %s\r\n", session_id); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "Session: %s\r\n", session_id); + avio_printf(c->pb, "\r\n"); } @@ -3441,7 +3446,7 @@ static int rtp_new_av_stream(HTTPContext *c, 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) { + if (ffio_open_dyn_packet_buf(&ctx->pb, max_packet_size) < 0) { /* XXX: close stream */ goto fail; } @@ -3453,7 +3458,7 @@ static int rtp_new_av_stream(HTTPContext *c, av_free(ctx); return -1; } - url_close_dyn_buf(ctx->pb, &dummy_buf); + avio_close_dyn_buf(ctx->pb, &dummy_buf); av_free(dummy_buf); c->rtp_ctx[stream_index] = ctx; @@ -3487,7 +3492,7 @@ static AVStream *add_av_stream1(FFStream *stream, AVCodecContext *codec, int cop fst->priv_data = av_mallocz(sizeof(FeedData)); fst->index = stream->nb_streams; av_set_pts_info(fst, 33, 1, 90000); - fst->sample_aspect_ratio = (AVRational){0,1}; + fst->sample_aspect_ratio = codec->sample_aspect_ratio; stream->streams[stream->nb_streams++] = fst; return fst; } @@ -3762,7 +3767,7 @@ static void build_feed_streams(void) } /* only write the header of the ffm file */ - if (url_fopen(&s->pb, feed->feed_filename, URL_WRONLY) < 0) { + if (avio_open(&s->pb, feed->feed_filename, URL_WRONLY) < 0) { http_log("Could not open output feed file '%s'\n", feed->feed_filename); exit(1); @@ -3781,7 +3786,7 @@ static void build_feed_streams(void) } /* XXX: need better api */ av_freep(&s->priv_data); - url_fclose(s->pb); + avio_close(s->pb); } /* get feed size and write index */ fd = open(feed->feed_filename, O_RDONLY);