| OLD | NEW |
| 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" | |
| 16 #include "media/base/audio_video_metadata_extractor.h" | 15 #include "media/base/audio_video_metadata_extractor.h" |
| 17 #include "media/base/data_source.h" | 16 #include "media/base/data_source.h" |
| 18 #include "net/base/mime_sniffer.h" | 17 #include "net/base/mime_sniffer.h" |
| 19 | 18 |
| 20 namespace MediaGalleries = extensions::api::media_galleries; | 19 namespace MediaGalleries = extensions::api::media_galleries; |
| 21 | 20 |
| 22 namespace metadata { | 21 namespace metadata { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 void SetStringScopedPtr(const std::string& value, | 25 void SetStringScopedPtr(const std::string& value, |
| 27 scoped_ptr<std::string>* destination) { | 26 scoped_ptr<std::string>* destination) { |
| 28 DCHECK(destination); | 27 DCHECK(destination); |
| 29 if (!value.empty()) | 28 if (!value.empty()) |
| 30 destination->reset(new std::string(value)); | 29 destination->reset(new std::string(value)); |
| 31 } | 30 } |
| 32 | 31 |
| 33 void SetIntScopedPtr(int value, scoped_ptr<int>* destination) { | 32 void SetIntScopedPtr(int value, scoped_ptr<int>* destination) { |
| 34 DCHECK(destination); | 33 DCHECK(destination); |
| 35 if (value >= 0) | 34 if (value >= 0) |
| 36 destination->reset(new int(value)); | 35 destination->reset(new int(value)); |
| 37 } | 36 } |
| 38 | 37 |
| 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 | |
| 50 // This runs on |media_thread_|, as the underlying FFmpeg operation is | 38 // This runs on |media_thread_|, as the underlying FFmpeg operation is |
| 51 // blocking, and the utility thread must not be blocked, so the media file | 39 // blocking, and the utility thread must not be blocked, so the media file |
| 52 // bytes can be sent from the browser process to the utility process. | 40 // bytes can be sent from the browser process to the utility process. |
| 53 void ParseAudioVideoMetadata( | 41 void ParseAudioVideoMetadata( |
| 54 media::DataSource* source, bool get_attached_images, | 42 media::DataSource* source, bool get_attached_images, |
| 55 MediaMetadataParser::MediaMetadata* metadata, | 43 MediaMetadataParser::MediaMetadata* metadata, |
| 56 std::vector<AttachedImage>* attached_images) { | 44 std::vector<AttachedImage>* attached_images) { |
| 57 DCHECK(source); | 45 DCHECK(source); |
| 58 DCHECK(metadata); | 46 DCHECK(metadata); |
| 59 | 47 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 MediaMetadataParser::MetadataCallback callback, | 105 MediaMetadataParser::MetadataCallback callback, |
| 118 MediaMetadataParser::MediaMetadata* metadata, | 106 MediaMetadataParser::MediaMetadata* metadata, |
| 119 std::vector<AttachedImage>* attached_images) { | 107 std::vector<AttachedImage>* attached_images) { |
| 120 DCHECK(!callback.is_null()); | 108 DCHECK(!callback.is_null()); |
| 121 DCHECK(metadata); | 109 DCHECK(metadata); |
| 122 DCHECK(attached_images); | 110 DCHECK(attached_images); |
| 123 | 111 |
| 124 callback.Run(*metadata, *attached_images); | 112 callback.Run(*metadata, *attached_images); |
| 125 } | 113 } |
| 126 | 114 |
| 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 | |
| 159 } // namespace | 115 } // namespace |
| 160 | 116 |
| 161 MediaMetadataParser::MediaMetadataParser(media::DataSource* source, | 117 MediaMetadataParser::MediaMetadataParser(media::DataSource* source, |
| 162 const std::string& mime_type, | 118 const std::string& mime_type, |
| 163 bool get_attached_images) | 119 bool get_attached_images) |
| 164 : source_(source), | 120 : source_(source), |
| 165 mime_type_(mime_type), | 121 mime_type_(mime_type), |
| 166 get_attached_images_(get_attached_images) { | 122 get_attached_images_(get_attached_images) { |
| 167 } | 123 } |
| 168 | 124 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 179 media_thread_.reset(new base::Thread("media_thread")); | 135 media_thread_.reset(new base::Thread("media_thread")); |
| 180 CHECK(media_thread_->Start()); | 136 CHECK(media_thread_->Start()); |
| 181 media_thread_->task_runner()->PostTaskAndReply( | 137 media_thread_->task_runner()->PostTaskAndReply( |
| 182 FROM_HERE, base::Bind(&ParseAudioVideoMetadata, source_, | 138 FROM_HERE, base::Bind(&ParseAudioVideoMetadata, source_, |
| 183 get_attached_images_, metadata, attached_images), | 139 get_attached_images_, metadata, attached_images), |
| 184 base::Bind(&FinishParseAudioVideoMetadata, callback, | 140 base::Bind(&FinishParseAudioVideoMetadata, callback, |
| 185 base::Owned(metadata), base::Owned(attached_images))); | 141 base::Owned(metadata), base::Owned(attached_images))); |
| 186 return; | 142 return; |
| 187 } | 143 } |
| 188 | 144 |
| 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 | |
| 198 callback.Run(MediaMetadata(), std::vector<AttachedImage>()); | 145 callback.Run(MediaMetadata(), std::vector<AttachedImage>()); |
| 199 } | 146 } |
| 200 | 147 |
| 201 } // namespace metadata | 148 } // namespace metadata |
| OLD | NEW |