ffserver: unify comment formating & drop unneeded braces

Signed-off-by: 's avatarReynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>
parent 1714fe29
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "libavformat/avformat.h" #include "libavformat/avformat.h"
// FIXME those are internal headers, ffserver _really_ shouldn't use them /* FIXME: those are internal headers, ffserver _really_ shouldn't use them */
#include "libavformat/ffm.h" #include "libavformat/ffm.h"
#include "libavformat/network.h" #include "libavformat/network.h"
#include "libavformat/os_support.h" #include "libavformat/os_support.h"
...@@ -251,7 +251,8 @@ static unsigned int nb_connections; ...@@ -251,7 +251,8 @@ static unsigned int nb_connections;
static uint64_t current_bandwidth; static uint64_t current_bandwidth;
static int64_t cur_time; // Making this global saves on passing it around everywhere /* Making this global saves on passing it around everywhere */
static int64_t cur_time;
static AVLFG random_state; static AVLFG random_state;
...@@ -630,9 +631,8 @@ static int http_server(void) ...@@ -630,9 +631,8 @@ static int http_server(void)
poll_entry++; poll_entry++;
} else { } else {
/* when ffserver is doing the timing, we work by /* when ffserver is doing the timing, we work by
looking at which packet needs to be sent every * looking at which packet needs to be sent every
10 ms */ * 10 ms (one tick wait XXX: 10 ms assumed) */
/* one tick wait XXX: 10 ms assumed */
if (delay > 10) if (delay > 10)
delay = 10; delay = 10;
} }
...@@ -655,7 +655,7 @@ static int http_server(void) ...@@ -655,7 +655,7 @@ static int http_server(void)
} }
/* wait for an event on one connection. We poll at least every /* wait for an event on one connection. We poll at least every
second to handle timeouts */ * second to handle timeouts */
do { do {
ret = poll(poll_table, poll_entry - poll_table, delay); ret = poll(poll_table, poll_entry - poll_table, delay);
if (ret < 0 && ff_neterrno() != AVERROR(EAGAIN) && if (ret < 0 && ff_neterrno() != AVERROR(EAGAIN) &&
...@@ -900,11 +900,11 @@ static int handle_connection(HTTPContext *c) ...@@ -900,11 +900,11 @@ static int handle_connection(HTTPContext *c)
if ((ptr >= c->buffer + 2 && !memcmp(ptr-2, "\n\n", 2)) || if ((ptr >= c->buffer + 2 && !memcmp(ptr-2, "\n\n", 2)) ||
(ptr >= c->buffer + 4 && !memcmp(ptr-4, "\r\n\r\n", 4))) { (ptr >= c->buffer + 4 && !memcmp(ptr-4, "\r\n\r\n", 4))) {
/* request found : parse it and reply */ /* request found : parse it and reply */
if (c->state == HTTPSTATE_WAIT_REQUEST) { if (c->state == HTTPSTATE_WAIT_REQUEST)
ret = http_parse_request(c); ret = http_parse_request(c);
} else { else
ret = rtsp_parse_request(c); ret = rtsp_parse_request(c);
}
if (ret < 0) if (ret < 0)
return -1; return -1;
} else if (ptr >= c->buffer_end) { } else if (ptr >= c->buffer_end) {
...@@ -949,8 +949,8 @@ static int handle_connection(HTTPContext *c) ...@@ -949,8 +949,8 @@ static int handle_connection(HTTPContext *c)
case HTTPSTATE_SEND_DATA_HEADER: case HTTPSTATE_SEND_DATA_HEADER:
case HTTPSTATE_SEND_DATA_TRAILER: case HTTPSTATE_SEND_DATA_TRAILER:
/* for packetized output, we consider we can always write (the /* for packetized output, we consider we can always write (the
input streams set the speed). It may be better to verify * input streams set the speed). It may be better to verify
that we do not rely too much on the kernel queues */ * that we do not rely too much on the kernel queues */
if (!c->is_packetized) { if (!c->is_packetized) {
if (c->poll_entry->revents & (POLLERR | POLLHUP)) if (c->poll_entry->revents & (POLLERR | POLLHUP))
return -1; return -1;
...@@ -1277,8 +1277,10 @@ static int validate_acl(FFServerStream *stream, HTTPContext *c) ...@@ -1277,8 +1277,10 @@ static int validate_acl(FFServerStream *stream, HTTPContext *c)
return ret; return ret;
} }
/* compute the real filename of a file by matching it without its /**
extensions to all the stream's filenames */ * compute the real filename of a file by matching it without its
* extensions to all the stream's filenames
*/
static void compute_real_filename(char *filename, int max_size) static void compute_real_filename(char *filename, int max_size)
{ {
char file1[1024]; char file1[1024];
...@@ -1396,7 +1398,7 @@ static int http_parse_request(HTTPContext *c) ...@@ -1396,7 +1398,7 @@ static int http_parse_request(HTTPContext *c)
compute_real_filename(filename, sizeof(filename) - 1); compute_real_filename(filename, sizeof(filename) - 1);
} }
// "redirect" / request to index.html /* "redirect" request to index.html */
if (!strlen(filename)) if (!strlen(filename))
av_strlcpy(filename, "index.html", sizeof(filename) - 1); av_strlcpy(filename, "index.html", sizeof(filename) - 1);
...@@ -1735,8 +1737,9 @@ static int http_parse_request(HTTPContext *c) ...@@ -1735,8 +1737,9 @@ static int http_parse_request(HTTPContext *c)
return 0; return 0;
send_status: send_status:
compute_status(c); compute_status(c);
c->http_error = 200; /* horrible : we use this value to avoid /* horrible: we use this value to avoid
going to the send data state */ * going to the send data state */
c->http_error = 200;
c->state = HTTPSTATE_SEND_HEADER; c->state = HTTPSTATE_SEND_HEADER;
return 0; return 0;
} }
...@@ -1847,8 +1850,8 @@ static void compute_status(HTTPContext *c) ...@@ -1847,8 +1850,8 @@ static void compute_status(HTTPContext *c)
strcpy(eosf - 3, ".ram"); strcpy(eosf - 3, ".ram");
else if (stream->fmt && !strcmp(stream->fmt->name, "rtp")) { else if (stream->fmt && !strcmp(stream->fmt->name, "rtp")) {
/* generate a sample RTSP director if /* generate a sample RTSP director if
unicast. Generate an SDP redirector if * unicast. Generate an SDP redirector if
multicast */ * multicast */
eosf = strrchr(sfilename, '.'); eosf = strrchr(sfilename, '.');
if (!eosf) if (!eosf)
eosf = sfilename + strlen(sfilename); eosf = sfilename + strlen(sfilename);
...@@ -2119,8 +2122,7 @@ static int64_t get_server_clock(HTTPContext *c) ...@@ -2119,8 +2122,7 @@ static int64_t get_server_clock(HTTPContext *c)
return (cur_time - c->start_time) * 1000; return (cur_time - c->start_time) * 1000;
} }
/* return the estimated time at which the current packet must be sent /* return the estimated time (in us) at which the current packet must be sent */
(in us) */
static int64_t get_packet_send_clock(HTTPContext *c) static int64_t get_packet_send_clock(HTTPContext *c)
{ {
int bytes_left, bytes_sent, frame_bytes; int bytes_left, bytes_sent, frame_bytes;
...@@ -2158,7 +2160,8 @@ static int http_prepare_data(HTTPContext *c) ...@@ -2158,7 +2160,8 @@ static int http_prepare_data(HTTPContext *c)
AVStream *src; AVStream *src;
c->fmt_ctx.streams[i] = av_mallocz(sizeof(AVStream)); c->fmt_ctx.streams[i] = av_mallocz(sizeof(AVStream));
/* if file or feed, then just take streams from FFServerStream struct */ /* if file or feed, then just take streams from FFServerStream
* struct */
if (!c->stream->feed || if (!c->stream->feed ||
c->stream->feed == c->stream) c->stream->feed == c->stream)
src = c->stream->streams[i]; src = c->stream->streams[i];
...@@ -2223,7 +2226,7 @@ static int http_prepare_data(HTTPContext *c) ...@@ -2223,7 +2226,7 @@ static int http_prepare_data(HTTPContext *c)
if (ret < 0) { if (ret < 0) {
if (c->stream->feed) { if (c->stream->feed) {
/* if coming from feed, it means we reached the end of the /* if coming from feed, it means we reached the end of the
ffm file, so must wait for more data */ * ffm file, so must wait for more data */
c->state = HTTPSTATE_WAIT_FEED; c->state = HTTPSTATE_WAIT_FEED;
return 1; /* state changed */ return 1; /* state changed */
} }
...@@ -2310,9 +2313,9 @@ static int http_prepare_data(HTTPContext *c) ...@@ -2310,9 +2313,9 @@ static int http_prepare_data(HTTPContext *c)
max_packet_size = c->rtp_handles[c->packet_stream_index]->max_packet_size; max_packet_size = c->rtp_handles[c->packet_stream_index]->max_packet_size;
ret = ffio_open_dyn_packet_buf(&ctx->pb, ret = ffio_open_dyn_packet_buf(&ctx->pb,
max_packet_size); max_packet_size);
} else { } else
ret = avio_open_dyn_buf(&ctx->pb); ret = avio_open_dyn_buf(&ctx->pb);
}
if (ret < 0) { if (ret < 0) {
/* XXX: potential leak */ /* XXX: potential leak */
return -1; return -1;
...@@ -2375,7 +2378,8 @@ static int http_prepare_data(HTTPContext *c) ...@@ -2375,7 +2378,8 @@ static int http_prepare_data(HTTPContext *c)
/* should convert the format at the same time */ /* should convert the format at the same time */
/* send data starting at c->buffer_ptr to the output connection /* send data starting at c->buffer_ptr to the output connection
* (either UDP or TCP) */ * (either UDP or TCP)
*/
static int http_send_data(HTTPContext *c) static int http_send_data(HTTPContext *c)
{ {
int len, ret; int len, ret;
...@@ -2456,8 +2460,8 @@ static int http_send_data(HTTPContext *c) ...@@ -2456,8 +2460,8 @@ static int http_send_data(HTTPContext *c)
rtsp_c->packet_buffer_ptr += len; rtsp_c->packet_buffer_ptr += len;
if (rtsp_c->packet_buffer_ptr < rtsp_c->packet_buffer_end) { if (rtsp_c->packet_buffer_ptr < rtsp_c->packet_buffer_end) {
/* if we could not send all the data, we will /* if we could not send all the data, we will
send it later, so a new state is needed to * send it later, so a new state is needed to
"lock" the RTSP TCP connection */ * "lock" the RTSP TCP connection */
rtsp_c->state = RTSPSTATE_SEND_PACKET; rtsp_c->state = RTSPSTATE_SEND_PACKET;
break; break;
} else } else
...@@ -2585,13 +2589,12 @@ static int http_receive_data(HTTPContext *c) ...@@ -2585,13 +2589,12 @@ static int http_receive_data(HTTPContext *c)
goto fail; goto fail;
c->buffer_ptr = c->buffer; c->buffer_ptr = c->buffer;
break; break;
} else if (++loop_run > 10) { } else if (++loop_run > 10)
/* no chunk header, abort */ /* no chunk header, abort */
goto fail; goto fail;
} else { else
c->buffer_ptr++; c->buffer_ptr++;
} }
}
if (c->buffer_end > c->buffer_ptr) { if (c->buffer_end > c->buffer_ptr) {
len = recv(c->fd, c->buffer_ptr, len = recv(c->fd, c->buffer_ptr,
...@@ -2623,7 +2626,7 @@ static int http_receive_data(HTTPContext *c) ...@@ -2623,7 +2626,7 @@ static int http_receive_data(HTTPContext *c)
if (c->buffer_ptr >= c->buffer_end) { if (c->buffer_ptr >= c->buffer_end) {
FFServerStream *feed = c->stream; FFServerStream *feed = c->stream;
/* a packet has been received : write it in the store, except /* a packet has been received : write it in the store, except
if header */ * if header */
if (c->data_count > FFM_PACKET_SIZE) { if (c->data_count > FFM_PACKET_SIZE) {
/* XXX: use llseek or url_seek /* XXX: use llseek or url_seek
* XXX: Should probably fail? */ * XXX: Should probably fail? */
...@@ -2829,10 +2832,10 @@ static int rtsp_parse_request(HTTPContext *c) ...@@ -2829,10 +2832,10 @@ static int rtsp_parse_request(HTTPContext *c)
the_end: the_end:
len = avio_close_dyn_buf(c->pb, &c->pb_buffer); len = avio_close_dyn_buf(c->pb, &c->pb_buffer);
c->pb = NULL; /* safety */ c->pb = NULL; /* safety */
if (len < 0) { if (len < 0)
/* XXX: cannot do more */ /* XXX: cannot do more */
return -1; return -1;
}
c->buffer_ptr = c->pb_buffer; c->buffer_ptr = c->pb_buffer;
c->buffer_end = c->pb_buffer + len; c->buffer_end = c->pb_buffer + len;
c->state = RTSPSTATE_SEND_REPLY; c->state = RTSPSTATE_SEND_REPLY;
...@@ -2851,9 +2854,9 @@ static int prepare_sdp_description(FFServerStream *stream, uint8_t **pbuffer, ...@@ -2851,9 +2854,9 @@ static int prepare_sdp_description(FFServerStream *stream, uint8_t **pbuffer,
*pbuffer = NULL; *pbuffer = NULL;
avc = avformat_alloc_context(); avc = avformat_alloc_context();
if (!avc || !rtp_format) { if (!avc || !rtp_format)
return -1; return -1;
}
avc->oformat = rtp_format; avc->oformat = rtp_format;
av_dict_set(&avc->metadata, "title", av_dict_set(&avc->metadata, "title",
entry ? entry->value : "No Title", 0); entry ? entry->value : "No Title", 0);
...@@ -2862,9 +2865,8 @@ static int prepare_sdp_description(FFServerStream *stream, uint8_t **pbuffer, ...@@ -2862,9 +2865,8 @@ static int prepare_sdp_description(FFServerStream *stream, uint8_t **pbuffer,
snprintf(avc->filename, 1024, "rtp://%s:%d?multicast=1?ttl=%d", snprintf(avc->filename, 1024, "rtp://%s:%d?multicast=1?ttl=%d",
inet_ntoa(stream->multicast_ip), inet_ntoa(stream->multicast_ip),
stream->multicast_port, stream->multicast_ttl); stream->multicast_port, stream->multicast_ttl);
} else { } else
snprintf(avc->filename, 1024, "rtp://0.0.0.0"); snprintf(avc->filename, 1024, "rtp://0.0.0.0");
}
avc->streams = av_malloc_array(avc->nb_streams, sizeof(*avc->streams)); avc->streams = av_malloc_array(avc->nb_streams, sizeof(*avc->streams));
if (!avc->streams) if (!avc->streams)
...@@ -2894,7 +2896,7 @@ static int prepare_sdp_description(FFServerStream *stream, uint8_t **pbuffer, ...@@ -2894,7 +2896,7 @@ static int prepare_sdp_description(FFServerStream *stream, uint8_t **pbuffer,
static void rtsp_cmd_options(HTTPContext *c, const char *url) static void rtsp_cmd_options(HTTPContext *c, const char *url)
{ {
// rtsp_reply_header(c, RTSP_STATUS_OK); /* rtsp_reply_header(c, RTSP_STATUS_OK); */
avio_printf(c->pb, "RTSP/1.0 %d %s\r\n", RTSP_STATUS_OK, "OK"); 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, "CSeq: %d\r\n", c->seq);
avio_printf(c->pb, "Public: %s\r\n", avio_printf(c->pb, "Public: %s\r\n",
...@@ -3061,7 +3063,7 @@ static void rtsp_cmd_setup(HTTPContext *c, const char *url, ...@@ -3061,7 +3063,7 @@ static void rtsp_cmd_setup(HTTPContext *c, const char *url,
} }
/* test if stream is OK (test needed because several SETUP needs /* test if stream is OK (test needed because several SETUP needs
to be done for a given file) */ * to be done for a given file) */
if (rtp_c->stream != stream) { if (rtp_c->stream != stream) {
rtsp_reply_error(c, RTSP_STATUS_SERVICE); rtsp_reply_error(c, RTSP_STATUS_SERVICE);
return; return;
...@@ -3122,8 +3124,10 @@ static void rtsp_cmd_setup(HTTPContext *c, const char *url, ...@@ -3122,8 +3124,10 @@ static void rtsp_cmd_setup(HTTPContext *c, const char *url,
} }
/* find an RTP connection by using the session ID. Check consistency /**
with filename */ * find an RTP connection by using the session ID. Check consistency
* with filename
*/
static HTTPContext *find_rtp_session_with_url(const char *url, static HTTPContext *find_rtp_session_with_url(const char *url,
const char *session_id) const char *session_id)
{ {
...@@ -3146,11 +3150,11 @@ static HTTPContext *find_rtp_session_with_url(const char *url, ...@@ -3146,11 +3150,11 @@ static HTTPContext *find_rtp_session_with_url(const char *url,
for(s=0; s<rtp_c->stream->nb_streams; ++s) { for(s=0; s<rtp_c->stream->nb_streams; ++s) {
snprintf(buf, sizeof(buf), "%s/streamid=%d", snprintf(buf, sizeof(buf), "%s/streamid=%d",
rtp_c->stream->filename, s); rtp_c->stream->filename, s);
if(!strncmp(path, buf, sizeof(buf))) { if(!strncmp(path, buf, sizeof(buf)))
// XXX: Should we reply with RTSP_STATUS_ONLY_AGGREGATE if nb_streams>1? /* XXX: Should we reply with RTSP_STATUS_ONLY_AGGREGATE
* if nb_streams>1? */
return rtp_c; return rtp_c;
} }
}
len = strlen(path); len = strlen(path);
if (len > 0 && path[len - 1] == '/' && if (len > 0 && path[len - 1] == '/' &&
!strncmp(path, rtp_c->stream->filename, len - 1)) !strncmp(path, rtp_c->stream->filename, len - 1))
...@@ -3227,7 +3231,7 @@ static HTTPContext *rtp_new_connection(struct sockaddr_in *from_addr, ...@@ -3227,7 +3231,7 @@ static HTTPContext *rtp_new_connection(struct sockaddr_in *from_addr,
const char *proto_str; const char *proto_str;
/* XXX: should output a warning page when coming /* XXX: should output a warning page when coming
close to the connection limit */ * close to the connection limit */
if (nb_connections >= config.nb_max_connections) if (nb_connections >= config.nb_max_connections)
goto fail; goto fail;
...@@ -3282,9 +3286,11 @@ static HTTPContext *rtp_new_connection(struct sockaddr_in *from_addr, ...@@ -3282,9 +3286,11 @@ static HTTPContext *rtp_new_connection(struct sockaddr_in *from_addr,
return NULL; return NULL;
} }
/* add a new RTP stream in an RTP connection (used in RTSP SETUP /**
command). If RTP/TCP protocol is used, TCP connection 'rtsp_c' is * add a new RTP stream in an RTP connection (used in RTSP SETUP
used. */ * command). If RTP/TCP protocol is used, TCP connection 'rtsp_c' is
* used.
*/
static int rtp_new_av_stream(HTTPContext *c, static int rtp_new_av_stream(HTTPContext *c,
int stream_index, struct sockaddr_in *dest_addr, int stream_index, struct sockaddr_in *dest_addr,
HTTPContext *rtsp_c) HTTPContext *rtsp_c)
...@@ -3362,10 +3368,10 @@ static int rtp_new_av_stream(HTTPContext *c, ...@@ -3362,10 +3368,10 @@ static int rtp_new_av_stream(HTTPContext *c,
/* normally, no packets should be output here, but the packet size may /* normally, no packets should be output here, but the packet size may
* be checked */ * be checked */
if (ffio_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 */ /* XXX: close stream */
goto fail; goto fail;
}
if (avformat_write_header(ctx, NULL) < 0) { if (avformat_write_header(ctx, NULL) < 0) {
fail: fail:
if (h) if (h)
...@@ -3402,12 +3408,12 @@ static AVStream *add_av_stream1(FFServerStream *stream, ...@@ -3402,12 +3408,12 @@ static AVStream *add_av_stream1(FFServerStream *stream,
return NULL; return NULL;
} }
avcodec_copy_context(fst->codec, codec); avcodec_copy_context(fst->codec, codec);
} else { } else
/* live streams must use the actual feed's codec since it may be /* live streams must use the actual feed's codec since it may be
* updated later to carry extradata needed by them. * updated later to carry extradata needed by them.
*/ */
fst->codec = codec; fst->codec = codec;
}
fst->priv_data = av_mallocz(sizeof(FeedData)); fst->priv_data = av_mallocz(sizeof(FeedData));
fst->index = stream->nb_streams; fst->index = stream->nb_streams;
avpriv_set_pts_info(fst, 33, 1, 90000); avpriv_set_pts_info(fst, 33, 1, 90000);
...@@ -3539,7 +3545,7 @@ static void build_file_streams(void) ...@@ -3539,7 +3545,7 @@ static void build_file_streams(void)
/* open stream */ /* open stream */
if (stream->fmt && !strcmp(stream->fmt->name, "rtp")) { if (stream->fmt && !strcmp(stream->fmt->name, "rtp")) {
/* specific case : if transport stream output to RTP, /* specific case : if transport stream output to RTP,
we use a raw transport stream reader */ * we use a raw transport stream reader */
av_dict_set(&stream->in_opts, "mpeg2ts_compute_pcr", "1", 0); av_dict_set(&stream->in_opts, "mpeg2ts_compute_pcr", "1", 0);
} }
...@@ -3561,7 +3567,7 @@ static void build_file_streams(void) ...@@ -3561,7 +3567,7 @@ static void build_file_streams(void)
remove_stream(stream); remove_stream(stream);
} else { } else {
/* find all the AVStreams inside and reference them in /* find all the AVStreams inside and reference them in
'stream' */ * 'stream' */
if (avformat_find_stream_info(infile, NULL) < 0) { if (avformat_find_stream_info(infile, NULL) < 0) {
http_log("Could not find codec parameters from '%s'\n", http_log("Could not find codec parameters from '%s'\n",
stream->feed_filename); stream->feed_filename);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment