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

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

Issue 191583002: Media Galleries API Metadata: Image metadata (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 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()));
49 metadata->width.reset(new int(extractor.width())); 64 metadata->width.reset(new int(extractor.width()));
50 } 65 }
51 66
52 SetStringScopedPtr(extractor.artist(), &metadata->artist); 67 SetStringScopedPtr(extractor.artist(), &metadata->artist);
53 SetStringScopedPtr(extractor.album(), &metadata->album); 68 SetStringScopedPtr(extractor.album(), &metadata->album);
54 SetStringScopedPtr(extractor.artist(), &metadata->artist); 69 SetStringScopedPtr(extractor.artist(), &metadata->artist);
55 SetStringScopedPtr(extractor.comment(), &metadata->comment); 70 SetStringScopedPtr(extractor.comment(), &metadata->comment);
56 SetStringScopedPtr(extractor.copyright(), &metadata->copyright); 71 SetStringScopedPtr(extractor.copyright(), &metadata->copyright);
57 SetIntScopedPtr(extractor.disc(), &metadata->disc); 72 SetIntScopedPtr(extractor.disc(), &metadata->disc);
58 SetStringScopedPtr(extractor.genre(), &metadata->genre); 73 SetStringScopedPtr(extractor.genre(), &metadata->genre);
59 SetStringScopedPtr(extractor.language(), &metadata->language); 74 SetStringScopedPtr(extractor.language(), &metadata->language);
60 SetIntScopedPtr(extractor.rotation(), &metadata->rotation); 75 SetIntScopedPtr(extractor.rotation(), &metadata->rotation);
61 SetStringScopedPtr(extractor.title(), &metadata->title); 76 SetStringScopedPtr(extractor.title(), &metadata->title);
62 SetIntScopedPtr(extractor.track(), &metadata->track); 77 SetIntScopedPtr(extractor.track(), &metadata->track);
63 78
64 return metadata.Pass(); 79 return metadata.Pass();
65 } 80 }
66 81
82 void FinishParseImageMetadata(
83 ImageMetadataExtractor* extractor,
84 scoped_ptr<MediaMetadataParser::MediaMetadata> metadata,
85 MediaMetadataParser::MetadataCallback callback,
86 bool extract_success) {
87 DCHECK(extractor);
88 DCHECK(metadata.get());
89
90 if (!extract_success) {
91 callback.Run(metadata.Pass());
92 return;
93 }
94
95 SetIntScopedPtr(extractor->height(), &metadata->height);
96 SetIntScopedPtr(extractor->width(), &metadata->width);
97
98 SetIntScopedPtr(extractor->rotation(), &metadata->rotation);
99
100 SetDoubleScopedPtr(extractor->x_resolution(), &metadata->x_resolution);
101 SetDoubleScopedPtr(extractor->y_resolution(), &metadata->y_resolution);
102 SetBoolScopedPtr(extractor->flash_fired(), &metadata->flash_fired);
103 SetStringScopedPtr(extractor->camera_make(), &metadata->camera_make);
104 SetStringScopedPtr(extractor->camera_model(), &metadata->camera_model);
105 SetDoubleScopedPtr(extractor->exposure_time_sec(),
106 &metadata->exposure_time_seconds);
107
108 SetDoubleScopedPtr(extractor->f_number(), &metadata->f_number);
109 SetDoubleScopedPtr(extractor->focal_length_mm(), &metadata->focal_length_mm);
110 SetDoubleScopedPtr(extractor->iso_equivalent(), &metadata->iso_equivalent);
111
112 callback.Run(metadata.Pass());
113 }
114
67 } // namespace 115 } // namespace
68 116
69 MediaMetadataParser::MediaMetadataParser(media::DataSource* source, 117 MediaMetadataParser::MediaMetadataParser(media::DataSource* source,
70 const std::string& mime_type) 118 const std::string& mime_type)
71 : source_(source), 119 : source_(source),
72 mime_type_(mime_type) { 120 mime_type_(mime_type) {
73 } 121 }
74 122
75 MediaMetadataParser::~MediaMetadataParser() {} 123 MediaMetadataParser::~MediaMetadataParser() {}
76 124
77 void MediaMetadataParser::Start(const MetadataCallback& callback) { 125 void MediaMetadataParser::Start(const MetadataCallback& callback) {
78 scoped_ptr<MediaMetadata> metadata(new MediaMetadata); 126 scoped_ptr<MediaMetadata> metadata(new MediaMetadata);
79 metadata->mime_type = mime_type_; 127 metadata->mime_type = mime_type_;
80 128
81 if (StartsWithASCII(mime_type_, "audio/", true) || 129 if (StartsWithASCII(mime_type_, "audio/", true) ||
82 StartsWithASCII(mime_type_, "video/", true)) { 130 StartsWithASCII(mime_type_, "video/", true)) {
83 media_thread_.reset(new base::Thread("media_thread")); 131 media_thread_.reset(new base::Thread("media_thread"));
84 CHECK(media_thread_->Start()); 132 CHECK(media_thread_->Start());
85 base::PostTaskAndReplyWithResult( 133 base::PostTaskAndReplyWithResult(
86 media_thread_->message_loop_proxy(), 134 media_thread_->message_loop_proxy(),
87 FROM_HERE, 135 FROM_HERE,
88 base::Bind(&ParseAudioVideoMetadata, source_, base::Passed(&metadata)), 136 base::Bind(&ParseAudioVideoMetadata, source_, base::Passed(&metadata)),
89 callback); 137 callback);
90 return; 138 return;
91 } 139 }
92 140
141 if (StartsWithASCII(mime_type_, "image/", true)) {
142 ImageMetadataExtractor* extractor = new ImageMetadataExtractor;
143 extractor->Extract(
144 source_,
145 base::Bind(&FinishParseImageMetadata, base::Owned(extractor),
146 base::Passed(&metadata), callback));
147 return;
148 }
149
93 // TODO(tommycli): Implement for image mime types. 150 // TODO(tommycli): Implement for image mime types.
94 callback.Run(metadata.Pass()); 151 callback.Run(metadata.Pass());
95 } 152 }
96 153
97 } // namespace metadata 154 } // namespace metadata
OLDNEW
« no previous file with comments | « chrome/utility/media_galleries/image_metadata_extractor_unittest.cc ('k') | third_party/libexif/libexif.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698