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

Side by Side Diff: content/renderer/media/audio_device_thread.h

Issue 9534002: Stop the AudioDeviceThread when the IO loop goes away. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove mutable. Stop thread synchronously if needed in ShutdownOnIOThread with IO exception. Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/media/audio_device.cc ('k') | content/renderer/media/audio_device_thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_THREAD_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_THREAD_H_
6 #define CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_THREAD_H_ 6 #define CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_THREAD_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/shared_memory.h" 14 #include "base/shared_memory.h"
15 #include "base/sync_socket.h" 15 #include "base/sync_socket.h"
16 #include "base/synchronization/lock.h"
16 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
17 #include "media/audio/audio_parameters.h" 18 #include "media/audio/audio_parameters.h"
18 19
19 class MessageLoop; 20 class MessageLoop;
20 21
21 // Data transfer between browser and render process uses a combination 22 // Data transfer between browser and render process uses a combination
22 // of sync sockets and shared memory. To read from the socket and render 23 // of sync sockets and shared memory. To read from the socket and render
23 // data, we use a worker thread, a.k.a. the AudioDeviceThread, which reads 24 // data, we use a worker thread, a.k.a. the AudioDeviceThread, which reads
24 // data from the browser via the socket and fills the shared memory from the 25 // data from the browser via the socket and fills the shared memory from the
25 // audio thread via the AudioDeviceThread::Callback interface/class. 26 // audio thread via the AudioDeviceThread::Callback interface/class.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 70
70 AudioDeviceThread(); 71 AudioDeviceThread();
71 ~AudioDeviceThread(); 72 ~AudioDeviceThread();
72 73
73 // Starts the audio thread. The thread must not already be running. 74 // Starts the audio thread. The thread must not already be running.
74 void Start(AudioDeviceThread::Callback* callback, 75 void Start(AudioDeviceThread::Callback* callback,
75 base::SyncSocket::Handle socket, 76 base::SyncSocket::Handle socket,
76 const char* thread_name); 77 const char* thread_name);
77 78
78 // This tells the audio thread to stop and clean up the data. 79 // This tells the audio thread to stop and clean up the data.
79 // The method is asynchronous, so the thread might still be running after it 80 // The method can stop the thread synchronously or asynchronously.
81 // In the latter case, the thread will still be running after Stop()
80 // returns, but the callback pointer is cleared so no further callbacks will 82 // returns, but the callback pointer is cleared so no further callbacks will
81 // be made (i.e. after Stop() returns, it is safe to delete the callback). 83 // be made (IOW after Stop() returns, it is safe to delete the callback).
82 // The |loop_for_join| parameter is required in order to join the worker 84 // The |loop_for_join| parameter is required for asynchronous operation
83 // thread and close the thread handle later via a posted task. 85 // in order to join the worker thread and close the thread handle later via a
84 // If set to NULL, the current message loop is used. Note that the thread 86 // posted task.
85 // that the message loop belongs to, must be allowed to join threads 87 // If set to NULL, function will wait for the thread to exit before returning.
86 // (see SetIOAllowed in base/thread_restrictions.h).
87 void Stop(MessageLoop* loop_for_join); 88 void Stop(MessageLoop* loop_for_join);
88 89
90 // Returns true if the thread is stopped or stopping.
91 bool IsStopped();
92
89 private: 93 private:
90 // Our own private SimpleThread override. We implement this in a 94 // Our own private SimpleThread override. We implement this in a
91 // private class so that we get the following benefits: 95 // private class so that we get the following benefits:
92 // 1) AudioDeviceThread doesn't expose SimpleThread methods. 96 // 1) AudioDeviceThread doesn't expose SimpleThread methods.
93 // I.e. the caller can't call Start()/Stop() - which would be bad. 97 // I.e. the caller can't call Start()/Stop() - which would be bad.
94 // 2) We override ThreadMain to add additional on-thread initialization 98 // 2) We override ThreadMain to add additional on-thread initialization
95 // while still synchronized with SimpleThread::Start() to provide 99 // while still synchronized with SimpleThread::Start() to provide
96 // reliable initialization. 100 // reliable initialization.
97 class Thread; 101 class Thread;
98 102
103 base::Lock thread_lock_;
99 scoped_refptr<AudioDeviceThread::Thread> thread_; 104 scoped_refptr<AudioDeviceThread::Thread> thread_;
100 105
101 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread); 106 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread);
102 }; 107 };
103 108
104 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_THREAD_H_ 109 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_THREAD_H_
OLDNEW
« no previous file with comments | « content/renderer/media/audio_device.cc ('k') | content/renderer/media/audio_device_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698