tor-browser

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

test_latency.cpp (1231B)


      1 #include "cubeb/cubeb.h"
      2 #include "gtest/gtest.h"
      3 #include <memory>
      4 #include <stdlib.h>
      5 // #define ENABLE_NORMAL_LOG
      6 // #define ENABLE_VERBOSE_LOG
      7 #include "common.h"
      8 
      9 TEST(cubeb, latency)
     10 {
     11  cubeb * ctx = NULL;
     12  int r;
     13  uint32_t max_channels;
     14  uint32_t preferred_rate;
     15  uint32_t latency_frames;
     16 
     17  r = common_init(&ctx, "Cubeb audio test");
     18  ASSERT_EQ(r, CUBEB_OK);
     19 
     20  std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
     21      ctx, cubeb_destroy);
     22 
     23  r = cubeb_get_max_channel_count(ctx, &max_channels);
     24  ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
     25  if (r == CUBEB_OK) {
     26    ASSERT_GT(max_channels, 0u);
     27  }
     28 
     29  r = cubeb_get_preferred_sample_rate(ctx, &preferred_rate);
     30  ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
     31  if (r == CUBEB_OK) {
     32    ASSERT_GT(preferred_rate, 0u);
     33  }
     34 
     35  cubeb_stream_params params = {
     36      CUBEB_SAMPLE_FLOAT32NE, preferred_rate,
     37      max_channels,           CUBEB_LAYOUT_UNDEFINED,
     38      CUBEB_STREAM_PREF_NONE, CUBEB_INPUT_PROCESSING_PARAM_NONE};
     39  r = cubeb_get_min_latency(ctx, &params, &latency_frames);
     40  ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
     41  if (r == CUBEB_OK) {
     42    ASSERT_GT(latency_frames, 0u);
     43  }
     44 }