| 281 | } |
| 282 | |
| 283 | static int ism_write_header(AVFormatContext *s) |
| 284 | { |
| 285 | SmoothStreamingContext *c = s->priv_data; |
| 286 | int ret = 0, i; |
| 287 | |
| 288 | if (mkdir(s->url, 0777) == -1 && errno != EEXIST) { |
| 289 | av_log(s, AV_LOG_ERROR, "mkdir failed\n"); |
| 290 | return AVERROR(errno); |
| 291 | } |
| 292 | |
| 293 | |
| 294 | c->streams = av_calloc(s->nb_streams, sizeof(*c->streams)); |
| 295 | if (!c->streams) { |
| 296 | return AVERROR(ENOMEM); |
| 297 | } |
| 298 | |
| 299 | for (i = 0; i < s->nb_streams; i++) { |
| 300 | OutputStream *os = &c->streams[i]; |
| 301 | AVFormatContext *ctx; |
| 302 | AVStream *st; |
| 303 | AVDictionary *opts = NULL; |
| 304 | |
| 305 | if (!s->streams[i]->codecpar->bit_rate) { |
| 306 | av_log(s, AV_LOG_WARNING, "No bit rate set for stream %d\n", i); |
| 307 | // create a tmp name for the directory of fragments |
| 308 | snprintf(os->dirname, sizeof(os->dirname), "%s/QualityLevels(Tmp_%d)", s->url, i); |
| 309 | } else { |
| 310 | snprintf(os->dirname, sizeof(os->dirname), "%s/QualityLevels(%"PRId64")", s->url, s->streams[i]->codecpar->bit_rate); |
| 311 | } |
| 312 | |
| 313 | if (mkdir(os->dirname, 0777) == -1 && errno != EEXIST) { |
| 314 | av_log(s, AV_LOG_ERROR, "mkdir failed\n"); |
| 315 | return AVERROR(errno); |
| 316 | } |
| 317 | |
| 318 | os->ctx = ctx = avformat_alloc_context(); |
| 319 | if (!ctx) { |
| 320 | return AVERROR(ENOMEM); |
| 321 | } |
| 322 | if ((ret = ff_copy_whiteblacklists(ctx, s)) < 0) |
| 323 | return ret; |
| 324 | EXTERN const FFOutputFormat ff_ismv_muxer; |
| 325 | ctx->oformat = &ff_ismv_muxer.p; |
| 326 | ctx->interrupt_callback = s->interrupt_callback; |
| 327 | |
| 328 | if (!(st = avformat_new_stream(ctx, NULL))) { |
| 329 | return AVERROR(ENOMEM); |
| 330 | } |
| 331 | if ((ret = avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar)) < 0) { |
| 332 | return ret; |
| 333 | } |
| 334 | st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; |
| 335 | st->time_base = s->streams[i]->time_base; |
| 336 | |
| 337 | ctx->pb = avio_alloc_context(os->iobuf, sizeof(os->iobuf), 1, os, NULL, ism_write, ism_seek); |
| 338 | if (!ctx->pb) { |
| 339 | return AVERROR(ENOMEM); |
| 340 | } |
nothing calls this directly
no test coverage detected