]> git.sesse.net Git - ffmpeg/commitdiff
Merge commit '310cc4bf82824f09bdd0b9147ed725cdbeaf9bdd'
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 28 Aug 2013 10:34:29 +0000 (12:34 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 28 Aug 2013 10:34:33 +0000 (12:34 +0200)
* commit '310cc4bf82824f09bdd0b9147ed725cdbeaf9bdd':
  smoothstreamingenc: Write to a temp file while updating the manifest

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavformat/smoothstreamingenc.c

index 7163c90c4da8e9968be482ea49917a51eeb783a2,7007264008fbceadcdf7257786c4cc0e51cd3239..fe6e27f94be2e21578a94531ed7309e67b7bd9cc
@@@ -2,20 -2,20 +2,20 @@@
   * Live smooth streaming fragmenter
   * Copyright (c) 2012 Martin Storsjo
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -210,14 -210,15 +210,15 @@@ static int write_manifest(AVFormatConte
  {
      SmoothStreamingContext *c = s->priv_data;
      AVIOContext *out;
-     char filename[1024];
+     char filename[1024], temp_filename[1024];
      int ret, i, video_chunks = 0, audio_chunks = 0, video_streams = 0, audio_streams = 0;
      int64_t duration = 0;
  
      snprintf(filename, sizeof(filename), "%s/Manifest", s->filename);
-     ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
+     snprintf(temp_filename, sizeof(temp_filename), "%s/Manifest.tmp", s->filename);
+     ret = avio_open2(&out, temp_filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
      if (ret < 0) {
-         av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", filename);
+         av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
          return ret;
      }
      avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
      avio_printf(out, "</SmoothStreamingMedia>\n");
      avio_flush(out);
      avio_close(out);
+     rename(temp_filename, filename);
      return 0;
  }
  
@@@ -287,11 -289,7 +289,11 @@@ static int ism_write_header(AVFormatCon
      int ret = 0, i;
      AVOutputFormat *oformat;
  
 -    mkdir(s->filename, 0777);
 +    if (mkdir(s->filename, 0777) < 0) {
 +        av_log(s, AV_LOG_ERROR, "mkdir failed\n");
 +        ret = AVERROR(errno);
 +        goto fail;
 +    }
  
      oformat = av_guess_format("ismv", NULL, NULL);
      if (!oformat) {
              goto fail;
          }
          snprintf(os->dirname, sizeof(os->dirname), "%s/QualityLevels(%d)", s->filename, s->streams[i]->codec->bit_rate);
 -        mkdir(os->dirname, 0777);
 +        if (mkdir(os->dirname, 0777) < 0) {
 +            ret = AVERROR(errno);
 +            av_log(s, AV_LOG_ERROR, "mkdir failed\n");
 +            goto fail;
 +        }
  
          ctx = avformat_alloc_context();
          if (!ctx) {
@@@ -428,7 -422,7 +430,7 @@@ static int parse_fragment(AVFormatConte
          if (len < 8 || len >= *moof_size)
              goto fail;
          if (tag == MKTAG('u','u','i','d')) {
 -            const uint8_t tfxd[] = {
 +            static const uint8_t tfxd[] = {
                  0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
                  0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
              };
@@@ -567,7 -561,7 +569,7 @@@ static int ism_write_packet(AVFormatCon
      SmoothStreamingContext *c = s->priv_data;
      AVStream *st = s->streams[pkt->stream_index];
      OutputStream *os = &c->streams[pkt->stream_index];
 -    int64_t end_dts = (c->nb_fragments + 1) * c->min_frag_duration;
 +    int64_t end_dts = (c->nb_fragments + 1LL) * c->min_frag_duration;
      int ret;
  
      if (st->first_dts == AV_NOPTS_VALUE)