blob: d05022f4697986695e1029d3c4c8df72c64841d5 [file] [log] [blame]
wu@webrtc.org364f2042013-11-20 21:49:41 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
wu@webrtc.org364f2042013-11-20 21:49:41 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
wu@webrtc.org364f2042013-11-20 21:49:41 +00009 */
10
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <stddef.h>
Steve Anton36b29d12017-10-30 09:57:42 -070012#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080013#include <utility>
Steve Anton191c39f2018-01-24 19:35:55 -080014#include <vector>
kwiberg0eb15ed2015-12-17 03:04:15 -080015
Yves Gerey3e707812018-11-28 16:47:49 +010016#include "absl/memory/memory.h"
17#include "absl/types/optional.h"
18#include "api/audio/audio_mixer.h"
Mirko Bonadei2ff3f492018-11-22 09:00:13 +010019#include "api/create_peerconnection_factory.h"
Anders Carlsson67537952018-05-03 11:28:29 +020020#include "api/video_codecs/builtin_video_decoder_factory.h"
21#include "api/video_codecs/builtin_video_encoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010022#include "api/video_codecs/video_decoder_factory.h"
23#include "api/video_codecs/video_encoder_factory.h"
24#include "modules/audio_device/include/audio_device.h"
Anders Carlsson67537952018-05-03 11:28:29 +020025#include "modules/audio_processing/include/audio_processing.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "p2p/base/fake_port_allocator.h"
27#include "p2p/base/port_allocator.h"
28#include "pc/test/fake_periodic_video_source.h"
29#include "pc/test/fake_periodic_video_track_source.h"
30#include "pc/test/fake_rtc_certificate_generator.h"
31#include "pc/test/mock_peer_connection_observers.h"
32#include "pc/test/peer_connection_test_wrapper.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "rtc_base/gunit.h"
Yves Gerey3e707812018-11-28 16:47:49 +010034#include "rtc_base/logging.h"
Steve Anton10542f22019-01-11 09:11:00 -080035#include "rtc_base/ref_counted_object.h"
36#include "rtc_base/rtc_certificate_generator.h"
37#include "rtc_base/string_encode.h"
Yves Gerey59cfd352018-11-26 16:22:20 +010038#include "rtc_base/thread_checker.h"
Steve Anton10542f22019-01-11 09:11:00 -080039#include "rtc_base/time_utils.h"
Yves Gerey3e707812018-11-28 16:47:49 +010040#include "test/gtest.h"
wu@webrtc.org364f2042013-11-20 21:49:41 +000041
wu@webrtc.org364f2042013-11-20 21:49:41 +000042using webrtc::FakeVideoTrackRenderer;
43using webrtc::IceCandidateInterface;
wu@webrtc.org364f2042013-11-20 21:49:41 +000044using webrtc::MediaStreamInterface;
Steve Anton191c39f2018-01-24 19:35:55 -080045using webrtc::MediaStreamTrackInterface;
wu@webrtc.org364f2042013-11-20 21:49:41 +000046using webrtc::MockSetSessionDescriptionObserver;
47using webrtc::PeerConnectionInterface;
Steve Anton191c39f2018-01-24 19:35:55 -080048using webrtc::RtpReceiverInterface;
Steve Antona3a92c22017-12-07 10:27:41 -080049using webrtc::SdpType;
wu@webrtc.org364f2042013-11-20 21:49:41 +000050using webrtc::SessionDescriptionInterface;
51using webrtc::VideoTrackInterface;
52
Steve Antona3a92c22017-12-07 10:27:41 -080053namespace {
Seth Hampson845e8782018-03-02 11:34:10 -080054const char kStreamIdBase[] = "stream_id";
Steve Antona3a92c22017-12-07 10:27:41 -080055const char kVideoTrackLabelBase[] = "video_track";
56const char kAudioTrackLabelBase[] = "audio_track";
57constexpr int kMaxWait = 10000;
58constexpr int kTestAudioFrameCount = 3;
59constexpr int kTestVideoFrameCount = 3;
60} // namespace
61
wu@webrtc.org364f2042013-11-20 21:49:41 +000062void PeerConnectionTestWrapper::Connect(PeerConnectionTestWrapper* caller,
63 PeerConnectionTestWrapper* callee) {
64 caller->SignalOnIceCandidateReady.connect(
65 callee, &PeerConnectionTestWrapper::AddIceCandidate);
66 callee->SignalOnIceCandidateReady.connect(
67 caller, &PeerConnectionTestWrapper::AddIceCandidate);
68
Yves Gerey665174f2018-06-19 15:03:05 +020069 caller->SignalOnSdpReady.connect(callee,
70 &PeerConnectionTestWrapper::ReceiveOfferSdp);
wu@webrtc.org364f2042013-11-20 21:49:41 +000071 callee->SignalOnSdpReady.connect(
72 caller, &PeerConnectionTestWrapper::ReceiveAnswerSdp);
73}
74
danilchape9021a32016-05-17 01:52:02 -070075PeerConnectionTestWrapper::PeerConnectionTestWrapper(
76 const std::string& name,
77 rtc::Thread* network_thread,
78 rtc::Thread* worker_thread)
79 : name_(name),
80 network_thread_(network_thread),
Yves Gerey59cfd352018-11-26 16:22:20 +010081 worker_thread_(worker_thread) {
82 pc_thread_checker_.DetachFromThread();
83}
wu@webrtc.org364f2042013-11-20 21:49:41 +000084
Yves Gerey59cfd352018-11-26 16:22:20 +010085PeerConnectionTestWrapper::~PeerConnectionTestWrapper() {
86 RTC_DCHECK_RUN_ON(&pc_thread_checker_);
87 // Either network_thread or worker_thread might be active at this point.
88 // Relying on ~PeerConnection to properly wait for them doesn't work,
89 // as a vptr race might occur (before we enter the destruction body).
90 // See: bugs.webrtc.org/9847
91 if (pc()) {
92 pc()->Close();
93 }
94}
wu@webrtc.org364f2042013-11-20 21:49:41 +000095
96bool PeerConnectionTestWrapper::CreatePc(
kwiberg9e5b11e2017-04-19 03:47:57 -070097 const webrtc::PeerConnectionInterface::RTCConfiguration& config,
98 rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
99 rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory) {
kwibergd1fe2812016-04-27 06:47:29 -0700100 std::unique_ptr<cricket::PortAllocator> port_allocator(
danilchape9021a32016-05-17 01:52:02 -0700101 new cricket::FakePortAllocator(network_thread_, nullptr));
wu@webrtc.org364f2042013-11-20 21:49:41 +0000102
Yves Gerey59cfd352018-11-26 16:22:20 +0100103 RTC_DCHECK_RUN_ON(&pc_thread_checker_);
104
deadbeefee8c6d32015-08-13 14:27:18 -0700105 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000106 if (fake_audio_capture_module_ == NULL) {
107 return false;
108 }
109
110 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700111 network_thread_, worker_thread_, rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200112 rtc::scoped_refptr<webrtc::AudioDeviceModule>(fake_audio_capture_module_),
113 audio_encoder_factory, audio_decoder_factory,
114 webrtc::CreateBuiltinVideoEncoderFactory(),
115 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
116 nullptr /* audio_processing */);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000117 if (!peer_connection_factory_) {
118 return false;
119 }
120
Henrik Boströmd79599d2016-06-01 13:58:50 +0200121 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator(
deadbeef1b54a5f2017-01-23 19:39:57 -0800122 new FakeRTCCertificateGenerator());
Henrik Boströmd79599d2016-06-01 13:58:50 +0200123 peer_connection_ = peer_connection_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200124 config, std::move(port_allocator), std::move(cert_generator), this);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000125
126 return peer_connection_.get() != NULL;
127}
128
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000129rtc::scoped_refptr<webrtc::DataChannelInterface>
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +0000130PeerConnectionTestWrapper::CreateDataChannel(
131 const std::string& label,
132 const webrtc::DataChannelInit& init) {
133 return peer_connection_->CreateDataChannel(label, &init);
134}
135
Steve Anton191c39f2018-01-24 19:35:55 -0800136void PeerConnectionTestWrapper::OnAddTrack(
137 rtc::scoped_refptr<RtpReceiverInterface> receiver,
138 const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {
139 RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": OnAddTrack";
140 if (receiver->track()->kind() == MediaStreamTrackInterface::kVideoKind) {
141 auto* video_track =
142 static_cast<VideoTrackInterface*>(receiver->track().get());
Karl Wiberg918f50c2018-07-05 11:40:33 +0200143 renderer_ = absl::make_unique<FakeVideoTrackRenderer>(video_track);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000144 }
145}
146
147void PeerConnectionTestWrapper::OnIceCandidate(
148 const IceCandidateInterface* candidate) {
149 std::string sdp;
150 EXPECT_TRUE(candidate->ToString(&sdp));
151 // Give the user a chance to modify sdp for testing.
152 SignalOnIceCandidateCreated(&sdp);
153 SignalOnIceCandidateReady(candidate->sdp_mid(), candidate->sdp_mline_index(),
154 sdp);
155}
156
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +0000157void PeerConnectionTestWrapper::OnDataChannel(
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700158 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) {
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +0000159 SignalOnDataChannel(data_channel);
160}
161
wu@webrtc.org364f2042013-11-20 21:49:41 +0000162void PeerConnectionTestWrapper::OnSuccess(SessionDescriptionInterface* desc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000163 // This callback should take the ownership of |desc|.
kwibergd1fe2812016-04-27 06:47:29 -0700164 std::unique_ptr<SessionDescriptionInterface> owned_desc(desc);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000165 std::string sdp;
166 EXPECT_TRUE(desc->ToString(&sdp));
167
Mirko Bonadei675513b2017-11-09 11:09:25 +0100168 RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": "
Steve Antona3a92c22017-12-07 10:27:41 -0800169 << webrtc::SdpTypeToString(desc->GetType())
170 << " sdp created: " << sdp;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000171
172 // Give the user a chance to modify sdp for testing.
173 SignalOnSdpCreated(&sdp);
174
Steve Antona3a92c22017-12-07 10:27:41 -0800175 SetLocalDescription(desc->GetType(), sdp);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000176
177 SignalOnSdpReady(sdp);
178}
179
180void PeerConnectionTestWrapper::CreateOffer(
Niels Möllerf06f9232018-08-07 12:32:18 +0200181 const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100182 RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": CreateOffer.";
Niels Möllerf06f9232018-08-07 12:32:18 +0200183 peer_connection_->CreateOffer(this, options);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000184}
185
186void PeerConnectionTestWrapper::CreateAnswer(
Niels Möllerf06f9232018-08-07 12:32:18 +0200187 const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100188 RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_
189 << ": CreateAnswer.";
Niels Möllerf06f9232018-08-07 12:32:18 +0200190 peer_connection_->CreateAnswer(this, options);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000191}
192
193void PeerConnectionTestWrapper::ReceiveOfferSdp(const std::string& sdp) {
Steve Antona3a92c22017-12-07 10:27:41 -0800194 SetRemoteDescription(SdpType::kOffer, sdp);
Niels Möllerf06f9232018-08-07 12:32:18 +0200195 CreateAnswer(webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
wu@webrtc.org364f2042013-11-20 21:49:41 +0000196}
197
198void PeerConnectionTestWrapper::ReceiveAnswerSdp(const std::string& sdp) {
Steve Antona3a92c22017-12-07 10:27:41 -0800199 SetRemoteDescription(SdpType::kAnswer, sdp);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000200}
201
Steve Antona3a92c22017-12-07 10:27:41 -0800202void PeerConnectionTestWrapper::SetLocalDescription(SdpType type,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000203 const std::string& sdp) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100204 RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_
Steve Antona3a92c22017-12-07 10:27:41 -0800205 << ": SetLocalDescription " << webrtc::SdpTypeToString(type)
206 << " " << sdp;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000207
Yves Gerey665174f2018-06-19 15:03:05 +0200208 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
209 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
wu@webrtc.org364f2042013-11-20 21:49:41 +0000210 peer_connection_->SetLocalDescription(
Steve Antona3a92c22017-12-07 10:27:41 -0800211 observer, webrtc::CreateSessionDescription(type, sdp).release());
wu@webrtc.org364f2042013-11-20 21:49:41 +0000212}
213
Steve Antona3a92c22017-12-07 10:27:41 -0800214void PeerConnectionTestWrapper::SetRemoteDescription(SdpType type,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000215 const std::string& sdp) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100216 RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_
Steve Antona3a92c22017-12-07 10:27:41 -0800217 << ": SetRemoteDescription " << webrtc::SdpTypeToString(type)
218 << " " << sdp;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000219
Yves Gerey665174f2018-06-19 15:03:05 +0200220 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
221 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
wu@webrtc.org364f2042013-11-20 21:49:41 +0000222 peer_connection_->SetRemoteDescription(
Steve Antona3a92c22017-12-07 10:27:41 -0800223 observer, webrtc::CreateSessionDescription(type, sdp).release());
wu@webrtc.org364f2042013-11-20 21:49:41 +0000224}
225
226void PeerConnectionTestWrapper::AddIceCandidate(const std::string& sdp_mid,
227 int sdp_mline_index,
228 const std::string& candidate) {
kwibergd1fe2812016-04-27 06:47:29 -0700229 std::unique_ptr<webrtc::IceCandidateInterface> owned_candidate(
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000230 webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, candidate, NULL));
231 EXPECT_TRUE(peer_connection_->AddIceCandidate(owned_candidate.get()));
wu@webrtc.org364f2042013-11-20 21:49:41 +0000232}
233
234void PeerConnectionTestWrapper::WaitForCallEstablished() {
235 WaitForConnection();
236 WaitForAudio();
237 WaitForVideo();
238}
239
240void PeerConnectionTestWrapper::WaitForConnection() {
241 EXPECT_TRUE_WAIT(CheckForConnection(), kMaxWait);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100242 RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": Connected.";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000243}
244
245bool PeerConnectionTestWrapper::CheckForConnection() {
246 return (peer_connection_->ice_connection_state() ==
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000247 PeerConnectionInterface::kIceConnectionConnected) ||
248 (peer_connection_->ice_connection_state() ==
249 PeerConnectionInterface::kIceConnectionCompleted);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000250}
251
252void PeerConnectionTestWrapper::WaitForAudio() {
253 EXPECT_TRUE_WAIT(CheckForAudio(), kMaxWait);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100254 RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_
255 << ": Got enough audio frames.";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000256}
257
258bool PeerConnectionTestWrapper::CheckForAudio() {
259 return (fake_audio_capture_module_->frames_received() >=
260 kTestAudioFrameCount);
261}
262
263void PeerConnectionTestWrapper::WaitForVideo() {
264 EXPECT_TRUE_WAIT(CheckForVideo(), kMaxWait);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100265 RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_
266 << ": Got enough video frames.";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000267}
268
269bool PeerConnectionTestWrapper::CheckForVideo() {
270 if (!renderer_) {
271 return false;
272 }
273 return (renderer_->num_rendered_frames() >= kTestVideoFrameCount);
274}
275
276void PeerConnectionTestWrapper::GetAndAddUserMedia(
Yves Gerey665174f2018-06-19 15:03:05 +0200277 bool audio,
278 const cricket::AudioOptions& audio_options,
Niels Möller5c4ddad2019-02-12 12:30:58 +0100279 bool video) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000280 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream =
Niels Möller5c4ddad2019-02-12 12:30:58 +0100281 GetUserMedia(audio, audio_options, video);
Mirko Bonadei739baf02019-01-27 17:29:42 +0100282 for (const auto& audio_track : stream->GetAudioTracks()) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700283 EXPECT_TRUE(peer_connection_->AddTrack(audio_track, {stream->id()}).ok());
Steve Anton191c39f2018-01-24 19:35:55 -0800284 }
Mirko Bonadei739baf02019-01-27 17:29:42 +0100285 for (const auto& video_track : stream->GetVideoTracks()) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700286 EXPECT_TRUE(peer_connection_->AddTrack(video_track, {stream->id()}).ok());
Steve Anton191c39f2018-01-24 19:35:55 -0800287 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000288}
289
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000290rtc::scoped_refptr<webrtc::MediaStreamInterface>
Niels Möller2d02e082018-05-21 11:23:35 +0200291PeerConnectionTestWrapper::GetUserMedia(
Yves Gerey665174f2018-06-19 15:03:05 +0200292 bool audio,
293 const cricket::AudioOptions& audio_options,
Niels Möller5c4ddad2019-02-12 12:30:58 +0100294 bool video) {
Seth Hampson845e8782018-03-02 11:34:10 -0800295 std::string stream_id =
296 kStreamIdBase + rtc::ToString(num_get_user_media_calls_++);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000297 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream =
Seth Hampson845e8782018-03-02 11:34:10 -0800298 peer_connection_factory_->CreateLocalMediaStream(stream_id);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000299
300 if (audio) {
Niels Möller2d02e082018-05-21 11:23:35 +0200301 cricket::AudioOptions options = audio_options;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000302 // Disable highpass filter so that we can get all the test audio frames.
Niels Möller2d02e082018-05-21 11:23:35 +0200303 options.highpass_filter = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000304 rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
Niels Möller2d02e082018-05-21 11:23:35 +0200305 peer_connection_factory_->CreateAudioSource(options);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000306 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
wu@webrtc.org364f2042013-11-20 21:49:41 +0000307 peer_connection_factory_->CreateAudioTrack(kAudioTrackLabelBase,
308 source));
309 stream->AddTrack(audio_track);
310 }
311
312 if (video) {
313 // Set max frame rate to 10fps to reduce the risk of the tests to be flaky.
Niels Möllera1cc73f2018-05-28 16:20:42 +0200314 webrtc::FakePeriodicVideoSource::Config config;
315 config.frame_interval_ms = 100;
Johannes Kron965e7942018-09-13 15:36:20 +0200316 config.timestamp_offset_ms = rtc::TimeMillis();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000317
perkja3ede6c2016-03-08 01:27:48 +0100318 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
Niels Möllera1cc73f2018-05-28 16:20:42 +0200319 new rtc::RefCountedObject<webrtc::FakePeriodicVideoTrackSource>(
320 config, /* remote */ false);
321
Seth Hampson845e8782018-03-02 11:34:10 -0800322 std::string videotrack_label = stream_id + kVideoTrackLabelBase;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000323 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
wu@webrtc.org364f2042013-11-20 21:49:41 +0000324 peer_connection_factory_->CreateVideoTrack(videotrack_label, source));
325
326 stream->AddTrack(video_track);
327 }
328 return stream;
329}