You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2011 Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include "talk/media/base/cpuid.h"
  28. #ifdef HAVE_YUV
  29. #include "libyuv/cpu_id.h"
  30. #endif
  31. namespace cricket {
  32. bool CpuInfo::TestCpuFlag(int flag) {
  33. #ifdef HAVE_YUV
  34. return libyuv::TestCpuFlag(flag) ? true : false;
  35. #else
  36. return false;
  37. #endif
  38. }
  39. void CpuInfo::MaskCpuFlagsForTest(int enable_flags) {
  40. #ifdef HAVE_YUV
  41. libyuv::MaskCpuFlags(enable_flags);
  42. #endif
  43. }
  44. // Detect an Intel Core I5 or better such as 4th generation Macbook Air.
  45. bool IsCoreIOrBetter() {
  46. #if defined(HAVE_YUV) && (defined(__i386__) || defined(__x86_64__) || \
  47. defined(_M_IX86) || defined(_M_X64))
  48. int cpu_info[4];
  49. libyuv::CpuId(cpu_info, 0); // Function 0: Vendor ID
  50. if (cpu_info[1] == 0x756e6547 && cpu_info[3] == 0x49656e69 &&
  51. cpu_info[2] == 0x6c65746e) { // GenuineIntel
  52. // Detect CPU Family and Model
  53. // 3:0 - Stepping
  54. // 7:4 - Model
  55. // 11:8 - Family
  56. // 13:12 - Processor Type
  57. // 19:16 - Extended Model
  58. // 27:20 - Extended Family
  59. libyuv::CpuId(cpu_info, 1); // Function 1: Family and Model
  60. int family = ((cpu_info[0] >> 8) & 0x0f) | ((cpu_info[0] >> 16) & 0xff0);
  61. int model = ((cpu_info[0] >> 4) & 0x0f) | ((cpu_info[0] >> 12) & 0xf0);
  62. // CpuFamily | CpuModel | Name
  63. // 6 | 14 | Yonah -- Core
  64. // 6 | 15 | Merom -- Core 2
  65. // 6 | 23 | Penryn -- Core 2 (most common)
  66. // 6 | 26 | Nehalem -- Core i*
  67. // 6 | 28 | Atom
  68. // 6 | 30 | Lynnfield -- Core i*
  69. // 6 | 37 | Westmere -- Core i*
  70. const int kAtom = 28;
  71. const int kCore2 = 23;
  72. if (family < 6 || family == 15 ||
  73. (family == 6 && (model == kAtom || model <= kCore2))) {
  74. return false;
  75. }
  76. return true;
  77. }
  78. #endif
  79. return false;
  80. }
  81. } // namespace cricket