diff options
author | Philip Gladstone <philipjsg@users.sourceforge.net> | 2002-05-24 01:18:19 +0000 |
---|---|---|
committer | Philip Gladstone <philipjsg@users.sourceforge.net> | 2002-05-24 01:18:19 +0000 |
commit | ec3b22326dc07fb8300a577bd6b17c19a0f1bcf7 (patch) | |
tree | af2d5bcfc39507491c6cd3d528e680fe97da75fa /ffserver.c | |
parent | 935cdf090219949afe1465b3d6c5b8e8643df1a6 (diff) | |
download | ffmpeg-ec3b22326dc07fb8300a577bd6b17c19a0f1bcf7.tar.gz |
* Add support for time-limiting a live stream. (Some guy streamed one of
my pondcam streams for 24 hours! I'll bet he wasn't watching.
* Add code to allocate the priv_data so that the ffm header can be
parsed again. [Fix crash]
Originally committed as revision 577 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'ffserver.c')
-rw-r--r-- | ffserver.c | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/ffserver.c b/ffserver.c index e0e1ca7e79..767da5f3a0 100644 --- a/ffserver.c +++ b/ffserver.c @@ -95,6 +95,7 @@ typedef struct HTTPContext { int last_packet_sent; /* true if last data packet was sent */ int suppress_log; int bandwidth; + time_t start_time; char protocol[16]; char method[16]; char url[128]; @@ -116,6 +117,7 @@ typedef struct FFStream { AVOutputFormat *fmt; int nb_streams; int prebuffer; /* Number of millseconds early to start */ + time_t max_time; int send_on_key; AVStream *streams[MAX_STREAMS]; int feed_streams[MAX_STREAMS]; /* index of streams in the feed */ @@ -559,7 +561,7 @@ static int http_parse_request(HTTPContext *c) c->bandwidth += st->codec.bit_rate; break; default: - abort(); + av_abort(); } } } @@ -636,7 +638,7 @@ static int http_parse_request(HTTPContext *c) q += sprintf(q, "http://%s/%s%s\r\n", hostbuf, filename, info); } else - abort(); + av_abort(); /* prepare output buffer */ c->buffer_ptr = c->buffer; @@ -829,7 +831,7 @@ static void compute_stats(HTTPContext *c) } break; default: - abort(); + av_abort(); } } q += sprintf(q, "<TD align=center> %s <TD align=right> %d <TD align=right> %d <TD> %s %s <TD align=right> %d <TD> %s %s", @@ -873,7 +875,7 @@ static void compute_stats(HTTPContext *c) type = "video"; break; default: - abort(); + av_abort(); } q += sprintf(q, "<tr><td align=right>%d<td>%s<td align=right>%d<td>%s\n", i, type, st->codec.bit_rate/1000, codec ? codec->name : ""); @@ -960,7 +962,7 @@ static void http_write_packet(void *opaque, c->buffer_ptr = c->buffer_end = c->buffer; if (c->buffer_end - c->buffer + size > IOBUFFER_MAX_SIZE) - abort(); + av_abort(); memcpy(c->buffer_end, buf, size); c->buffer_end += size; @@ -1127,8 +1129,12 @@ static int http_prepare_data(HTTPContext *c) c->stream->feed->feed_write_index, c->stream->feed->feed_size); } - - if (av_read_packet(c->fmt_in, &pkt) < 0) { + + if (c->stream->max_time && + c->stream->max_time + c->start_time > time(0)) { + /* We have timed out */ + c->state = HTTPSTATE_SEND_DATA_TRAILER; + } else if (av_read_packet(c->fmt_in, &pkt) < 0) { if (c->stream->feed && c->stream->feed->feed_opened) { /* if coming from feed, it means we reached the end of the ffm file, so must wait for more data */ @@ -1326,18 +1332,25 @@ static int http_receive_data(HTTPContext *c) if (!fmt_in) goto fail; + s.priv_data = av_mallocz(fmt_in->priv_data_size); + if (!s.priv_data) + goto fail; + if (fmt_in->read_header(&s, 0) < 0) { + av_freep(&s.priv_data); goto fail; } /* Now we have the actual streams */ if (s.nb_streams != feed->nb_streams) { + av_freep(&s.priv_data); goto fail; } for (i = 0; i < s.nb_streams; i++) { memcpy(&feed->streams[i]->codec, &s.streams[i]->codec, sizeof(AVCodecContext)); } + av_freep(&s.priv_data); } c->buffer_ptr = c->buffer; } @@ -1379,7 +1392,7 @@ int add_av_stream(FFStream *feed, goto found; break; default: - abort(); + av_abort(); } } } @@ -1530,7 +1543,7 @@ void add_codec(FFStream *stream, AVCodecContext *av) break; default: - abort(); + av_abort(); } st = av_mallocz(sizeof(AVStream)); @@ -1807,6 +1820,11 @@ int parse_ffconfig(const char *filename) filename, line_num, arg); errors++; } + } else if (!strcasecmp(cmd, "MaxTime")) { + get_arg(arg, sizeof(arg), &p); + if (stream) { + stream->max_time = atoi(arg); + } } else if (!strcasecmp(cmd, "AudioBitRate")) { get_arg(arg, sizeof(arg), &p); if (stream) { |