Ticket #13311: 20180819_1111_vaaapi.patch

File 20180819_1111_vaaapi.patch, 25.0 KB (added by Peter Bennett, 6 years ago)

Preview very lightly tested first phase of new vaapi support

  • mythtv/configure

    diff --git a/mythtv/configure b/mythtv/configure
    index 07c67f7ebb5..2f1e147ddac 100755
    a b Advanced options (experts only): 
    134134  --disable-vdpau          disable NVidia VDPAU hardware acceleration.
    135135  --disable-crystalhd      disable Broadcom CrystalHD hardware decoder support
    136136  --disable-vaapi          disable VAAPI hardware accelerated video decoding
     137  --disable-vaapi2         disable VAAPI@ hardware accelerated video decoding
    137138  --disable-openmax        disable OpenMAX hardware accelerated video decoding
    138139  --disable-dxva2          disable hardware accelerated decoding on windows
    139140  --disable-mediacodec     disable hardware accelerated decoding on android
    HWACCEL_AUTODETECT_LIBRARY_LIST=" 
    14011402    crystalhd
    14021403    dxva2
    14031404    vaapi
     1405    vaapi2
    14041406    vda
    14051407    vdpau
    14061408"
    USING_LIST=' 
    20402042    opengl
    20412043    opengles
    20422044    vaapi
     2045    vaapi2
    20432046    vdpau
    20442047    openmax
    20452048    mediacodec
    if enabled x11 ; then 
    72737276  echo "xv support                ${xv-no}"
    72747277  echo "VDPAU support             ${vdpau-no}"
    72757278  echo "VAAPI support             ${vaapi-no}"
     7279  echo "VAAPI2 support            ${vaapi2-no}"
    72767280  echo "CrystalHD support         ${crystalhd-no}"
    72777281  echo "OpenMAX support           ${openmax-no}"
    72787282  if enabled openmax ; then
  • mythtv/libs/libmythtv/avformatdecoder.cpp

    diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
    index 6b9cca5663a..69a99ac4cc2 100644
    a b extern "C" { 
    7070#include <QtAndroidExtras>
    7171#endif
    7272
     73#ifdef USING_VAAPI2
     74#include "vaapi2context.h"
     75#endif
     76
    7377extern "C" {
    7478#include "libavutil/avutil.h"
    7579#include "libavutil/error.h"
    void AvFormatDecoder::GetDecoders(render_opts &opts) 
    385389    opts.decoders->append("vaapi");
    386390    (*opts.equiv_decoders)["vaapi"].append("dummy");
    387391#endif
     392#ifdef USING_VAAPI2
     393    opts.decoders->append("vaapi2");
     394    (*opts.equiv_decoders)["vaapi2"].append("dummy");
     395#endif
    388396#ifdef USING_MEDIACODEC
    389397    opts.decoders->append("mediacodec");
    390398    (*opts.equiv_decoders)["mediacodec"].append("dummy");
    enum AVPixelFormat get_format_dxva2(struct AVCodecContext *avctx, 
    15201528}
    15211529#endif
    15221530
    1523 #ifdef USING_VAAPI
     1531
    15241532static bool IS_VAAPI_PIX_FMT(enum AVPixelFormat fmt)
    15251533{
    15261534    return fmt == AV_PIX_FMT_VAAPI_MOCO ||
    static bool IS_VAAPI_PIX_FMT(enum AVPixelFormat fmt) 
    15281536           fmt == AV_PIX_FMT_VAAPI_VLD;
    15291537}
    15301538
     1539#ifdef USING_VAAPI
     1540
    15311541// Declared separately to allow attribute
    15321542static enum AVPixelFormat get_format_vaapi(struct AVCodecContext *,
    15331543                                         const enum AVPixelFormat *) MUNUSED;
    enum AVPixelFormat get_format_vaapi(struct AVCodecContext *avctx, 
    15541564}
    15551565#endif
    15561566
     1567#ifdef USING_VAAPI2
     1568static enum AVPixelFormat get_format_vaapi2(struct AVCodecContext *avctx,
     1569                                           const enum AVPixelFormat *valid_fmts)
     1570{
     1571    enum AVPixelFormat ret = AV_PIX_FMT_NONE;
     1572    while (*valid_fmts != AV_PIX_FMT_NONE) {
     1573        if (IS_VAAPI_PIX_FMT(*valid_fmts))
     1574        {
     1575            ret = *valid_fmts;
     1576            break;
     1577        }
     1578        valid_fmts++;
     1579    }
     1580
     1581    // AVBufferRef* dev_ctx = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_VAAPI);
     1582    // AVBufferRef* frame_ctx = av_hwframe_ctx_alloc(dev_ctx);
     1583    // avctx->hw_frames_ctx = frame_ctx;
     1584    // avctx->hwaccel_context =
     1585    return ret;
     1586}
     1587#endif
     1588
    15571589#ifdef USING_MEDIACODEC
    15581590static enum AVPixelFormat get_format_mediacodec(struct AVCodecContext *avctx,
    15591591                                           const enum AVPixelFormat *valid_fmts)
    void AvFormatDecoder::InitVideoCodec(AVStream *stream, AVCodecContext *enc, 
    16341666    else
    16351667#endif
    16361668#ifdef USING_VAAPI
    1637     if (CODEC_IS_VAAPI(codec, enc))
     1669    if (CODEC_IS_VAAPI(codec, enc) && codec_is_vaapi(video_codec_id))
    16381670    {
    16391671        enc->get_buffer2     = get_avf_buffer_vaapi;
    16401672        enc->get_format      = get_format_vaapi;
    void AvFormatDecoder::InitVideoCodec(AVStream *stream, AVCodecContext *enc, 
    16491681        enc->slice_flags     = SLICE_FLAG_CODED_ORDER | SLICE_FLAG_ALLOW_FIELD;
    16501682    }
    16511683    else
     1684#endif
     1685#ifdef USING_VAAPI2
     1686    if (codec_is_vaapi2(video_codec_id))
     1687    {
     1688        enc->get_format      = get_format_vaapi2;
     1689        // TODO - check return code from following call
     1690        Vaapi2Context::HwDecoderInit(enc);
     1691    }
     1692    else
    16521693#endif
    16531694    if (codec && codec->capabilities & AV_CODEC_CAP_DR1)
    16541695    {
    int AvFormatDecoder::ScanStreams(bool novideo) 
    25422583                        foundgpudecoder = true;
    25432584                    }
    25442585                }
     2586#endif // USING_MEDIACODEC
     2587#ifdef USING_VAAPI2
     2588                if (!foundgpudecoder)
     2589                {
     2590                    MythCodecID vaapi2_mcid;
     2591                    AVPixelFormat pix_fmt = AV_PIX_FMT_YUV420P;
     2592                    vaapi2_mcid = Vaapi2Context::GetBestSupportedCodec(
     2593                        &codec, dec, mpeg_version(enc->codec_id),
     2594                        pix_fmt);
     2595
     2596                    if (codec_is_vaapi2(vaapi2_mcid))
     2597                    {
     2598                        gCodecMap->freeCodecContext(ic->streams[selTrack]);
     2599                        enc = gCodecMap->getCodecContext(ic->streams[selTrack], codec);
     2600                        video_codec_id = vaapi2_mcid;
     2601                        foundgpudecoder = true;
     2602                    }
     2603                }
    25452604#endif // USING_MEDIACODEC
    25462605            }
    25472606            // default to mpeg2
    int AvFormatDecoder::ScanStreams(bool novideo) 
    25632622
    25642623            use_frame_timing = false;
    25652624            if (! private_dec
    2566                 && (codec_is_std(video_codec_id) || codec_is_mediacodec(video_codec_id)))
     2625                && (codec_is_std(video_codec_id)
     2626                    || codec_is_mediacodec(video_codec_id))
     2627                    || codec_is_vaapi2(video_codec_id))
    25672628                use_frame_timing = true;
    25682629
    25692630            if (FlagIsSet(kDecodeSingleThreaded))
    bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic) 
    38473908    }
    38483909    else if (!directrendering)
    38493910    {
     3911        AVFrame *tmp_frame = NULL;
     3912
     3913        if (IS_VAAPI_PIX_FMT((AVPixelFormat)mpa_pic->format))
     3914        {
     3915            int ret = 0;
     3916            tmp_frame = av_frame_alloc();
     3917            /* retrieve data from GPU to CPU */
     3918            if ((ret = av_hwframe_transfer_data(tmp_frame, mpa_pic, 0)) < 0) {
     3919                LOG(VB_GENERAL, LOG_ERR, LOC
     3920                    + QString("Error %1 transferring the data to system memory")
     3921                        .arg(ret));
     3922                av_frame_free(&tmp_frame);
     3923                return false;
     3924            }
     3925        }
     3926        else
     3927            tmp_frame = mpa_pic;
     3928
    38503929        AVFrame tmppicture;
    38513930
    38523931        VideoFrame *xf = picframe;
    bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic) 
    38543933
    38553934        unsigned char *buf = picframe->buf;
    38563935        av_image_fill_arrays(tmppicture.data, tmppicture.linesize,
    3857             buf, AV_PIX_FMT_YUV420P, context->width,
    3858                        context->height, IMAGE_ALIGN);
     3936            buf, AV_PIX_FMT_YUV420P, tmp_frame->width,
     3937                       tmp_frame->height, IMAGE_ALIGN);
    38593938        tmppicture.data[0] = buf + picframe->offsets[0];
    38603939        tmppicture.data[1] = buf + picframe->offsets[1];
    38613940        tmppicture.data[2] = buf + picframe->offsets[2];
    bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic) 
    38643943        tmppicture.linesize[2] = picframe->pitches[2];
    38653944
    38663945        QSize dim = get_video_dim(*context);
    3867         sws_ctx = sws_getCachedContext(sws_ctx, context->width,
    3868                                        context->height, context->pix_fmt,
    3869                                        context->width, context->height,
     3946        sws_ctx = sws_getCachedContext(sws_ctx, tmp_frame->width,
     3947                                       tmp_frame->height, (AVPixelFormat)tmp_frame->format,
     3948                                       tmp_frame->width, tmp_frame->height,
    38703949                                       AV_PIX_FMT_YUV420P, SWS_FAST_BILINEAR,
    38713950                                       NULL, NULL, NULL);
    38723951        if (!sws_ctx)
    bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic) 
    38743953            LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to allocate sws context");
    38753954            return false;
    38763955        }
    3877         sws_scale(sws_ctx, mpa_pic->data, mpa_pic->linesize, 0, dim.height(),
     3956        sws_scale(sws_ctx, tmp_frame->data, tmp_frame->linesize, 0, dim.height(),
    38783957                  tmppicture.data, tmppicture.linesize);
    38793958
    38803959        if (xf)
    bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic) 
    38873966            xf->aspect = current_aspect;
    38883967            m_parent->DiscardVideoFrame(xf);
    38893968        }
     3969        if (tmp_frame)
     3970            av_frame_free(&tmp_frame);
    38903971    }
    38913972    else if (!picframe)
    38923973    {
  • mythtv/libs/libmythtv/libmythtv.pro

    diff --git a/mythtv/libs/libmythtv/libmythtv.pro b/mythtv/libs/libmythtv/libmythtv.pro
    index 939ca20984b..75efa55ec13 100644
    a b using_frontend { 
    505505        using_opengl_video:DEFINES += USING_GLVAAPI
    506506    }
    507507
     508    using_vaapi2 {
     509        DEFINES += USING_VAAPI2
     510        HEADERS += vaapi2context.h
     511        SOURCES += vaapi2context.cpp
     512    }
     513
    508514    using_mediacodec {
    509515        DEFINES += USING_MEDIACODEC
    510516        HEADERS += mediacodeccontext.h
  • mythtv/libs/libmythtv/mythcodecid.cpp

    diff --git a/mythtv/libs/libmythtv/mythcodecid.cpp b/mythtv/libs/libmythtv/mythcodecid.cpp
    index b2023512b5f..cff4ba03585 100644
    a b QString toString(MythCodecID codecid) 
    123123        case kCodec_HEVC_MEDIACODEC:
    124124            return "HEVC MEDIACODEC";
    125125
     126        case kCodec_MPEG1_VAAPI2:
     127            return "MPEG1 VAAPI2";
     128        case kCodec_MPEG2_VAAPI2:
     129            return "MPEG2 VAAPI2";
     130        case kCodec_H263_VAAPI2:
     131            return "H.263 VAAPI2";
     132        case kCodec_MPEG4_VAAPI2:
     133            return "MPEG4 VAAPI2";
     134        case kCodec_H264_VAAPI2:
     135            return "H.264 VAAPI2";
     136        case kCodec_VC1_VAAPI2:
     137            return "VC1 VAAPI2";
     138        case kCodec_WMV3_VAAPI2:
     139            return "WMV3 VAAPI2";
     140        case kCodec_VP8_VAAPI2:
     141            return "VP8 VAAPI2";
     142        case kCodec_VP9_VAAPI2:
     143            return "VP9 VAAPI2";
     144        case kCodec_HEVC_VAAPI2:
     145            return "HEVC VAAPI2";
     146
    126147        default:
    127148            break;
    128149    }
    int myth2av_codecid(MythCodecID codec_id, bool &vdpau) 
    305326            ret = AV_CODEC_ID_HEVC;
    306327            break;
    307328
     329        case kCodec_MPEG1_VAAPI2:
     330            ret = AV_CODEC_ID_MPEG1VIDEO;
     331            break;
     332        case kCodec_MPEG2_VAAPI2:
     333            ret = AV_CODEC_ID_MPEG2VIDEO;
     334            break;
     335        case kCodec_H263_VAAPI2:
     336            ret = AV_CODEC_ID_H263;
     337            break;
     338        case kCodec_MPEG4_VAAPI2:
     339            ret = AV_CODEC_ID_MPEG4;
     340            break;
     341        case kCodec_H264_VAAPI2:
     342            ret = AV_CODEC_ID_H264;
     343            break;
     344        case kCodec_VC1_VAAPI2:
     345            ret = AV_CODEC_ID_VC1;
     346            break;
     347        case kCodec_WMV3_VAAPI2:
     348            ret = AV_CODEC_ID_WMV3;
     349            break;
     350        case kCodec_VP8_VAAPI2:
     351            ret = AV_CODEC_ID_VP8;
     352            break;
     353        case kCodec_VP9_VAAPI2:
     354            ret = AV_CODEC_ID_VP9;
     355            break;
     356        case kCodec_HEVC_VAAPI2:
     357            ret = AV_CODEC_ID_HEVC;
     358            break;
     359
    308360        default:
    309361            LOG(VB_GENERAL, LOG_ERR,
    310362                QString("Error: MythCodecID %1 has not been "
    QString get_encoding_type(MythCodecID codecid) 
    356408        case kCodec_MPEG1_VAAPI:
    357409        case kCodec_MPEG1_DXVA2:
    358410        case kCodec_MPEG1_MEDIACODEC:
     411        case kCodec_MPEG1_VAAPI2:
    359412        case kCodec_MPEG2:
    360413        case kCodec_MPEG2_VDPAU:
    361414        case kCodec_MPEG2_VAAPI:
    362415        case kCodec_MPEG2_DXVA2:
    363416        case kCodec_MPEG2_MEDIACODEC:
     417        case kCodec_MPEG2_VAAPI2:
    364418            return "MPEG-2";
    365419
    366420        case kCodec_H263:
    QString get_encoding_type(MythCodecID codecid) 
    368422        case kCodec_H263_VAAPI:
    369423        case kCodec_H263_DXVA2:
    370424        case kCodec_H263_MEDIACODEC:
     425        case kCodec_H263_VAAPI2:
    371426            return "H.263";
    372427
    373428        case kCodec_NUV_MPEG4:
    QString get_encoding_type(MythCodecID codecid) 
    376431        case kCodec_MPEG4_VAAPI:
    377432        case kCodec_MPEG4_DXVA2:
    378433        case kCodec_MPEG4_MEDIACODEC:
     434        case kCodec_MPEG4_VAAPI2:
    379435            return "MPEG-4";
    380436
    381437        case kCodec_H264:
    QString get_encoding_type(MythCodecID codecid) 
    383439        case kCodec_H264_VAAPI:
    384440        case kCodec_H264_DXVA2:
    385441        case kCodec_H264_MEDIACODEC:
     442        case kCodec_H264_VAAPI2:
    386443            return "H.264";
    387444
    388445        case kCodec_VC1:
    QString get_encoding_type(MythCodecID codecid) 
    390447        case kCodec_VC1_VAAPI:
    391448        case kCodec_VC1_DXVA2:
    392449        case kCodec_VC1_MEDIACODEC:
     450        case kCodec_VC1_VAAPI2:
    393451            return "VC-1";
    394452
    395453        case kCodec_WMV3:
    QString get_encoding_type(MythCodecID codecid) 
    397455        case kCodec_WMV3_VAAPI:
    398456        case kCodec_WMV3_DXVA2:
    399457        case kCodec_WMV3_MEDIACODEC:
     458        case kCodec_WMV3_VAAPI2:
    400459            return "WMV3";
    401460
    402461        case kCodec_VP8:
    QString get_encoding_type(MythCodecID codecid) 
    404463        case kCodec_VP8_VAAPI:
    405464        case kCodec_VP8_DXVA2:
    406465        case kCodec_VP8_MEDIACODEC:
     466        case kCodec_VP8_VAAPI2:
    407467            return "VP8";
    408468
    409469        case kCodec_VP9:
    QString get_encoding_type(MythCodecID codecid) 
    411471        case kCodec_VP9_VAAPI:
    412472        case kCodec_VP9_DXVA2:
    413473        case kCodec_VP9_MEDIACODEC:
     474        case kCodec_VP9_VAAPI2:
    414475            return "VP8";
    415476
    416477        case kCodec_HEVC:
    QString get_encoding_type(MythCodecID codecid) 
    418479        case kCodec_HEVC_VAAPI:
    419480        case kCodec_HEVC_DXVA2:
    420481        case kCodec_HEVC_MEDIACODEC:
     482        case kCodec_HEVC_VAAPI2:
    421483            return "HEVC";
    422484
    423485        case kCodec_NONE:
    QString get_encoding_type(MythCodecID codecid) 
    426488        case kCodec_VAAPI_END:
    427489        case kCodec_DXVA2_END:
    428490        case kCodec_MEDIACODEC_END:
     491        case kCodec_VAAPI2_END:
    429492            return QString();
    430493    }
    431494
    QString get_decoder_name(MythCodecID codec_id) 
    446509    if (codec_is_mediacodec(codec_id))
    447510        return "mediacodec";
    448511
     512    if (codec_is_vaapi2(codec_id))
     513        return "vaapi2";
     514
    449515    return "ffmpeg";
    450516}
  • mythtv/libs/libmythtv/mythcodecid.h

    diff --git a/mythtv/libs/libmythtv/mythcodecid.h b/mythtv/libs/libmythtv/mythcodecid.h
    index ce3620467d9..f1d225d4beb 100644
    a b typedef enum 
    9191
    9292    kCodec_MEDIACODEC_END,
    9393
     94    kCodec_VAAPI2_BEGIN = kCodec_MEDIACODEC_END,
     95
     96    kCodec_MPEG1_VAAPI2,
     97    kCodec_MPEG2_VAAPI2,
     98    kCodec_H263_VAAPI2,
     99    kCodec_MPEG4_VAAPI2,
     100    kCodec_H264_VAAPI2,
     101    kCodec_VC1_VAAPI2,
     102    kCodec_WMV3_VAAPI2,
     103    kCodec_VP8_VAAPI2,
     104    kCodec_VP9_VAAPI2,
     105    kCodec_HEVC_VAAPI2,
     106
     107    kCodec_VAAPI2_END,
     108
    94109} MythCodecID;
    95110
    96111// MythCodecID convenience functions
    typedef enum 
    113128                                (id == kCodec_VC1_DXVA2)))
    114129#define codec_is_mediacodec(id) ((id > kCodec_MEDIACODEC_BEGIN) &&     \
    115130                               (id < kCodec_MEDIACODEC_END))
     131#define codec_is_vaapi2(id)    ((id > kCodec_VAAPI2_BEGIN) &&     \
     132                               (id < kCodec_VAAPI2_END))
    116133
    117 #define codec_sw_copy(id) (codec_is_std(id) || codec_is_mediacodec(id))
     134#define codec_sw_copy(id) (codec_is_std(id) || codec_is_mediacodec(id) || codec_is_vaapi2(id))
    118135
    119136QString get_encoding_type(MythCodecID codecid);
    120137QString get_decoder_name(MythCodecID codec_id);
    int mpeg_version(int codec_id); 
    156173#define CODEC_IS_MEDIACODEC(codec) (0)
    157174#endif
    158175
    159 #define CODEC_IS_HWACCEL(codec, enc) (CODEC_IS_VDPAU(codec)      ||     \
    160                                       CODEC_IS_VAAPI(codec, enc) ||     \
    161                                       CODEC_IS_DXVA2(codec, enc) ||    \
    162                                       CODEC_IS_MEDIACODEC(codec))
    163 
    164176#endif // _MYTH_CODEC_ID_H_
  • new file mythtv/libs/libmythtv/vaapi2context.cpp

    diff --git a/mythtv/libs/libmythtv/vaapi2context.cpp b/mythtv/libs/libmythtv/vaapi2context.cpp
    new file mode 100644
    index 00000000000..2cd275b36b9
    - +  
     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 "vaapi2context.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("VAAPI2: ")
     36
     37MythCodecID Vaapi2Context::GetBestSupportedCodec(
     38    AVCodec **ppCodec,
     39    const QString &decoder,
     40    uint stream_type,
     41    AVPixelFormat &pix_fmt)
     42{
     43    enum AVHWDeviceType type = AV_HWDEVICE_TYPE_VAAPI;
     44
     45    AVPixelFormat fmt = AV_PIX_FMT_NONE;
     46    if (decoder == "vaapi2")
     47    {
     48        for (int i = 0;; i++) {
     49            const AVCodecHWConfig *config = avcodec_get_hw_config(*ppCodec, i);
     50            if (!config) {
     51                LOG(VB_PLAYBACK, LOG_INFO, LOC +
     52                    QString("Decoder %1 does not support device type %2.")
     53                        .arg((*ppCodec)->name).arg(av_hwdevice_get_type_name(type)));
     54                break;
     55            }
     56            if (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX &&
     57                config->device_type == type) {
     58                fmt = config->pix_fmt;
     59                break;
     60            }
     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_VAAPI2 + (stream_type - 1));
     72    }
     73}
     74
     75int Vaapi2Context::HwDecoderInit(AVCodecContext *ctx)
     76{
     77    int ret = 0;
     78    AVBufferRef *hw_device_ctx = NULL;
     79
     80    ret = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_VAAPI,
     81                                      NULL, NULL, 0);
     82    if (ret < 0)
     83    {
     84        char error[AV_ERROR_MAX_STRING_SIZE];
     85        LOG(VB_GENERAL, LOG_ERR, LOC +
     86            QString("av_hwdevice_ctx_create error: %1 (%2)")
     87            .arg(av_make_error_string(error, sizeof(error), ret))
     88            .arg(ret));
     89    }
     90    else
     91        ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);
     92
     93    return ret;
     94}
  • new file mythtv/libs/libmythtv/vaapi2context.h

    diff --git a/mythtv/libs/libmythtv/vaapi2context.h b/mythtv/libs/libmythtv/vaapi2context.h
    new file mode 100644
    index 00000000000..d8d9408530a
    - +  
     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 VAAPI2CONTEXT_H
     27#define VAAPI2CONTEXT_H
     28
     29#include "mythcodecid.h"
     30
     31extern "C" {
     32    #include "libavcodec/avcodec.h"
     33}
     34
     35class Vaapi2Context
     36{
     37  public:
     38    static MythCodecID GetBestSupportedCodec(AVCodec **ppCodec,
     39                                             const QString &decoder,
     40                                             uint stream_type,
     41                                             AVPixelFormat &pix_fmt);
     42    static int HwDecoderInit(AVCodecContext *ctx);
     43};
     44
     45#endif // VIDEOOUTOPENGLMEDIACODEC_H
     46 No newline at end of file
  • mythtv/libs/libmythtv/videodisplayprofile.cpp

    diff --git a/mythtv/libs/libmythtv/videodisplayprofile.cpp b/mythtv/libs/libmythtv/videodisplayprofile.cpp
    index 700ee3bb990..5afdc0f2282 100644
    a b QString VideoDisplayProfile::GetDecoderName(const QString &decoder) 
    852852        dec_name["dxva2"]    = QObject::tr("Windows hardware acceleration");
    853853        dec_name["vda"]      = QObject::tr("Mac VDA hardware acceleration");
    854854        dec_name["mediacodec"] = QObject::tr("Android MediaCodec decoder");
     855        dec_name["vaapi2"]   = QObject::tr("VAAPI2 acceleration");
    855856    }
    856857
    857858    QString ret = decoder;
    QString VideoDisplayProfile::GetDecoderHelp(QString decoder) 
    913914            "Mediacodec will use the graphics hardware to "
    914915            "accelerate video decoding on Android. ");
    915916
     917    if (decoder == "vaapi2")
     918        msg += QObject::tr(
     919            "VAAPI2 is a new implemtation of VAAPI to will use the graphics hardware to "
     920            "accelerate video decoding on Android. ");
     921
    916922    return msg;
    917923}
    918924
    void VideoDisplayProfile::CreateProfiles(const QString &hostname) 
    14681474        CreateProfile(groupid, 1, "", "", "",
    14691475                      "mediacodec", 4, true, "opengl",
    14701476                      "opengl2", true,
     1477                      "opengldoubleratelinearblend", "opengllinearblend",
     1478                      "");
     1479    }
     1480#endif
     1481
     1482#ifdef USING_VAAPI2
     1483    if (!profiles.contains("VAAPI2 Normal")) {
     1484        (void) QObject::tr("VAAPI2 Normal",
     1485                           "Sample: VAAPI2 Normal");
     1486        groupid = CreateProfileGroup("VAAPI2 Normal", hostname);
     1487        CreateProfile(groupid, 1, "", "", "",
     1488                      "vaapi2", 4, true, "opengl",
     1489                      "opengl2", true,
    14711490                      "none", "none",
    14721491                      "");
    14731492    }
  • mythtv/libs/libmythtv/videoout_opengl.cpp

    diff --git a/mythtv/libs/libmythtv/videoout_opengl.cpp b/mythtv/libs/libmythtv/videoout_opengl.cpp
    index b689947d738..b287086009e 100644
    a b void VideoOutputOpenGL::GetRenderOptions(render_opts &opts, 
    4040        (*opts.safe_renderers)["openmax"].append("opengl");
    4141    if (opts.decoders->contains("mediacodec"))
    4242        (*opts.safe_renderers)["mediacodec"].append("opengl");
     43    if (opts.decoders->contains("vaapi2"))
     44        (*opts.safe_renderers)["vaapi2"].append("opengl");
    4345    opts.priorities->insert("opengl", 65);
    4446
    4547    // lite profile - no colourspace control, GPU deinterlacing
    bool VideoOutputOpenGL::InputChanged(const QSize &video_dim_buf, 
    270272        StopEmbedding();
    271273    }
    272274
    273     if (!codec_is_std(av_codec_id) && !codec_is_mediacodec(av_codec_id))
     275    if (!codec_is_std(av_codec_id)
     276        && !codec_is_mediacodec(av_codec_id)
     277        && !codec_is_vaapi2(av_codec_id))
    274278    {
    275279        LOG(VB_GENERAL, LOG_ERR, LOC + "New video codec is not supported.");
    276280        errorState = kError_Unknown;
    QStringList VideoOutputOpenGL::GetAllowedRenderers( 
    741745    {
    742746        list << "opengl" << "opengl-lite";
    743747    }
    744     else if (codec_is_mediacodec(myth_codec_id) && !getenv("NO_OPENGL"))
     748    else if ((codec_is_mediacodec(myth_codec_id) || codec_is_vaapi2(myth_codec_id))
     749            && !getenv("NO_OPENGL"))
    745750    {
    746751        list << "opengl";
    747752    }