Ticket #8593: vaapi_v1.diff
| File vaapi_v1.diff, 40.4 KB (added by markk, 2 years ago) |
|---|
-
configure
128 128 --enable-xvmc-vld enable XvMC VLD accel. for the Unichrome (Pro) chipset 129 129 --xvmc-lib=LIB XvMC library override (for crosscompiling) 130 130 --enable-vdpau enable NVidia VDPAU hardware acceleration. 131 --enable-vaapi enable VAAPI hardware acceleration 131 132 --disable-opengl-video disable OpenGL based video display 132 133 --enable-mac-accel enable Mac OS X MPEG acceleration 133 134 --disable-opengl-vsync disable OpenGL vsync method … … 1336 1337 dvdv 1337 1338 opengl 1338 1339 vdpau 1340 vaapi 1339 1341 ' 1340 1342 1341 1343 CMDLINE_SELECT=" … … 1678 1680 xvmc_deps="xv X11_extensions_XvMClib_h" 1679 1681 xvmc_vld_deps="xvmc X11_extensions_vldXvMC_h" 1680 1682 xvmcw_deps="xvmc" 1683 vaapi_deps="opengl_video" 1681 1684 1682 1685 # default parameters 1683 1686 pre_logfile="config.ep" … … 3394 3397 check_header termios.h 3395 3398 check_header vdpau/vdpau.h 3396 3399 check_header vdpau/vdpau_x11.h 3400 check_header va/va.h 3401 check_header va/va_x11.h 3397 3402 check_header X11/extensions/XvMClib.h 3398 3403 3399 3404 check_struct dxva2api.h DXVA_PictureParameters wDecodedPictureIndex … … 3662 3667 disable vdpau; } 3663 3668 fi 3664 3669 3670 if ! disabled vaapi && enabled va_va_h; then 3671 enable vaapi 3672 fi 3673 3665 3674 enabled debug && add_cflags -g"$debuglevel" && add_asflags -g"$debuglevel" 3666 3675 enabled debug && add_cxxflags -g"$debuglevel" 3667 3676 … … 4219 4228 echo "XvMC libs $VENDOR_XVMC_LIBS" 4220 4229 fi 4221 4230 echo "VDPAU support ${vdpau-no}" 4231 echo "VAAPI support ${vaapi-no}" 4222 4232 fi 4223 4233 echo "OpenGL video ${opengl_video-no}" 4224 4234 if test x"$target_os" = x"darwin" ; then -
libs/libmythtv/videoout_openglvaapi.h
1 #ifndef VIDEOOUTPUTOPENGLVAAPI_H 2 #define VIDEOOUTPUTOPENGLVAAPI_H 3 4 #include "videoout_opengl.h" 5 #include "vaapicontext.h" 6 7 class VideoOutputOpenGLVAAPI : public VideoOutputOpenGL 8 { 9 public: 10 static void GetRenderOptions(render_opts &opts, QStringList &cpudeints); 11 12 VideoOutputOpenGLVAAPI(MythCodecID codec_id); 13 ~VideoOutputOpenGLVAAPI(); 14 15 bool Init(int width, int height, float aspect, WId winid, 16 int winx, int winy, int winw, int winh, WId embedid = 0); 17 bool InitVAAPIContext(QSize size); 18 bool CreateBuffers(void); 19 void* GetVAAPIContext(void); 20 void SetProfile(void); 21 virtual void TearDown(void); 22 virtual bool InputChanged(const QSize &input_size, float aspect, 23 MythCodecID av_codec_id, void *codec_private, 24 bool &aspect_only); 25 uint8_t* GetSurfaceIDPointer(void* buf); 26 void ProcessFrame(VideoFrame *frame, OSD *osd, 27 FilterChain *filterList, 28 const PIPMap &pipPlayers, 29 FrameScanType scan); 30 void Show(FrameScanType ); 31 32 static QStringList GetAllowedRenderers(MythCodecID myth_codec_id, 33 const QSize &video_dim); 34 static MythCodecID GetBestSupportedCodec(uint width, uint height, 35 uint stream_type, 36 bool no_acceleration, 37 PixelFormat &pix_fmt); 38 39 private: 40 MythCodecID m_codec_id; 41 VAAPIContext *m_ctx; 42 }; 43 44 #endif // VIDEOOUTPUTOPENGLVAAPI_H 45 -
libs/libmythtv/videoout_opengl.cpp
9 9 #include "mythuihelper.h" 10 10 11 11 #define LOC QString("VidOutOGL: ") 12 #define LOC_ERR QString("VidOutOGL : ")12 #define LOC_ERR QString("VidOutOGL Error: ") 13 13 14 14 void VideoOutputOpenGL::GetRenderOptions(render_opts &opts, 15 15 QStringList &cpudeints) 16 16 { 17 17 opts.renderers->append("opengl"); 18 18 opts.deints->insert("opengl", cpudeints); 19 (*opts.deints)["opengl"].append("opengllinearblend");20 (*opts.deints)["opengl"].append("openglonefield");21 (*opts.deints)["opengl"].append("openglkerneldeint");22 19 (*opts.deints)["opengl"].append("bobdeint"); 23 (*opts.deints)["opengl"].append("openglbobdeint"); 24 (*opts.deints)["opengl"].append("opengldoubleratelinearblend"); 25 (*opts.deints)["opengl"].append("opengldoubleratekerneldeint"); 26 (*opts.deints)["opengl"].append("opengldoubleratefieldorder"); 27 (*opts.deints)["opengl"].append("opengldoublerateyadif"); 28 (*opts.deints)["opengl"].append("openglyadif"); 20 opts.deints->insert("opengl", VideoOutputOpenGL::GetOpenGLDeints()); 29 21 (*opts.osds)["opengl"].append("softblend"); 30 22 (*opts.osds)["opengl"].append("opengl2"); 31 23 (*opts.safe_renderers)["dummy"].append("opengl"); … … 37 29 opts.priorities->insert("opengl", 65); 38 30 } 39 31 32 QStringList VideoOutputOpenGL::GetOpenGLDeints(void) 33 { 34 QStringList result; 35 result.append("opengllinearblend"); 36 result.append("openglonefield"); 37 result.append("openglkerneldeint"); 38 result.append("openglbobdeint"); 39 result.append("opengldoubleratelinearblend"); 40 result.append("opengldoubleratekerneldeint"); 41 result.append("opengldoubleratefieldorder"); 42 result.append("opengldoublerateyadif"); 43 result.append("openglyadif"); 44 return result; 45 } 46 40 47 VideoOutputOpenGL::VideoOutputOpenGL(void) 41 48 : VideoOutput(), 42 49 gl_context_lock(QMutex::Recursive), … … 123 130 winid, winx, winy, winw, winh, 124 131 embedid); 125 132 126 if (db_vdisp_profile) 127 db_vdisp_profile->SetVideoRenderer("opengl"); 133 SetProfile(); 128 134 129 135 success &= SetupContext(); 130 136 InitDisplayMeasurements(width, height, false); 131 137 success &= CreateBuffers(); 138 success &= CreatePauseFrame(); 132 139 success &= SetupOpenGL(); 133 140 134 141 InitOSD(); … … 144 151 return success; 145 152 } 146 153 154 void VideoOutputOpenGL::SetProfile(void) 155 { 156 if (db_vdisp_profile) 157 db_vdisp_profile->SetVideoRenderer("opengl"); 158 } 159 147 160 bool VideoOutputOpenGL::InputChanged(const QSize &input_size, 148 161 float aspect, 149 162 MythCodecID av_codec_id, … … 276 289 bool VideoOutputOpenGL::CreateBuffers(void) 277 290 { 278 291 QMutexLocker locker(&gl_context_lock); 279 280 bool success = true;281 292 vbuffers.Init(31, true, 1, 12, 4, 2, false); 282 success &= vbuffers.CreateBuffers(windows[0].GetVideoDim().width(), 283 windows[0].GetVideoDim().height()); 293 return vbuffers.CreateBuffers(windows[0].GetVideoDim().width(), 294 windows[0].GetVideoDim().height()); 295 } 284 296 297 bool VideoOutputOpenGL::CreatePauseFrame(void) 298 { 285 299 av_pause_frame.height = vbuffers.GetScratchFrame()->height; 286 300 av_pause_frame.width = vbuffers.GetScratchFrame()->width; 287 301 av_pause_frame.bpp = vbuffers.GetScratchFrame()->bpp; … … 290 304 av_pause_frame.frameNumber = vbuffers.GetScratchFrame()->frameNumber; 291 305 292 306 if (!av_pause_frame.buf) 293 { 294 success = false; 295 } 296 else 297 { 298 int size = av_pause_frame.width * av_pause_frame.height; 299 memset(av_pause_frame.buf, 0, size); 300 memset(av_pause_frame.buf + size, 127, size / 2); 301 } 307 return false; 302 308 303 return success; 309 int size = av_pause_frame.width * av_pause_frame.height; 310 memset(av_pause_frame.buf, 0, size); 311 memset(av_pause_frame.buf + size, 127, size / 2); 312 return true; 304 313 } 305 314 306 315 void VideoOutputOpenGL::ProcessFrame(VideoFrame *frame, OSD *osd, … … 371 380 framesPlayed = buffer->frameNumber + 1; 372 381 gl_context_lock.unlock(); 373 382 374 if (buffer->codec != FMT_YV12)375 return;383 //if (buffer->codec != FMT_YV12) 384 // return; 376 385 377 386 gl_videochain->SetVideoRect(vsz_enabled ? vsz_desired_display_rect : 378 387 windows[0].GetDisplayVideoRect(), -
libs/libmythtv/avformatdecoder.cpp
49 49 } 50 50 #endif // USING_VDPAU 51 51 52 #ifdef USING_VAAPI 53 #include "videoout_openglvaapi.h" 54 #endif // USING_VAAPI 55 52 56 extern "C" { 53 57 #include "avutil.h" 54 58 #include "ac3_parser.h" … … 92 96 void render_slice_vdpau(struct AVCodecContext *s, const AVFrame *src, 93 97 int offset[4], int y, int type, int height); 94 98 99 int get_avf_buffer_vaapi(struct AVCodecContext *c, AVFrame *pic); 100 95 101 static AVCodec *find_vdpau_decoder(AVCodec *c, enum CodecID id) 96 102 { 97 103 AVCodec *codec = c; … … 461 467 opts.decoders->append("vdpau"); 462 468 (*opts.equiv_decoders)["vdpau"].append("dummy"); 463 469 #endif 470 471 #ifdef USING_VAAPI 472 opts.decoders->append("vaapi"); 473 (*opts.equiv_decoders)["vaapi"].append("dummy"); 474 #endif 464 475 } 465 476 466 477 AvFormatDecoder::AvFormatDecoder(NuppelVideoPlayer *parent, … … 1368 1379 return fmt[i]; 1369 1380 } 1370 1381 1382 static bool IS_VAAPI_PIX_FMT(enum PixelFormat fmt) 1383 { 1384 return fmt == PIX_FMT_VAAPI_MOCO || 1385 fmt == PIX_FMT_VAAPI_IDCT || 1386 fmt == PIX_FMT_VAAPI_VLD; 1387 } 1388 1389 static enum PixelFormat get_format_vaapi(struct AVCodecContext *avctx, 1390 const enum PixelFormat *fmt) 1391 { 1392 if (!fmt) 1393 return PIX_FMT_NONE; 1394 int i = 0; 1395 for (; fmt[i] != PIX_FMT_NONE ; i++) 1396 if (IS_VAAPI_PIX_FMT(fmt[i])) 1397 break; 1398 return fmt[i]; 1399 } 1400 1371 1401 static bool IS_DR1_PIX_FMT(const enum PixelFormat fmt) 1372 1402 { 1373 1403 switch (fmt) … … 1439 1469 directrendering = true; 1440 1470 if ( 1441 1471 !gCoreContext->GetNumSetting("DecodeExtraAudio", 0) && 1442 !CODEC_IS_HWACCEL(codec)) 1472 !CODEC_IS_HWACCEL(codec)) // FIXME - no VAAPI 1443 1473 { 1444 1474 SetLowBuffers(false); 1445 1475 } … … 1473 1503 enc->draw_horiz_band = render_slice_vdpau; 1474 1504 enc->slice_flags = SLICE_FLAG_CODED_ORDER | SLICE_FLAG_ALLOW_FIELD; 1475 1505 } 1506 else if (codec && IS_VAAPI_PIX_FMT(enc->pix_fmt)) 1507 { 1508 enc->get_buffer = get_avf_buffer_vaapi; 1509 enc->get_format = get_format_vaapi; 1510 enc->release_buffer = release_avf_buffer; 1511 enc->slice_flags = SLICE_FLAG_CODED_ORDER | SLICE_FLAG_ALLOW_FIELD; // is this correct? 1512 } 1476 1513 else if (codec && codec->capabilities & CODEC_CAP_DR1) 1477 1514 { 1478 1515 enc->flags |= CODEC_FLAG_EMU_EDGE; … … 1955 1992 handled = true; 1956 1993 } 1957 1994 #endif // USING_VDPAU 1995 #ifdef USING_VAAPI 1996 MythCodecID vaapi_mcid; 1997 PixelFormat pix_fmt = PIX_FMT_YUV420P; 1998 vaapi_mcid = VideoOutputOpenGLVAAPI::GetBestSupportedCodec( 1999 width, height, mpeg_version(enc->codec_id), 2000 no_hardware_decoders, pix_fmt); 2001 2002 if (vaapi_mcid >= video_codec_id) 2003 { 2004 enc->codec_id = (CodecID)myth2av_codecid(vaapi_mcid); 2005 video_codec_id = vaapi_mcid; 2006 handled = true; 2007 enc->pix_fmt = pix_fmt; 2008 if (!no_hardware_decoders && 2009 codec_is_vaapi_hw(video_codec_id)) 2010 { 2011 enc->pix_fmt = pix_fmt; 2012 } 2013 } 2014 #endif // USING_VAAPI 1958 2015 #ifdef USING_XVMC 1959 2016 1960 2017 bool force_xv = no_hardware_decoders; … … 2673 2730 } 2674 2731 } 2675 2732 2733 int get_avf_buffer_vaapi(struct AVCodecContext *c, AVFrame *pic) 2734 { 2735 AvFormatDecoder *nd = (AvFormatDecoder *)(c->opaque); 2736 VideoFrame *frame = nd->GetNVP()->GetNextVideoFrame(false); 2737 2738 pic->data[0] = frame->buf; 2739 pic->data[1] = frame->priv[0]; 2740 pic->data[2] = frame->priv[1]; 2741 2742 pic->linesize[0] = 0; 2743 pic->linesize[1] = 0; 2744 pic->linesize[2] = 0; 2745 2746 pic->opaque = frame; 2747 pic->type = FF_BUFFER_TYPE_USER; 2748 2749 pic->age = 256 * 256 * 256 * 64; 2750 2751 frame->pix_fmt = c->pix_fmt; 2752 2753 #ifdef USING_VAAPI 2754 if (nd->GetNVP()->getVideoOutput()) 2755 { 2756 VideoOutputOpenGLVAAPI *vo = 2757 dynamic_cast<VideoOutputOpenGLVAAPI*>(nd->GetNVP()->getVideoOutput()); 2758 c->hwaccel_context = (vaapi_context*)vo->GetVAAPIContext(); 2759 pic->data[3] = vo->GetSurfaceIDPointer(frame->buf); 2760 } 2761 #endif 2762 2763 return 0; 2764 } 2765 2676 2766 void AvFormatDecoder::DecodeDTVCC(const uint8_t *buf, uint len) 2677 2767 { 2678 2768 if (!len) -
libs/libmythtv/videoout_openglvaapi.cpp
1 #include "videoout_openglvaapi.h" 2 3 #define LOC QString("VidOutVAAPI: ") 4 #define LOC_ERR QString("VidOutVAAPI Error: ") 5 6 void VideoOutputOpenGLVAAPI::GetRenderOptions(render_opts &opts, 7 QStringList &cpudeints) 8 { 9 opts.renderers->append("openglvaapi"); 10 opts.deints->insert("openglvaapi", VideoOutputOpenGL::GetOpenGLDeints()); 11 (*opts.osds)["openglvaapi"].append("opengl2"); 12 13 if (opts.decoders->contains("vaapi")) 14 (*opts.safe_renderers)["vaapi"].append("openglvaapi"); 15 16 opts.priorities->insert("openglvaapi", 110); 17 } 18 19 VideoOutputOpenGLVAAPI::VideoOutputOpenGLVAAPI(MythCodecID codec_id) 20 : VideoOutputOpenGL(), m_codec_id(codec_id), m_ctx(NULL) 21 { 22 if (gCoreContext->GetNumSetting("UseVideoModes", 0)) 23 display_res = DisplayRes::GetDisplayRes(true); 24 } 25 26 VideoOutputOpenGLVAAPI::~VideoOutputOpenGLVAAPI() 27 { 28 TearDown(); 29 } 30 31 void VideoOutputOpenGLVAAPI::TearDown(void) 32 { 33 VideoOutputOpenGL::TearDown(); 34 delete m_ctx; 35 } 36 37 bool VideoOutputOpenGLVAAPI::Init(int width, int height, float aspect, 38 WId winid, int winx, int winy, int winw, 39 int winh, WId embedid) 40 { 41 if (!InitVAAPIContext(QSize(width, height))) 42 return false; 43 return VideoOutputOpenGL::Init(width, height, aspect, winid, winx, winy, 44 winw, winh, embedid); 45 } 46 47 bool VideoOutputOpenGLVAAPI::InputChanged(const QSize &input_size, float aspect, 48 MythCodecID av_codec_id, void *codec_private, 49 bool &aspect_only) 50 { 51 VERBOSE(VB_PLAYBACK, LOC + QString("InputChanged(%1,%2,%3) %4") 52 .arg(input_size.width()).arg(input_size.height()).arg(aspect) 53 .arg(toString(av_codec_id))); 54 55 QMutexLocker locker(&gl_context_lock); 56 57 if (!codec_is_vaapi_hw(av_codec_id)) 58 { 59 VERBOSE(VB_IMPORTANT, LOC_ERR + 60 QString("New video codec is not supported.")); 61 errorState = kError_Unknown; 62 return false; 63 } 64 65 if (input_size == windows[0].GetVideoDim()) 66 { 67 if (windows[0].GetVideoAspect() != aspect) 68 { 69 aspect_only = true; 70 VideoAspectRatioChanged(aspect); 71 MoveResize(); 72 } 73 return true; 74 } 75 76 TearDown(); 77 QRect disp = windows[0].GetDisplayVisibleRect(); 78 if (Init(input_size.width(), input_size.height(), 79 aspect, gl_parent_win, disp.left(), disp.top(), 80 disp.width(), disp.height(), gl_embed_win)) 81 { 82 BestDeint(); 83 return true; 84 } 85 86 VERBOSE(VB_IMPORTANT, LOC_ERR + 87 QString("Failed to re-initialise video output.")); 88 errorState = kError_Unknown; 89 90 return false; 91 } 92 93 bool VideoOutputOpenGLVAAPI::InitVAAPIContext(QSize size) 94 { 95 m_ctx = new VAAPIContext(m_codec_id); 96 if (m_ctx && m_ctx->Create(size)) 97 return true; 98 return false; 99 } 100 101 bool VideoOutputOpenGLVAAPI::CreateBuffers(void) 102 { 103 if (!codec_is_vaapi_hw(m_codec_id) || !m_ctx) 104 return false; 105 106 QMutexLocker locker(&gl_context_lock); 107 int num_buffers = m_ctx->GetNumBuffers(); 108 const QSize video_dim = windows[0].GetVideoDim(); 109 vbuffers.Init(num_buffers, true, 2, 1, 4, 1, false); // shouldn't need pause frame 110 111 bool ok = true; 112 for (int i = 0; i < num_buffers; i++) 113 { 114 ok &= vbuffers.CreateBuffer(video_dim.width(), 115 video_dim.height(), i, 116 m_ctx->GetVideoSurface(i)); 117 } 118 return ok; 119 } 120 121 void* VideoOutputOpenGLVAAPI::GetVAAPIContext(void) 122 { 123 if (m_ctx) 124 return &m_ctx->m_ctx; 125 return NULL; 126 } 127 128 void VideoOutputOpenGLVAAPI::SetProfile(void) 129 { 130 if (db_vdisp_profile) 131 db_vdisp_profile->SetVideoRenderer("openglvaapi"); 132 } 133 134 uint8_t* VideoOutputOpenGLVAAPI::GetSurfaceIDPointer(void* buf) 135 { 136 if (m_ctx) 137 return m_ctx->GetSurfaceIDPointer(buf); 138 return NULL; 139 } 140 141 void VideoOutputOpenGLVAAPI::ProcessFrame(VideoFrame *frame, OSD *osd, 142 FilterChain *filterList, 143 const PIPMap &pipPlayers, 144 FrameScanType scan) 145 { 146 QMutexLocker locker(&gl_context_lock); 147 if (!gl_videochain || !gl_context) 148 return; 149 150 OpenGLLocker ctx_lock(gl_context); 151 152 if (!frame) 153 { 154 frame = vbuffers.GetScratchFrame(); 155 CopyFrame(vbuffers.GetScratchFrame(), &av_pause_frame); 156 } 157 158 if (!windows[0].IsEmbedding()) 159 { 160 gl_pipchain_active = NULL; 161 ShowPIPs(frame, pipPlayers); 162 } 163 164 if (m_ctx) 165 { 166 QRect disp = windows[0].GetDisplayVideoRect(); 167 m_ctx->ShowSurface(gl_parent_win, disp, frame->buf); 168 } 169 } 170 171 void VideoOutputOpenGLVAAPI::Show(FrameScanType scan) 172 { 173 } 174 175 QStringList VideoOutputOpenGLVAAPI::GetAllowedRenderers( 176 MythCodecID myth_codec_id, const QSize &video_dim) 177 { 178 (void) video_dim; 179 QStringList list; 180 if ((codec_is_std(myth_codec_id) || codec_is_vaapi_hw(myth_codec_id)) && 181 !getenv("NO_VAAPI")) 182 { 183 list += "openglvaapi"; 184 } 185 return list; 186 } 187 188 MythCodecID VideoOutputOpenGLVAAPI::GetBestSupportedCodec( 189 uint width, uint height, 190 uint stream_type, bool no_acceleration, 191 PixelFormat &pix_fmt) 192 { 193 QSize size(width, height); 194 bool use_cpu = no_acceleration; 195 VideoDisplayProfile vdp; 196 vdp.SetInput(size); 197 QString dec = vdp.GetDecoder(); 198 199 MythCodecID test_cid = (MythCodecID)(kCodec_MPEG1_VAAPI + (stream_type-1)); 200 use_cpu |= !codec_is_vaapi_hw(test_cid); 201 use_cpu |= !VAAPIContext::IsFormatAccelerated(size, test_cid, pix_fmt); 202 if ((dec != "vaapi") || getenv("NO_VAAPI") || use_cpu) 203 return (MythCodecID)(kCodec_MPEG1 + (stream_type-1)); 204 205 return test_cid; 206 } -
libs/libmythtv/libmythtv.pro
344 344 345 345 using_glx_proc_addr_arb:DEFINES += USING_GLX_PROC_ADDR_ARB 346 346 347 using_vaapi: DEFINES += USING_VAAPI 348 using_vaapi: DEFINES += videoout_openglvaapi.h vaapicontext.h 349 using_vaapi: SOURCES += videoout_openglvaapi.cpp vaapicontext.cpp 350 using_vaapi: LIBS += -lva -lva-x11 351 347 352 # Misc. frontend 348 353 HEADERS += DetectLetterbox.h 349 354 SOURCES += DetectLetterbox.cpp -
libs/libmythtv/vaapicontext.cpp
1 #include "mythverbose.h" 2 #include "mythxdisplay.h" 3 #include "mythcodecid.h" 4 5 #include "vaapicontext.h" 6 7 #define LOC QString("VAAPI: ") 8 #define LOC_ERR QString("VAAPI Error: ") 9 #define NUM_VAAPI_BUFFERS 20 10 11 #define INIT_ST \ 12 VAStatus va_status; \ 13 bool ok = true; 14 15 #define CHECK_ST \ 16 ok &= (va_status == VA_STATUS_SUCCESS); \ 17 if (!ok) { \ 18 VERBOSE(VB_GENERAL, LOC_ERR + QString("Error at %1:%2 (#%3, %4)") \ 19 .arg(__FILE__).arg( __LINE__).arg(va_status) \ 20 .arg(vaErrorStr(va_status))); \ 21 } 22 23 #define CREATE_CHECK(arg1, arg2) \ 24 if (ok) \ 25 { \ 26 ok = arg1; \ 27 if (!ok) \ 28 VERBOSE(VB_IMPORTANT, LOC_ERR + arg2); \ 29 } 30 31 QString profileToString(VAProfile profile) 32 { 33 if (VAProfileMPEG2Simple == profile) return "MPEG2Simple"; 34 if (VAProfileMPEG2Main == profile) return "MPEG2Main"; 35 if (VAProfileMPEG4Simple == profile) return "MPEG4Simple"; 36 if (VAProfileMPEG4AdvancedSimple == profile) return "MPEG4AdvSimple"; 37 if (VAProfileMPEG4Main == profile) return "MPEG4Main"; 38 if (VAProfileH264Baseline == profile) return "H264Base"; 39 if (VAProfileH264Main == profile) return "H264Main"; 40 if (VAProfileH264High == profile) return "H264High"; 41 if (VAProfileVC1Simple == profile) return "VC1Simple"; 42 if (VAProfileVC1Main == profile) return "VC1Main"; 43 if (VAProfileVC1Advanced == profile) return "VC1Advanced"; 44 if (VAProfileH263Baseline == profile) return "H263Base"; 45 return "Unknown"; 46 } 47 48 QString entryToString(VAEntrypoint entry) 49 { 50 if (VAEntrypointVLD == entry) return "VLD "; 51 if (VAEntrypointIZZ == entry) return "IZZ "; 52 if (VAEntrypointIDCT == entry) return "IDCT "; 53 if (VAEntrypointMoComp == entry) return "MC "; 54 if (VAEntrypointDeblocking == entry) return "Deblock (UNSUPPORTED) "; 55 if (VAEntrypointEncSlice == entry) return "EncSlice (UNSUPPORTED) "; 56 return "Unknown"; 57 } 58 59 VAProfile preferredProfile(MythCodecID codec) 60 { 61 // FIXME handle unsupported codecs properly 62 if (kCodec_H263_VAAPI == codec) return VAProfileH263Baseline; 63 if (kCodec_MPEG4_VAAPI == codec) return VAProfileMPEG4AdvancedSimple; 64 if (kCodec_H264_VAAPI == codec) return VAProfileH264High; 65 if (kCodec_VC1_VAAPI == codec) return VAProfileVC1Advanced; 66 if (kCodec_WMV3_VAAPI == codec) return VAProfileVC1Main; 67 return VAProfileMPEG2Main; 68 } 69 70 bool VAAPIContext::IsFormatAccelerated(QSize size, MythCodecID codec, 71 PixelFormat &pix_fmt) 72 { 73 bool result = false; 74 VAAPIContext *ctx = new VAAPIContext(codec); 75 if (ctx) 76 { 77 result = ctx->CreateDummy(size); 78 pix_fmt = ctx->GetPixelFormat(); 79 } 80 delete ctx; 81 return result; 82 } 83 84 VAAPIContext::VAAPIContext(MythCodecID codec) 85 : m_codec(codec), m_display(NULL), 86 m_vaProfile(VAProfileMPEG2Main)/* ?? */, 87 m_vaEntrypoint(VAEntrypointEncSlice), 88 m_pix_fmt(PIX_FMT_YUV420P), m_numSurfaces(NUM_VAAPI_BUFFERS), 89 m_surfaces(NULL), m_surfaceData(NULL) 90 { 91 memset(&m_ctx, 0, sizeof(vaapi_context)); 92 } 93 94 VAAPIContext::~VAAPIContext() 95 { 96 INIT_ST 97 98 if (m_ctx.context_id) 99 { 100 va_status = vaDestroyContext(m_ctx.display, m_ctx.context_id); 101 CHECK_ST 102 } 103 if (m_ctx.config_id) 104 { 105 va_status = vaDestroyConfig(m_ctx.display, m_ctx.config_id); 106 CHECK_ST 107 } 108 if (m_surfaces) 109 { 110 va_status = vaDestroySurfaces(m_ctx.display, m_surfaces, m_numSurfaces); 111 CHECK_ST 112 } 113 114 if (m_ctx.display) 115 { 116 va_status = vaTerminate(m_ctx.display); 117 CHECK_ST 118 } 119 120 if (m_surfaces) 121 delete [] m_surfaces; 122 if (m_surfaceData) 123 delete [] m_surfaceData; 124 125 delete m_display; 126 } 127 128 bool VAAPIContext::CreateDummy(QSize size)\ 129 { 130 m_size = size; 131 bool ok = true; 132 m_display = OpenMythXDisplay(); 133 CREATE_CHECK(!m_size.isEmpty(), "Invalid size") 134 CREATE_CHECK(m_display != NULL, "Invalid display") 135 CREATE_CHECK(InitDisplay(), "Invalid VADisplay") 136 CREATE_CHECK(InitProfiles(), "No supported profiles") 137 return ok; 138 } 139 140 bool VAAPIContext::Create(QSize size) 141 { 142 m_size = size; 143 bool ok = true; 144 m_display = OpenMythXDisplay(); 145 CREATE_CHECK(!m_size.isEmpty(), "Invalid size") 146 CREATE_CHECK(m_display != NULL, "Invalid display") 147 CREATE_CHECK(InitDisplay(), "Invalid VADisplay") 148 CREATE_CHECK(InitProfiles(), "No supported profiles") 149 CREATE_CHECK(InitBuffers(), "Failed to create buffers.") 150 CREATE_CHECK(InitContext(), "Failed to create context") 151 return ok; 152 } 153 154 bool VAAPIContext::InitDisplay(void) 155 { 156 int major_ver, minor_ver; 157 m_ctx.display = vaGetDisplay(m_display->GetDisplay()); 158 INIT_ST 159 va_status = vaInitialize(m_ctx.display, &major_ver, &minor_ver); 160 CHECK_ST 161 162 static bool debugged = false; 163 if (ok && !debugged) 164 { 165 debugged = true; 166 VERBOSE(VB_IMPORTANT, LOC + QString("Version: %1.%2") 167 .arg(major_ver).arg(minor_ver)); 168 VERBOSE(VB_IMPORTANT, LOC + QString("Vendor : %1") 169 .arg(vaQueryVendorString(m_ctx.display))); 170 } 171 return ok; 172 } 173 174 bool VAAPIContext::InitProfiles(void) 175 { 176 if (!codec_is_vaapi_hw(m_codec) || !m_ctx.display) 177 return false; 178 179 int max_profiles, max_entrypoints; 180 VAProfile profile_wanted = preferredProfile(m_codec); 181 VAProfile profile_found = VAProfileMPEG2Main; // FIXME 182 VAEntrypoint entry_found = VAEntrypointEncSlice; // unsupported value 183 184 max_profiles = vaMaxNumProfiles(m_ctx.display); 185 max_entrypoints = vaMaxNumEntrypoints(m_ctx.display); 186 VAProfile *profiles = new VAProfile[max_profiles]; 187 VAEntrypoint *entries = new VAEntrypoint[max_entrypoints]; 188 189 static bool debugged = false; 190 if (profiles && entries) 191 { 192 INIT_ST 193 int act_profiles, act_entries; 194 va_status = vaQueryConfigProfiles(m_ctx.display, 195 profiles, 196 &act_profiles); 197 CHECK_ST 198 if (ok && act_profiles > 0) 199 { 200 for (int i = 0; i < act_profiles; i++) 201 { 202 va_status = vaQueryConfigEntrypoints(m_ctx.display, 203 profiles[i], 204 entries, 205 &act_entries); 206 if (va_status == VA_STATUS_SUCCESS && act_entries > 0) 207 { 208 if (profiles[i] == profile_wanted) 209 { 210 profile_found = profile_wanted; 211 for (int j = 0; j < act_entries; j++) 212 if (entries[j] < entry_found) 213 entry_found = entries[j]; 214 } 215 216 if (!debugged) 217 { 218 QString entrylist = "Entrypoints: "; 219 for (int j = 0; j < act_entries; j++) 220 entrylist += entryToString(entries[j]); 221 VERBOSE(VB_IMPORTANT, LOC + QString("Profile: %1 %2") 222 .arg(profileToString(profiles[i])).arg(entrylist)); 223 } 224 } 225 } 226 } 227 debugged = true; 228 } 229 delete profiles; 230 delete entries; 231 232 VERBOSE(VB_PLAYBACK, LOC + QString("Desired profile for '%1': %2") 233 .arg(toString(m_codec)).arg(profileToString(profile_wanted))); 234 VERBOSE(VB_PLAYBACK, LOC + QString("Found profile %1 with entry %2") 235 .arg(profileToString(profile_found)).arg(entryToString(entry_found))); 236 237 if (profile_wanted != profile_found) 238 { 239 VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to find supported profile."); 240 return false; 241 } 242 243 if (entry_found > VAEntrypointMoComp) 244 { 245 VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to find suitable entry point."); 246 return false; 247 } 248 249 m_vaProfile = profile_wanted; 250 m_vaEntrypoint = entry_found; 251 if (VAEntrypointVLD == m_vaEntrypoint) 252 m_pix_fmt = PIX_FMT_VAAPI_VLD; 253 else if (VAEntrypointIDCT == m_vaEntrypoint) 254 m_pix_fmt = PIX_FMT_VAAPI_IDCT; 255 else if (VAEntrypointMoComp == m_vaEntrypoint) 256 m_pix_fmt = PIX_FMT_VAAPI_MOCO; 257 return true; 258 } 259 260 bool VAAPIContext::InitBuffers(void) 261 { 262 m_surfaces = new VASurfaceID[m_numSurfaces]; 263 m_surfaceData = new vaapi_surface[m_numSurfaces]; 264 265 if (!m_surfaces || !m_surfaceData) 266 return false; 267 268 INIT_ST 269 va_status = vaCreateSurfaces(m_ctx.display, m_size.width(), m_size.height(), 270 VA_RT_FORMAT_YUV420, m_numSurfaces, 271 m_surfaces); 272 CHECK_ST 273 274 for (int i =0; i < m_numSurfaces; i++) 275 m_surfaceData[i].m_id = m_surfaces[i]; 276 277 return ok; 278 } 279 280 bool VAAPIContext::InitContext(void) 281 { 282 if (!m_ctx.display || m_vaEntrypoint > VAEntrypointMoComp) 283 return false; 284 285 VAConfigAttrib attrib; 286 attrib.type = VAConfigAttribRTFormat; 287 INIT_ST 288 va_status = vaGetConfigAttributes(m_ctx.display, m_vaProfile, 289 m_vaEntrypoint, &attrib, 1); 290 CHECK_ST 291 292 if (!ok || !(attrib.value & VA_RT_FORMAT_YUV420)) 293 { 294 VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to confirm YUV420 chroma"); 295 return false; 296 } 297 298 va_status = vaCreateConfig(m_ctx.display, m_vaProfile, m_vaEntrypoint, 299 &attrib, 1, &m_ctx.config_id); 300 CHECK_ST 301 if (!ok) 302 { 303 VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to create decoder config."); 304 return false; 305 } 306 307 va_status = vaCreateContext(m_ctx.display, m_ctx.config_id, 308 m_size.width(), m_size.height(), VA_PROGRESSIVE, 309 m_surfaces, m_numSurfaces, 310 &m_ctx.context_id); 311 CHECK_ST 312 if (!ok) 313 { 314 VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to create decoder context."); 315 return false; 316 } 317 return true; 318 } 319 320 void* VAAPIContext::GetVideoSurface(int i) 321 { 322 if (i < 0 || i >= m_numSurfaces) 323 return NULL; 324 return &m_surfaceData[i]; 325 } 326 327 uint8_t* VAAPIContext::GetSurfaceIDPointer(void* buf) 328 { 329 if (!buf) 330 return NULL; 331 const vaapi_surface *surf = (vaapi_surface*)buf; 332 return (uint8_t*)(uintptr_t)surf->m_id; 333 } 334 335 void VAAPIContext::ShowSurface(int win, QRect &rect, void* buf) 336 { 337 if (!buf) 338 return; 339 340 const vaapi_surface *surf = (vaapi_surface*)buf; 341 INIT_ST 342 va_status = vaPutSurface(m_ctx.display, surf->m_id, win, 0, 0, 343 m_size.width(), m_size.height(), 344 rect.left(), rect.top(), 345 rect.width(), rect.height(), 346 NULL, 0, 0); 347 CHECK_ST 348 } -
libs/libmythtv/videoout_opengl.h
10 10 { 11 11 public: 12 12 static void GetRenderOptions(render_opts &opts, QStringList &cpudeints); 13 static QStringList GetOpenGLDeints(void); 13 14 VideoOutputOpenGL(); 14 ~VideoOutputOpenGL();15 virtual ~VideoOutputOpenGL(); 15 16 16 bool Init(int width, int height, float aspect, WId winid, 17 int winx, int winy, int winw, int winh, WId embedid = 0); 18 void TearDown(void); 17 virtual bool Init(int width, int height, float aspect, WId winid, 18 int winx, int winy, int winw, int winh, WId embedid = 0); 19 virtual void SetProfile(void); 20 virtual void TearDown(void); 19 21 20 22 void PrepareFrame(VideoFrame *buffer, FrameScanType, OSD *osd); 21 v oid ProcessFrame(VideoFrame *frame, OSD *osd,22 FilterChain *filterList,23 const PIPMap &pipPlayers,24 FrameScanType scan);25 v oid Show(FrameScanType );26 bool InputChanged(const QSize &input_size, float aspect,27 MythCodecID av_codec_id, void *codec_private,28 bool &aspect_only);23 virtual void ProcessFrame(VideoFrame *frame, OSD *osd, 24 FilterChain *filterList, 25 const PIPMap &pipPlayers, 26 FrameScanType scan); 27 virtual void Show(FrameScanType ); 28 virtual bool InputChanged(const QSize &input_size, float aspect, 29 MythCodecID av_codec_id, void *codec_private, 30 bool &aspect_only); 29 31 DisplayInfo GetDisplayInfo(void); 30 32 void UpdatePauseFrame(void); 31 33 void DrawUnusedRects(bool) { } … … 51 53 virtual bool ApproveDeintFilter(const QString& filtername) const; 52 54 virtual MythPainter *GetOSDPainter(void) { return (MythPainter*)gl_painter; } 53 55 54 private: 55 bool CreateBuffers(void); 56 protected: 57 virtual bool CreateBuffers(void); 58 bool CreatePauseFrame(void); 56 59 bool SetupContext(void); 57 60 bool SetupOpenGL(void); 58 61 void InitOSD(void); -
libs/libmythtv/mythcodecid.h
76 76 77 77 kCodec_VDPAU_END, 78 78 79 kCodec_VAAPI_BEGIN = kCodec_VDPAU_END, 80 81 kCodec_MPEG1_VAAPI, 82 kCodec_MPEG2_VAAPI, 83 kCodec_H263_VAAPI, 84 kCodec_MPEG4_VAAPI, 85 kCodec_H264_VAAPI, 86 kCodec_VC1_VAAPI, 87 kCodec_WMV3_VAAPI, 88 89 kCodec_VAAPI_END, 79 90 } MythCodecID; 80 91 81 92 // MythCodecID convenience functions … … 93 104 (id < kCodec_VDPAU_END) 94 105 #define codec_is_vdpau_hw(id) (codec_is_vdpau(id) &&\ 95 106 (id != kCodec_H263_VDPAU)) 107 #define codec_is_vaapi(id) (id > kCodec_VAAPI_BEGIN) &&\ 108 (id < kCodec_VAAPI_END) 109 #define codec_is_vaapi_hw(id) (codec_is_vaapi(id) &&\ 110 (id != kCodec_H263_VAAPI)) 96 111 97 112 QString get_encoding_type(MythCodecID codecid); 98 113 QString get_decoder_name(MythCodecID codec_id, bool libmpeg2); -
libs/libmythtv/mythcodecid.cpp
92 92 case kCodec_WMV3_VDPAU: 93 93 return "WMV3 VDPAU"; 94 94 95 case kCodec_MPEG1_VAAPI: 96 return "MPEG1 VAAPI"; 97 case kCodec_MPEG2_VAAPI: 98 return "MPEG2 VAAPI"; 99 case kCodec_H263_VAAPI: 100 return "H.263 VAAPI"; 101 case kCodec_MPEG4_VAAPI: 102 return "MPEG4 VAAPI"; 103 case kCodec_H264_VAAPI: 104 return "H.264 VAAPI"; 105 case kCodec_VC1_VAAPI: 106 return "VC1 VAAPI"; 107 case kCodec_WMV3_VAAPI: 108 return "WMV3 VAAPI"; 109 95 110 default: 96 111 break; 97 112 } … … 228 243 vdpau = true; 229 244 break; 230 245 246 case kCodec_MPEG1_VAAPI: 247 ret = CODEC_ID_MPEG1VIDEO; 248 vld = idct = mc = true; 249 break; 250 case kCodec_MPEG2_VAAPI: 251 ret = CODEC_ID_MPEG2VIDEO; 252 vld = idct = mc = true; 253 break; 254 case kCodec_H263_VAAPI: 255 VERBOSE(VB_IMPORTANT, "Error: VAAPI H.263 not supported by ffmpeg"); 256 break; 257 case kCodec_MPEG4_VAAPI: 258 ret = CODEC_ID_MPEG4; 259 vld = true; 260 break; 261 case kCodec_H264_VAAPI: 262 ret = CODEC_ID_H264; 263 vld = true; 264 break; 265 case kCodec_VC1_VAAPI: 266 ret = CODEC_ID_VC1; 267 vld = true; 268 break; 269 case kCodec_WMV3_VAAPI: 270 ret = CODEC_ID_WMV3; 271 vld = true; 272 break; 273 231 274 default: 232 275 VERBOSE(VB_IMPORTANT, 233 276 QString("Error: MythCodecID %1 has not been " … … 283 326 case kCodec_MPEG2_VLD: 284 327 case kCodec_MPEG2_DVDV: 285 328 case kCodec_MPEG2_VDPAU: 329 case kCodec_MPEG2_VAAPI: 286 330 return "MPEG-2"; 287 331 288 332 case kCodec_H263: … … 291 335 case kCodec_H263_VLD: 292 336 case kCodec_H263_DVDV: 293 337 case kCodec_H263_VDPAU: 338 case kCodec_H263_VAAPI: 294 339 return "H.263"; 295 340 296 341 case kCodec_NUV_MPEG4: … … 300 345 case kCodec_MPEG4_VLD: 301 346 case kCodec_MPEG4_DVDV: 302 347 case kCodec_MPEG4_VDPAU: 348 case kCodec_MPEG4_VAAPI: 303 349 return "MPEG-4"; 304 350 305 351 case kCodec_H264: … … 338 384 if (codec_is_vdpau(codec_id)) 339 385 return "vdpau"; 340 386 387 if (codec_is_vaapi(codec_id)) 388 return "vaapi"; 389 341 390 return "ffmpeg"; 342 391 } -
libs/libmythtv/videooutbase.cpp
40 40 #include "videoout_vdpau.h" 41 41 #endif 42 42 43 #ifdef USING_VAAPI 44 #include "videoout_openglvaapi.h" 45 #endif 46 43 47 #include "videoout_null.h" 44 48 #include "dithertable.h" 45 49 … … 96 100 #ifdef USING_VDPAU 97 101 VideoOutputVDPAU::GetRenderOptions(opts); 98 102 #endif // USING_VDPAU 103 104 #ifdef USING_VAAPI 105 VideoOutputOpenGLVAAPI::GetRenderOptions(opts, cpudeints); 106 #endif // USING_VAAPI 99 107 } 100 108 101 109 /** … … 143 151 renderers += VideoOutputVDPAU::GetAllowedRenderers(codec_id, video_dim); 144 152 #endif // USING_VDPAU 145 153 154 #ifdef USING_VAAPI 155 renderers += VideoOutputOpenGLVAAPI::GetAllowedRenderers(codec_id, video_dim); 156 #endif // USING_VAAPI 157 146 158 VERBOSE(VB_PLAYBACK, LOC + "Allowed renderers: " + 147 159 to_comma_list(renderers)); 148 160 … … 205 217 vo = new VideoOutputVDPAU(codec_id); 206 218 #endif // USING_VDPAU 207 219 220 #ifdef USING_VAAPI 221 if (renderer == "openglvaapi") 222 vo = new VideoOutputOpenGLVAAPI(codec_id); 223 #endif // USING_VAAPI 224 208 225 #ifdef USING_XV 209 226 if (xvlist.contains(renderer)) 210 227 vo = new VideoOutputXv(codec_id); -
libs/libmythtv/vaapicontext.h
1 #ifndef VAAPICONTEXT_H 2 #define VAAPICONTEXT_H 3 4 extern "C" { 5 #include "libavcodec/vaapi.h" 6 } 7 8 #include "va/va.h" 9 #include "va/va_x11.h" 10 11 struct vaapi_surface 12 { 13 VASurfaceID m_id; 14 }; 15 16 class VAAPIContext 17 { 18 public: 19 static bool IsFormatAccelerated(QSize size, MythCodecID codec, 20 PixelFormat &pix_fmt); 21 VAAPIContext(MythCodecID codec); 22 ~VAAPIContext(); 23 24 bool Create(QSize size); 25 bool CreateDummy(QSize size); 26 void* GetVideoSurface(int i); 27 int GetNumBuffers(void) { return m_numSurfaces; } 28 PixelFormat GetPixelFormat(void) { return m_pix_fmt; } 29 uint8_t* GetSurfaceIDPointer(void* buf); 30 31 // temp hack 32 void ShowSurface(int win, QRect &rect, void* buf); 33 34 bool InitDisplay(void); 35 bool InitProfiles(void); 36 bool InitBuffers(void); 37 bool InitContext(void); 38 39 vaapi_context m_ctx; 40 MythCodecID m_codec; 41 QSize m_size; 42 MythXDisplay *m_display; 43 VAProfile m_vaProfile; 44 VAEntrypoint m_vaEntrypoint; 45 PixelFormat m_pix_fmt; 46 int m_numSurfaces; 47 VASurfaceID *m_surfaces; 48 vaapi_surface *m_surfaceData; 49 }; 50 51 #endif // VAAPICONTEXT_H -
libs/libmythtv/videodisplayprofile.cpp
642 642 dec_name["xvmc-vld"] = QObject::tr("VIA XvMC"); 643 643 dec_name["macaccel"] = QObject::tr("Mac hardware acceleration"); 644 644 dec_name["vdpau"] = QObject::tr("NVidia VDPAU acceleration"); 645 dec_name["vaapi"] = QObject::tr("VA API"); 645 646 } 646 647 647 648 QString ret = decoder; … … 691 692 "VDPAU will attempt to use the graphics hardware to " 692 693 "accelerate video decoding and playback."); 693 694 695 if (decoder == "vaapi") 696 msg += QObject::tr( 697 "VAAPI will attempt to use the graphics hardware to " 698 "accelerate video decoding and playback."); 699 694 700 return msg; 695 701 } 696 702 … … 1237 1243 "This is the only video renderer for NVidia VDPAU decoding."); 1238 1244 } 1239 1245 1246 if (renderer == "openglvaapi") 1247 { 1248 msg = QObject::tr( 1249 "This is the only video renderer for VAAPI decoding."); 1250 } 1251 1240 1252 return msg; 1241 1253 }
