summaryrefslogtreecommitdiffstats
path: root/media/cast/test/utility/audio_utility_unittest.cc
blob: 900636553b67b3d97d7a54dfa9759945baf6fae1 (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
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stdint.h>

#include "media/base/video_frame.h"
#include "media/cast/test/utility/audio_utility.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace media {
namespace cast {
namespace test {
namespace {

TEST(AudioTimestampTest, Small) {
  std::vector<float> samples(480);
  for (int32_t in_timestamp = 0; in_timestamp < 65536; in_timestamp += 2077) {
    EncodeTimestamp(in_timestamp, 0, samples.size(), &samples.front());
    uint16_t out_timestamp;
    EXPECT_TRUE(
        DecodeTimestamp(&samples.front(), samples.size(), &out_timestamp));
    ASSERT_EQ(in_timestamp, out_timestamp);
  }
}

TEST(AudioTimestampTest, Negative) {
  std::vector<float> samples(480);
  uint16_t out_timestamp;
  EXPECT_FALSE(
      DecodeTimestamp(&samples.front(), samples.size(), &out_timestamp));
}

TEST(AudioTimestampTest, CheckPhase) {
  std::vector<float> samples(4800);
  EncodeTimestamp(4711, 0, samples.size(), &samples.front());
  for (size_t i = 0; i < samples.size() - 240; i += 143) {
    uint16_t out_timestamp;
    EXPECT_TRUE(DecodeTimestamp(&samples.front() + i, samples.size() - i,
                                &out_timestamp));
    ASSERT_EQ(4711, out_timestamp);
  }
}

}  // namespace
}  // namespace test
}  // namespace cast
}  // namespace media