AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StreamProperties.hpp
Go to the documentation of this file.
1 #ifndef _AV_TRANSCODER_MEDIA_PROPERTY_STREAM_PROPERTIES_HPP
2 #define _AV_TRANSCODER_MEDIA_PROPERTY_STREAM_PROPERTIES_HPP
3 
7 
8 namespace avtranscoder
9 {
10 
11 /// Virtual based class of properties for all types of stream
12 class AvExport StreamProperties
13 {
14 public:
15  StreamProperties(const FormatContext& formatContext, const size_t index);
16  virtual ~StreamProperties() = 0;
17 
18  size_t getStreamIndex() const { return _streamIndex; }
19  size_t getStreamId() const;
20  Rational getTimeBase() const;
21  float getDuration() const; ///< in seconds
22  AVMediaType getStreamType() const;
23 
24  size_t getCodecId() const;
25  std::string getCodecName() const;
26  std::string getCodecLongName() const;
27 
28  const PropertyVector& getMetadatas() const { return _metadatas; }
29 
30 #ifndef SWIG
31  const AVFormatContext& getAVFormatContext() const { return *_formatContext; }
32 #endif
33 
34  std::string asJson() const; ///< Return all properties as a json format.
35  PropertyMap asMap() const; ///< Return all properties as a map (name of property, value)
36  PropertyVector asVector() const; ///< Same data with a specific order
37  virtual PropertyVector& fillVector(PropertyVector& data) const; ///< To avoid copy of the vector
38 
39 private:
40 #ifndef SWIG
41  template <typename T>
42  void addProperty(PropertyVector& dataVector, const std::string& key, T (StreamProperties::*getter)(void) const) const
43  {
44  try
45  {
46  detail::add(dataVector, key, (this->*getter)());
47  }
48  catch(const std::exception& e)
49  {
50  detail::add(dataVector, key, detail::propertyValueIfError);
51  }
52  }
53 #endif
54 
55 protected:
56  const AVFormatContext* _formatContext; ///< Has link (no ownership)
57  AVCodecContext* _codecContext; ///< Has link (no ownership)
58  AVCodec* _codec; ///< Has link (no ownership)
59 
60  size_t _streamIndex;
62 };
63 
64 #ifndef SWIG
65 AvExport std::ostream& operator<<(std::ostream& flux, const StreamProperties& streamProperties);
66 #endif
67 }
68 
69 #endif
std::vector< std::pair< std::string, std::string > > PropertyVector
PropertyVector is a vector of pair, because the order of properties matters to us.
Definition: util.hpp:23
const AVFormatContext * _formatContext
Has link (no ownership)
const AVFormatContext & getAVFormatContext() const
void add(PropertyVector &propertyVector, const std::string &key, const size_t &value)
Definition: util.cpp:16
AVCodec * _codec
Has link (no ownership)
const PropertyVector & getMetadatas() const
std::map< std::string, std::string > PropertyMap
Definition: util.hpp:24
Wrapper of an AVFormatContext.
AVCodecContext * _codecContext
Has link (no ownership)
Virtual based class of properties for all types of stream.
void addProperty(PropertyVector &dataVector, const std::string &key, T(StreamProperties::*getter)(void) const) const
AVRational Rational
Definition: common.hpp:55
std::ostream & operator<<(std::ostream &flux, const InputFile &input)
Definition: InputFile.cpp:171
const std::string propertyValueIfError
Definition: util.hpp:38