#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) \
// 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;
}
}
- 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,