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

Issue 1830933002: Making AudioThread::Thread restartable *** DRAFT *** (Closed)

Created:
4 years, 9 months ago by o1ka
Modified:
4 years, 7 months ago
CC:
vanellope-cl_google.com, chromium-reviews, feature-media-reviews_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

*** This CL has been merged into https://codereview.chromium.org/1703473002/ *** Making AudioThread::Thread restartable *** DRAFT *** Based on Henrik's CL https://codereview.chromium.org/1703473002/ I changed audio_device_thread.cc and added some comments to audio_output_device.cc. It's a compilable sketch, not a tested implementaion. Actually, it won't work, because AudioOutoutDevice needs some fixes (I commented on that). We need to cleanup AOD, and probably convert AudioDeviceThread into an interface. (I'm not sure an extra lock it adds is needed.) Actually, can we probably invest some time in AOD/AID refactoring? They share quite a lot of the same code which is copy-pasted. Also, it would be nice to get rid of "stopping hack" and probably even make AOD/AID non-refcounted if we can clarify all the object lifetime stuff. BUG=

Patch Set 1 #

Total comments: 55
Unified diffs Side-by-side diffs Delta from patch set Stats (+237 lines, -90 lines) Patch
M media/audio/audio_device_thread.h View 2 chunks +17 lines, -7 lines 4 comments Download
M media/audio/audio_device_thread.cc View 10 chunks +153 lines, -45 lines 41 comments Download
M media/audio/audio_input_device.cc View 1 chunk +2 lines, -2 lines 0 comments Download
M media/audio/audio_output_device.h View 2 chunks +5 lines, -3 lines 2 comments Download
M media/audio/audio_output_device.cc View 12 chunks +60 lines, -33 lines 8 comments Download

Messages

Total messages: 14 (4 generated)
o1ka
Hej, I sketched some draft for "restartable" based on Henrik's CL, using condition instead of ...
4 years, 9 months ago (2016-03-24 10:51:02 UTC) #2
Henrik Grunell
One critical comment about the lock and condition variable. You can basically skip the other ...
4 years, 9 months ago (2016-03-25 09:24:01 UTC) #3
o1ka
Henrik's questions answered. https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_thread.cc File media/audio/audio_device_thread.cc (right): https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_thread.cc#newcode83 media/audio/audio_device_thread.cc:83: ResumeAction action_; On 2016/03/25 09:24:01, Henrik ...
4 years, 8 months ago (2016-03-29 08:49:17 UTC) #4
Henrik Grunell
Looked through AudioDeviceThread for races. Looks good! For AudioDeviceThread, before doing any bigger refactorings we ...
4 years, 8 months ago (2016-03-31 09:01:37 UTC) #5
o1ka
guidou@, could you take a look? (see the description, it's a draft!). Specifically, we are ...
4 years, 8 months ago (2016-03-31 10:02:38 UTC) #8
o1ka
https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_thread.cc File media/audio/audio_device_thread.cc (right): https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_thread.cc#newcode81 media/audio/audio_device_thread.cc:81: base::Lock action_lock_; // Protects everything below. On 2016/03/31 09:01:36, ...
4 years, 8 months ago (2016-03-31 10:10:57 UTC) #9
o1ka
https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_thread.cc File media/audio/audio_device_thread.cc (right): https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_thread.cc#newcode87 media/audio/audio_device_thread.cc:87: // Reset on client threaid. shutdown on client thread, ...
4 years, 8 months ago (2016-03-31 11:27:15 UTC) #10
Guido Urdaneta
https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_thread.cc File media/audio/audio_device_thread.cc (right): https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_thread.cc#newcode59 media/audio/audio_device_thread.cc:59: enum ResumeAction { kActionPause, kActionPlay, kActionStop }; It seems ...
4 years, 8 months ago (2016-04-01 10:17:02 UTC) #11
Henrik Grunell
Some comments I forgot to post on Thursday, plus a new one. Main things are ...
4 years, 8 months ago (2016-04-04 08:08:59 UTC) #12
Henrik Grunell
4 years, 7 months ago (2016-05-09 12:13:37 UTC) #13
I've addressed all comments here in CL
https://codereview.chromium.org/1703473002/.

Note that all further reviewing is done in that CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
File media/audio/audio_device_thread.cc (right):

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.cc:59: enum ResumeAction { kActionPause,
kActionPlay, kActionStop };
On 2016/04/01 10:17:01, Guido Urdaneta wrote:
> It seems to me that this represents a state instead of an action.
> What about calling this enum simply State and the values kStatePaused,
> kStatePlaying and kStateStopped?

Agree. Done in other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.cc:68: // Runs the loop that reads from the
socket, called in ThreadMain(),
On 2016/04/01 10:17:01, Guido Urdaneta wrote:
> s/,/.

Done in other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.cc:81: base::Lock action_lock_;  // Protects
everything below.
On 2016/04/04 08:08:59, Henrik Grunell wrote:
> On 2016/03/31 10:10:56, o1ka wrote:
> > On 2016/03/31 09:01:36, Henrik Grunell wrote:
> > > |socket_| is not protected by the lock, but only accessed on audio thread,
> or
> > > ShutDown() on control thread, which is fine.
> > 
> > |socket_| IS protected by the lock. It can be reset in ThreadMain, this is
> done
> > under the lock, as well as Stop() shuts it down under the lock, to avoid a
> race.
> > All rest of socket access in threadMain is not under the lock, since the
only
> > race we need to avoid is related to shutdown.
> 
> Ah, right. But does it seems that we could call Play() then Pause(), and maybe
> |socket_| isn't initialized in between. We'd dereference nullptr in Pause().
We
> need to add a condition for doing Shutdown().

Done in other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.cc:82: base::ConditionVariable
action_condition_;
On 2016/04/01 10:17:01, Guido Urdaneta wrote:
> Can you use a WaitableEvent instead of a ConditionVariable?
> My understanding is that the ConditionVariable has worse performance on
Windows,
> although that might have changed.

This simplifies the locking and state checking in ThreadMain().

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.cc:83: ResumeAction action_;
On 2016/04/01 10:17:01, Guido Urdaneta wrote:
> On 2016/03/29 08:49:17, o1ka wrote:
> > On 2016/03/25 09:24:01, Henrik Grunell wrote:
> > > Is this action to perform, or ongoing, or something else? (Add comment.)
> > 
> > How would you call it?
> 
> I would call it state_ :)

