Bug 1341483 - MP4Metadata::Metadata() now also returns a success/error code - r=kinetik

The returned MediaResult is used as error or warning in MP4Demuxer::Init().

MozReview-Commit-ID: Bnv4xG8bCJ4

--HG--
extra : rebase_source : c1952ed61396834b0cd7da58c9b64481a5c46ab1
This commit is contained in:
Gerald Squelart 2017-02-27 13:01:11 +11:00
Родитель f8036e08d5
Коммит 1bbbbd132d
4 изменённых файлов: 68 добавлений и 22 удалений

Просмотреть файл

@ -127,16 +127,21 @@ MP4Demuxer::Init()
// 'result' will capture the first warning, if any.
MediaResult result{NS_OK};
RefPtr<MediaByteBuffer> initData = mp4_demuxer::MP4Metadata::Metadata(stream);
if (!initData) {
mp4_demuxer::MP4Metadata::ResultAndByteBuffer initData =
mp4_demuxer::MP4Metadata::Metadata(stream);
if (!initData.Ref()) {
return InitPromise::CreateAndReject(
MediaResult(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
RESULT_DETAIL("Invalid MP4 metadata or OOM")),
NS_FAILED(initData.Result())
? Move(initData.Result())
: MediaResult(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
RESULT_DETAIL("Invalid MP4 metadata or OOM")),
__func__);
} else if (NS_FAILED(initData.Result()) && result == NS_OK) {
result = Move(initData.Result());
}
RefPtr<mp4_demuxer::BufferStream> bufferstream =
new mp4_demuxer::BufferStream(initData);
new mp4_demuxer::BufferStream(initData.Ref());
mp4_demuxer::MP4Metadata metadata{bufferstream};

Просмотреть файл

@ -79,7 +79,8 @@ public:
explicit MP4MetadataStagefright(Stream* aSource);
~MP4MetadataStagefright();
static already_AddRefed<mozilla::MediaByteBuffer> Metadata(Stream* aSource);
static MP4Metadata::ResultAndByteBuffer Metadata(Stream* aSource);
uint32_t GetNumberTracks(mozilla::TrackInfo::TrackType aType) const;
mozilla::UniquePtr<mozilla::TrackInfo> GetTrackInfo(mozilla::TrackInfo::TrackType aType,
size_t aTrackNumber) const;
@ -126,7 +127,8 @@ public:
explicit MP4MetadataRust(Stream* aSource);
~MP4MetadataRust();
static already_AddRefed<mozilla::MediaByteBuffer> Metadata(Stream* aSource);
static MP4Metadata::ResultAndByteBuffer Metadata(Stream* aSource);
uint32_t GetNumberTracks(mozilla::TrackInfo::TrackType aType) const;
mozilla::UniquePtr<mozilla::TrackInfo> GetTrackInfo(mozilla::TrackInfo::TrackType aType,
size_t aTrackNumber) const;
@ -243,7 +245,7 @@ MP4Metadata::~MP4Metadata()
{
}
/*static*/ already_AddRefed<mozilla::MediaByteBuffer>
/*static*/ MP4Metadata::ResultAndByteBuffer
MP4Metadata::Metadata(Stream* aSource)
{
return MP4MetadataStagefright::Metadata(aSource);
@ -685,11 +687,17 @@ MP4MetadataStagefright::GetTrackNumber(mozilla::TrackID aTrackID)
return -1;
}
/*static*/ already_AddRefed<mozilla::MediaByteBuffer>
/*static*/ MP4Metadata::ResultAndByteBuffer
MP4MetadataStagefright::Metadata(Stream* aSource)
{
auto parser = mozilla::MakeUnique<MoofParser>(aSource, 0, false);
return parser->Metadata();
RefPtr<mozilla::MediaByteBuffer> buffer = parser->Metadata();
if (!buffer) {
return {MediaResult(NS_ERROR_DOM_MEDIA_METADATA_ERR,
RESULT_DETAIL("Cannot parse metadata")),
nullptr};
}
return {NS_OK, Move(buffer)};
}
bool
@ -951,11 +959,11 @@ MP4MetadataRust::ReadTrackIndice(mp4parse_byte_data* aIndices, mozilla::TrackID
return true;
}
/*static*/ already_AddRefed<mozilla::MediaByteBuffer>
/*static*/ MP4Metadata::ResultAndByteBuffer
MP4MetadataRust::Metadata(Stream* aSource)
{
MOZ_ASSERT(false, "Not yet implemented");
return nullptr;
return {NS_ERROR_NOT_IMPLEMENTED, nullptr};
}
} // namespace mp4_demuxer

Просмотреть файл

