Merge commit '01f1f017d831cf14617aaaeafcec3ae3a81efce7'
authorRodger Combs <rodger.combs@gmail.com>
Tue, 26 Sep 2017 17:12:19 +0000 (14:12 -0300)
committerJames Almer <jamrial@gmail.com>
Tue, 26 Sep 2017 17:12:19 +0000 (14:12 -0300)
* commit '01f1f017d831cf14617aaaeafcec3ae3a81efce7':
  dashenc: use avio_dynbuf instead of packet_write callback

Merged-by: Rodger Combs <rodger.combs@gmail.com>
1  2 
libavformat/dashenc.c

@@@ -694,11 -818,9 +707,10 @@@ static int dash_init(AVFormatContext *s
          st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
          st->time_base = s->streams[i]->time_base;
          ctx->avoid_negative_ts = s->avoid_negative_ts;
 +        ctx->flags = s->flags;
  
-         ctx->pb = avio_alloc_context(os->iobuf, sizeof(os->iobuf), AVIO_FLAG_WRITE, os, NULL, dash_write, NULL);
-         if (!ctx->pb)
-             return AVERROR(ENOMEM);
+         if ((ret = avio_open_dyn_buf(&ctx->pb)) < 0)
 -            goto fail;
++            return ret;
  
          if (c->single_file) {
              if (c->single_file_name)
@@@ -902,12 -1002,10 +915,10 @@@ static int dash_flush(AVFormatContext *
                  ff_format_io_close(s, &os->out);
          }
  
-         start_pos = avio_tell(os->ctx->pb);
          if (!c->single_file) {
 -            dash_fill_tmpl_params(filename, sizeof(filename), c->media_seg_name, i, os->segment_index, os->bit_rate, os->start_pts);
 +            ff_dash_fill_tmpl_params(filename, sizeof(filename), c->media_seg_name, i, os->segment_index, os->bit_rate, os->start_pts);
              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), use_rename ? "%s.tmp" : "%s", full_path);
              ret = s->io_open(s, &os->out, temp_path, AVIO_FLAG_WRITE, NULL);
              if (ret < 0)
                  break;
              snprintf(full_path, sizeof(full_path), "%s%s", c->dirname, os->initfile);
          }
  
-         av_write_frame(os->ctx, NULL);
-         avio_flush(os->ctx->pb);
+         ret = flush_dynbuf(os, &range_length);
+         if (ret < 0)
+             break;
          os->packets_written = 0;
  
-         range_length = avio_tell(os->ctx->pb) - start_pos;
          if (c->single_file) {
-             find_index_range(s, full_path, start_pos, &index_length);
+             find_index_range(s, full_path, os->pos, &index_length);
          } else {
              ff_format_io_close(s, &os->out);
 -            ret = ff_rename(temp_path, full_path);
 -            if (ret < 0)
 -                break;
 +
 +            if (use_rename) {
 +                ret = avpriv_io_move(temp_path, full_path);
 +                if (ret < 0)
 +                    break;
 +            }
          }
  
          if (!os->bit_rate) {