From a117b04113f8e6f6684e050b8a3a54b44e74672a Mon Sep 17 00:00:00 2001 From: charujain Date: Thu, 13 Jul 2017 07:06:39 -0700 Subject: [PATCH] Revert of Make the default ctor of rtc::Thread, protected (patchset #3 id:40001 of https://codereview.webrtc.org/2981623002/ ) Reason for revert: Break projects. Original issue's description: > Make the default ctor of rtc::Thread, protected. > The goal is to force use of Thread::Create or Thread::CreateWithSocketServer. > > The default constructor constructs a 'default' socket server, which is usually a 'physical' socket server, but not always. Not every instance of Thread actually needs to have network support, so it's better to have this be explicit instead of unknowingly instantiate one. > > BUG=none > > Review-Url: https://codereview.webrtc.org/2981623002 > Cr-Commit-Position: refs/heads/master@{#19001} > Committed: https://chromium.googlesource.com/external/webrtc/+/a8a351599788f346a2265cfcd3da9a06f577de7f TBR=kthelgason@webrtc.org,tommi@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=none Review-Url: https://codereview.webrtc.org/2979963002 Cr-Commit-Position: refs/heads/master@{#19003} --- webrtc/pc/channelmanager_unittest.cc | 32 ++++--- webrtc/pc/peerconnectionendtoend_unittest.cc | 14 ++- webrtc/pc/peerconnectioninterface_unittest.cc | 9 +- webrtc/pc/proxy_unittest.cc | 26 +++--- webrtc/pc/rtcstats_integrationtest.cc | 15 ++-- webrtc/pc/test/fakeaudiocapturemodule.cc | 2 +- webrtc/rtc_base/criticalsection_unittest.cc | 2 +- webrtc/rtc_base/messagequeue_unittest.cc | 42 ++++----- webrtc/rtc_base/nullsocketserver_unittest.cc | 6 +- .../rtc_base/physicalsocketserver_unittest.cc | 2 +- .../rtccertificategenerator_unittest.cc | 2 +- webrtc/rtc_base/socket_unittest.cc | 2 +- webrtc/rtc_base/thread.h | 5 +- webrtc/rtc_base/thread_unittest.cc | 86 ++++++++++--------- webrtc/rtc_base/timeutils_unittest.cc | 8 +- .../src/jni/androidmediadecoder_jni.cc | 39 ++++----- 16 files changed, 142 insertions(+), 150 deletions(-) diff --git a/webrtc/pc/channelmanager_unittest.cc b/webrtc/pc/channelmanager_unittest.cc index b322407b46..c03056c637 100644 --- a/webrtc/pc/channelmanager_unittest.cc +++ b/webrtc/pc/channelmanager_unittest.cc @@ -38,9 +38,7 @@ static const VideoCodec kVideoCodecs[] = { class ChannelManagerTest : public testing::Test { protected: ChannelManagerTest() - : network_(rtc::Thread::CreateWithSocketServer()), - worker_(rtc::Thread::Create()), - fme_(new cricket::FakeMediaEngine()), + : fme_(new cricket::FakeMediaEngine()), fdme_(new cricket::FakeDataEngine()), cm_(new cricket::ChannelManager( std::unique_ptr(fme_), @@ -54,8 +52,8 @@ class ChannelManagerTest : public testing::Test { } webrtc::RtcEventLogNullImpl event_log_; - std::unique_ptr network_; - std::unique_ptr worker_; + rtc::Thread network_; + rtc::Thread worker_; // |fme_| and |fdme_| are actually owned by |cm_|. cricket::FakeMediaEngine* fme_; cricket::FakeDataEngine* fdme_; @@ -76,14 +74,14 @@ TEST_F(ChannelManagerTest, StartupShutdown) { // Test that we startup/shutdown properly with a worker thread. TEST_F(ChannelManagerTest, StartupShutdownOnThread) { - network_->Start(); - worker_->Start(); + network_.Start(); + worker_.Start(); EXPECT_FALSE(cm_->initialized()); EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); - EXPECT_TRUE(cm_->set_network_thread(network_.get())); - EXPECT_EQ(network_.get(), cm_->network_thread()); - EXPECT_TRUE(cm_->set_worker_thread(worker_.get())); - EXPECT_EQ(worker_.get(), cm_->worker_thread()); + EXPECT_TRUE(cm_->set_network_thread(&network_)); + EXPECT_EQ(&network_, cm_->network_thread()); + EXPECT_TRUE(cm_->set_worker_thread(&worker_)); + EXPECT_EQ(&worker_, cm_->worker_thread()); EXPECT_TRUE(cm_->Init()); EXPECT_TRUE(cm_->initialized()); // Setting the network or worker thread while initialized should fail. @@ -123,13 +121,13 @@ TEST_F(ChannelManagerTest, CreateDestroyChannels) { // Test that we can create and destroy a voice and video channel with a worker. TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { - network_->Start(); - worker_->Start(); - EXPECT_TRUE(cm_->set_worker_thread(worker_.get())); - EXPECT_TRUE(cm_->set_network_thread(network_.get())); + network_.Start(); + worker_.Start(); + EXPECT_TRUE(cm_->set_worker_thread(&worker_)); + EXPECT_TRUE(cm_->set_network_thread(&network_)); EXPECT_TRUE(cm_->Init()); - transport_controller_.reset(new cricket::FakeTransportController( - network_.get(), ICEROLE_CONTROLLING)); + transport_controller_.reset( + new cricket::FakeTransportController(&network_, ICEROLE_CONTROLLING)); cricket::DtlsTransportInternal* rtp_transport = transport_controller_->CreateDtlsTransport( cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP); diff --git a/webrtc/pc/peerconnectionendtoend_unittest.cc b/webrtc/pc/peerconnectionendtoend_unittest.cc index f7cd91f00e..c83235229d 100644 --- a/webrtc/pc/peerconnectionendtoend_unittest.cc +++ b/webrtc/pc/peerconnectionendtoend_unittest.cc @@ -54,14 +54,12 @@ class PeerConnectionEndToEndTest DataChannelList; PeerConnectionEndToEndTest() { - network_thread_ = rtc::Thread::CreateWithSocketServer(); - worker_thread_ = rtc::Thread::Create(); - RTC_CHECK(network_thread_->Start()); - RTC_CHECK(worker_thread_->Start()); + RTC_CHECK(network_thread_.Start()); + RTC_CHECK(worker_thread_.Start()); caller_ = new rtc::RefCountedObject( - "caller", network_thread_.get(), worker_thread_.get()); + "caller", &network_thread_, &worker_thread_); callee_ = new rtc::RefCountedObject( - "callee", network_thread_.get(), worker_thread_.get()); + "callee", &network_thread_, &worker_thread_); webrtc::PeerConnectionInterface::IceServer ice_server; ice_server.uri = "stun:stun.l.google.com:19302"; config_.servers.push_back(ice_server); @@ -167,8 +165,8 @@ class PeerConnectionEndToEndTest } protected: - std::unique_ptr network_thread_; - std::unique_ptr worker_thread_; + rtc::Thread network_thread_; + rtc::Thread worker_thread_; rtc::scoped_refptr caller_; rtc::scoped_refptr callee_; DataChannelList caller_signaled_data_channels_; diff --git a/webrtc/pc/peerconnectioninterface_unittest.cc b/webrtc/pc/peerconnectioninterface_unittest.cc index 59ed2e4b28..c10324a94b 100644 --- a/webrtc/pc/peerconnectioninterface_unittest.cc +++ b/webrtc/pc/peerconnectioninterface_unittest.cc @@ -1278,15 +1278,14 @@ TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) { // and on the correct thread. TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionInitializesPortAllocator) { - std::unique_ptr network_thread( - rtc::Thread::CreateWithSocketServer()); - network_thread->Start(); + rtc::Thread network_thread; + network_thread.Start(); rtc::scoped_refptr pc_factory( webrtc::CreatePeerConnectionFactory( - network_thread.get(), rtc::Thread::Current(), rtc::Thread::Current(), + &network_thread, rtc::Thread::Current(), rtc::Thread::Current(), nullptr, nullptr, nullptr)); std::unique_ptr port_allocator( - new cricket::FakePortAllocator(network_thread.get(), nullptr)); + new cricket::FakePortAllocator(&network_thread, nullptr)); cricket::FakePortAllocator* raw_port_allocator = port_allocator.get(); PeerConnectionInterface::RTCConfiguration config; rtc::scoped_refptr pc( diff --git a/webrtc/pc/proxy_unittest.cc b/webrtc/pc/proxy_unittest.cc index c21599d351..0d97c4174f 100644 --- a/webrtc/pc/proxy_unittest.cc +++ b/webrtc/pc/proxy_unittest.cc @@ -95,7 +95,7 @@ class SignalingProxyTest : public testing::Test { protected: void SetUp() override { - signaling_thread_ = rtc::Thread::Create(); + signaling_thread_.reset(new rtc::Thread()); ASSERT_TRUE(signaling_thread_->Start()); fake_ = Fake::Create(); fake_signaling_proxy_ = @@ -182,8 +182,8 @@ class ProxyTest : public testing::Test { protected: void SetUp() override { - signaling_thread_ = rtc::Thread::Create(); - worker_thread_ = rtc::Thread::Create(); + signaling_thread_.reset(new rtc::Thread()); + worker_thread_.reset(new rtc::Thread()); ASSERT_TRUE(signaling_thread_->Start()); ASSERT_TRUE(worker_thread_->Start()); fake_ = Fake::Create(); @@ -283,22 +283,20 @@ END_PROXY_MAP() class OwnedProxyTest : public testing::Test { public: OwnedProxyTest() - : signaling_thread_(rtc::Thread::Create()), - worker_thread_(rtc::Thread::Create()), - foo_(new Foo()), - foo_proxy_(FooProxy::Create(signaling_thread_.get(), - worker_thread_.get(), + : foo_(new Foo()), + foo_proxy_(FooProxy::Create(&signaling_thread_, + &worker_thread_, std::unique_ptr(foo_))) { - signaling_thread_->Start(); - worker_thread_->Start(); + signaling_thread_.Start(); + worker_thread_.Start(); } - void CheckSignalingThread() { EXPECT_TRUE(signaling_thread_->IsCurrent()); } - void CheckWorkerThread() { EXPECT_TRUE(worker_thread_->IsCurrent()); } + void CheckSignalingThread() { EXPECT_TRUE(signaling_thread_.IsCurrent()); } + void CheckWorkerThread() { EXPECT_TRUE(worker_thread_.IsCurrent()); } protected: - std::unique_ptr signaling_thread_; - std::unique_ptr worker_thread_; + rtc::Thread signaling_thread_; + rtc::Thread worker_thread_; Foo* foo_; // Owned by foo_proxy_, not this class. std::unique_ptr foo_proxy_; }; diff --git a/webrtc/pc/rtcstats_integrationtest.cc b/webrtc/pc/rtcstats_integrationtest.cc index 3dffb8d713..3d1e7d66ea 100644 --- a/webrtc/pc/rtcstats_integrationtest.cc +++ b/webrtc/pc/rtcstats_integrationtest.cc @@ -34,15 +34,14 @@ const int64_t kGetStatsTimeoutMs = 10000; class RTCStatsIntegrationTest : public testing::Test { public: RTCStatsIntegrationTest() - : network_thread_(new rtc::Thread(&virtual_socket_server_)), - worker_thread_(rtc::Thread::Create()) { - RTC_CHECK(network_thread_->Start()); - RTC_CHECK(worker_thread_->Start()); + : network_thread_(&virtual_socket_server_), worker_thread_() { + RTC_CHECK(network_thread_.Start()); + RTC_CHECK(worker_thread_.Start()); caller_ = new rtc::RefCountedObject( - "caller", network_thread_.get(), worker_thread_.get()); + "caller", &network_thread_, &worker_thread_); callee_ = new rtc::RefCountedObject( - "callee", network_thread_.get(), worker_thread_.get()); + "callee", &network_thread_, &worker_thread_); } void StartCall() { @@ -97,8 +96,8 @@ class RTCStatsIntegrationTest : public testing::Test { // |network_thread_| uses |virtual_socket_server_| so they must be // constructed/destructed in the correct order. rtc::VirtualSocketServer virtual_socket_server_; - std::unique_ptr network_thread_; - std::unique_ptr worker_thread_; + rtc::Thread network_thread_; + rtc::Thread worker_thread_; rtc::scoped_refptr caller_; rtc::scoped_refptr callee_; }; diff --git a/webrtc/pc/test/fakeaudiocapturemodule.cc b/webrtc/pc/test/fakeaudiocapturemodule.cc index 5812d3900f..4bc6e4faec 100644 --- a/webrtc/pc/test/fakeaudiocapturemodule.cc +++ b/webrtc/pc/test/fakeaudiocapturemodule.cc @@ -624,7 +624,7 @@ bool FakeAudioCaptureModule::ShouldStartProcessing() { void FakeAudioCaptureModule::UpdateProcessing(bool start) { if (start) { if (!process_thread_) { - process_thread_ = rtc::Thread::Create(); + process_thread_.reset(new rtc::Thread()); process_thread_->Start(); } process_thread_->Post(RTC_FROM_HERE, this, MSG_START_PROCESS); diff --git a/webrtc/rtc_base/criticalsection_unittest.cc b/webrtc/rtc_base/criticalsection_unittest.cc index 2e136bf804..672a6746a6 100644 --- a/webrtc/rtc_base/criticalsection_unittest.cc +++ b/webrtc/rtc_base/criticalsection_unittest.cc @@ -201,7 +201,7 @@ struct CompareAndSwapOp { void StartThreads(std::vector>* threads, MessageHandler* handler) { for (int i = 0; i < kNumThreads; ++i) { - std::unique_ptr thread(Thread::Create()); + std::unique_ptr thread(new Thread()); thread->Start(); thread->Post(RTC_FROM_HERE, handler); threads->push_back(std::move(thread)); diff --git a/webrtc/rtc_base/messagequeue_unittest.cc b/webrtc/rtc_base/messagequeue_unittest.cc index 4003e2ddcd..e31adf9549 100644 --- a/webrtc/rtc_base/messagequeue_unittest.cc +++ b/webrtc/rtc_base/messagequeue_unittest.cc @@ -38,9 +38,9 @@ class MessageQueueTest: public testing::Test, public MessageQueue { bool IsLocked() { // We have to do this on a worker thread, or else the TryEnter will // succeed, since our critical sections are reentrant. - std::unique_ptr worker(Thread::CreateWithSocketServer()); - worker->Start(); - return worker->Invoke( + Thread worker; + worker.Start(); + return worker.Invoke( RTC_FROM_HERE, rtc::Bind(&MessageQueueTest::IsLocked_Worker, this)); } }; @@ -152,10 +152,10 @@ TEST(MessageQueueManager, Clear) { // all registered message queues. TEST(MessageQueueManager, ProcessAllMessageQueues) { Event entered_process_all_message_queues(true, false); - auto a = Thread::CreateWithSocketServer(); - auto b = Thread::CreateWithSocketServer(); - a->Start(); - b->Start(); + Thread a; + Thread b; + a.Start(); + b.Start(); volatile int messages_processed = 0; FunctorMessageHandler> incrementer( @@ -173,10 +173,10 @@ TEST(MessageQueueManager, ProcessAllMessageQueues) { }); // Post messages (both delayed and non delayed) to both threads. - a->Post(RTC_FROM_HERE, &incrementer); - b->Post(RTC_FROM_HERE, &incrementer); - a->PostDelayed(RTC_FROM_HERE, 0, &incrementer); - b->PostDelayed(RTC_FROM_HERE, 0, &incrementer); + a.Post(RTC_FROM_HERE, &incrementer); + b.Post(RTC_FROM_HERE, &incrementer); + a.PostDelayed(RTC_FROM_HERE, 0, &incrementer); + b.PostDelayed(RTC_FROM_HERE, 0, &incrementer); rtc::Thread::Current()->Post(RTC_FROM_HERE, &event_signaler); MessageQueueManager::ProcessAllMessageQueues(); @@ -185,9 +185,9 @@ TEST(MessageQueueManager, ProcessAllMessageQueues) { // Test that ProcessAllMessageQueues doesn't hang if a thread is quitting. TEST(MessageQueueManager, ProcessAllMessageQueuesWithQuittingThread) { - auto t = Thread::CreateWithSocketServer(); - t->Start(); - t->Quit(); + Thread t; + t.Start(); + t.Quit(); MessageQueueManager::ProcessAllMessageQueues(); } @@ -195,8 +195,8 @@ TEST(MessageQueueManager, ProcessAllMessageQueuesWithQuittingThread) { // messages. TEST(MessageQueueManager, ProcessAllMessageQueuesWithClearedQueue) { Event entered_process_all_message_queues(true, false); - auto t = Thread::CreateWithSocketServer(); - t->Start(); + Thread t; + t.Start(); FunctorMessageHandler> clearer( [&entered_process_all_message_queues] { @@ -213,7 +213,7 @@ TEST(MessageQueueManager, ProcessAllMessageQueuesWithClearedQueue) { }); // Post messages (both delayed and non delayed) to both threads. - t->Post(RTC_FROM_HERE, &clearer); + t.Post(RTC_FROM_HERE, &clearer); rtc::Thread::Current()->Post(RTC_FROM_HERE, &event_signaler); MessageQueueManager::ProcessAllMessageQueues(); } @@ -231,7 +231,7 @@ class EmptyHandler : public MessageHandler { }; TEST(MessageQueueManager, ClearReentrant) { - std::unique_ptr t(Thread::Create()); + Thread t; EmptyHandler handler; RefCountedHandler* inner_handler( new rtc::RefCountedObject()); @@ -242,7 +242,7 @@ TEST(MessageQueueManager, ClearReentrant) { // The inner handler will be removed in a re-entrant fashion from the // message queue of the thread while the outer handler is removed, verifying // that the iterator is not invalidated in "MessageQueue::Clear". - t->Post(RTC_FROM_HERE, inner_handler, 0); - t->Post(RTC_FROM_HERE, &handler, 0, - new ScopedRefMessageData(inner_handler)); + t.Post(RTC_FROM_HERE, inner_handler, 0); + t.Post(RTC_FROM_HERE, &handler, 0, + new ScopedRefMessageData(inner_handler)); } diff --git a/webrtc/rtc_base/nullsocketserver_unittest.cc b/webrtc/rtc_base/nullsocketserver_unittest.cc index 5538322643..5908d32958 100644 --- a/webrtc/rtc_base/nullsocketserver_unittest.cc +++ b/webrtc/rtc_base/nullsocketserver_unittest.cc @@ -28,9 +28,9 @@ class NullSocketServerTest }; TEST_F(NullSocketServerTest, WaitAndSet) { - auto thread = Thread::Create(); - EXPECT_TRUE(thread->Start()); - thread->Post(RTC_FROM_HERE, this, 0); + Thread thread; + EXPECT_TRUE(thread.Start()); + thread.Post(RTC_FROM_HERE, this, 0); // The process_io will be ignored. const bool process_io = true; EXPECT_TRUE_WAIT(ss_.Wait(SocketServer::kForever, process_io), kTimeout); diff --git a/webrtc/rtc_base/physicalsocketserver_unittest.cc b/webrtc/rtc_base/physicalsocketserver_unittest.cc index 34ba027897..ee95c2367a 100644 --- a/webrtc/rtc_base/physicalsocketserver_unittest.cc +++ b/webrtc/rtc_base/physicalsocketserver_unittest.cc @@ -610,7 +610,7 @@ TEST_F(PosixSignalDeliveryTest, SignalOnDifferentThread) { // Start a new thread that raises it. It will have to be delivered to that // thread. Our implementation should safely handle it and dispatch // RecordSignal() on this thread. - std::unique_ptr thread(Thread::CreateWithSocketServer()); + std::unique_ptr thread(new Thread()); std::unique_ptr runnable(new RaiseSigTermRunnable()); thread->Start(runnable.get()); EXPECT_TRUE(ss_->Wait(1500, true)); diff --git a/webrtc/rtc_base/rtccertificategenerator_unittest.cc b/webrtc/rtc_base/rtccertificategenerator_unittest.cc index df820d93cc..f09f797974 100644 --- a/webrtc/rtc_base/rtccertificategenerator_unittest.cc +++ b/webrtc/rtc_base/rtccertificategenerator_unittest.cc @@ -24,7 +24,7 @@ class RTCCertificateGeneratorFixture : public RTCCertificateGeneratorCallback { public: RTCCertificateGeneratorFixture() : signaling_thread_(Thread::Current()), - worker_thread_(Thread::Create()), + worker_thread_(new Thread()), generate_async_completed_(false) { RTC_CHECK(signaling_thread_); RTC_CHECK(worker_thread_->Start()); diff --git a/webrtc/rtc_base/socket_unittest.cc b/webrtc/rtc_base/socket_unittest.cc index 5ef01679ff..35bf2d1c4d 100644 --- a/webrtc/rtc_base/socket_unittest.cc +++ b/webrtc/rtc_base/socket_unittest.cc @@ -681,7 +681,7 @@ void SocketTest::SocketServerWaitInternal(const IPAddress& loopback) { EXPECT_FALSE(sink.Check(accepted.get(), SSE_READ)); // Shouldn't signal when blocked in a thread Send, where process_io is false. - std::unique_ptr thread(Thread::CreateWithSocketServer()); + std::unique_ptr thread(new Thread()); thread->Start(); Sleeper sleeper; TypedMessageData data(client.get()); diff --git a/webrtc/rtc_base/thread.h b/webrtc/rtc_base/thread.h index 72f15fde1c..35b28eac53 100644 --- a/webrtc/rtc_base/thread.h +++ b/webrtc/rtc_base/thread.h @@ -101,10 +101,9 @@ class Runnable { // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread(). class LOCKABLE Thread : public MessageQueue { - protected: - Thread(); - public: + // Create a new Thread and optionally assign it to the passed SocketServer. + Thread(); explicit Thread(SocketServer* ss); explicit Thread(std::unique_ptr ss); diff --git a/webrtc/rtc_base/thread_unittest.cc b/webrtc/rtc_base/thread_unittest.cc index f5cf347f67..db7d038172 100644 --- a/webrtc/rtc_base/thread_unittest.cc +++ b/webrtc/rtc_base/thread_unittest.cc @@ -195,24 +195,24 @@ TEST(ThreadTest, DISABLED_Main) { const SocketAddress addr("127.0.0.1", 0); // Create the messaging client on its own thread. - auto th1 = Thread::CreateWithSocketServer(); - Socket* socket = - th1->socketserver()->CreateAsyncSocket(addr.family(), SOCK_DGRAM); - MessageClient msg_client(th1.get(), socket); + Thread th1; + Socket* socket = th1.socketserver()->CreateAsyncSocket(addr.family(), + SOCK_DGRAM); + MessageClient msg_client(&th1, socket); // Create the socket client on its own thread. - auto th2 = Thread::CreateWithSocketServer(); + Thread th2; AsyncSocket* asocket = - th2->socketserver()->CreateAsyncSocket(addr.family(), SOCK_DGRAM); - SocketClient sock_client(asocket, addr, th1.get(), &msg_client); + th2.socketserver()->CreateAsyncSocket(addr.family(), SOCK_DGRAM); + SocketClient sock_client(asocket, addr, &th1, &msg_client); socket->Connect(sock_client.address()); - th1->Start(); - th2->Start(); + th1.Start(); + th2.Start(); // Get the messages started. - th1->PostDelayed(RTC_FROM_HERE, 100, &msg_client, 0, new TestMessage(1)); + th1.PostDelayed(RTC_FROM_HERE, 100, &msg_client, 0, new TestMessage(1)); // Give the clients a little while to run. // Messages will be processed at 100, 300, 500, 700, 900. @@ -221,9 +221,9 @@ TEST(ThreadTest, DISABLED_Main) { // Stop the sending client. Give the receiver a bit longer to run, in case // it is running on a machine that is under load (e.g. the build machine). - th1->Stop(); + th1.Stop(); th_main->ProcessMessages(200); - th2->Stop(); + th2.Stop(); // Make sure the results were correct EXPECT_EQ(5, msg_client.count); @@ -236,19 +236,23 @@ TEST(ThreadTest, DISABLED_Main) { // There's no easy way to verify the name was set properly at this time. TEST(ThreadTest, Names) { // Default name - auto thread = Thread::CreateWithSocketServer(); + Thread *thread; + thread = new Thread(); EXPECT_TRUE(thread->Start()); thread->Stop(); + delete thread; + thread = new Thread(); // Name with no object parameter - thread = Thread::CreateWithSocketServer(); EXPECT_TRUE(thread->SetName("No object", nullptr)); EXPECT_TRUE(thread->Start()); thread->Stop(); + delete thread; // Really long name - thread = Thread::CreateWithSocketServer(); + thread = new Thread(); EXPECT_TRUE(thread->SetName("Abcdefghijklmnopqrstuvwxyz1234567890", this)); EXPECT_TRUE(thread->Start()); thread->Stop(); + delete thread; } TEST(ThreadTest, Wrap) { @@ -266,21 +270,21 @@ TEST(ThreadTest, Wrap) { TEST(ThreadTest, Invoke) { // Create and start the thread. - auto thread = Thread::CreateWithSocketServer(); - thread->Start(); + Thread thread; + thread.Start(); // Try calling functors. - EXPECT_EQ(42, thread->Invoke(RTC_FROM_HERE, FunctorA())); + EXPECT_EQ(42, thread.Invoke(RTC_FROM_HERE, FunctorA())); AtomicBool called; FunctorB f2(&called); - thread->Invoke(RTC_FROM_HERE, f2); + thread.Invoke(RTC_FROM_HERE, f2); EXPECT_TRUE(called.get()); // Try calling bare functions. struct LocalFuncs { static int Func1() { return 999; } static void Func2() {} }; - EXPECT_EQ(999, thread->Invoke(RTC_FROM_HERE, &LocalFuncs::Func1)); - thread->Invoke(RTC_FROM_HERE, &LocalFuncs::Func2); + EXPECT_EQ(999, thread.Invoke(RTC_FROM_HERE, &LocalFuncs::Func1)); + thread.Invoke(RTC_FROM_HERE, &LocalFuncs::Func2); } // Verifies that two threads calling Invoke on each other at the same time does @@ -290,8 +294,8 @@ TEST(ThreadTest, TwoThreadsInvokeNoDeadlock) { Thread* current_thread = Thread::Current(); ASSERT_TRUE(current_thread != nullptr); - auto other_thread = Thread::CreateWithSocketServer(); - other_thread->Start(); + Thread other_thread; + other_thread.Start(); struct LocalFuncs { static void Set(bool* out) { *out = true; } @@ -301,7 +305,7 @@ TEST(ThreadTest, TwoThreadsInvokeNoDeadlock) { }; bool called = false; - other_thread->Invoke( + other_thread.Invoke( RTC_FROM_HERE, Bind(&LocalFuncs::InvokeSet, current_thread, &called)); EXPECT_TRUE(called); @@ -313,10 +317,9 @@ TEST(ThreadTest, TwoThreadsInvokeNoDeadlock) { TEST(ThreadTest, ThreeThreadsInvoke) { AutoThread thread; Thread* thread_a = Thread::Current(); - auto thread_b = Thread::CreateWithSocketServer(); - auto thread_c = Thread::CreateWithSocketServer(); - thread_b->Start(); - thread_c->Start(); + Thread thread_b, thread_c; + thread_b.Start(); + thread_c.Start(); class LockedBool { public: @@ -374,9 +377,9 @@ TEST(ThreadTest, ThreeThreadsInvoke) { // Start the sequence A --(invoke)--> B --(async invoke)--> C --(invoke)--> A. // Thread B returns when C receives the call and C should be blocked until A // starts to process messages. - thread_b->Invoke(RTC_FROM_HERE, - Bind(&LocalFuncs::AsyncInvokeSetAndWait, &invoker, - thread_c.get(), thread_a, &thread_a_called)); + thread_b.Invoke(RTC_FROM_HERE, + Bind(&LocalFuncs::AsyncInvokeSetAndWait, &invoker, + &thread_c, thread_a, &thread_a_called)); EXPECT_FALSE(thread_a_called.Get()); EXPECT_TRUE_WAIT(thread_a_called.Get(), 2000); @@ -403,9 +406,9 @@ class SetNameOnSignalQueueDestroyedTester : public sigslot::has_slots<> { }; TEST(ThreadTest, SetNameOnSignalQueueDestroyed) { - auto thread1 = Thread::CreateWithSocketServer(); - SetNameOnSignalQueueDestroyedTester tester1(thread1.get()); - thread1.reset(); + Thread* thread1 = new Thread(); + SetNameOnSignalQueueDestroyedTester tester1(thread1); + delete thread1; Thread* thread2 = new AutoThread(); SetNameOnSignalQueueDestroyedTester tester2(thread2); @@ -435,13 +438,12 @@ class AsyncInvokeTest : public testing::Test { TEST_F(AsyncInvokeTest, FireAndForget) { AsyncInvoker invoker; // Create and start the thread. - auto thread = Thread::CreateWithSocketServer(); - thread->Start(); + Thread thread; + thread.Start(); // Try calling functor. AtomicBool called; - invoker.AsyncInvoke(RTC_FROM_HERE, thread.get(), FunctorB(&called)); + invoker.AsyncInvoke(RTC_FROM_HERE, &thread, FunctorB(&called)); EXPECT_TRUE_WAIT(called.get(), kWaitTimeout); - thread->Stop(); } TEST_F(AsyncInvokeTest, KillInvokerDuringExecute) { @@ -452,12 +454,12 @@ TEST_F(AsyncInvokeTest, KillInvokerDuringExecute) { Event functor_continue(false, false); Event functor_finished(false, false); - auto thread = Thread::CreateWithSocketServer(); - thread->Start(); + Thread thread; + thread.Start(); volatile bool invoker_destroyed = false; { AsyncInvoker invoker; - invoker.AsyncInvoke(RTC_FROM_HERE, thread.get(), + invoker.AsyncInvoke(RTC_FROM_HERE, &thread, [&functor_started, &functor_continue, &functor_finished, &invoker_destroyed] { functor_started.Set(); @@ -548,7 +550,7 @@ struct CreateInvoker { // Test that we can call AsyncInvoke() after the thread died. TEST_F(GuardedAsyncInvokeTest, KillThreadFireAndForget) { // Create and start the thread. - std::unique_ptr thread(Thread::Create()); + std::unique_ptr thread(new Thread()); thread->Start(); std::unique_ptr invoker; // Create the invoker on |thread|. diff --git a/webrtc/rtc_base/timeutils_unittest.cc b/webrtc/rtc_base/timeutils_unittest.cc index a409fb679c..5fd94365b1 100644 --- a/webrtc/rtc_base/timeutils_unittest.cc +++ b/webrtc/rtc_base/timeutils_unittest.cc @@ -349,8 +349,8 @@ TEST(FakeClock, SettingTimeWakesThreads) { FakeClock clock; SetClockForTesting(&clock); - std::unique_ptr worker(Thread::CreateWithSocketServer()); - worker->Start(); + Thread worker; + worker.Start(); // Post an event that won't be executed for 10 seconds. Event message_handler_dispatched(false, false); @@ -358,7 +358,7 @@ TEST(FakeClock, SettingTimeWakesThreads) { message_handler_dispatched.Set(); }; FunctorMessageHandler handler(functor); - worker->PostDelayed(RTC_FROM_HERE, 60000, &handler); + worker.PostDelayed(RTC_FROM_HERE, 60000, &handler); // Wait for a bit for the worker thread to be started and enter its socket // select(). Otherwise this test would be trivial since the worker thread @@ -369,7 +369,7 @@ TEST(FakeClock, SettingTimeWakesThreads) { // and dispatch the message instantly. clock.AdvanceTime(TimeDelta::FromSeconds(60u)); EXPECT_TRUE(message_handler_dispatched.Wait(0)); - worker->Stop(); + worker.Stop(); SetClockForTesting(nullptr); diff --git a/webrtc/sdk/android/src/jni/androidmediadecoder_jni.cc b/webrtc/sdk/android/src/jni/androidmediadecoder_jni.cc index 3e9f80fd42..cae9b8f4a4 100644 --- a/webrtc/sdk/android/src/jni/androidmediadecoder_jni.cc +++ b/webrtc/sdk/android/src/jni/androidmediadecoder_jni.cc @@ -55,7 +55,7 @@ namespace webrtc_jni { // Logging macros. #define TAG_DECODER "MediaCodecVideoDecoder" #ifdef TRACK_BUFFER_TIMING -#define ALOGV(...) \ +#define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG_DECODER, __VA_ARGS__) #else #define ALOGV(...) @@ -180,25 +180,24 @@ class MediaCodecVideoDecoder : public webrtc::VideoDecoder, std::vector input_buffers_; }; -MediaCodecVideoDecoder::MediaCodecVideoDecoder(JNIEnv* jni, - VideoCodecType codecType, - jobject render_egl_context) - : codecType_(codecType), - render_egl_context_(render_egl_context), - key_frame_required_(true), - inited_(false), - sw_fallback_required_(false), - codec_thread_(Thread::Create()), - j_media_codec_video_decoder_class_( - jni, - FindClass(jni, "org/webrtc/MediaCodecVideoDecoder")), - j_media_codec_video_decoder_( - jni, - jni->NewObject(*j_media_codec_video_decoder_class_, - GetMethodID(jni, - *j_media_codec_video_decoder_class_, - "", - "()V"))) { +MediaCodecVideoDecoder::MediaCodecVideoDecoder( + JNIEnv* jni, VideoCodecType codecType, jobject render_egl_context) : + codecType_(codecType), + render_egl_context_(render_egl_context), + key_frame_required_(true), + inited_(false), + sw_fallback_required_(false), + codec_thread_(new Thread()), + j_media_codec_video_decoder_class_( + jni, + FindClass(jni, "org/webrtc/MediaCodecVideoDecoder")), + j_media_codec_video_decoder_( + jni, + jni->NewObject(*j_media_codec_video_decoder_class_, + GetMethodID(jni, + *j_media_codec_video_decoder_class_, + "", + "()V"))) { codec_thread_->SetName("MediaCodecVideoDecoder", NULL); RTC_CHECK(codec_thread_->Start()) << "Failed to start MediaCodecVideoDecoder";