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

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

Issue 1791623002: Revert of Media Galleries Partial Deprecation: Remove image metadata & libexif. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Manual revert/rebase. Created 4 years, 9 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
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/location.h" 10 #include "base/location.h"
11 #include "base/memory/linked_ptr.h" 11 #include "base/memory/linked_ptr.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 "media/base/audio_video_metadata_extractor.h" 16 #include "media/base/audio_video_metadata_extractor.h"
16 #include "media/base/data_source.h" 17 #include "media/base/data_source.h"
17 #include "net/base/mime_sniffer.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);
28 if (!value.empty()) 29 if (!value.empty())
29 destination->reset(new std::string(value)); 30 destination->reset(new std::string(value));
30 } 31 }
31 32
32 void SetIntScopedPtr(int value, scoped_ptr<int>* destination) { 33 void SetIntScopedPtr(int value, scoped_ptr<int>* destination) {
33 DCHECK(destination); 34 DCHECK(destination);
34 if (value >= 0) 35 if (value >= 0)
35 destination->reset(new int(value)); 36 destination->reset(new int(value));
36 } 37 }
37 38
39 void SetDoubleScopedPtr(double value, scoped_ptr<double>* destination) {
40 DCHECK(destination);
41 if (value >= 0)
42 destination->reset(new double(value));
43 }
44
45 void SetBoolScopedPtr(bool value, scoped_ptr<bool>* destination) {
46 DCHECK(destination);
47 destination->reset(new bool(value));
48 }
49
38 // This runs on |media_thread_|, as the underlying FFmpeg operation is 50 // This runs on |media_thread_|, as the underlying FFmpeg operation is
39 // 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
40 // 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.
41 void ParseAudioVideoMetadata( 53 void ParseAudioVideoMetadata(
42 media::DataSource* source, bool get_attached_images, 54 media::DataSource* source, bool get_attached_images,
43 MediaMetadataParser::MediaMetadata* metadata, 55 MediaMetadataParser::MediaMetadata* metadata,
44 std::vector<AttachedImage>* attached_images) { 56 std::vector<AttachedImage>* attached_images) {
45 DCHECK(source); 57 DCHECK(source);
46 DCHECK(metadata); 58 DCHECK(metadata);
47 59
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 MediaMetadataParser::MetadataCallback callback, 117 MediaMetadataParser::MetadataCallback callback,
106 MediaMetadataParser::MediaMetadata* metadata, 118 MediaMetadataParser::MediaMetadata* metadata,
107 std::vector<AttachedImage>* attached_images) { 119 std::vector<AttachedImage>* attached_images) {
108 DCHECK(!callback.is_null()); 120 DCHECK(!callback.is_null());
109 DCHECK(metadata); 121 DCHECK(metadata);
110 DCHECK(attached_images); 122 DCHECK(attached_images);
111 123
112 callback.Run(*metadata, *attached_images); 124 callback.Run(*metadata, *attached_images);
113 } 125 }
114 126
127 void FinishParseImageMetadata(
128 ImageMetadataExtractor* extractor, const std::string& mime_type,
129 MediaMetadataParser::MetadataCallback callback, bool extract_success) {
130 DCHECK(extractor);
131 MediaMetadataParser::MediaMetadata metadata;
132 metadata.mime_type = mime_type;
133
134 if (!extract_success) {
135 callback.Run(metadata, std::vector<AttachedImage>());
136 return;
137 }
138
139 SetIntScopedPtr(extractor->height(), &metadata.height);
140 SetIntScopedPtr(extractor->width(), &metadata.width);
141
142 SetIntScopedPtr(extractor->rotation(), &metadata.rotation);
143
144 SetDoubleScopedPtr(extractor->x_resolution(), &metadata.x_resolution);
145 SetDoubleScopedPtr(extractor->y_resolution(), &metadata.y_resolution);
146 SetBoolScopedPtr(extractor->flash_fired(), &metadata.flash_fired);
147 SetStringScopedPtr(extractor->camera_make(), &metadata.camera_make);
148 SetStringScopedPtr(extractor->camera_model(), &metadata.camera_model);
149 SetDoubleScopedPtr(extractor->exposure_time_sec(),
150 &metadata.exposure_time_seconds);
151
152 SetDoubleScopedPtr(extractor->f_number(), &metadata.f_number);
153 SetDoubleScopedPtr(extractor->focal_length_mm(), &metadata.focal_length_mm);
154 SetDoubleScopedPtr(extractor->iso_equivalent(), &metadata.iso_equivalent);
155
156 callback.Run(metadata, std::vector<AttachedImage>());
157 }
158
115 } // namespace 159 } // namespace
116 160
117 MediaMetadataParser::MediaMetadataParser(media::DataSource* source, 161 MediaMetadataParser::MediaMetadataParser(media::DataSource* source,
118 const std::string& mime_type, 162 const std::string& mime_type,
119 bool get_attached_images) 163 bool get_attached_images)
120 : source_(source), 164 : source_(source),
121 mime_type_(mime_type), 165 mime_type_(mime_type),
122 get_attached_images_(get_attached_images) { 166 get_attached_images_(get_attached_images) {
123 } 167 }
124 168
(...skipping 10 matching lines...) Expand all
135 media_thread_.reset(new base::Thread("media_thread")); 179 media_thread_.reset(new base::Thread("media_thread"));
136 CHECK(media_thread_->Start()); 180 CHECK(media_thread_->Start());
137 media_thread_->task_runner()->PostTaskAndReply( 181 media_thread_->task_runner()->PostTaskAndReply(
138 FROM_HERE, base::Bind(&ParseAudioVideoMetadata, source_, 182 FROM_HERE, base::Bind(&ParseAudioVideoMetadata, source_,
139 get_attached_images_, metadata, attached_images), 183 get_attached_images_, metadata, attached_images),
140 base::Bind(&FinishParseAudioVideoMetadata, callback, 184 base::Bind(&FinishParseAudioVideoMetadata, callback,
141 base::Owned(metadata), base::Owned(attached_images))); 185 base::Owned(metadata), base::Owned(attached_images)));
142 return; 186 return;
143 } 187 }
144 188
189 if (base::StartsWith(mime_type_, "image/", base::CompareCase::SENSITIVE)) {
190 ImageMetadataExtractor* extractor = new ImageMetadataExtractor;
191 extractor->Extract(
192 source_,
193 base::Bind(&FinishParseImageMetadata, base::Owned(extractor),
194 mime_type_, callback));
195 return;
196 }
197
145 callback.Run(MediaMetadata(), std::vector<AttachedImage>()); 198 callback.Run(MediaMetadata(), std::vector<AttachedImage>());
146 } 199 }
147 200
148 } // namespace metadata 201 } // namespace metadata
OLDNEW
« no previous file with comments | « chrome/utility/media_galleries/media_metadata_parser.h ('k') | testing/chromoting/chromoting_browser_tests.isolate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698