tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

frame_blocker.cc (3114B)


      1 /*
      2 *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #include "modules/audio_processing/aec3/frame_blocker.h"
     12 
     13 #include <algorithm>
     14 #include <cstddef>
     15 #include <vector>
     16 
     17 #include "api/array_view.h"
     18 #include "modules/audio_processing/aec3/aec3_common.h"
     19 #include "modules/audio_processing/aec3/block.h"
     20 #include "rtc_base/checks.h"
     21 
     22 namespace webrtc {
     23 
     24 FrameBlocker::FrameBlocker(size_t num_bands, size_t num_channels)
     25    : num_bands_(num_bands),
     26      num_channels_(num_channels),
     27      buffer_(num_bands_, std::vector<std::vector<float>>(num_channels)) {
     28  RTC_DCHECK_LT(0, num_bands);
     29  RTC_DCHECK_LT(0, num_channels);
     30  for (auto& band : buffer_) {
     31    for (auto& channel : band) {
     32      channel.reserve(kBlockSize);
     33      RTC_DCHECK(channel.empty());
     34    }
     35  }
     36 }
     37 
     38 FrameBlocker::~FrameBlocker() = default;
     39 
     40 void FrameBlocker::InsertSubFrameAndExtractBlock(
     41    const std::vector<std::vector<ArrayView<float>>>& sub_frame,
     42    Block* block) {
     43  RTC_DCHECK(block);
     44  RTC_DCHECK_EQ(num_bands_, block->NumBands());
     45  RTC_DCHECK_EQ(num_bands_, sub_frame.size());
     46  for (size_t band = 0; band < num_bands_; ++band) {
     47    RTC_DCHECK_EQ(num_channels_, block->NumChannels());
     48    RTC_DCHECK_EQ(num_channels_, sub_frame[band].size());
     49    for (size_t channel = 0; channel < num_channels_; ++channel) {
     50      RTC_DCHECK_GE(kBlockSize - 16, buffer_[band][channel].size());
     51      RTC_DCHECK_EQ(kSubFrameLength, sub_frame[band][channel].size());
     52      const int samples_to_block = kBlockSize - buffer_[band][channel].size();
     53      std::copy(buffer_[band][channel].begin(), buffer_[band][channel].end(),
     54                block->begin(band, channel));
     55      std::copy(sub_frame[band][channel].begin(),
     56                sub_frame[band][channel].begin() + samples_to_block,
     57                block->begin(band, channel) + kBlockSize - samples_to_block);
     58      buffer_[band][channel].clear();
     59      buffer_[band][channel].insert(
     60          buffer_[band][channel].begin(),
     61          sub_frame[band][channel].begin() + samples_to_block,
     62          sub_frame[band][channel].end());
     63    }
     64  }
     65 }
     66 
     67 bool FrameBlocker::IsBlockAvailable() const {
     68  return kBlockSize == buffer_[0][0].size();
     69 }
     70 
     71 void FrameBlocker::ExtractBlock(Block* block) {
     72  RTC_DCHECK(block);
     73  RTC_DCHECK_EQ(num_bands_, block->NumBands());
     74  RTC_DCHECK_EQ(num_channels_, block->NumChannels());
     75  RTC_DCHECK(IsBlockAvailable());
     76  for (size_t band = 0; band < num_bands_; ++band) {
     77    for (size_t channel = 0; channel < num_channels_; ++channel) {
     78      RTC_DCHECK_EQ(kBlockSize, buffer_[band][channel].size());
     79      std::copy(buffer_[band][channel].begin(), buffer_[band][channel].end(),
     80                block->begin(band, channel));
     81      buffer_[band][channel].clear();
     82    }
     83  }
     84 }
     85 
     86 }  // namespace webrtc