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

Side by Side Diff: chrome/utility/media_galleries/media_metadata_parser.cc

Issue 216443005: Reapply "Media Galleries API Metadata: Image metadata" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge origin/master 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 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/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/task_runner_util.h" 12 #include "base/task_runner_util.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "chrome/utility/media_galleries/image_metadata_extractor.h"
14 #include "media/base/audio_video_metadata_extractor.h" 15 #include "media/base/audio_video_metadata_extractor.h"
15 #include "media/base/data_source.h" 16 #include "media/base/data_source.h"
16 17
17 namespace metadata { 18 namespace metadata {
18 19
19 namespace { 20 namespace {
20 21
21 void SetStringScopedPtr(const std::string& value, 22 void SetStringScopedPtr(const std::string& value,
22 scoped_ptr<std::string>* destination) { 23 scoped_ptr<std::string>* destination) {
24 DCHECK(destination);
23 if (!value.empty()) 25 if (!value.empty())
24 destination->reset(new std::string(value)); 26 destination->reset(new std::string(value));
25 } 27 }
26 28
27 void SetIntScopedPtr(int value, scoped_ptr<int>* destination) { 29 void SetIntScopedPtr(int value, scoped_ptr<int>* destination) {
30 DCHECK(destination);
28 if (value >= 0) 31 if (value >= 0)
29 destination->reset(new int(value)); 32 destination->reset(new int(value));
30 } 33 }
31 34
35 void SetDoubleScopedPtr(double value, scoped_ptr<double>* destination) {
36 DCHECK(destination);
37 if (value >= 0)
38 destination->reset(new double(value));
39 }
40
41 void SetBoolScopedPtr(bool value, scoped_ptr<bool>* destination) {
42 DCHECK(destination);
43 destination->reset(new bool(value));
44 }
45
32 // This runs on |media_thread_|, as the underlying FFmpeg operation is 46 // This runs on |media_thread_|, as the underlying FFmpeg operation is
33 // blocking, and the utility thread must not be blocked, so the media file 47 // blocking, and the utility thread must not be blocked, so the media file
34 // bytes can be sent from the browser process to the utility process. 48 // bytes can be sent from the browser process to the utility process.
35 scoped_ptr<MediaMetadataParser::MediaMetadata> ParseAudioVideoMetadata( 49 scoped_ptr<MediaMetadataParser::MediaMetadata> ParseAudioVideoMetadata(
36 media::DataSource* source, 50 media::DataSource* source,
37 scoped_ptr<MediaMetadataParser::MediaMetadata> metadata) { 51 scoped_ptr<MediaMetadataParser::MediaMetadata> metadata) {
38 DCHECK(source); 52 DCHECK(source);
53 DCHECK(metadata.get());
39 media::AudioVideoMetadataExtractor extractor; 54 media::AudioVideoMetadataExtractor extractor;
40 55
41 if (!extractor.Extract(source)) 56 if (!extractor.Extract(source))
42 return metadata.Pass(); 57 return metadata.Pass();
43 58
44 if (extractor.duration() >= 0) 59 if (extractor.duration() >= 0)
45 metadata->duration.reset(new double(extractor.duration())); 60 metadata->duration.reset(new double(extractor.duration()));
46 61
47 if (extractor.height() >= 0 && extractor.width() >= 0) { 62 if (extractor.height() >= 0 && extractor.width() >= 0) {
48 metadata->height.reset(new int(extractor.height())); 63 metadata->height.reset(new int(extractor.height()));
(...skipping 14 matching lines...) Expand all
63 78
64 for (std::map<std::string, std::string>::const_iterator it = 79 for (std::map<std::string, std::string>::const_iterator it =
65 extractor.raw_tags().begin(); 80 extractor.raw_tags().begin();
66 it != extractor.raw_tags().end(); ++it) { 81 it != extractor.raw_tags().end(); ++it) {
67 metadata->raw_tags.additional_properties.SetString(it->first, it->second); 82 metadata->raw_tags.additional_properties.SetString(it->first, it->second);
68 } 83 }
69 84
70 return metadata.Pass(); 85 return metadata.Pass();
71 } 86 }
72 87
88 void FinishParseImageMetadata(
89 ImageMetadataExtractor* extractor,
90 scoped_ptr<MediaMetadataParser::MediaMetadata> metadata,
91 MediaMetadataParser::MetadataCallback callback,
92 bool extract_success) {
93 DCHECK(extractor);
94 DCHECK(metadata.get());
95
96 if (!extract_success) {
97 callback.Run(metadata.Pass());
98 return;
99 }
100
101 SetIntScopedPtr(extractor->height(), &metadata->height);
102 SetIntScopedPtr(extractor->width(), &metadata->width);
103
104 SetIntScopedPtr(extractor->rotation(), &metadata->rotation);
105
106 SetDoubleScopedPtr(extractor->x_resolution(), &metadata->x_resolution);
107 SetDoubleScopedPtr(extractor->y_resolution(), &metadata->y_resolution);
108 SetBoolScopedPtr(extractor->flash_fired(), &metadata->flash_fired);
109 SetStringScopedPtr(extractor->camera_make(), &metadata->camera_make);
110 SetStringScopedPtr(extractor->camera_model(), &metadata->camera_model);
111 SetDoubleScopedPtr(extractor->exposure_time_sec(),
112 &metadata->exposure_time_seconds);
113
114 SetDoubleScopedPtr(extractor->f_number(), &metadata->f_number);
115 SetDoubleScopedPtr(extractor->focal_length_mm(), &metadata->focal_length_mm);
116 SetDoubleScopedPtr(extractor->iso_equivalent(), &metadata->iso_equivalent);
117
118 callback.Run(metadata.Pass());
119 }
120
73 } // namespace 121 } // namespace
74 122
75 MediaMetadataParser::MediaMetadataParser(media::DataSource* source, 123 MediaMetadataParser::MediaMetadataParser(media::DataSource* source,
76 const std::string& mime_type) 124 const std::string& mime_type)
77 : source_(source), 125 : source_(source),
78 mime_type_(mime_type) { 126 mime_type_(mime_type) {
79 } 127 }
80 128
81 MediaMetadataParser::~MediaMetadataParser() {} 129 MediaMetadataParser::~MediaMetadataParser() {}
82 130
83 void MediaMetadataParser::Start(const MetadataCallback& callback) { 131 void MediaMetadataParser::Start(const MetadataCallback& callback) {
84 scoped_ptr<MediaMetadata> metadata(new MediaMetadata); 132 scoped_ptr<MediaMetadata> metadata(new MediaMetadata);
85 metadata->mime_type = mime_type_; 133 metadata->mime_type = mime_type_;
86 134
87 if (StartsWithASCII(mime_type_, "audio/", true) || 135 if (StartsWithASCII(mime_type_, "audio/", true) ||
88 StartsWithASCII(mime_type_, "video/", true)) { 136 StartsWithASCII(mime_type_, "video/", true)) {
89 media_thread_.reset(new base::Thread("media_thread")); 137 media_thread_.reset(new base::Thread("media_thread"));
90 CHECK(media_thread_->Start()); 138 CHECK(media_thread_->Start());
91 base::PostTaskAndReplyWithResult( 139 base::PostTaskAndReplyWithResult(
92 media_thread_->message_loop_proxy(), 140 media_thread_->message_loop_proxy(),
93 FROM_HERE, 141 FROM_HERE,
94 base::Bind(&ParseAudioVideoMetadata, source_, base::Passed(&metadata)), 142 base::Bind(&ParseAudioVideoMetadata, source_, base::Passed(&metadata)),
95 callback); 143 callback);
96 return; 144 return;
97 } 145 }
98 146
147 if (StartsWithASCII(mime_type_, "image/", true)) {
148 ImageMetadataExtractor* extractor = new ImageMetadataExtractor;
149 extractor->Extract(
150 source_,
151 base::Bind(&FinishParseImageMetadata, base::Owned(extractor),
152 base::Passed(&metadata), callback));
153 return;
154 }
155
99 // TODO(tommycli): Implement for image mime types. 156 // TODO(tommycli): Implement for image mime types.
100 callback.Run(metadata.Pass()); 157 callback.Run(metadata.Pass());
101 } 158 }
102 159
103 } // namespace metadata 160 } // namespace metadata
OLDNEW
« no previous file with comments | « chrome/utility/media_galleries/image_metadata_extractor_unittest.cc ('k') | content/content_browsertests.isolate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698