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

Public Member Functions

virtual int64_t getTimeStamp ()
 Get the time stamp of this object in getTimeBase() units. More...
 
virtual void setTimeStamp (int64_t aTimeStamp)
 Set the time stamp for this object in getTimeBase() units. More...
 
virtual IRationalgetTimeBase ()
 Get the time base that time stamps of this object are represented in. More...
 
virtual void setTimeBase (IRational *aBase)
 Set the time base that time stamps of this object are represented in. More...
 
virtual int32_t getSize ()
 Get the size in bytes of the raw data available for this object. More...
 
virtual bool isKey ()
 Is this object a key object? i.e. More...
 
virtual bool isComplete ()
 Returns whether or not we think this buffer has been filled with data. More...
 
virtual int32_t getSampleRate ()
 Find the sample rate of the samples in this audio buffer. More...
 
virtual int32_t getChannels ()
 Return the number of channels of the samples in this buffer. More...
 
virtual IAudioSamples::ChannelLayout getChannelLayout ()
 
virtual Format getFormat ()
 Find the Format of the samples in this buffer. More...
 
virtual int32_t getSampleBitDepth ()
 Find out the bit-depth of the samples in this buffer. More...
 
virtual int32_t getNumSamples ()
 Get the number of samples in this video. More...
 
virtual int32_t getMaxBufferSize ()
 
virtual int32_t getSampleSize ()
 
virtual int32_t getMaxSamples ()
 
virtual com::avpkit::ferry::IBuffergetData ()
 Get any underlying raw data available for this object. More...
 
virtual int64_t getPts ()
 What is the Presentation Time Stamp of this set of audio samples. More...
 
virtual void setPts (int64_t aValue)
 Set the Presentation Time Stamp for this set of samples. More...
 
virtual int64_t getNextPts ()
 What would be the next Presentation Time Stamp after all the samples in this buffer were played? More...
 
virtual int32_t setSample (int32_t sampleIndex, int32_t channel, Format format, int32_t sample)
 Sets the sample at the given index and channel to the sample. More...
 
virtual int32_t getSample (int32_t sampleIndex, int32_t channel, Format format)
 Get the sample at the given sampleIndex and channel, and return it in the asked for format. More...
 
virtual void setData (com::avpkit::ferry::IBuffer *buffer)
 Sets the underlying buffer used by this object. More...
 
virtual void setComplete (bool complete, int32_t numSamples, int32_t sampleRate, int32_t channels, Format sampleFmt, int64_t pts)
 Call this if you modify the samples and are now done. More...
 
virtual void setComplete (bool complete, int32_t numSamples, int32_t sampleRate, int32_t channels, ChannelLayout channelLayout, Format format, int64_t pts)
 
virtual short * getRawSamples (uint32_t startingSample)
 
virtual int32_t ensureCapacity (int32_t capacityInBytes)
 Called by decoder before decoding to ensure sufficient space.
 
- 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...
 

Static Public Member Functions

static AudioSamplesmake (int32_t numSamples, int32_t numChannels)
 
static AudioSamplesmake (int32_t numSamples, int32_t numChannels, IAudioSamples::Format)
 
static AudioSamplesmake (com::avpkit::ferry::IBuffer *buffer, int32_t channels, IAudioSamples::Format format)
 
- Static Public Member Functions inherited from com::avpkit::core::IAudioSamples
static int32_t findSampleBitDepth (Format format)
 A convenience method that returns the # of bits in a given format. More...
 
static IAudioSamplesmake (int32_t numSamples, int32_t numChannels)
 Get a new audio samples buffer. More...
 
static int64_t samplesToDefaultPts (int64_t samples, int sampleRate)
 Converts a number of samples at a given sampleRate into Microseconds. More...
 
static int64_t defaultPtsToSamples (int64_t duration, int sampleRate)
 Converts a duration in microseconds into a number of samples, assuming a given sampleRate. More...
 
