Bug 1016413 - Implement reporting metadata with fmp4 backend. r=rillian
☠☠ backed out by aa52cfb29acb ☠ ☠
authorCorentin Cos <corentin.cos@gmail.com>
Tue, 17 Jun 2014 00:32:18 +0200
changeset 189614 9fd0316dcd1bd4e7fb8d1aa5fe1a08f5d3a0a2e3
parent 189613 fc071decd42d50366b3b2d19b073976f4450555a
child 189615 3ff9374610b71410b65fc44b01200559953eaca4
push id26992
push userkwierso@gmail.com
push dateFri, 20 Jun 2014 01:07:53 +0000
treeherdermozilla-central@bdac18bd6c74 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1016413
milestone33.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 1016413 - Implement reporting metadata with fmp4 backend. r=rillian There are 3 files modified in order to have the reporting work. MP4Reader::ReadMetadata() has now its aTags parameter affected with a certain MetadataTags structure which comes from MP4Demuxer::GetTags(). MP4Demuxer::GetTags() is in the mp4_demuxer's namespace, where a structure mapping tags key to its char* value is set. MP4Demuxer::GetTags() loops all along this mapping structure, and checks for each key if there is metadata corresponding to it in the current file's extracted metadata. If there is, it stores the current key and its corresponding metadata value into a mozilla::MetadataTags structure.
content/media/fmp4/MP4Reader.cpp
media/libstagefright/binding/include/mp4_demuxer/mp4_demuxer.h
media/libstagefright/binding/mp4_demuxer.cpp
--- a/content/media/fmp4/MP4Reader.cpp
+++ b/content/media/fmp4/MP4Reader.cpp
@@ -245,17 +245,17 @@ MP4Reader::ReadMetadata(MediaInfo* aInfo
   }
   // We can seek if we get a duration *and* the reader reports that it's
   // seekable.
   if (!mDecoder->GetResource()->IsTransportSeekable() || !mDemuxer->CanSeek()) {
     mDecoder->SetMediaSeekable(false);
   }
 
   *aInfo = mInfo;
-  *aTags = nullptr;
+  *aTags = mDemuxer->GetTags();
 
   return NS_OK;
 }
 
 bool
 MP4Reader::HasAudio()
 {
   return mAudio.mActive;
--- a/media/libstagefright/binding/include/mp4_demuxer/mp4_demuxer.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/mp4_demuxer.h
@@ -3,16 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MP4_DEMUXER_H_
 #define MP4_DEMUXER_H_
 
 #include "nsAutoPtr.h"
 #include "mozilla/gfx/Rect.h"
 #include "mp4_demuxer/DecoderData.h"
+#include "AbstractMediaDecoder.h"
 
 namespace mp4_demuxer
 {
 
 struct StageFrightPrivate;
 typedef int64_t Microseconds;
 
 class Stream
@@ -33,16 +34,17 @@ class MP4Demuxer
 public:
   MP4Demuxer(Stream* aSource);
   ~MP4Demuxer();
 
   bool Init();
   Microseconds Duration();
   bool CanSeek();
 
+  mozilla::MetadataTags* GetTags();
   bool HasValidAudio();
   bool HasValidVideo();
 
   void SeekAudio(Microseconds aTime);
   void SeekVideo(Microseconds aTime);
 
   // DemuxAudioSample and DemuxVideoSample functions return nullptr on end of
   // stream or error.
--- a/media/libstagefright/binding/mp4_demuxer.cpp
+++ b/media/libstagefright/binding/mp4_demuxer.cpp
@@ -3,24 +3,48 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "include/MPEG4Extractor.h"
 #include "media/stagefright/DataSource.h"
 #include "media/stagefright/MediaSource.h"
 #include "media/stagefright/MetaData.h"
 #include "mp4_demuxer/Adts.h"
 #include "mp4_demuxer/mp4_demuxer.h"
-
+#include "mozilla/ArrayUtils.h"
 #include <stdint.h>
 
 using namespace stagefright;
 
 namespace mp4_demuxer
 {
 
+struct tagmap {
+  const uint32_t key;
+  const char* name;
+};
+
+const struct tagmap keys[] = {
+  { kKeyAlbum, "album" },
+  { kKeyArtist, "artist" },
+  { kKeyAlbumArtist, "albumArtist" },
+  { kKeyComposer, "composer" },
+  { kKeyGenre, "genre" },
+  { kKeyTitle, "title" },
+  { kKeyYear, "year" },
+  { kKeyAlbumArt, "albumArt" },
+  { kKeyAlbumArtMIME, "albumArtMIME" },
+  { kKeyAuthor, "author" },
+  { kKeyCDTrackNumber, "cdTrackNumber" },
+  { kKeyDiscNumber, "discNumber" },
+  { kKeyDate, "date" },
+  { kKeyWriter, "writer" },
+  { kKeyCompilation, "compilation" },
+  { kKeyLocation, "location" },
+};
+
 struct StageFrightPrivate
 {
   sp<MPEG4Extractor> mExtractor;
 
   sp<MediaSource> mAudio;
   MediaSource::ReadOptions mAudioOptions;
 
   sp<MediaSource> mVideo;
@@ -75,16 +99,38 @@ MP4Demuxer::~MP4Demuxer()
   if (mPrivate->mAudio.get()) {
     mPrivate->mAudio->stop();
   }
   if (mPrivate->mVideo.get()) {
     mPrivate->mVideo->stop();
   }
 }
 
+mozilla::MetadataTags*
+MP4Demuxer::GetTags()
+{
+  mozilla::MetadataTags* tags = new mozilla::MetadataTags;
+  sp<MetaData> metaData = mPrivate->mExtractor->getMetaData();
+  const char* value = nullptr;
+  nsCString cstringValue;
+  size_t key_count = mozilla::ArrayLength(keys);
+
+  for (size_t i = 0; i < key_count; i++) {
+    if (metaData->findCString(keys[i].key, &value)) {
+      MOZ_ASSERT(value);
+      cstringValue = nsCString(value);
+      if (IsUTF8(cstringValue)) {
+        tags->Put(nsCString(keys[i].name), cstringValue);
+      }
+    }
+  }
+
+  return tags;
+}
+
 bool
 MP4Demuxer::Init()
 {
   sp<MediaExtractor> e = mPrivate->mExtractor;
   for (size_t i = 0; i < e->countTracks(); i++) {
     sp<MetaData> metaData = e->getTrackMetaData(i);
 
     const char* mimeType;