stream->conns_served);
fmt_bytecount(pb, stream->bytes_served);
switch(stream->stream_type) {
- case STREAM_TYPE_LIVE:
- {
+ case STREAM_TYPE_LIVE: {
int audio_bit_rate = 0;
int video_bit_rate = 0;
const char *audio_codec_name = "";
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))
- {
+ 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)) {
+ } else if (find_info_tag(buf, sizeof(buf), "buffer", info)) {
int prebuffer = strtol(buf, 0, 10);
stream_pos = av_gettime() - prebuffer * (int64_t)1000000;
} else
strcpy(input_filename, c->stream->feed_filename);
buf_size = 0;
/* compute position (relative time) */
- if (find_info_tag(buf, sizeof(buf), "date", info))
- {
+ if (find_info_tag(buf, sizeof(buf), "date", info)) {
stream_pos = parse_date(buf, 1);
if (stream_pos == INT64_MIN)
return -1;
- }
- else
+ } else
stream_pos = 0;
}
if (input_filename[0] == '\0')
av_strlcpy(c->fmt_ctx.title, c->stream->title,
sizeof(c->fmt_ctx.title));
- /* open output stream by using specified codecs */
- c->fmt_ctx.oformat = c->stream->fmt;
- c->fmt_ctx.nb_streams = c->stream->nb_streams;
- for(i=0;i<c->fmt_ctx.nb_streams;i++) {
+ for(i=0;i<c->stream->nb_streams;i++) {
AVStream *st;
AVStream *src;
st = av_mallocz(sizeof(AVStream));
st->codec->frame_number = 0; /* XXX: should be done in
AVStream, not in codec */
}
+ /* set output format parameters */
+ c->fmt_ctx.oformat = c->stream->fmt;
+ c->fmt_ctx.nb_streams = c->stream->nb_streams;
+
c->got_key_frame = 0;
/* prepare header and save header data in a stream */
}
} else {
AVCodecContext *codec;
-
+ AVStream *ist, *ost;
send_it:
+ ist = c->fmt_in->streams[source_index];
/* specific handling for RTP: we use several
output stream (one for each RTP
connection). XXX: need more abstract handling */
if (c->is_packetized) {
- AVStream *st;
/* compute send time and duration */
- st = c->fmt_in->streams[pkt.stream_index];
- c->cur_pts = av_rescale_q(pkt.dts, st->time_base, AV_TIME_BASE_Q);
- if (st->start_time != AV_NOPTS_VALUE)
- c->cur_pts -= av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q);
- c->cur_frame_duration = av_rescale_q(pkt.duration, st->time_base, AV_TIME_BASE_Q);
+ c->cur_pts = av_rescale_q(pkt.dts, ist->time_base, AV_TIME_BASE_Q);
+ if (ist->start_time != AV_NOPTS_VALUE)
+ c->cur_pts -= av_rescale_q(ist->start_time, ist->time_base, AV_TIME_BASE_Q);
+ c->cur_frame_duration = av_rescale_q(pkt.duration, ist->time_base, AV_TIME_BASE_Q);
#if 0
printf("index=%d pts=%0.3f duration=%0.6f\n",
pkt.stream_index,
/* XXX: potential leak */
return -1;
}
- c->fmt_ctx.pb->is_streamed = 1;
+ ost = ctx->streams[pkt.stream_index];
+
+ ctx->pb->is_streamed = 1;
if (pkt.dts != AV_NOPTS_VALUE)
- pkt.dts = av_rescale_q(pkt.dts,
- c->fmt_in->streams[source_index]->time_base,
- ctx->streams[pkt.stream_index]->time_base);
+ pkt.dts = av_rescale_q(pkt.dts, ist->time_base, ost->time_base);
if (pkt.pts != AV_NOPTS_VALUE)
- pkt.pts = av_rescale_q(pkt.pts,
- c->fmt_in->streams[source_index]->time_base,
- ctx->streams[pkt.stream_index]->time_base);
- pkt.duration = av_rescale_q(pkt.duration,
- c->fmt_in->streams[source_index]->time_base,
- ctx->streams[pkt.stream_index]->time_base);
+ pkt.pts = av_rescale_q(pkt.pts, ist->time_base, ost->time_base);
+ pkt.duration = av_rescale_q(pkt.duration, ist->time_base, ost->time_base);
if (av_write_frame(ctx, &pkt) < 0) {
http_log("Error writing frame to output\n");
c->state = HTTPSTATE_SEND_DATA_TRAILER;
AVInputFormat *fmt_in;
int i;
- url_open_buf(&pb, c->buffer, c->buffer_end - c->buffer, URL_RDONLY);
- pb->is_streamed = 1;
-
/* use feed output format name to find corresponding input format */
fmt_in = av_find_input_format(feed->fmt->name);
if (!fmt_in)
goto fail;
- av_open_input_stream(&s, pb, c->stream->feed_filename, fmt_in, NULL);
+ url_open_buf(&pb, c->buffer, c->buffer_end - c->buffer, URL_RDONLY);
+ pb->is_streamed = 1;
+
+ if (av_open_input_stream(&s, pb, c->stream->feed_filename, fmt_in, NULL) < 0) {
+ av_free(pb);
+ goto fail;
+ }
/* Now we have the actual streams */
if (s->nb_streams != feed->nb_streams) {
goto fail;
}
- for (i = 0; i < s->nb_streams; i++)
- memcpy(feed->streams[i]->codec,
- s->streams[i]->codec, sizeof(AVCodecContext));
+ for (i = 0; i < s->nb_streams; i++) {
+ AVStream *fst = feed->streams[i];
+ AVStream *st = s->streams[i];
+ memcpy(fst->codec, st->codec, sizeof(AVCodecContext));
+ if (fst->codec->extradata_size) {
+ fst->codec->extradata = av_malloc(fst->codec->extradata_size);
+ if (!fst->codec->extradata)
+ goto fail;
+ memcpy(fst->codec->extradata, st->codec->extradata,
+ fst->codec->extradata_size);
+ }
+ }
av_close_input_stream(s);
av_free(pb);
char *ipaddr;
URLContext *h = NULL;
uint8_t *dummy_buf;
- char buf2[32];
int max_packet_size;
/* now we can open the relevant output stream */
goto fail;
}
- http_log("%s:%d - - [%s] \"PLAY %s/streamid=%d %s\"\n",
+ http_log("%s:%d - - \"PLAY %s/streamid=%d %s\"\n",
ipaddr, ntohs(dest_addr->sin_port),
- ctime1(buf2),
c->stream->filename, stream_index, c->protocol);
/* normally, no packets should be output here, but the packet size may be checked */
} else {
/* child */
setsid();
- chdir("/");
close(0);
open("/dev/null", O_RDWR);
if (strcmp(logfilename, "-") != 0) {
av_log_set_callback(http_av_log);
}
+ if (ffserver_daemon)
+ chdir("/");
+
if (http_server() < 0) {
http_log("Could not start server\n");
exit(1);