Niels Möller | 2e47f7c | 2018-10-16 10:41:42 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018 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 <vector> |
| 12 | |
| 13 | #include "api/test/loopback_media_transport.h" |
| 14 | #include "test/gmock.h" |
| 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | namespace { |
| 19 | |
| 20 | class MockMediaTransportAudioSinkInterface |
| 21 | : public MediaTransportAudioSinkInterface { |
| 22 | public: |
| 23 | MOCK_METHOD2(OnData, void(uint64_t, MediaTransportEncodedAudioFrame)); |
| 24 | }; |
| 25 | |
| 26 | // Test only uses the sequence number. |
| 27 | MediaTransportEncodedAudioFrame CreateAudioFrame(int sequence_number) { |
| 28 | static constexpr int kSamplingRateHz = 48000; |
| 29 | static constexpr int kStartingSampleIndex = 0; |
| 30 | static constexpr int kSamplesPerChannel = 480; |
| 31 | static constexpr uint8_t kPayloadType = 17; |
| 32 | |
| 33 | return MediaTransportEncodedAudioFrame( |
| 34 | kSamplingRateHz, kStartingSampleIndex, kSamplesPerChannel, |
| 35 | sequence_number, MediaTransportEncodedAudioFrame::FrameType::kSpeech, |
| 36 | kPayloadType, std::vector<uint8_t>(kSamplesPerChannel)); |
| 37 | } |
| 38 | |
| 39 | } // namespace |
| 40 | |
| 41 | TEST(LoopbackMediaTransport, AudioWithNoSinkSilentlyIgnored) { |
| 42 | MediaTransportPair transport_pair; |
| 43 | transport_pair.first()->SendAudioFrame(1, CreateAudioFrame(0)); |
| 44 | transport_pair.second()->SendAudioFrame(2, CreateAudioFrame(0)); |
| 45 | } |
| 46 | |
| 47 | TEST(LoopbackMediaTransport, AudioDeliveredToSink) { |
| 48 | MediaTransportPair transport_pair; |
| 49 | testing::StrictMock<MockMediaTransportAudioSinkInterface> sink; |
| 50 | EXPECT_CALL(sink, |
| 51 | OnData(1, testing::Property( |
| 52 | &MediaTransportEncodedAudioFrame::sequence_number, |
| 53 | testing::Eq(10)))); |
| 54 | transport_pair.second()->SetReceiveAudioSink(&sink); |
| 55 | transport_pair.first()->SendAudioFrame(1, CreateAudioFrame(10)); |
| 56 | |
| 57 | transport_pair.second()->SetReceiveAudioSink(nullptr); |
| 58 | } |
| 59 | |
| 60 | } // namespace webrtc |