Bug 1419627 - Update mp4parse-rust callers in cheddar->cbindgen migration. r=rillian

MozReview-Commit-ID: AbyXNRrqr4X

--HG--
extra : rebase_source : be40cd12b6155a50528c3806049d3d1f47dda522
This commit is contained in:
Matthew Gregan 2017-11-22 15:15:51 +13:00
Родитель ea7bba6329
Коммит 169b8f6906
5 изменённых файлов: 75 добавлений и 80 удалений

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

@ -61,16 +61,16 @@ vector_reader(uint8_t* buffer, uintptr_t size, void* userdata)
TEST(rust, MP4MetadataEmpty)
{
mp4parse_status rv;
mp4parse_io io;
Mp4parseStatus rv;
Mp4parseIo io;
// Shouldn't be able to read with no context.
rv = mp4parse_read(nullptr);
EXPECT_EQ(rv, mp4parse_status_BAD_ARG);
EXPECT_EQ(rv, MP4PARSE_STATUS_BAD_ARG);
// Shouldn't be able to wrap an mp4parse_io with null members.
// Shouldn't be able to wrap an Mp4parseIo with null members.
io = { nullptr, nullptr };
mp4parse_parser* context = mp4parse_new(&io);
Mp4parseParser* context = mp4parse_new(&io);
EXPECT_EQ(context, nullptr);
io = { nullptr, &io };
@ -87,7 +87,7 @@ TEST(rust, MP4MetadataEmpty)
context = mp4parse_new(&io);
ASSERT_NE(context, nullptr);
rv = mp4parse_read(context);
EXPECT_EQ(rv, mp4parse_status_IO);
EXPECT_EQ(rv, MP4PARSE_STATUS_IO);
mp4parse_free(context);
// Short buffers should fail.
@ -96,21 +96,21 @@ TEST(rust, MP4MetadataEmpty)
context = mp4parse_new(&io);
ASSERT_NE(context, nullptr);
rv = mp4parse_read(context);
EXPECT_EQ(rv, mp4parse_status_INVALID);
EXPECT_EQ(rv, MP4PARSE_STATUS_INVALID);
mp4parse_free(context);
buf.buffer.reserve(4097);
context = mp4parse_new(&io);
ASSERT_NE(context, nullptr);
rv = mp4parse_read(context);
EXPECT_EQ(rv, mp4parse_status_INVALID);
EXPECT_EQ(rv, MP4PARSE_STATUS_INVALID);
mp4parse_free(context);
// Empty buffers should fail.
buf.buffer.resize(4097, 0);
context = mp4parse_new(&io);
rv = mp4parse_read(context);
EXPECT_EQ(rv, mp4parse_status_UNSUPPORTED);
EXPECT_EQ(rv, MP4PARSE_STATUS_UNSUPPORTED);
mp4parse_free(context);
}
@ -126,16 +126,16 @@ TEST(rust, MP4Metadata)
read_vector reader = read_vector(f, s.st_size);
fclose(f);
mp4parse_io io = { vector_reader, &reader };
mp4parse_parser* context = mp4parse_new(&io);
Mp4parseIo io = { vector_reader, &reader };
Mp4parseParser* context = mp4parse_new(&io);
ASSERT_NE(nullptr, context);
mp4parse_status rv = mp4parse_read(context);
EXPECT_EQ(mp4parse_status_OK, rv);
Mp4parseStatus rv = mp4parse_read(context);
EXPECT_EQ(MP4PARSE_STATUS_OK, rv);
uint32_t tracks = 0;
rv = mp4parse_get_track_count(context, &tracks);
EXPECT_EQ(mp4parse_status_OK, rv);
EXPECT_EQ(MP4PARSE_STATUS_OK, rv);
EXPECT_EQ(2U, tracks);
mp4parse_free(context);

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

