| 236 | } |
| 237 | |
| 238 | static int segment_start(AVFormatContext *s, int write_header) |
| 239 | { |
| 240 | SegmentContext *seg = s->priv_data; |
| 241 | AVFormatContext *oc = seg->avf; |
| 242 | int err = 0; |
| 243 | |
| 244 | if (write_header) { |
| 245 | avformat_free_context(oc); |
| 246 | seg->avf = NULL; |
| 247 | if ((err = segment_mux_init(s)) < 0) |
| 248 | return err; |
| 249 | oc = seg->avf; |
| 250 | } |
| 251 | |
| 252 | seg->segment_idx++; |
| 253 | if ((seg->segment_idx_wrap) && (seg->segment_idx % seg->segment_idx_wrap == 0)) |
| 254 | seg->segment_idx_wrap_nb++; |
| 255 | |
| 256 | if ((err = set_segment_filename(s)) < 0) |
| 257 | return err; |
| 258 | |
| 259 | if ((err = s->io_open(s, &oc->pb, oc->url, AVIO_FLAG_WRITE, NULL)) < 0) { |
| 260 | av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", oc->url); |
| 261 | return err; |
| 262 | } |
| 263 | if (!seg->individual_header_trailer) |
| 264 | oc->pb->seekable = 0; |
| 265 | |
| 266 | if (oc->oformat->priv_class && oc->priv_data) |
| 267 | av_opt_set(oc->priv_data, "mpegts_flags", "+resend_headers", 0); |
| 268 | |
| 269 | if (write_header) { |
| 270 | AVDictionary *options = NULL; |
| 271 | av_dict_copy(&options, seg->format_options, 0); |
| 272 | av_dict_set(&options, "fflags", "-autobsf", 0); |
| 273 | err = avformat_write_header(oc, &options); |
| 274 | av_dict_free(&options); |
| 275 | if (err < 0) |
| 276 | return err; |
| 277 | } |
| 278 | |
| 279 | seg->segment_frame_count = 0; |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | static int segment_list_open(AVFormatContext *s) |
| 284 | { |
no test coverage detected