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

Issue 7497025: refactor AudioInputDevice to remove race condition. (Closed)

Created:
9 years, 5 months ago by wjia(left Chromium)
Modified:
9 years, 4 months ago
CC:
chromium-reviews, hclam+watch_chromium.org, ddorwin+watch_chromium.org, fischman+watch_chromium.org, jam, acolwell+watch_chromium.org, annacc+watch_chromium.org, joi+watch-content_chromium.org, ajwong+watch_chromium.org, vrk (LEFT CHROMIUM)
Visibility:
Public.

Description

refactor AudioInputDevice to remove race condition. fix resource loss. refactor API between AudioInputDevice and WebRtcAudioDeviceImpl. The racing condition is: |stream_id_| is accessed from different thread. More specifically, client could call AudioInputDevice::Stop before AudioInputDevice::InitializeOnIOThread, AudioInputDevice::StartOnIOThread or AudioInputDevice::OnLowLatencyCreated is executed. BUG=none TEST=trybots

Patch Set 1 #

Patch Set 2 : add a new thread and keep joinable thread #

Patch Set 3 : support repeating start/stop and fix resource loss #

Patch Set 4 : add comments #

Total comments: 57

Patch Set 5 : code review #

Total comments: 2

Patch Set 6 : code review #

Patch Set 7 : async API #

Patch Set 8 : rebase + minor update #

Total comments: 37

Patch Set 9 : code review #

Unified diffs Side-by-side diffs Delta from patch set Stats (+471 lines, -205 lines) Patch
M content/content_renderer.gypi View 1 2 3 4 5 6 7 2 chunks +2 lines, -0 lines 0 comments Download
M content/renderer/media/audio_input_device.h View 1 2 3 4 5 6 7 8 8 chunks +51 lines, -20 lines 0 comments Download
M content/renderer/media/audio_input_device.cc View 1 2 3 4 5 6 7 5 chunks +123 lines, -57 lines 0 comments Download
A content/renderer/media/audio_input_device_event_handler.h View 1 2 3 4 5 6 7 8 1 chunk +20 lines, -0 lines 0 comments Download
M content/renderer/media/audio_input_message_filter.cc View 1 2 3 4 5 6 7 1 chunk +5 lines, -3 lines 0 comments Download
M content/renderer/media/webrtc_audio_device_impl.h View 1 2 3 4 5 6 7 8 6 chunks +143 lines, -99 lines 0 comments Download
M content/renderer/media/webrtc_audio_device_impl.cc View 1 2 3 4 5 6 7 10 chunks +127 lines, -26 lines 0 comments Download

Messages

Total messages: 15 (0 generated)
henrika_dont_use
Thanks Wei! Added some comments (mainly questions actually). Feels great but there are some areas ...
9 years, 4 months ago (2011-07-30 15:50:59 UTC) #1
henrika_dont_use
Almost forgot. What happened to the thread-priority? We should set a higher prio, right?
9 years, 4 months ago (2011-07-30 15:57:13 UTC) #2
xians
http://codereview.chromium.org/7497025/diff/11001/content/renderer/media/audio_input_device.cc File content/renderer/media/audio_input_device.cc (right): http://codereview.chromium.org/7497025/diff/11001/content/renderer/media/audio_input_device.cc#newcode41 content/renderer/media/audio_input_device.cc:41: capture_thread_.Stop(); It is for thread safety, stream_id_ is only ...
9 years, 4 months ago (2011-08-01 11:41:23 UTC) #3
wjia(left Chromium)
I will refactor ADM as well. After that, the WaitableEvents might be gone. The code ...
9 years, 4 months ago (2011-08-01 22:40:10 UTC) #4
henrika_dont_use
Thanks. Added some minor comments. http://codereview.chromium.org/7497025/diff/15001/content/renderer/media/audio_input_device.h File content/renderer/media/audio_input_device.h (right): http://codereview.chromium.org/7497025/diff/15001/content/renderer/media/audio_input_device.h#newcode108 content/renderer/media/audio_input_device.h:108: // The following methods ...
9 years, 4 months ago (2011-08-02 09:31:57 UTC) #5
wjia(left Chromium)
The refactoring of AudioInputDevice and ADM is done as of Patch Set 7. Now the ...
9 years, 4 months ago (2011-08-04 18:57:53 UTC) #6
henrika_dont_use
Thanks for doing this work Wei, looks nice so far. Added some comments and questions. ...
9 years, 4 months ago (2011-08-07 16:52:26 UTC) #7
scherkus (not reviewing)
Could you describe in the CL comment what the race condition we're solving is? It's ...
9 years, 4 months ago (2011-08-08 21:45:59 UTC) #8
wjia(left Chromium)
http://codereview.chromium.org/7497025/diff/21003/content/content_renderer.gypi File content/content_renderer.gypi (right): http://codereview.chromium.org/7497025/diff/21003/content/content_renderer.gypi#newcode221 content/content_renderer.gypi:221: '../third_party/webrtc/modules/audio_coding/main/source/audio_coding_module.gyp:audio_coding_module', On 2011/08/07 16:52:27, henrika wrote: > Not required ...
9 years, 4 months ago (2011-08-09 01:40:36 UTC) #9
wjia(left Chromium)
On 2011/08/08 21:45:59, scherkus wrote: > Could you describe in the CL comment what the ...
9 years, 4 months ago (2011-08-09 01:48:03 UTC) #10
scherkus (not reviewing)
Random idea... it's definitely more refactoring but I think it should help clean up the ...
9 years, 4 months ago (2011-08-09 21:39:14 UTC) #11
tommi1
I suggest that we start by fixing the race condition without changing the current contract. ...
9 years, 4 months ago (2011-08-09 22:40:15 UTC) #12
henrika_dont_use
Still on vacation; don't want to make too detailed comments. Some general feedback: I like ...
9 years, 4 months ago (2011-08-10 08:18:28 UTC) #13
xians
Hi, I took some time to try out Tommi's proposals today, and I got two ...
9 years, 4 months ago (2011-08-10 19:28:47 UTC) #14
wjia(left Chromium)
9 years, 4 months ago (2011-08-10 23:04:24 UTC) #15
IF it's "really" desired to have a synchronous API (between AudioInputDevice
and ADM), there are several ways to fix the racing condition. But note that
sync API might not work well when AudioInputDevice grows full-fledged, e.g.,
adding error handling code to process errors from browser process. Anyway,
here are the possible fixes for sync API:

