stream_ffmpeg: handle rtsp:// URLs by default, add lavf://

Make stream_ffmpeg handle rtsp:// URLs by default, without requiring
ffmpeg://rtsp://. Previously (after removal of other rtsp
implementations) rtsp:// fell back to using HTTP, which was unlikely
to work.

Also add lavf:// as an alternative to ffmpeg:// to force the stream
implementation. Since libavformat can come from Libav rather than
FFmpeg, using the ffmpeg name in the prefix is misleading.
This commit is contained in:
Uoti Urpala 2012-09-07 19:39:46 +03:00 committed by wm4
parent 60cbc9461b
commit 6903319c66
3 changed files with 31 additions and 22 deletions

View File

@ -200,7 +200,8 @@ static int lavf_check_file(demuxer_t *demuxer)
mp_msg(MSGT_DEMUX, MSGL_WARN, "Stream url is not set!\n");
avpd.filename = "";
}
if (!strncmp(avpd.filename, "ffmpeg://", 9))
if (!strncmp(avpd.filename, "ffmpeg://", 9) ||
!strncmp(avpd.filename, "lavf://", 7))
avpd.filename += 9;
avpd.buf_size = probe_data_size;
@ -616,10 +617,12 @@ static demuxer_t *demux_open_lavf(demuxer_t *demuxer)
}
if (demuxer->stream->url) {
if (!strncmp(demuxer->stream->url, "ffmpeg://rtsp:", 14))
av_strlcpy(mp_filename, demuxer->stream->url + 9,
sizeof(mp_filename));
else
if (demuxer->stream->lavf_type && !strcmp(demuxer->stream->lavf_type,
"rtsp")) {
// Remove possible leading ffmpeg:// or lavf://
char *name = strstr(demuxer->stream->url, "rtsp:");
av_strlcpy(mp_filename, name, sizeof(mp_filename));
} else
av_strlcat(mp_filename, demuxer->stream->url, sizeof(mp_filename));
} else
av_strlcat(mp_filename, "foobar.dummy", sizeof(mp_filename));

View File

@ -93,6 +93,7 @@ static const stream_info_t* const auto_open_streams[] = {
#ifdef CONFIG_CDDA
&stream_info_cdda,
#endif
&stream_info_ffmpeg, // use for rstp:// before http fallback
#ifdef CONFIG_NETWORKING
&stream_info_netstream,
&stream_info_http1,
@ -128,7 +129,6 @@ static const stream_info_t* const auto_open_streams[] = {
#ifdef CONFIG_LIBBLURAY
&stream_info_bluray,
#endif
&stream_info_ffmpeg,
&stream_info_null,
&stream_info_mf,

View File

@ -89,7 +89,7 @@ static void close_f(stream_t *stream)
avio_close(avio);
}
static const char prefix[] = "ffmpeg://";
static const char * const prefix[] = { "lavf://", "ffmpeg://" };
static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
{
@ -97,8 +97,6 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
const char *filename;
AVIOContext *avio = NULL;
int res = STREAM_ERROR;
int64_t size;
int dummy;
if (mode == STREAM_READ)
flags = AVIO_FLAG_READ;
@ -116,12 +114,22 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
mp_msg(MSGT_OPEN, MSGL_ERR, "[ffmpeg] No URL\n");
goto out;
}
if (!strncmp(filename, prefix, strlen(prefix)))
filename += strlen(prefix);
dummy = !strncmp(filename, "rtsp:", 5);
for (int i = 0; i < sizeof(prefix) / sizeof(prefix[0]); i++)
if (!strncmp(filename, prefix[i], strlen(prefix[i])))
filename += strlen(prefix[i]);
if (!strncmp(filename, "rtsp:", 5)) {
/* This is handled as a special demuxer, without a separate
* stream layer. demux_lavf will do all the real work.
*/
stream->type = STREAMTYPE_STREAM;
stream->seek = NULL;
*file_format = DEMUXER_TYPE_LAVF;
stream->lavf_type = "rtsp";
return STREAM_OK;
}
mp_msg(MSGT_OPEN, MSGL_V, "[ffmpeg] Opening %s\n", filename);
if (!dummy && avio_open(&avio, filename, flags) < 0)
if (avio_open(&avio, filename, flags) < 0)
goto out;
char *rtmp[] = {"rtmp:", "rtmpt:", "rtmpe:", "rtmpte:", "rtmps:"};
@ -131,21 +139,19 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
stream->lavf_type = "flv";
}
stream->priv = avio;
size = dummy ? 0 : avio_size(avio);
int64_t size = avio_size(avio);
if (size >= 0)
stream->end_pos = size;
stream->type = STREAMTYPE_FILE;
stream->seek = seek;
if (dummy || !avio->seekable) {
if (!avio->seekable) {
stream->type = STREAMTYPE_STREAM;
stream->seek = NULL;
}
if (!dummy) {
stream->fill_buffer = fill_buffer;
stream->write_buffer = write_buffer;
stream->control = control;
stream->close = close_f;
}
stream->fill_buffer = fill_buffer;
stream->write_buffer = write_buffer;
stream->control = control;
stream->close = close_f;
res = STREAM_OK;
out:
@ -158,7 +164,7 @@ const stream_info_t stream_info_ffmpeg = {
"",
"",
open_f,
{ "ffmpeg", "rtmp", NULL },
{ "lavf", "ffmpeg", "rtmp", "rtsp", NULL },
NULL,
1 // Urls are an option string
};