本文整理汇总了C++中Frame::GetSizeAvailable方法的典型用法代码示例。如果您正苦于以下问题:C++ Frame::GetSizeAvailable方法的具体用法?C++ Frame::GetSizeAvailable怎么用?C++ Frame::GetSizeAvailable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Frame
的用法示例。
在下文中一共展示了Frame::GetSizeAvailable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Read
uint32_t WaveReader::Read(uint32_t num_samples)
{
int64_t end_position = mPosition + num_samples;
// check read limits
if (mSampleCount <= 0 ||
mPosition >= mSampleCount ||
mPosition >= mReadStartPosition + mReadDuration ||
end_position <= 0 ||
end_position <= mReadStartPosition)
{
// always be positioned num_samples after previous position
Seek(end_position);
return 0;
}
// adjust sample count and seek to start of data if needed
uint32_t first_sample_offset = 0;
uint32_t read_num_samples = num_samples;
if (mPosition < mReadStartPosition) {
first_sample_offset = (uint32_t)(mReadStartPosition - mPosition);
read_num_samples -= first_sample_offset;
Seek(mReadStartPosition);
}
if (end_position > mReadStartPosition + mReadDuration)
read_num_samples -= (uint32_t)(end_position - (mReadStartPosition + mReadDuration));
BMX_ASSERT(read_num_samples > 0);
// read samples
bool have_read = false;
size_t i;
for (i = 0; i < mTracks.size(); i++) {
if (!mTracks[i]->IsEnabled())
continue;
Frame *frame = mTracks[i]->GetFrameBuffer()->CreateFrame();
frame->Grow(read_num_samples * mTracks[i]->GetBlockAlign());
// read samples directly into the frame if there is only 1 track; else read into read buffer
if (!have_read) {
unsigned char *buffer;
if (mTracks.size() == 1) {
buffer = frame->GetBytesAvailable();
} else {
mReadBuffer.Allocate(read_num_samples * mBlockAlign);
buffer = mReadBuffer.GetBytes();
}
uint32_t bytes_read = mInput->Read(buffer, read_num_samples * mBlockAlign);
if (bytes_read < read_num_samples * mBlockAlign) {
log_error("Failed to read %u samples of %u\n",
read_num_samples - bytes_read / mBlockAlign, read_num_samples);
read_num_samples = bytes_read / mBlockAlign;
}
if (mTracks.size() > 1)
mReadBuffer.SetSize(read_num_samples * mBlockAlign);
have_read = true;
}
if (mTracks.size() > 1) {
deinterleave_audio(mReadBuffer.GetBytes(), mReadBuffer.GetSize(),
mQuantizationBits, mChannelCount, (uint16_t)i,
frame->GetBytesAvailable(), frame->GetSizeAvailable());
}
frame->SetSize(read_num_samples * mTracks[i]->GetBlockAlign());
frame->edit_rate = mSamplingRate;
frame->position = mPosition;
frame->track_edit_rate = mSamplingRate;
frame->track_position = mPosition;
frame->request_num_samples = num_samples;
frame->first_sample_offset = first_sample_offset;
frame->num_samples = read_num_samples;
frame->file_position = mDataStartFilePosition + mPosition * mBlockAlign;
mTracks[i]->GetFrameBuffer()->PushFrame(frame);
}
if (have_read)
mPosition += read_num_samples;
// always be positioned num_samples after previous position
if (mPosition < end_position)
Seek(end_position);
return read_num_samples;
}