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

Public Member Functions

virtual int addAudioSamples (IAudioSamples *samples)
 Adds audio samples to this filter. More...
 
virtual int addVideoPicture (IVideoPicture *picture)
 Adds picture to this filter. More...
 
- 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...
 
virtual void setReady ()
 

Static Public Member Functions

static BufferSourcemake (AVFilterGraph *graph, IAudioSamples::Format format, int channels, int sample_rate, IRational *time_base, IAudioSamples::ChannelLayout channel_layout)
 
static BufferSourcemake (AVFilterGraph *graph, IPixelFormat::Type format, int width, int height, IRational *frame_rate, IRational *time_base)
 
static BufferSourcemake (AVFilterGraph *graph, IVideoPicture *picture, IRational *frame_rate)
 
- 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 44 of file BufferSource.h.

Member Function Documentation

◆ addAudioSamples()

int com::avpkit::core::BufferSource::addAudioSamples ( IAudioSamples samples)
virtual

Adds audio samples to this filter.

Parameters
samplesthe audio samples to add
Returns
0 on success or <0 if an error occurs

Implements com::avpkit::core::IBufferSource.

Definition at line 38 of file BufferSource.cpp.

38  {
39  int retval = -1;
40  if (!mFilterContext || !ready) {
41  VS_LOG_ERROR("Try to add samples to an unitialized abuffer");
42  return retval;
43  }
44  if (samples) {
45  AudioSamples* inSamples = static_cast<AudioSamples*> (samples);
46  AVFrame* frame = av_frame_alloc();
47  if (frame) {
48  frame->nb_samples = inSamples->getNumSamples();
49  frame->sample_rate = inSamples->getSampleRate();
50  frame->format = inSamples->getFormat();
51  frame->channels = inSamples->getChannels();
52  frame->channel_layout = (uint64_t) inSamples->getChannelLayout();
53  IRational* timeBase = inSamples->getTimeBase();
54  frame->pts = mTimeBase->rescale(inSamples->getPts(), timeBase);
55  VS_REF_RELEASE(timeBase);
56  int data_size = av_samples_get_buffer_size(&frame->linesize[0],
57  frame->channels,
58  frame->nb_samples,
59  (AVSampleFormat) frame->format,
60  0);
61  if (data_size >= 0) {
62  retval = avcodec_fill_audio_frame(frame,
63  frame->channels,
64  (AVSampleFormat) frame->format,
65  (const uint8_t*) inSamples->getRawSamples(0),
66  data_size,
67  0);
68  retval = av_buffersrc_write_frame(mFilterContext, frame);
69  } else {
70  av_frame_free(&frame);
71  }
72  if (retval < 0) {
73  av_frame_free(&frame);
74  }
75  av_frame_free(&frame);
76  }
77  } else {
78  retval = av_buffersrc_add_frame_flags(mFilterContext, NULL, AV_BUFFERSRC_FLAG_PUSH);
79  }
80 
81 
82  return retval;
83  }

References com::avpkit::core::AudioSamples::getChannels(), com::avpkit::core::AudioSamples::getFormat(), com::avpkit::core::AudioSamples::getNumSamples(), com::avpkit::core::AudioSamples::getPts(), com::avpkit::core::AudioSamples::getSampleRate(), and com::avpkit::core::AudioSamples::getTimeBase().

◆ addVideoPicture()

int com::avpkit::core::BufferSource::addVideoPicture ( IVideoPicture picture)
virtual

Adds picture to this filter.

Parameters
picturethe picture to add
Returns
0 on success or <0 if an error occurs

Implements com::avpkit::core::IBufferSource.

Definition at line 85 of file BufferSource.cpp.

85  {
86  int retval = -1;
87  if (!mFilterContext || !ready) {
88  VS_LOG_ERROR("Try to add picture to an unitialized buffer");
89  return retval;
90  }
91  if (picture) {
92  AVFrame* frame = av_frame_alloc();
93  if (frame) {
94  VideoPicture* inPicture = static_cast<VideoPicture*> (picture);
95  IRational* timeBase = inPicture->getTimeBase();
96  int64_t pts = mTimeBase->rescale(inPicture->getPts(), timeBase);
97  VS_REF_RELEASE(timeBase);
98  av_frame_ref(frame, inPicture->getAVFrame());
99  frame->pts = pts;
100  retval = av_buffersrc_add_frame(mFilterContext, frame);
101  av_frame_free(&frame);
102  }
103  } else {
104  retval = av_buffersrc_add_frame_flags(mFilterContext, NULL, AV_BUFFERSRC_FLAG_PUSH);
105  }
106 
107  return retval;
108  }

References com::avpkit::core::VideoPicture::getAVFrame(), com::avpkit::core::VideoPicture::getPts(), and com::avpkit::core::VideoPicture::getTimeBase().


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