SOURCE Location
webrtc/webrtc/modules/audio_device/ios/audio_device_ios.cc
Function
Osstatus
Audiodeviceiphone::recordprocessimpl (
Audiounitrenderactionflags *ioactionflags,
Const Audiotimestamp *intimestamp,
uint32_t Inbusnumber,
uint32_t innumberframes)
{
...........
while (Bufpos < n_rec_buffers)
{
if ((_recordinglength[bufpos] > 0) && (_recordinglength[bufpos] < nosamp10ms))
{
Found the partially full buffer
Insertpos = static_cast<int16_t> (Bufpos);
Don ' t need to search more, quit loop
Bufpos = n_rec_buffers;
}
else if (( -1 = = insertpos) && (0 = = _recordinglength[bufpos]))
{
Found an empty buffer
Insertpos = static_cast<int16_t> (Bufpos);
}
++bufpos;
}
...............
}
The first reading of this function, the simple understanding is to find unused, or not fully filled slot, understanding is understood but feel a little inefficient, so optimized, the results of understanding there is a problem.
Osstatus
Audiodeviceiphone::recordprocessimpl (
Audiounitrenderactionflags *ioactionflags,
Const Audiotimestamp *intimestamp,
uint32_t Inbusnumber,
uint32_t innumberframes)
{
...........
Bufpos = 0;
Insertpos =-1;
nCopy = 0;
Find slots that are not in use or are not fully filled
while (Bufpos < n_rec_buffers)
{
if ((_recordinglength[bufpos] > 0) && (_recordinglength[bufpos] < nosamp10ms))
{
Found the partially full buffer
Insertpos = static_cast<int16_t> (Bufpos);
Don ' t need to search more, quit loop
Break
}
else if (( -1 = = insertpos) && (0 = = _recordinglength[bufpos]))
{
Insertpos = static_cast<int16_t> (Bufpos);
Break
}
++bufpos;
}
...............
}
Compared to the original, added two break, the results of careful thinking found that the second break is not right. After you find the empty slot, you still have to consider whether there are any slots that are not filled under the traverse.
Osstatus
Audiodeviceiphone::recordprocessimpl (
Audiounitrenderactionflags *ioactionflags,
Const Audiotimestamp *intimestamp,
uint32_t Inbusnumber,
uint32_t innumberframes)
{
...........
Bufpos = 0;
Insertpos =-1;
nCopy = 0;
Find slots that are not in use or are not fully filled
while (Bufpos < n_rec_buffers)
{
if ((_recordinglength[bufpos] > 0) && (_recordinglength[bufpos] < nosamp10ms))
{
Found the partially full buffer
Insertpos = static_cast<int16_t> (Bufpos);
Don ' t need to search more, quit loop
Break
}
else if (( -1 = = insertpos) && (0 = = _recordinglength[bufpos]))
{
Found an empty buffer, find the slot, and then continue to find the length of the slot, priority to use
Insertpos = static_cast<int16_t> (Bufpos);
}
++bufpos;
}
...............
}
Fix OK, this is to read carefully, understand the requirements. If you use a linked list, there is no problem.
WEBRTC Source Fragment Analysis (1) Audio buffer copy