Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: webrtc/api/rtpsenderreceiver_unittest.cc

Issue 1894283002: Fixing a segfault that can occur when changing the track of an RtpSender. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/rtpsender.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 13
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webrtc/api/audiotrack.h" 16 #include "webrtc/api/audiotrack.h"
17 #include "webrtc/api/mediastream.h" 17 #include "webrtc/api/mediastream.h"
18 #include "webrtc/api/remoteaudiosource.h" 18 #include "webrtc/api/remoteaudiosource.h"
19 #include "webrtc/api/rtpreceiver.h" 19 #include "webrtc/api/rtpreceiver.h"
20 #include "webrtc/api/rtpsender.h" 20 #include "webrtc/api/rtpsender.h"
21 #include "webrtc/api/streamcollection.h" 21 #include "webrtc/api/streamcollection.h"
22 #include "webrtc/api/test/fakevideotracksource.h" 22 #include "webrtc/api/test/fakevideotracksource.h"
23 #include "webrtc/api/videotracksource.h" 23 #include "webrtc/api/videotracksource.h"
24 #include "webrtc/api/videotrack.h" 24 #include "webrtc/api/videotrack.h"
25 #include "webrtc/base/gunit.h" 25 #include "webrtc/base/gunit.h"
26 #include "webrtc/media/base/mediachannel.h" 26 #include "webrtc/media/base/mediachannel.h"
27 27
28 using ::testing::_; 28 using ::testing::_;
29 using ::testing::Exactly; 29 using ::testing::Exactly;
30 using ::testing::InvokeWithoutArgs;
30 using ::testing::Return; 31 using ::testing::Return;
31 32
32 static const char kStreamLabel1[] = "local_stream_1"; 33 static const char kStreamLabel1[] = "local_stream_1";
33 static const char kVideoTrackId[] = "video_1"; 34 static const char kVideoTrackId[] = "video_1";
34 static const char kAudioTrackId[] = "audio_1"; 35 static const char kAudioTrackId[] = "audio_1";
35 static const uint32_t kVideoSsrc = 98; 36 static const uint32_t kVideoSsrc = 98;
36 static const uint32_t kVideoSsrc2 = 100; 37 static const uint32_t kVideoSsrc2 = 100;
37 static const uint32_t kAudioSsrc = 99; 38 static const uint32_t kAudioSsrc = 99;
38 static const uint32_t kAudioSsrc2 = 101; 39 static const uint32_t kAudioSsrc2 = 101;
39 40
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 } 409 }
409 410
410 TEST_F(RtpSenderReceiverTest, AudioSenderTrackSetToNull) { 411 TEST_F(RtpSenderReceiverTest, AudioSenderTrackSetToNull) {
411 rtc::scoped_refptr<AudioTrackInterface> track = 412 rtc::scoped_refptr<AudioTrackInterface> track =
412 AudioTrack::Create(kAudioTrackId, nullptr); 413 AudioTrack::Create(kAudioTrackId, nullptr);
413 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _)); 414 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
414 rtc::scoped_refptr<AudioRtpSender> sender = 415 rtc::scoped_refptr<AudioRtpSender> sender =
415 new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr); 416 new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
416 sender->SetSsrc(kAudioSsrc); 417 sender->SetSsrc(kAudioSsrc);
417 418
418 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1); 419 // Expect that SetAudioSend will be called before the reference to the track
420 // is released.
421 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, nullptr))
422 .Times(1)
423 .WillOnce(InvokeWithoutArgs([&track] {
424 EXPECT_LT(2, track->AddRef());
425 track->Release();
426 }));
419 EXPECT_TRUE(sender->SetTrack(nullptr)); 427 EXPECT_TRUE(sender->SetTrack(nullptr));
420 428
421 // Make sure it's SetTrack that called methods on the provider, and not the 429 // Make sure it's SetTrack that called methods on the provider, and not the
422 // destructor. 430 // destructor.
423 EXPECT_CALL(audio_provider_, SetAudioSend(_, _, _, _)).Times(0); 431 EXPECT_CALL(audio_provider_, SetAudioSend(_, _, _, _)).Times(0);
424 } 432 }
425 433
426 TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) { 434 TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) {
427 AddVideoTrack(); 435 rtc::scoped_refptr<VideoTrackSourceInterface> source(
428 EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, video_track_.get())); 436 FakeVideoTrackSource::Create());
437 rtc::scoped_refptr<VideoTrackInterface> track =
438 VideoTrack::Create(kVideoTrackId, source);
439 EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, track.get()));
429 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _)); 440 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
430 rtc::scoped_refptr<VideoRtpSender> sender = 441 rtc::scoped_refptr<VideoRtpSender> sender =
431 new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_); 442 new VideoRtpSender(track, kStreamLabel1, &video_provider_);
432 sender->SetSsrc(kVideoSsrc); 443 sender->SetSsrc(kVideoSsrc);
433 444
434 EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, nullptr)).Times(1); 445 // Expect that SetSource will be called before the reference to the track
446 // is released.
447 EXPECT_CALL(video_provider_, SetSource(kVideoSsrc, nullptr))
448 .Times(1)
449 .WillOnce(InvokeWithoutArgs([&track] {
450 EXPECT_LT(2, track->AddRef());
451 track->Release();
452 return true;
453 }));
435 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1); 454 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
436 EXPECT_TRUE(sender->SetTrack(nullptr)); 455 EXPECT_TRUE(sender->SetTrack(nullptr));
437 456
438 // Make sure it's SetTrack that called methods on the provider, and not the 457 // Make sure it's SetTrack that called methods on the provider, and not the
439 // destructor. 458 // destructor.
440 EXPECT_CALL(video_provider_, SetSource(_, _)).Times(0); 459 EXPECT_CALL(video_provider_, SetSource(_, _)).Times(0);
441 EXPECT_CALL(video_provider_, SetVideoSend(_, _, _)).Times(0); 460 EXPECT_CALL(video_provider_, SetVideoSend(_, _, _)).Times(0);
442 } 461 }
443 462
444 TEST_F(RtpSenderReceiverTest, AudioSenderSsrcChanged) { 463 TEST_F(RtpSenderReceiverTest, AudioSenderSsrcChanged) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 .WillOnce(Return(RtpParameters())); 516 .WillOnce(Return(RtpParameters()));
498 EXPECT_CALL(video_provider_, SetVideoRtpParameters(kVideoSsrc, _)) 517 EXPECT_CALL(video_provider_, SetVideoRtpParameters(kVideoSsrc, _))
499 .WillOnce(Return(true)); 518 .WillOnce(Return(true));
500 RtpParameters params = video_rtp_sender_->GetParameters(); 519 RtpParameters params = video_rtp_sender_->GetParameters();
501 EXPECT_TRUE(video_rtp_sender_->SetParameters(params)); 520 EXPECT_TRUE(video_rtp_sender_->SetParameters(params));
502 521
503 DestroyVideoRtpSender(); 522 DestroyVideoRtpSender();
504 } 523 }
505 524
506 } // namespace webrtc 525 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/rtpsender.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698