fix #1: Change AudioInputDevice::Start() to real sync mode. This is the
easiest, but client has to wait a bit longer during starting. The current
Start() returns after it posts a task to IO thread. But AudioInputDevice is
still in the middle of starting recording by IPC back and forth with browser
process. If Start() can wait till Record message is sent to browser process,
then racing condition is gone since there is no other async message coming
from browser process for now.

fix #2: This will be a bit complicated. Make all member variables accessed
on IO thread. AudioInputDevice::ShutDownOnIOThread also closes socket_ as
its last operation. When audio_thread_ exits, it signals a WaitableEvent
which Stop() is waiting on. Then Stop() joins audio_thread_. Furthermore,
AudioInputDevice needs to handle the timing when Stop() is called. Stop()
could be called before AudioInputDevice::OnLowLatencyCreated is called, or
before AudioInputDevice::StartOnIOThread is called.

Wei

On Wed, Aug 10, 2011 at 12:28 PM, Shijing Xian <xians@google.com> wrote:

>
> Hi,
>
> I took some time to try out Tommi's proposals today, and I got two
> questions and would like to know your opinions on them.
>
> 1, how bad is it to join the audio_thread_ on the IO thread.
> Since the stop command comes from the ADM, we can have the audio_thread_
> Capture callback returns immediately when it detects the call has been
> stopped.
> In this case, the cost on joining the audio_thread_ on IO thread should not
> be much.
>
> In case joining on IO thread is not acceptable.
> 2, can we just use locks on Stop() and OnLowLatencyCreated()?
> Currently we join the audio_thread_ in Stop(), but audio_thread_ is also
> accessed in OnLowLatencyCreated() on IO thread.
> If we can consider using locks on them, we can keep the existing design.
> And since OnLowLatencyCreated() and Stop() are normally called only once
> during a call, so the lock should not matter much.
>
>
> BR,
> /SX
>
>
> On Wed, Aug 10, 2011 at 10:18 AM, <henrika@google.com> wrote:
>
>> Still on vacation; don't want to make too detailed comments.
>>
>> Some general feedback:
>>
>> I like Tommi's idea of fixing the main issues under the current contract.
>>
>> We have more issues in our list and I suggest that we discuss the solution
>> for
>> them one by one to ensure that the consequences are OK. Moving "unique"
>> stuff up
>> the chain (to the ADM or to a proxy) feels like a good idea for these
>> parts.
>>
>> It is important that we don't forget that the changes we make in
>> AudioInputDevice should most likely be adopted by AudioDevice as well.
>> Hence,
>> they must be clear and well defined and should not force AudioDevice
>> clients to
>> make too large changes. In the end, we must have good explainaitions why
>> each
>> change is actually required.
>>
>>
>>
http://codereview.chromium.**org/7497025/<http://codereview.chromium.org/7497...
>>
>
>

Powered by Google App Engine
This is Rietveld 408576698