Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Unified Diff: chrome/utility/media_galleries/media_metadata_parser.cc

Issue 121383002: Media Galleries API Metadata: Add audio video metadata extractor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address thestig comments Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/utility/media_galleries/media_metadata_parser.cc
diff --git a/chrome/utility/media_galleries/media_metadata_parser.cc b/chrome/utility/media_galleries/media_metadata_parser.cc
index 33102c9c6cf3368c74d39c2c34983bfce0e11eba..1a2cba79c94a98ed267b5969d550333fc5453ed4 100644
--- a/chrome/utility/media_galleries/media_metadata_parser.cc
+++ b/chrome/utility/media_galleries/media_metadata_parser.cc
@@ -4,14 +4,34 @@
#include "chrome/utility/media_galleries/media_metadata_parser.h"
+#include <string>
+
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
+#include "base/strings/string_util.h"
+#include "media/base/audio_video_metadata_extractor.h"
+#include "media/base/data_source.h"
namespace metadata {
-MediaMetadataParser::MediaMetadataParser(DataReader* reader,
+namespace {
+
+void SetStringScopedPtr(const std::string& value,
+ scoped_ptr<std::string>* destination) {
+ if (!value.empty())
+ destination->reset(new std::string(value));
+}
+
+void SetIntScopedPtr(int value, scoped_ptr<int>* destination) {
+ if (value >= 0)
+ destination->reset(new int(value));
+}
+
+} // namespace
+
+MediaMetadataParser::MediaMetadataParser(media::DataSource* source,
const std::string& mime_type)
- : reader_(reader),
+ : source_(source),
metadata_(new MediaMetadata) {
metadata_->mime_type = mime_type;
}
@@ -22,8 +42,41 @@ void MediaMetadataParser::Start(const MetadataCallback& callback) {
DCHECK(callback_.is_null());
callback_ = callback;
- // TODO(tommycli): Implement for various mime types.
+ if (StartsWithASCII(metadata_->mime_type, "audio/", true) ||
+ StartsWithASCII(metadata_->mime_type, "video/", true)) {
+ PopulateAudioVideoMetadata();
+ }
+
+ // TODO(tommycli): Implement for image mime types.
callback_.Run(metadata_.Pass());
}
+void MediaMetadataParser::PopulateAudioVideoMetadata() {
+ DCHECK(source_);
+ DCHECK(metadata_.get());
+ media::AudioVideoMetadataExtractor extractor;
+
+ if (!extractor.Extract(source_))
+ return;
+
+ if (extractor.duration() >= 0)
+ metadata_->duration.reset(new double(extractor.duration()));
+
+ if (extractor.height() >= 0 && extractor.width() >= 0) {
+ metadata_->height.reset(new int(extractor.height()));
+ metadata_->width.reset(new int(extractor.width()));
+ }
+
+ SetStringScopedPtr(extractor.artist(), &metadata_->artist);
+ SetStringScopedPtr(extractor.album(), &metadata_->album);
+ SetStringScopedPtr(extractor.artist(), &metadata_->artist);
+ SetStringScopedPtr(extractor.comment(), &metadata_->comment);
+ SetStringScopedPtr(extractor.copyright(), &metadata_->copyright);
+ SetIntScopedPtr(extractor.disc(), &metadata_->disc);
+ SetStringScopedPtr(extractor.genre(), &metadata_->genre);
+ SetStringScopedPtr(extractor.language(), &metadata_->language);
+ SetStringScopedPtr(extractor.title(), &metadata_->title);
+ SetIntScopedPtr(extractor.track(), &metadata_->track);
+}
+
} // namespace metadata

Powered by Google App Engine
This is Rietveld 408576698