Bug 1353944 - Update enums for mp4parse 0.8.0. r?kinetik draft
authorRalph Giles <giles@mozilla.com>
Wed, 05 Apr 2017 17:30:47 -0700
changeset 556537 628d8aa03600d319eca1c3cee5b145169b1ea72b
parent 556536 f1f5393744f98c94cd0c995846c63981acf8892a
child 622916 ab9b28961a37c0e86cb0c814901b33b96ffa91a7
push id52577
push userbmo:giles@thaumas.net
push dateThu, 06 Apr 2017 01:08:09 +0000
reviewerskinetik
bugs1353944
milestone55.0a1
Bug 1353944 - Update enums for mp4parse 0.8.0. r?kinetik The support to namespace prefixing in moz-cheddar means we can simplify exported enum names on the rust side. However this makes for some spelling changes on the C side. MozReview-Commit-ID: 4t6NDusx0uI
media/libstagefright/binding/DecoderData.cpp
media/libstagefright/binding/MP4Metadata.cpp
media/libstagefright/gtest/TestMP4Rust.cpp
--- a/media/libstagefright/binding/DecoderData.cpp
+++ b/media/libstagefright/binding/DecoderData.cpp
@@ -200,32 +200,32 @@ UpdateTrackProtectedInfo(mozilla::TrackI
 }
 
 void
 MP4AudioInfo::Update(const mp4parse_track_info* track,
                      const mp4parse_track_audio_info* 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
     // start of the codec-specific config blob.
     MOZ_ASSERT(audio->codec_specific_config.data);
     MOZ_ASSERT(audio->codec_specific_config.length >= 12);
     uint16_t preskip =
       LittleEndian::readUint16(audio->codec_specific_config.data + 10);
     OpusDataDecoder::AppendCodecDelay(mCodecSpecificConfig,
         mozilla::FramesToUsecs(preskip, 48000).value());
-  } else if (track->codec == MP4PARSE_CODEC_AAC) {
+  } else if (track->codec == mp4parse_codec_AAC) {
     mMimeType = MEDIA_MIMETYPE_AUDIO_AAC;
-  } else if (track->codec == MP4PARSE_CODEC_FLAC) {
+  } else if (track->codec == mp4parse_codec_FLAC) {
     mMimeType = MEDIA_MIMETYPE_AUDIO_FLAC;
-  } else if (track->codec == MP4PARSE_CODEC_MP3) {
+  } else if (track->codec == mp4parse_codec_MP3) {
     mMimeType = MEDIA_MIMETYPE_AUDIO_MPEG;
   }
 
   mRate = audio->sample_rate;
   mChannels = audio->channels;
   mBitDepth = audio->bit_depth;
   mExtendedProfile = audio->profile;
   mDuration = track->duration;