static IAudioSamplesmake (com::avpkit::ferry::IBuffer *buffer, int channels, IAudioSamples::Format format)
 Creates an IAudioSamples object by wrapping an object. More...
 
static IAudioSamplesmake (int32_t numSamples, int32_t numChannels, IAudioSamples::Format format)
 Get a new audio samples buffer. More...
 

Additional Inherited Members

- Public Types inherited from com::avpkit::core::IAudioSamples
enum  Format {
  FMT_NONE = -1 , FMT_U8 , FMT_S16 , FMT_S32 ,
  FMT_FLT , FMT_DBL , FMT_U8P , FMT_S16P ,
  FMT_S32P , FMT_FLTP , FMT_DBLP
}
 The format we use to represent audio. More...
 
enum class  ChannelLayout : uint64_t {
  CH_NONE = 0 , CH_FRONT_LEFT = 0x00000001 , CH_FRONT_RIGHT = 0x00000002 , CH_FRONT_CENTER = 0x00000004 ,
  CH_LOW_FREQUENCY = 0x00000008 , CH_BACK_LEFT = 0x00000010 , CH_BACK_RIGHT = 0x00000020 , CH_FRONT_LEFT_OF_CENTER = 0x00000040 ,
  CH_FRONT_RIGHT_OF_CENTER = 0x00000080 , CH_BACK_CENTER = 0x00000100 , CH_SIDE_LEFT = 0x00000200 , CH_SIDE_RIGHT = 0x00000400 ,
  CH_TOP_CENTER = 0x00000800 , CH_TOP_FRONT_LEFT = 0x00001000 , CH_TOP_FRONT_CENTER = 0x00002000 , CH_TOP_FRONT_RIGHT = 0x00004000 ,
  CH_TOP_BACK_LEFT = 0x00008000 , CH_TOP_BACK_CENTER = 0x00010000 , CH_TOP_BACK_RIGHT = 0x00020000 , CH_STEREO_LEFT = 0x20000000 ,
  CH_STEREO_RIGHT = 0x40000000 , CH_WIDE_LEFT = 0x0000000080000000ULL , CH_WIDE_RIGHT = 0x0000000100000000ULL , CH_SURROUND_DIRECT_LEFT = 0x0000000200000000ULL ,
  CH_SURROUND_DIRECT_RIGHT = 0x0000000400000000ULL , CH_LOW_FREQUENCY_2 = 0x0000000800000000ULL , CH_LAYOUT_NATIVE = 0x8000000000000000ULL , ,
  channel_mask_c , CH_LAYOUT_MONO = (CH_FRONT_CENTER) , CH_LAYOUT_STEREO = (CH_FRONT_LEFT|CH_FRONT_RIGHT) , CH_LAYOUT_2POINT1 = (CH_LAYOUT_STEREO|CH_LOW_FREQUENCY) ,
  CH_LAYOUT_2_1 = (CH_LAYOUT_STEREO|CH_BACK_CENTER) , CH_LAYOUT_SURROUND = (CH_LAYOUT_STEREO|CH_FRONT_CENTER) , CH_LAYOUT_3POINT1 = (CH_LAYOUT_SURROUND|CH_LOW_FREQUENCY) , CH_LAYOUT_4POINT0 = (CH_LAYOUT_SURROUND|CH_BACK_CENTER) ,
  CH_LAYOUT_4POINT1 = (CH_LAYOUT_4POINT0|CH_LOW_FREQUENCY) , CH_LAYOUT_2_2 = (CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT) , CH_LAYOUT_QUAD = (CH_LAYOUT_STEREO|CH_BACK_LEFT|CH_BACK_RIGHT) , CH_LAYOUT_5POINT0 = (CH_LAYOUT_SURROUND|CH_SIDE_LEFT|CH_SIDE_RIGHT) ,
  CH_LAYOUT_5POINT1 = (CH_LAYOUT_5POINT0|CH_LOW_FREQUENCY) , CH_LAYOUT_5POINT0_BACK = (CH_LAYOUT_SURROUND|CH_BACK_LEFT|CH_BACK_RIGHT) , CH_LAYOUT_5POINT1_BACK = (CH_LAYOUT_5POINT0_BACK|CH_LOW_FREQUENCY) , CH_LAYOUT_6POINT0 = (CH_LAYOUT_5POINT0|CH_BACK_CENTER) ,
  CH_LAYOUT_6POINT0_FRONT = (CH_LAYOUT_2_2|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER) , CH_LAYOUT_HEXAGONAL = (CH_LAYOUT_5POINT0_BACK|CH_BACK_CENTER) , CH_LAYOUT_6POINT1 = (CH_LAYOUT_5POINT1|CH_BACK_CENTER) , CH_LAYOUT_6POINT1_BACK = (CH_LAYOUT_5POINT1_BACK|CH_BACK_CENTER) ,
  CH_LAYOUT_6POINT1_FRONT = (CH_LAYOUT_6POINT0_FRONT|CH_LOW_FREQUENCY) , CH_LAYOUT_7POINT0 = (CH_LAYOUT_5POINT0|CH_BACK_LEFT|CH_BACK_RIGHT) , CH_LAYOUT_7POINT0_FRONT = (CH_LAYOUT_5POINT0|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER) , CH_LAYOUT_7POINT1 = (CH_LAYOUT_5POINT1|CH_BACK_LEFT|CH_BACK_RIGHT) ,
  CH_LAYOUT_7POINT1_WIDE = (CH_LAYOUT_5POINT1|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER) , CH_LAYOUT_7POINT1_WIDE_BACK = (CH_LAYOUT_5POINT1_BACK|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER) , CH_LAYOUT_OCTAGONAL = (CH_LAYOUT_5POINT0|CH_BACK_LEFT|CH_BACK_CENTER|CH_BACK_RIGHT) , CH_LAYOUT_HEXADECAGONAL = (CH_LAYOUT_OCTAGONAL|CH_WIDE_LEFT|CH_WIDE_RIGHT|CH_TOP_BACK_LEFT|CH_TOP_BACK_RIGHT|CH_TOP_BACK_CENTER|CH_TOP_FRONT_CENTER|CH_TOP_FRONT_LEFT|CH_TOP_FRONT_RIGHT) ,
  CH_LAYOUT_STEREO_DOWNMIX = (CH_STEREO_LEFT|CH_STEREO_RIGHT)
}
 
