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

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: Create Blobs on browser-process, eliminating two IPC copies. 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..2b18ad2f14d816493cc9cc556366cd28b60a8d4e 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,16 @@ 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_images,
+ MediaMetadataParser::MediaMetadata* metadata,
+ std::vector<AttachedImage>* attached_images) {
DCHECK(source);
- DCHECK(metadata.get());
+ DCHECK(metadata);
media::AudioVideoMetadataExtractor extractor;
- if (!extractor.Extract(source))
- return metadata.Pass();
+ if (!extractor.Extract(source, get_attached_images))
+ return;
if (extractor.duration() >= 0)
metadata->duration.reset(new double(extractor.duration()));
@@ -96,19 +98,38 @@ scoped_ptr<MediaMetadataParser::MediaMetadata> ParseAudioVideoMetadata(
metadata->raw_tags.push_back(stream_info);
}
- return metadata.Pass();
+ if (get_attached_images) {
+ for (std::vector<std::string>::const_iterator it =
+ extractor.attached_images_bytes().begin();
+ it != extractor.attached_images_bytes().end(); ++it) {
+ AttachedImage image;
+ image.data = *it;
+ net::SniffMimeTypeFromLocalData(it->c_str(), it->length(), &image.type);
+ attached_images->push_back(image);
+ }
+ }
+}
+
+void FinishParseAudioVideoMetadata(
+ MediaMetadataParser::MetadataCallback callback,
+ scoped_ptr<MediaMetadataParser::MediaMetadata> metadata,
+ std::vector<AttachedImage>* attached_images) {
+ DCHECK(!callback.is_null());
+ DCHECK(metadata.get());
+ DCHECK(attached_images);
+
+ callback.Run(metadata.Pass(), *attached_images);
}
void FinishParseImageMetadata(
ImageMetadataExtractor* extractor,
scoped_ptr<MediaMetadataParser::MediaMetadata> metadata,
- MediaMetadataParser::MetadataCallback callback,
- bool extract_success) {
+ MediaMetadataParser::MetadataCallback callback, bool extract_success) {
DCHECK(extractor);
DCHECK(metadata.get());
if (!extract_success) {
- callback.Run(metadata.Pass());
+ callback.Run(metadata.Pass(), std::vector<AttachedImage>());
return;
}
@@ -129,15 +150,17 @@ 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<AttachedImage>());
}
} // namespace
MediaMetadataParser::MediaMetadataParser(media::DataSource* source,
- const std::string& mime_type)
+ const std::string& mime_type,
+ bool get_attached_images)
: source_(source),
- mime_type_(mime_type) {
+ mime_type_(mime_type),
+ get_attached_images_(get_attached_images) {
}
MediaMetadataParser::~MediaMetadataParser() {}
@@ -148,13 +171,17 @@ void MediaMetadataParser::Start(const MetadataCallback& callback) {
if (StartsWithASCII(mime_type_, "audio/", true) ||
StartsWithASCII(mime_type_, "video/", true)) {
+ std::vector<AttachedImage>* attached_images =
+ new std::vector<AttachedImage>;
+
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_images_,
+ metadata.get(), attached_images),
+ base::Bind(&FinishParseAudioVideoMetadata, callback,
+ base::Passed(&metadata), base::Owned(attached_images)));
return;
}
@@ -167,8 +194,7 @@ void MediaMetadataParser::Start(const MetadataCallback& callback) {
return;
}
- // TODO(tommycli): Implement for image mime types.
- callback.Run(metadata.Pass());
+ callback.Run(metadata.Pass(), std::vector<AttachedImage>());
}
} // namespace metadata

Powered by Google App Engine
This is Rietveld 408576698