Skip to content
This repository
Browse code

Merge pull request #2699 from FernetMenta/hwaccel

move vdpau into hwaccel
  • Loading branch information...
commit 06b20663ebf9a59691b6e61e4ac0fa2d46968441 2 parents 37d7b77 + 6bfa7bb
Rainer Hochecker authored May 08, 2013
2  lib/ffmpeg/libavcodec/mpeg12.c
@@ -1202,6 +1202,7 @@ static const enum AVPixelFormat mpeg1_hwaccel_pixfmt_list_420[] = {
1202 1202
 #endif
1203 1203
 #if CONFIG_MPEG1_VDPAU_HWACCEL
1204 1204
     AV_PIX_FMT_VDPAU_MPEG1,
  1205
+    AV_PIX_FMT_VDPAU,
1205 1206
 #endif
1206 1207
     AV_PIX_FMT_YUV420P,
1207 1208
     AV_PIX_FMT_NONE
@@ -1214,6 +1215,7 @@ static const enum AVPixelFormat mpeg2_hwaccel_pixfmt_list_420[] = {
1214 1215
 #endif
1215 1216
 #if CONFIG_MPEG2_VDPAU_HWACCEL
1216 1217
     AV_PIX_FMT_VDPAU_MPEG2,
  1218
+    AV_PIX_FMT_VDPAU,
1217 1219
 #endif
1218 1220
 #if CONFIG_MPEG2_DXVA2_HWACCEL
1219 1221
     AV_PIX_FMT_DXVA2_VLD,
2  lib/ffmpeg/libavcodec/vdpau_vc1.c
@@ -59,7 +59,7 @@ static int vdpau_vc1_start_frame(AVCodecContext *avctx,
59 59
     else
60 60
         info->picture_type  = s->pict_type - 1 + s->pict_type / 3;
61 61
 
62  
-    info->frame_coding_mode = v->fcm;
  62
+    info->frame_coding_mode = v->fcm ? v->fcm + 1 : 0;
63 63
     info->postprocflag      = v->postprocflag;
64 64
     info->pulldown          = v->broadcast;
65 65
     info->interlace         = v->interlace;
32  ...g/patches/0036-backport-register-vdpau-hwaccel-for-mpeg12-fe1f36547d0be963e352de0cde1a6cba59ea2e78.patch
... ...
@@ -0,0 +1,32 @@
  1
+From bb6ba57092c402b6f2e5edf6d1691beafafa0460 Mon Sep 17 00:00:00 2001
  2
+From: Rainer Hochecker <fernetmenta@online.de>
  3
+Date: Mon, 6 May 2013 20:58:28 +0200
  4
+Subject: [PATCH] ffmpeg backport: register vdpau hwaccel for mpeg12
  5
+
  6
+---
  7
+ libavcodec/mpeg12.c |    2 ++
  8
+ 1 file changed, 2 insertions(+)
  9
+
  10
+diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
  11
+index 9d2743a..0f94772 100644
  12
+--- a/libavcodec/mpeg12.c
  13
++++ b/libavcodec/mpeg12.c
  14
+@@ -1202,6 +1202,7 @@ static const enum AVPixelFormat mpeg1_hwaccel_pixfmt_list_420[] = {
  15
+ #endif
  16
+ #if CONFIG_MPEG1_VDPAU_HWACCEL
  17
+     AV_PIX_FMT_VDPAU_MPEG1,
  18
++    AV_PIX_FMT_VDPAU,
  19
+ #endif
  20
+     AV_PIX_FMT_YUV420P,
  21
+     AV_PIX_FMT_NONE
  22
+@@ -1214,6 +1215,7 @@ static const enum AVPixelFormat mpeg2_hwaccel_pixfmt_list_420[] = {
  23
+ #endif
  24
+ #if CONFIG_MPEG2_VDPAU_HWACCEL
  25
+     AV_PIX_FMT_VDPAU_MPEG2,
  26
++    AV_PIX_FMT_VDPAU,
  27
+ #endif
  28
+ #if CONFIG_MPEG2_DXVA2_HWACCEL
  29
+     AV_PIX_FMT_DXVA2_VLD,
  30
+-- 
  31
+1.7.9.5
  32
+
25  ...fmpeg/patches/0037-backport-fix-vdpau-vc1-interlace-modes-b37cc5995b88ec68a68cb8e496a008e1cd467077.patch
... ...
@@ -0,0 +1,25 @@
  1
+From b37cc5995b88ec68a68cb8e496a008e1cd467077 Mon Sep 17 00:00:00 2001
  2
+From: Rainer Hochecker <fernetmenta@online.de>
  3
+Date: Sun, 5 May 2013 15:12:59 +0200
  4
+Subject: [PATCH] fix vdpau vc1 interlace modes
  5
+
  6
+---
  7
+ libavcodec/vdpau_vc1.c |    2 +-
  8
+ 1 file changed, 1 insertion(+), 1 deletion(-)
  9
+
  10
+diff --git a/libavcodec/vdpau_vc1.c b/libavcodec/vdpau_vc1.c
  11
+index f5da9bb..993ef26 100644
  12
+--- a/libavcodec/vdpau_vc1.c
  13
++++ b/libavcodec/vdpau_vc1.c
  14
+@@ -59,7 +59,7 @@ static int vdpau_vc1_start_frame(AVCodecContext *avctx,
  15
+     else
  16
+         info->picture_type  = s->pict_type - 1 + s->pict_type / 3;
  17
+ 
  18
+-    info->frame_coding_mode = v->fcm;
  19
++    info->frame_coding_mode = v->fcm ? v->fcm + 1 : 0;
  20
+     info->postprocflag      = v->postprocflag;
  21
+     info->pulldown          = v->broadcast;
  22
+     info->interlace         = v->interlace;
  23
+-- 
  24
+1.7.9.5
  25
+
36  xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
@@ -74,9 +74,6 @@ enum PixelFormat CDVDVideoCodecFFmpeg::GetFormat( struct AVCodecContext * avctx
74 74
 #ifdef HAVE_LIBVDPAU
75 75
     if(CVDPAU::IsVDPAUFormat(*cur) && CSettings::Get().GetBool("videoplayer.usevdpau"))
76 76
     {
77  
-      if(ctx->GetHardware())
78  
-        return *cur;
79  
-        
80 77
       CLog::Log(LOGNOTICE,"CDVDVideoCodecFFmpeg::GetFormat - Creating VDPAU(%ix%i)", avctx->width, avctx->height);
81 78
       CVDPAU* vdp = new CVDPAU();
82 79
       if(vdp->Open(avctx, *cur))
@@ -203,39 +200,6 @@ bool CDVDVideoCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options
203 200
     }
204 201
   }
205 202
 
206  
-#ifdef HAVE_LIBVDPAU
207  
-  if(CSettings::Get().GetBool("videoplayer.usevdpau") && !m_bSoftware)
208  
-  {
209  
-    while((pCodec = m_dllAvCodec.av_codec_next(pCodec)))
210  
-    {
211  
-      if(pCodec->id == hints.codec
212  
-      && pCodec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
213  
-      {
214  
-        if ((pCodec->id == CODEC_ID_MPEG4) && !g_advancedSettings.m_videoAllowMpeg4VDPAU)
215  
-          continue;
216  
-
217  
-        CLog::Log(LOGNOTICE,"CDVDVideoCodecFFmpeg::Open() Creating VDPAU(%ix%i, %d)",hints.width, hints.height, hints.codec);
218  
-        CVDPAU* vdp = new CVDPAU();
219  
-        m_pCodecContext = m_dllAvCodec.avcodec_alloc_context3(pCodec);
220  
-        m_pCodecContext->codec_id = hints.codec;
221  
-        m_pCodecContext->width    = hints.width;
222  
-        m_pCodecContext->height   = hints.height;
223  
-        m_pCodecContext->coded_width   = hints.width;
224  
-        m_pCodecContext->coded_height  = hints.height;
225  
-        if(vdp->Open(m_pCodecContext, pCodec->pix_fmts ? pCodec->pix_fmts[0] : PIX_FMT_NONE))
226  
-        {
227  
-          m_pHardware = vdp;
228  
-          m_pCodecContext->codec_id = CODEC_ID_NONE; // ffmpeg will complain if this has been set
229  
-          break;
230  
-        }
231  
-        m_dllAvUtil.av_freep(&m_pCodecContext);
232  
-        CLog::Log(LOGNOTICE,"CDVDVideoCodecFFmpeg::Open() Failed to get VDPAU device");
233  
-        vdp->Release();
234  
-      }
235  
-    }
236  
-  }
237  
-#endif
238  
-
239 203
   if(pCodec == NULL)
240 204
     pCodec = m_dllAvCodec.avcodec_find_decoder(hints.codec);
241 205
 
66  xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp
@@ -184,6 +184,9 @@ bool CVDPAU::Open(AVCodecContext* avctx, const enum PixelFormat, unsigned int su
184 184
     return false;
185 185
   }
186 186
 
  187
+  if ((avctx->codec_id == CODEC_ID_MPEG4) && !g_advancedSettings.m_videoAllowMpeg4VDPAU)
  188
+    return false;
  189
+
187 190
   if (!dl_handle)
188 191
   {
189 192
     dl_handle  = dlopen("libvdpau.so.1", RTLD_LAZY);
@@ -239,10 +242,15 @@ bool CVDPAU::Open(AVCodecContext* avctx, const enum PixelFormat, unsigned int su
239 242
     InitCSCMatrix(avctx->coded_height);
240 243
 
241 244
     /* finally setup ffmpeg */
  245
+    memset(&m_hwContext, 0, sizeof(AVVDPAUContext));
  246
+    m_hwContext.render = CVDPAU::Render;
  247
+    m_hwContext.bitstream_buffers_allocated = 0;
242 248
     avctx->get_buffer      = CVDPAU::FFGetBuffer;
243 249
     avctx->release_buffer  = CVDPAU::FFReleaseBuffer;
244 250
     avctx->draw_horiz_band = CVDPAU::FFDrawSlice;
245 251
     avctx->slice_flags=SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD;
  252
+    avctx->hwaccel_context = &m_hwContext;
  253
+    avctx->thread_count    = 1;
246 254
 
247 255
     g_Windowing.Register(this);
248 256
     return true;
@@ -272,6 +280,11 @@ void CVDPAU::Close()
272 280
     free(render);
273 281
   }
274 282
 
  283
+  if (m_hwContext.bitstream_buffers_allocated)
  284
+  {
  285
+    m_dllAvUtil.av_freep(&m_hwContext.bitstream_buffers);
  286
+  }
  287
+
275 288
   g_Windowing.Unregister(this);
276 289
   m_dllAvUtil.Unload();
277 290
 }
@@ -497,11 +510,10 @@ int CVDPAU::Check(AVCodecContext* avctx)
497 510
 
498 511
 bool CVDPAU::IsVDPAUFormat(PixelFormat format)
499 512
 {
500  
-  if ((format >= PIX_FMT_VDPAU_H264) && (format <= PIX_FMT_VDPAU_VC1)) return true;
501  
-#if (defined PIX_FMT_VDPAU_MPEG4_IN_AVUTIL)
502  
-  if (format == PIX_FMT_VDPAU_MPEG4) return true;
503  
-#endif
504  
-  else return false;
  513
+  if (format == AV_PIX_FMT_VDPAU)
  514
+    return true;
  515
+  else
  516
+    return false;
505 517
 }
506 518
 
507 519
 void CVDPAU::CheckFeatures()
@@ -914,35 +926,35 @@ void CVDPAU::FiniVDPAUOutput()
914 926
 }
915 927
 
916 928
 
917  
-void CVDPAU::ReadFormatOf( PixelFormat fmt
  929
+void CVDPAU::ReadFormatOf( AVCodecID codec
918 930
                          , VdpDecoderProfile &vdp_decoder_profile
919 931
                          , VdpChromaType     &vdp_chroma_type)
920 932
 {
921  
-  switch (fmt)
  933
+  switch (codec)
922 934
   {
923  
-    case PIX_FMT_VDPAU_MPEG1:
  935
+    case AV_CODEC_ID_MPEG1VIDEO:
924 936
       vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG1;
925 937
       vdp_chroma_type     = VDP_CHROMA_TYPE_420;
926 938
       break;
927  
-    case PIX_FMT_VDPAU_MPEG2:
  939
+    case AV_CODEC_ID_MPEG2VIDEO:
928 940
       vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
929 941
       vdp_chroma_type     = VDP_CHROMA_TYPE_420;
930 942
       break;
931  
-    case PIX_FMT_VDPAU_H264:
  943
+    case  AV_CODEC_ID_H264:
932 944
       vdp_decoder_profile = VDP_DECODER_PROFILE_H264_HIGH;
933 945
       vdp_chroma_type     = VDP_CHROMA_TYPE_420;
934 946
       break;
935  
-    case PIX_FMT_VDPAU_WMV3:
  947
+    case AV_CODEC_ID_WMV3:
936 948
       vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_MAIN;
937 949
       vdp_chroma_type     = VDP_CHROMA_TYPE_420;
938 950
       break;
939  
-    case PIX_FMT_VDPAU_VC1:
  951
+    case AV_CODEC_ID_VC1:
940 952
       vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
941 953
       vdp_chroma_type     = VDP_CHROMA_TYPE_420;
942 954
       break;
943 955
 #if (defined PIX_FMT_VDPAU_MPEG4_IN_AVUTIL) && \
944 956
     (defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP)
945  
-    case PIX_FMT_VDPAU_MPEG4:
  957
+    case AV_CODEC_ID_MPEG4:
946 958
       vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
947 959
       vdp_chroma_type     = VDP_CHROMA_TYPE_420;
948 960
       break;
@@ -969,9 +981,9 @@ bool CVDPAU::ConfigVDPAU(AVCodecContext* avctx, int ref_frames)
969 981
   past[1] = past[0] = current = future = NULL;
970 982
   CLog::Log(LOGNOTICE, " (VDPAU) screenWidth:%i vidWidth:%i surfaceWidth:%i",OutWidth,vid_width,surface_width);
971 983
   CLog::Log(LOGNOTICE, " (VDPAU) screenHeight:%i vidHeight:%i surfaceHeight:%i",OutHeight,vid_height,surface_height);
972  
-  ReadFormatOf(avctx->pix_fmt, vdp_decoder_profile, vdp_chroma_type);
  984
+  ReadFormatOf(avctx->codec_id, vdp_decoder_profile, vdp_chroma_type);
973 985
 
974  
-  if(avctx->pix_fmt == PIX_FMT_VDPAU_H264)
  986
+  if(avctx->codec_id == AV_CODEC_ID_H264)
975 987
   {
976 988
      max_references = ref_frames;
977 989
      if (max_references > 16) max_references = 16;
@@ -1229,7 +1241,7 @@ int CVDPAU::FFGetBuffer(AVCodecContext *avctx, AVFrame *pic)
1229 1241
   {
1230 1242
     // create a new surface
1231 1243
     VdpDecoderProfile profile;
1232  
-    ReadFormatOf(avctx->pix_fmt, profile, vdp->vdp_chroma_type);
  1244
+    ReadFormatOf(avctx->codec_id, profile, vdp->vdp_chroma_type);
1233 1245
     render = (vdpau_render_state*)calloc(sizeof(vdpau_render_state), 1);
1234 1246
     if (render == NULL)
1235 1247
     {
@@ -1259,8 +1271,9 @@ int CVDPAU::FFGetBuffer(AVCodecContext *avctx, AVFrame *pic)
1259 1271
   if (render == NULL)
1260 1272
     return -1;
1261 1273
 
1262  
-  pic->data[1] =  pic->data[2] = NULL;
1263  
-  pic->data[0]= (uint8_t*)render;
  1274
+  pic->data[1] = pic->data[2] = NULL;
  1275
+  pic->data[0] = (uint8_t*)render;
  1276
+  pic->data[3] = (uint8_t*)(uintptr_t)render->surface;
1264 1277
 
1265 1278
   pic->linesize[0] = pic->linesize[1] =  pic->linesize[2] = 0;
1266 1279
 
@@ -1313,6 +1326,13 @@ void CVDPAU::FFReleaseBuffer(AVCodecContext *avctx, AVFrame *pic)
1313 1326
   render->state &= ~FF_VDPAU_STATE_USED_FOR_REFERENCE;
1314 1327
 }
1315 1328
 
  1329
+VdpStatus CVDPAU::Render(VdpDecoder decoder, VdpVideoSurface target,
  1330
+                         VdpPictureInfo const *picture_info,
  1331
+                         uint32_t bitstream_buffer_count,
  1332
+                         VdpBitstreamBuffer const * bitstream_buffers)
  1333
+{
  1334
+  return VDP_STATUS_OK;
  1335
+}
1316 1336
 
1317 1337
 void CVDPAU::FFDrawSlice(struct AVCodecContext *s,
1318 1338
                                            const AVFrame *src, int offset[4],
@@ -1355,8 +1375,8 @@ void CVDPAU::FFDrawSlice(struct AVCodecContext *s,
1355 1375
   }
1356 1376
 
1357 1377
   uint32_t max_refs = 0;
1358  
-  if(s->pix_fmt == PIX_FMT_VDPAU_H264)
1359  
-    max_refs = render->info.h264.num_ref_frames;
  1378
+  if(s->codec_id == AV_CODEC_ID_H264)
  1379
+    max_refs = vdp->m_hwContext.info.h264.num_ref_frames;
1360 1380
 
1361 1381
   if(vdp->decoder == VDP_INVALID_HANDLE
1362 1382
   || vdp->vdpauConfigured == false
@@ -1368,9 +1388,9 @@ void CVDPAU::FFDrawSlice(struct AVCodecContext *s,
1368 1388
 
1369 1389
   vdp_st = vdp->vdp_decoder_render(vdp->decoder,
1370 1390
                                    render->surface,
1371  
-                                   (VdpPictureInfo const *)&(render->info),
1372  
-                                   render->bitstream_buffers_used,
1373  
-                                   render->bitstream_buffers);
  1391
+                                   (VdpPictureInfo const *)&(vdp->m_hwContext.info),
  1392
+                                   vdp->m_hwContext.bitstream_buffers_used,
  1393
+                                   vdp->m_hwContext.bitstream_buffers);
1374 1394
   vdp->CheckStatus(vdp_st, __LINE__);
1375 1395
 }
1376 1396
 
7  xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.h
@@ -94,6 +94,10 @@ class CVDPAU
94 94
                                const AVFrame *src, int offset[4],
95 95
                                int y, int type, int height);
96 96
   static int              FFGetBuffer(AVCodecContext *avctx, AVFrame *pic);
  97
+  static VdpStatus        Render(VdpDecoder decoder, VdpVideoSurface target,
  98
+                                 VdpPictureInfo const *picture_info,
  99
+                                 uint32_t bitstream_buffer_count,
  100
+                                 VdpBitstreamBuffer const * bitstream_buffers);
97 101
 
98 102
   void Present();
99 103
   bool ConfigVDPAU(AVCodecContext *avctx, int ref_frames);
@@ -222,11 +226,12 @@ class CVDPAU
222 226
   int                  m_feature_count;
223 227
 
224 228
   static bool IsVDPAUFormat(PixelFormat fmt);
225  
-  static void ReadFormatOf( PixelFormat fmt
  229
+  static void ReadFormatOf( AVCodecID codec
226 230
                           , VdpDecoderProfile &decoder_profile
227 231
                           , VdpChromaType     &chroma_type);
228 232
 
229 233
   std::vector<vdpau_render_state*> m_videoSurfaces;
  234
+  AVVDPAUContext m_hwContext;
230 235
   DllAvUtil   m_dllAvUtil;
231 236
 
232 237
   enum VDPAUOutputMethod

0 notes on commit 06b2066

Please sign in to comment.
Something went wrong with that request. Please try again.