WEBRTC Source Fragment Analysis (1) Audio buffer copy

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.