Mojiificaiton of the audio output device: using mojo from different thread

31 views
Skip to first unread message

Riadh Chtara

unread,
Mar 21, 2016, 8:59:02 AM3/21/16
to mojo-dev
Hello,
I'm Riadh Chtara. I'm interning with the chrome audio integration team.
I will work on mojiificaiton of the audio output device.
So to start, we created  a dummy mojo service and client that was based on this cl:
And it was working perfectly, however when we started calling mojo from AudioMessageFilter::AudioOutputIPCImpl::CreateStream instead from  RenderThreadImpl::RenderThreadImpl
The browser crash and we get this: (which we think means it's not possible to use mojo from the thread which called  AudioMessageFilter::AudioOutputIPCImpl::CreateStream)


[1:14:0321/133923:ERROR:audio_message_filter.cc(127)] Start establish MOJO
[1:14:0321/133923:ERROR:audio_message_filter.cc(130)] test
[1:2:0321/133923:FATAL:router.cc(108)] Check failed: thread_checker_.CalledOnValidThread(). 
#0 0x7fab3a44222e base::debug::StackTrace::StackTrace()
#1 0x7fab3a4806af logging::LogMessage::~LogMessage()
#2 0x7fab32d23e6b mojo::internal::Router::Accept()
#3 0x7fab33caee93 content::AudioDebugRecordingProxy::RegisterObserver()
#4 0x7fab39c9b06f content::AudioDebugRecorder::RegisterObserver()
#5 0x7fab39ca41f8 content::AudioMessageFilter::AudioOutputIPCImpl::CreateStream()
#6 0x7fab328119d4 media::AudioOutputDevice::CreateStreamOnIOThread()
#7 0x7fab2f3003b1 _ZN4base8internal15RunnableAdapterIMN7banners20AppBannerDataFetcherEFvRK8SkBitmapEE3RunIJS6_EEEvPS3_DpOT_
#8 0x7fab2f300321 _ZN4base8internal12InvokeHelperILb0EvNS0_15RunnableAdapterIMN7banners20AppBannerDataFetcherEFvRK8SkBitmapEEEE8MakeItSoIJPS4_S7_EEEvSA_DpOT_
#9 0x7fab328154b0 _ZN4base8internal7InvokerINS_13IndexSequenceIJLm0ELm1EEEENS0_9BindStateINS0_15RunnableAdapterIMN5media17AudioOutputDeviceEFvRKNS6_15AudioParametersEEEEFvPS7_SA_EJSE_RS8_EEENS0_12InvokeHelperILb0EvSD_EEFvvEE3RunEPNS0_13BindStateBaseE
#10 0x7fab2f2ebe6e base::Callback<>::Run()
#11 0x7fab3a44520e base::debug::TaskAnnotator::RunTask()
#12 0x7fab3a4961cf base::MessageLoop::RunTask()
#13 0x7fab3a496458 base::MessageLoop::DeferOrRunPendingTask()
#14 0x7fab3a496622 base::MessageLoop::DoWork()
#15 0x7fab3a4a564e base::MessagePumpLibevent::Run()
#16 0x7fab3a495bff base::MessageLoop::RunHandler()
#17 0x7fab3a508fe4 base::RunLoop::Run()
#18 0x7fab3a494ca4 base::MessageLoop::Run()
#19 0x7fab3a56a5e9 base::Thread::Run()
#20 0x7fab3a56a939 base::Thread::ThreadMain()
#21 0x7fab3a5592fa base::(anonymous namespace)::ThreadFunc()
#22 0x7fab29a20182 start_thread
#23 0x7fab265a347d clone

Received signal 6
#0 0x7fab3a44222e base::debug::StackTrace::StackTrace()
#1 0x7fab3a441d6f base::debug::(anonymous namespace)::StackDumpSignalHandler()
#2 0x7fab29a28340 <unknown>
#3 0x7fab264dfcc9 gsignal
#4 0x7fab264e30d8 abort
#5 0x7fab3a441246 base::debug::(anonymous namespace)::DebugBreak()
#6 0x7fab3a441228 base::debug::BreakDebugger()
#7 0x7fab3a4809fd logging::LogMessage::~LogMessage()
#8 0x7fab32d23e6b mojo::internal::Router::Accept()
#9 0x7fab33caee93 content::AudioDebugRecordingProxy::RegisterObserver()
#10 0x7fab39c9b06f content::AudioDebugRecorder::RegisterObserver()
#11 0x7fab39ca41f8 content::AudioMessageFilter::AudioOutputIPCImpl::CreateStream()
#12 0x7fab328119d4 media::AudioOutputDevice::CreateStreamOnIOThread()
#13 0x7fab2f3003b1 _ZN4base8internal15RunnableAdapterIMN7banners20AppBannerDataFetcherEFvRK8SkBitmapEE3RunIJS6_EEEvPS3_DpOT_
#14 0x7fab2f300321 _ZN4base8internal12InvokeHelperILb0EvNS0_15RunnableAdapterIMN7banners20AppBannerDataFetcherEFvRK8SkBitmapEEEE8MakeItSoIJPS4_S7_EEEvSA_DpOT_
#15 0x7fab328154b0 _ZN4base8internal7InvokerINS_13IndexSequenceIJLm0ELm1EEEENS0_9BindStateINS0_15RunnableAdapterIMN5media17AudioOutputDeviceEFvRKNS6_15AudioParametersEEEEFvPS7_SA_EJSE_RS8_EEENS0_12InvokeHelperILb0EvSD_EEFvvEE3RunEPNS0_13BindStateBaseE
#16 0x7fab2f2ebe6e base::Callback<>::Run()
#17 0x7fab3a44520e base::debug::TaskAnnotator::RunTask()
#18 0x7fab3a4961cf base::MessageLoop::RunTask()
#19 0x7fab3a496458 base::MessageLoop::DeferOrRunPendingTask()
#20 0x7fab3a496622 base::MessageLoop::DoWork()
#21 0x7fab3a4a564e base::MessagePumpLibevent::Run()
#22 0x7fab3a495bff base::MessageLoop::RunHandler()
#23 0x7fab3a508fe4 base::RunLoop::Run()
#24 0x7fab3a494ca4 base::MessageLoop::Run()
#25 0x7fab3a56a5e9 base::Thread::Run()
#26 0x7fab3a56a939 base::Thread::ThreadMain()
#27 0x7fab3a5592fa base::(anonymous namespace)::ThreadFunc()
#28 0x7fab29a20182 start_thread
#29 0x7fab265a347d clone
  r8: 0000000000000001  r9: 00007fab265f9e00 r10: 0000000000000008 r11: 0000000000000202
 r12: 0000000000000000 r13: 0000000000000000 r14: 00007fab201b69c0 r15: 00007fab201b6700
  di: 0000000000000001  si: 0000000000000002  bp: 00007fab201b3a70  bx: 00007fab201b6700
  dx: 0000000000000006  ax: 0000000000000000  cx: ffffffffffffffff  sp: 00007fab201b3938
  ip: 00007fab264dfcc9 efl: 0000000000000202 cgf: 0000000000000033 erf: 0000000000000000
 trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
[10932:10932:0321/133929:ERROR:process_metrics_linux.cc(136)] opendir(/proc/0/task): No such file or directory
[10932:10932:0321/133930:WARNING:pref_notifier_impl.cc(27)] pref observer found at shutdown plugins.always_authorize
[10932:10932:0321/133930:WARNING:pref_notifier_impl.cc(27)] pref observer found at shutdown plugins.allow_outdated
[10932:10932:0321/133930:WARNING:pref_notifier_impl.cc(27)] pref observer found at shutdown printing.enabled




 If  we call mojo from base::MessageLoop::current()->task_runner() thread like this, it works:

void AudioDebugRecorder::NotifyConsumers(int id) {
  main_thread_task_runner_->PostTask(FROM_HERE, base::Bind(
      &AudioDebugRecorder::NotifyConsumersOnMainThread,
      base::Unretained(this),
      id));
}

void AudioDebugRecorder::NotifyConsumersOnMainThread(
    int id) {
  DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
  service_->RegisterObserver(id);

}

So do you know please if it's possible to call majo from any thread in the rendrer? or It's possible to just use it from base::MessageLoop::current()->task_runner() thread?
Thanks a lot
Riadh
 

Colin Blundell

unread,
Mar 21, 2016, 9:01:28 AM3/21/16
to Riadh Chtara, chromium-mojo
+chromium-mojo 

mojo-dev@ to BCC

Ken Rockot

unread,
Mar 21, 2016, 12:45:11 PM3/21/16
to Riadh Chtara, mojo-dev
It is definitely OK to use Mojo from any thread that has a MessageLoop, but individual bindings objects (instances of mojo::Binding<T> or mojo::InterfacePtr<T>) are not thread-safe. You're hitting a thread-checker which indicates you're trying to use one such object from a thread it doesn't live on.
 
Thanks a lot
Riadh
 

Ken Rockot

unread,
Mar 21, 2016, 12:46:28 PM3/21/16
to Riadh Chtara, mojo-dev
Note that you can pass ownership of bindings objects to another thread if you want to use them from that thread, but then maybe you could just avoid creating them on the wrong thread in the first place. It would be helpful to see some code in any case.

Anand K. Mistry

unread,
Mar 21, 2016, 12:55:28 PM3/21/16
to Ken Rockot, Riadh Chtara, chromium-mojo
mojo-dev to bcc. Please send these to chromium-mojo@

As Ken said, you can only use a binding on the thread that bound it (by calling Bind()). If you can want to call form another thread, you can either post a task, or split your functionality into two interface and bind them to appropriate threads.

P.S. That reminds me, I should try and get that change submitted.

--
You received this message because you are subscribed to the Google Groups "mojo-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojo-dev+u...@chromium.org.



--
Anand K. Mistry
Software Engineer
Google Australia

Anand K. Mistry

unread,
Mar 21, 2016, 12:56:18 PM3/21/16
to Ken Rockot, Riadh Chtara, chromium-mojo
mojo-dev to bcc. Please send these to chromium-mojo@

As Ken said, you can only use a binding on the thread that bound it (by calling Bind()). If you can want to call form another thread, you can either post a task, or split your functionality into two interface and bind them to appropriate threads.

P.S. That reminds me, I should try and get that change submitted.
On 21 March 2016 at 09:46, Ken Rockot <roc...@chromium.org> wrote:
Reply all
Reply to author
Forward
0 new messages