1 /*
2  *  Copyright (c) 2015 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 #ifndef VIDEO_VIDEO_QUALITY_TEST_H_
11 #define VIDEO_VIDEO_QUALITY_TEST_H_
12 
13 #include <map>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "api/fec_controller.h"
19 #include "api/rtc_event_log/rtc_event_log_factory.h"
20 #include "api/task_queue/task_queue_base.h"
21 #include "api/task_queue/task_queue_factory.h"
22 #include "api/test/frame_generator_interface.h"
23 #include "api/test/video_quality_test_fixture.h"
24 #include "api/video/video_bitrate_allocator_factory.h"
25 #include "call/fake_network_pipe.h"
26 #include "media/engine/internal_decoder_factory.h"
27 #include "media/engine/internal_encoder_factory.h"
28 #include "test/call_test.h"
29 #include "test/layer_filtering_transport.h"
30 #include "video/video_analyzer.h"
31 #ifdef WEBRTC_WIN
32 #include "modules/audio_device/win/core_audio_utility_win.h"
33 #endif
34 
35 namespace webrtc {
36 
37 class VideoQualityTest : public test::CallTest,
38                          public VideoQualityTestFixtureInterface {
39  public:
40   explicit VideoQualityTest(
41       std::unique_ptr<InjectionComponents> injection_components);
42 
43   void RunWithAnalyzer(const Params& params) override;
44   void RunWithRenderers(const Params& params) override;
45 
payload_type_map()46   const std::map<uint8_t, webrtc::MediaType>& payload_type_map() override {
47     return payload_type_map_;
48   }
49 
50   static void FillScalabilitySettings(
51       Params* params,
52       size_t video_idx,
53       const std::vector<std::string>& stream_descriptors,
54       int num_streams,
55       size_t selected_stream,
56       int num_spatial_layers,
57       int selected_sl,
58       InterLayerPredMode inter_layer_pred,
59       const std::vector<std::string>& sl_descriptors);
60 
61   // Helper static methods.
62   static VideoStream DefaultVideoStream(const Params& params, size_t video_idx);
63   static VideoStream DefaultThumbnailStream();
64   static std::vector<int> ParseCSV(const std::string& str);
65 
66  protected:
67   std::map<uint8_t, webrtc::MediaType> payload_type_map_;
68 
69   // No-op implementation to be able to instantiate this class from non-TEST_F
70   // locations.
71   void TestBody() override;
72 
73   // Helper methods accessing only params_.
74   std::string GenerateGraphTitle() const;
75   void CheckParamsAndInjectionComponents();
76 
77   // Helper methods for setting up the call.
78   void CreateCapturers();
79   std::unique_ptr<test::FrameGeneratorInterface> CreateFrameGenerator(
80       size_t video_idx);
81   void SetupThumbnailCapturers(size_t num_thumbnail_streams);
82   std::unique_ptr<VideoDecoder> CreateVideoDecoder(
83       const SdpVideoFormat& format);
84   std::unique_ptr<VideoEncoder> CreateVideoEncoder(const SdpVideoFormat& format,
85                                                    VideoAnalyzer* analyzer);
86   void SetupVideo(Transport* send_transport, Transport* recv_transport);
87   void SetupThumbnails(Transport* send_transport, Transport* recv_transport);
88   void StartAudioStreams();
89   void StartThumbnails();
90   void StopThumbnails();
91   void DestroyThumbnailStreams();
92   // Helper method for creating a real ADM (using hardware) for all platforms.
93   rtc::scoped_refptr<AudioDeviceModule> CreateAudioDevice();
94   void InitializeAudioDevice(Call::Config* send_call_config,
95                              Call::Config* recv_call_config,
96                              bool use_real_adm);
97   void SetupAudio(Transport* transport);
98 
99   void StartEncodedFrameLogs(VideoReceiveStream* stream);
100 
101   virtual std::unique_ptr<test::LayerFilteringTransport> CreateSendTransport();
102   virtual std::unique_ptr<test::DirectTransport> CreateReceiveTransport();
103 
104   std::vector<std::unique_ptr<rtc::VideoSourceInterface<VideoFrame>>>
105       thumbnail_capturers_;
106   Clock* const clock_;
107   const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
108   RtcEventLogFactory rtc_event_log_factory_;
109 
110   test::FunctionVideoDecoderFactory video_decoder_factory_;
111   std::unique_ptr<VideoDecoderFactory> decoder_factory_;
112   test::FunctionVideoEncoderFactory video_encoder_factory_;
113   test::FunctionVideoEncoderFactory video_encoder_factory_with_analyzer_;
114   std::unique_ptr<VideoBitrateAllocatorFactory>
115       video_bitrate_allocator_factory_;
116   std::unique_ptr<VideoEncoderFactory> encoder_factory_;
117   std::vector<VideoSendStream::Config> thumbnail_send_configs_;
118   std::vector<VideoEncoderConfig> thumbnail_encoder_configs_;
119   std::vector<VideoSendStream*> thumbnail_send_streams_;
120   std::vector<VideoReceiveStream::Config> thumbnail_receive_configs_;
121   std::vector<VideoReceiveStream*> thumbnail_receive_streams_;
122 
123   int receive_logs_;
124   int send_logs_;
125 
126   Params params_;
127   std::unique_ptr<InjectionComponents> injection_components_;
128 
129   // Set non-null when running with analyzer.
130   std::unique_ptr<VideoAnalyzer> analyzer_;
131 
132   // Note: not same as similarly named member in CallTest. This is the number of
133   // separate send streams, the one in CallTest is the number of substreams for
134   // a single send stream.
135   size_t num_video_streams_;
136 
137 #ifdef WEBRTC_WIN
138   // Windows Core Audio based ADM needs to run on a COM initialized thread.
139   // Only referenced in combination with --audio --use_real_adm flags.
140   std::unique_ptr<webrtc_win::ScopedCOMInitializer> com_initializer_;
141 #endif
142 };
143 
144 }  // namespace webrtc
145 
146 #endif  // VIDEO_VIDEO_QUALITY_TEST_H_
147