Revision b62a33d0 libavformat/matroskaenc.c

View differences:

libavformat/matroskaenc.c
386 386
    return currentpos;
387 387
}
388 388

  
389
static int put_xiph_codecpriv(ByteIOContext *pb, AVCodecContext *codec)
389
static int put_xiph_codecpriv(AVFormatContext *s, ByteIOContext *pb, AVCodecContext *codec)
390 390
{
391 391
    uint8_t *header_start[3];
392 392
    int header_len[3];
......
400 400

  
401 401
    if (ff_split_xiph_headers(codec->extradata, codec->extradata_size,
402 402
                              first_header_size, header_start, header_len) < 0) {
403
        av_log(codec, AV_LOG_ERROR, "Extradata corrupt.\n");
403
        av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n");
404 404
        return -1;
405 405
    }
406 406

  
......
416 416

  
417 417
#define FLAC_STREAMINFO_SIZE 34
418 418

  
419
static int put_flac_codecpriv(ByteIOContext *pb, AVCodecContext *codec)
419
static int put_flac_codecpriv(AVFormatContext *s, ByteIOContext *pb, AVCodecContext *codec)
420 420
{
421 421
    // if the extradata_size is greater than FLAC_STREAMINFO_SIZE,
422 422
    // assume that it's in Matroska's format already
423 423
    if (codec->extradata_size < FLAC_STREAMINFO_SIZE) {
424
        av_log(codec, AV_LOG_ERROR, "Invalid FLAC extradata\n");
424
        av_log(s, AV_LOG_ERROR, "Invalid FLAC extradata\n");
425 425
        return -1;
426 426
    } else if (codec->extradata_size == FLAC_STREAMINFO_SIZE) {
427 427
        // only the streaminfo packet
428 428
        put_byte(pb, 0);
429 429
        put_xiph_size(pb, codec->extradata_size);
430
        av_log(codec, AV_LOG_ERROR, "Only one packet\n");
430
        av_log(s, AV_LOG_ERROR, "Only one packet\n");
431 431
    }
432 432
    put_buffer(pb, codec->extradata, codec->extradata_size);
433 433
    return 0;
434 434
}
435 435

  
436
static void get_aac_sample_rates(AVCodecContext *codec, int *sample_rate, int *output_sample_rate)
436
static void get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, int *sample_rate, int *output_sample_rate)
437 437
{
438 438
    static const int aac_sample_rates[] = {
439 439
        96000, 88200, 64000, 48000, 44100, 32000,
......
442 442
    int sri;
443 443

  
444 444
    if (codec->extradata_size < 2) {
445
        av_log(codec, AV_LOG_WARNING, "no AAC extradata, unable to determine samplerate\n");
445
        av_log(s, AV_LOG_WARNING, "no AAC extradata, unable to determine samplerate\n");
446 446
        return;
447 447
    }
448 448

  
449 449
    sri = ((codec->extradata[0] << 1) & 0xE) | (codec->extradata[1] >> 7);
450 450
    if (sri > 12) {
451
        av_log(codec, AV_LOG_WARNING, "AAC samplerate index out of bounds\n");
451
        av_log(s, AV_LOG_WARNING, "AAC samplerate index out of bounds\n");
452 452
        return;
453 453
    }
454 454
    *sample_rate = aac_sample_rates[sri];
......
457 457
    if (codec->extradata_size == 5) {
458 458
        sri = (codec->extradata[4] >> 3) & 0xF;
459 459
        if (sri > 12) {
460
            av_log(codec, AV_LOG_WARNING, "AAC output samplerate index out of bounds\n");
460
            av_log(s, AV_LOG_WARNING, "AAC output samplerate index out of bounds\n");
461 461
            return;
462 462
        }
463 463
        *output_sample_rate = aac_sample_rates[sri];
464 464
    }
465 465
}
466 466

  
467
static int mkv_write_codecprivate(ByteIOContext *pb, AVCodecContext *codec, int native_id)
467
static int mkv_write_codecprivate(AVFormatContext *s, ByteIOContext *pb, AVCodecContext *codec, int native_id)
468 468
{
469 469
    ByteIOContext dyn_cp;
470 470
    uint8_t *codecpriv;
......
474 474

  
475 475
    if (native_id) {
476 476
        if (codec->codec_id == CODEC_ID_VORBIS || codec->codec_id == CODEC_ID_THEORA)
477
            ret = put_xiph_codecpriv(&dyn_cp, codec);
477
            ret = put_xiph_codecpriv(s, &dyn_cp, codec);
478 478
        else if (codec->codec_id == CODEC_ID_FLAC)
479
            ret = put_flac_codecpriv(&dyn_cp, codec);
479
            ret = put_flac_codecpriv(s, &dyn_cp, codec);
480 480
        else if (codec->extradata_size)
481 481
            put_buffer(&dyn_cp, codec->extradata, codec->extradata_size);
482 482
    } else if (codec->codec_type == CODEC_TYPE_VIDEO) {
483 483
        if (!codec->codec_tag)
484 484
            codec->codec_tag = codec_get_tag(codec_bmp_tags, codec->codec_id);
485 485
        if (!codec->codec_tag) {
486
            av_log(codec, AV_LOG_ERROR, "no bmp codec id found");
486
            av_log(s, AV_LOG_ERROR, "no bmp codec id found");
487 487
            ret = -1;
488 488
        }
489 489

  
......
493 493
        if (!codec->codec_tag)
494 494
            codec->codec_tag = codec_get_tag(codec_wav_tags, codec->codec_id);
495 495
        if (!codec->codec_tag) {
496
            av_log(codec, AV_LOG_ERROR, "no wav codec id found");
496
            av_log(s, AV_LOG_ERROR, "no wav codec id found");
497 497
            ret = -1;
498 498
        }
499 499

  
......
531 531
            bit_depth = av_get_bits_per_sample_format(codec->sample_fmt);
532 532

  
533 533
        if (codec->codec_id == CODEC_ID_AAC)
534
            get_aac_sample_rates(codec, &sample_rate, &output_sample_rate);
534
            get_aac_sample_rates(s, codec, &sample_rate, &output_sample_rate);
535 535

  
536 536
        track = start_ebml_master(pb, MATROSKA_ID_TRACKENTRY, 0);
537 537
        put_ebml_uint (pb, MATROSKA_ID_TRACKNUMBER     , i + 1);
......
598 598
                av_log(s, AV_LOG_ERROR, "Only audio, video, and subtitles are supported for Matroska.");
599 599
                break;
600 600
        }
601
        ret = mkv_write_codecprivate(pb, codec, native_id);
601
        ret = mkv_write_codecprivate(s, pb, codec, native_id);
602 602
        if (ret < 0) return ret;
603 603

  
604 604
        end_ebml_master(pb, track);

Also available in: Unified diff