this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update CoreAudio for new libavcodec

Some previously deprecated functions have now been removed entirely. Note that this updated implementation has NOT been tested.

+72 -10
+1 -1
src/CoreAudio/AFAVFormatComponent/AudioFileFormatGeneric.cpp
··· 81 81 82 82 UncertainResult AudioFileFormatGeneric::FileDataIsThisFormat(UInt32 inDataByteSize, const void* inData) 83 83 { 84 - AVInputFormat* fmt = av_find_input_format(m_avformatShortName); 84 + const AVInputFormat* fmt = av_find_input_format(m_avformatShortName); 85 85 if (!fmt) 86 86 return false; 87 87
+69 -7
src/CoreAudio/AudioToolbox/AudioConverterImpl.cpp
··· 28 28 29 29 extern "C" { 30 30 #include <libavcodec/avcodec.h> 31 + #include <libavcodec/codec.h> 31 32 #include <libavutil/opt.h> 32 33 #include <libavutil/mem.h> 33 34 } ··· 35 36 static constexpr int ENCODER_FRAME_SAMPLES = 1024; 36 37 37 38 // http://blinkingblip.wordpress.com/ 38 - 39 - __attribute__((constructor)) static void init_avcodec() 40 - { 41 - avcodec_register_all(); 42 - } 43 39 44 40 static void throwFFMPEGError(int errnum, const char* function) 45 41 { ··· 75 71 76 72 // TODO: non-interleaved audio 77 73 78 - AVCodec *codecIn, *codecOut; 74 + const AVCodec *codecIn, *codecOut; 79 75 AVCodecContext *cIn; 80 76 AVCodecContext *cOut; 81 77 enum AVCodecID idIn, idOut; ··· 385 381 if (m_avpktOutUsed >= m_avpktOut.size) 386 382 { 387 383 m_avpktOutUsed = 0; 388 - av_free_packet(&m_avpktOut); 384 + av_packet_unref(&m_avpktOut); 389 385 } 390 386 } 391 387 else ··· 450 446 return false; 451 447 } 452 448 449 + #if 0 453 450 err = avcodec_decode_audio4(m_decoder, srcaudio, &gotFrame, &m_avpkt); 454 451 if (err < 0) 455 452 throwFFMPEGError(err, "avcodec_decode_audio4()"); 456 453 457 454 m_avpkt.size -= err; 458 455 m_avpkt.data += err; 456 + #else 457 + #warning TODO: test this new avcodec decoder code 458 + err = avcodec_send_packet(m_decoder, &m_avpkt); 459 + 460 + if (err < 0) { 461 + if (err == AVERROR(EAGAIN)) { 462 + // we need to consume frames before sending more packets 463 + err = 0; 464 + } 465 + if (err < 0) { 466 + throwFFMPEGError(err, "avcodec_send_packet()"); 467 + } 468 + } else { 469 + // on success, the data packet has been consumed entirely 470 + m_avpkt.data += m_avpkt.size; 471 + m_avpkt.size = 0; 472 + } 473 + 474 + err = avcodec_receive_frame(m_decoder, srcaudio); 475 + 476 + if (err < 0) { 477 + gotFrame = false; 478 + if (err == AVERROR(EAGAIN)) { 479 + // we need to send more packets before consuming a frame 480 + err = 0; 481 + } 482 + if (err < 0) { 483 + throwFFMPEGError(err, "avcodec_receive_frame()"); 484 + } 485 + } else { 486 + // on success, we have a valid frame 487 + gotFrame = true; 488 + } 489 + #endif 459 490 460 491 if (gotFrame) 461 492 { ··· 532 563 if (err < 0) 533 564 throwFFMPEGError(err, "avcodec_fill_audio_frame()"); 534 565 566 + #if 0 535 567 err = avcodec_encode_audio2(m_encoder, &m_avpktOut, m_audioFrame, &gotFrame); 536 568 if (err < 0) 537 569 throwFFMPEGError(err, "avcodec_encode_audio2()"); 570 + #else 571 + #warning TODO: test this new avcodec encoder code 572 + err = avcodec_send_frame(m_encoder, m_audioFrame); 573 + 574 + if (err < 0) { 575 + if (err == AVERROR(EAGAIN)) { 576 + // we need to consume more packets before sending 577 + // TODO: handle this case properly. 578 + // for now, we just proceed to throw an error to avoid dropping a frame 579 + } 580 + if (err < 0) { 581 + throwFFMPEGError(err, "avcodec_send_frame()"); 582 + } 583 + } 584 + 585 + err = avcodec_receive_packet(m_encoder, &m_avpkt); 586 + 587 + if (err < 0) { 588 + gotFrame = false; 589 + if (err == AVERROR(EAGAIN)) { 590 + // we need to send more frames before consuming a packet 591 + err = 0; 592 + } 593 + if (err < 0) { 594 + throwFFMPEGError(err, "avcodec_receive_packet()"); 595 + } 596 + } else { 597 + gotFrame = true; 598 + } 599 + #endif 538 600 539 601 m_audioFramePrebuf.consume(requiredBytes); 540 602
+2 -2
src/CoreAudio/AudioToolbox/AudioConverterImpl.h
··· 56 56 SwrContext* m_resampler = nullptr; 57 57 UInt32 m_outBitRate = 128000; 58 58 bool m_encoderInitialized = false; 59 - AVCodec* m_codecIn = nullptr; 60 - AVCodec* m_codecOut = nullptr; 59 + const AVCodec* m_codecIn = nullptr; 60 + const AVCodec* m_codecOut = nullptr; 61 61 62 62 #ifdef DEBUG_AUDIOCONVERTER 63 63 std::ofstream m_resamplerInput, m_resamplerOutput, m_encoderOutput;