@ -53,7 +53,7 @@ MP4AudioInfo::IsValid() const
static void
UpdateTrackProtectedInfo(mozilla::TrackInfo& aConfig,
const mp4parse_sinf_info& aSinf)
const Mp4parseSinfInfo& aSinf)
{
if (aSinf.is_encrypted != 0) {
aConfig.mCrypto.mValid = true;
@ -64,12 +64,12 @@ UpdateTrackProtectedInfo(mozilla::TrackInfo& aConfig,
}
void
MP4AudioInfo::Update(const mp4parse_track_info* track,
const mp4parse_track_audio_info* audio)
MP4AudioInfo::Update(const Mp4parseTrackInfo* track,
const Mp4parseTrackAudioInfo* audio)
{
UpdateTrackProtectedInfo(*this, audio->protected_data);
if (track->codec == mp4parse_codec_OPUS) {
if (track->codec == MP4PARSE_CODEC_OPUS) {
mMimeType = NS_LITERAL_CSTRING("audio/opus");
// The Opus decoder expects the container's codec delay or
// pre-skip value, in microseconds, as a 64-bit int at the
@ -80,11 +80,11 @@ MP4AudioInfo::Update(const mp4parse_track_info* track,
mozilla::LittleEndian::readUint16(audio->extra_data.data + 10);
mozilla::OpusDataDecoder::AppendCodecDelay(mCodecSpecificConfig,
mozilla::FramesToUsecs(preskip, 48000).value());
} else if (track->codec == mp4parse_codec_AAC) {
} else if (track->codec == MP4PARSE_CODEC_AAC) {
mMimeType = NS_LITERAL_CSTRING("audio/mp4a-latm");
} else if (track->codec == mp4parse_codec_FLAC) {
} else if (track->codec == MP4PARSE_CODEC_FLAC) {
mMimeType = NS_LITERAL_CSTRING("audio/flac");
} else if (track->codec == mp4parse_codec_MP3) {
} else if (track->codec == MP4PARSE_CODEC_MP3) {
mMimeType = NS_LITERAL_CSTRING("audio/mpeg");
}
@ -114,15 +114,15 @@ MP4AudioInfo::Update(const mp4parse_track_info* track,
}
void
MP4VideoInfo::Update(const mp4parse_track_info* track,
const mp4parse_track_video_info* video)
MP4VideoInfo::Update(const Mp4parseTrackInfo* track,
const Mp4parseTrackVideoInfo* video)
{
UpdateTrackProtectedInfo(*this, video->protected_data);
if (track->codec == mp4parse_codec_AVC) {
if (track->codec == MP4PARSE_CODEC_AVC) {
mMimeType = NS_LITERAL_CSTRING("video/avc");
} else if (track->codec == mp4parse_codec_VP9) {
} else if (track->codec == MP4PARSE_CODEC_VP9) {
mMimeType = NS_LITERAL_CSTRING("video/vp9");
} else if (track->codec == mp4parse_codec_MP4V) {
} else if (track->codec == MP4PARSE_CODEC_MP4V) {
mMimeType = NS_LITERAL_CSTRING("video/mp4v-es");
}
mTrackId = track->track_id;

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

@ -13,12 +13,7 @@
#include "nsString.h"
#include "nsTArray.h"
#include "nsString.h"
extern "C" {
typedef struct mp4parse_track_info mp4parse_track_info;
typedef struct mp4parse_track_audio_info mp4parse_track_audio_info;
typedef struct mp4parse_track_video_info mp4parse_track_video_info;
}
#include "mp4parse.h"
namespace mozilla
{
@ -63,8 +58,8 @@ class MP4AudioInfo : public mozilla::AudioInfo
public:
MP4AudioInfo() = default;
void Update(const mp4parse_track_info* track,
const mp4parse_track_audio_info* audio);
void Update(const Mp4parseTrackInfo* track,
const Mp4parseTrackAudioInfo* audio);
virtual bool IsValid() const override;
};
@ -74,8 +69,8 @@ class MP4VideoInfo : public mozilla::VideoInfo
public:
MP4VideoInfo() = default;
void Update(const mp4parse_track_info* track,
const mp4parse_track_video_info* video);
void Update(const Mp4parseTrackInfo* track,
const Mp4parseTrackVideoInfo* video);
virtual bool IsValid() const override;
};

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

@ -25,7 +25,7 @@ using mozilla::media::TimeUnit;
namespace mozilla {
LazyLogModule gMP4MetadataLog("MP4Metadata");
IndiceWrapper::IndiceWrapper(mp4parse_byte_data& aIndice)
IndiceWrapper::IndiceWrapper(Mp4parseByteData& aIndice)
{
mIndice.length = aIndice.length;
mIndice.indices = aIndice.indices;
@ -45,7 +45,7 @@ IndiceWrapper::GetIndice(size_t aIndex, Index::Indice& aIndice) const
return false;
}
const mp4parse_indice* indice = &mIndice.indices[aIndex];
const Mp4parseIndice* indice = &mIndice.indices[aIndex];
aIndice.start_offset = indice->start_offset;
aIndice.end_offset = indice->end_offset;
aIndice.start_composition = indice->start_composition;
@ -103,7 +103,7 @@ MP4Metadata::MP4Metadata(ByteStream* aSource)
: mSource(aSource)
, mSourceAdaptor(aSource)
{
mp4parse_io io = { read_source, &mSourceAdaptor };
Mp4parseIo io = { read_source, &mSourceAdaptor };
mParser.reset(mp4parse_new(&io));
MOZ_ASSERT(mParser);
@ -119,10 +119,10 @@ MP4Metadata::~MP4Metadata()
nsresult
MP4Metadata::Parse()
{
mp4parse_status rv = mp4parse_read(mParser.get());
if (rv != mp4parse_status_OK) {
Mp4parseStatus rv = mp4parse_read(mParser.get());
if (rv != MP4PARSE_STATUS_OK) {
MOZ_LOG(gMP4MetadataLog, LogLevel::Debug, ("Parse failed, return code %d\n", rv));
return rv == mp4parse_status_OOM ? NS_ERROR_OUT_OF_MEMORY
return rv == MP4PARSE_STATUS_OOM ? NS_ERROR_OUT_OF_MEMORY
: NS_ERROR_DOM_MEDIA_METADATA_ERR;
}
@ -134,8 +134,8 @@ MP4Metadata::Parse()
void
MP4Metadata::UpdateCrypto()
{
mp4parse_pssh_info info = {};
if (mp4parse_get_pssh_info(mParser.get(), &info) != mp4parse_status_OK) {
Mp4parsePsshInfo info = {};
if (mp4parse_get_pssh_info(mParser.get(), &info) != MP4PARSE_STATUS_OK) {
return;
}
@ -147,13 +147,13 @@ MP4Metadata::UpdateCrypto()
}
bool
TrackTypeEqual(TrackInfo::TrackType aLHS, mp4parse_track_type aRHS)
TrackTypeEqual(TrackInfo::TrackType aLHS, Mp4parseTrackType aRHS)
{
switch (aLHS) {
case TrackInfo::kAudioTrack:
return aRHS == mp4parse_track_type_AUDIO;
return aRHS == MP4PARSE_TRACK_TYPE_AUDIO;
case TrackInfo::kVideoTrack:
return aRHS == mp4parse_track_type_VIDEO;
return aRHS == MP4PARSE_TRACK_TYPE_VIDEO;
default:
return false;
}
@ -164,7 +164,7 @@ MP4Metadata::GetNumberTracks(mozilla::TrackInfo::TrackType aType) const
{
uint32_t tracks;
auto rv = mp4parse_get_track_count(mParser.get(), &tracks);
if (rv != mp4parse_status_OK) {
if (rv != MP4PARSE_STATUS_OK) {
MOZ_LOG(gMP4MetadataLog, LogLevel::Warning,
("rust parser error %d counting tracks", rv));
return {MediaResult(NS_ERROR_DOM_MEDIA_METADATA_ERR,
@ -174,12 +174,12 @@ MP4Metadata::GetNumberTracks(mozilla::TrackInfo::TrackType aType) const
uint32_t total = 0;
for (uint32_t i = 0; i < tracks; ++i) {
mp4parse_track_info track_info;
Mp4parseTrackInfo track_info;
rv = mp4parse_get_track_info(mParser.get(), i, &track_info);
if (rv != mp4parse_status_OK) {
if (rv != MP4PARSE_STATUS_OK) {
continue;
}
if (track_info.codec == mp4parse_codec::mp4parse_codec_UNKNOWN) {
if (track_info.codec == MP4PARSE_CODEC_UNKNOWN) {
continue;
}
if (TrackTypeEqual(aType, track_info.track_type)) {
@ -199,7 +199,7 @@ MP4Metadata::TrackTypeToGlobalTrackIndex(mozilla::TrackInfo::TrackType aType, si
{
uint32_t tracks;
auto rv = mp4parse_get_track_count(mParser.get(), &tracks);
if (rv != mp4parse_status_OK) {
if (rv != MP4PARSE_STATUS_OK) {
return Nothing();
}
@ -209,9 +209,9 @@ MP4Metadata::TrackTypeToGlobalTrackIndex(mozilla::TrackInfo::TrackType aType, si
track index when a match is found. */
uint32_t perType = 0;
for (uint32_t i = 0; i < tracks; ++i) {
mp4parse_track_info track_info;
Mp4parseTrackInfo track_info;
rv = mp4parse_get_track_info(mParser.get(), i, &track_info);
if (rv != mp4parse_status_OK) {
if (rv != MP4PARSE_STATUS_OK) {
continue;
}
if (TrackTypeEqual(aType, track_info.track_type)) {
@ -237,9 +237,9 @@ MP4Metadata::GetTrackInfo(mozilla::TrackInfo::TrackType aType,
nullptr};
}
mp4parse_track_info info;
Mp4parseTrackInfo info;
auto rv = mp4parse_get_track_info(mParser.get(), trackIndex.value(), &info);
if (rv != mp4parse_status_OK) {
if (rv != MP4PARSE_STATUS_OK) {
MOZ_LOG(gMP4MetadataLog, LogLevel::Warning, ("mp4parse_get_track_info returned %d", rv));
return {MediaResult(NS_ERROR_DOM_MEDIA_METADATA_ERR,
RESULT_DETAIL("Cannot find %s track #%zu",
@ -250,17 +250,17 @@ MP4Metadata::GetTrackInfo(mozilla::TrackInfo::TrackType aType,
#ifdef DEBUG
const char* codec_string = "unrecognized";
switch (info.codec) {
case mp4parse_codec_UNKNOWN: codec_string = "unknown"; break;
case mp4parse_codec_AAC: codec_string = "aac"; break;
case mp4parse_codec_OPUS: codec_string = "opus"; break;
case mp4parse_codec_FLAC: codec_string = "flac"; break;
case mp4parse_codec_AVC: codec_string = "h.264"; break;
case mp4parse_codec_VP9: codec_string = "vp9"; break;
case mp4parse_codec_MP3: codec_string = "mp3"; break;
case mp4parse_codec_MP4V: codec_string = "mp4v"; break;
case mp4parse_codec_JPEG: codec_string = "jpeg"; break;
case mp4parse_codec_AC3: codec_string = "ac-3"; break;
case mp4parse_codec_EC3: codec_string = "ec-3"; break;
case MP4PARSE_CODEC_UNKNOWN: codec_string = "unknown"; break;
case MP4PARSE_CODEC_AAC: codec_string = "aac"; break;
case MP4PARSE_CODEC_OPUS: codec_string = "opus"; break;
case MP4PARSE_CODEC_FLAC: codec_string = "flac"; break;
case MP4PARSE_CODEC_AVC: codec_string = "h.264"; break;
case MP4PARSE_CODEC_VP9: codec_string = "vp9"; break;
case MP4PARSE_CODEC_MP3: codec_string = "mp3"; break;
case MP4PARSE_CODEC_MP4V: codec_string = "mp4v"; break;
case MP4PARSE_CODEC_JPEG: codec_string = "jpeg"; break;
case MP4PARSE_CODEC_AC3: codec_string = "ac-3"; break;
case MP4PARSE_CODEC_EC3: codec_string = "ec-3"; break;
}
MOZ_LOG(gMP4MetadataLog, LogLevel::Debug,
("track codec %s (%u)\n", codec_string, info.codec));
@ -270,9 +270,9 @@ MP4Metadata::GetTrackInfo(mozilla::TrackInfo::TrackType aType,
UniquePtr<mozilla::TrackInfo> e;
switch (aType) {
case TrackInfo::TrackType::kAudioTrack: {
mp4parse_track_audio_info audio;
Mp4parseTrackAudioInfo audio;
auto rv = mp4parse_get_track_audio_info(mParser.get(), trackIndex.value(), &audio);
if (rv != mp4parse_status_OK) {
if (rv != MP4PARSE_STATUS_OK) {
MOZ_LOG(gMP4MetadataLog, LogLevel::Warning, ("mp4parse_get_track_audio_info returned error %d", rv));
return {MediaResult(NS_ERROR_DOM_MEDIA_METADATA_ERR,
RESULT_DETAIL("Cannot parse %s track #%zu",
@ -286,9 +286,9 @@ MP4Metadata::GetTrackInfo(mozilla::TrackInfo::TrackType aType,
}
break;
case TrackInfo::TrackType::kVideoTrack: {
mp4parse_track_video_info video;
Mp4parseTrackVideoInfo video;
auto rv = mp4parse_get_track_video_info(mParser.get(), trackIndex.value(), &video);
if (rv != mp4parse_status_OK) {
if (rv != MP4PARSE_STATUS_OK) {
MOZ_LOG(gMP4MetadataLog, LogLevel::Warning, ("mp4parse_get_track_video_info returned error %d", rv));
return {MediaResult(NS_ERROR_DOM_MEDIA_METADATA_ERR,
RESULT_DETAIL("Cannot parse %s track #%zu",
@ -312,9 +312,9 @@ MP4Metadata::GetTrackInfo(mozilla::TrackInfo::TrackType aType,
// No duration in track, use fragment_duration.
if (e && !e->mDuration.IsPositive()) {
mp4parse_fragment_info info;
Mp4parseFragmentInfo info;
auto rv = mp4parse_get_fragment_info(mParser.get(), &info);
if (rv == mp4parse_status_OK) {
if (rv == MP4PARSE_STATUS_OK) {
e->mDuration = TimeUnit::FromMicroseconds(info.fragment_duration);
}
}
@ -346,11 +346,11 @@ MP4Metadata::Crypto() const
MP4Metadata::ResultAndIndice
MP4Metadata::GetTrackIndice(mozilla::TrackID aTrackID)
{
mp4parse_byte_data indiceRawData = {};
Mp4parseByteData indiceRawData = {};
uint8_t fragmented = false;
auto rv = mp4parse_is_fragmented(mParser.get(), aTrackID, &fragmented);
if (rv != mp4parse_status_OK) {
if (rv != MP4PARSE_STATUS_OK) {
return {MediaResult(NS_ERROR_DOM_MEDIA_METADATA_ERR,
RESULT_DETAIL("Cannot parse whether track id %d is "
"fragmented, mp4parse_error=%d",
@ -360,7 +360,7 @@ MP4Metadata::GetTrackIndice(mozilla::TrackID aTrackID)
if (!fragmented) {
rv = mp4parse_get_indice_table(mParser.get(), aTrackID, &indiceRawData);
if (rv != mp4parse_status_OK) {
if (rv != MP4PARSE_STATUS_OK) {
return {MediaResult(NS_ERROR_DOM_MEDIA_METADATA_ERR,
RESULT_DETAIL("Cannot parse index table in track id %d, "
"mp4parse_error=%d",

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

@ -26,13 +26,13 @@ public:
bool GetIndice(size_t aIndex, Index::Indice& aIndice) const;
explicit IndiceWrapper(mp4parse_byte_data& aRustIndice);
explicit IndiceWrapper(Mp4parseByteData& aRustIndice);
protected:
mp4parse_byte_data mIndice;
Mp4parseByteData mIndice;
};
struct FreeMP4Parser { void operator()(mp4parse_parser* aPtr) { mp4parse_free(aPtr); } };
struct FreeMP4Parser { void operator()(Mp4parseParser* aPtr) { mp4parse_free(aPtr); } };
// Wrap an Stream to remember the read offset.
class StreamAdaptor {
@ -110,7 +110,7 @@ private:
CryptoFile mCrypto;
RefPtr<ByteStream> mSource;
StreamAdaptor mSourceAdaptor;
mozilla::UniquePtr<mp4parse_parser, FreeMP4Parser> mParser;
mozilla::UniquePtr<Mp4parseParser, FreeMP4Parser> mParser;
};
} // namespace mozilla