@ -5,16 +5,17 @@
#ifndef MP4METADATA_H_
#define MP4METADATA_H_
#include "mozilla/TypeTraits.h"
#include "mozilla/UniquePtr.h"
#include "mp4_demuxer/DecoderData.h"
#include "mp4_demuxer/Index.h"
#include "MediaData.h"
#include "MediaInfo.h"
#include "MediaResult.h"
#include "Stream.h"
#include "mp4parse.h"
namespace mp4_demuxer
{
namespace mp4_demuxer {
class MP4MetadataStagefright;
class MP4MetadataRust;
@ -36,7 +37,32 @@ public:
explicit MP4Metadata(Stream* aSource);
~MP4Metadata();
static already_AddRefed<mozilla::MediaByteBuffer> Metadata(Stream* aSource);
// Simple template class containing a MediaResult and another type.
template <typename T>
class ResultAndType
{
public:
template <typename M2, typename T2>
ResultAndType(M2&& aM, T2&& aT)
: mResult(Forward<M2>(aM)), mT(Forward<T2>(aT))
{
}
ResultAndType(const ResultAndType&) = default;
ResultAndType& operator=(const ResultAndType&) = default;
ResultAndType(ResultAndType&&) = default;
ResultAndType& operator=(ResultAndType&&) = default;
mozilla::MediaResult& Result() { return mResult; }
T& Ref() { return mT; }
private:
mozilla::MediaResult mResult;
typename mozilla::Decay<T>::Type mT;
};
using ResultAndByteBuffer = ResultAndType<RefPtr<mozilla::MediaByteBuffer>>;
static ResultAndByteBuffer Metadata(Stream* aSource);
uint32_t GetNumberTracks(mozilla::TrackInfo::TrackType aType) const;
mozilla::UniquePtr<mozilla::TrackInfo> GetTrackInfo(mozilla::TrackInfo::TrackType aType,
size_t aTrackNumber) const;

Просмотреть файл

@ -74,8 +74,10 @@ TEST(stagefright_MP4Metadata, EmptyStream)
{
RefPtr<Stream> stream = new TestStream(nullptr, 0);
RefPtr<MediaByteBuffer> metadataBuffer = MP4Metadata::Metadata(stream);
EXPECT_FALSE(metadataBuffer);
MP4Metadata::ResultAndByteBuffer metadataBuffer =
MP4Metadata::Metadata(stream);
EXPECT_TRUE(NS_OK != metadataBuffer.Result());
EXPECT_FALSE(static_cast<bool>(metadataBuffer.Ref()));
MP4Metadata metadata(stream);
EXPECT_EQ(0u, metadata.GetNumberTracks(TrackInfo::kUndefinedTrack));
@ -275,8 +277,10 @@ TEST(stagefright_MPEG4Metadata, test_case_mp4)
ASSERT_FALSE(buffer.IsEmpty());
RefPtr<Stream> stream = new TestStream(buffer.Elements(), buffer.Length());
RefPtr<MediaByteBuffer> metadataBuffer = MP4Metadata::Metadata(stream);
EXPECT_TRUE(metadataBuffer);
MP4Metadata::ResultAndByteBuffer metadataBuffer =
MP4Metadata::Metadata(stream);
EXPECT_EQ(NS_OK, metadataBuffer.Result());
EXPECT_TRUE(metadataBuffer.Ref());
MP4Metadata metadata(stream);
EXPECT_EQ(0u, metadata.GetNumberTracks(TrackInfo::kUndefinedTrack));
@ -360,7 +364,8 @@ TEST(stagefright_MPEG4Metadata, test_case_mp4_subsets)
RefPtr<TestStream> stream =
new TestStream(buffer.Elements() + offset, size);
RefPtr<MediaByteBuffer> metadataBuffer = MP4Metadata::Metadata(stream);
MP4Metadata::ResultAndByteBuffer metadataBuffer =
MP4Metadata::Metadata(stream);
MP4Metadata metadata(stream);
if (stream->mHighestSuccessfulEndOffset <= 0) {
@ -552,8 +557,10 @@ TEST(stagefright_MP4Metadata, EmptyCTTS)
buffer->AppendElements(media_libstagefright_gtest_video_init_mp4, media_libstagefright_gtest_video_init_mp4_len);
RefPtr<BufferStream> stream = new BufferStream(buffer);
RefPtr<MediaByteBuffer> metadataBuffer = MP4Metadata::Metadata(stream);
EXPECT_TRUE(metadataBuffer);
MP4Metadata::ResultAndByteBuffer metadataBuffer =
MP4Metadata::Metadata(stream);
EXPECT_EQ(NS_OK, metadataBuffer.Result());
EXPECT_TRUE(metadataBuffer.Ref());
MP4Metadata metadata(stream);