MockMediaResource.h (1884B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MOCK_MEDIA_RESOURCE_H_ 8 #define MOCK_MEDIA_RESOURCE_H_ 9 10 #include "MediaResource.h" 11 #include "mozilla/Atomics.h" 12 #include "nsTArray.h" 13 14 namespace mozilla { 15 16 DDLoggedTypeDeclNameAndBase(MockMediaResource, MediaResource); 17 18 class MockMediaResource : public MediaResource, 19 public DecoderDoctorLifeLogger<MockMediaResource> { 20 public: 21 explicit MockMediaResource(const char* aFileName); 22 nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, 23 uint32_t* aBytes) override; 24 // Data stored in file, caching recommended. 25 bool ShouldCacheReads() override { return true; } 26 void Pin() override {} 27 void Unpin() override {} 28 int64_t GetLength() override; 29 int64_t GetNextCachedData(int64_t aOffset) override; 30 int64_t GetCachedDataEnd(int64_t aOffset) override; 31 bool IsDataCachedToEndOfResource(int64_t aOffset) override { return false; } 32 nsresult ReadFromCache(char* aBuffer, int64_t aOffset, 33 uint32_t aCount) override { 34 uint32_t bytesRead = 0; 35 nsresult rv = ReadAt(aOffset, aBuffer, aCount, &bytesRead); 36 NS_ENSURE_SUCCESS(rv, rv); 37 return bytesRead == aCount ? NS_OK : NS_ERROR_FAILURE; 38 } 39 40 nsresult Open(); 41 nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override; 42 43 void MockClearBufferedRanges(); 44 void MockAddBufferedRange(int64_t aStart, int64_t aEnd); 45 46 protected: 47 virtual ~MockMediaResource(); 48 49 private: 50 FILE* mFileHandle; 51 const char* mFileName; 52 MediaByteRangeSet mRanges; 53 Atomic<int> mEntry; 54 }; 55 56 } // namespace mozilla 57 58 #endif