Bug 1148102: P4. Split WebMPacketQueue, use nsRefPtr instead. r=jya

This commit is contained in:
Jan Gerber 2015-07-03 17:38:00 +02:00 committed by Jean-Yves Avenard
parent 215f42557f
commit e37d212fd1
5 changed files with 48 additions and 46 deletions

View File

@ -186,7 +186,7 @@ IntelWebMVideoDecoder::Demux(nsRefPtr<VP8Sample>& aSample, bool* aEOS)
nsRefPtr<NesteggPacketHolder> next_holder(mReader->NextPacket(WebMReader::VIDEO));
if (next_holder) {
next_tstamp = holder->Timestamp();
mReader->PushVideoPacket(next_holder.forget());
mReader->PushVideoPacket(next_holder);
} else {
next_tstamp = tstamp;
next_tstamp += tstamp - mReader->GetLastVideoFrameTime();

View File

@ -73,6 +73,38 @@ private:
NesteggPacketHolder& operator= (NesteggPacketHolder const& aOther);
};
// Queue for holding nestegg packets.
class WebMPacketQueue {
public:
int32_t GetSize() {
return mQueue.size();
}
void Push(NesteggPacketHolder* aItem) {
mQueue.push_back(aItem);
}
void PushFront(NesteggPacketHolder* aItem) {
mQueue.push_front(Move(aItem));
}
nsRefPtr<NesteggPacketHolder> PopFront() {
nsRefPtr<NesteggPacketHolder> result = mQueue.front();
mQueue.pop_front();
return result;
}
void Reset() {
while (!mQueue.empty()) {
mQueue.pop_front();
}
}
private:
std::deque<nsRefPtr<NesteggPacketHolder>> mQueue;
};
} // namespace mozilla
#endif

View File

@ -114,7 +114,7 @@ SoftwareWebMVideoDecoder::DecodeVideoFrame(bool &aKeyframeSkip,
nsRefPtr<NesteggPacketHolder> next_holder(mReader->NextPacket(WebMReader::VIDEO));
if (next_holder) {
next_tstamp = next_holder->Timestamp();
mReader->PushVideoPacket(next_holder.forget());
mReader->PushVideoPacket(next_holder);
} else {
next_tstamp = tstamp;
next_tstamp += tstamp - mReader->GetLastVideoFrameTime();

View File

@ -538,7 +538,7 @@ bool WebMReader::DecodeAudioPacket(NesteggPacketHolder* aHolder)
return true;
}
already_AddRefed<NesteggPacketHolder> WebMReader::NextPacket(TrackType aTrackType)
nsRefPtr<NesteggPacketHolder> WebMReader::NextPacket(TrackType aTrackType)
{
// The packet queue that packets will be pushed on if they
// are not the type we are interested in.
@ -575,18 +575,18 @@ already_AddRefed<NesteggPacketHolder> WebMReader::NextPacket(TrackType aTrackTyp
if (hasOtherType && otherTrack == holder->Track()) {
// Save the packet for when we want these packets
otherPackets.Push(holder.forget());
otherPackets.Push(holder);
continue;
}
// The packet is for the track we want to play
if (hasType && ourTrack == holder->Track()) {
return holder.forget();
return holder;
}
} while (true);
}
already_AddRefed<NesteggPacketHolder>
nsRefPtr<NesteggPacketHolder>
WebMReader::DemuxPacket()
{
nestegg_packet* packet;
@ -629,7 +629,7 @@ WebMReader::DemuxPacket()
return nullptr;
}
return holder.forget();
return holder;
}
bool WebMReader::DecodeAudioData()
@ -655,10 +655,10 @@ bool WebMReader::FilterPacketByTime(int64_t aEndTime, WebMPacketQueue& aOutput)
}
int64_t tstamp = holder->Timestamp();
if (tstamp >= aEndTime) {
PushVideoPacket(holder.forget());
PushVideoPacket(holder);
return true;
} else {
aOutput.PushFront(holder.forget());
aOutput.PushFront(holder);
}
}
@ -691,7 +691,7 @@ int64_t WebMReader::GetNextKeyframeTime(int64_t aTimeThreshold)
keyframeTime = holder->Timestamp();
}
skipPacketQueue.PushFront(holder.forget());
skipPacketQueue.PushFront(holder);
}
uint32_t size = skipPacketQueue.GetSize();
@ -716,9 +716,9 @@ bool WebMReader::DecodeVideoFrame(bool &aKeyframeSkip, int64_t aTimeThreshold)
return mVideoDecoder->DecodeVideoFrame(aKeyframeSkip, aTimeThreshold);
}
void WebMReader::PushVideoPacket(already_AddRefed<NesteggPacketHolder> aItem)
void WebMReader::PushVideoPacket(NesteggPacketHolder* aItem)
{
mVideoPackets.PushFront(Move(aItem));
mVideoPackets.PushFront(aItem);
}
nsRefPtr<MediaDecoderReader::SeekPromise>

View File

@ -24,37 +24,7 @@ static const unsigned NS_PER_USEC = 1000;
static const double NS_PER_S = 1e9;
class WebMBufferedState;
// Queue for holding nestegg packets.
class WebMPacketQueue {
public:
int32_t GetSize() {
return mQueue.size();
}
void Push(already_AddRefed<NesteggPacketHolder> aItem) {
mQueue.push_back(Move(aItem));
}
void PushFront(already_AddRefed<NesteggPacketHolder> aItem) {
mQueue.push_front(Move(aItem));
}
already_AddRefed<NesteggPacketHolder> PopFront() {
nsRefPtr<NesteggPacketHolder> result = mQueue.front().forget();
mQueue.pop_front();
return result.forget();
}
void Reset() {
while (!mQueue.empty()) {
mQueue.pop_front();
}
}
private:
std::deque<nsRefPtr<NesteggPacketHolder>> mQueue;
};
class WebMPacketQueue;
class WebMReader;
@ -135,10 +105,10 @@ public:
// Read a packet from the nestegg file. Returns nullptr if all packets for
// the particular track have been read. Pass VIDEO or AUDIO to indicate the
// type of the packet we want to read.
already_AddRefed<NesteggPacketHolder> NextPacket(TrackType aTrackType);
nsRefPtr<NesteggPacketHolder> NextPacket(TrackType aTrackType);
// Pushes a packet to the front of the video packet queue.
virtual void PushVideoPacket(already_AddRefed<NesteggPacketHolder> aItem);
virtual void PushVideoPacket(NesteggPacketHolder* aItem);
int GetVideoCodec();
nsIntRect GetPicture();
@ -181,7 +151,7 @@ private:
// Internal method that demuxes the next packet from the stream. The caller
// is responsible for making sure it doesn't get lost.
already_AddRefed<NesteggPacketHolder> DemuxPacket();
nsRefPtr<NesteggPacketHolder> DemuxPacket();
// libnestegg context for webm container. Access on state machine thread
// or decoder thread only.