| 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..a1de57e53e5f713477305169f294180ce1172b32 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_pictures,
|
| + MediaMetadataParser::MediaMetadata* metadata,
|
| + std::vector<AttachedPicture>* attached_pictures) {
|
| 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,19 +98,38 @@ scoped_ptr<MediaMetadataParser::MediaMetadata> ParseAudioVideoMetadata(
|
| metadata->raw_tags.push_back(stream_info);
|
| }
|
|
|
| - return metadata.Pass();
|
| + if (get_attached_pictures) {
|
| + for (std::vector<std::string>::const_iterator it =
|
| + extractor.attached_pictures_bytes().begin();
|
| + it != extractor.attached_pictures_bytes().end(); ++it) {
|
| + AttachedPicture picture;
|
| + picture.data = *it;
|
| + net::SniffMimeTypeFromLocalData(it->c_str(), it->length(), &picture.type);
|
| + attached_pictures->push_back(picture);
|
| + }
|
| + }
|
| +}
|
| +
|
| +void FinishParseAudioVideoMetadata(
|
| + MediaMetadataParser::MetadataCallback callback,
|
| + scoped_ptr<MediaMetadataParser::MediaMetadata> metadata,
|
| + std::vector<AttachedPicture>* attached_pictures) {
|
| + DCHECK(!callback.is_null());
|
| + DCHECK(metadata.get());
|
| + DCHECK(attached_pictures);
|
| +
|
| + callback.Run(metadata.Pass(), *attached_pictures);
|
| }
|
|
|
| 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<AttachedPicture>());
|
| 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<AttachedPicture>());
|
| }
|
|
|
| } // 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 +171,17 @@ void MediaMetadataParser::Start(const MetadataCallback& callback) {
|
|
|
| if (StartsWithASCII(mime_type_, "audio/", true) ||
|
| StartsWithASCII(mime_type_, "video/", true)) {
|
| + std::vector<AttachedPicture>* attached_pictures =
|
| + new std::vector<AttachedPicture>;
|
| +
|
| 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),
|
| + base::Bind(&FinishParseAudioVideoMetadata, callback,
|
| + base::Passed(&metadata), base::Owned(attached_pictures)));
|
| 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<AttachedPicture>());
|
| }
|
|
|
| } // namespace metadata
|
|
|