Ticket #13233: 20180614_1724_mediacodec_and_ffmpeg.patch

File 20180614_1724_mediacodec_and_ffmpeg.patch, 41.6 KB (added by Peter Bennett, 3 years ago)

Preliminary code with mediacodec support

  • mythtv/configure

    diff --git a/mythtv/configure b/mythtv/configure
    index a47e6823ba3..536f61d11e2 100755
    a b Advanced options (experts only): 
    135135  --disable-vaapi          disable VAAPI hardware accelerated video decoding
    136136  --disable-openmax        disable OpenMAX hardware accelerated video decoding
    137137  --disable-dxva2          disable hardware accelerated decoding on windows
     138  --disable-mediacodec     disable hardware accelerated decoding on android
    138139  --disable-opengl-video   disable OpenGL based video display
    139140  --disable-opengl-themepainter disable OpenGL based theme painting
    140141  --disable-libass         disable libass SSA/ASS subtitle support
    USING_LIST=' 
    20322033    vaapi
    20332034    vdpau
    20342035    openmax
     2036    mediacodec
    20352037'
    20362038
    20372039CMDLINE_SELECT="
    enable libcrypto 
    27572759enable libdns_sd
    27582760enable libxml2
    27592761enable lirc
     2762enable mediacodec
    27602763enable mheg
    27612764enable mythtranscode
    27622765enable opengl
    ffmpeg_optset extra_cxxflags extra_ldflags target_os 
    69606963ffmpeg_optset pkg_config prefix libdir as objcc dep_cc host_cc
    69616964ffmpeg_optset host_ld
    69626965ffmpeg_optenable cross_compile libmp3lame libx264 libx265 libvpx libxvid
    6963 ffmpeg_optenable vdpau vaapi libxml2 libass dxva2 mediacodec
    6964 ffmpeg_optenable jni libbluray libfontconfig libfreetype libiec61883
     6966ffmpeg_optenable vdpau vaapi libxml2 libass dxva2
     6967ffmpeg_optenable libbluray libfontconfig libfreetype libiec61883
    69656968ffmpeg_optenable crystalhd sdl2 ffplay
     6969if test $target_os = "android"; then
     6970    enabled mediacodec && enable jni
     6971    ffmpeg_optenable mediacodec jni
     6972else
     6973    disable mediacodec
     6974fi
     6975
    69666976ffmpeg_extra_cflags="$extra_cflags -w"
    69676977
    69686978## Call FFmpeg configure here
  • mythtv/external/FFmpeg/libavcodec/mediacodecdec_common.c

    diff --git a/mythtv/external/FFmpeg/libavcodec/mediacodecdec_common.c b/mythtv/external/FFmpeg/libavcodec/mediacodecdec_common.c
    index 40a2ee67781..887865a281d 100644
    a b static int mediacodec_dec_flush_codec(AVCodecContext *avctx, MediaCodecDecContex 
    443443    FFAMediaCodec *codec = s->codec;
    444444    int status;
    445445
     446    s->output_buffer_count = 0;
     447
    446448    s->draining = 0;
    447449    s->flushing = 0;
    448450    s->eos = 0;
    int ff_mediacodec_dec_receive(AVCodecContext *avctx, MediaCodecDecContext *s, 
    670672        /* If the codec is flushing or need to be flushed, block for a fair
    671673         * amount of time to ensure we got a frame */
    672674        output_dequeue_timeout_us = OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US;
    673     } else if (!wait) {
     675    } else if (s->output_buffer_count == 0 || !wait) {
     676        /* If the codec hasn't produced any frames, do not block so we
     677         * can push data to it as fast as possible, and get the first
     678         * frame */
    674679        output_dequeue_timeout_us = 0;
    675680    }
    676681
    int ff_mediacodec_dec_receive(AVCodecContext *avctx, MediaCodecDecContext *s, 
    704709                }
    705710            }
    706711
     712            s->output_buffer_count++;
    707713            return 0;
    708714        } else {
    709715            status = ff_AMediaCodec_releaseOutputBuffer(codec, index, 0);
  • mythtv/external/FFmpeg/libavcodec/mediacodecdec_common.h

    diff --git a/mythtv/external/FFmpeg/libavcodec/mediacodecdec_common.h b/mythtv/external/FFmpeg/libavcodec/mediacodecdec_common.h
    index d280236b8ee..0b21129fee4 100644
    a b typedef struct MediaCodecDecContext { 
    6464    int display_width;
    6565    int display_height;
    6666
     67    uint64_t output_buffer_count;
    6768    ssize_t current_input_buffer;
    6869
    6970    bool delay_flush;
  • mythtv/libs/libmythtv/avformatdecoder.cpp

    diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
    index 2c3a1985a05..c3386ea9d9e 100644
    a b extern "C" { 
    6262#include "vaapicontext.h"
    6363#endif
    6464
     65#ifdef USING_MEDIACODEC
     66#include "mediacodeccontext.h"
     67extern "C" {
     68#include "libavcodec/jni.h"
     69}
     70#include <QtAndroidExtras>
     71#endif
     72
    6573extern "C" {
    6674#include "libavutil/avutil.h"
    6775#include "libavutil/error.h"
    void AvFormatDecoder::GetDecoders(render_opts &opts) 
    374382    opts.decoders->append("vaapi");
    375383    (*opts.equiv_decoders)["vaapi"].append("dummy");
    376384#endif
     385#ifdef USING_MEDIACODEC
     386    opts.decoders->append("mediacodec");
     387    (*opts.equiv_decoders)["mediacodec"].append("dummy");
     388#endif
    377389
    378390    PrivateDecoder::GetDecoders(opts);
    379391}
    AvFormatDecoder::AvFormatDecoder(MythPlayer *parent, 
    405417      pts_detected(false),
    406418      reordered_pts_detected(false),
    407419      pts_selected(true),
     420      use_frame_timing(false),
    408421      force_dts_timestamps(false),
    409422      playerFlags(flags),
    410423      video_codec_id(kCodec_NONE),
    enum AVPixelFormat get_format_vaapi(struct AVCodecContext *avctx, 
    15401553}
    15411554#endif
    15421555
     1556#ifdef USING_MEDIACODEC
     1557static enum AVPixelFormat get_format_mediacodec(struct AVCodecContext *avctx,
     1558                                           const enum AVPixelFormat *valid_fmts)
     1559{
     1560    enum AVPixelFormat ret = *valid_fmts; // default to first
     1561    while (*valid_fmts != AV_PIX_FMT_NONE) {
     1562        if (*valid_fmts == AV_PIX_FMT_YUV420P)
     1563            ret = AV_PIX_FMT_YUV420P;
     1564        valid_fmts++;
     1565    }
     1566    return ret;
     1567}
     1568#endif
     1569
     1570
    15431571static bool IS_DR1_PIX_FMT(const enum AVPixelFormat fmt)
    15441572{
    15451573    switch (fmt)
    void AvFormatDecoder::InitVideoCodec(AVStream *stream, AVCodecContext *enc, 
    15751603    enc->debug = 0;
    15761604    // enc->error_rate = 0;
    15771605
    1578     AVCodec *codec = avcodec_find_decoder(enc->codec_id);
     1606    // AVCodec *codec = avcodec_find_decoder(enc->codec_id);
     1607    const AVCodec *codec = enc->codec;
    15791608
    15801609    if (selectedStream)
    15811610    {
    void AvFormatDecoder::InitVideoCodec(AVStream *stream, AVCodecContext *enc, 
    16121641        enc->slice_flags     = SLICE_FLAG_CODED_ORDER | SLICE_FLAG_ALLOW_FIELD;
    16131642    }
    16141643    else
     1644#endif
     1645#ifdef USING_MEDIACODEC
     1646    if (CODEC_IS_MEDIACODEC(codec))
     1647    {
     1648        // enc->get_buffer2     = get_avf_buffer;
     1649        enc->get_format      = get_format_mediacodec;
     1650        enc->slice_flags     = SLICE_FLAG_CODED_ORDER | SLICE_FLAG_ALLOW_FIELD;
     1651    }
     1652    else
    16151653#endif
    16161654    if (codec && codec->capabilities & AV_CODEC_CAP_DR1)
    16171655    {
    void AvFormatDecoder::InitVideoCodec(AVStream *stream, AVCodecContext *enc, 
    16791717        }
    16801718
    16811719        m_parent->SetKeyframeDistance(keyframedist);
    1682         AVCodec *codec = avcodec_find_decoder(enc->codec_id);
     1720        // AVCodec *codec = avcodec_find_decoder(enc->codec_id);
     1721        const AVCodec *codec = enc->codec;
    16831722        QString codecName;
    16841723        if (codec)
    16851724            codecName = codec->name;
    int AvFormatDecoder::ScanStreams(bool novideo) 
    23682407
    23692408            if (averror_count > SEQ_PKT_ERR_MAX)
    23702409                gCodecMap->freeCodecContext(ic->streams[selTrack]);
    2371             AVCodecContext *enc = gCodecMap->getCodecContext(ic->streams[selTrack]);
     2410            AVCodecContext *enc = gCodecMap->getCodecContext(ic->streams[selTrack], codec);
    23722411            StreamInfo si(selTrack, 0, 0, 0, 0);
    23732412
    23742413            tracks[kTrackTypeVideo].push_back(si);
    int AvFormatDecoder::ScanStreams(bool novideo) 
    23932432            uint height = max(dim.height(), 16);
    23942433            QString dec = "ffmpeg";
    23952434            uint thread_count = 1;
    2396             AVCodec *codec1 = avcodec_find_decoder(enc->codec_id);
     2435            // AVCodec *codec1 = avcodec_find_decoder(enc->codec_id);
    23972436            QString codecName;
    2398             if (codec1)
    2399                 codecName = codec1->name;
     2437            if (enc->codec)
     2438                codecName = enc->codec->name;
    24002439            if (enc->framerate.den && enc->framerate.num)
    24012440                fps = float(enc->framerate.num) / float(enc->framerate.den);
    24022441            else
    int AvFormatDecoder::ScanStreams(bool novideo) 
    24732512                }
    24742513#endif // USING_GLVAAPI
    24752514#ifdef USING_DXVA2
    2476                 if (!foundgpudecode)
     2515                if (!foundgpudecoder)
    24772516                {
    24782517                    MythCodecID dxva2_mcid;
    24792518                    AVPixelFormat pix_fmt = AV_PIX_FMT_YUV420P;
    int AvFormatDecoder::ScanStreams(bool novideo) 
    24892528                    }
    24902529                }
    24912530#endif // USING_DXVA2
    2492                 if (foundgpudecoder)
     2531#ifdef USING_MEDIACODEC
     2532                if (!foundgpudecoder)
    24932533                {
    2494                     enc->codec_id = (AVCodecID) myth2av_codecid(video_codec_id);
     2534                    MythCodecID mediacodec_mcid;
     2535                    AVPixelFormat pix_fmt = AV_PIX_FMT_YUV420P;
     2536                    mediacodec_mcid = MediaCodecContext::GetBestSupportedCodec(
     2537                        &codec, dec, mpeg_version(enc->codec_id),
     2538                        pix_fmt);
     2539
     2540                    if (codec_is_mediacodec(mediacodec_mcid))
     2541                    {
     2542                        gCodecMap->freeCodecContext(ic->streams[selTrack]);
     2543                        enc = gCodecMap->getCodecContext(ic->streams[selTrack], codec);
     2544                        video_codec_id = mediacodec_mcid;
     2545                        foundgpudecoder = true;
     2546                    }
    24952547                }
     2548#endif // USING_MEDIACODEC
     2549// UNNECESSARY PGB
     2550                // if (foundgpudecoder)
     2551                // {
     2552                //     enc->codec_id = (AVCodecID) myth2av_codecid(video_codec_id);
     2553                // }
    24962554            }
    24972555
    24982556            // default to mpeg2
    int AvFormatDecoder::ScanStreams(bool novideo) 
    25022560                    "Unknown video codec - defaulting to MPEG2");
    25032561                video_codec_id = kCodec_MPEG2;
    25042562            }
    2505             else
    2506             {
    2507                 codec = avcodec_find_decoder(enc->codec_id);
    2508             }
     2563// UNNECESSARY PGB
     2564            // else
     2565            // {
     2566            //     codec = avcodec_find_decoder(enc->codec_id);
     2567            // }
    25092568
    25102569            // Use a PrivateDecoder if allowed in playerFlags AND matched
    25112570            // via the decoder name
    int AvFormatDecoder::ScanStreams(bool novideo) 
    25162575            if (!codec_is_std(video_codec_id))
    25172576                thread_count = 1;
    25182577
     2578            if (codec_is_std(video_codec_id) || codec_is_mediacodec(video_codec_id))
     2579                use_frame_timing = true;
     2580            else
     2581                use_frame_timing = false;
     2582
    25192583            if (FlagIsSet(kDecodeSingleThreaded))
    25202584                thread_count = 1;
    25212585
    int AvFormatDecoder::ScanStreams(bool novideo) 
    25312595            ScanATSCCaptionStreams(selTrack);
    25322596            UpdateATSCCaptionTracks();
    25332597
    2534             LOG(VB_PLAYBACK, LOG_INFO, LOC +
     2598            LOG(VB_GENERAL, LOG_INFO, LOC +
    25352599                QString("Using %1 for video decoding")
    25362600                .arg(GetCodecDecoderName()));
    25372601
    bool AvFormatDecoder::OpenAVCodec(AVCodecContext *avctx, const AVCodec *codec) 
    26112675{
    26122676    QMutexLocker locker(avcodeclock);
    26132677
     2678#ifdef USING_MEDIACODEC
     2679    if (QString("mediacodec") == codec->wrapper_name)
     2680        av_jni_set_java_vm(QAndroidJniEnvironment::javaVM(), NULL);
     2681#endif
    26142682    int ret = avcodec_open2(avctx, codec, NULL);
    26152683    if (ret < 0)
    26162684    {
    bool AvFormatDecoder::ProcessVideoPacket(AVStream *curstream, AVPacket *pkt) 
    35423610    int64_t pts = 0;
    35433611    AVCodecContext *context = gCodecMap->getCodecContext(curstream);
    35443612    MythAVFrame mpa_pic;
     3613    int frameCount = 0;
    35453614    if (!mpa_pic)
    35463615    {
    35473616        return false;
    bool AvFormatDecoder::ProcessVideoPacket(AVStream *curstream, AVPacket *pkt) 
    35513620    if (pkt->pts != (int64_t)AV_NOPTS_VALUE)
    35523621        pts_detected = true;
    35533622
    3554     avcodeclock->lock();
    3555     if (private_dec)
     3623    // Whan a single packet produces multiple frames, tryAgain
     3624    // is used so that they can all be processed.
     3625    bool tryAgain = true;
     3626    while (tryAgain)
    35563627    {
    3557         if (QString(ic->iformat->name).contains("avi") || !pts_detected)
    3558             pkt->pts = pkt->dts;
    3559         // TODO disallow private decoders for dvd playback
    3560         // N.B. we do not reparse the frame as it breaks playback for
    3561         // everything but libmpeg2
    3562         ret = private_dec->GetFrame(curstream, mpa_pic, &gotpicture, pkt);
    3563     }
    3564     else
    3565     {
    3566         context->reordered_opaque = pkt->pts;
    3567         //  SUGGESTION
    3568         //  Now that avcodec_decode_video2 is deprecated and replaced
    3569         //  by 2 calls (receive frame and send packet), this could be optimized
    3570         //  into separate routines or separate threads.
    3571         //  Also now that it always consumes a whole buffer some code
    3572         //  in the caller may be able to be optimized.
    3573         ret = avcodec_receive_frame(context, mpa_pic);
    3574         if (ret == 0)
    3575             gotpicture = 1;
     3628        avcodeclock->lock();
     3629        if (private_dec)
     3630        {
     3631            if (QString(ic->iformat->name).contains("avi") || !pts_detected)
     3632                pkt->pts = pkt->dts;
     3633            // TODO disallow private decoders for dvd playback
     3634            // N.B. we do not reparse the frame as it breaks playback for
     3635            // everything but libmpeg2
     3636            ret = private_dec->GetFrame(curstream, mpa_pic, &gotpicture, pkt);
     3637        }
     3638        else
     3639        {
     3640            if (!use_frame_timing)
     3641                context->reordered_opaque = pkt->pts;
     3642
     3643            //  SUGGESTION
     3644            //  Now that avcodec_decode_video2 is deprecated and replaced
     3645            //  by 2 calls (receive frame and send packet), this could be optimized
     3646            //  into separate routines or separate threads.
     3647            //  Also now that it always consumes a whole buffer some code
     3648            //  in the caller may be able to be optimized.
     3649            ret = avcodec_receive_frame(context, mpa_pic);
     3650            // LOG(VB_PLAYBACK, LOG_INFO, LOC +
     3651            //     QString("avcodec_receive_frame return:%1")
     3652            //     .arg(ret));
     3653
     3654            if (ret == 0)
     3655                gotpicture = 1;
     3656            else
     3657                gotpicture = 0;
     3658            if (ret == AVERROR(EAGAIN))
     3659                ret = 0;
     3660            if (ret == 0)
     3661            {
     3662                ret = avcodec_send_packet(context, pkt);
     3663                // LOG(VB_PLAYBACK, LOG_INFO, LOC +
     3664                //     QString("avcodec_send_packet return:%1")
     3665                //     .arg(ret));
     3666                // if (ret == AVERROR(EAGAIN) && !gotpicture)
     3667                // {
     3668                //     ret = avcodec_send_packet(context, pkt);
     3669                //     LOG(VB_PLAYBACK, LOG_INFO, LOC +
     3670                //         QString("avcodec_second send_packet return:%1")
     3671                //         .arg(ret));
     3672                // }
     3673            }
     3674        }
     3675        avcodeclock->unlock();
     3676
    35763677        if (ret == AVERROR(EAGAIN))
     3678        {
     3679            tryAgain = true;
     3680            use_frame_timing = true;
    35773681            ret = 0;
    3578         if (ret == 0)
    3579             ret = avcodec_send_packet(context, pkt);
    3580         // The code assumes that there is always space to add a new
    3581         // packet. This seems risky but has always worked.
    3582         // It should actually check if (ret == AVERROR(EAGAIN)) and then keep
    3583         // the packet around and try it again after processing the frame
    3584         // received here.
    3585     }
    3586     avcodeclock->unlock();
     3682        }
     3683        else
     3684            tryAgain = false;
    35873685
    3588     if (ret < 0)
    3589     {
    3590         char error[AV_ERROR_MAX_STRING_SIZE];
    3591         LOG(VB_GENERAL, LOG_ERR, LOC +
    3592             QString("video decode error: %1 (%2)")
    3593             .arg(av_make_error_string(error, sizeof(error), ret))
    3594             .arg(gotpicture));
    3595         if (ret == AVERROR_INVALIDDATA)
     3686        if (ret < 0)
    35963687        {
    3597             if (++averror_count > SEQ_PKT_ERR_MAX)
     3688            char error[AV_ERROR_MAX_STRING_SIZE];
     3689            LOG(VB_GENERAL, LOG_ERR, LOC +
     3690                QString("video decode error: %1 (%2)")
     3691                .arg(av_make_error_string(error, sizeof(error), ret))
     3692                .arg(gotpicture));
     3693            if (ret == AVERROR_INVALIDDATA)
    35983694            {
    3599                 // If erroring on GPU assist, try switching to software decode
    3600                 if (codec_is_std(video_codec_id))
    3601                     m_parent->SetErrored(QObject::tr("Video Decode Error"));
    3602                 else
    3603                     m_streams_changed = true;
     3695                if (++averror_count > SEQ_PKT_ERR_MAX)
     3696                {
     3697                    // If erroring on GPU assist, try switching to software decode
     3698                    if (codec_is_std(video_codec_id))
     3699                        m_parent->SetErrored(QObject::tr("Video Decode Error"));
     3700                    else
     3701                        m_streams_changed = true;
     3702                }
    36043703            }
     3704            return false;
    36053705        }
    3606         return false;
    3607     }
    3608     // averror_count counts sequential errors, so if you have a successful
    3609     // packet then reset it
    3610     averror_count = 0;
    36113706
    3612     if (!gotpicture)
    3613     {
    3614         return true;
    3615     }
     3707        if (tryAgain && !gotpicture)
     3708        {
     3709            LOG(VB_PLAYBACK, LOG_INFO, LOC +
     3710                QString("Video Decode Buffering Retry"));
     3711            usleep(10000);
     3712            continue;
     3713        }
    36163714
    3617     // Detect faulty video timestamps using logic from ffplay.
    3618     if (pkt->dts != (int64_t)AV_NOPTS_VALUE)
    3619     {
    3620         faulty_dts += (pkt->dts <= last_dts_for_fault_detection);
    3621         last_dts_for_fault_detection = pkt->dts;
    3622     }
    3623     if (mpa_pic->reordered_opaque != (int64_t)AV_NOPTS_VALUE)
    3624     {
    3625         faulty_pts += (mpa_pic->reordered_opaque <= last_pts_for_fault_detection);
    3626         last_pts_for_fault_detection = mpa_pic->reordered_opaque;
    3627         reordered_pts_detected = true;
    3628     }
     3715        // averror_count counts sequential errors, so if you have a successful
     3716        // packet then reset it
     3717        averror_count = 0;
    36293718
    3630     // Explicity use DTS for DVD since they should always be valid for every
    3631     // frame and fixups aren't enabled for DVD.
    3632     // Select reordered_opaque (PTS) timestamps if they are less faulty or the
    3633     // the DTS timestamp is missing. Also use fixups for missing PTS instead of
    3634     // DTS to avoid oscillating between PTS and DTS. Only select DTS if PTS is
    3635     // more faulty or never detected.
    3636     if (force_dts_timestamps)
    3637     {
    3638         if (pkt->dts != (int64_t)AV_NOPTS_VALUE)
    3639             pts = pkt->dts;
    3640         pts_selected = false;
    3641     }
    3642     else if (ringBuffer->IsDVD())
    3643     {
    3644         if (pkt->dts != (int64_t)AV_NOPTS_VALUE)
    3645             pts = pkt->dts;
    3646         pts_selected = false;
    3647     }
    3648     else if (private_dec && private_dec->NeedsReorderedPTS() &&
    3649              mpa_pic->reordered_opaque != (int64_t)AV_NOPTS_VALUE)
    3650     {
    3651         pts = mpa_pic->reordered_opaque;
    3652         pts_selected = true;
    3653     }
    3654     else if (faulty_pts <= faulty_dts && reordered_pts_detected)
    3655     {
    3656         if (mpa_pic->reordered_opaque != (int64_t)AV_NOPTS_VALUE)
    3657             pts = mpa_pic->reordered_opaque;
    3658         pts_selected = true;
    3659     }
    3660     else if (pkt->dts != (int64_t)AV_NOPTS_VALUE)
    3661     {
    3662         pts = pkt->dts;
    3663         pts_selected = false;
    3664     }
     3719        if (!gotpicture)
     3720        {
     3721            return true;
     3722        }
    36653723
    3666     LOG(VB_PLAYBACK | VB_TIMESTAMP, LOG_DEBUG, LOC +
    3667         QString("video packet timestamps reordered %1 pts %2 dts %3 (%4)")
    3668             .arg(mpa_pic->reordered_opaque).arg(pkt->pts).arg(pkt->dts)
    3669             .arg((force_dts_timestamps) ? "dts forced" :
    3670                  (pts_selected) ? "reordered" : "dts"));
     3724        frameCount++;
     3725        LOG(VB_PLAYBACK | VB_TIMESTAMP, LOG_INFO, LOC +
     3726            QString("video timecodes packet-pts:%1 frame-pts:%2 packet-dts: %3 frame-dts:%4 frameCount:%5")
     3727                .arg(pkt->pts).arg(mpa_pic->pts).arg(pkt->pts)
     3728                .arg(mpa_pic->pkt_dts).arg(frameCount));
    36713729
    3672     mpa_pic->reordered_opaque = pts;
     3730        if (!use_frame_timing)
     3731        {
     3732            // Detect faulty video timestamps using logic from ffplay.
     3733            if (pkt->dts != (int64_t)AV_NOPTS_VALUE)
     3734            {
     3735                faulty_dts += (pkt->dts <= last_dts_for_fault_detection);
     3736                last_dts_for_fault_detection = pkt->dts;
     3737            }
     3738            if (mpa_pic->reordered_opaque != (int64_t)AV_NOPTS_VALUE)
     3739            {
     3740                faulty_pts += (mpa_pic->reordered_opaque <= last_pts_for_fault_detection);
     3741                last_pts_for_fault_detection = mpa_pic->reordered_opaque;
     3742                reordered_pts_detected = true;
     3743            }
     3744
     3745            // Explicity use DTS for DVD since they should always be valid for every
     3746            // frame and fixups aren't enabled for DVD.
     3747            // Select reordered_opaque (PTS) timestamps if they are less faulty or the
     3748            // the DTS timestamp is missing. Also use fixups for missing PTS instead of
     3749            // DTS to avoid oscillating between PTS and DTS. Only select DTS if PTS is
     3750            // more faulty or never detected.
     3751            if (force_dts_timestamps)
     3752            {
     3753                if (pkt->dts != (int64_t)AV_NOPTS_VALUE)
     3754                    pts = pkt->dts;
     3755                pts_selected = false;
     3756            }
     3757            else if (ringBuffer->IsDVD())
     3758            {
     3759                if (pkt->dts != (int64_t)AV_NOPTS_VALUE)
     3760                    pts = pkt->dts;
     3761                pts_selected = false;
     3762            }
     3763            else if (private_dec && private_dec->NeedsReorderedPTS() &&
     3764                    mpa_pic->reordered_opaque != (int64_t)AV_NOPTS_VALUE)
     3765            {
     3766                pts = mpa_pic->reordered_opaque;
     3767                pts_selected = true;
     3768            }
     3769            else if (faulty_pts <= faulty_dts && reordered_pts_detected)
     3770            {
     3771                if (mpa_pic->reordered_opaque != (int64_t)AV_NOPTS_VALUE)
     3772                    pts = mpa_pic->reordered_opaque;
     3773                pts_selected = true;
     3774            }
     3775            else if (pkt->dts != (int64_t)AV_NOPTS_VALUE)
     3776            {
     3777                pts = pkt->dts;
     3778                pts_selected = false;
     3779            }
    36733780
    3674     ProcessVideoFrame(curstream, mpa_pic);
     3781            LOG(VB_PLAYBACK | VB_TIMESTAMP, LOG_DEBUG, LOC +
     3782                QString("video packet timestamps reordered %1 pts %2 dts %3 (%4)")
     3783                    .arg(mpa_pic->reordered_opaque).arg(pkt->pts).arg(pkt->dts)
     3784                    .arg((force_dts_timestamps) ? "dts forced" :
     3785                        (pts_selected) ? "reordered" : "dts"));
    36753786
     3787            mpa_pic->reordered_opaque = pts;
     3788        }
     3789        ProcessVideoFrame(curstream, mpa_pic);
     3790    }
    36763791    return true;
    36773792}
    36783793
    bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic) 
    37773892        return false;
    37783893    }
    37793894
    3780     long long pts = (long long)(av_q2d(stream->time_base) *
     3895    long long pts;
     3896    if (use_frame_timing)
     3897    {
     3898        pts = mpa_pic->pts;
     3899        if (pts == AV_NOPTS_VALUE)
     3900            pts = mpa_pic->pkt_dts;
     3901        if (pts == AV_NOPTS_VALUE)
     3902        {
     3903            LOG(VB_GENERAL, LOG_ERR, LOC + "No PTS found - unable to process video.");
     3904            return false;
     3905        }
     3906        pts = (long long)(av_q2d(stream->time_base) *
     3907                                pts * 1000);
     3908    }
     3909    else
     3910        pts = (long long)(av_q2d(stream->time_base) *
    37813911                                mpa_pic->reordered_opaque * 1000);
    37823912
    37833913    long long temppts = pts;
    bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic) 
    37963926
    37973927    LOG(VB_PLAYBACK | VB_TIMESTAMP, LOG_INFO, LOC +
    37983928        QString("video timecode %1 %2 %3 %4%5")
    3799             .arg(mpa_pic->reordered_opaque).arg(pts).arg(temppts).arg(lastvpts)
     3929            .arg(use_frame_timing ? mpa_pic->pts : mpa_pic->reordered_opaque).arg(pts)
     3930            .arg(temppts).arg(lastvpts)
    38003931            .arg((pts != temppts) ? " fixup" : ""));
    38013932
    38023933    if (picframe)
  • mythtv/libs/libmythtv/avformatdecoder.h

    diff --git a/mythtv/libs/libmythtv/avformatdecoder.h b/mythtv/libs/libmythtv/avformatdecoder.h
    index 486e0bb1bed..e4dded21576 100644
    a b class AvFormatDecoder : public DecoderBase 
    322322    bool pts_detected;
    323323    bool reordered_pts_detected;
    324324    bool pts_selected;
     325    // set use_frame_timing true to utilize the pts values in returned
     326    // frames. Set fale to use deprecated method.
     327    bool use_frame_timing;
    325328
    326329    bool force_dts_timestamps;
    327330
  • mythtv/libs/libmythtv/libmythtv.pro

    diff --git a/mythtv/libs/libmythtv/libmythtv.pro b/mythtv/libs/libmythtv/libmythtv.pro
    index 438207f3096..6eb6127ca7a 100644
    a b  
    11include ( ../../settings.pro )
    22
    33QT += network xml sql widgets
     4android: QT += androidextras
    45
    56TEMPLATE = lib
    67TARGET = mythtv-$$LIBVERSION
    using_frontend { 
    503504        using_opengl_video:DEFINES += USING_GLVAAPI
    504505    }
    505506
     507    using_mediacodec {
     508        DEFINES += USING_MEDIACODEC
     509        HEADERS += mediacodeccontext.h
     510        SOURCES += mediacodeccontext.cpp
     511    }
     512
    506513    # Misc. frontend
    507514    HEADERS += DetectLetterbox.h
    508515    SOURCES += DetectLetterbox.cpp
  • new file mythtv/libs/libmythtv/mediacodeccontext.cpp

    diff --git a/mythtv/libs/libmythtv/mediacodeccontext.cpp b/mythtv/libs/libmythtv/mediacodeccontext.cpp
    new file mode 100644
    index 00000000000..d95de6a01a1
    - +  
     1//////////////////////////////////////////////////////////////////////////////
     2// Copyright (c) 2017 MythTV Developers <mythtv-dev@mythtv.org>
     3//
     4// This is part of MythTV (https://www.mythtv.org)
     5//
     6// This program is free software; you can redistribute it and/or modify
     7// it under the terms of the GNU General Public License as published by
     8// the Free Software Foundation; either version 2 of the License, or
     9// (at your option) any later version.
     10//
     11// This program is distributed in the hope that it will be useful,
     12// but WITHOUT ANY WARRANTY; without even the implied warranty of
     13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14// GNU General Public License for more details.
     15//
     16// You should have received a copy of the GNU General Public License
     17// along with this program; if not, write to the Free Software
     18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
     19//
     20// You should have received a copy of the GNU General Public License
     21// along with this program.  If not, see <http://www.gnu.org/licenses/>.
     22//
     23//////////////////////////////////////////////////////////////////////////////
     24
     25#include "mediacodeccontext.h"
     26
     27#include "mythlogging.h"
     28
     29extern "C" {
     30    #include "libavutil/pixfmt.h"
     31    #include "libavutil/hwcontext.h"
     32    #include "libavcodec/avcodec.h"
     33}
     34
     35#define LOC QString("MEDIACODEC: ")
     36
     37MythCodecID MediaCodecContext::GetBestSupportedCodec(
     38    AVCodec **ppCodec,
     39    const QString &decoder,
     40    uint stream_type,
     41    AVPixelFormat &pix_fmt)
     42{
     43    enum AVHWDeviceType type = AV_HWDEVICE_TYPE_MEDIACODEC;
     44
     45    AVPixelFormat fmt = AV_PIX_FMT_NONE;
     46    if (decoder == "mediacodec")
     47    {
     48        QString decodername = QString((*ppCodec)->name) + "_mediacodec";
     49        if (decodername == "mpeg2video_mediacodec")
     50            decodername = "mpeg2_mediacodec";
     51        AVCodec *newCodec = avcodec_find_decoder_by_name (decodername.toLocal8Bit());
     52        if (newCodec)
     53        {
     54            *ppCodec = newCodec;
     55            fmt = AV_PIX_FMT_MEDIACODEC;
     56        }
     57        else
     58            LOG(VB_PLAYBACK, LOG_INFO, LOC +
     59                QString("Decoder %1 does not support device type %2.")
     60                    .arg((*ppCodec)->name).arg(av_hwdevice_get_type_name(type)));
     61    }
     62
     63    if (fmt == AV_PIX_FMT_NONE)
     64        return (MythCodecID)(kCodec_MPEG1 + (stream_type - 1));
     65    else
     66    {
     67        LOG(VB_PLAYBACK, LOG_INFO, LOC +
     68            QString("Decoder %1 supports device type %2.")
     69                .arg((*ppCodec)->name).arg(av_hwdevice_get_type_name(type)));
     70        pix_fmt = fmt;
     71        return (MythCodecID)(kCodec_MPEG1_MEDIACODEC + (stream_type - 1));
     72    }
     73}
  • new file mythtv/libs/libmythtv/mediacodeccontext.h

    diff --git a/mythtv/libs/libmythtv/mediacodeccontext.h b/mythtv/libs/libmythtv/mediacodeccontext.h
    new file mode 100644
    index 00000000000..7f116487e0b
    - +  
     1//////////////////////////////////////////////////////////////////////////////
     2// Copyright (c) 2017 MythTV Developers <mythtv-dev@mythtv.org>
     3//
     4// This is part of MythTV (https://www.mythtv.org)
     5//
     6// This program is free software; you can redistribute it and/or modify
     7// it under the terms of the GNU General Public License as published by
     8// the Free Software Foundation; either version 2 of the License, or
     9// (at your option) any later version.
     10//
     11// This program is distributed in the hope that it will be useful,
     12// but WITHOUT ANY WARRANTY; without even the implied warranty of
     13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14// GNU General Public License for more details.
     15//
     16// You should have received a copy of the GNU General Public License
     17// along with this program; if not, write to the Free Software
     18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
     19//
     20// You should have received a copy of the GNU General Public License
     21// along with this program.  If not, see <http://www.gnu.org/licenses/>.
     22//
     23//////////////////////////////////////////////////////////////////////////////
     24
     25
     26#ifndef VIDEOOUTOPENGLMEDIACODEC_H
     27#define VIDEOOUTOPENGLMEDIACODEC_H
     28
     29#include "videoout_opengl.h"
     30
     31
     32class MediaCodecContext
     33{
     34  public:
     35    static MythCodecID GetBestSupportedCodec(AVCodec **ppCodec,
     36                                             const QString &decoder,
     37                                             uint stream_type,
     38                                             AVPixelFormat &pix_fmt);
     39};
     40
     41#endif // VIDEOOUTOPENGLMEDIACODEC_H
     42 No newline at end of file
  • mythtv/libs/libmythtv/mythcodecid.cpp

    diff --git a/mythtv/libs/libmythtv/mythcodecid.cpp b/mythtv/libs/libmythtv/mythcodecid.cpp
    index cd9170a648d..b2023512b5f 100644
    a b QString toString(MythCodecID codecid) 
    102102        case kCodec_HEVC_DXVA2:
    103103            return "HEVC DXVA2";
    104104
     105        case kCodec_MPEG1_MEDIACODEC:
     106            return "MPEG1 MEDIACODEC";
     107        case kCodec_MPEG2_MEDIACODEC:
     108            return "MPEG2 MEDIACODEC";
     109        case kCodec_H263_MEDIACODEC:
     110            return "H.263 MEDIACODEC";
     111        case kCodec_MPEG4_MEDIACODEC:
     112            return "MPEG4 MEDIACODEC";
     113        case kCodec_H264_MEDIACODEC:
     114            return "H.264 MEDIACODEC";
     115        case kCodec_VC1_MEDIACODEC:
     116            return "VC1 MEDIACODEC";
     117        case kCodec_WMV3_MEDIACODEC:
     118            return "WMV3 MEDIACODEC";
     119        case kCodec_VP8_MEDIACODEC:
     120            return "VP8 MEDIACODEC";
     121        case kCodec_VP9_MEDIACODEC:
     122            return "VP9 MEDIACODEC";
     123        case kCodec_HEVC_MEDIACODEC:
     124            return "HEVC MEDIACODEC";
     125
    105126        default:
    106127            break;
    107128    }
    int myth2av_codecid(MythCodecID codec_id, bool &vdpau) 
    253274            ret = AV_CODEC_ID_HEVC;
    254275            break;
    255276
     277        case kCodec_MPEG1_MEDIACODEC:
     278            ret = AV_CODEC_ID_MPEG1VIDEO;
     279            break;
     280        case kCodec_MPEG2_MEDIACODEC:
     281            ret = AV_CODEC_ID_MPEG2VIDEO;
     282            break;
     283        case kCodec_H263_MEDIACODEC:
     284            ret = AV_CODEC_ID_H263;
     285            break;
     286        case kCodec_MPEG4_MEDIACODEC:
     287            ret = AV_CODEC_ID_MPEG4;
     288            break;
     289        case kCodec_H264_MEDIACODEC:
     290            ret = AV_CODEC_ID_H264;
     291            break;
     292        case kCodec_VC1_MEDIACODEC:
     293            ret = AV_CODEC_ID_VC1;
     294            break;
     295        case kCodec_WMV3_MEDIACODEC:
     296            ret = AV_CODEC_ID_WMV3;
     297            break;
     298        case kCodec_VP8_MEDIACODEC:
     299            ret = AV_CODEC_ID_VP8;
     300            break;
     301        case kCodec_VP9_MEDIACODEC:
     302            ret = AV_CODEC_ID_VP9;
     303            break;
     304        case kCodec_HEVC_MEDIACODEC:
     305            ret = AV_CODEC_ID_HEVC;
     306            break;
     307
    256308        default:
    257309            LOG(VB_GENERAL, LOG_ERR,
    258310                QString("Error: MythCodecID %1 has not been "
    QString get_encoding_type(MythCodecID codecid) 
    303355        case kCodec_MPEG1_VDPAU:
    304356        case kCodec_MPEG1_VAAPI:
    305357        case kCodec_MPEG1_DXVA2:
     358        case kCodec_MPEG1_MEDIACODEC:
    306359        case kCodec_MPEG2:
    307360        case kCodec_MPEG2_VDPAU:
    308361        case kCodec_MPEG2_VAAPI:
    309362        case kCodec_MPEG2_DXVA2:
     363        case kCodec_MPEG2_MEDIACODEC:
    310364            return "MPEG-2";
    311365
    312366        case kCodec_H263:
    313367        case kCodec_H263_VDPAU:
    314368        case kCodec_H263_VAAPI:
    315369        case kCodec_H263_DXVA2:
     370        case kCodec_H263_MEDIACODEC:
    316371            return "H.263";
    317372
    318373        case kCodec_NUV_MPEG4:
    QString get_encoding_type(MythCodecID codecid) 
    320375        case kCodec_MPEG4_VDPAU:
    321376        case kCodec_MPEG4_VAAPI:
    322377        case kCodec_MPEG4_DXVA2:
     378        case kCodec_MPEG4_MEDIACODEC:
    323379            return "MPEG-4";
    324380
    325381        case kCodec_H264:
    326382        case kCodec_H264_VDPAU:
    327383        case kCodec_H264_VAAPI:
    328384        case kCodec_H264_DXVA2:
     385        case kCodec_H264_MEDIACODEC:
    329386            return "H.264";
    330387
    331388        case kCodec_VC1:
    332389        case kCodec_VC1_VDPAU:
    333390        case kCodec_VC1_VAAPI:
    334391        case kCodec_VC1_DXVA2:
     392        case kCodec_VC1_MEDIACODEC:
    335393            return "VC-1";
    336394
    337395        case kCodec_WMV3:
    338396        case kCodec_WMV3_VDPAU:
    339397        case kCodec_WMV3_VAAPI:
    340398        case kCodec_WMV3_DXVA2:
     399        case kCodec_WMV3_MEDIACODEC:
    341400            return "WMV3";
    342401
    343402        case kCodec_VP8:
    344403        case kCodec_VP8_VDPAU:
    345404        case kCodec_VP8_VAAPI:
    346405        case kCodec_VP8_DXVA2:
     406        case kCodec_VP8_MEDIACODEC:
    347407            return "VP8";
    348408
    349409        case kCodec_VP9:
    350410        case kCodec_VP9_VDPAU:
    351411        case kCodec_VP9_VAAPI:
    352412        case kCodec_VP9_DXVA2:
     413        case kCodec_VP9_MEDIACODEC:
    353414            return "VP8";
    354415
    355416        case kCodec_HEVC:
    356417        case kCodec_HEVC_VDPAU:
    357418        case kCodec_HEVC_VAAPI:
    358419        case kCodec_HEVC_DXVA2:
     420        case kCodec_HEVC_MEDIACODEC:
    359421            return "HEVC";
    360422
    361423        case kCodec_NONE:
    QString get_encoding_type(MythCodecID codecid) 
    363425        case kCodec_VDPAU_END:
    364426        case kCodec_VAAPI_END:
    365427        case kCodec_DXVA2_END:
     428        case kCodec_MEDIACODEC_END:
    366429            return QString();
    367430    }
    368431
    QString get_decoder_name(MythCodecID codec_id) 
    380443    if (codec_is_dxva2(codec_id))
    381444        return "dxva2";
    382445
     446    if (codec_is_mediacodec(codec_id))
     447        return "mediacodec";
     448
    383449    return "ffmpeg";
    384450}
  • mythtv/libs/libmythtv/mythcodecid.h

    diff --git a/mythtv/libs/libmythtv/mythcodecid.h b/mythtv/libs/libmythtv/mythcodecid.h
    index 92466df9b8c..7ad5f157065 100644
    a b typedef enum 
    7575    kCodec_HEVC_DXVA2,
    7676
    7777    kCodec_DXVA2_END,
     78
     79    kCodec_MEDIACODEC_BEGIN = kCodec_DXVA2_END,
     80
     81    kCodec_MPEG1_MEDIACODEC,
     82    kCodec_MPEG2_MEDIACODEC,
     83    kCodec_H263_MEDIACODEC,
     84    kCodec_MPEG4_MEDIACODEC,
     85    kCodec_H264_MEDIACODEC,
     86    kCodec_VC1_MEDIACODEC,
     87    kCodec_WMV3_MEDIACODEC,
     88    kCodec_VP8_MEDIACODEC,
     89    kCodec_VP9_MEDIACODEC,
     90    kCodec_HEVC_MEDIACODEC,
     91
     92    kCodec_MEDIACODEC_END,
     93
    7894} MythCodecID;
    7995
    8096// MythCodecID convenience functions
    8197#define codec_is_std(id)      (id < kCodec_NORMAL_END)
     98// temporary test
    8299#define codec_is_std_mpeg(id) (id == kCodec_MPEG1 || id == kCodec_MPEG2)
    83100#define codec_is_vdpau(id)    ((id > kCodec_VDPAU_BEGIN) &&     \
    84101                               (id < kCodec_VDPAU_END))
    typedef enum 
    95112                               ((id == kCodec_H264_DXVA2)  ||   \
    96113                                (id == kCodec_MPEG2_DXVA2) ||   \
    97114                                (id == kCodec_VC1_DXVA2)))
     115#define codec_is_mediacodec(id) ((id > kCodec_MEDIACODEC_BEGIN) &&     \
     116                               (id < kCodec_MEDIACODEC_END))
     117
     118#define codec_sw_copy(id) (codec_is_std(id) || codec_is_mediacodec(id))
    98119
    99120QString get_encoding_type(MythCodecID codecid);
    100121QString get_decoder_name(MythCodecID codec_id);
    int mpeg_version(int codec_id); 
    130151#define CODEC_IS_DXVA2(codec, enc) (0)
    131152#endif
    132153
     154#ifdef USING_MEDIACODEC
     155#define CODEC_IS_MEDIACODEC(codec) (codec && (QString("mediacodec") == codec->wrapper_name))
     156#else
     157#define CODEC_IS_MEDIACODEC(codec) (0)
     158#endif
     159
    133160#define CODEC_IS_HWACCEL(codec, enc) (CODEC_IS_VDPAU(codec)      ||     \
    134161                                      CODEC_IS_VAAPI(codec, enc) ||     \
    135                                       CODEC_IS_DXVA2(codec, enc))
     162                                      CODEC_IS_DXVA2(codec, enc) ||    \
     163                                      CODEC_IS_MEDIACODEC(codec))
    136164
    137165#endif // _MYTH_CODEC_ID_H_
  • mythtv/libs/libmythtv/videobuffers.cpp

    diff --git a/mythtv/libs/libmythtv/videobuffers.cpp b/mythtv/libs/libmythtv/videobuffers.cpp
    index e20c13d2772..92620924ca9 100644
    a b extern "C" { 
    1515#include "compat.h"
    1616#include "mythlogging.h"
    1717
    18 #define TRY_LOCK_SPINS                 100
    19 #define TRY_LOCK_SPINS_BEFORE_WARNING   10
    20 #define TRY_LOCK_SPIN_WAIT             100 /* usec */
     18#define TRY_LOCK_SPINS                 2000
     19#define TRY_LOCK_SPINS_BEFORE_WARNING  9999
     20#define TRY_LOCK_SPIN_WAIT             1000 /* usec */
    2121
    2222int next_dbg_str = 0;
    2323
    VideoFrame *VideoBuffers::GetNextFreeFrame(BufferType enqueue_to) 
    289289
    290290        if (tries >= TRY_LOCK_SPINS)
    291291        {
     292            LOG(VB_GENERAL, LOG_ERR, QString("GetNextFreeFrame: "
     293            "available:%1 used:%2 limbo:%3 pause:%4 displayed:%5 decode:%6 finished:%7")
     294            .arg(available.size()).arg(used.size()).arg(limbo.size()).arg(pause.size()).arg(displayed.size()).arg(decode.size()).arg(finished.size()));
    292295            LOG(VB_GENERAL, LOG_ERR,
    293296                QString("GetNextFreeFrame() unable to "
    294297                        "lock frame %1 times. Discarding Frames.")
  • mythtv/libs/libmythtv/videodisplayprofile.cpp

    diff --git a/mythtv/libs/libmythtv/videodisplayprofile.cpp b/mythtv/libs/libmythtv/videodisplayprofile.cpp
    index 4aec35f421d..700ee3bb990 100644
    a b QString VideoDisplayProfile::GetDecoderName(const QString &decoder) 
    851851        dec_name["vaapi"]    = QObject::tr("VAAPI acceleration");
    852852        dec_name["dxva2"]    = QObject::tr("Windows hardware acceleration");
    853853        dec_name["vda"]      = QObject::tr("Mac VDA hardware acceleration");
     854        dec_name["mediacodec"] = QObject::tr("Android MediaCodec decoder");
    854855    }
    855856
    856857    QString ret = decoder;
    QString VideoDisplayProfile::GetDecoderHelp(QString decoder) 
    907908            "Openmax will use the graphics hardware to "
    908909            "accelerate video decoding on Raspberry Pi. ");
    909910
     911    if (decoder == "mediacodec")
     912        msg += QObject::tr(
     913            "Mediacodec will use the graphics hardware to "
     914            "accelerate video decoding on Android. ");
     915
    910916    return msg;
    911917}
    912918
    void VideoDisplayProfile::CreateProfiles(const QString &hostname) 
    14531459                      "");
    14541460    }
    14551461#endif
     1462
     1463#ifdef USING_MEDIACODEC
     1464    if (!profiles.contains("MediaCodec Normal")) {
     1465        (void) QObject::tr("MediaCodec Normal",
     1466                           "Sample: MediaCodec Normal");
     1467        groupid = CreateProfileGroup("MediaCodec Normal", hostname);
     1468        CreateProfile(groupid, 1, "", "", "",
     1469                      "mediacodec", 4, true, "opengl",
     1470                      "opengl2", true,
     1471                      "none", "none",
     1472                      "");
     1473    }
     1474#endif
     1475
    14561476}
    14571477
    14581478QStringList VideoDisplayProfile::GetVideoRenderers(const QString &decoder)
  • mythtv/libs/libmythtv/videoout_opengl.cpp

    diff --git a/mythtv/libs/libmythtv/videoout_opengl.cpp b/mythtv/libs/libmythtv/videoout_opengl.cpp
    index af80727f7ef..7f1f38d275a 100644
    a b void VideoOutputOpenGL::GetRenderOptions(render_opts &opts, 
    3838        (*opts.safe_renderers)["crystalhd"].append("opengl");
    3939    if (opts.decoders->contains("openmax"))
    4040        (*opts.safe_renderers)["openmax"].append("opengl");
     41    if (opts.decoders->contains("mediacodec"))
     42        (*opts.safe_renderers)["mediacodec"].append("opengl");
    4143    opts.priorities->insert("opengl", 65);
    4244
    4345    // lite profile - no colourspace control, GPU deinterlacing
    bool VideoOutputOpenGL::SetupOpenGL(void) 
    417419                                  window.GetVideoDispDim(), dvr,
    418420                                  window.GetDisplayVideoRect(),
    419421                                  window.GetVideoRect(), true,
    420                                   options, !codec_is_std(video_codec_id));
     422                                  options, !codec_sw_copy(video_codec_id));
    421423    if (success)
    422424    {
    423425        bool temp_deinterlacing = m_deinterlacing;
    void VideoOutputOpenGL::CreatePainter(void) 
    473475bool VideoOutputOpenGL::CreateBuffers(void)
    474476{
    475477    QMutexLocker locker(&gl_context_lock);
    476     vbuffers.Init(31, true, 1, 12, 4, 2);
     478    if (codec_is_mediacodec(video_codec_id))
     479        vbuffers.Init(40, true, 10, 12, 4, 2);
     480    else
     481        vbuffers.Init(31, true, 1, 12, 4, 2);
    477482    return vbuffers.CreateBuffers(FMT_YV12,
    478483                                  window.GetVideoDim().width(),
    479484                                  window.GetVideoDim().height());
    void VideoOutputOpenGL::ProcessFrame(VideoFrame *frame, OSD */*osd*/, 
    525530        gl_valid = true;
    526531    }
    527532
    528     bool sw_frame = codec_is_std(video_codec_id) &&
     533    bool sw_frame = codec_sw_copy(video_codec_id) &&
    529534                    video_codec_id != kCodec_NONE;
    530535    bool deint_proc = m_deinterlacing && (m_deintFilter != NULL);
    531536    OpenGLLocker ctx_lock(gl_context);
    QStringList VideoOutputOpenGL::GetAllowedRenderers( 
    735740    {
    736741        list << "opengl" << "opengl-lite";
    737742    }
     743    else if (codec_is_mediacodec(myth_codec_id) && !getenv("NO_OPENGL"))
     744    {
     745        list << "opengl";
     746    }
    738747
    739748    return list;
    740749}