Done in other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.cc:87: // Reset on client threaid.
On 2016/03/31 11:27:15, o1ka wrote:
> shutdown on client thread, reset in thread main.

Done in other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.cc:102: AudioDeviceThread::~AudioDeviceThread()
{ DCHECK(!thread_.get()); }
On 2016/04/01 10:17:01, Guido Urdaneta wrote:
> Should action_ have a particular value at destruction time?

Good point. (Although in ADT::Thread::~Thread().) Done in other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.cc:106: base::AutoLock auto_lock(thread_lock_);
On 2016/03/31 09:01:36, Henrik Grunell wrote:
> On 2016/03/29 08:49:17, o1ka wrote:
> > On 2016/03/25 09:24:01, Henrik Grunell wrote:
> > > If we decide to keep this layer/class, I wonder if we can use require this
> > > object be called on the same thread? Does the AudioOutputDevice call them
on
> > the
> > > same thread?
> > 
> > I think you know better since you digged into AOD already. My understanding
is
> > that as of now, Pause() and Stop() can be called from a different thread,
and
> > Pause() should be fixed.
> 
> Yeah, it does all on the IO thread, but the Stop() hack thing.

There is actually thread checkers in ADT::Thread::Start(), Play() (renamed to
Resume() in other CL) and Pause(). That should be enough.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.cc:123: thread_->Play(callback, socket);
On 2016/03/31 09:01:36, Henrik Grunell wrote:
> On 2016/03/29 08:49:17, o1ka wrote:
> > On 2016/03/25 09:24:01, Henrik Grunell wrote:
> > > Play() then Stop() could be called on different threads, and if Stop() is
> > > executed first, we need a
> > > if (thread_.get())
> > > here.
> > 
> > Good catch! This part is inherited from the original CL though, and I did
not
> > touch it, since I hope we are getting rig of the whole class.
> 
> OK, sg.

Done in other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.cc:170: void
AudioDeviceThread::Thread::Stop(base::MessageLoop* loop_for_join) {
On 2016/04/04 08:08:59, Henrik Grunell wrote:
> We must guarantee that after Stop() or Pause() have returned, the callback
will
> not be run.

This is not part of the contract anymore.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.cc:171: // NB: Stop() can be called any time,
even before Start(), because it's
On 2016/04/01 10:17:01, Guido Urdaneta wrote:
> On 2016/03/29 08:49:17, o1ka wrote:
> > On 2016/03/25 09:24:01, Henrik Grunell wrote:
> > > What does NB mean?
> > 
> > https://en.wikipedia.org/wiki/Nota_bene :)
> 
> Probably better to remove the NB :)

Done in other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.cc:178: ;
On 2016/03/31 10:10:56, o1ka wrote:
> remove ;

Done in other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
File media/audio/audio_device_thread.h (right):

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.h:97: // Releases the thread from wait mode so
that it starts running with the given
On 2016/04/01 10:17:01, Guido Urdaneta wrote:
> Nit: Release is perhaps not the most familiar term for this.
> What about something like "Puts the thread in running mode" or something like
> that. Note that you use this wording in the documentation of Pause().

Done in other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_device_th...
media/audio/audio_device_thread.h:111: // Not sure if we need this extra class
and extra lock?
On 2016/03/25 09:24:01, Henrik Grunell wrote:
> Yeah, does the below motivation hold? It seems pretty old, it refers to
> SimpleThread, but we use PlatformThread, so maybe the need for wrapping is
> obsolete.

Changed to TODO in other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_output_de...
File media/audio/audio_output_device.cc (right):

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_output_de...
media/audio/audio_output_device.cc:116: // on IO thread only.
On 2016/04/04 08:08:59, Henrik Grunell wrote:
> The problem here is that after Stop() returns, the callback can go away, this
is
> the reason for stopping the audio thread right away in Stop(), and having
> |stopping_hack_|. We must ensure the callback isn't called or that it outlives
> AOD (see comment in OnStreamCreated()).
> 
> olka@ and I discussed offline to remove ref counting on AOD, similar work is
> currently done for AudioInputDevice.

This has been addressed in the other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_output_de...
media/audio/audio_output_device.cc:276: // Stop(). In most cases, the thread
will already be stopped.
On 2016/04/01 10:17:01, Guido Urdaneta wrote:
> now you call Pause() instead of Stop()

Done in other CL.

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_output_de...
File media/audio/audio_output_device.h (right):

https://codereview.chromium.org/1830933002/diff/1/media/audio/audio_output_de...
media/audio/audio_output_device.h:47: // 2. Control thread (may be the main
render thread or another thread).
On 2016/03/31 09:01:37, Henrik Grunell wrote:
> Hmm, "Start(), Stop(), Play(), Pause(), SetVolume() must be called on the same
> thread." But there are no thread checks. What about adding that?

This comment is obsolete. For example, Pause() is called in the Render()
callback function in the mixer. Removed in other CL.

Powered by Google App Engine
This is Rietveld 408576698