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

Side by Side 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, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/utility/media_galleries/media_metadata_parser.h" 5 #include "chrome/utility/media_galleries/media_metadata_parser.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/task_runner_util.h" 13 #include "base/task_runner_util.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "chrome/utility/media_galleries/image_metadata_extractor.h" 15 #include "chrome/utility/media_galleries/image_metadata_extractor.h"
16 #include "media/base/audio_video_metadata_extractor.h" 16 #include "media/base/audio_video_metadata_extractor.h"
17 #include "media/base/data_source.h" 17 #include "media/base/data_source.h"
18 #include "net/base/mime_sniffer.h"
18 19
19 namespace MediaGalleries = extensions::api::media_galleries; 20 namespace MediaGalleries = extensions::api::media_galleries;
20 21
21 namespace metadata { 22 namespace metadata {
22 23
23 namespace { 24 namespace {
24 25
25 void SetStringScopedPtr(const std::string& value, 26 void SetStringScopedPtr(const std::string& value,
26 scoped_ptr<std::string>* destination) { 27 scoped_ptr<std::string>* destination) {
27 DCHECK(destination); 28 DCHECK(destination);
(...skipping 14 matching lines...) Expand all
42 } 43 }
43 44
44 void SetBoolScopedPtr(bool value, scoped_ptr<bool>* destination) { 45 void SetBoolScopedPtr(bool value, scoped_ptr<bool>* destination) {
45 DCHECK(destination); 46 DCHECK(destination);
46 destination->reset(new bool(value)); 47 destination->reset(new bool(value));
47 } 48 }
48 49
49 // This runs on |media_thread_|, as the underlying FFmpeg operation is 50 // This runs on |media_thread_|, as the underlying FFmpeg operation is
50 // blocking, and the utility thread must not be blocked, so the media file 51 // blocking, and the utility thread must not be blocked, so the media file
51 // bytes can be sent from the browser process to the utility process. 52 // bytes can be sent from the browser process to the utility process.
52 scoped_ptr<MediaMetadataParser::MediaMetadata> ParseAudioVideoMetadata( 53 void ParseAudioVideoMetadata(
53 media::DataSource* source, 54 media::DataSource* source, bool get_attached_images,
54 scoped_ptr<MediaMetadataParser::MediaMetadata> metadata) { 55 MediaMetadataParser::MediaMetadata* metadata,
56 std::vector<AttachedImage>* attached_images) {
55 DCHECK(source); 57 DCHECK(source);
56 DCHECK(metadata.get()); 58 DCHECK(metadata);
57 media::AudioVideoMetadataExtractor extractor; 59 media::AudioVideoMetadataExtractor extractor;
58 60
59 if (!extractor.Extract(source)) 61 if (!extractor.Extract(source, get_attached_images))
60 return metadata.Pass(); 62 return;
61 63
62 if (extractor.duration() >= 0) 64 if (extractor.duration() >= 0)
63 metadata->duration.reset(new double(extractor.duration())); 65 metadata->duration.reset(new double(extractor.duration()));
64 66
65 if (extractor.height() >= 0 && extractor.width() >= 0) { 67 if (extractor.height() >= 0 && extractor.width() >= 0) {
66 metadata->height.reset(new int(extractor.height())); 68 metadata->height.reset(new int(extractor.height()));
67 metadata->width.reset(new int(extractor.width())); 69 metadata->width.reset(new int(extractor.width()));
68 } 70 }
69 71
70 SetStringScopedPtr(extractor.artist(), &metadata->artist); 72 SetStringScopedPtr(extractor.artist(), &metadata->artist);
(...skipping 18 matching lines...) Expand all
89 for (std::map<std::string, std::string>::const_iterator tag_it = 91 for (std::map<std::string, std::string>::const_iterator tag_it =
90 it->tags.begin(); 92 it->tags.begin();
91 tag_it != it->tags.end(); ++tag_it) { 93 tag_it != it->tags.end(); ++tag_it) {
92 stream_info->tags.additional_properties.SetString(tag_it->first, 94 stream_info->tags.additional_properties.SetString(tag_it->first,
93 tag_it->second); 95 tag_it->second);
94 } 96 }
95 97
96 metadata->raw_tags.push_back(stream_info); 98 metadata->raw_tags.push_back(stream_info);
97 } 99 }
98 100
99 return metadata.Pass(); 101 if (get_attached_images) {
102 for (std::vector<std::string>::const_iterator it =
103 extractor.attached_images_bytes().begin();
104 it != extractor.attached_images_bytes().end(); ++it) {
105 AttachedImage image;
106 image.data = *it;
107 net::SniffMimeTypeFromLocalData(it->c_str(), it->length(), &image.type);
108 attached_images->push_back(image);
109 }
110 }
111 }
112
113 void FinishParseAudioVideoMetadata(
114 MediaMetadataParser::MetadataCallback callback,
115 scoped_ptr<MediaMetadataParser::MediaMetadata> metadata,
116 std::vector<AttachedImage>* attached_images) {
117 DCHECK(!callback.is_null());
118 DCHECK(metadata.get());
119 DCHECK(attached_images);
120
121 callback.Run(metadata.Pass(), *attached_images);
100 } 122 }
101 123
102 void FinishParseImageMetadata( 124 void FinishParseImageMetadata(
103 ImageMetadataExtractor* extractor, 125 ImageMetadataExtractor* extractor,
104 scoped_ptr<MediaMetadataParser::MediaMetadata> metadata, 126 scoped_ptr<MediaMetadataParser::MediaMetadata> metadata,
105 MediaMetadataParser::MetadataCallback callback, 127 MediaMetadataParser::MetadataCallback callback, bool extract_success) {
106 bool extract_success) {
107 DCHECK(extractor); 128 DCHECK(extractor);
108 DCHECK(metadata.get()); 129 DCHECK(metadata.get());
109 130
110 if (!extract_success) { 131 if (!extract_success) {
111 callback.Run(metadata.Pass()); 132 callback.Run(metadata.Pass(), std::vector<AttachedImage>());
112 return; 133 return;
113 } 134 }
114 135
115 SetIntScopedPtr(extractor->height(), &metadata->height); 136 SetIntScopedPtr(extractor->height(), &metadata->height);
116 SetIntScopedPtr(extractor->width(), &metadata->width); 137 SetIntScopedPtr(extractor->width(), &metadata->width);
117 138
118 SetIntScopedPtr(extractor->rotation(), &metadata->rotation); 139 SetIntScopedPtr(extractor->rotation(), &metadata->rotation);
119 140
120 SetDoubleScopedPtr(extractor->x_resolution(), &metadata->x_resolution); 141 SetDoubleScopedPtr(extractor->x_resolution(), &metadata->x_resolution);
121 SetDoubleScopedPtr(extractor->y_resolution(), &metadata->y_resolution); 142 SetDoubleScopedPtr(extractor->y_resolution(), &metadata->y_resolution);
122 SetBoolScopedPtr(extractor->flash_fired(), &metadata->flash_fired); 143 SetBoolScopedPtr(extractor->flash_fired(), &metadata->flash_fired);
123 SetStringScopedPtr(extractor->camera_make(), &metadata->camera_make); 144 SetStringScopedPtr(extractor->camera_make(), &metadata->camera_make);
124 SetStringScopedPtr(extractor->camera_model(), &metadata->camera_model); 145 SetStringScopedPtr(extractor->camera_model(), &metadata->camera_model);
125 SetDoubleScopedPtr(extractor->exposure_time_sec(), 146 SetDoubleScopedPtr(extractor->exposure_time_sec(),
126 &metadata->exposure_time_seconds); 147 &metadata->exposure_time_seconds);
127 148
128 SetDoubleScopedPtr(extractor->f_number(), &metadata->f_number); 149 SetDoubleScopedPtr(extractor->f_number(), &metadata->f_number);
129 SetDoubleScopedPtr(extractor->focal_length_mm(), &metadata->focal_length_mm); 150 SetDoubleScopedPtr(extractor->focal_length_mm(), &metadata->focal_length_mm);
130 SetDoubleScopedPtr(extractor->iso_equivalent(), &metadata->iso_equivalent); 151 SetDoubleScopedPtr(extractor->iso_equivalent(), &metadata->iso_equivalent);
131 152
132 callback.Run(metadata.Pass()); 153 callback.Run(metadata.Pass(), std::vector<AttachedImage>());
133 } 154 }
134 155
135 } // namespace 156 } // namespace
136 157
137 MediaMetadataParser::MediaMetadataParser(media::DataSource* source, 158 MediaMetadataParser::MediaMetadataParser(media::DataSource* source,
138 const std::string& mime_type) 159 const std::string& mime_type,
160 bool get_attached_images)
139 : source_(source), 161 : source_(source),
140 mime_type_(mime_type) { 162 mime_type_(mime_type),
163 get_attached_images_(get_attached_images) {
141 } 164 }
142 165
143 MediaMetadataParser::~MediaMetadataParser() {} 166 MediaMetadataParser::~MediaMetadataParser() {}
144 167
145 void MediaMetadataParser::Start(const MetadataCallback& callback) { 168 void MediaMetadataParser::Start(const MetadataCallback& callback) {
146 scoped_ptr<MediaMetadata> metadata(new MediaMetadata); 169 scoped_ptr<MediaMetadata> metadata(new MediaMetadata);
147 metadata->mime_type = mime_type_; 170 metadata->mime_type = mime_type_;
148 171
149 if (StartsWithASCII(mime_type_, "audio/", true) || 172 if (StartsWithASCII(mime_type_, "audio/", true) ||
150 StartsWithASCII(mime_type_, "video/", true)) { 173 StartsWithASCII(mime_type_, "video/", true)) {
174 std::vector<AttachedImage>* attached_images =
175 new std::vector<AttachedImage>;
176
151 media_thread_.reset(new base::Thread("media_thread")); 177 media_thread_.reset(new base::Thread("media_thread"));
152 CHECK(media_thread_->Start()); 178 CHECK(media_thread_->Start());
153 base::PostTaskAndReplyWithResult( 179 media_thread_->message_loop_proxy()->PostTaskAndReply(
154 media_thread_->message_loop_proxy(),
155 FROM_HERE, 180 FROM_HERE,
156 base::Bind(&ParseAudioVideoMetadata, source_, base::Passed(&metadata)), 181 base::Bind(&ParseAudioVideoMetadata, source_, get_attached_images_,
157 callback); 182 metadata.get(), attached_images),
183 base::Bind(&FinishParseAudioVideoMetadata, callback,
184 base::Passed(&metadata), base::Owned(attached_images)));
158 return; 185 return;
159 } 186 }
160 187
161 if (StartsWithASCII(mime_type_, "image/", true)) { 188 if (StartsWithASCII(mime_type_, "image/", true)) {
162 ImageMetadataExtractor* extractor = new ImageMetadataExtractor; 189 ImageMetadataExtractor* extractor = new ImageMetadataExtractor;
163 extractor->Extract( 190 extractor->Extract(
164 source_, 191 source_,
165 base::Bind(&FinishParseImageMetadata, base::Owned(extractor), 192 base::Bind(&FinishParseImageMetadata, base::Owned(extractor),
166 base::Passed(&metadata), callback)); 193 base::Passed(&metadata), callback));
167 return; 194 return;
168 } 195 }
169 196
170 // TODO(tommycli): Implement for image mime types. 197 callback.Run(metadata.Pass(), std::vector<AttachedImage>());
171 callback.Run(metadata.Pass());
172 } 198 }
173 199
174 } // namespace metadata 200 } // namespace metadata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698