AVPKit
com::avpkit::core::BufferSink Class Reference
Inheritance diagram for com::avpkit::core::BufferSink:
Collaboration diagram for com::avpkit::core::BufferSink:

Public Member Functions

virtual int getSampleRate ()
 Returns the sample rate of output filtered samples. More...
 
virtual int getChannels ()
 Returns the channel number of output filtered samples. More...
 
virtual int getWidth ()
 Returns the width of output filtered picture. More...
 
virtual int getHeight ()
 Returns the height of output filtered picture. More...
 
virtual IRationalgetFrameRate ()
 Returns the frame rate output filtered picture. More...
 
virtual IRationalgetTimeBase ()
 Returns the frame rate output filtered picture. More...
 
virtual void setNumSamples (int frameSize)
 Sets the number of samples for each output filtered samples. More...
 
virtual int fillAudioSamples (IAudioSamples *samples)
 Fills this audio samples with filtered data. More...
 
virtual int fillVideoPicture (IVideoPicture *picture)
 Fills this video picture with filtered data. More...
 
virtual void setReady ()
 
- Public Member Functions inherited from com::avpkit::ferry::RefCounted
virtual int32_t acquire ()
 Internal Only. More...
 
virtual int32_t release ()
 Internal Only. More...
 
virtual RefCountedcopyReference ()
 Create a new Java object that refers to the same native object. More...
 
virtual int32_t getCurrentRefCount ()
 Return the current reference count on this object. More...
 
void setJavaAllocator (void *allocator)
 This method is public but not part of the standard API. More...
 
void * getJavaAllocator ()
 This method is public but not part of the standard API. More...
 
- Public Member Functions inherited from com::avpkit::core::MediaFilter
virtual int setIntProperty (const char *name, int value)
 Sets an integer parameter for this filter. More...
 
virtual int setDoubleProperty (const char *name, double value)
 Sets a double parameter for this filter. More...
 
virtual int setProperty (const char *name, const char *value)
 Sets a string parameter for this filter. More...
 
virtual int setRationalProperty (const char *name, IRational *value)
 Sets a rational parameter for this filter. More...
 
virtual int initFilter ()
 Initialize filter. More...
 
virtual int addFilter (IMediaFilter *filter)
 Add a filter as an output of this filter. More...
 
virtual int addSink (IBufferSink *filterSink)
 Add a filter as an output of this filter. More...
 

Static Public Member Functions

static BufferSinkmake (AVFilterGraph *, IAudioSamples::ChannelLayout channel_layout)
 
static BufferSinkmake (AVFilterGraph *, IPixelFormat::Type pixel_type)
 
- Static Public Member Functions inherited from com::avpkit::core::MediaFilter
static MediaFiltermake (AVFilterGraph *graph, const char *name)
 

Additional Inherited Members

- Protected Member Functions inherited from com::avpkit::ferry::RefCounted
virtual void destroy ()
 This method is called by RefCounted objects when their Ref Count reaches zero and they are about to be destroyed.
 
- Protected Member Functions inherited from com::avpkit::core::MediaFilter
int getAvailableInput ()
 
int getAvailableOutput ()
 
AVFilterContext * getAVFilter ()
 
- Protected Attributes inherited from com::avpkit::ferry::RefCounted
AtomicIntegermRefCount
 This is the internal reference count, represented as an AtomicInteger to make sure it is thread safe.
 
void * mAllocator
 Not part of public API.
 
- Protected Attributes inherited from com::avpkit::core::MediaFilter
const AVFilter * mFilter
 
AVFilterContext * mFilterContext
 
bool ready
 

Detailed Description

Definition at line 41 of file BufferSink.h.

Member Function Documentation

◆ fillAudioSamples()

int com::avpkit::core::BufferSink::fillAudioSamples ( IAudioSamples samples)
virtual

Fills this audio samples with filtered data.

Parameters
samplesthe audio samples filled with filtered data
Returns
0 on success or <0 if an error occurs

Implements com::avpkit::core::IBufferSink.

Definition at line 76 of file BufferSink.cpp.

