本文整理汇总了C++中nsCircularByteBuffer::SetCapacity方法的典型用法代码示例。如果您正苦于以下问题:C++ nsCircularByteBuffer::SetCapacity方法的具体用法?C++ nsCircularByteBuffer::SetCapacity怎么用?C++ nsCircularByteBuffer::SetCapacity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsCircularByteBuffer
的用法示例。
在下文中一共展示了nsCircularByteBuffer::SetCapacity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetCubebContext
nsresult
BufferedAudioStream::Init(int32_t aNumChannels, int32_t aRate,
const dom::AudioChannelType aAudioChannelType)
{
cubeb* cubebContext = GetCubebContext();
if (!cubebContext || aNumChannels < 0 || aRate < 0) {
return NS_ERROR_FAILURE;
}
mInRate = mOutRate = aRate;
mChannels = aNumChannels;
mDumpFile = OpenDumpFile(this);
cubeb_stream_params params;
params.rate = aRate;
params.channels = aNumChannels;
#if defined(__ANDROID__)
#if defined(MOZ_B2G)
params.stream_type = ConvertChannelToCubebType(aAudioChannelType);
#else
params.stream_type = CUBEB_STREAM_TYPE_MUSIC;
#endif
if (params.stream_type == CUBEB_STREAM_TYPE_MAX) {
return NS_ERROR_INVALID_ARG;
}
#endif
if (AUDIO_OUTPUT_FORMAT == AUDIO_FORMAT_S16) {
params.format = CUBEB_SAMPLE_S16NE;
} else {
params.format = CUBEB_SAMPLE_FLOAT32NE;
}
mBytesPerFrame = sizeof(AudioDataValue) * aNumChannels;
mAudioClock.Init();
{
cubeb_stream* stream;
if (cubeb_stream_init(cubebContext, &stream, "BufferedAudioStream", params,
GetCubebLatency(), DataCallback_S, StateCallback_S, this) == CUBEB_OK) {
mCubebStream.own(stream);
}
}
if (!mCubebStream) {
return NS_ERROR_FAILURE;
}
// Size mBuffer for one second of audio. This value is arbitrary, and was
// selected based on the observed behaviour of the existing AudioStream
// implementations.
uint32_t bufferLimit = FramesToBytes(aRate);
NS_ABORT_IF_FALSE(bufferLimit % mBytesPerFrame == 0, "Must buffer complete frames");
mBuffer.SetCapacity(bufferLimit);
return NS_OK;
}
示例2: GetCubebContext
nsresult
nsBufferedAudioStream::Init(int32_t aNumChannels, int32_t aRate,
const dom::AudioChannelType aAudioChannelType)
{
cubeb* cubebContext = GetCubebContext();
if (!cubebContext || aNumChannels < 0 || aRate < 0) {
return NS_ERROR_FAILURE;
}
mRate = aRate;
mChannels = aNumChannels;
cubeb_stream_params params;
params.rate = aRate;
params.channels = aNumChannels;
if (AUDIO_OUTPUT_FORMAT == AUDIO_FORMAT_S16) {
params.format = CUBEB_SAMPLE_S16NE;
} else {
params.format = CUBEB_SAMPLE_FLOAT32NE;
}
mBytesPerFrame = sizeof(AudioDataValue) * aNumChannels;
{
cubeb_stream* stream;
if (cubeb_stream_init(cubebContext, &stream, "nsBufferedAudioStream", params,
GetCubebLatency(), DataCallback_S, StateCallback_S, this) == CUBEB_OK) {
mCubebStream.own(stream);
}
}
if (!mCubebStream) {
return NS_ERROR_FAILURE;
}
// Size mBuffer for one second of audio. This value is arbitrary, and was
// selected based on the observed behaviour of the existing AudioStream
// implementations.
uint32_t bufferLimit = aRate * mBytesPerFrame;
NS_ABORT_IF_FALSE(bufferLimit % mBytesPerFrame == 0, "Must buffer complete frames");
mBuffer.SetCapacity(bufferLimit);
return NS_OK;
}