@@ -249,19 +249,19 @@ MP4AudioInfo::Update(const mp4parse_trac
   }
 }
 
 void
 MP4VideoInfo::Update(const mp4parse_track_info* track,
                      const mp4parse_track_video_info* video)
 {
   UpdateTrackProtectedInfo(*this, video->protected_data);
-  if (track->codec == MP4PARSE_CODEC_AVC) {
+  if (track->codec == mp4parse_codec_AVC) {
     mMimeType = MEDIA_MIMETYPE_VIDEO_AVC;
-  } else if (track->codec == MP4PARSE_CODEC_VP9) {
+  } else if (track->codec == mp4parse_codec_VP9) {
     mMimeType = NS_LITERAL_CSTRING("video/vp9");
   }
   mTrackId = track->track_id;
   mDuration = track->duration;
   mMediaTime = track->media_time;
   mDisplay.width = video->display_width;
   mDisplay.height = video->display_height;
   mImage.width = video->image_width;
--- a/media/libstagefright/binding/MP4Metadata.cpp
+++ b/media/libstagefright/binding/MP4Metadata.cpp
@@ -730,105 +730,105 @@ MP4MetadataRust::MP4MetadataRust(Stream*
   mp4parse_io io = { read_source, &mRustSource };
   mRustParser.reset(mp4parse_new(&io));
   MOZ_ASSERT(mRustParser);
 
   if (MOZ_LOG_TEST(sLog, LogLevel::Debug)) {
     mp4parse_log(true);
   }
 
-  mp4parse_error rv = mp4parse_read(mRustParser.get());
+  mp4parse_status rv = mp4parse_read(mRustParser.get());
   MOZ_LOG(sLog, LogLevel::Debug, ("rust parser returned %d\n", rv));
   Telemetry::Accumulate(Telemetry::MEDIA_RUST_MP4PARSE_SUCCESS,
-                        rv == MP4PARSE_OK);
-  if (rv != MP4PARSE_OK) {
+                        rv == mp4parse_status_OK);
+  if (rv != mp4parse_status_OK) {
     MOZ_ASSERT(rv > 0);
     Telemetry::Accumulate(Telemetry::MEDIA_RUST_MP4PARSE_ERROR_CODE, rv);
   }
 
   UpdateCrypto();
 }
 
 MP4MetadataRust::~MP4MetadataRust()
 {
 }
 
 void
 MP4MetadataRust::UpdateCrypto()
 {
   mp4parse_pssh_info info = {};
-  if (mp4parse_get_pssh_info(mRustParser.get(), &info) != MP4PARSE_OK) {
+  if (mp4parse_get_pssh_info(mRustParser.get(), &info) != mp4parse_status_OK) {
     return;
   }
 
   if (info.data.length == 0) {
     return;
   }
 
   mCrypto.Update(info.data.data, info.data.length);
 }
 
 bool
 TrackTypeEqual(TrackInfo::TrackType aLHS, mp4parse_track_type 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;
   }
 }
 
 uint32_t
 MP4MetadataRust::GetNumberTracks(mozilla::TrackInfo::TrackType aType) const
 {
   uint32_t tracks;
   auto rv = mp4parse_get_track_count(mRustParser.get(), &tracks);
-  if (rv != MP4PARSE_OK) {
+  if (rv != mp4parse_status_OK) {
     MOZ_LOG(sLog, LogLevel::Warning,
         ("rust parser error %d counting tracks", rv));
     return 0;
   }
   MOZ_LOG(sLog, LogLevel::Info, ("rust parser found %u tracks", tracks));
 
   uint32_t total = 0;
   for (uint32_t i = 0; i < tracks; ++i) {
     mp4parse_track_info track_info;
     rv = mp4parse_get_track_info(mRustParser.get(), i, &track_info);
-    if (rv != MP4PARSE_OK) {
+    if (rv != mp4parse_status_OK) {
       continue;
     }
     if (TrackTypeEqual(aType, track_info.track_type)) {
         total += 1;
     }
   }
 
   return total;
 }
 
 Maybe<uint32_t>
 MP4MetadataRust::TrackTypeToGlobalTrackIndex(mozilla::TrackInfo::TrackType aType, size_t aTrackNumber) const
 {
   uint32_t tracks;
   auto rv = mp4parse_get_track_count(mRustParser.get(), &tracks);
-  if (rv != MP4PARSE_OK) {
+  if (rv != mp4parse_status_OK) {
     return Nothing();
   }
 
   /* The MP4Metadata API uses a per-TrackType index of tracks, but mp4parse
      (and libstagefright) use a global track index.  Convert the index by
      counting the tracks of the requested type and returning the global
      track index when a match is found. */
   uint32_t perType = 0;
   for (uint32_t i = 0; i < tracks; ++i) {
     mp4parse_track_info track_info;
     rv = mp4parse_get_track_info(mRustParser.get(), i, &track_info);
-    if (rv != MP4PARSE_OK) {
+    if (rv != mp4parse_status_OK) {
       continue;
     }
     if (TrackTypeEqual(aType, track_info.track_type)) {
       if (perType == aTrackNumber) {
         return Some(i);
       }
       perType += 1;
     }
@@ -843,54 +843,54 @@ MP4MetadataRust::GetTrackInfo(mozilla::T
 {
   Maybe<uint32_t> trackIndex = TrackTypeToGlobalTrackIndex(aType, aTrackNumber);
   if (trackIndex.isNothing()) {
     return nullptr;
   }
 
   mp4parse_track_info info;
   auto rv = mp4parse_get_track_info(mRustParser.get(), trackIndex.value(), &info);
-  if (rv != MP4PARSE_OK) {
+  if (rv != mp4parse_status_OK) {
     MOZ_LOG(sLog, LogLevel::Warning, ("mp4parse_get_track_info returned %d", rv));
     return nullptr;
   }
 #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_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;
   }
   MOZ_LOG(sLog, LogLevel::Debug, ("track codec %s (%u)\n",
         codec_string, info.codec));
 #endif
 
   // This specialization interface is crazy.
   UniquePtr<mozilla::TrackInfo> e;
   switch (aType) {
     case TrackInfo::TrackType::kAudioTrack: {
       mp4parse_track_audio_info audio;
       auto rv = mp4parse_get_track_audio_info(mRustParser.get(), trackIndex.value(), &audio);
-      if (rv != MP4PARSE_OK) {
+      if (rv != mp4parse_status_OK) {
         MOZ_LOG(sLog, LogLevel::Warning, ("mp4parse_get_track_audio_info returned error %d", rv));
         return nullptr;
       }
       auto track = mozilla::MakeUnique<MP4AudioInfo>();
       track->Update(&info, &audio);
       e = Move(track);
     }
     break;
     case TrackInfo::TrackType::kVideoTrack: {
       mp4parse_track_video_info video;
       auto rv = mp4parse_get_track_video_info(mRustParser.get(), trackIndex.value(), &video);
-      if (rv != MP4PARSE_OK) {
+      if (rv != mp4parse_status_OK) {
         MOZ_LOG(sLog, LogLevel::Warning, ("mp4parse_get_track_video_info returned error %d", rv));
         return nullptr;
       }
       auto track = mozilla::MakeUnique<MP4VideoInfo>();
       track->Update(&info, &video);
       e = Move(track);
     }
     break;
@@ -899,17 +899,17 @@ MP4MetadataRust::GetTrackInfo(mozilla::T
       return nullptr;
       break;
   }
 
   // No duration in track, use fragment_duration.
   if (e && !e->mDuration) {
     mp4parse_fragment_info info;
     auto rv = mp4parse_get_fragment_info(mRustParser.get(), &info);
-    if (rv == MP4PARSE_OK) {
+    if (rv == mp4parse_status_OK) {
       e->mDuration = info.fragment_duration;
     }
   }
 
   if (e && e->IsValid()) {
     return e;
   }
   MOZ_LOG(sLog, LogLevel::Debug, ("TrackInfo didn't validate"));
@@ -930,26 +930,26 @@ MP4MetadataRust::Crypto() const
   return mCrypto;
 }
 
 bool
 MP4MetadataRust::ReadTrackIndice(mp4parse_byte_data* aIndices, mozilla::TrackID aTrackID)
 {
   uint8_t fragmented = false;
   auto rv = mp4parse_is_fragmented(mRustParser.get(), aTrackID, &fragmented);
-  if (rv != MP4PARSE_OK) {
+  if (rv != mp4parse_status_OK) {
     return false;
   }
 
   if (fragmented) {
     return true;
   }
 
   rv = mp4parse_get_indice_table(mRustParser.get(), aTrackID, aIndices);
-  if (rv != MP4PARSE_OK) {
+  if (rv != mp4parse_status_OK) {
     return false;
   }
 
   return true;
 }
 
 /*static*/ already_AddRefed<mozilla::MediaByteBuffer>
 MP4MetadataRust::Metadata(Stream* aSource)
--- a/media/libstagefright/gtest/TestMP4Rust.cpp
+++ b/media/libstagefright/gtest/TestMP4Rust.cpp
@@ -56,22 +56,22 @@ vector_reader(uint8_t* buffer, uintptr_t
   uintptr_t length = std::min(available, size);
   memcpy(buffer, source->buffer.data() + source->location, length);
   source->location += length;
   return length;
 }
 
 TEST(rust, MP4MetadataEmpty)
 {
-  mp4parse_error rv;
+  mp4parse_status rv;
   mp4parse_io io;
 
   // Shouldn't be able to read with no context.
   rv = mp4parse_read(nullptr);
-  EXPECT_EQ(rv, MP4PARSE_ERROR_BADARG);
+  EXPECT_EQ(rv, mp4parse_status_BAD_ARG);
 
   // Shouldn't be able to wrap an mp4parse_io with null members.
   io = { nullptr, nullptr };
   mp4parse_parser* context = mp4parse_new(&io);
   EXPECT_EQ(context, nullptr);
 
   io = { nullptr, &io };
   context = mp4parse_new(&io);
@@ -82,40 +82,40 @@ TEST(rust, MP4MetadataEmpty)
   context = mp4parse_new(&io);
   EXPECT_EQ(context, nullptr);
 
   // Read method errors should propagate.
   io = { error_reader, &io };
   context = mp4parse_new(&io);
   ASSERT_NE(context, nullptr);
   rv = mp4parse_read(context);
-  EXPECT_EQ(rv, MP4PARSE_ERROR_IO);
+  EXPECT_EQ(rv, mp4parse_status_IO);
   mp4parse_free(context);
 
   // Short buffers should fail.
   read_vector buf(0);
   io = { vector_reader, &buf };
   context = mp4parse_new(&io);
   ASSERT_NE(context, nullptr);
   rv = mp4parse_read(context);
-  EXPECT_EQ(rv, MP4PARSE_ERROR_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_ERROR_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_ERROR_UNSUPPORTED);
+  EXPECT_EQ(rv, mp4parse_status_UNSUPPORTED);
   mp4parse_free(context);
 }
 
 TEST(rust, MP4Metadata)
 {
   FILE* f = fopen("street.mp4", "rb");
   ASSERT_TRUE(f != nullptr);
   // Read just the moov header to work around the parser
@@ -125,18 +125,18 @@ TEST(rust, MP4Metadata)
   ASSERT_EQ(0, fstat(fileno(f), &s));
   read_vector reader = read_vector(f, s.st_size);
   fclose(f);
 
   mp4parse_io io = { vector_reader, &reader };
   mp4parse_parser* context = mp4parse_new(&io);
   ASSERT_NE(nullptr, context);
 
-  mp4parse_error rv = mp4parse_read(context);
-  EXPECT_EQ(MP4PARSE_OK, rv);
+  mp4parse_status rv = mp4parse_read(context);
+  EXPECT_EQ(mp4parse_status_OK, rv);
 
   uint32_t tracks = 0;
   rv = mp4parse_get_track_count(context, &tracks);
-  EXPECT_EQ(MP4PARSE_OK, rv);
+  EXPECT_EQ(mp4parse_status_OK, rv);
   EXPECT_EQ(2U, tracks);
 
   mp4parse_free(context);
 }