Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=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 MOZILLA_RESOURCEQUEUE_H_
8 : #define MOZILLA_RESOURCEQUEUE_H_
9 :
10 : #include "nsDeque.h"
11 : #include "MediaData.h"
12 :
13 : namespace mozilla {
14 :
15 : class ErrorResult;
16 :
17 : // A SourceBufferResource has a queue containing the data that is appended
18 : // to it. The queue holds instances of ResourceItem which is an array of the
19 : // bytes. Appending data to the SourceBufferResource pushes this onto the
20 : // queue.
21 :
22 : // Data is evicted once it reaches a size threshold. This pops the items off
23 : // the front of the queue and deletes it. If an eviction happens then the
24 : // MediaSource is notified (done in SourceBuffer::AppendData) which then
25 : // requests all SourceBuffers to evict data up to approximately the same
26 : // timepoint.
27 :
28 0 : struct ResourceItem {
29 : explicit ResourceItem(MediaByteBuffer* aData);
30 : size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
31 : RefPtr<MediaByteBuffer> mData;
32 : };
33 :
34 0 : class ResourceQueue : private nsDeque {
35 : public:
36 : ResourceQueue();
37 :
38 : // Returns the logical byte offset of the start of the data.
39 : uint64_t GetOffset();
40 :
41 : // Returns the length of all items in the queue plus the offset.
42 : // This is the logical length of the resource.
43 : uint64_t GetLength();
44 :
45 : // Copies aCount bytes from aOffset in the queue into aDest.
46 : void CopyData(uint64_t aOffset, uint32_t aCount, char* aDest);
47 :
48 : void AppendItem(MediaByteBuffer* aData);
49 :
50 : // Tries to evict at least aSizeToEvict from the queue up until
51 : // aOffset. Returns amount evicted.
52 : uint32_t Evict(uint64_t aOffset, uint32_t aSizeToEvict,
53 : ErrorResult& aRv);
54 :
55 : uint32_t EvictBefore(uint64_t aOffset, ErrorResult& aRv);
56 :
57 : uint32_t EvictAll();
58 :
59 : size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
60 :
61 : #if defined(DEBUG)
62 : void Dump(const char* aPath);
63 : #endif
64 :
65 : private:
66 : ResourceItem* ResourceAt(uint32_t aIndex) const;
67 :
68 : // Returns the index of the resource that contains the given
69 : // logical offset. aResourceOffset will contain the offset into
70 : // the resource at the given index returned if it is not null. If
71 : // no such resource exists, returns GetSize() and aOffset is
72 : // untouched.
73 : uint32_t GetAtOffset(uint64_t aOffset, uint32_t *aResourceOffset);
74 :
75 : ResourceItem* PopFront();
76 :
77 : // Logical length of the resource.
78 : uint64_t mLogicalLength;
79 :
80 : // Logical offset into the resource of the first element in the queue.
81 : uint64_t mOffset;
82 : };
83 :
84 : } // namespace mozilla
85 :
86 : #endif /* MOZILLA_RESOURCEQUEUE_H_ */
|