Bug 1181651: Replace use of stagefright::Vector with nsTArray. r=kentuckyfriedtakahe

This commit is contained in:
Jean-Yves Avenard 2015-08-20 15:29:39 +10:00
parent 4926c595bb
commit bc78372079
3 changed files with 37 additions and 16 deletions

View File

@ -68,13 +68,13 @@ private:
static inline bool
ConvertIndex(FallibleTArray<Index::Indice>& aDest,
const stagefright::Vector<stagefright::MediaSource::Indice>& aIndex,
const nsTArray<stagefright::MediaSource::Indice>& aIndex,
int64_t aMediaTime)
{
if (!aDest.SetCapacity(aIndex.size(), mozilla::fallible)) {
if (!aDest.SetCapacity(aIndex.Length(), mozilla::fallible)) {
return false;
}
for (size_t i = 0; i < aIndex.size(); i++) {
for (size_t i = 0; i < aIndex.Length(); i++) {
Index::Indice indice;
const stagefright::MediaSource::Indice& s_indice = aIndex[i];
indice.start_offset = s_indice.start_offset;

View File

@ -23,6 +23,7 @@
#include <media/stagefright/MediaErrors.h>
#include <utils/RefBase.h>
#include <utils/Vector.h>
#include "nsTArray.h"
namespace stagefright {
@ -118,7 +119,7 @@ struct MediaSource : public virtual RefBase {
bool sync;
};
virtual Vector<Indice> exportIndex() = 0;
virtual nsTArray<Indice> exportIndex() = 0;
protected:
virtual ~MediaSource();

View File

@ -62,7 +62,7 @@ public:
virtual status_t read(MediaBuffer **buffer, const ReadOptions *options = NULL);
virtual status_t fragmentedRead(MediaBuffer **buffer, const ReadOptions *options = NULL);
virtual Vector<Indice> exportIndex();
virtual nsTArray<Indice> exportIndex();
protected:
virtual ~MPEG4Source();
@ -4108,13 +4108,30 @@ static int compositionOrder(MediaSource::Indice* const* indice0,
}
}
Vector<MediaSource::Indice> MPEG4Source::exportIndex()
class CompositionSorter
{
Vector<Indice> index;
public:
bool LessThan(MediaSource::Indice* aFirst, MediaSource::Indice* aSecond) const
{
return aFirst->start_composition < aSecond->start_composition;
}
bool Equals(MediaSource::Indice* aFirst, MediaSource::Indice* aSecond) const
{
return aFirst->start_composition == aSecond->start_composition;
}
};
nsTArray<MediaSource::Indice> MPEG4Source::exportIndex()
{
FallibleTArray<MediaSource::Indice> index;
if (!mTimescale) {
return index;
}
if (!index.SetCapacity(mSampleTable->countSamples(), mozilla::fallible)) {
return index;
}
for (uint32_t sampleIndex = 0; sampleIndex < mSampleTable->countSamples();
sampleIndex++) {
off64_t offset;
@ -4138,20 +4155,23 @@ Vector<MediaSource::Indice> MPEG4Source::exportIndex()
indice.end_composition =
(compositionTime * 1000000ll + duration * 1000000ll) / mTimescale;
indice.sync = isSyncSample;
index.add(indice);
// FIXME: Make this infallible after bug 968520 is done.
MOZ_ALWAYS_TRUE(index.AppendElement(indice, mozilla::fallible));
}
// Fix up composition durations so we don't end up with any unsightly gaps.
if (index.size() != 0) {
Indice* array = index.editArray();
Vector<Indice*> composition_order;
composition_order.reserve(index.size());
for (uint32_t i = 0; i < index.size(); i++) {
composition_order.add(&array[i]);
if (index.Length() != 0) {
FallibleTArray<Indice*> composition_order;
if (!composition_order.SetCapacity(index.Length(), mozilla::fallible)) {
return index;
}
for (uint32_t i = 0; i < index.Length(); i++) {
// FIXME: Make this infallible after bug 968520 is done.
MOZ_ALWAYS_TRUE(composition_order.AppendElement(&index[i], mozilla::fallible));
}
composition_order.sort(compositionOrder);
for (uint32_t i = 0; i + 1 < composition_order.size(); i++) {
composition_order.Sort(CompositionSorter());
for (uint32_t i = 0; i + 1 < composition_order.Length(); i++) {
composition_order[i]->end_composition =
composition_order[i + 1]->start_composition;
}