zoukankan      html  css  js  c++  java
  • WEBRTC源码片段分析(1)音频缓冲拷贝

    源码位置
    webrtc/webrtc/modules/audio_device/ios/audio_device_ios.cc
    函数
    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;
    }
    ...............
    }
    一开始阅读这段函数时,简单理解就是查找未使用,或者未完全填满的槽位,理解是理解了但感觉有点效率不高,故优化了下,结果理解就出了问题.
    OSStatus
    AudioDeviceIPhone::RecordProcessImpl(
    AudioUnitRenderActionFlags *ioActionFlags,
    const AudioTimeStamp *inTimeStamp,
    uint32_t inBusNumber,
    uint32_t inNumberFrames)
    {
    ...........
    bufPos = 0;
    insertPos = -1;
    nCopy = 0;
    //查找未使用,或者未完全填满的槽位
    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;
    }
    ...............
    }
    相比原版,增加了两个break,结果仔细思考发现,第二个break是不对的.找到空槽位之后,仍然要考虑遍历下有没有未填满的槽位.
    OSStatus
    AudioDeviceIPhone::RecordProcessImpl(
    AudioUnitRenderActionFlags *ioActionFlags,
    const AudioTimeStamp *inTimeStamp,
    uint32_t inBusNumber,
    uint32_t inNumberFrames)
    {
    ...........
    bufPos = 0;
    insertPos = -1;
    nCopy = 0;
    //查找未使用,或者未完全填满的槽位
    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,找到空槽后,再继续找长度不足的槽位,优先使用
    insertPos = static_cast<int16_t>(bufPos);
    }
    ++bufPos;
    }
    ...............
    }
    修正后OK了,这还是要仔细阅读,理解清楚了需求.如果使用链表,就不会有问题了.

  • 相关阅读:
    在SharePoint 2010中使用jQuery
    SharePoint 2010整合Silverlight 4应用 任务管理
    在LINQ to SharePoint中使用创建时间,创建者,修改时间,修改者
    修改SharePoint页面上的控件数量的限制
    SharePoint 2010开发工具图解系列:PowerShell脚本
    SharePoint 2010:部署.resx(资源)文件到App_GlobalResources的简单方法
    使用[本人]创建视图筛选时的一个问题和解答
    在SharePoint 2010环境下区分w3wp进程
    通过PowerShell实现SharePoint列表增删改
    SharePoint 2010开发工具图解系列:Visual Studio 2010创建事件接收器
  • 原文地址:https://www.cnblogs.com/decwang/p/4629952.html
Copyright © 2011-2022 走看看