76  {
77  int retval = -1;
78  if (!ready) {
79  return -1;
80  }
81  if (samples) {
82  AudioSamples* outSamples = static_cast<AudioSamples*> (samples);
83  if (outSamples) {
84  outSamples->setComplete(false, 0, outSamples->getSampleRate(), outSamples->getChannels(), outSamples->getChannelLayout(),
86  AVFrame* frame = av_frame_alloc();
87  if (frame) {
88  retval = av_buffersink_get_frame(mSinkFilterContext, frame);
89  if (retval == AVERROR(EAGAIN)) {
90  //VS_LOG_WARN("No data available retry later");
91  } else if (retval >= 0) {
92  int buffer_size;
93  buffer_size = av_samples_get_buffer_size(NULL, frame->channels, frame->nb_samples, (AVSampleFormat) frame->format, 0);
94  outSamples->ensureCapacity(buffer_size);
95  memcpy(outSamples->getRawSamples(0), frame->extended_data[0], buffer_size);
96  IRational* timeBase = outSamples->getTimeBase();
97  outSamples->setComplete(true,
98  frame->nb_samples,
99  frame->sample_rate,
100  frame->channels,
101  (IAudioSamples::ChannelLayout)frame->channel_layout,
103  timeBase->rescale(frame->pts, mTimeBase.value()));
104  VS_REF_RELEASE(timeBase);
105  }
106  av_frame_free(&frame);
107  }
108  }
109  }
110  return retval;
111  }

References com::avpkit::core::AudioSamples::ensureCapacity(), com::avpkit::core::IAudioSamples::FMT_S16, com::avpkit::core::AudioSamples::getChannels(), com::avpkit::core::AudioSamples::getSampleRate(), com::avpkit::core::AudioSamples::getTimeBase(), com::avpkit::core::IRational::rescale(), and com::avpkit::core::AudioSamples::setComplete().

◆ fillVideoPicture()

int com::avpkit::core::BufferSink::fillVideoPicture ( IVideoPicture picture)
virtual

Fills this video picture with filtered data.

Parameters
samplesthe video picture filled with filtered data
Returns
0 on success or <0 if an error occurs

Implements com::avpkit::core::IBufferSink.

Definition at line 113 of file BufferSink.cpp.

113  {
114  int retval = -1;
115  if (!ready) {
116  return -1;
117  }
118  if (picture) {
119  VideoPicture* outPicture = static_cast<VideoPicture*> (picture);
120 
121  if (picture) {
122  outPicture->setComplete(false, IPixelFormat::NONE, outPicture->getWidth(), outPicture->getHeight(), 0);
123  AVFrame* frame = av_frame_alloc();
124  if (frame) {
125  retval = av_buffersink_get_frame(mSinkFilterContext, frame);
126  if (retval == AVERROR(EAGAIN)) {
127  //VS_LOG_WARN("No data available retry later");
128  } else if (retval >= 0) {
129  outPicture->copyAVFrame(frame, (IPixelFormat::Type)frame->format, frame->width, frame->height);
130  IRational* timeBase = outPicture->getTimeBase();
131  outPicture->setComplete(true,
132  (IPixelFormat::Type)frame->format,
133  frame->width,
134  frame->height,
135  timeBase->rescale(frame->pts, mTimeBase.value()));
136  VS_REF_RELEASE(timeBase);
137  }
138  av_frame_free(&frame);
139  }
140  }
141  }
142  return retval;
143  }

References com::avpkit::core::VideoPicture::copyAVFrame(), com::avpkit::core::VideoPicture::getHeight(), com::avpkit::core::VideoPicture::getTimeBase(), com::avpkit::core::VideoPicture::getWidth(), com::avpkit::core::IRational::rescale(), and com::avpkit::core::VideoPicture::setComplete().

◆ getChannels()

int com::avpkit::core::BufferSink::getChannels ( )
virtual

Returns the channel number of output filtered samples.

Returns
the channel number

Implements com::avpkit::core::IBufferSink.

Definition at line 41 of file BufferSink.cpp.

41  {
42  return av_buffersink_get_channels(mSinkFilterContext);
43  }

◆ getFrameRate()

IRational * com::avpkit::core::BufferSink::getFrameRate ( )
virtual

Returns the frame rate output filtered picture.

Returns
the frame rate

Implements com::avpkit::core::IBufferSink.

Definition at line 57 of file BufferSink.cpp.

57  {
58  AVRational frameRate = av_buffersink_get_frame_rate(mSinkFilterContext);
59  return IRational::make(frameRate.num, frameRate.den);
60  }
static IRational * make()
Get a new rational that will be set to 0/0.
Definition: IRational.cpp:79

References com::avpkit::core::IRational::make().

◆ getHeight()

int com::avpkit::core::BufferSink::getHeight ( )
virtual

Returns the height of output filtered picture.

Returns
the height

Implements com::avpkit::core::IBufferSink.

Definition at line 53 of file BufferSink.cpp.

53  {
54  return av_buffersink_get_h(mSinkFilterContext);
55  }

◆ getSampleRate()

int com::avpkit::core::BufferSink::getSampleRate ( )
virtual

Returns the sample rate of output filtered samples.

Returns
the sample rate

Implements com::avpkit::core::IBufferSink.

Definition at line 45 of file BufferSink.cpp.

45  {
46  return av_buffersink_get_sample_rate(mSinkFilterContext);
47  }

◆ getTimeBase()

IRational * com::avpkit::core::BufferSink::getTimeBase ( )
virtual

Returns the frame rate output filtered picture.

Returns
the frame rate

Implements com::avpkit::core::IBufferSink.

Definition at line 62 of file BufferSink.cpp.

62  {
63  AVRational frameRate = av_buffersink_get_time_base(mSinkFilterContext);
64  return IRational::make(frameRate.num, frameRate.den);
65  }

References com::avpkit::core::IRational::make().

◆ getWidth()

int com::avpkit::core::BufferSink::getWidth ( )
virtual

Returns the width of output filtered picture.

Returns
the width

Implements com::avpkit::core::IBufferSink.

Definition at line 49 of file BufferSink.cpp.

49  {
50  return av_buffersink_get_w(mSinkFilterContext);
51  }

◆ setNumSamples()

void com::avpkit::core::BufferSink::setNumSamples ( int  frameSize)
virtual

Sets the number of samples for each output filtered samples.

The last buffer will be padded with 0.

Parameters
frameSizethe number of samples of output

Implements com::avpkit::core::IBufferSink.

Definition at line 67 of file BufferSink.cpp.

67  {
68  av_buffersink_set_frame_size(mSinkFilterContext, frameSize);
69  }

The documentation for this class was generated from the following files: