Bug 603912 - Backed out changeset ee16bb4a5c95 a=backout

This commit is contained in:
Chris Pearce 2010-10-17 10:03:00 +13:00
parent dbe8ff3cd4
commit 2a059431ea
2 changed files with 39 additions and 26 deletions

View File

@ -66,13 +66,6 @@ static const unsigned NS_PER_MS = 1000000;
static const float NS_PER_S = 1e9; static const float NS_PER_S = 1e9;
static const float MS_PER_S = 1e3; static const float MS_PER_S = 1e3;
NS_SPECIALIZE_TEMPLATE
class nsAutoRefTraits<nestegg_packet> : public nsPointerRefTraits<nestegg_packet>
{
public:
static void Release(nestegg_packet* aPacket) { nestegg_free_packet(aPacket); }
};
// Functions for reading and seeking using nsMediaStream required for // Functions for reading and seeking using nsMediaStream required for
// nestegg_io. The 'user data' passed to these functions is the // nestegg_io. The 'user data' passed to these functions is the
// decoder from which the media stream is obtained. // decoder from which the media stream is obtained.
@ -365,6 +358,7 @@ PRBool nsWebMReader::DecodeAudioPacket(nestegg_packet* aPacket)
uint64_t tstamp = 0; uint64_t tstamp = 0;
r = nestegg_packet_tstamp(aPacket, &tstamp); r = nestegg_packet_tstamp(aPacket, &tstamp);
if (r == -1) { if (r == -1) {
nestegg_free_packet(aPacket);
return PR_FALSE; return PR_FALSE;
} }
@ -411,17 +405,20 @@ PRBool nsWebMReader::DecodeAudioPacket(nestegg_packet* aPacket)
size_t length; size_t length;
r = nestegg_packet_data(aPacket, i, &data, &length); r = nestegg_packet_data(aPacket, i, &data, &length);
if (r == -1) { if (r == -1) {
nestegg_free_packet(aPacket);
return PR_FALSE; return PR_FALSE;
} }
ogg_packet opacket = InitOggPacket(data, length, PR_FALSE, PR_FALSE, -1); ogg_packet opacket = InitOggPacket(data, length, PR_FALSE, PR_FALSE, -1);
if (vorbis_synthesis(&mVorbisBlock, &opacket) != 0) { if (vorbis_synthesis(&mVorbisBlock, &opacket) != 0) {
nestegg_free_packet(aPacket);
return PR_FALSE; return PR_FALSE;
} }
if (vorbis_synthesis_blockin(&mVorbisDsp, if (vorbis_synthesis_blockin(&mVorbisDsp,
&mVorbisBlock) != 0) { &mVorbisBlock) != 0) {
nestegg_free_packet(aPacket);
return PR_FALSE; return PR_FALSE;
} }
@ -439,11 +436,13 @@ PRBool nsWebMReader::DecodeAudioPacket(nestegg_packet* aPacket)
PRInt64 duration = 0; PRInt64 duration = 0;
if (!SamplesToMs(samples, rate, duration)) { if (!SamplesToMs(samples, rate, duration)) {
NS_WARNING("Int overflow converting WebM audio duration"); NS_WARNING("Int overflow converting WebM audio duration");
nestegg_free_packet(aPacket);
return PR_FALSE; return PR_FALSE;
} }
PRInt64 total_duration = 0; PRInt64 total_duration = 0;
if (!SamplesToMs(total_samples, rate, total_duration)) { if (!SamplesToMs(total_samples, rate, total_duration)) {
NS_WARNING("Int overflow converting WebM audio total_duration"); NS_WARNING("Int overflow converting WebM audio total_duration");
nestegg_free_packet(aPacket);
return PR_FALSE; return PR_FALSE;
} }
@ -458,15 +457,18 @@ PRBool nsWebMReader::DecodeAudioPacket(nestegg_packet* aPacket)
mAudioQueue.Push(s); mAudioQueue.Push(s);
mAudioSamples += samples; mAudioSamples += samples;
if (vorbis_synthesis_read(&mVorbisDsp, samples) != 0) { if (vorbis_synthesis_read(&mVorbisDsp, samples) != 0) {
nestegg_free_packet(aPacket);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
nestegg_free_packet(aPacket);
return PR_TRUE; return PR_TRUE;
} }
nsReturnRef<nestegg_packet> nsWebMReader::NextPacket(TrackType aTrackType) nestegg_packet* nsWebMReader::NextPacket(TrackType aTrackType)
{ {
// The packet queue that packets will be pushed on if they // The packet queue that packets will be pushed on if they
// are not the type we are interested in. // are not the type we are interested in.
@ -491,30 +493,30 @@ nsReturnRef<nestegg_packet> nsWebMReader::NextPacket(TrackType aTrackType)
// Value of other track // Value of other track
PRUint32 otherTrack = aTrackType == VIDEO ? mAudioTrack : mVideoTrack; PRUint32 otherTrack = aTrackType == VIDEO ? mAudioTrack : mVideoTrack;
nsAutoRef<nestegg_packet> packet; nestegg_packet* packet = NULL;
if (packets.GetSize() > 0) { if (packets.GetSize() > 0) {
packet.own(packets.PopFront()); packet = packets.PopFront();
} else { }
else {
// Keep reading packets until we find a packet // Keep reading packets until we find a packet
// for the track we want. // for the track we want.
do { do {
nestegg_packet* p; int r = nestegg_read_packet(mContext, &packet);
int r = nestegg_read_packet(mContext, &p);
if (r <= 0) { if (r <= 0) {
return nsReturnRef<nestegg_packet>(); return NULL;
} }
packet.own(p);
unsigned int track = 0; unsigned int track = 0;
r = nestegg_packet_track(packet, &track); r = nestegg_packet_track(packet, &track);
if (r == -1) { if (r == -1) {
return nsReturnRef<nestegg_packet>(); nestegg_free_packet(packet);
return NULL;
} }
if (hasOtherType && otherTrack == track) { if (hasOtherType && otherTrack == track) {
// Save the packet for when we want these packets // Save the packet for when we want these packets
otherPackets.Push(packet.disown()); otherPackets.Push(packet);
continue; continue;
} }
@ -522,10 +524,13 @@ nsReturnRef<nestegg_packet> nsWebMReader::NextPacket(TrackType aTrackType)
if (hasType && ourTrack == track) { if (hasType && ourTrack == track) {
break; break;
} }
// The packet is for a track we're not interested in
nestegg_free_packet(packet);
} while (PR_TRUE); } while (PR_TRUE);
} }
return packet.out(); return packet;
} }
PRBool nsWebMReader::DecodeAudioData() PRBool nsWebMReader::DecodeAudioData()
@ -533,7 +538,7 @@ PRBool nsWebMReader::DecodeAudioData()
MonitorAutoEnter mon(mMonitor); MonitorAutoEnter mon(mMonitor);
NS_ASSERTION(mDecoder->OnStateMachineThread() || mDecoder->OnDecodeThread(), NS_ASSERTION(mDecoder->OnStateMachineThread() || mDecoder->OnDecodeThread(),
"Should be on state machine thread or decode thread."); "Should be on state machine thread or decode thread.");
nsAutoRef<nestegg_packet> packet(NextPacket(AUDIO)); nestegg_packet* packet = NextPacket(AUDIO);
if (!packet) { if (!packet) {
mAudioQueue.Finish(); mAudioQueue.Finish();
return PR_FALSE; return PR_FALSE;
@ -548,28 +553,32 @@ PRBool nsWebMReader::DecodeVideoFrame(PRBool &aKeyframeSkip,
MonitorAutoEnter mon(mMonitor); MonitorAutoEnter mon(mMonitor);
NS_ASSERTION(mDecoder->OnStateMachineThread() || mDecoder->OnDecodeThread(), NS_ASSERTION(mDecoder->OnStateMachineThread() || mDecoder->OnDecodeThread(),
"Should be on state machine or decode thread."); "Should be on state machine or decode thread.");
int r = 0;
nestegg_packet* packet = NextPacket(VIDEO);
nsAutoRef<nestegg_packet> packet(NextPacket(VIDEO));
if (!packet) { if (!packet) {
mVideoQueue.Finish(); mVideoQueue.Finish();
return PR_FALSE; return PR_FALSE;
} }
unsigned int track = 0; unsigned int track = 0;
int r = nestegg_packet_track(packet, &track); r = nestegg_packet_track(packet, &track);
if (r == -1) { if (r == -1) {
nestegg_free_packet(packet);
return PR_FALSE; return PR_FALSE;
} }
unsigned int count = 0; unsigned int count = 0;
r = nestegg_packet_count(packet, &count); r = nestegg_packet_count(packet, &count);
if (r == -1) { if (r == -1) {
nestegg_free_packet(packet);
return PR_FALSE; return PR_FALSE;
} }
uint64_t tstamp = 0; uint64_t tstamp = 0;
r = nestegg_packet_tstamp(packet, &tstamp); r = nestegg_packet_tstamp(packet, &tstamp);
if (r == -1) { if (r == -1) {
nestegg_free_packet(packet);
return PR_FALSE; return PR_FALSE;
} }
@ -579,13 +588,14 @@ PRBool nsWebMReader::DecodeVideoFrame(PRBool &aKeyframeSkip,
// video frame. // video frame.
uint64_t next_tstamp = 0; uint64_t next_tstamp = 0;
{ {
nsAutoRef<nestegg_packet> next_packet(NextPacket(VIDEO)); nestegg_packet* next_packet = NextPacket(VIDEO);
if (next_packet) { if (next_packet) {
r = nestegg_packet_tstamp(next_packet, &next_tstamp); r = nestegg_packet_tstamp(next_packet, &next_tstamp);
if (r == -1) { if (r == -1) {
nestegg_free_packet(next_packet);
return PR_FALSE; return PR_FALSE;
} }
mVideoPackets.PushFront(next_packet.disown()); mVideoPackets.PushFront(next_packet);
} else { } else {
MonitorAutoExit exitMon(mMonitor); MonitorAutoExit exitMon(mMonitor);
MonitorAutoEnter decoderMon(mDecoder->GetMonitor()); MonitorAutoEnter decoderMon(mDecoder->GetMonitor());
@ -605,6 +615,7 @@ PRBool nsWebMReader::DecodeVideoFrame(PRBool &aKeyframeSkip,
size_t length; size_t length;
r = nestegg_packet_data(packet, i, &data, &length); r = nestegg_packet_data(packet, i, &data, &length);
if (r == -1) { if (r == -1) {
nestegg_free_packet(packet);
return PR_FALSE; return PR_FALSE;
} }
@ -622,6 +633,7 @@ PRBool nsWebMReader::DecodeVideoFrame(PRBool &aKeyframeSkip,
} }
if(vpx_codec_decode(&mVP8, data, length, NULL, 0)) { if(vpx_codec_decode(&mVP8, data, length, NULL, 0)) {
nestegg_free_packet(packet);
return PR_FALSE; return PR_FALSE;
} }
@ -668,12 +680,14 @@ PRBool nsWebMReader::DecodeVideoFrame(PRBool &aKeyframeSkip,
si.is_kf, si.is_kf,
-1); -1);
if (!v) { if (!v) {
nestegg_free_packet(packet);
return PR_FALSE; return PR_FALSE;
} }
mVideoQueue.Push(v); mVideoQueue.Push(v);
} }
} }
nestegg_free_packet(packet);
return PR_TRUE; return PR_TRUE;
} }

View File

@ -42,7 +42,6 @@
#include "nsDeque.h" #include "nsDeque.h"
#include "nsBuiltinDecoderReader.h" #include "nsBuiltinDecoderReader.h"
#include "nsWebMBufferedParser.h" #include "nsWebMBufferedParser.h"
#include "nsAutoRef.h"
#include "nestegg/nestegg.h" #include "nestegg/nestegg.h"
#include "vpx/vpx_decoder.h" #include "vpx/vpx_decoder.h"
#include "vpx/vp8dx.h" #include "vpx/vp8dx.h"
@ -140,7 +139,7 @@ private:
// Read a packet from the nestegg file. Returns NULL if all packets for // Read a packet from the nestegg file. Returns NULL if all packets for
// the particular track have been read. Pass VIDEO or AUDIO to indicate the // the particular track have been read. Pass VIDEO or AUDIO to indicate the
// type of the packet we want to read. // type of the packet we want to read.
nsReturnRef<nestegg_packet> NextPacket(TrackType aTrackType); nestegg_packet* NextPacket(TrackType aTrackType);
// Returns an initialized ogg packet with data obtained from the WebM container. // Returns an initialized ogg packet with data obtained from the WebM container.
ogg_packet InitOggPacket(unsigned char* aData, ogg_packet InitOggPacket(unsigned char* aData,