Ticket #13186: 003_avcodec_encode_audio2.patch

File 003_avcodec_encode_audio2.patch, 5.4 KB (added by Peter Bennett, 6 years ago)

Patch 003 - avcodec_encode_audio2

  • mythtv/libs/libmyth/audio/audiooutputdigitalencoder.cpp

    diff --git a/mythtv/libs/libmyth/audio/audiooutputdigitalencoder.cpp b/mythtv/libs/libmyth/audio/audiooutputdigitalencoder.cpp
    index e902732..bd6dbcd 100644
    a b size_t AudioOutputDigitalEncoder::Encode(void *buf, int len, AudioFormat format) 
    239239        av_init_packet(&pkt);
    240240        pkt.data          = NULL;
    241241        pkt.size          = 0;
    242         int got_packet    = 0;
     242        bool got_packet   = false;
    243243
    244244        AudioOutputUtil::DeinterleaveSamples(
    245245            FORMAT_S16, channels,
    size_t AudioOutputDigitalEncoder::Encode(void *buf, int len, AudioFormat format) 
    247247            (uint8_t*)(in + i * samples_per_frame),
    248248            size_channel * channels);
    249249
    250         int ret           = avcodec_encode_audio2(av_context, &pkt, m_frame,
    251                                                   &got_packet);
     250        //  SUGGESTION
     251        //  Now that avcodec_encode_audio2 is deprecated and replaced
     252        //  by 2 calls, this could be optimized
     253        //  into separate routines or separate threads.
     254        int ret = avcodec_receive_packet(av_context, &pkt);
     255        if (ret == 0)
     256            got_packet = true;
     257        if (ret == AVERROR(EAGAIN))
     258            ret = 0;
     259        if (ret == 0)
     260            ret = avcodec_send_frame(av_context, m_frame);
     261        // if ret from avcodec_send_frame is AVERROR(EAGAIN) then
     262        // there are 2 packets to be received while only 1 frame to be
     263        // sent. The code does not cater for this. Hopefully it will not happen.
    252264
    253265        if (ret < 0)
    254266        {
    255             LOG(VB_AUDIO, LOG_ERR, LOC + "AC-3 encode error");
     267            char error[AV_ERROR_MAX_STRING_SIZE];
     268            LOG(VB_GENERAL, LOG_ERR, LOC +
     269                QString("audio encode error: %1 (%2)")
     270                .arg(av_make_error_string(error, sizeof(error), ret))
     271                .arg(got_packet));
    256272            return ret;
    257273        }
    258274        i++;
  • mythtv/libs/libmythtv/avformatwriter.cpp

    diff --git a/mythtv/libs/libmythtv/avformatwriter.cpp b/mythtv/libs/libmythtv/avformatwriter.cpp
    index e34dc2d..a3282be 100644
    a b int AVFormatWriter::WriteAudioFrame(unsigned char *buf, int /*fnum*/, long long 
    323323    bswap_16_buf((short int*) buf, m_audioFrameSize, m_audioChannels);
    324324#endif
    325325
    326     int got_packet = 0;
     326    bool got_packet = false;
    327327    int ret = 0;
    328328    int samples_per_avframe  = m_audioFrameSize * m_audioChannels;
    329329    int sampleSizeIn   = AudioOutputSettings::SampleSize(FORMAT_S16);
    int AVFormatWriter::WriteAudioFrame(unsigned char *buf, int /*fnum*/, long long 
    370370
    371371    {
    372372        QMutexLocker locker(avcodeclock);
    373         ret = avcodec_encode_audio2(m_audioStream->codec, &pkt,
    374                                     m_audPicture, &got_packet);
     373        //  SUGGESTION
     374        //  Now that avcodec_encode_audio2 is deprecated and replaced
     375        //  by 2 calls, this could be optimized
     376        //  into separate routines or separate threads.
     377        got_packet = false;
     378        ret = avcodec_receive_packet(m_audioStream->codec, &pkt);
     379        if (ret == 0)
     380            got_packet = true;
     381        if (ret == AVERROR(EAGAIN))
     382            ret = 0;
     383        if (ret == 0)
     384            ret = avcodec_send_frame(m_audioStream->codec, m_audPicture);
     385        // if ret from avcodec_send_frame is AVERROR(EAGAIN) then
     386        // there are 2 packets to be received while only 1 frame to be
     387        // sent. The code does not cater for this. Hopefully it will not happen.
    375388    }
    376389
    377390    if (ret < 0)
    378391    {
    379         LOG(VB_RECORD, LOG_ERR, "avcodec_encode_audio2() failed");
     392        char error[AV_ERROR_MAX_STRING_SIZE];
     393        LOG(VB_GENERAL, LOG_ERR, LOC +
     394            QString("audio encode error: %1 (%2)")
     395            .arg(av_make_error_string(error, sizeof(error), ret))
     396            .arg(got_packet));
    380397        return ret;
    381398    }
    382399
  • mythtv/programs/mythtranscode/external/replex/replex.c

    diff --git a/mythtv/programs/mythtranscode/external/replex/replex.c b/mythtv/programs/mythtranscode/external/replex/replex.c
    index d94af07..f5821f7 100644
    a b static int avcodec_encode_audio(AVCodecContext *avctx, 
    8888{
    8989    AVPacket pkt;
    9090    AVFrame *frame;
    91     int ret, samples_size, got_packet;
     91    int ret, samples_size;
    9292
    9393    av_init_packet(&pkt);
    9494    pkt.data = buf;
    static int avcodec_encode_audio(AVCodecContext *avctx, 
    139139        frame = NULL;
    140140    }
    141141
    142     got_packet = 0;
    143     ret = avcodec_encode_audio2(avctx, &pkt, frame, &got_packet);
     142    //  SUGGESTION
     143    //  Now that avcodec_encode_audio2 is deprecated and replaced
     144    //  by 2 calls, this could be optimized
     145    //  into separate routines or separate threads.
     146    ret = avcodec_receive_packet(avctx, &pkt);
     147    if (ret != 0)
     148        pkt.size=0;
     149    if (ret == AVERROR(EAGAIN))
     150        ret = 0;
     151    if (ret == 0)
     152        ret = avcodec_send_frame(avctx, frame);
     153
     154    if (ret < 0)
     155    {
     156        char error[AV_ERROR_MAX_STRING_SIZE+25];
     157                strcpy(error,"audio encode error: ");
     158                strcat(error, av_make_error_string(error, sizeof(error), ret));
     159        LOG(VB_GENERAL, LOG_ERR, error);
     160    }
    144161
    145162    /* free any side data since we cannot return it */
    146163    av_packet_free_side_data(&pkt);