mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2025-10-07 01:36:16 +08:00
lavf: Don't try to update files atomically with renames on windows
On windows, rename(2) will fail if the target file exists. On unix this trick is used to make sure that people reading the file either will get the full previous file, or the full new version of the file, but no intermediate version. Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
@@ -163,6 +163,7 @@ static int write_manifest(AVFormatContext *s, int final)
|
||||
HDSContext *c = s->priv_data;
|
||||
AVIOContext *out;
|
||||
char filename[1024], temp_filename[1024];
|
||||
const char *write_filename;
|
||||
int ret, i;
|
||||
float duration = 0;
|
||||
|
||||
@@ -171,10 +172,11 @@ static int write_manifest(AVFormatContext *s, int final)
|
||||
|
||||
snprintf(filename, sizeof(filename), "%s/index.f4m", s->filename);
|
||||
snprintf(temp_filename, sizeof(temp_filename), "%s/index.f4m.tmp", s->filename);
|
||||
ret = avio_open2(&out, temp_filename, AVIO_FLAG_WRITE,
|
||||
write_filename = USE_RENAME_REPLACE ? temp_filename : filename;
|
||||
ret = avio_open2(&out, write_filename, AVIO_FLAG_WRITE,
|
||||
&s->interrupt_callback, NULL);
|
||||
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", write_filename);
|
||||
return ret;
|
||||
}
|
||||
avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
||||
@@ -204,7 +206,7 @@ static int write_manifest(AVFormatContext *s, int final)
|
||||
avio_printf(out, "</manifest>\n");
|
||||
avio_flush(out);
|
||||
avio_close(out);
|
||||
return ff_rename(temp_filename, filename);
|
||||
return USE_RENAME_REPLACE ? ff_rename(temp_filename, filename) : 0;
|
||||
}
|
||||
|
||||
static void update_size(AVIOContext *out, int64_t pos)
|
||||
@@ -223,6 +225,7 @@ static int write_abst(AVFormatContext *s, OutputStream *os, int final)
|
||||
HDSContext *c = s->priv_data;
|
||||
AVIOContext *out;
|
||||
char filename[1024], temp_filename[1024];
|
||||
const char *write_filename;
|
||||
int i, ret;
|
||||
int64_t asrt_pos, afrt_pos;
|
||||
int start = 0, fragments;
|
||||
@@ -240,10 +243,11 @@ static int write_abst(AVFormatContext *s, OutputStream *os, int final)
|
||||
"%s/stream%d.abst", s->filename, index);
|
||||
snprintf(temp_filename, sizeof(temp_filename),
|
||||
"%s/stream%d.abst.tmp", s->filename, index);
|
||||
ret = avio_open2(&out, temp_filename, AVIO_FLAG_WRITE,
|
||||
write_filename = USE_RENAME_REPLACE ? temp_filename : filename;
|
||||
ret = avio_open2(&out, write_filename, AVIO_FLAG_WRITE,
|
||||
&s->interrupt_callback, NULL);
|
||||
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", write_filename);
|
||||
return ret;
|
||||
}
|
||||
avio_wb32(out, 0); // abst size
|
||||
@@ -285,7 +289,7 @@ static int write_abst(AVFormatContext *s, OutputStream *os, int final)
|
||||
update_size(out, afrt_pos);
|
||||
update_size(out, 0);
|
||||
avio_close(out);
|
||||
return ff_rename(temp_filename, filename);
|
||||
return USE_RENAME_REPLACE ? ff_rename(temp_filename, filename) : 0;
|
||||
}
|
||||
|
||||
static int init_file(AVFormatContext *s, OutputStream *os, int64_t start_ts)
|
||||
|
Reference in New Issue
Block a user