vaapi: support various profile 74/27174/5
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 5 Sep 2014 12:57:52 +0000 (21:57 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 11 Sep 2014 06:56:27 +0000 (23:56 -0700)
Change-Id: I85469eb2afce718211a3cfdd7da593e616aa932e
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/hw/pci/maru_brillcodec_vaapi.c

index b34afa0..f9171d7 100644 (file)
@@ -44,7 +44,6 @@
 #include "maru_brillcodec_plugin.h"
 
 #define SURFACE_COUNT   4
-#define PROFILE         VAProfileH264High
 
 #ifndef VA_SURFACE_ATTRIB_SETTABLE
 #define vaCreateSurfaces(d, f, w, h, s, ns, a, na) \
@@ -65,12 +64,11 @@ static void *va_display;
 // FIXME
 static VAPluginContext *va_ctx = &(VAPluginContext) {};
 
-static int create_surfaces(AVCodecContext *ctx, int width, int height)
+static int create_surfaces(AVCodecContext *ctx, int width, int height, VAProfile profile)
 {
     assert(width > 0 && height > 0);
 
     VAConfigID config_id;
-    VAProfile profile = PROFILE; // FIXME
 
     /* Create a VA configuration */
     VAConfigAttrib attrib;
@@ -171,11 +169,65 @@ static bool setup(AVCodecContext *ctx, int width, int height) {
         }
     }
 
-    if(create_surfaces(ctx, width, height)) {
+    VAProfile profile;
+
+    int codec_id = ctx->codec_id;
+    switch(codec_id)
+    {
+    case AV_CODEC_ID_MPEG1VIDEO:
+    case AV_CODEC_ID_MPEG2VIDEO:
+        profile = VAProfileMPEG2Main;
+        break;
+    case AV_CODEC_ID_MPEG4:
+        profile = VAProfileMPEG4AdvancedSimple;
+        break;
+    case AV_CODEC_ID_WMV3:
+        profile = VAProfileVC1Main;
+        break;
+    case AV_CODEC_ID_VC1:
+        profile = VAProfileVC1Advanced;
+        break;
+    case AV_CODEC_ID_H264:
+        profile = VAProfileH264High;
+        break;;
+    default:
+        goto error;
+    }
+
+    int num_profiles = vaMaxNumProfiles(va_display);
+    VAProfile *profiles_list = calloc(num_profiles, sizeof(VAProfile));
+    bool is_supported_profile;
+    int i;
+
+    if (!profiles_list) {
+        goto error;
+    }
+
+    VAStatus status = vaQueryConfigProfiles(va_display, profiles_list, &num_profiles);
+    if (status == VA_STATUS_SUCCESS) {
+        for (i = 0; i < num_profiles; ++i) {
+            if (profiles_list[i] == profile) {
+                is_supported_profile = true;
+                break;
+            }
+        }
+    }
+    free(profiles_list);
+    if (!is_supported_profile)
+    {
+        printf("Codec and profile not supported by the VAAPI device");
+        goto error;
+    }
+
+    if(create_surfaces(ctx, width, height, profile)) {
         printf("Failed to initialize the VAAPI device\n");
     }
 
     return true;
+
+error:
+    // TODO: error handling
+    return false;
 }
 
 static void copy_plane(uint8_t *dst,