Home | History | Annotate | Download | only in base
      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 
      5 #ifndef MEDIA_BASE_AUDIO_VIDEO_METADATA_EXTRACTOR_H_
      6 #define MEDIA_BASE_AUDIO_VIDEO_METADATA_EXTRACTOR_H_
      7 
      8 #include <map>
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/basictypes.h"
     13 #include "media/base/media_export.h"
     14 
     15 struct AVDictionary;
     16 
     17 namespace media {
     18 
     19 class DataSource;
     20 
     21 // This class extracts a string dictionary of metadata tags for audio and video
     22 // files. It also provides the format name.
     23 class MEDIA_EXPORT AudioVideoMetadataExtractor {
     24  public:
     25   typedef std::map<std::string, std::string> TagDictionary;
     26 
     27   struct StreamInfo {
     28     StreamInfo();
     29     ~StreamInfo();
     30     std::string type;
     31     TagDictionary tags;
     32   };
     33 
     34   typedef std::vector<StreamInfo> StreamInfoVector;
     35 
     36   AudioVideoMetadataExtractor();
     37   ~AudioVideoMetadataExtractor();
     38 
     39   // Returns whether or not the fields were successfully extracted. Should only
     40   // be called once.
     41   bool Extract(DataSource* source, bool extract_attached_pics);
     42 
     43   // Returns -1 if we cannot extract the duration. In seconds.
     44   double duration() const;
     45 
     46   // Returns -1 for containers without video.
     47   int width() const;
     48   int height() const;
     49 
     50   // Returns -1 if undefined.
     51   int rotation() const;
     52 
     53   // Returns -1 or an empty string if the value is undefined.
     54   const std::string& album() const;
     55   const std::string& artist() const;
     56   const std::string& comment() const;
     57   const std::string& copyright() const;
     58   const std::string& date() const;
     59   int disc() const;
     60   const std::string& encoder() const;
     61   const std::string& encoded_by() const;
     62   const std::string& genre() const;
     63   const std::string& language() const;
     64   const std::string& title() const;
     65   int track() const;
     66 
     67   // First element is the container. Subsequent elements are the child streams.
     68   const StreamInfoVector& stream_infos() const;
     69 
     70   // Empty if Extract call did not request attached images, or if no attached
     71   // images were found.
     72   const std::vector<std::string>& attached_images_bytes() const;
     73 
     74  private:
     75   void ExtractDictionary(AVDictionary* metadata, TagDictionary* raw_tags);
     76 
     77   bool extracted_;
     78 
     79   int duration_;
     80   int width_;
     81   int height_;
     82 
     83   std::string album_;
     84   std::string artist_;
     85   std::string comment_;
     86   std::string copyright_;
     87   std::string date_;
     88   int disc_;
     89   std::string encoder_;
     90   std::string encoded_by_;
     91   std::string genre_;
     92   std::string language_;
     93   int rotation_;
     94   std::string title_;
     95   int track_;
     96 
     97   StreamInfoVector stream_infos_;
     98 
     99   std::vector<std::string> attached_images_bytes_;
    100 
    101   DISALLOW_COPY_AND_ASSIGN(AudioVideoMetadataExtractor);
    102 };
    103 
    104 }  // namespace media
    105 
    106 #endif  // MEDIA_BASE_AUDIO_VIDEO_METADATA_EXTRACTOR_H_
    107