static bool
IsSupportedVideo(mozIGeckoMediaPluginService* aGMPService,
                 const nsAString& aKeySystem,
                 const nsAString& aVideoType)
{
  return IsH264ContentType(aVideoType) &&
         (GMPDecryptsAndDecodesH264(aGMPService, aKeySystem) ||
          GMPDecryptsAndGeckoDecodesH264(aGMPService, aKeySystem, aVideoType));
}
// If this keysystem's CDM explicitly says it doesn't support decoding,
// that means it's OK with passing the decrypted samples back to Gecko
// for decoding.
static bool
GMPDecryptsAndGeckoDecodesH264(mozIGeckoMediaPluginService* aGMPService,
                               const nsAString& aKeySystem,
                               const nsAString& aContentType,
                               DecoderDoctorDiagnostics* aDiagnostics)
{
  MOZ_ASSERT(HaveGMPFor(aGMPService,
                        NS_ConvertUTF16toUTF8(aKeySystem),
                        NS_LITERAL_CSTRING(GMP_API_DECRYPTOR)));
  MOZ_ASSERT(IsH264ContentType(aContentType));
  return !HaveGMPFor(aGMPService,
                     NS_ConvertUTF16toUTF8(aKeySystem),
                     NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
                     NS_LITERAL_CSTRING("h264")) &&
         MP4Decoder::CanHandleMediaType(aContentType, aDiagnostics);
}
// If this keysystem's CDM explicitly says it doesn't support decoding,
// that means it's OK with passing the decrypted samples back to Gecko
// for decoding. Note we special case Clearkey on Windows, where we need
// to check for whether WMF is usable because the CDM uses that
// to decode.
static bool
GMPDecryptsAndGeckoDecodesH264(mozIGeckoMediaPluginService* aGMPService,
                               const nsAString& aKeySystem,
                               const nsAString& aContentType)
{
  MOZ_ASSERT(HaveGMPFor(aGMPService,
                        NS_ConvertUTF16toUTF8(aKeySystem),
                        NS_LITERAL_CSTRING(GMP_API_DECRYPTOR)));
  MOZ_ASSERT(IsH264ContentType(aContentType));
  return
    (!HaveGMPFor(aGMPService,
                 NS_ConvertUTF16toUTF8(aKeySystem),
                 NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
                 NS_LITERAL_CSTRING("h264"))
#ifdef XP_WIN
    // Clearkey on Windows advertises that it can decode in its GMP info
    // file, but uses Windows Media Foundation to decode. That's not present
    // on Windows XP, and on some Vista, Windows N, and KN variants without
    // certain services packs. So don't try to use gmp-clearkey for decoding
    // if we don't have a decoder here.
    || (aKeySystem.EqualsLiteral("org.w3.clearkey") && !WMFDecoderModule::HasH264())
#endif
    ) && MP4Decoder::CanHandleMediaType(aContentType);
}