AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StreamTranscoder.hpp
Go to the documentation of this file.
1 #ifndef _AV_TRANSCODER_STREAM_TRANSCODER_HPP_
2 #define _AV_TRANSCODER_STREAM_TRANSCODER_HPP_
3 
5 
8 
11 
15 
16 namespace avtranscoder
17 {
18 
19 class ITransform;
20 
21 class AvExport StreamTranscoder
22 {
23 private:
24  StreamTranscoder(const StreamTranscoder& streamTranscoder);
25  StreamTranscoder& operator=(const StreamTranscoder& streamTranscoder);
26 
27 public:
28  /**
29  * @brief rewrap stream
30  * @note offset feature when rewrap a stream is not supported
31  **/
32  StreamTranscoder(IInputStream& inputStream, IOutputFile& outputFile, const float offset = 0);
33 
34  /**
35  * @brief transcode stream
36  **/
37  StreamTranscoder(IInputStream& inputStream, IOutputFile& outputFile, const ProfileLoader::Profile& profile,
38  const int subStreamIndex = -1, const float offset = 0);
39 
40  /**
41  * @brief encode from a generated stream
42  * @note offset feature has no sense here
43  **/
44  StreamTranscoder(const ICodec& inputCodec, IOutputFile& outputFile, const ProfileLoader::Profile& profile);
45 
47 
48  /**
49  * @brief Pre-process codec latency.
50  * @note This can be called several times with no side effects.
51  * @note Can take a little bit of time.
52  */
53  void preProcessCodecLatency();
54 
55  /**
56  * @brief process a single frame for the current stream
57  * @return the process status result
58  */
59  bool processFrame();
60 
61  //@{
62  /** Switch decoder */
63  void switchToGeneratorDecoder();
64  void switchToInputDecoder();
65  //@}
66 
67  /**
68  * @brief Get the total duration (in seconds), ie. duration of the stream and the offset applies
69  * @note if it's a generated stream, return limit of double.
70  * @note if offset > duration of the stream, return 0
71  */
72  float getDuration() const;
73 
74  /// Returns a pointer to the current decoder (from input file or from generator)
75  IDecoder* getCurrentDecoder() const { return _currentDecoder; }
76  /// Returns a pointer to the encoder
77  IEncoder* getEncoder() const { return _outputEncoder; }
78 
79  /// Returns a pointer to the object which transforms the decoded data
80  ITransform* getTransform() const { return _transform; }
81 
82  /// Returns a pointer to the object which manage filtering
83  FilterGraph* getFilterGraph() const { return _filterGraph; }
84 
85  /// Returns a pointer to the stream which unwraps data
86  IInputStream* getInputStream() const { return _inputStream; }
87  /// Returns a reference to the stream which wraps data
88  IOutputStream& getOutputStream() const { return *_outputStream; }
89 
90  /**
91  * @brief Returns if the stream has the ability to switch to a generator.
92  */
93  bool canSwitchToGenerator();
94 
95  /**
96  * @brief Set if the stream needs to switch to a generator when ended
97  * @note Throws a runtime_error exception if the stream cannot switch to a generator
98  * @see canSwitchToGenerator
99  */
100  void needToSwitchToGenerator(const bool needToSwitch = true);
101 
102  /**
103  * @note Throws a runtime_error exception if it's a positive offset and the stream cannot switch to a generator
104  * @see needToSwitchToGenerator
105  */
106  void setOffset(const float offset);
107 
108  //@{
109  // Get the current process case.
111  {
114  eProcessCaseGenerator
115  };
116  EProcessCase getProcessCase() const;
117  //@}
118 
119 private:
120  bool processRewrap();
121  bool processTranscode(const int subStreamIndex = -1); ///< By default transcode all channels
122 
123 private:
124  IInputStream* _inputStream; ///< Input stream to read next packet (has link, no ownership)
125  IOutputStream* _outputStream; ///< Output stream to wrap next packet (has link, no ownership)
126 
127  Frame* _sourceBuffer; ///< Has ownership
128  Frame* _frameBuffer; ///< Has ownership
129 
130  IDecoder* _inputDecoder; ///< Decoder of packets read from _inputStream (has ownership)
131  IDecoder* _generator; ///< Generator of audio or video packets (has ownership)
132  IDecoder* _currentDecoder; ///< Link to _inputDecoder or _generator
133  IEncoder* _outputEncoder; ///< Encoder of packets which will be wrapped by _outputStream (has ownership)
134 
135  ITransform* _transform; ///< Video or audio transform (has ownership)
136 
137  FilterGraph* _filterGraph; ///< Filter graph (has ownership)
138 
139  int _subStreamIndex; ///< Index of channel that is processed from the input stream (<0 if no demultiplexing).
140 
141  float _offset; ///< Offset, in seconds, at the beginning of the StreamTranscoder.
142 
143  bool _needToSwitchToGenerator; ///< Set if need to switch to a generator during the process (because, of other streams
144  /// duration, or an offset)
145 };
146 }
147 
148 #endif
IEncoder * getEncoder() const
Returns a pointer to the encoder.
IOutputfile is the interface to wrap and write medias. It can be overloaded to integrate custom wrapp...
Definition: IOutputFile.hpp:22
IDecoder * _inputDecoder
Decoder of packets read from _inputStream (has ownership)
ITransform * getTransform() const
Returns a pointer to the object which transforms the decoded data.
IInputStream * getInputStream() const
Returns a pointer to the stream which unwraps data.
Frame * _sourceBuffer
Has ownership.
FilterGraph * getFilterGraph() const
Returns a pointer to the object which manage filtering.
IDecoder * _generator
Generator of audio or video packets (has ownership)
std::map< std::string, std::string > Profile
IEncoder * _outputEncoder
Encoder of packets which will be wrapped by _outputStream (has ownership)
int _subStreamIndex
Index of channel that is processed from the input stream (<0 if no demultiplexing).
IDecoder * _currentDecoder
Link to _inputDecoder or _generator.
Frame * _frameBuffer
Has ownership.
IOutputStream * _outputStream
Output stream to wrap next packet (has link, no ownership)
FilterGraph * _filterGraph
Filter graph (has ownership)
This class describes decoded (raw) audio or video data.
Definition: Frame.hpp:16
Manager of filters.
Definition: FilterGraph.hpp:21
IInputStream * _inputStream
Input stream to read next packet (has link, no ownership)
float _offset
Offset, in seconds, at the beginning of the StreamTranscoder.
IOutputStream & getOutputStream() const
Returns a reference to the stream which wraps data.
IDecoder * getCurrentDecoder() const
Returns a pointer to the current decoder (from input file or from generator)
ITransform * _transform
Video or audio transform (has ownership)