| 387 | } |
| 388 | |
| 389 | static int opt_map_channel(void *optctx, const char *opt, const char *arg) |
| 390 | { |
| 391 | OptionsContext *o = optctx; |
| 392 | int n; |
| 393 | AVStream *st; |
| 394 | AudioChannelMap *m; |
| 395 | |
| 396 | GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps); |
| 397 | m = &o->audio_channel_maps[o->nb_audio_channel_maps - 1]; |
| 398 | |
| 399 | /* muted channel syntax */ |
| 400 | n = sscanf(arg, "%d:%d.%d", &m->channel_idx, &m->ofile_idx, &m->ostream_idx); |
| 401 | if ((n == 1 || n == 3) && m->channel_idx == -1) { |
| 402 | m->file_idx = m->stream_idx = -1; |
| 403 | if (n == 1) |
| 404 | m->ofile_idx = m->ostream_idx = -1; |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | /* normal syntax */ |
| 409 | n = sscanf(arg, "%d.%d.%d:%d.%d", |
| 410 | &m->file_idx, &m->stream_idx, &m->channel_idx, |
| 411 | &m->ofile_idx, &m->ostream_idx); |
| 412 | |
| 413 | if (n != 3 && n != 5) { |
| 414 | av_log(NULL, AV_LOG_FATAL, "Syntax error, mapchan usage: " |
| 415 | "[file.stream.channel|-1][:syncfile:syncstream]\n"); |
| 416 | exit_program(1); |
| 417 | } |
| 418 | |
| 419 | if (n != 5) // only file.stream.channel specified |
| 420 | m->ofile_idx = m->ostream_idx = -1; |
| 421 | |
| 422 | /* check input */ |
| 423 | if (m->file_idx < 0 || m->file_idx >= nb_input_files) { |
| 424 | av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file index: %d\n", |
| 425 | m->file_idx); |
| 426 | exit_program(1); |
| 427 | } |
| 428 | if (m->stream_idx < 0 || |
| 429 | m->stream_idx >= input_files[m->file_idx]->nb_streams) { |
| 430 | av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file stream index #%d.%d\n", |
| 431 | m->file_idx, m->stream_idx); |
| 432 | exit_program(1); |
| 433 | } |
| 434 | st = input_files[m->file_idx]->ctx->streams[m->stream_idx]; |
| 435 | if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) { |
| 436 | av_log(NULL, AV_LOG_FATAL, "mapchan: stream #%d.%d is not an audio stream.\n", |
| 437 | m->file_idx, m->stream_idx); |
| 438 | exit_program(1); |
| 439 | } |
| 440 | if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->channels) { |
| 441 | av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n", |
| 442 | m->file_idx, m->stream_idx, m->channel_idx); |
| 443 | exit_program(1); |
| 444 | } |
| 445 | return 0; |
| 446 | } |
nothing calls this directly
no test coverage detected