audio_video_metadata_extractor.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_FILTERS_AUDIO_VIDEO_METADATA_EXTRACTOR_H_
  5. #define MEDIA_FILTERS_AUDIO_VIDEO_METADATA_EXTRACTOR_H_
  6. #include <map>
  7. #include <string>
  8. #include <vector>
  9. #include "media/base/media_export.h"
  10. struct AVDictionary;
  11. namespace media {
  12. class DataSource;
  13. // This class extracts a string dictionary of metadata tags for audio and video
  14. // files. It also provides the format name.
  15. class MEDIA_EXPORT AudioVideoMetadataExtractor {
  16. public:
  17. typedef std::map<std::string, std::string> TagDictionary;
  18. struct StreamInfo {
  19. StreamInfo();
  20. StreamInfo(const StreamInfo& other);
  21. ~StreamInfo();
  22. std::string type;
  23. TagDictionary tags;
  24. };
  25. typedef std::vector<StreamInfo> StreamInfoVector;
  26. AudioVideoMetadataExtractor();
  27. AudioVideoMetadataExtractor(const AudioVideoMetadataExtractor&) = delete;
  28. AudioVideoMetadataExtractor& operator=(const AudioVideoMetadataExtractor&) =
  29. delete;
  30. ~AudioVideoMetadataExtractor();
  31. // Returns whether or not the fields were successfully extracted. Should only
  32. // be called once.
  33. bool Extract(DataSource* source, bool extract_attached_pics);
  34. // Returns whether or not duration information was extracted. Do not call
  35. // duration() if this returns false.
  36. bool has_duration() const;
  37. // Returns the duration in seconds. Value is undefined if has_duration()
  38. // returns false.
  39. double duration() const;
  40. // Returns -1 for containers without video.
  41. int width() const;
  42. int height() const;
  43. // Returns -1 if undefined.
  44. int rotation() const;
  45. // Returns -1 or an empty string if the value is undefined.
  46. const std::string& album() const;
  47. const std::string& artist() const;
  48. const std::string& comment() const;
  49. const std::string& copyright() const;
  50. const std::string& date() const;
  51. int disc() const;
  52. const std::string& encoder() const;
  53. const std::string& encoded_by() const;
  54. const std::string& genre() const;
  55. const std::string& language() const;
  56. const std::string& title() const;
  57. int track() const;
  58. // First element is the container. Subsequent elements are the child streams.
  59. const StreamInfoVector& stream_infos() const;
  60. // Empty if Extract call did not request attached images, or if no attached
  61. // images were found.
  62. const std::vector<std::string>& attached_images_bytes() const;
  63. private:
  64. void ExtractDictionary(AVDictionary* metadata, TagDictionary* raw_tags);
  65. bool extracted_;
  66. bool has_duration_;
  67. double duration_; // Valid only if |has_duration_| is true.
  68. int width_;
  69. int height_;
  70. std::string album_;
  71. std::string artist_;
  72. std::string comment_;
  73. std::string copyright_;
  74. std::string date_;
  75. int disc_;
  76. std::string encoder_;
  77. std::string encoded_by_;
  78. std::string genre_;
  79. std::string language_;
  80. int rotation_;
  81. std::string title_;
  82. int track_;
  83. StreamInfoVector stream_infos_;
  84. std::vector<std::string> attached_images_bytes_;
  85. };
  86. } // namespace media
  87. #endif // MEDIA_FILTERS_AUDIO_VIDEO_METADATA_EXTRACTOR_H_