Browse code

Merge commit '9f7590f4e497c12693247d7f935a20d7773a64dd'

* commit '9f7590f4e497c12693247d7f935a20d7773a64dd':
avconv_vaapi: use the hwcontext device creation API

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>

Hendrik Leppkes authored on 2016/06/26 22:36:27
Showing 1 changed files
... ...
@@ -523,102 +523,14 @@ fail:
523 523
 
524 524
 static AVClass *vaapi_log = &vaapi_class;
525 525
 
526
-static av_cold void vaapi_device_uninit(AVHWDeviceContext *hwdev)
527
-{
528
-    AVVAAPIDeviceContext *hwctx = hwdev->hwctx;
529
-    av_log(&vaapi_log, AV_LOG_VERBOSE, "Terminating VAAPI connection.\n");
530
-    vaTerminate(hwctx->display);
531
-}
532
-
533 526
 av_cold int vaapi_device_init(const char *device)
534 527
 {
535
-    AVHWDeviceContext    *hwdev;
536
-    AVVAAPIDeviceContext *hwctx;
537
-    VADisplay display;
538
-    VAStatus vas;
539
-    int major, minor, err;
540
-
541
-    display = 0;
542
-
543
-#if HAVE_VAAPI_X11
544
-    if (!display) {
545
-        Display *x11_display;
546
-
547
-        // Try to open the device as an X11 display.
548
-        x11_display = XOpenDisplay(device);
549
-        if (!x11_display) {
550
-            av_log(&vaapi_log, AV_LOG_WARNING, "Cannot open X11 display "
551
-                   "%s.\n", XDisplayName(device));
552
-        } else {
553
-            display = vaGetDisplay(x11_display);
554
-            if (!display) {
555
-                av_log(&vaapi_log, AV_LOG_WARNING, "Cannot open a VA display "
556
-                       "from X11 display %s.\n", XDisplayName(device));
557
-                XCloseDisplay(x11_display);
558
-            } else {
559
-                av_log(&vaapi_log, AV_LOG_VERBOSE, "Opened VA display via "
560
-                       "X11 display %s.\n", XDisplayName(device));
561
-            }
562
-        }
563
-    }
564
-#endif
565
-
566
-#if HAVE_VAAPI_DRM
567
-    if (!display && device) {
568
-        int drm_fd;
569
-
570
-        // Try to open the device as a DRM path.
571
-        drm_fd = open(device, O_RDWR);
572
-        if (drm_fd < 0) {
573
-            av_log(&vaapi_log, AV_LOG_WARNING, "Cannot open DRM device %s.\n",
574
-                   device);
575
-        } else {
576
-            display = vaGetDisplayDRM(drm_fd);
577
-            if (!display) {
578
-                av_log(&vaapi_log, AV_LOG_WARNING, "Cannot open a VA display "
579
-                       "from DRM device %s.\n", device);
580
-                close(drm_fd);
581
-            } else {
582
-                av_log(&vaapi_log, AV_LOG_VERBOSE, "Opened VA display via "
583
-                       "DRM device %s.\n", device);
584
-            }
585
-        }
586
-    }
587
-#endif
588
-
589
-    if (!display) {
590
-        av_log(&vaapi_log, AV_LOG_ERROR, "No VA display found for "
591
-               "device %s.\n", device);
592
-        return AVERROR(EINVAL);
593
-    }
594
-
595
-    vas = vaInitialize(display, &major, &minor);
596
-    if (vas != VA_STATUS_SUCCESS) {
597
-        av_log(&vaapi_log, AV_LOG_ERROR, "Failed to initialise VAAPI "
598
-               "connection: %d (%s).\n", vas, vaErrorStr(vas));
599
-        return AVERROR(EIO);
600
-    }
601
-    av_log(&vaapi_log, AV_LOG_VERBOSE, "Initialised VAAPI connection: "
602
-           "version %d.%d\n", major, minor);
603
-
604
-    hw_device_ctx = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_VAAPI);
605
-    if (!hw_device_ctx) {
606
-        av_log(&vaapi_log, AV_LOG_ERROR, "Failed to create VAAPI "
607
-               "hardware context.\n");
608
-        vaTerminate(display);
609
-        return AVERROR(ENOMEM);
610
-    }
611
-
612
-    hwdev = (AVHWDeviceContext*)hw_device_ctx->data;
613
-    hwdev->free = &vaapi_device_uninit;
614
-
615
-    hwctx = hwdev->hwctx;
616
-    hwctx->display = display;
528
+    int err;
617 529
 
618
-    err = av_hwdevice_ctx_init(hw_device_ctx);
530
+    err = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_VAAPI,
531
+                                 device, NULL, 0);
619 532
     if (err < 0) {
620
-        av_log(&vaapi_log, AV_LOG_ERROR, "Failed to initialise VAAPI "
621
-               "hardware context: %d\n", err);
533
+        av_log(&vaapi_log, AV_LOG_ERROR, "Failed to create a VAAPI device\n");
622 534
         return err;
623 535
     }
624 536