AVPKit
BufferSink.h
1 /*******************************************************************************
2  * Copyright (c) 2024, 2026, Olivier Ayache. All rights reserved.
3  *
4  * This file is part of AVPKit.
5  *
6  * AVPKit is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * AVPKit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with AVPKit. If not, see <http://www.gnu.org/licenses/>.
18  *******************************************************************************/
19 
20 #ifndef BUFFERSINK_H
21 #define BUFFERSINK_H
22 
23 #include <com/avpkit/core/IAudioSamples.h>
24 #include <com/avpkit/core/IVideoPicture.h>
25 #include <com/avpkit/core/IRational.h>
26 #include <com/avpkit/core/IBufferSink.h>
27 #include <com/avpkit/core/MediaFilter.h>
28 #include <com/avpkit/core/MediaFilter.h>
29 #include <com/avpkit/ferry/RefPointer.h>
30 
31 extern "C" {
32 #include "libavfilter/avfilter.h"
33 #include "libavfilter/buffersink.h"
34 #include "libavutil/opt.h"
35 }
36 
37 namespace com {
38  namespace avpkit {
39  namespace core {
40 
41  class BufferSink : public IBufferSink, public MediaFilter {
42  VS_JNIUTILS_REFCOUNTED_OBJECT(BufferSink)
43  public:
44  static BufferSink* make(AVFilterGraph*, IAudioSamples::ChannelLayout channel_layout);
45  static BufferSink* make(AVFilterGraph*, IPixelFormat::Type pixel_type);
46  virtual int getSampleRate();
47  virtual int getChannels();
48  virtual int getWidth();
49  virtual int getHeight();
50  virtual IRational* getFrameRate();
51  virtual IRational* getTimeBase();
52  virtual void setNumSamples(int frameSize);
53  virtual int fillAudioSamples(IAudioSamples* samples);
54  virtual int fillVideoPicture(IVideoPicture* picture);
55  virtual void setReady();
56 
57  protected:
58  BufferSink();
59  virtual ~BufferSink();
60  private:
61  AVFilterGraph* mFilterGraph;
62  int mSampleRate;
63  const AVFilter* mSinkFilter;
64  AVFilterContext* mSinkFilterContext;
66  };
67 
68  }
69  }
70 }
71 
72 #endif /* BUFFERSINK_H */
73 
virtual int getChannels()
Returns the channel number of output filtered samples.
Definition: BufferSink.cpp:41
virtual IRational * getTimeBase()
Returns the frame rate output filtered picture.
Definition: BufferSink.cpp:62
virtual int getWidth()
Returns the width of output filtered picture.
Definition: BufferSink.cpp:49
virtual void setNumSamples(int frameSize)
Sets the number of samples for each output filtered samples.
Definition: BufferSink.cpp:67
virtual IRational * getFrameRate()
Returns the frame rate output filtered picture.
Definition: BufferSink.cpp:57
virtual int getHeight()
Returns the height of output filtered picture.
Definition: BufferSink.cpp:53
virtual int fillVideoPicture(IVideoPicture *picture)
Fills this video picture with filtered data.
Definition: BufferSink.cpp:113
virtual int getSampleRate()
Returns the sample rate of output filtered samples.
Definition: BufferSink.cpp:45
virtual int fillAudioSamples(IAudioSamples *samples)
Fills this audio samples with filtered data.
Definition: BufferSink.cpp:76
A set of raw (decoded) samples, plus a timestamp for when to play those samples relative to other ite...
Definition: IAudioSamples.h:38
This class wraps represents a Rational number for the AVPKit.
Definition: IRational.h:43
Represents one raw (undecoded) picture in a video stream, plus a timestamp for when to display that v...
Definition: IVideoPicture.h:40
This class is only useful from C++.
Definition: RefPointer.h:47
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...