commit ed7041cd41a517dbd42da8b4e1a8c10b7d6689bd
Author: Gwenole Beauchesne <gbeauchesne@splitted-desktop.com>
Date:   Tue Feb 23 10:05:25 2010 +0000

    Detect Broadcom Crystal HD chip.

diff --git a/va/Makefile.am b/va/Makefile.am
index 5018ef0..014ba8e 100644
--- a/va/Makefile.am
+++ b/va/Makefile.am
@@ -27,7 +27,7 @@ INCLUDES = \
 LDADD = \
 	$(LIBVA_LT_LDFLAGS)
 
-libva_la_SOURCES = va.c va_trace.c va_fool.c va_fool_getframe.c
+libva_la_SOURCES = va.c va_trace.c va_fool.c va_fool_getframe.c va_crystalhd.c
 libva_ladir = $(libdir)
 libva_la_LDFLAGS = $(LDADD) -no-undefined
 libva_la_LIBADD = $(LIBVA_LIBS) -ldl
@@ -87,4 +87,5 @@ DISTCLEANFILES = \
 	va_version.h
 
 EXTRA_DIST = \
-	va_version.h.in
+	va_version.h.in \
+	va_crystalhd.h
diff --git a/va/va.c b/va/va.c
index 10befe8..17ed08d 100644
--- a/va/va.c
+++ b/va/va.c
@@ -28,6 +28,7 @@
 #include "va_backend.h"
 #include "va_trace.h"
 #include "va_fool.h"
+#include "va_crystalhd.h"
 
 #include <assert.h>
 #include <stdarg.h>
@@ -415,6 +416,15 @@ VAStatus vaInitialize (
         vaStatus = va_openDriver(dpy, driver_name);
         va_infoMessage("va_openDriver() returns %d\n", vaStatus);
 
+        if (vaStatus != VA_STATUS_SUCCESS && !driver_name_env)
+        {
+            if (va_hasCrystalHD())
+            {
+                vaStatus = va_openDriver(dpy, "crystalhd");
+                va_infoMessage("va_openDriver() returns %d\n", vaStatus);
+            }
+        }
+
         *major_version = VA_MAJOR_VERSION;
         *minor_version = VA_MINOR_VERSION;
     }
diff --git a/va/va_crystalhd.c b/va/va_crystalhd.c
new file mode 100644
index 0000000..1ddd4fe
--- /dev/null
+++ b/va/va_crystalhd.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2010 Splitted-Desktop Systems. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "config.h"
+#include "va_crystalhd.h"
+
+/* Checks if the Broadcom Crystal HD decoder is available */
+int va_hasCrystalHD(void)
+{
+    char line[1024];
+    int len, vendor, device, dummy, found = 0;
+    FILE *fp;
+
+    fp = fopen("/proc/bus/pci/devices", "r");
+    if (!fp)
+        return 0;
+
+    while (!found && fgets(line, sizeof(line), fp)) {
+        len = strlen(line);
+        if (len == 0)
+            continue;
+        line[len - 1] = 0;
+        if (sscanf(line, "%x %04x%04x", &dummy, &vendor, &device) == 3) {
+            if (vendor == 0x14e4 && device == 0x1612) /* BCM70012 */
+                found = 1;
+        }
+    }
+    fclose(fp);
+    return found;
+}
diff --git a/va/va_crystalhd.h b/va/va_crystalhd.h
new file mode 100644
index 0000000..44a39d9
--- /dev/null
+++ b/va/va_crystalhd.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2010 Splitted-Desktop Systems. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef VA_CRYSTALHD_H
+#define VA_CRYSTALHD_H
+
+/** Checks if the Broadcom Crystal HD decoder is available */
+int va_hasCrystalHD(void)
+    ATTRIBUTE_HIDDEN;
+
+#endif /* VA_CRYSTALHD_H */
