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

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

Issue 217233005: Revert 260917 "Media Galleries API Metadata: Image metadata" (Closed) Base URL: svn://svn.chromium.org/chrome/
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"
15 #include "media/base/audio_video_metadata_extractor.h" 14 #include "media/base/audio_video_metadata_extractor.h"
16 #include "media/base/data_source.h" 15 #include "media/base/data_source.h"
17 16
18 namespace metadata { 17 namespace metadata {
19 18
20 namespace { 19 namespace {
21 20
22 void SetStringScopedPtr(const std::string& value, 21 void SetStringScopedPtr(const std::string& value,
23 scoped_ptr<std::string>* destination) { 22 scoped_ptr<std::string>* destination) {
24 DCHECK(destination);
25 if (!value.empty()) 23 if (!value.empty())
26 destination->reset(new std::string(value)); 24 destination->reset(new std::string(value));
27 } 25 }
28 26
29 void SetIntScopedPtr(int value, scoped_ptr<int>* destination) { 27 void SetIntScopedPtr(int value, scoped_ptr<int>* destination) {
30 DCHECK(destination);
31 if (value >= 0) 28 if (value >= 0)
32 destination->reset(new int(value)); 29 destination->reset(new int(value));
33 } 30 }
34 31
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
46 // This runs on |media_thread_|, as the underlying FFmpeg operation is 32 // This runs on |media_thread_|, as the underlying FFmpeg operation is
47 // blocking, and the utility thread must not be blocked, so the media file 33 // blocking, and the utility thread must not be blocked, so the media file
48 // bytes can be sent from the browser process to the utility process. 34 // bytes can be sent from the browser process to the utility process.
49 scoped_ptr<MediaMetadataParser::MediaMetadata> ParseAudioVideoMetadata( 35 scoped_ptr<MediaMetadataParser::MediaMetadata> ParseAudioVideoMetadata(
50 media::DataSource* source, 36 media::DataSource* source,
51 scoped_ptr<MediaMetadataParser::MediaMetadata> metadata) { 37 scoped_ptr<MediaMetadataParser::MediaMetadata> metadata) {
52 DCHECK(source); 38 DCHECK(source);
53 DCHECK(metadata.get());
54 media::AudioVideoMetadataExtractor extractor; 39 media::AudioVideoMetadataExtractor extractor;
55 40
56 if (!extractor.Extract(source)) 41 if (!extractor.Extract(source))
57 return metadata.Pass(); 42 return metadata.Pass();
58 43
59 if (extractor.duration() >= 0) 44 if (extractor.duration() >= 0)
60 metadata->duration.reset(new double(extractor.duration())); 45 metadata->duration.reset(new double(extractor.duration()));
61 46
62 if (extractor.height() >= 0 && extractor.width() >= 0) { 47 if (extractor.height() >= 0 && extractor.width() >= 0) {
63 metadata->height.reset(new int(extractor.height())); 48 metadata->height.reset(new int(extractor.height()));
64 metadata->width.reset(new int(extractor.width())); 49 metadata->width.reset(new int(extractor.width()));
65 } 50 }
66 51
67 SetStringScopedPtr(extractor.artist(), &metadata->artist); 52 SetStringScopedPtr(extractor.artist(), &metadata->artist);
68 SetStringScopedPtr(extractor.album(), &metadata->album); 53 SetStringScopedPtr(extractor.album(), &metadata->album);
69 SetStringScopedPtr(extractor.artist(), &metadata->artist); 54 SetStringScopedPtr(extractor.artist(), &metadata->artist);
70 SetStringScopedPtr(extractor.comment(), &metadata->comment); 55 SetStringScopedPtr(extractor.comment(), &metadata->comment);
71 SetStringScopedPtr(extractor.copyright(), &metadata->copyright); 56 SetStringScopedPtr(extractor.copyright(), &metadata->copyright);
72 SetIntScopedPtr(extractor.disc(), &metadata->disc); 57 SetIntScopedPtr(extractor.disc(), &metadata->disc);
73 SetStringScopedPtr(extractor.genre(), &metadata->genre); 58 SetStringScopedPtr(extractor.genre(), &metadata->genre);
74 SetStringScopedPtr(extractor.language(), &metadata->language); 59 SetStringScopedPtr(extractor.language(), &metadata->language);
75 SetIntScopedPtr(extractor.rotation(), &metadata->rotation); 60 SetIntScopedPtr(extractor.rotation(), &metadata->rotation);
76 SetStringScopedPtr(extractor.title(), &metadata->title); 61 SetStringScopedPtr(extractor.title(), &metadata->title);
77 SetIntScopedPtr(extractor.track(), &metadata->track); 62 SetIntScopedPtr(extractor.track(), &metadata->track);
78 63
79 return metadata.Pass(); 64 return metadata.Pass();
80 } 65 }
81 66
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
115 } // namespace 67 } // namespace
116 68
117 MediaMetadataParser::MediaMetadataParser(media::DataSource* source, 69 MediaMetadataParser::MediaMetadataParser(media::DataSource* source,
118 const std::string& mime_type) 70 const std::string& mime_type)
119 : source_(source), 71 : source_(source),
120 mime_type_(mime_type) { 72 mime_type_(mime_type) {
121 } 73 }
122 74
123 MediaMetadataParser::~MediaMetadataParser() {} 75 MediaMetadataParser::~MediaMetadataParser() {}
124 76
125 void MediaMetadataParser::Start(const MetadataCallback& callback) { 77 void MediaMetadataParser::Start(const MetadataCallback& callback) {
126 scoped_ptr<MediaMetadata> metadata(new MediaMetadata); 78 scoped_ptr<MediaMetadata> metadata(new MediaMetadata);
127 metadata->mime_type = mime_type_; 79 metadata->mime_type = mime_type_;
128 80
129 if (StartsWithASCII(mime_type_, "audio/", true) || 81 if (StartsWithASCII(mime_type_, "audio/", true) ||
130 StartsWithASCII(mime_type_, "video/", true)) { 82 StartsWithASCII(mime_type_, "video/", true)) {
131 media_thread_.reset(new base::Thread("media_thread")); 83 media_thread_.reset(new base::Thread("media_thread"));
132 CHECK(media_thread_->Start()); 84 CHECK(media_thread_->Start());
133 base::PostTaskAndReplyWithResult( 85 base::PostTaskAndReplyWithResult(
134 media_thread_->message_loop_proxy(), 86 media_thread_->message_loop_proxy(),
135 FROM_HERE, 87 FROM_HERE,
136 base::Bind(&ParseAudioVideoMetadata, source_, base::Passed(&metadata)), 88 base::Bind(&ParseAudioVideoMetadata, source_, base::Passed(&metadata)),
137 callback); 89 callback);
138 return; 90 return;
139 } 91 }
140 92
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
150 // TODO(tommycli): Implement for image mime types. 93 // TODO(tommycli): Implement for image mime types.
151 callback.Run(metadata.Pass()); 94 callback.Run(metadata.Pass());
152 } 95 }
153 96
154 } // namespace metadata 97 } // namespace metadata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698