From 0f8b14b1fe4ff26501b39522c2f04b8b6f899829 Mon Sep 17 00:00:00 2001 From: Ralph Giles Date: Mon, 2 Nov 2015 11:39:00 -0800 Subject: [PATCH] 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 | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/media/libstagefright/binding/MP4Metadata.cpp b/media/libstagefright/binding/MP4Metadata.cpp index 1b97e0723b1c..ce37f623197e 100644 --- a/media/libstagefright/binding/MP4Metadata.cpp +++ b/media/libstagefright/binding/MP4Metadata.cpp @@ -13,6 +13,7 @@ #include #include +#include using namespace stagefright; @@ -106,9 +107,43 @@ MP4Metadata::~MP4Metadata() { } +#ifdef MOZ_RUST_MP4PARSE +#include "mp4parse.h" + +// Helper to test the rust parser on a data source. +static bool try_rust(RefPtr 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(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++) {