1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef GMPUtils_h_ 7 #define GMPUtils_h_ 8 9 #include "mozilla/UniquePtr.h" 10 #include "mozilla/RefPtr.h" 11 #include "mozilla/AbstractThread.h" 12 #include "nsStringFwd.h" 13 #include "nsTArray.h" 14 #include "nsCOMPtr.h" 15 #include "nsClassHashtable.h" 16 17 #define CHROMIUM_CDM_API_BACKWARD_COMPAT "chromium-cdm9-host4" 18 #define CHROMIUM_CDM_API "chromium-cdm10-host4" 19 20 class nsIFile; 21 class nsIDirectoryEnumerator; 22 23 namespace mozilla { 24 25 template <typename T> 26 struct DestroyPolicy { operatorDestroyPolicy27 void operator()(T* aGMPObject) const { aGMPObject->Destroy(); } 28 }; 29 30 template <typename T> 31 using GMPUniquePtr = mozilla::UniquePtr<T, DestroyPolicy<T>>; 32 33 void SplitAt(const char* aDelims, const nsACString& aInput, 34 nsTArray<nsCString>& aOutTokens); 35 36 nsCString ToHexString(const nsTArray<uint8_t>& aBytes); 37 38 nsCString ToHexString(const uint8_t* aBytes, uint32_t aLength); 39 40 bool FileExists(nsIFile* aFile); 41 42 // Enumerate directory entries for a specified path. 43 class DirectoryEnumerator { 44 public: 45 enum Mode { 46 DirsOnly, // Enumeration only includes directories. 47 FilesAndDirs // Enumeration includes directories and non-directory files. 48 }; 49 50 DirectoryEnumerator(nsIFile* aPath, Mode aMode); 51 52 already_AddRefed<nsIFile> Next(); 53 54 private: 55 Mode mMode; 56 nsCOMPtr<nsIDirectoryEnumerator> mIter; 57 }; 58 59 class GMPInfoFileParser { 60 public: 61 bool Init(nsIFile* aFile); 62 bool Contains(const nsCString& aKey) const; 63 nsCString Get(const nsCString& aKey) const; 64 65 private: 66 nsClassHashtable<nsCStringHashKey, nsCString> mValues; 67 }; 68 69 bool ReadIntoString(nsIFile* aFile, nsCString& aOutDst, size_t aMaxLength); 70 71 bool HaveGMPFor(const nsCString& aAPI, nsTArray<nsCString>&& aTags); 72 73 void LogToConsole(const nsAString& aMsg); 74 75 RefPtr<AbstractThread> GetGMPAbstractThread(); 76 77 // Returns the number of bytes required to store an aWidth x aHeight image in 78 // I420 format, padded so that the width and height are multiples of 16. 79 size_t I420FrameBufferSizePadded(int32_t aWidth, int32_t aHeight); 80 81 } // namespace mozilla 82 83 #endif 84