tor-browser

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

aec_dump_unittest.cc (3017B)


      1 /*
      2 *  Copyright (c) 2017 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/include/aec_dump.h"
     12 
     13 #include <stdio.h>
     14 
     15 #include <array>
     16 #include <cstddef>
     17 #include <cstdint>
     18 #include <cstdio>
     19 #include <memory>
     20 #include <string>
     21 
     22 #include "api/audio/audio_processing.h"
     23 #include "modules/audio_processing/aec_dump/aec_dump_factory.h"
     24 #include "rtc_base/task_queue_for_test.h"
     25 #include "test/gtest.h"
     26 #include "test/testsupport/file_utils.h"
     27 
     28 namespace webrtc {
     29 
     30 TEST(AecDumper, APICallsDoNotCrash) {
     31  // Note order of initialization: Task queue has to be initialized
     32  // before AecDump.
     33  TaskQueueForTest file_writer_queue("file_writer_queue");
     34 
     35  const std::string filename =
     36      test::TempFilename(test::OutputPath(), "aec_dump");
     37 
     38  {
     39    std::unique_ptr<AecDump> aec_dump =
     40        AecDumpFactory::Create(filename, -1, file_writer_queue.Get());
     41 
     42    constexpr int kNumChannels = 1;
     43    constexpr int kNumSamplesPerChannel = 160;
     44    std::array<int16_t, kNumSamplesPerChannel * kNumChannels> frame;
     45    frame.fill(0.f);
     46    aec_dump->WriteRenderStreamMessage(frame.data(), kNumChannels,
     47                                       kNumSamplesPerChannel);
     48 
     49    aec_dump->AddCaptureStreamInput(frame.data(), kNumChannels,
     50                                    kNumSamplesPerChannel);
     51    aec_dump->AddCaptureStreamOutput(frame.data(), kNumChannels,
     52                                     kNumSamplesPerChannel);
     53 
     54    aec_dump->WriteCaptureStreamMessage();
     55 
     56    InternalAPMConfig apm_config;
     57    aec_dump->WriteConfig(apm_config);
     58 
     59    ProcessingConfig api_format;
     60    constexpr int64_t kTimeNowMs = 123456789ll;
     61    aec_dump->WriteInitMessage(api_format, kTimeNowMs);
     62  }
     63  // Remove file after the AecDump d-tor has finished.
     64  ASSERT_EQ(0, remove(filename.c_str()));
     65 }
     66 
     67 TEST(AecDumper, WriteToFile) {
     68  TaskQueueForTest file_writer_queue("file_writer_queue");
     69 
     70  const std::string filename =
     71      test::TempFilename(test::OutputPath(), "aec_dump");
     72 
     73  {
     74    std::unique_ptr<AecDump> aec_dump =
     75        AecDumpFactory::Create(filename, -1, file_writer_queue.Get());
     76 
     77    constexpr int kNumChannels = 1;
     78    constexpr int kNumSamplesPerChannel = 160;
     79    std::array<int16_t, kNumSamplesPerChannel * kNumChannels> frame;
     80    frame.fill(0.f);
     81 
     82    aec_dump->WriteRenderStreamMessage(frame.data(), kNumChannels,
     83                                       kNumSamplesPerChannel);
     84  }
     85 
     86  // Verify the file has been written after the AecDump d-tor has
     87  // finished.
     88  FILE* fid = fopen(filename.c_str(), "r");
     89  ASSERT_TRUE(fid != nullptr);
     90 
     91  // Clean it up.
     92  ASSERT_EQ(0, fclose(fid));
     93  ASSERT_EQ(0, remove(filename.c_str()));
     94 }
     95 
     96 }  // namespace webrtc