typedef enum com::avpkit::core::IAudioSamples::Format Format
 The format we use to represent audio. More...
 
- 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 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.
 

Detailed Description

Definition at line 32 of file AudioSamples.h.

Member Function Documentation

◆ getChannels()

int32_t com::avpkit::core::AudioSamples::getChannels ( )
virtual

Return the number of channels of the samples in this buffer.

For example, 1 is mono, 2 is stereo.

Returns
The number of channels.

Implements com::avpkit::core::IAudioSamples.

Definition at line 215 of file AudioSamples.cpp.

216  {
217  return mChannels;
218  }

Referenced by com::avpkit::core::BufferSource::addAudioSamples(), com::avpkit::core::StreamCoder::encodeAudio(), com::avpkit::core::BufferSink::fillAudioSamples(), and com::avpkit::core::AudioResampler::resample().

◆ getData()

com::avpkit::ferry::IBuffer * com::avpkit::core::AudioSamples::getData ( )
virtual

Get any underlying raw data available for this object.

Returns
The raw data, or null if not accessible.

Implements com::avpkit::core::IMediaData.

Definition at line 257 of file AudioSamples.cpp.

258  {
259  allocInternalSamples();
260  IBuffer* retval = mSamples.get();
261  if (!retval)
262  throw std::bad_alloc();
263  return retval;
264  }
Allows Java code to get data from a native buffers, and optionally modify native memory directly.
Definition: IBuffer.h:54
T * get()
Call RefCounted::acquire() on the managed pointer and return it.
Definition: RefPointer.h:206

◆ getFormat()

IAudioSamples::Format com::avpkit::core::AudioSamples::getFormat ( )
virtual

