15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef MEDIA_BASE_AUDIO_VIDEO_METADATA_EXTRACTOR_H_
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define MEDIA_BASE_AUDIO_VIDEO_METADATA_EXTRACTOR_H_
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include <map>
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <string>
100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include <vector>
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/basictypes.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "media/base/media_export.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct AVDictionary;
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace media {
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class DataSource;
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This class extracts a string dictionary of metadata tags for audio and video
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// files. It also provides the format name.
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class MEDIA_EXPORT AudioVideoMetadataExtractor {
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  typedef std::map<std::string, std::string> TagDictionary;
260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  struct StreamInfo {
280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    StreamInfo();
290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    ~StreamInfo();
300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    std::string type;
310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    TagDictionary tags;
320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  };
330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  typedef std::vector<StreamInfo> StreamInfoVector;
350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AudioVideoMetadataExtractor();
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ~AudioVideoMetadataExtractor();
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns whether or not the fields were successfully extracted. Should only
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // be called once.
41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  bool Extract(DataSource* source, bool extract_attached_pics);
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns -1 if we cannot extract the duration. In seconds.
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  double duration() const;
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns -1 for containers without video.
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int width() const;
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int height() const;
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns -1 if undefined.
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int rotation() const;
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns -1 or an empty string if the value is undefined.
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const std::string& album() const;
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const std::string& artist() const;
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const std::string& comment() const;
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const std::string& copyright() const;
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const std::string& date() const;
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int disc() const;
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const std::string& encoder() const;
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const std::string& encoded_by() const;
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const std::string& genre() const;
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const std::string& language() const;
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const std::string& title() const;
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int track() const;
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // First element is the container. Subsequent elements are the child streams.
680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  const StreamInfoVector& stream_infos() const;
69c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
70cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Empty if Extract call did not request attached images, or if no attached
71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // images were found.
72cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  const std::vector<std::string>& attached_images_bytes() const;
73cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  void ExtractDictionary(AVDictionary* metadata, TagDictionary* raw_tags);
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool extracted_;
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int duration_;
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int width_;
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int height_;
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string album_;
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string artist_;
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string comment_;
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string copyright_;
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string date_;
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int disc_;
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string encoder_;
905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string encoded_by_;
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string genre_;
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string language_;
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int rotation_;
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string title_;
955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int track_;
965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  StreamInfoVector stream_infos_;
98c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
99cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  std::vector<std::string> attached_images_bytes_;
100cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AudioVideoMetadataExtractor);
1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace media
1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // MEDIA_BASE_AUDIO_VIDEO_METADATA_EXTRACTOR_H_
107