summaryrefslogtreecommitdiff
path: root/media/libcubeb/tests/test_latency.cpp
blob: 0586b1a367e8c59ba2e0380e26823f308a81b9c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <stdlib.h>
#include "cubeb/cubeb.h"
#include <assert.h>
#include <stdio.h>
#ifdef CUBEB_GECKO_BUILD
#include "TestHarness.h"
#endif

#define LOG(msg) fprintf(stderr, "%s\n", msg);

int main(int /*argc*/, char * /*argv*/[])
{
#ifdef CUBEB_GECKO_BUILD
  ScopedXPCOM xpcom("test_latency");
#endif

  cubeb * ctx = NULL;
  int r;
  uint32_t max_channels;
  uint32_t preferred_rate;
  uint32_t latency_frames;

  LOG("latency_test start");
  r = cubeb_init(&ctx, "Cubeb audio test");
  assert(r == CUBEB_OK && "Cubeb init failed.");
  LOG("cubeb_init ok");

  r = cubeb_get_max_channel_count(ctx, &max_channels);
  assert(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
  if (r == CUBEB_OK) {
    assert(max_channels > 0 && "Invalid max channel count.");
    LOG("cubeb_get_max_channel_count ok");
  }

  r = cubeb_get_preferred_sample_rate(ctx, &preferred_rate);
  assert(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
  if (r == CUBEB_OK) {
    assert(preferred_rate > 0 && "Invalid preferred sample rate.");
    LOG("cubeb_get_preferred_sample_rate ok");
  }

  cubeb_stream_params params = {
    CUBEB_SAMPLE_FLOAT32NE,
    preferred_rate,
    max_channels
  };
  r = cubeb_get_min_latency(ctx, params, &latency_frames);
  assert(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
  if (r == CUBEB_OK) {
    assert(latency_frames > 0 && "Invalid minimal latency.");
    LOG("cubeb_get_min_latency ok");
  }

  cubeb_destroy(ctx);
  LOG("cubeb_destroy ok");
  return EXIT_SUCCESS;
}