Find the Format of the samples in this buffer.

Right now only FMT_S16 is supported.

Returns
The format of the samples.

Implements com::avpkit::core::IAudioSamples.

Definition at line 203 of file AudioSamples.cpp.

204  {
205  return mSampleFmt;
206  }

Referenced by com::avpkit::core::BufferSource::addAudioSamples(), and com::avpkit::core::AudioResampler::resample().

◆ getMaxBufferSize()

int32_t com::avpkit::core::AudioSamples::getMaxBufferSize ( )
virtual
Returns
Maximum number of bytes that can be put in this buffer. To get the number of samples you can put in this IAudioSamples instance, do the following num_samples = getMaxBufferSize() / (getSampleSize())

Implements com::avpkit::core::IAudioSamples.

Definition at line 234 of file AudioSamples.cpp.

235  {
236  allocInternalSamples();
237  return mSamples->getBufferSize()-VS_AUDIOSAMPLES_BUFFER_PADDING;
238  }
virtual int32_t getBufferSize()=0
Get the current maximum number of bytes that can be safely placed in this buffer.

Referenced by com::avpkit::core::StreamCoder::decodeAudio(), and com::avpkit::core::AudioResampler::resample().

◆ getMaxSamples()

int32_t com::avpkit::core::AudioSamples::getMaxSamples ( )
virtual
Returns
Maximum number of samples this buffer can hold.

Implements com::avpkit::core::IAudioSamples.

Definition at line 267 of file AudioSamples.cpp.

268  {
269  return getMaxBufferSize() / getSampleSize();
270  }
virtual int32_t getMaxBufferSize()

◆ getNextPts()

int64_t com::avpkit::core::AudioSamples::getNextPts ( )
virtual

What would be the next Presentation Time Stamp after all the samples in this buffer were played?

Returns
the next presentation time stamp (pts)

Implements com::avpkit::core::IAudioSamples.

Definition at line 329 of file AudioSamples.cpp.

330  {
331  int64_t retval = Global::NO_PTS;
332  if (mPts != Global::NO_PTS)
333  retval = mPts + IAudioSamples::samplesToDefaultPts(this->getNumSamples(), this->getSampleRate());
334 
335  return retval;
336  }
virtual int32_t getSampleRate()
Find the sample rate of the samples in this audio buffer.
virtual int32_t getNumSamples()
Get the number of samples in this video.
static const int64_t NO_PTS
A value that means no time stamp is set for a given object.
Definition: Global.h:50
static int64_t samplesToDefaultPts(int64_t samples, int sampleRate)
Converts a number of samples at a given sampleRate into Microseconds.

References com::avpkit::core::Global::NO_PTS, and com::avpkit::core::IAudioSamples::samplesToDefaultPts().

◆ getNumSamples()

int32_t com::avpkit::core::AudioSamples::getNumSamples ( )
virtual

Get the number of samples in this video.

For example, if you have 100 bytes of stereo (2-channel) 16-bit audio in this buffer, there are 25 samples. If you have 100 bytes of mono (1-channel) 16-bit audio in this buffer, you have 50 samples.

Returns
The number of samples.

Implements com::avpkit::core::IAudioSamples.

Definition at line 228 of file AudioSamples.cpp.

229  {
230  return mNumSamples;
231  }

Referenced by com::avpkit::core::BufferSource::addAudioSamples(), com::avpkit::core::StreamCoder::encodeAudio(), getSize(), and com::avpkit::core::AudioResampler::resample().

◆ getPts()

int64_t com::avpkit::core::AudioSamples::getPts ( )
virtual

What is the Presentation Time Stamp of this set of audio samples.

Returns
the presentation time stamp (pts)

Implements com::avpkit::core::IAudioSamples.

Definition at line 317 of file AudioSamples.cpp.

318  {
319  return mPts;
320  }

Referenced by com::avpkit::core::BufferSource::addAudioSamples(), com::avpkit::core::StreamCoder::encodeAudio(), getTimeStamp(), and com::avpkit::core::AudioResampler::resample().

