1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 #if !defined(NesteggPacketHolder_h_)
7 # define NesteggPacketHolder_h_
11 # include "nsAutoRef.h"
12 # include "nestegg/nestegg.h"
16 // Holds a nestegg_packet, and its file offset. This is needed so we
17 // know the offset in the file we've played up to, in order to calculate
18 // whether it's likely we can play through to the end without needing
19 // to stop to buffer, given the current download rate.
20 class NesteggPacketHolder
{
22 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NesteggPacketHolder
)
31 bool Init(nestegg_packet
* aPacket
, int64_t aOffset
, unsigned aTrack
,
33 uint64_t timestamp_ns
;
34 if (nestegg_packet_tstamp(aPacket
, ×tamp_ns
) == -1) {
38 // We store the timestamp as signed microseconds so that it's easily
39 // comparable to other timestamps we have in the system.
40 mTimestamp
= timestamp_ns
/ 1000;
44 mIsKeyframe
= aIsKeyframe
;
47 if (!nestegg_packet_duration(aPacket
, &duration_ns
)) {
48 mDuration
= duration_ns
/ 1000;
53 nestegg_packet
* Packet() {
54 MOZ_ASSERT(IsInitialized());
58 MOZ_ASSERT(IsInitialized());
62 MOZ_ASSERT(IsInitialized());
66 MOZ_ASSERT(IsInitialized());
70 MOZ_ASSERT(IsInitialized());
74 MOZ_ASSERT(IsInitialized());
79 ~NesteggPacketHolder() { nestegg_free_packet(mPacket
); }
81 bool IsInitialized() { return mOffset
>= 0; }
83 nestegg_packet
* mPacket
;
85 // Offset in bytes. This is the offset of the end of the Block
86 // which contains the packet.
89 // Packet presentation timestamp in microseconds.
92 // Packet duration in microseconds; -1 if unknown or retrieval failed.
98 // Does this packet contain a keyframe?
101 // Copy constructor and assignment operator not implemented. Don't use them!
102 NesteggPacketHolder(const NesteggPacketHolder
& aOther
);
103 NesteggPacketHolder
& operator=(NesteggPacketHolder
const& aOther
);
106 // Queue for holding nestegg packets.
107 class WebMPacketQueue
{
109 int32_t GetSize() { return mQueue
.size(); }
111 void Push(NesteggPacketHolder
* aItem
) { mQueue
.push_back(aItem
); }
113 void PushFront(NesteggPacketHolder
* aItem
) {
114 mQueue
.push_front(std::move(aItem
));
117 already_AddRefed
<NesteggPacketHolder
> PopFront() {
118 RefPtr
<NesteggPacketHolder
> result
= std::move(mQueue
.front());
120 return result
.forget();
124 while (!mQueue
.empty()) {
130 std::deque
<RefPtr
<NesteggPacketHolder
>> mQueue
;
133 } // namespace mozilla