Commit 18ac6423 authored by Marton Balint's avatar Marton Balint

avformat: migrate to AVFormatContext->url

Signed-off-by: default avatarMarton Balint <cus@passwd.hu>
parent 45ec2e44
...@@ -126,10 +126,10 @@ static int add_file(AVFormatContext *avf, char *filename, ConcatFile **rfile, ...@@ -126,10 +126,10 @@ static int add_file(AVFormatContext *avf, char *filename, ConcatFile **rfile,
url = filename; url = filename;
filename = NULL; filename = NULL;
} else { } else {
url_len = strlen(avf->filename) + strlen(filename) + 16; url_len = strlen(avf->url) + strlen(filename) + 16;
if (!(url = av_malloc(url_len))) if (!(url = av_malloc(url_len)))
FAIL(AVERROR(ENOMEM)); FAIL(AVERROR(ENOMEM));
ff_make_absolute_url(url, url_len, avf->filename, filename); ff_make_absolute_url(url, url_len, avf->url, filename);
av_freep(&filename); av_freep(&filename);
} }
......
...@@ -692,7 +692,7 @@ static int write_manifest(AVFormatContext *s, int final) ...@@ -692,7 +692,7 @@ static int write_manifest(AVFormatContext *s, int final)
AVIOContext *out; AVIOContext *out;
char temp_filename[1024]; char temp_filename[1024];
int ret, i; int ret, i;
const char *proto = avio_find_protocol_name(s->filename); const char *proto = avio_find_protocol_name(s->url);
int use_rename = proto && !strcmp(proto, "file"); int use_rename = proto && !strcmp(proto, "file");
static unsigned int warned_non_file = 0; static unsigned int warned_non_file = 0;
AVDictionaryEntry *title = av_dict_get(s->metadata, "title", NULL, 0); AVDictionaryEntry *title = av_dict_get(s->metadata, "title", NULL, 0);
...@@ -701,7 +701,7 @@ static int write_manifest(AVFormatContext *s, int final) ...@@ -701,7 +701,7 @@ static int write_manifest(AVFormatContext *s, int final)
if (!use_rename && !warned_non_file++) if (!use_rename && !warned_non_file++)
av_log(s, AV_LOG_ERROR, "Cannot use rename on non file protocol, this may lead to races and temporary partial files\n"); av_log(s, AV_LOG_ERROR, "Cannot use rename on non file protocol, this may lead to races and temporary partial files\n");
snprintf(temp_filename, sizeof(temp_filename), use_rename ? "%s.tmp" : "%s", s->filename); snprintf(temp_filename, sizeof(temp_filename), use_rename ? "%s.tmp" : "%s", s->url);
set_http_options(&opts, c); set_http_options(&opts, c);
ret = dashenc_io_open(s, &c->mpd_out, temp_filename, &opts); ret = dashenc_io_open(s, &c->mpd_out, temp_filename, &opts);
if (ret < 0) { if (ret < 0) {
...@@ -778,7 +778,7 @@ static int write_manifest(AVFormatContext *s, int final) ...@@ -778,7 +778,7 @@ static int write_manifest(AVFormatContext *s, int final)
dashenc_io_close(s, &c->mpd_out, temp_filename); dashenc_io_close(s, &c->mpd_out, temp_filename);
if (use_rename) { if (use_rename) {
if ((ret = avpriv_io_move(temp_filename, s->filename)) < 0) if ((ret = avpriv_io_move(temp_filename, s->url)) < 0)
return ret; return ret;
} }
...@@ -859,14 +859,14 @@ static int dash_init(AVFormatContext *s) ...@@ -859,14 +859,14 @@ static int dash_init(AVFormatContext *s)
if (c->single_file) if (c->single_file)
c->use_template = 0; c->use_template = 0;
av_strlcpy(c->dirname, s->filename, sizeof(c->dirname)); av_strlcpy(c->dirname, s->url, sizeof(c->dirname));
ptr = strrchr(c->dirname, '/'); ptr = strrchr(c->dirname, '/');
if (ptr) { if (ptr) {
av_strlcpy(basename, &ptr[1], sizeof(basename)); av_strlcpy(basename, &ptr[1], sizeof(basename));
ptr[1] = '\0'; ptr[1] = '\0';
} else { } else {
c->dirname[0] = '\0'; c->dirname[0] = '\0';
av_strlcpy(basename, s->filename, sizeof(basename)); av_strlcpy(basename, s->url, sizeof(basename));
} }
ptr = strrchr(basename, '.'); ptr = strrchr(basename, '.');
...@@ -1025,7 +1025,7 @@ static int dash_write_header(AVFormatContext *s) ...@@ -1025,7 +1025,7 @@ static int dash_write_header(AVFormatContext *s)
} }
ret = write_manifest(s, 0); ret = write_manifest(s, 0);
if (!ret) if (!ret)
av_log(s, AV_LOG_VERBOSE, "Manifest written to: %s\n", s->filename); av_log(s, AV_LOG_VERBOSE, "Manifest written to: %s\n", s->url);
return ret; return ret;
} }
...@@ -1124,7 +1124,7 @@ static int dash_flush(AVFormatContext *s, int final, int stream) ...@@ -1124,7 +1124,7 @@ static int dash_flush(AVFormatContext *s, int final, int stream)
DASHContext *c = s->priv_data; DASHContext *c = s->priv_data;
int i, ret = 0; int i, ret = 0;
const char *proto = avio_find_protocol_name(s->filename); const char *proto = avio_find_protocol_name(s->url);
int use_rename = proto && !strcmp(proto, "file"); int use_rename = proto && !strcmp(proto, "file");
int cur_flush_segment_index = 0; int cur_flush_segment_index = 0;
...@@ -1332,7 +1332,7 @@ static int dash_write_trailer(AVFormatContext *s) ...@@ -1332,7 +1332,7 @@ static int dash_write_trailer(AVFormatContext *s)
snprintf(filename, sizeof(filename), "%s%s", c->dirname, os->initfile); snprintf(filename, sizeof(filename), "%s%s", c->dirname, os->initfile);
unlink(filename); unlink(filename);
} }
unlink(s->filename); unlink(s->url);
} }
return 0; return 0;
......
...@@ -124,9 +124,9 @@ static int fifo_thread_write_header(FifoThreadContext *ctx) ...@@ -124,9 +124,9 @@ static int fifo_thread_write_header(FifoThreadContext *ctx)
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = ff_format_output_open(avf2, avf->filename, &format_options); ret = ff_format_output_open(avf2, avf->url, &format_options);
if (ret < 0) { if (ret < 0) {
av_log(avf, AV_LOG_ERROR, "Error opening %s: %s\n", avf->filename, av_log(avf, AV_LOG_ERROR, "Error opening %s: %s\n", avf->url,
av_err2str(ret)); av_err2str(ret));
goto end; goto end;
} }
...@@ -500,13 +500,13 @@ static int fifo_init(AVFormatContext *avf) ...@@ -500,13 +500,13 @@ static int fifo_init(AVFormatContext *avf)
} }
} }
oformat = av_guess_format(fifo->format, avf->filename, NULL); oformat = av_guess_format(fifo->format, avf->url, NULL);
if (!oformat) { if (!oformat) {
ret = AVERROR_MUXER_NOT_FOUND; ret = AVERROR_MUXER_NOT_FOUND;
return ret; return ret;
} }
ret = fifo_mux_init(avf, oformat, avf->filename); ret = fifo_mux_init(avf, oformat, avf->url);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -610,10 +610,10 @@ static int shift_data(AVFormatContext *s) ...@@ -610,10 +610,10 @@ static int shift_data(AVFormatContext *s)
* writing, so we re-open the same output, but for reading. It also avoids * writing, so we re-open the same output, but for reading. It also avoids
* a read/seek/write/seek back and forth. */ * a read/seek/write/seek back and forth. */
avio_flush(s->pb); avio_flush(s->pb);
ret = s->io_open(s, &read_pb, s->filename, AVIO_FLAG_READ, NULL); ret = s->io_open(s, &read_pb, s->url, AVIO_FLAG_READ, NULL);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Unable to re-open %s output file for " av_log(s, AV_LOG_ERROR, "Unable to re-open %s output file for "
"the second pass (add_keyframe_index)\n", s->filename); "the second pass (add_keyframe_index)\n", s->url);
goto end; goto end;
} }
......
...@@ -311,7 +311,7 @@ static int gxf_write_material_data_section(AVFormatContext *s) ...@@ -311,7 +311,7 @@ static int gxf_write_material_data_section(AVFormatContext *s)
AVIOContext *pb = s->pb; AVIOContext *pb = s->pb;
int64_t pos; int64_t pos;
int len; int len;
const char *filename = strrchr(s->filename, '/'); const char *filename = strrchr(s->url, '/');
pos = avio_tell(pb); pos = avio_tell(pb);
avio_wb16(pb, 0); /* size */ avio_wb16(pb, 0); /* size */
...@@ -320,7 +320,7 @@ static int gxf_write_material_data_section(AVFormatContext *s) ...@@ -320,7 +320,7 @@ static int gxf_write_material_data_section(AVFormatContext *s)
if (filename) if (filename)
filename++; filename++;
else else
filename = s->filename; filename = s->url;
len = strlen(filename); len = strlen(filename);
avio_w8(pb, MAT_NAME); avio_w8(pb, MAT_NAME);
......
...@@ -169,8 +169,8 @@ static int write_manifest(AVFormatContext *s, int final) ...@@ -169,8 +169,8 @@ static int write_manifest(AVFormatContext *s, int final)
if (c->nb_streams > 0) if (c->nb_streams > 0)
duration = c->streams[0].last_ts * av_q2d(s->streams[0]->time_base); duration = c->streams[0].last_ts * av_q2d(s->streams[0]->time_base);
snprintf(filename, sizeof(filename), "%s/index.f4m", s->filename); snprintf(filename, sizeof(filename), "%s/index.f4m", s->url);
snprintf(temp_filename, sizeof(temp_filename), "%s/index.f4m.tmp", s->filename); snprintf(temp_filename, sizeof(temp_filename), "%s/index.f4m.tmp", s->url);
ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, NULL); ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, NULL);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename); av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
...@@ -178,7 +178,7 @@ static int write_manifest(AVFormatContext *s, int final) ...@@ -178,7 +178,7 @@ static int write_manifest(AVFormatContext *s, int final)
} }
avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
avio_printf(out, "<manifest xmlns=\"http://ns.adobe.com/f4m/1.0\">\n"); avio_printf(out, "<manifest xmlns=\"http://ns.adobe.com/f4m/1.0\">\n");
avio_printf(out, "\t<id>%s</id>\n", av_basename(s->filename)); avio_printf(out, "\t<id>%s</id>\n", av_basename(s->url));
avio_printf(out, "\t<streamType>%s</streamType>\n", avio_printf(out, "\t<streamType>%s</streamType>\n",
final ? "recorded" : "live"); final ? "recorded" : "live");
avio_printf(out, "\t<deliveryType>streaming</deliveryType>\n"); avio_printf(out, "\t<deliveryType>streaming</deliveryType>\n");
...@@ -236,9 +236,9 @@ static int write_abst(AVFormatContext *s, OutputStream *os, int final) ...@@ -236,9 +236,9 @@ static int write_abst(AVFormatContext *s, OutputStream *os, int final)
cur_media_time = os->fragments[os->nb_fragments - 1]->start_time; cur_media_time = os->fragments[os->nb_fragments - 1]->start_time;
snprintf(filename, sizeof(filename), snprintf(filename, sizeof(filename),
"%s/stream%d.abst", s->filename, index); "%s/stream%d.abst", s->url, index);
snprintf(temp_filename, sizeof(temp_filename), snprintf(temp_filename, sizeof(temp_filename),
"%s/stream%d.abst.tmp", s->filename, index); "%s/stream%d.abst.tmp", s->url, index);
ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, NULL); ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, NULL);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename); av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
...@@ -317,9 +317,9 @@ static int hds_write_header(AVFormatContext *s) ...@@ -317,9 +317,9 @@ static int hds_write_header(AVFormatContext *s)
int ret = 0, i; int ret = 0, i;
AVOutputFormat *oformat; AVOutputFormat *oformat;
if (mkdir(s->filename, 0777) == -1 && errno != EEXIST) { if (mkdir(s->url, 0777) == -1 && errno != EEXIST) {
ret = AVERROR(errno); ret = AVERROR(errno);
av_log(s, AV_LOG_ERROR , "Failed to create directory %s\n", s->filename); av_log(s, AV_LOG_ERROR , "Failed to create directory %s\n", s->url);
goto fail; goto fail;
} }
...@@ -412,7 +412,7 @@ static int hds_write_header(AVFormatContext *s) ...@@ -412,7 +412,7 @@ static int hds_write_header(AVFormatContext *s)
s->streams[os->first_stream + j]->time_base = os->ctx->streams[j]->time_base; s->streams[os->first_stream + j]->time_base = os->ctx->streams[j]->time_base;
snprintf(os->temp_filename, sizeof(os->temp_filename), snprintf(os->temp_filename, sizeof(os->temp_filename),
"%s/stream%d_temp", s->filename, i); "%s/stream%d_temp", s->url, i);
ret = init_file(s, os, 0); ret = init_file(s, os, 0);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
...@@ -476,7 +476,7 @@ static int hds_flush(AVFormatContext *s, OutputStream *os, int final, ...@@ -476,7 +476,7 @@ static int hds_flush(AVFormatContext *s, OutputStream *os, int final,
close_file(s, os); close_file(s, os);
snprintf(target_filename, sizeof(target_filename), snprintf(target_filename, sizeof(target_filename),
"%s/stream%dSeg1-Frag%d", s->filename, index, os->fragment_index); "%s/stream%dSeg1-Frag%d", s->url, index, os->fragment_index);
ret = ff_rename(os->temp_filename, target_filename, s); ret = ff_rename(os->temp_filename, target_filename, s);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -549,13 +549,13 @@ static int hds_write_trailer(AVFormatContext *s) ...@@ -549,13 +549,13 @@ static int hds_write_trailer(AVFormatContext *s)
if (c->remove_at_exit) { if (c->remove_at_exit) {
char filename[1024]; char filename[1024];
snprintf(filename, sizeof(filename), "%s/index.f4m", s->filename); snprintf(filename, sizeof(filename), "%s/index.f4m", s->url);
unlink(filename); unlink(filename);
for (i = 0; i < c->nb_streams; i++) { for (i = 0; i < c->nb_streams; i++) {
snprintf(filename, sizeof(filename), "%s/stream%d.abst", s->filename, i); snprintf(filename, sizeof(filename), "%s/stream%d.abst", s->url, i);
unlink(filename); unlink(filename);
} }
rmdir(s->filename); rmdir(s->url);
} }
hds_free(s); hds_free(s);
......
...@@ -198,7 +198,7 @@ int ff_img_read_header(AVFormatContext *s1) ...@@ -198,7 +198,7 @@ int ff_img_read_header(AVFormatContext *s1)
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
av_strlcpy(s->path, s1->filename, sizeof(s->path)); av_strlcpy(s->path, s1->url, sizeof(s->path));
s->img_number = 0; s->img_number = 0;
s->img_count = 0; s->img_count = 0;
...@@ -338,7 +338,7 @@ int ff_img_read_header(AVFormatContext *s1) ...@@ -338,7 +338,7 @@ int ff_img_read_header(AVFormatContext *s1)
pd.buf = probe_buffer; pd.buf = probe_buffer;
pd.buf_size = probe_buffer_size; pd.buf_size = probe_buffer_size;
pd.filename = s1->filename; pd.filename = s1->url;
while ((fmt = av_iformat_next(fmt))) { while ((fmt = av_iformat_next(fmt))) {
if (fmt->read_header != ff_img_read_header || if (fmt->read_header != ff_img_read_header ||
......
...@@ -53,7 +53,7 @@ static int write_header(AVFormatContext *s) ...@@ -53,7 +53,7 @@ static int write_header(AVFormatContext *s)
AVStream *st = s->streams[0]; AVStream *st = s->streams[0];
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(st->codecpar->format); const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(st->codecpar->format);
av_strlcpy(img->path, s->filename, sizeof(img->path)); av_strlcpy(img->path, s->url, sizeof(img->path));
/* find format */ /* find format */
if (s->oformat->flags & AVFMT_NOFILE) if (s->oformat->flags & AVFMT_NOFILE)
...@@ -156,7 +156,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -156,7 +156,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
av_assert0(!img->split_planes); av_assert0(!img->split_planes);
ret = avformat_alloc_output_context2(&fmt, NULL, img->muxer, s->filename); ret = avformat_alloc_output_context2(&fmt, NULL, img->muxer, s->url);
if (ret < 0) if (ret < 0)
return ret; return ret;
st = avformat_new_stream(fmt, NULL); st = avformat_new_stream(fmt, NULL);
......
...@@ -3953,8 +3953,8 @@ static int webm_dash_manifest_read_header(AVFormatContext *s) ...@@ -3953,8 +3953,8 @@ static int webm_dash_manifest_read_header(AVFormatContext *s)
} }
// basename of the file // basename of the file
buf = strrchr(s->filename, '/'); buf = strrchr(s->url, '/');
av_dict_set(&s->streams[0]->metadata, FILENAME, buf ? ++buf : s->filename, 0); av_dict_set(&s->streams[0]->metadata, FILENAME, buf ? ++buf : s->url, 0);
// track number // track number
tracks = matroska->tracks.elem; tracks = matroska->tracks.elem;
......
...@@ -342,9 +342,9 @@ static int read_header(AVFormatContext *avctx) ...@@ -342,9 +342,9 @@ static int read_header(AVFormatContext *avctx)
return ret; return ret;
/* scan secondary files */ /* scan secondary files */
if (strlen(avctx->filename) > 2) { if (strlen(avctx->url) > 2) {
int i; int i;
char *filename = av_strdup(avctx->filename); char *filename = av_strdup(avctx->url);
if (!filename) if (!filename)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
......
...@@ -4115,7 +4115,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) ...@@ -4115,7 +4115,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) { if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) {
MOVDref *dref = &sc->drefs[sc->dref_id - 1]; MOVDref *dref = &sc->drefs[sc->dref_id - 1];
if (c->enable_drefs) { if (c->enable_drefs) {
if (mov_open_dref(c, &sc->pb, c->fc->filename, dref) < 0) if (mov_open_dref(c, &sc->pb, c->fc->url, dref) < 0)
av_log(c->fc, AV_LOG_ERROR, av_log(c->fc, AV_LOG_ERROR,
"stream %d, error opening alias: path='%s', dir='%s', " "stream %d, error opening alias: path='%s', dir='%s', "
"filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n", "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n",
......
...@@ -1556,9 +1556,9 @@ static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track) ...@@ -1556,9 +1556,9 @@ static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track)
else if (track->mode == MODE_ISM) else if (track->mode == MODE_ISM)
tag = track->par->codec_tag; tag = track->par->codec_tag;
else if (track->mode == MODE_IPOD) { else if (track->mode == MODE_IPOD) {
if (!av_match_ext(s->filename, "m4a") && if (!av_match_ext(s->url, "m4a") &&
!av_match_ext(s->filename, "m4v") && !av_match_ext(s->url, "m4v") &&
!av_match_ext(s->filename, "m4b")) !av_match_ext(s->url, "m4b"))
av_log(s, AV_LOG_WARNING, "Warning, extension is not .m4a nor .m4v " av_log(s, AV_LOG_WARNING, "Warning, extension is not .m4a nor .m4v "
"Quicktime/Ipod might not play the file\n"); "Quicktime/Ipod might not play the file\n");
tag = track->par->codec_tag; tag = track->par->codec_tag;
...@@ -6400,10 +6400,10 @@ static int shift_data(AVFormatContext *s) ...@@ -6400,10 +6400,10 @@ static int shift_data(AVFormatContext *s)
* writing, so we re-open the same output, but for reading. It also avoids * writing, so we re-open the same output, but for reading. It also avoids
* a read/seek/write/seek back and forth. */ * a read/seek/write/seek back and forth. */
avio_flush(s->pb); avio_flush(s->pb);
ret = s->io_open(s, &read_pb, s->filename, AVIO_FLAG_READ, NULL); ret = s->io_open(s, &read_pb, s->url, AVIO_FLAG_READ, NULL);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Unable to re-open %s output file for " av_log(s, AV_LOG_ERROR, "Unable to re-open %s output file for "
"the second pass (faststart)\n", s->filename); "the second pass (faststart)\n", s->url);
goto end; goto end;
} }
......
...@@ -703,7 +703,7 @@ static int vobsub_read_header(AVFormatContext *s) ...@@ -703,7 +703,7 @@ static int vobsub_read_header(AVFormatContext *s)
if (!vobsub->sub_name) { if (!vobsub->sub_name) {
char *ext; char *ext;
vobsub->sub_name = av_strdup(s->filename); vobsub->sub_name = av_strdup(s->url);
if (!vobsub->sub_name) { if (!vobsub->sub_name) {
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto end; goto end;
...@@ -718,7 +718,7 @@ static int vobsub_read_header(AVFormatContext *s) ...@@ -718,7 +718,7 @@ static int vobsub_read_header(AVFormatContext *s)
goto end; goto end;
} }
memcpy(ext, !strncmp(ext, "IDX", 3) ? "SUB" : "sub", 3); memcpy(ext, !strncmp(ext, "IDX", 3) ? "SUB" : "sub", 3);
av_log(s, AV_LOG_VERBOSE, "IDX/SUB: %s -> %s\n", s->filename, vobsub->sub_name); av_log(s, AV_LOG_VERBOSE, "IDX/SUB: %s -> %s\n", s->url, vobsub->sub_name);
} }
if (!(iformat = av_find_input_format("mpeg"))) { if (!(iformat = av_find_input_format("mpeg"))) {
......
...@@ -1012,7 +1012,7 @@ static int mpegts_init(AVFormatContext *s) ...@@ -1012,7 +1012,7 @@ static int mpegts_init(AVFormatContext *s)
ts->sdt_packet_period, ts->pat_packet_period); ts->sdt_packet_period, ts->pat_packet_period);
if (ts->m2ts_mode == -1) { if (ts->m2ts_mode == -1) {
if (av_match_ext(s->filename, "m2ts")) { if (av_match_ext(s->url, "m2ts")) {
ts->m2ts_mode = 1; ts->m2ts_mode = 1;
} else { } else {
ts->m2ts_mode = 0; ts->m2ts_mode = 0;
......
...@@ -104,7 +104,7 @@ static int io_open_default(AVFormatContext *s, AVIOContext **pb, ...@@ -104,7 +104,7 @@ static int io_open_default(AVFormatContext *s, AVIOContext **pb,
{ {
int loglevel; int loglevel;
if (!strcmp(url, s->filename) || if (!strcmp(url, s->url) ||
s->iformat && !strcmp(s->iformat->name, "image2") || s->iformat && !strcmp(s->iformat->name, "image2") ||
s->oformat && !strcmp(s->oformat->name, "image2") s->oformat && !strcmp(s->oformat->name, "image2")
) { ) {
......
...@@ -1686,7 +1686,7 @@ int ff_rtsp_connect(AVFormatContext *s) ...@@ -1686,7 +1686,7 @@ int ff_rtsp_connect(AVFormatContext *s)
redirect: redirect:
/* extract hostname and port */ /* extract hostname and port */
av_url_split(proto, sizeof(proto), auth, sizeof(auth), av_url_split(proto, sizeof(proto), auth, sizeof(auth),
host, sizeof(host), &port, path, sizeof(path), s->filename); host, sizeof(host), &port, path, sizeof(path), s->url);
if (!strcmp(proto, "rtsps")) { if (!strcmp(proto, "rtsps")) {
lower_rtsp_proto = "tls"; lower_rtsp_proto = "tls";
...@@ -1717,7 +1717,7 @@ redirect: ...@@ -1717,7 +1717,7 @@ redirect:
} }
} }
/* Construct the URI used in request; this is similar to s->filename, /* Construct the URI used in request; this is similar to s->url,
* but with authentication credentials removed and RTSP specific options * but with authentication credentials removed and RTSP specific options
* stripped out. */ * stripped out. */
ff_url_join(rt->control_uri, sizeof(rt->control_uri), proto, NULL, ff_url_join(rt->control_uri, sizeof(rt->control_uri), proto, NULL,
...@@ -1905,13 +1905,19 @@ redirect: ...@@ -1905,13 +1905,19 @@ redirect:
ff_rtsp_close_streams(s); ff_rtsp_close_streams(s);
ff_rtsp_close_connections(s); ff_rtsp_close_connections(s);
if (reply->status_code >=300 && reply->status_code < 400 && s->iformat) { if (reply->status_code >=300 && reply->status_code < 400 && s->iformat) {
av_strlcpy(s->filename, reply->location, sizeof(s->filename)); char *new_url = av_strdup(reply->location);
if (!new_url) {
err = AVERROR(ENOMEM);
goto fail2;
}
ff_format_set_url(s, new_url);
rt->session_id[0] = '\0'; rt->session_id[0] = '\0';
av_log(s, AV_LOG_INFO, "Status %d: Redirecting to %s\n", av_log(s, AV_LOG_INFO, "Status %d: Redirecting to %s\n",
reply->status_code, reply->status_code,
s->filename); s->url);
goto redirect; goto redirect;
} }
fail2:
ff_network_close(); ff_network_close();
return err; return err;
} }
...@@ -2425,7 +2431,7 @@ static int rtp_read_header(AVFormatContext *s) ...@@ -2425,7 +2431,7 @@ static int rtp_read_header(AVFormatContext *s)
if (!ff_network_init()) if (!ff_network_init())
return AVERROR(EIO); return AVERROR(EIO);
ret = ffurl_open_whitelist(&in, s->filename, AVIO_FLAG_READ, ret = ffurl_open_whitelist(&in, s->url, AVIO_FLAG_READ,
&s->interrupt_callback, NULL, s->protocol_whitelist, s->protocol_blacklist, NULL); &s->interrupt_callback, NULL, s->protocol_whitelist, s->protocol_blacklist, NULL);
if (ret) if (ret)
goto fail; goto fail;
...@@ -2476,7 +2482,7 @@ static int rtp_read_header(AVFormatContext *s) ...@@ -2476,7 +2482,7 @@ static int rtp_read_header(AVFormatContext *s)
} }
av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port,
NULL, 0, s->filename); NULL, 0, s->url);
snprintf(sdp, sizeof(sdp), snprintf(sdp, sizeof(sdp),
"v=0\r\nc=IN IP%d %s\r\nm=%s %d RTP/AVP %d\r\n", "v=0\r\nc=IN IP%d %s\r\nm=%s %d RTP/AVP %d\r\n",
......
...@@ -644,7 +644,7 @@ static int rtsp_listen(AVFormatContext *s) ...@@ -644,7 +644,7 @@ static int rtsp_listen(AVFormatContext *s)
/* extract hostname and port */ /* extract hostname and port */
av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host), av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host),
&port, path, sizeof(path), s->filename); &port, path, sizeof(path), s->url);
/* ff_url_join. No authorization by now (NULL) */ /* ff_url_join. No authorization by now (NULL) */
ff_url_join(rt->control_uri, sizeof(rt->control_uri), proto, NULL, host, ff_url_join(rt->control_uri, sizeof(rt->control_uri), proto, NULL, host,
...@@ -804,7 +804,7 @@ static int resetup_tcp(AVFormatContext *s) ...@@ -804,7 +804,7 @@ static int resetup_tcp(AVFormatContext *s)
int port; int port;
av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, NULL, 0, av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, NULL, 0,
s->filename); s->url);
ff_rtsp_undo_setup(s, 0); ff_rtsp_undo_setup(s, 0);
return ff_rtsp_make_setup_request(s, host, port, RTSP_LOWER_TRANSPORT_TCP, return ff_rtsp_make_setup_request(s, host, port, RTSP_LOWER_TRANSPORT_TCP,
rt->real_challenge); rt->real_challenge);
......
...@@ -50,6 +50,7 @@ int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr) ...@@ -50,6 +50,7 @@ int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr)
int i; int i;
char *sdp; char *sdp;
AVFormatContext sdp_ctx, *ctx_array[1]; AVFormatContext sdp_ctx, *ctx_array[1];
char url[1024];
if (s->start_time_realtime == 0 || s->start_time_realtime == AV_NOPTS_VALUE) if (s->start_time_realtime == 0 || s->start_time_realtime == AV_NOPTS_VALUE)
s->start_time_realtime = av_gettime(); s->start_time_realtime = av_gettime();
...@@ -71,7 +72,8 @@ int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr) ...@@ -71,7 +72,8 @@ int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr)
* flexible SDP creation interface. * flexible SDP creation interface.
*/ */
sdp_ctx = *s; sdp_ctx = *s;
ff_url_join(sdp_ctx.filename, sizeof(sdp_ctx.filename), sdp_ctx.url = url;
ff_url_join(url, sizeof(url),
"rtsp", NULL, addr, -1, NULL); "rtsp", NULL, addr, -1, NULL);
ctx_array[0] = &sdp_ctx; ctx_array[0] = &sdp_ctx;
if (av_sdp_create(ctx_array, 1, sdp, SDP_MAX_SIZE)) { if (av_sdp_create(ctx_array, 1, sdp, SDP_MAX_SIZE)) {
......
...@@ -74,7 +74,7 @@ static int sap_read_header(AVFormatContext *s) ...@@ -74,7 +74,7 @@ static int sap_read_header(AVFormatContext *s)
return AVERROR(EIO); return AVERROR(EIO);
av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port,
path, sizeof(path), s->filename); path, sizeof(path), s->url);
if (port < 0) if (port < 0)
port = 9875; port = 9875;
......
...@@ -84,7 +84,7 @@ static int sap_write_header(AVFormatContext *s) ...@@ -84,7 +84,7 @@ static int sap_write_header(AVFormatContext *s)
/* extract hostname and port */ /* extract hostname and port */
av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &base_port, av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &base_port,
path, sizeof(path), s->filename); path, sizeof(path), s->url);
if (base_port < 0) if (base_port < 0)
base_port = 5004; base_port = 5004;
...@@ -144,6 +144,7 @@ static int sap_write_header(AVFormatContext *s) ...@@ -144,6 +144,7 @@ static int sap_write_header(AVFormatContext *s)
s->start_time_realtime = av_gettime(); s->start_time_realtime = av_gettime();
for (i = 0; i < s->nb_streams; i++) { for (i = 0; i < s->nb_streams; i++) {
URLContext *fd; URLContext *fd;
char *new_url;
ff_url_join(url, sizeof(url), "rtp", NULL, host, base_port, ff_url_join(url, sizeof(url), "rtp", NULL, host, base_port,