◆ getSample()

int32_t com::avpkit::core::AudioSamples::getSample ( int32_t  sampleIndex,
int32_t  channel,
Format  format 
)
virtual

Get the sample at the given sampleIndex and channel, and return it in the asked for format.

Parameters
sampleIndexThe zero-based index into this set of samples.
channelThe zero-based channel to get the sample from
formatThe format to return in
Returns
The sample if available. If that sample is not available (e.g. because the channel doesn't exist, or the samples have not been setComplete(bool, int32_t, int32_t, int32_t, Format, int64_t)), then this method returns 0. It is up to the caller to ensure the inputs are valid given that 0 is also a valid sample value.

Implements com::avpkit::core::IAudioSamples.

Definition at line 366 of file AudioSamples.cpp.

367  {
368  int32_t retval = 0;
369  try
370  {
371  if (channel < 0 || channel >= mChannels)
372  throw std::invalid_argument("cannot getSample for given channel");
373  if (format != FMT_S16)
374  throw std::invalid_argument("only support format: FMT_S16");
375  if (sampleIndex >= this->getNumSamples())
376  throw std::invalid_argument("sampleIndex out of bounds");
377 
378  short *rawSamples = this->getRawSamples(0);
379  if (!rawSamples)
380  throw std::runtime_error("no samples buffer set in AudioSamples");
381 
382  retval = rawSamples[sampleIndex*mChannels + channel];
383  }
384  catch(std::exception & e)
385  {
386  VS_LOG_DEBUG("Error: %s", e.what());
387  retval = 0;
388  }
389  return retval;
390  }

◆ getSampleBitDepth()

int32_t com::avpkit::core::AudioSamples::getSampleBitDepth ( )
virtual

Find out the bit-depth of the samples in this buffer.

Returns
Number of bits in a raw sample (per channel)

Implements com::avpkit::core::IAudioSamples.

Definition at line 241 of file AudioSamples.cpp.

242  {
243  return IAudioSamples::findSampleBitDepth(mSampleFmt);
244  }
static int32_t findSampleBitDepth(Format format)
A convenience method that returns the # of bits in a given format.

References com::avpkit::core::IAudioSamples::findSampleBitDepth().

Referenced by com::avpkit::core::AudioResampler::resample().

◆ getSampleRate()

int32_t com::avpkit::core::AudioSamples::getSampleRate ( )
virtual

Find the sample rate of the samples in this audio buffer.

Returns
The Sampling Rate of the samples in this buffer (e.g. 22050).

Implements com::avpkit::core::IAudioSamples.

Definition at line 209 of file AudioSamples.cpp.

210  {
211  return mSampleRate;
212  }

Referenced by com::avpkit::core::BufferSource::addAudioSamples(), com::avpkit::core::StreamCoder::encodeAudio(), com::avpkit::core::BufferSink::fillAudioSamples(), and com::avpkit::core::AudioResampler::resample().

◆ getSampleSize()

int32_t com::avpkit::core::AudioSamples::getSampleSize ( )
virtual
Returns
Number of bytes in a single sample of audio (including channels). You can also get this by getSampleBitDepth()*getChannels()/8.

Implements com::avpkit::core::IAudioSamples.

Definition at line 247 of file AudioSamples.cpp.

248  {
249  int32_t bits = getSampleBitDepth();
250  if (bits < 8)
251  bits = 8;
252 
253  return bits/8 * getChannels();
254  }
virtual int32_t getChannels()
Return the number of channels of the samples in this buffer.
virtual int32_t getSampleBitDepth()
Find out the bit-depth of the samples in this buffer.

Referenced by com::avpkit::core::StreamCoder::encodeAudio(), and getSize().

◆ getSize()

virtual int32_t com::avpkit::core::AudioSamples::getSize ( )
inlinevirtual

Get the size in bytes of the raw data available for this object.

Returns
the size in bytes, or -1 if it cannot be computed.

Implements com::avpkit::core::IMediaData.

Definition at line 41 of file AudioSamples.h.

41 { return getNumSamples()*getSampleSize(); }

References getNumSamples(), and getSampleSize().

◆ getTimeBase()

virtual IRational* com::avpkit::core::AudioSamples::getTimeBase ( )
inlinevirtual

Get the time base that time stamps of this object are represented in.

Caller must release the returned value.

Returns
the time base.

Implements com::avpkit::core::IMediaData.

Definition at line 39 of file AudioSamples.h.

39 { return mTimeBase.get(); }

Referenced by com::avpkit::core::BufferSource::addAudioSamples(), and com::avpkit::core::BufferSink::fillAudioSamples().

◆ getTimeStamp()

virtual int64_t com::avpkit::core::AudioSamples::getTimeStamp ( )
inlinevirtual

Get the time stamp of this object in getTimeBase() units.

Returns
the time stamp

Implements com::avpkit::core::IMediaData.

Definition at line 37 of file AudioSamples.h.

37 { return getPts(); }
virtual int64_t getPts()
What is the Presentation Time Stamp of this set of audio samples.

References getPts().

Referenced by com::avpkit::core::StreamCoder::encodeAudio().

◆ isComplete()

bool com::avpkit::core::AudioSamples::isComplete ( )
virtual

Returns whether or not we think this buffer has been filled with data.

Returns
Has setComplete() been called and the buffer populated.

Implements com::avpkit::core::IAudioSamples.

Definition at line 197 of file AudioSamples.cpp.

198  {
199  return mIsComplete;
200  }

Referenced by com::avpkit::core::StreamCoder::encodeAudio(), and com::avpkit::core::AudioResampler::resample().

◆ isKey()

virtual bool com::avpkit::core::AudioSamples::isKey ( )
inlinevirtual

Is this object a key object? i.e.

it can be interpreted without needing any other media objects

Returns
true if it's a key, false if not

Implements com::avpkit::core::IMediaData.

Definition at line 42 of file AudioSamples.h.

42 { return true; }

◆ setComplete()

void com::avpkit::core::AudioSamples::setComplete ( bool  complete,
int32_t  numSamples,
int32_t  sampleRate,
int32_t  channels,
Format  format,
int64_t  pts 
)
virtual

Call this if you modify the samples and are now done.

This updates the pertinent information in the structure.

Parameters
completeIs this set of samples complete?
numSamplesNumber of samples in this update (note that 4 shorts of 16-bit audio in stereo is actually 1 sample).
sampleRateThe sample rate (in Hz) of this set of samples.
channelsThe number of channels in this set of samples.
formatThe sample-format of this set of samples.
ptsThe presentation time stamp of the starting sample in this buffer. Caller must ensure pts is in units of 1/1,000,000 of a second

Implements com::avpkit::core::IAudioSamples.

Definition at line 273 of file AudioSamples.cpp.

276  {
277  mIsComplete = complete;
278  if (channels <= 0)
279  channels = 1;
280 
281  mChannels = channels;
282  mChannelLayout = (ChannelLayout)av_get_default_channel_layout(mChannels);
283  mSampleRate = sampleRate;
284  mSampleFmt = format;
285  if (mSamples)
286  // if we've allocated a buffer, reset the type
287  setBufferType(mSampleFmt, mSamples.value());
288 
289  if (mIsComplete)
290  {
291  mNumSamples = FFMIN(numSamples,
293 #if 0
294  {
295  short* samps = this->getRawSamples(0);
296  for(int32_t i = 0; i < mNumSamples;i++)
297  {
298  int32_t samp = samps[i];
299  VS_LOG_DEBUG("i: %d; samp: %d", i, samp);
300  }
301  }
302 #endif // VS_DEBUG
303  } else {
304  mNumSamples = 0;
305  }
306  setPts(pts);
307  }
virtual void setPts(int64_t aValue)
Set the Presentation Time Stamp for this set of samples.
T * value()
Return the managed pointer without calling RefCounted::acquire() on it.
Definition: RefPointer.h:226

Referenced by com::avpkit::core::StreamCoder::decodeAudio(), com::avpkit::core::BufferSink::fillAudioSamples(), and com::avpkit::core::AudioResampler::resample().

◆ setData()

void com::avpkit::core::AudioSamples::setData ( com::avpkit::ferry::IBuffer buffer)
virtual

Sets the underlying buffer used by this object.

This is an advanced method and is not recommended for use by those who don't fully understand how IBuffers work. Implementations of IMediaData may behave in undefined ways if the buffer you pass in is not big enough for what you ask them to do (e.g. they may discard your buffer and allocate a larger one if they need more space). It is up to the caller to ensure the buffer passed in is large enough, and is not simultaneously in use by another part of the system.

Parameters
bufferThe buffer to set. If null, this method is ignored.

Implements com::avpkit::core::IMediaData.

Definition at line 189 of file AudioSamples.cpp.

190  {
191  if (!buffer) return;
192  mSamples.reset(buffer, true);
193  setBufferType(mSampleFmt, buffer);
194  }
void reset(T *ptr=0, bool acquire=false)
Reset the managed pointer, calling RefCounted::release() on the previously managed pointer first.
Definition: RefPointer.h:237

◆ setPts()

void com::avpkit::core::AudioSamples::setPts ( int64_t  aValue)
virtual

Set the Presentation Time Stamp for this set of samples.

Parameters
aValuethe new value

Implements com::avpkit::core::IAudioSamples.

Definition at line 323 of file AudioSamples.cpp.

324  {
325  mPts = aValue;
326  }

Referenced by setTimeStamp().

◆ setSample()

int32_t com::avpkit::core::AudioSamples::setSample ( int32_t  sampleIndex,
int32_t  channel,
Format  format,
int32_t  sample 
)
virtual

Sets the sample at the given index and channel to the sample.

In theory we assume input is the given Format, and will convert if needed, but right now we only support FMT_S16 anyway.

Parameters
sampleIndexThe zero-based index into the set of samples
channelThe zero-based channel number. If this set of samples doesn't have that given channel, an error is returned.
formatThe format of the given sample
sampleThe actual sample
Returns
>= 0 on success; -1 on error.

Implements com::avpkit::core::IAudioSamples.

Definition at line 339 of file AudioSamples.cpp.

340  {
341  int32_t retval = -1;
342  try {
343  if (channel < 0 || channel >= mChannels)
344  throw std::invalid_argument("cannot setSample for given channel");
345  if (format != FMT_S16)
346  throw std::invalid_argument("only support format: FMT_S16");
347  if (sampleIndex >= this->getMaxSamples())
348  throw std::invalid_argument("sampleIndex out of bounds");
349 
350  short *rawSamples = this->getRawSamples(0);
351  if (!rawSamples)
352  throw std::runtime_error("no samples buffer set in AudioSamples");
353 
354  rawSamples[sampleIndex*mChannels + channel] = (short)sample;
355  retval = 0;
356  }
357  catch (std::exception & e)
358  {
359  VS_LOG_DEBUG("Error: %s", e.what());
360  retval = -1;
361  }
362  return retval;
363  }

◆ setTimeBase()

virtual void com::avpkit::core::AudioSamples::setTimeBase ( IRational aBase)
inlinevirtual

Set the time base that time stamps of this object are represented in.

Parameters
aBasethe new time base. If null an exception is thrown.

Implements com::avpkit::core::IMediaData.

Definition at line 40 of file AudioSamples.h.

40 { mTimeBase.reset(aBase, true); }

◆ setTimeStamp()

virtual void com::avpkit::core::AudioSamples::setTimeStamp ( int64_t  aTimeStamp)
inlinevirtual

Set the time stamp for this object in getTimeBase() units.

Parameters
aTimeStampThe time stamp

Implements com::avpkit::core::IMediaData.

Definition at line 38 of file AudioSamples.h.

38 { setPts(aTimeStamp); }

References setPts().


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