Ticket #13186: 006_more_avstream_codec.patch

File 006_more_avstream_codec.patch, 18.6 KB (added by Peter Bennett, 8 years ago)

Patch 006 - deprecated AVStream::codec, avcodec_close, avcodec_get_context_defaults3

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

    diff --git a/mythtv/libs/libmyth/audio/audiooutputdigitalencoder.cpp b/mythtv/libs/libmyth/audio/audiooutputdigitalencoder.cpp
    index bd6dbcd..0a60141 100644
    a b AudioOutputDigitalEncoder::~AudioOutputDigitalEncoder() 
    6363void AudioOutputDigitalEncoder::Reset(void)
    6464{
    6565    if (av_context)
    66     {
    67         avcodec_close(av_context);
    68         av_freep(&av_context);
    69     }
     66        avcodec_free_context(&av_context);
     67
    7068    av_frame_free(&m_frame);
    7169
    7270    delete m_spdifenc;
    bool AudioOutputDigitalEncoder::Init( 
    125123    }
    126124
    127125    av_context                 = avcodec_alloc_context3(codec);
    128     avcodec_get_context_defaults3(av_context, codec);
    129126
    130127    av_context->bit_rate       = bitrate;
    131128    av_context->sample_rate    = samplerate;
  • mythtv/libs/libmythtv/AirPlay/mythraopconnection.cpp

    diff --git a/mythtv/libs/libmythtv/AirPlay/mythraopconnection.cpp b/mythtv/libs/libmythtv/AirPlay/mythraopconnection.cpp
    index f91d71c..861204f 100644
    a b void MythRAOPConnection::DestroyDecoder(void) 
    16861686{
    16871687    if (m_codeccontext)
    16881688    {
    1689         avcodec_close(m_codeccontext);
    1690         av_free(m_codeccontext);
     1689        avcodec_free_context(&m_codeccontext);
    16911690    }
    16921691    m_codec = NULL;
    1693     m_codeccontext = NULL;
    16941692}
    16951693
    16961694bool MythRAOPConnection::OpenAudioDevice(void)
  • mythtv/libs/libmythtv/avformatwriter.cpp

    diff --git a/mythtv/libs/libmythtv/avformatwriter.cpp b/mythtv/libs/libmythtv/avformatwriter.cpp
    index 7540fad..ed3ba0a 100644
    a b int AVFormatWriter::WriteVideoFrame(VideoFrame *frame) 
    256256    av_init_packet(&pkt);
    257257    pkt.data = NULL;
    258258    pkt.size = 0;
     259    AVCodecContext *avctx = gCodecMap->getCodecContext(m_videoStream);
    259260    {
    260261        QMutexLocker locker(avcodeclock);
    261         ret = avcodec_encode_video2(m_videoStream->codec, &pkt,
     262        ret = avcodec_encode_video2(avctx, &pkt,
    262263                                    m_picture, &got_pkt);
    263264    }
    264265
    int AVFormatWriter::WriteAudioFrame(unsigned char *buf, int /*fnum*/, long long 
    326327
    327328    bool got_packet = false;
    328329    int ret = 0;
     330    AVCodecContext *avctx = gCodecMap->getCodecContext(m_audioStream);
    329331    int samples_per_avframe  = m_audioFrameSize * m_audioChannels;
    330332    int sampleSizeIn   = AudioOutputSettings::SampleSize(FORMAT_S16);
    331333    AudioFormat format =
    332         AudioOutputSettings::AVSampleFormatToFormat(m_audioStream->codec->sample_fmt);
     334        AudioOutputSettings::AVSampleFormatToFormat(avctx->sample_fmt);
    333335    int sampleSizeOut  = AudioOutputSettings::SampleSize(format);
    334336
    335337    AVPacket pkt;
    int AVFormatWriter::WriteAudioFrame(unsigned char *buf, int /*fnum*/, long long 
    337339    pkt.data          = NULL;
    338340    pkt.size          = 0;
    339341
    340     if (av_get_packed_sample_fmt(m_audioStream->codec->sample_fmt) == AV_SAMPLE_FMT_FLT)
     342    if (av_get_packed_sample_fmt(avctx->sample_fmt) == AV_SAMPLE_FMT_FLT)
    341343    {
    342344        AudioOutputUtil::toFloat(FORMAT_S16, (void *)m_audioInBuf, (void *)buf,
    343345                                 samples_per_avframe * sampleSizeIn);
    344346        buf = m_audioInBuf;
    345347    }
    346     if (av_sample_fmt_is_planar(m_audioStream->codec->sample_fmt))
     348    if (av_sample_fmt_is_planar(avctx->sample_fmt))
    347349    {
    348350        AudioOutputUtil::DeinterleaveSamples(format,
    349351                                             m_audioChannels,
    int AVFormatWriter::WriteAudioFrame(unsigned char *buf, int /*fnum*/, long long 
    364366
    365367    m_audPicture->linesize[0] = m_audioFrameSize;
    366368    m_audPicture->nb_samples = m_audioFrameSize;
    367     m_audPicture->format = m_audioStream->codec->sample_fmt;
     369    m_audPicture->format = avctx->sample_fmt;
    368370    m_audPicture->extended_data = m_audPicture->data;
    369371
    370372    m_bufferedAudioFrameTimes.push_back(timecode);
    int AVFormatWriter::WriteAudioFrame(unsigned char *buf, int /*fnum*/, long long 
    376378        //  by 2 calls, this could be optimized
    377379        //  into separate routines or separate threads.
    378380        got_packet = false;
    379         ret = avcodec_receive_packet(m_audioStream->codec, &pkt);
     381        ret = avcodec_receive_packet(avctx, &pkt);
    380382        if (ret == 0)
    381383            got_packet = true;
    382384        if (ret == AVERROR(EAGAIN))
    383385            ret = 0;
    384386        if (ret == 0)
    385             ret = avcodec_send_frame(m_audioStream->codec, m_audPicture);
     387            ret = avcodec_send_frame(avctx, m_audPicture);
    386388        // if ret from avcodec_send_frame is AVERROR(EAGAIN) then
    387389        // there are 2 packets to be received while only 1 frame to be
    388390        // sent. The code does not cater for this. Hopefully it will not happen.
    AVStream* AVFormatWriter::AddVideoStream(void) 
    466468    }
    467469    st->id = 0;
    468470
    469     c = st->codec;
    470471
    471472    codec = avcodec_find_encoder(m_ctx->oformat->video_codec);
    472473    if (!codec)
    AVStream* AVFormatWriter::AddVideoStream(void) 
    476477        return NULL;
    477478    }
    478479
    479     avcodec_get_context_defaults3(c, codec);
     480    gCodecMap->freeCodecContext(st);
     481    c = gCodecMap->getCodecContext(st, codec);
    480482
    481483    c->codec                      = codec;
    482484    c->codec_id                   = m_ctx->oformat->video_codec;
    bool AVFormatWriter::OpenVideo(void) 
    576578{
    577579    AVCodecContext *c;
    578580
    579     c = m_videoStream->codec;
     581    c = gCodecMap->getCodecContext(m_videoStream);
    580582
    581583    if (!m_width || !m_height)
    582584        return false;
    AVStream* AVFormatWriter::AddAudioStream(void) 
    620622    }
    621623    st->id = 1;
    622624
    623     c = st->codec;
     625    c = gCodecMap->getCodecContext(st, NULL, true);
     626
    624627    c->codec_id     = m_ctx->oformat->audio_codec;
    625628    c->codec_type   = AVMEDIA_TYPE_AUDIO;
    626629    c->bit_rate     = m_audioBitrate;
    bool AVFormatWriter::OpenAudio(void) 
    664667    AVCodecContext *c;
    665668    AVCodec *codec;
    666669
    667     c = m_audioStream->codec;
     670    c = gCodecMap->getCodecContext(m_audioStream);
    668671
    669672    c->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
    670673
  • mythtv/libs/libmythtv/mhi.cpp

    diff --git a/mythtv/libs/libmythtv/mhi.cpp b/mythtv/libs/libmythtv/mhi.cpp
    index eba6e34..b7605d2 100644
    a b void MHIBitmap::CreateFromMPEG(const unsigned char *data, int length) 
    19701970Close:
    19711971    pkt.data = buff;
    19721972    av_packet_unref(&pkt);
    1973     avcodec_close(c);
    1974     av_free(c);
     1973    avcodec_free_context(&c);
    19751974}
    19761975
    19771976// Scale the bitmap.  Only used for image derived from MPEG I-frames.
  • mythtv/libs/libmythtv/mythavutil.cpp

    diff --git a/mythtv/libs/libmythtv/mythavutil.cpp b/mythtv/libs/libmythtv/mythavutil.cpp
    index 7706bd1..aabf020 100644
    a b MythCodecMap::~MythCodecMap() 
    389389    freeAllCodecContexts();
    390390}
    391391
    392 AVCodecContext *MythCodecMap::getCodecContext(const AVStream *stream, const AVCodec *pCodec)
     392AVCodecContext *MythCodecMap::getCodecContext(const AVStream *stream,
     393    const AVCodec *pCodec, bool nullCodec)
    393394{
    394395    QMutexLocker lock(&mapLock);
    395396    AVCodecContext *avctx = streamMap.value(stream, NULL);
    AVCodecContext *MythCodecMap::getCodecContext(const AVStream *stream, const AVCo 
    397398    {
    398399        if (stream == NULL || stream->codecpar == NULL)
    399400            return NULL;
    400         if (!pCodec)
    401             pCodec = avcodec_find_decoder(stream->codecpar->codec_id);
    402         if (!pCodec)
     401        if (nullCodec)
     402            pCodec = NULL;
     403        else
    403404        {
    404             LOG(VB_GENERAL, LOG_WARNING,
    405                 QString("avcodec_find_decoder fail for %1").arg(stream->codecpar->codec_id));
    406             return NULL;
     405            if (!pCodec)
     406                pCodec = avcodec_find_decoder(stream->codecpar->codec_id);
     407            if (!pCodec)
     408            {
     409                LOG(VB_GENERAL, LOG_WARNING,
     410                    QString("avcodec_find_decoder fail for %1").arg(stream->codecpar->codec_id));
     411                return NULL;
     412            }
    407413        }
    408414        avctx = avcodec_alloc_context3(pCodec);
    409         if (avcodec_parameters_to_context(avctx, stream->codecpar) != NULL)
     415        if (avcodec_parameters_to_context(avctx, stream->codecpar) < 0)
    410416            avcodec_free_context(&avctx);
    411417        if (avctx)
    412418        {
  • mythtv/libs/libmythtv/mythavutil.h

    diff --git a/mythtv/libs/libmythtv/mythavutil.h b/mythtv/libs/libmythtv/mythavutil.h
    index cd57361..3e16df0 100644
    a b class MythCodecMap 
    9292    MythCodecMap();
    9393    ~MythCodecMap();
    9494    static MythCodecMap *getInstance();
    95     AVCodecContext *getCodecContext(const AVStream*,  const AVCodec *pCodec = NULL);
     95    AVCodecContext *getCodecContext(const AVStream*,
     96        const AVCodec *pCodec = NULL, bool nullCodec = false);
    9697    AVCodecContext *hasCodecContext(const AVStream*);
    9798    void freeCodecContext(const AVStream*);
    9899    void freeAllCodecContexts();
  • mythtv/libs/libmythtv/nuppeldecoder.cpp

    diff --git a/mythtv/libs/libmythtv/nuppeldecoder.cpp b/mythtv/libs/libmythtv/nuppeldecoder.cpp
    index 010b144..9ecd237 100644
    a b bool NuppelDecoder::InitAVCodecVideo(int codec) 
    702702        directrendering = true;
    703703
    704704    if (mpa_vidctx)
    705         av_free(mpa_vidctx);
     705        avcodec_free_context(&mpa_vidctx);
    706706
    707707    mpa_vidctx = avcodec_alloc_context3(NULL);
    708708
    void NuppelDecoder::CloseAVCodecVideo(void) 
    742742{
    743743    QMutexLocker locker(avcodeclock);
    744744
    745     if (mpa_vidcodec)
    746     {
    747         avcodec_close(mpa_vidctx);
    748 
    749         if (mpa_vidctx)
    750         {
    751             av_free(mpa_vidctx);
    752             mpa_vidctx = NULL;
    753         }
    754     }
     745    if (mpa_vidcodec && mpa_vidctx)
     746        avcodec_free_context(&mpa_vidctx);
    755747}
    756748
    757749bool NuppelDecoder::InitAVCodecAudio(int codec)
    bool NuppelDecoder::InitAVCodecAudio(int codec) 
    781773    }
    782774
    783775    if (mpa_audctx)
    784         av_free(mpa_audctx);
     776        avcodec_free_context(&mpa_audctx);
    785777
    786778    mpa_audctx = avcodec_alloc_context3(NULL);
    787779
    void NuppelDecoder::CloseAVCodecAudio(void) 
    802794{
    803795    QMutexLocker locker(avcodeclock);
    804796
    805     if (mpa_audcodec)
    806     {
    807         avcodec_close(mpa_audctx);
    808 
    809         if (mpa_audctx)
    810         {
    811             av_free(mpa_audctx);
    812             mpa_audctx = NULL;
    813         }
    814     }
     797    if (mpa_audcodec && mpa_audctx)
     798        avcodec_free_context(&mpa_audctx);
    815799}
    816800
    817801static void CopyToVideo(unsigned char *buf, int video_width,
  • mythtv/libs/libmythtv/privatedecoder_crystalhd.cpp

    diff --git a/mythtv/libs/libmythtv/privatedecoder_crystalhd.cpp b/mythtv/libs/libmythtv/privatedecoder_crystalhd.cpp
    index 6c8841d..91f7a6e 100644
    a b  
    11#include "privatedecoder_crystalhd.h"
    22#include "mythlogging.h"
     3#include "mythavutil.h"
    34#include "fourcc.h"
    45#include "unistd.h"
    56
    bool PrivateDecoderCrystalHD::HasBufferedFrames(void) 
    424425int PrivateDecoderCrystalHD::ProcessPacket(AVStream *stream, AVPacket *pkt)
    425426{
    426427    int result = -1;
    427     AVCodecContext *avctx = stream->codec;
     428    AVCodecContext *avctx = gCodecMap->getCodecContext(stream);
    428429    if (!avctx)
    429430        return result;
    430431
    int PrivateDecoderCrystalHD::GetFrame(AVStream *stream, 
    516517    if (!stream || !m_device || !picture)
    517518        return result;
    518519
    519     AVCodecContext *avctx = stream->codec;
     520    AVCodecContext *avctx = gCodecMap->getCodecContext(stream);
     521
    520522    if (!avctx || !StartFetcherThread())
    521523        return result;
    522524
  • mythtv/libs/libmythtv/privatedecoder_vda.cpp

    diff --git a/mythtv/libs/libmythtv/privatedecoder_vda.cpp b/mythtv/libs/libmythtv/privatedecoder_vda.cpp
    index f98a2d5..21a5656 100644
    a b  
    66#define ERR QString("VDADec error: ")
    77
    88#include "mythframe.h"
     9#include "mythavutil.h"
    910#include "util-osx-cocoa.h"
    1011#include "privatedecoder_vda.h"
    1112#include "util-osx.h"
    int PrivateDecoderVDA::GetFrame(AVStream *stream, 
    550551    if (!m_lib || !stream)
    551552        return result;
    552553
    553     AVCodecContext *avctx = stream->codec;
     554    AVCodecContext *avctx = gCodecMap->getCodecContext(stream);
    554555    if (!avctx)
    555556        return result;
    556557
  • mythtv/libs/libmythtv/recorders/NuppelVideoRecorder.cpp

    diff --git a/mythtv/libs/libmythtv/recorders/NuppelVideoRecorder.cpp b/mythtv/libs/libmythtv/recorders/NuppelVideoRecorder.cpp
    index c8b2e80..cf9daf8 100644
    a b NuppelVideoRecorder::~NuppelVideoRecorder(void) 
    270270    if (mpa_vidcodec)
    271271    {
    272272        QMutexLocker locker(avcodeclock);
    273         avcodec_close(mpa_vidctx);
     273        avcodec_free_context(&mpa_vidctx);
    274274    }
    275275
    276     if (mpa_vidctx)
    277         av_free(mpa_vidctx);
    278     mpa_vidctx = NULL;
    279 
    280276    if (videoFilters)
    281277        delete videoFilters;
    282278    if (FiltMan)
    bool NuppelVideoRecorder::SetupAVCodecVideo(void) 
    525521    if (mpa_vidcodec)
    526522    {
    527523        QMutexLocker locker(avcodeclock);
    528         avcodec_close(mpa_vidctx);
     524        avcodec_free_context(&mpa_vidctx);
    529525    }
    530526
    531     if (mpa_vidctx)
    532         av_free(mpa_vidctx);
    533     mpa_vidctx = NULL;
    534 
    535527    QByteArray vcodec = videocodec.toLatin1();
    536528    mpa_vidcodec = avcodec_find_encoder_by_name(vcodec.constData());
    537529
  • 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 f5821f7..932f75c 100644
    a b static int encode_mp2_audio(audio_frame_t *aframe, uint8_t *buffer, int bufsize) 
    218218                    "frame size (%d) does not equal required size (%d)?",
    219219                        out_size, bufsize);
    220220                free(samples);
    221                 avcodec_close(c);
    222                 av_free(c);
     221                avcodec_free_context(&c);
    223222                return 1;
    224223        }
    225224
    226225        free(samples);
    227         avcodec_close(c);
    228         av_free(c);
     226        avcodec_free_context(&c);
    229227       
    230228        return 0;
    231229}
  • mythtv/programs/mythtranscode/mpeg2fix.cpp

    diff --git a/mythtv/programs/mythtranscode/mpeg2fix.cpp b/mythtv/programs/mythtranscode/mpeg2fix.cpp
    index f25b16d..2a85480 100644
    a b bool MPEG2fixup::InitAV(QString inputfile, const char *type, int64_t offset) 
    874874
    875875    for (unsigned int i = 0; i < inputFC->nb_streams; i++)
    876876    {
    877         switch (inputFC->streams[i]->codec->codec_type)
     877        switch (inputFC->streams[i]->codecpar->codec_type)
    878878        {
    879879            case AVMEDIA_TYPE_VIDEO:
    880880                if (vid_id == -1)
    bool MPEG2fixup::InitAV(QString inputfile, const char *type, int64_t offset) 
    883883
    884884            case AVMEDIA_TYPE_AUDIO:
    885885                if (!allaudio && ext_count > 0 &&
    886                     inputFC->streams[i]->codec->channels < 2 &&
    887                     inputFC->streams[i]->codec->sample_rate < 100000)
     886                    inputFC->streams[i]->codecpar->channels < 2 &&
     887                    inputFC->streams[i]->codecpar->sample_rate < 100000)
    888888                {
    889889                    LOG(VB_GENERAL, LOG_ERR,
    890890                        QString("Skipping audio stream: %1").arg(i));
    891891                    break;
    892892                }
    893                 if (inputFC->streams[i]->codec->codec_id == AV_CODEC_ID_AC3 ||
    894                     inputFC->streams[i]->codec->codec_id == AV_CODEC_ID_MP3 ||
    895                     inputFC->streams[i]->codec->codec_id == AV_CODEC_ID_MP2)
     893                if (inputFC->streams[i]->codecpar->codec_id == AV_CODEC_ID_AC3 ||
     894                    inputFC->streams[i]->codecpar->codec_id == AV_CODEC_ID_MP3 ||
     895                    inputFC->streams[i]->codecpar->codec_id == AV_CODEC_ID_MP2)
    896896                {
    897897                    aud_map[i] = ext_count++;
    898898                    aFrame[i] = new FrameList();
    bool MPEG2fixup::InitAV(QString inputfile, const char *type, int64_t offset) 
    900900                else
    901901                    LOG(VB_GENERAL, LOG_ERR,
    902902                        QString("Skipping unsupported audio stream: %1")
    903                             .arg(inputFC->streams[i]->codec->codec_id));
     903                            .arg(inputFC->streams[i]->codecpar->codec_id));
    904904                break;
    905905            default:
    906906                LOG(VB_GENERAL, LOG_ERR,
    907907                    QString("Skipping unsupported codec %1 on stream %2")
    908                         .arg(inputFC->streams[i]->codec->codec_type).arg(i));
     908                        .arg(inputFC->streams[i]->codecpar->codec_type).arg(i));
    909909                break;
    910910        }
    911911    }
    bool MPEG2fixup::BuildFrame(AVPacket *pkt, QString fname) 
    13281328    SetRepeat(pkt->data, pkt->size, info->display_picture->nb_fields,
    13291329              !!(info->display_picture->flags & PIC_FLAG_TOP_FIELD_FIRST));
    13301330
    1331     avcodec_close(c);
    1332     av_freep(&c);
     1331    avcodec_free_context(&c);
    13331332
    13341333    return false;
    13351334}
    int MPEG2fixup::GetFrame(AVPacket *pkt) 
    14581457            return 1;
    14591458        }
    14601459
    1461         switch (inputFC->streams[pkt->stream_index]->codec->codec_type)
     1460        switch (inputFC->streams[pkt->stream_index]->codecpar->codec_type)
    14621461        {
    14631462            case AVMEDIA_TYPE_VIDEO:
    14641463                vFrame.append(tmpFrame);
  • mythtv/programs/mythutil/musicmetautils.cpp

    diff --git a/mythtv/programs/mythutil/musicmetautils.cpp b/mythtv/programs/mythutil/musicmetautils.cpp
    index e303a60..de2c8510 100644
    a b static int CalcTrackLength(const MythUtilCommandLineParser &cmdline) 
    275275        AVStream *st = inputFC->streams[i];
    276276        char buf[256];
    277277
    278         avcodec_string(buf, sizeof(buf), st->codec, false);
     278        const AVCodec *pCodec = avcodec_find_decoder(st->codecpar->codec_id);
     279        if (!pCodec)
     280        {
     281            LOG(VB_GENERAL, LOG_WARNING,
     282                QString("avcodec_find_decoder fail for %1").arg(st->codecpar->codec_id));
     283            continue;
     284        }
     285        AVCodecContext *avctx = avcodec_alloc_context3(pCodec);
     286        avcodec_parameters_to_context(avctx, st->codecpar);
     287        av_codec_set_pkt_timebase(avctx, st->time_base);
     288
     289        avcodec_string(buf, sizeof(buf), avctx, false);
    279290
    280         switch (inputFC->streams[i]->codec->codec_type)
     291        switch (inputFC->streams[i]->codecpar->codec_type)
    281292        {
    282293            case AVMEDIA_TYPE_AUDIO:
    283294            {
    static int CalcTrackLength(const MythUtilCommandLineParser &cmdline) 
    299310            default:
    300311                LOG(VB_GENERAL, LOG_ERR,
    301312                    QString("Skipping unsupported codec %1 on stream %2")
    302                         .arg(inputFC->streams[i]->codec->codec_type).arg(i));
     313                        .arg(inputFC->streams[i]->codecpar->codec_type).arg(i));
    303314                break;
    304315        }
     316        avcodec_free_context(&avctx);
    305317    }
    306318
    307319    // Close input file