Merge commit '675ac56b7ee0f204963fde55295197c5df80aa91'

* commit '675ac56b7ee0f204963fde55295197c5df80aa91':
  Revert "lavf: Don't try to update files atomically with renames on windows"

Conflicts:
	libavformat/dashenc.c
	libavformat/hdsenc.c
	libavformat/internal.h
	libavformat/smoothstreamingenc.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
pull/100/head
Michael Niedermayer 10 years ago
commit 4ae1d6021b
  1. 14
      libavformat/dashenc.c
  2. 16
      libavformat/hdsenc.c
  3. 6
      libavformat/internal.h
  4. 8
      libavformat/smoothstreamingenc.c

@ -296,15 +296,13 @@ static int write_manifest(AVFormatContext *s, int final)
DASHContext *c = s->priv_data; DASHContext *c = s->priv_data;
AVIOContext *out; AVIOContext *out;
char temp_filename[1024]; char temp_filename[1024];
const char *write_filename;
int ret, i; int ret, i;
AVDictionaryEntry *title = av_dict_get(s->metadata, "title", NULL, 0); AVDictionaryEntry *title = av_dict_get(s->metadata, "title", NULL, 0);
snprintf(temp_filename, sizeof(temp_filename), "%s.tmp", s->filename); snprintf(temp_filename, sizeof(temp_filename), "%s.tmp", s->filename);
write_filename = USE_RENAME_REPLACE ? temp_filename : s->filename; ret = avio_open2(&out, temp_filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
ret = avio_open2(&out, write_filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", write_filename); av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
return ret; return ret;
} }
avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
@ -394,7 +392,7 @@ static int write_manifest(AVFormatContext *s, int final)
avio_printf(out, "</MPD>\n"); avio_printf(out, "</MPD>\n");
avio_flush(out); avio_flush(out);
avio_close(out); avio_close(out);
return USE_RENAME_REPLACE ? ff_rename(temp_filename, s->filename, s) : 0; return ff_rename(temp_filename, s->filename, s);
} }
static int dash_write_header(AVFormatContext *s) static int dash_write_header(AVFormatContext *s)
@ -610,7 +608,6 @@ static int dash_flush(AVFormatContext *s, int final, int stream)
for (i = 0; i < s->nb_streams; i++) { for (i = 0; i < s->nb_streams; i++) {
OutputStream *os = &c->streams[i]; OutputStream *os = &c->streams[i];
char filename[1024] = "", full_path[1024], temp_path[1024]; char filename[1024] = "", full_path[1024], temp_path[1024];
const char *write_path;
int64_t start_pos = avio_tell(os->ctx->pb); int64_t start_pos = avio_tell(os->ctx->pb);
int range_length, index_length = 0; int range_length, index_length = 0;
@ -633,8 +630,7 @@ static int dash_flush(AVFormatContext *s, int final, int stream)
snprintf(filename, sizeof(filename), "chunk-stream%d-%05d.m4s", i, os->segment_index); snprintf(filename, sizeof(filename), "chunk-stream%d-%05d.m4s", i, os->segment_index);
snprintf(full_path, sizeof(full_path), "%s%s", c->dirname, filename); snprintf(full_path, sizeof(full_path), "%s%s", c->dirname, filename);
snprintf(temp_path, sizeof(temp_path), "%s.tmp", full_path); snprintf(temp_path, sizeof(temp_path), "%s.tmp", full_path);
write_path = USE_RENAME_REPLACE ? temp_path : full_path; ret = ffurl_open(&os->out, temp_path, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
ret = ffurl_open(&os->out, write_path, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
if (ret < 0) if (ret < 0)
break; break;
write_styp(os->ctx->pb); write_styp(os->ctx->pb);
@ -649,7 +645,7 @@ static int dash_flush(AVFormatContext *s, int final, int stream)
} else { } else {
ffurl_close(os->out); ffurl_close(os->out);
os->out = NULL; os->out = NULL;
ret = USE_RENAME_REPLACE ? ff_rename(temp_path, full_path, s) : 0; ret = ff_rename(temp_path, full_path, s);
if (ret < 0) if (ret < 0)
break; break;
} }

@ -163,7 +163,6 @@ static int write_manifest(AVFormatContext *s, int final)
HDSContext *c = s->priv_data; HDSContext *c = s->priv_data;
AVIOContext *out; AVIOContext *out;
char filename[1024], temp_filename[1024]; char filename[1024], temp_filename[1024];
const char *write_filename;
int ret, i; int ret, i;
float duration = 0; float duration = 0;
@ -172,11 +171,10 @@ static int write_manifest(AVFormatContext *s, int final)
snprintf(filename, sizeof(filename), "%s/index.f4m", s->filename); snprintf(filename, sizeof(filename), "%s/index.f4m", s->filename);
snprintf(temp_filename, sizeof(temp_filename), "%s/index.f4m.tmp", s->filename); snprintf(temp_filename, sizeof(temp_filename), "%s/index.f4m.tmp", s->filename);
write_filename = USE_RENAME_REPLACE ? temp_filename : filename; ret = avio_open2(&out, temp_filename, AVIO_FLAG_WRITE,
ret = avio_open2(&out, write_filename, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL); &s->interrupt_callback, NULL);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", write_filename); av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
return ret; return ret;
} }
avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
@ -206,7 +204,7 @@ static int write_manifest(AVFormatContext *s, int final)
avio_printf(out, "</manifest>\n"); avio_printf(out, "</manifest>\n");
avio_flush(out); avio_flush(out);
avio_close(out); avio_close(out);
return USE_RENAME_REPLACE ? ff_rename(temp_filename, filename, s) : 0; return ff_rename(temp_filename, filename, s);
} }
static void update_size(AVIOContext *out, int64_t pos) static void update_size(AVIOContext *out, int64_t pos)
@ -225,7 +223,6 @@ static int write_abst(AVFormatContext *s, OutputStream *os, int final)
HDSContext *c = s->priv_data; HDSContext *c = s->priv_data;
AVIOContext *out; AVIOContext *out;
char filename[1024], temp_filename[1024]; char filename[1024], temp_filename[1024];
const char *write_filename;
int i, ret; int i, ret;
int64_t asrt_pos, afrt_pos; int64_t asrt_pos, afrt_pos;
int start = 0, fragments; int start = 0, fragments;
@ -243,11 +240,10 @@ static int write_abst(AVFormatContext *s, OutputStream *os, int final)
"%s/stream%d.abst", s->filename, index); "%s/stream%d.abst", s->filename, 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->filename, index);
write_filename = USE_RENAME_REPLACE ? temp_filename : filename; ret = avio_open2(&out, temp_filename, AVIO_FLAG_WRITE,
ret = avio_open2(&out, write_filename, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL); &s->interrupt_callback, NULL);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", write_filename); av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
return ret; return ret;
} }
avio_wb32(out, 0); // abst size avio_wb32(out, 0); // abst size
@ -289,7 +285,7 @@ static int write_abst(AVFormatContext *s, OutputStream *os, int final)
update_size(out, afrt_pos); update_size(out, afrt_pos);
update_size(out, 0); update_size(out, 0);
avio_close(out); avio_close(out);
return USE_RENAME_REPLACE ? ff_rename(temp_filename, filename, s) : 0; return ff_rename(temp_filename, filename, s);
} }
static int init_file(AVFormatContext *s, OutputStream *os, int64_t start_ts) static int init_file(AVFormatContext *s, OutputStream *os, int64_t start_ts)

