Bug 1127554 - Make MP4Sample::Pad fallible. v1 r=mattwoodrow

This commit is contained in:
Bobby Holley 2015-02-11 14:36:21 -08:00
parent 5314527fbc
commit 9092b791ba
4 changed files with 20 additions and 5 deletions

View File

@ -88,7 +88,12 @@ FFmpegAudioDecoder<LIBAV_VER>::DecodePacket(MP4Sample* aSample)
AVPacket packet;
av_init_packet(&packet);
aSample->Pad(FF_INPUT_BUFFER_PADDING_SIZE);
if (!aSample->Pad(FF_INPUT_BUFFER_PADDING_SIZE)) {
NS_WARNING("FFmpeg audio decoder failed to allocate sample.");
mCallback->Error();
return;
}
packet.data = aSample->data;
packet.size = aSample->size;

View File

@ -54,7 +54,12 @@ FFmpegH264Decoder<LIBAV_VER>::DoDecodeFrame(mp4_demuxer::MP4Sample* aSample)
av_init_packet(&packet);
mp4_demuxer::AnnexB::ConvertSampleToAnnexB(aSample);
aSample->Pad(FF_INPUT_BUFFER_PADDING_SIZE);
if (!aSample->Pad(FF_INPUT_BUFFER_PADDING_SIZE)) {
NS_WARNING("FFmpeg h264 decoder failed to allocate sample.");
mCallback->Error();
return DecodeResult::DECODE_ERROR;
}
packet.data = aSample->data;
packet.size = aSample->size;
packet.dts = aSample->decode_timestamp;

View File

@ -254,7 +254,7 @@ MP4Sample::Update(int64_t& aMediaTime)
crypto.Update(m);
}
void
bool
MP4Sample::Pad(size_t aPaddingBytes)
{
size_t newSize = size + aPaddingBytes;
@ -263,7 +263,10 @@ MP4Sample::Pad(size_t aPaddingBytes)
// not then we copy to a new buffer.
uint8_t* newData = mMediaBuffer && newSize <= mMediaBuffer->size()
? data
: new uint8_t[newSize];
: new (fallible) uint8_t[newSize];
if (!newData) {
return false;
}
memset(newData + size, 0, aPaddingBytes);
@ -275,6 +278,8 @@ MP4Sample::Pad(size_t aPaddingBytes)
mMediaBuffer = nullptr;
}
}
return true;
}
void

View File

@ -158,7 +158,7 @@ public:
virtual ~MP4Sample();
MP4Sample* Clone() const;
void Update(int64_t& aMediaTime);
void Pad(size_t aPaddingBytes);
bool Pad(size_t aPaddingBytes);
stagefright::MediaBuffer* mMediaBuffer;