* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#define _XOPEN_SOURCE 600
-
#include "config.h"
#if !HAVE_CLOSESOCKET
#define closesocket close
#include <strings.h>
#include <stdlib.h>
#include "libavformat/avformat.h"
+#include "libavformat/ffm.h"
#include "libavformat/network.h"
#include "libavformat/os_support.h"
#include "libavformat/rtpdec.h"
#include "libavutil/lfg.h"
#include "libavutil/random_seed.h"
#include "libavutil/parseutils.h"
-#include "libavcodec/opt.h"
+#include "libavutil/opt.h"
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
#include "cmdutils.h"
-const char program_name[] = "FFserver";
+const char program_name[] = "ffserver";
const int program_birth_year = 2000;
static const OptionDef options[];
"RTSP_SEND_PACKET",
};
-#if !FF_API_MAX_STREAMS
#define MAX_STREAMS 20
-#endif
#define IOBUFFER_INIT_SIZE 8192
}
}
-#ifdef DEBUG_WMP
+#ifdef DEBUG
http_log("\nGot request:\n%s\n", c->buffer);
#endif
return 0;
}
-#ifdef DEBUG_WMP
+#ifdef DEBUG
if (strcmp(stream->filename + strlen(stream->filename) - 4, ".asf") == 0)
http_log("\nGot request:\n%s\n", c->buffer);
#endif
}
}
-#if 1
if (c->fmt_in->iformat->read_seek)
av_seek_frame(c->fmt_in, -1, stream_pos, 0);
-#endif
/* set the start time (needed for maxtime and RTP packet timing) */
c->start_time = cur_time;
c->first_pts = AV_NOPTS_VALUE;
av_metadata_set2(&c->fmt_ctx.metadata, "copyright", c->stream->copyright, 0);
av_metadata_set2(&c->fmt_ctx.metadata, "title" , c->stream->title , 0);
+ c->fmt_ctx.streams = av_mallocz(sizeof(AVStream *) * c->stream->nb_streams);
+
for(i=0;i<c->stream->nb_streams;i++) {
- AVStream *st;
AVStream *src;
- st = av_mallocz(sizeof(AVStream));
- c->fmt_ctx.streams[i] = st;
+ c->fmt_ctx.streams[i] = av_mallocz(sizeof(AVStream));
/* if file or feed, then just take streams from FFStream struct */
if (!c->stream->feed ||
c->stream->feed == c->stream)
else
src = c->stream->feed->streams[c->stream->feed_streams[i]];
- *st = *src;
- st->priv_data = 0;
- st->codec->frame_number = 0; /* XXX: should be done in
+ *(c->fmt_ctx.streams[i]) = *src;
+ c->fmt_ctx.streams[i]->priv_data = 0;
+ c->fmt_ctx.streams[i]->codec->frame_number = 0; /* XXX: should be done in
AVStream, not in codec */
}
/* set output format parameters */
/*
* HACK to avoid mpeg ps muxer to spit many underflow errors
- * Default value from FFmpeg
+ * Default value from Libav
* Try to set it use configuration option
*/
c->fmt_ctx.preload = (int)(0.5*AV_TIME_BASE);
snprintf(avc->filename, 1024, "rtp://0.0.0.0");
}
-#if !FF_API_MAX_STREAMS
if (avc->nb_streams >= INT_MAX/sizeof(*avc->streams) ||
!(avc->streams = av_malloc(avc->nb_streams * sizeof(*avc->streams))))
goto sdp_done;
-#endif
if (avc->nb_streams >= INT_MAX/sizeof(*avs) ||
!(avs = av_malloc(avc->nb_streams * sizeof(*avs))))
goto sdp_done;
av_sdp_create(&avc, 1, *pbuffer, 2048);
sdp_done:
-#if !FF_API_MAX_STREAMS
av_free(avc->streams);
-#endif
av_metadata_free(&avc->metadata);
av_free(avc);
av_free(avs);
static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPMessageHeader *h)
{
HTTPContext *rtp_c;
- char session_id[32];
rtp_c = find_rtp_session_with_url(url, h->session_id);
if (!rtp_c) {
return;
}
- av_strlcpy(session_id, rtp_c->session_id, sizeof(session_id));
-
- /* abort the session */
- close_connection(rtp_c);
-
/* now everything is OK, so we can send the connection parameters */
rtsp_reply_header(c, RTSP_STATUS_OK);
/* session ID */
- avio_printf(c->pb, "Session: %s\r\n", session_id);
+ avio_printf(c->pb, "Session: %s\r\n", rtp_c->session_id);
avio_printf(c->pb, "\r\n");
+
+ /* abort the session */
+ close_connection(rtp_c);
}
if (!st)
goto fail;
ctx->nb_streams = 1;
+ ctx->streams = av_mallocz(sizeof(AVStream *) * ctx->nb_streams);
+ if (!ctx->streams)
+ goto fail;
ctx->streams[0] = st;
if (!c->stream->feed ||
"rtp://%s:%d", ipaddr, ntohs(dest_addr->sin_port));
}
- if (url_open(&h, ctx->filename, AVIO_WRONLY) < 0)
+ if (url_open(&h, ctx->filename, AVIO_FLAG_WRITE) < 0)
goto fail;
c->rtp_handles[stream_index] = h;
max_packet_size = url_get_max_packet_size(h);
for(feed = first_feed; feed != NULL; feed = feed->next_feed) {
int fd;
- if (url_exist(feed->feed_filename)) {
+ if (avio_check(feed->feed_filename, AVIO_FLAG_READ) > 0) {
/* See if it matches */
AVFormatContext *s;
int matches = 0;
unlink(feed->feed_filename);
}
}
- if (!url_exist(feed->feed_filename)) {
+ if (avio_check(feed->feed_filename, AVIO_FLAG_WRITE) <= 0) {
AVFormatContext s1 = {0}, *s = &s1;
if (feed->readonly) {
}
/* only write the header of the ffm file */
- if (avio_open(&s->pb, feed->feed_filename, AVIO_WRONLY) < 0) {
+ if (avio_open(&s->pb, feed->feed_filename, AVIO_FLAG_WRITE) < 0) {
http_log("Could not open output feed file '%s'\n",
feed->feed_filename);
exit(1);
}
s->oformat = feed->fmt;
s->nb_streams = feed->nb_streams;
- for(i=0;i<s->nb_streams;i++) {
- AVStream *st;
- st = feed->streams[i];
- s->streams[i] = st;
- }
+ s->streams = feed->streams;
av_set_parameters(s, NULL);
if (av_write_header(s) < 0) {
http_log("Container doesn't supports the required parameters\n");