Exemplo n.º 1
0
TEST(rust, MP4Metadata)
{
  FILE* f = fopen("street.mp4", "rb");
  ASSERT_TRUE(f != nullptr);
  // Read just the moov header to work around the parser
  // treating mid-box eof as an error.
  //read_vector reader = read_vector(f, 1061);
  struct stat s;
  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);

  uint32_t tracks = 0;
  rv = mp4parse_get_track_count(context, &tracks);
  EXPECT_EQ(MP4PARSE_OK, rv);
  EXPECT_EQ(2U, tracks);

  mp4parse_free(context);
}
Exemplo n.º 2
0
MP4Metadata::MP4Metadata(ByteStream* aSource)
    : mSource(aSource), mSourceAdaptor(aSource) {
  DDLINKCHILD("source", aSource);

  Mp4parseIo io = {read_source, &mSourceAdaptor};
  mParser.reset(mp4parse_new(&io));
  MOZ_ASSERT(mParser);
}
Exemplo n.º 3
0
TEST(rust, MP4MetadataEmpty)
{
  mp4parse_error rv;
  mp4parse_io io;

  // Shouldn't be able to read with no context.
  rv = mp4parse_read(nullptr);
  EXPECT_EQ(rv, MP4PARSE_ERROR_BADARG);

  // 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);
  EXPECT_EQ(context, nullptr);

  // FIXME: this should probably be accepted.
  io = { error_reader, nullptr };
  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);
  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);
  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);
  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);
  mp4parse_free(context);
}
Exemplo n.º 4
0
MP4MetadataRust::MP4MetadataRust(Stream* aSource)
  : mSource(aSource)
  , mRustState(mp4parse_new())
{
  static LazyLogModule sLog("MP4Metadata");

  std::vector<uint8_t> buffer;
  int32_t rv = read_source(mSource, buffer);
  if (rv == MP4PARSE_OK) {
    rv = mp4parse_read(mRustState.get(), buffer.data(), buffer.size());
  }
  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) {
    MOZ_ASSERT(rv > 0);
    Telemetry::Accumulate(Telemetry::MEDIA_RUST_MP4PARSE_ERROR_CODE,
                          rv);
  }
}
Exemplo n.º 5
0
uint32_t
MP4Metadata::GetNumberTracks(mozilla::TrackInfo::TrackType aType) const
{
#ifdef MOZ_RUST_MP4PARSE
  // Try in rust first.
  mRustState.reset(mp4parse_new());
  int32_t rust_tracks = 0;
  bool rust_mp4parse_success = try_rust(mRustState, mSource, &rust_tracks);
  Telemetry::Accumulate(Telemetry::MEDIA_RUST_MP4PARSE_SUCCESS,
                        rust_mp4parse_success);
#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;
    }
    switch (aType) {
      case mozilla::TrackInfo::kAudioTrack:
        if (!strncmp(mimeType, "audio/", 6) &&
            CheckTrack(mimeType, metaData.get(), i)) {
          total++;
        }
        break;
      case mozilla::TrackInfo::kVideoTrack:
        if (!strncmp(mimeType, "video/", 6) &&
            CheckTrack(mimeType, metaData.get(), i)) {
          total++;
        }
        break;
      default:
        break;
    }
  }
#ifdef MOZ_RUST_MP4PARSE
  uint32_t rust_total = 0;
  const char* rust_track_type = nullptr;
  if (rust_mp4parse_success && rust_tracks > 0) {
    for (int32_t i = 0; i < rust_tracks; ++i) {
      mp4parse_track_info track_info;
      int32_t r = mp4parse_get_track_info(mRustState.get(), i, &track_info);
      switch (aType) {
      case mozilla::TrackInfo::kAudioTrack:
        rust_track_type = "audio";
        if (r == 0 && track_info.track_type == MP4PARSE_TRACK_TYPE_AAC) {
          rust_total += 1;
        }
        break;
      case mozilla::TrackInfo::kVideoTrack:
        rust_track_type = "video";
        if (r == 0 && track_info.track_type == MP4PARSE_TRACK_TYPE_H264) {
          rust_total += 1;
        }
        break;
      default:
        break;
      }
    }
  }
  static LazyLogModule sLog("MP4Metadata");
  MOZ_LOG(sLog, LogLevel::Info, ("%s tracks found: stagefright=%u rust=%u",
                                 rust_track_type, total, rust_total));
#endif
  return total;
}