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

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

Issue 250143002: Media Galleries API: Audio/Video attached pictures support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 9475bb877e683606002314e3ee2d203458678105..22e20684e6f0e5149ef2d6298c7fc3baf852016c 100644
--- a/chrome/utility/media_galleries/media_metadata_parser.cc
+++ b/chrome/utility/media_galleries/media_metadata_parser.cc
@@ -15,6 +15,7 @@
#include "chrome/utility/media_galleries/image_metadata_extractor.h"
#include "media/base/audio_video_metadata_extractor.h"
#include "media/base/data_source.h"
+#include "net/base/mime_sniffer.h"
namespace MediaGalleries = extensions::api::media_galleries;
@@ -49,15 +50,17 @@ void SetBoolScopedPtr(bool value, scoped_ptr<bool>* destination) {
// This runs on |media_thread_|, as the underlying FFmpeg operation is
// blocking, and the utility thread must not be blocked, so the media file
// bytes can be sent from the browser process to the utility process.
-scoped_ptr<MediaMetadataParser::MediaMetadata> ParseAudioVideoMetadata(
- media::DataSource* source,
- scoped_ptr<MediaMetadataParser::MediaMetadata> metadata) {
+void ParseAudioVideoMetadata(
+ media::DataSource* source, bool get_attached_pictures,
+ MediaMetadataParser::MediaMetadata* metadata,
+ std::vector<std::string>* attached_pictures_bytes,
vandebo (ex-Chrome) 2014/04/23 23:22:45 Maybe there should be a struct ThumbnailData { std
tommycli 2014/04/29 00:15:51 Done.
+ std::vector<std::string>* attached_pictures_types) {
DCHECK(source);
- DCHECK(metadata.get());
+ DCHECK(metadata);
media::AudioVideoMetadataExtractor extractor;
- if (!extractor.Extract(source))
- return metadata.Pass();
+ if (!extractor.Extract(source, get_attached_pictures))
+ return;
if (extractor.duration() >= 0)
metadata->duration.reset(new double(extractor.duration()));
@@ -96,7 +99,32 @@ scoped_ptr<MediaMetadataParser::MediaMetadata> ParseAudioVideoMetadata(
metadata->raw_tags.push_back(stream_info);
}
- return metadata.Pass();
+ if (get_attached_pictures) {
+ DCHECK(attached_pictures_bytes);
+ DCHECK(attached_pictures_types);
+ *attached_pictures_bytes = extractor.attached_pictures_bytes();
+ for (std::vector<std::string>::const_iterator it =
+ attached_pictures_bytes->begin();
+ it != attached_pictures_bytes->end(); ++it) {
+ std::string type;
+ net::SniffMimeTypeFromLocalData(it->c_str(), it->length(), &type);
+ attached_pictures_types->push_back(type);
+ }
+ }
+}
+
+void FinishParseAudioVideoMetadata(
+ MediaMetadataParser::MetadataCallback callback,
vandebo (ex-Chrome) 2014/04/23 23:22:45 Is this needed? Can you just bind to the callback
tommycli 2014/04/29 00:15:51 Needed so that the callback could base::Owned the
+ scoped_ptr<MediaMetadataParser::MediaMetadata> metadata,
+ std::vector<std::string>* attached_pictures_bytes,
+ std::vector<std::string>* attached_pictures_types) {
+ DCHECK(!callback.is_null());
+ DCHECK(metadata.get());
+ DCHECK(attached_pictures_bytes);
+ DCHECK(attached_pictures_types);
+
+ callback.Run(metadata.Pass(), *attached_pictures_bytes,
+ *attached_pictures_types);
}
void FinishParseImageMetadata(
@@ -108,7 +136,8 @@ void FinishParseImageMetadata(
DCHECK(metadata.get());
if (!extract_success) {
- callback.Run(metadata.Pass());
+ callback.Run(metadata.Pass(), std::vector<std::string>(),
+ std::vector<std::string>());
return;
}
@@ -129,15 +158,18 @@ void FinishParseImageMetadata(
SetDoubleScopedPtr(extractor->focal_length_mm(), &metadata->focal_length_mm);
SetDoubleScopedPtr(extractor->iso_equivalent(), &metadata->iso_equivalent);
- callback.Run(metadata.Pass());
+ callback.Run(metadata.Pass(), std::vector<std::string>(),
+ std::vector<std::string>());
}
} // namespace
MediaMetadataParser::MediaMetadataParser(media::DataSource* source,
- const std::string& mime_type)
+ const std::string& mime_type,
+ bool get_attached_pictures)
: source_(source),
- mime_type_(mime_type) {
+ mime_type_(mime_type),
+ get_attached_pictures_(get_attached_pictures) {
}
MediaMetadataParser::~MediaMetadataParser() {}
@@ -148,13 +180,22 @@ void MediaMetadataParser::Start(const MetadataCallback& callback) {
if (StartsWithASCII(mime_type_, "audio/", true) ||
StartsWithASCII(mime_type_, "video/", true)) {
+ std::vector<std::string>* attached_pictures_bytes =
+ new std::vector<std::string>;
+ std::vector<std::string>* attached_pictures_types =
+ new std::vector<std::string>;
+
media_thread_.reset(new base::Thread("media_thread"));
CHECK(media_thread_->Start());
- base::PostTaskAndReplyWithResult(
- media_thread_->message_loop_proxy(),
+ media_thread_->message_loop_proxy()->PostTaskAndReply(
FROM_HERE,
- base::Bind(&ParseAudioVideoMetadata, source_, base::Passed(&metadata)),
- callback);
+ base::Bind(&ParseAudioVideoMetadata, source_, get_attached_pictures_,
+ metadata.get(), attached_pictures_bytes,
+ attached_pictures_types),
+ base::Bind(&FinishParseAudioVideoMetadata, callback,
+ base::Passed(&metadata),
+ base::Owned(attached_pictures_bytes),
+ base::Owned(attached_pictures_types)));
return;
}
@@ -167,8 +208,8 @@ void MediaMetadataParser::Start(const MetadataCallback& callback) {
return;
}
- // TODO(tommycli): Implement for image mime types.
- callback.Run(metadata.Pass());
+ callback.Run(metadata.Pass(), std::vector<std::string>(),
+ std::vector<std::string>());
}
} // namespace metadata

Powered by Google App Engine
This is Rietveld 408576698