Benjamin Wright | 150a907 | 2018-10-26 22:43:06 | [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 "api/test/fake_frame_decryptor.h" |
| 12 | #include "api/test/fake_frame_encryptor.h" |
| 13 | #include "media/engine/internaldecoderfactory.h" |
| 14 | #include "modules/video_coding/codecs/vp8/include/vp8.h" |
| 15 | #include "test/call_test.h" |
| 16 | #include "test/field_trial.h" |
| 17 | #include "test/gtest.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | class FrameEncryptionEndToEndTest : public test::CallTest { |
| 22 | public: |
| 23 | FrameEncryptionEndToEndTest() = default; |
| 24 | |
| 25 | private: |
| 26 | // GenericDescriptor is required for FrameEncryption to work. |
| 27 | test::ScopedFieldTrials field_trials_{"WebRTC-GenericDescriptor/Enabled/"}; |
| 28 | }; |
| 29 | |
| 30 | // Validates that payloads cannot be sent without a frame encryptor and frame |
| 31 | // decryptor attached. |
| 32 | TEST_F(FrameEncryptionEndToEndTest, RequireFrameEncryptionEnforced) { |
| 33 | class DecryptedFrameObserver : public test::EndToEndTest, |
| 34 | public rtc::VideoSinkInterface<VideoFrame> { |
| 35 | public: |
| 36 | DecryptedFrameObserver() |
| 37 | : EndToEndTest(kDefaultTimeoutMs), |
| 38 | encoder_factory_([]() { return VP8Encoder::Create(); }) {} |
| 39 | |
| 40 | private: |
| 41 | void ModifyVideoConfigs( |
| 42 | VideoSendStream::Config* send_config, |
| 43 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 44 | VideoEncoderConfig* encoder_config) override { |
| 45 | // Use VP8 instead of FAKE. |
| 46 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
| 47 | send_config->rtp.payload_name = "VP8"; |
| 48 | send_config->rtp.payload_type = kVideoSendPayloadType; |
| 49 | send_config->frame_encryptor = new FakeFrameEncryptor(); |
| 50 | send_config->crypto_options.sframe.require_frame_encryption = true; |
| 51 | encoder_config->codec_type = kVideoCodecVP8; |
| 52 | VideoReceiveStream::Decoder decoder = |
| 53 | test::CreateMatchingDecoder(*send_config); |
| 54 | decoder.decoder_factory = &decoder_factory_; |
| 55 | for (auto& recv_config : *receive_configs) { |
| 56 | recv_config.decoders.clear(); |
| 57 | recv_config.decoders.push_back(decoder); |
| 58 | recv_config.renderer = this; |
| 59 | recv_config.frame_decryptor = new FakeFrameDecryptor(); |
| 60 | recv_config.crypto_options.sframe.require_frame_encryption = true; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Validate that rotation is preserved. |
| 65 | void OnFrame(const VideoFrame& video_frame) override { |
| 66 | observation_complete_.Set(); |
| 67 | } |
| 68 | |
| 69 | void PerformTest() override { |
| 70 | EXPECT_TRUE(Wait()) |
| 71 | << "Timed out waiting for decrypted frames to be rendered."; |
| 72 | } |
| 73 | |
| 74 | std::unique_ptr<VideoEncoder> encoder_; |
| 75 | test::FunctionVideoEncoderFactory encoder_factory_; |
| 76 | InternalDecoderFactory decoder_factory_; |
| 77 | } test; |
| 78 | |
| 79 | RunBaseTest(&test); |
| 80 | } |
| 81 | } // namespace webrtc |