avcpp  2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
buffersink.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "avconfig.h"
4 
5 #if AVCPP_HAS_AVFILTER
6 
7 #include <stdint.h>
8 #include <memory>
9 
10 #include "ffmpeg.h"
11 #include "rational.h"
12 #include "filtercontext.h"
13 #include "filter.h"
14 #include "averror.h"
15 #include "frame.h"
16 
17 namespace av {
18 
19 class BufferSinkFilterContext
20 {
21  // To protect access
22  enum {
23  ReqUninited,
24  ReqGetFrame,
25  ReqGetSamples
26  };
27 
28 public:
29  BufferSinkFilterContext() = default;
30  explicit BufferSinkFilterContext(const FilterContext& ctx, OptionalErrorCode ec = throws());
31 
32  void assign(const FilterContext &ctx, OptionalErrorCode ec = throws());
33  BufferSinkFilterContext& operator=(const FilterContext &ctx);
34 
35 
36  bool getVideoFrame(VideoFrame &frame, int flags, OptionalErrorCode ec = throws());
37  bool getVideoFrame(VideoFrame &frame, OptionalErrorCode ec = throws());
38 
39  bool getAudioFrame(AudioSamples &samples, int flags, OptionalErrorCode ec = throws());
40  bool getAudioFrame(AudioSamples &samples, OptionalErrorCode ec = throws());
41  bool getAudioSamples(AudioSamples &samples, size_t samplesCount, OptionalErrorCode ec = throws());
42 
43  void setFrameSize(unsigned size, OptionalErrorCode ec = throws());
44  Rational frameRate(OptionalErrorCode ec = throws());
45 
46  static FilterMediaType checkFilter(const Filter& filter) noexcept;
47 
48 private:
49  // AVERROR_EOF and AVERROR(EAGAIN) never thrown, but can be returned via error_code
50  // if ec == throws(), false returns silently
51  bool getFrame(AVFrame *frame, int flags, OptionalErrorCode ec);
52  bool getSamples(AVFrame *frame, int nbSamples, OptionalErrorCode ec);
53 
54 private:
55  FilterContext m_sink;
56  FilterMediaType m_type = FilterMediaType::Unknown;
57  int m_req = ReqUninited;
58 };
59 
60 
61 } // namespace av
62 
63 #endif
Definition: audioresampler.cpp:8