Bug 1219047 - Call rust mp4parser with logging. r=kinetik
authorRalph Giles <giles@mozilla.com>
Mon, 02 Nov 2015 11:39:00 -0800
changeset 270801 4a48d855141720d3cf8e5c579db79fba4155b4fa
parent 270800 3fd50056e877dbf41fdc91b870923280c2128d58
child 270802 aff89c5a3121cd1e0882660f930b5076fad05c82
push id67472
push userrgiles@mozilla.com
push dateMon, 02 Nov 2015 21:36:15 +0000
treeherdermozilla-inbound@4a48d8551417 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1219047, 1219530
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1219047 - Call rust mp4parser with logging. r=kinetik Add a helper for passing the initialization segments of mp4 streams to the rust parser and log the result. This runs real data through the new parser for testing but doesn't use the results. Code is conditional on MOZ_RUST_MP4PARSE to be defined in confvars.sh. See bug 1219530.
media/libstagefright/binding/MP4Metadata.cpp
--- a/media/libstagefright/binding/MP4Metadata.cpp
+++ b/media/libstagefright/binding/MP4Metadata.cpp
@@ -8,16 +8,17 @@
 #include "media/stagefright/MediaSource.h"
 #include "media/stagefright/MetaData.h"
 #include "mozilla/Monitor.h"
 #include "mp4_demuxer/MoofParser.h"
 #include "mp4_demuxer/MP4Metadata.h"
 
 #include <limits>
 #include <stdint.h>
+#include <vector>
 
 using namespace stagefright;
 
 namespace mp4_demuxer
 {
 
 struct StageFrightPrivate
 {
@@ -101,19 +102,53 @@ MP4Metadata::MP4Metadata(Stream* aSource
 
   UpdateCrypto(metaData.get());
 }
 
 MP4Metadata::~MP4Metadata()
 {
 }
 
+#ifdef MOZ_RUST_MP4PARSE
+#include "mp4parse.h"
+
+// Helper to test the rust parser on a data source.
+static bool try_rust(RefPtr<Stream> aSource)
+{
+  int64_t length;
+  if (!aSource->Length(&length)) {
+    fprintf(stderr, "Couldn't get source length\n");
+    return false;
+  }
+  fprintf(stderr, "Source length %d bytes\n", (long long int)length);
+  if (length <= 0) {
+    return false;
+  }
+  size_t bytes_read = 0;
+  auto buffer = std::vector<uint8_t>(length);
+  bool rv = aSource->ReadAt(0, buffer.data(), length, &bytes_read);
+  if (!rv || bytes_read != size_t(length)) {
+    fprintf(stderr, "Error copying mp4 data\n");
+    return false;
+  }
+  auto context = mp4parse_new();
+  int32_t tracks = mp4parse_read(context, buffer.data(), bytes_read);
+  mp4parse_free(context);
+  fprintf(stderr, "rust parser found %d tracks\n", int(tracks));
+  return true;
+}
+#endif
+
 uint32_t
 MP4Metadata::GetNumberTracks(mozilla::TrackInfo::TrackType aType) const
 {
+#ifdef MOZ_RUST_MP4PARSE
+  // Try in rust first.
+  try_rust(mSource);
+#endif
   size_t tracks = mPrivate->mMetadataExtractor->countTracks();
   uint32_t total = 0;
   for (size_t i = 0; i < tracks; i++) {
     sp<MetaData> metaData = mPrivate->mMetadataExtractor->getTrackMetaData(i);
 
     const char* mimeType;
     if (metaData == nullptr || !metaData->findCString(kKeyMIMEType, &mimeType)) {
       continue;