@ -436,10 +436,4 @@ enum AVWriteUncodedFrameFlags {
*/ */
int ff_copy_whitelists(AVFormatContext *dst, AVFormatContext *src); int ff_copy_whitelists(AVFormatContext *dst, AVFormatContext *src);
#ifndef _WIN32
#define USE_RENAME_REPLACE 1
#else
#define USE_RENAME_REPLACE 0
#endif
#endif /* AVFORMAT_INTERNAL_H */ #endif /* AVFORMAT_INTERNAL_H */

@ -215,16 +215,14 @@ static int write_manifest(AVFormatContext *s, int final)
SmoothStreamingContext *c = s->priv_data; SmoothStreamingContext *c = s->priv_data;
AVIOContext *out; AVIOContext *out;
char filename[1024], temp_filename[1024]; char filename[1024], temp_filename[1024];
const char *write_filename;
int ret, i, video_chunks = 0, audio_chunks = 0, video_streams = 0, audio_streams = 0; int ret, i, video_chunks = 0, audio_chunks = 0, video_streams = 0, audio_streams = 0;
int64_t duration = 0; int64_t duration = 0;
snprintf(filename, sizeof(filename), "%s/Manifest", s->filename); snprintf(filename, sizeof(filename), "%s/Manifest", s->filename);
snprintf(temp_filename, sizeof(temp_filename), "%s/Manifest.tmp", s->filename); snprintf(temp_filename, sizeof(temp_filename), "%s/Manifest.tmp", s->filename);
write_filename = USE_RENAME_REPLACE ? temp_filename : filename; ret = avio_open2(&out, temp_filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
ret = avio_open2(&out, write_filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", write_filename); av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
return ret; return ret;
} }
avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
@ -285,7 +283,7 @@ static int write_manifest(AVFormatContext *s, int final)
avio_printf(out, "</SmoothStreamingMedia>\n"); avio_printf(out, "</SmoothStreamingMedia>\n");
avio_flush(out); avio_flush(out);
avio_close(out); avio_close(out);
return USE_RENAME_REPLACE ? ff_rename(temp_filename, filename, s) : 0; return ff_rename(temp_filename, filename, s);
} }
static int ism_write_header(AVFormatContext *s) static int ism_write_header(AVFormatContext *s)

Loading…
Cancel
Save