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 <map> | |
Lei Zhang
2014/01/07 21:44:25
not used
tommycli
2014/01/07 23:12:36
Done.
| |
8 #include <string> | |
9 | |
7 #include "base/bind.h" | 10 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/strings/string_util.h" | |
13 #include "media/base/audio_video_metadata_extractor.h" | |
14 #include "media/base/data_source.h" | |
9 | 15 |
10 namespace metadata { | 16 namespace metadata { |
11 | 17 |
12 MediaMetadataParser::MediaMetadataParser(DataReader* reader, | 18 namespace { |
19 | |
20 void SetStringScopedPtr(const std::string& value, | |
21 scoped_ptr<std::string>* destination) { | |
22 if (!value.empty()) | |
23 destination->reset(new std::string(value)); | |
24 } | |
25 | |
26 void SetIntScopedPtr(int value, scoped_ptr<int>* destination) { | |
27 if (value >= 0) | |
28 destination->reset(new int(value)); | |
29 } | |
30 | |
31 } // namespace | |
32 | |
33 MediaMetadataParser::MediaMetadataParser(media::DataSource* source, | |
13 const std::string& mime_type) | 34 const std::string& mime_type) |
14 : reader_(reader), | 35 : source_(source), |
15 metadata_(new MediaMetadata) { | 36 metadata_(new MediaMetadata) { |
16 metadata_->mime_type = mime_type; | 37 metadata_->mime_type = mime_type; |
17 } | 38 } |
18 | 39 |
19 MediaMetadataParser::~MediaMetadataParser() {} | 40 MediaMetadataParser::~MediaMetadataParser() {} |
20 | 41 |
21 void MediaMetadataParser::Start(const MetadataCallback& callback) { | 42 void MediaMetadataParser::Start(const MetadataCallback& callback) { |
22 DCHECK(callback_.is_null()); | 43 DCHECK(callback_.is_null()); |
23 callback_ = callback; | 44 callback_ = callback; |
24 | 45 |
25 // TODO(tommycli): Implement for various mime types. | 46 if (StartsWithASCII(metadata_->mime_type, "audio/", true) || |
47 StartsWithASCII(metadata_->mime_type, "video/", true)) { | |
48 PopulateAudioVideoMetadata(); | |
49 } | |
50 | |
51 // TODO(tommycli): Implement for image mime types. | |
26 callback_.Run(metadata_.Pass()); | 52 callback_.Run(metadata_.Pass()); |
27 } | 53 } |
28 | 54 |
55 void MediaMetadataParser::PopulateAudioVideoMetadata() { | |
56 DCHECK(source_); | |
57 DCHECK(metadata_.get()); | |
58 media::AudioVideoMetadataExtractor extractor; | |
59 | |
60 if (!extractor.Extract(source_)) | |
61 return; | |
62 | |
63 if (extractor.duration() >= 0) | |
64 metadata_->duration.reset(new double(extractor.duration())); | |
65 | |
66 if (extractor.height() >= 0 && extractor.width() >= 0) { | |
67 metadata_->height.reset(new int(extractor.height())); | |
68 metadata_->width.reset(new int(extractor.width())); | |
69 } | |
70 | |
71 SetStringScopedPtr(extractor.artist(), &metadata_->artist); | |
72 SetStringScopedPtr(extractor.album(), &metadata_->album); | |
73 SetStringScopedPtr(extractor.artist(), &metadata_->artist); | |
74 SetStringScopedPtr(extractor.comment(), &metadata_->comment); | |
75 SetStringScopedPtr(extractor.copyright(), &metadata_->copyright); | |
76 SetIntScopedPtr(extractor.disc(), &metadata_->disc); | |
77 SetStringScopedPtr(extractor.genre(), &metadata_->genre); | |
78 SetStringScopedPtr(extractor.language(), &metadata_->language); | |
79 SetStringScopedPtr(extractor.title(), &metadata_->title); | |
80 SetIntScopedPtr(extractor.track(), &metadata_->track); | |
81 } | |
82 | |
29 } // namespace metadata | 83 } // namespace metadata |
OLD | NEW |