GMPUtils.h (2517B)
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 "MediaResult.h" 10 #include "gmp-errors.h" 11 #include "mozilla/AbstractThread.h" 12 #include "mozilla/UniquePtr.h" 13 #include "nsCOMPtr.h" 14 #include "nsClassHashtable.h" 15 #include "nsStringFwd.h" 16 #include "nsTArray.h" 17 18 #define CHROMIUM_CDM_API_BACKWARD_COMPAT "chromium-cdm10-host4" 19 #define CHROMIUM_CDM_API "chromium-cdm11-host4" 20 21 class GMPVideoEncodedFrame; 22 class nsIFile; 23 class nsIDirectoryEnumerator; 24 25 namespace mozilla { 26 27 template <typename T> 28 struct DestroyPolicy { 29 void operator()(T* aGMPObject) const { aGMPObject->Destroy(); } 30 }; 31 32 template <typename T> 33 using GMPUniquePtr = mozilla::UniquePtr<T, DestroyPolicy<T>>; 34 35 void SplitAt(const char* aDelims, const nsACString& aInput, 36 nsTArray<nsCString>& aOutTokens); 37 38 nsCString ToHexString(const nsTArray<uint8_t>& aBytes); 39 40 nsCString ToHexString(const uint8_t* aBytes, uint32_t aLength); 41 42 bool FileExists(nsIFile* aFile); 43 44 // Enumerate directory entries for a specified path. 45 class DirectoryEnumerator { 46 public: 47 enum Mode { 48 DirsOnly, // Enumeration only includes directories. 49 FilesAndDirs // Enumeration includes directories and non-directory files. 50 }; 51 52 DirectoryEnumerator(nsIFile* aPath, Mode aMode); 53 54 already_AddRefed<nsIFile> Next(); 55 56 private: 57 Mode mMode; 58 nsCOMPtr<nsIDirectoryEnumerator> mIter; 59 }; 60 61 class GMPInfoFileParser { 62 public: 63 bool Init(nsIFile* aFile); 64 bool Contains(const nsCString& aKey) const; 65 nsCString Get(const nsCString& aKey) const; 66 67 private: 68 nsClassHashtable<nsCStringHashKey, nsCString> mValues; 69 }; 70 71 bool ReadIntoString(nsIFile* aFile, nsCString& aOutDst, size_t aMaxLength); 72 73 bool HaveGMPFor(const nsACString& aAPI, const nsTArray<nsCString>& aTags); 74 75 bool IsOnGMPThread(); 76 77 void LogToConsole(const nsAString& aMsg); 78 79 already_AddRefed<nsISerialEventTarget> GetGMPThread(); 80 81 // Returns the number of bytes required to store an aWidth x aHeight image in 82 // I420 format, padded so that the width and height are multiples of 16. 83 size_t I420FrameBufferSizePadded(int32_t aWidth, int32_t aHeight); 84 85 bool AdjustOpenH264NALUSequence(GMPVideoEncodedFrame* aEncodedFrame); 86 87 MediaResult ToMediaResult(GMPErr aErr, const nsACString& aMessage); 88 89 } // namespace mozilla 90 91 #endif