OLD | NEW |
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 #include "media/audio/audio_output_device.h" | 5 #include "media/audio/audio_output_device.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 }; | 41 }; |
42 | 42 |
43 AudioOutputDevice::AudioOutputDevice( | 43 AudioOutputDevice::AudioOutputDevice( |
44 scoped_ptr<AudioOutputIPC> ipc, | 44 scoped_ptr<AudioOutputIPC> ipc, |
45 const scoped_refptr<base::MessageLoopProxy>& io_loop) | 45 const scoped_refptr<base::MessageLoopProxy>& io_loop) |
46 : ScopedLoopObserver(io_loop), | 46 : ScopedLoopObserver(io_loop), |
47 callback_(NULL), | 47 callback_(NULL), |
48 ipc_(ipc.Pass()), | 48 ipc_(ipc.Pass()), |
49 state_(IDLE), | 49 state_(IDLE), |
50 play_on_start_(true), | 50 play_on_start_(true), |
| 51 session_id_(-1), |
51 stopping_hack_(false) { | 52 stopping_hack_(false) { |
52 CHECK(ipc_); | 53 CHECK(ipc_); |
53 | 54 |
54 // The correctness of the code depends on the relative values assigned in the | 55 // The correctness of the code depends on the relative values assigned in the |
55 // State enum. | 56 // State enum. |
56 COMPILE_ASSERT(IPC_CLOSED < IDLE, invalid_enum_value_assignment_0); | 57 COMPILE_ASSERT(IPC_CLOSED < IDLE, invalid_enum_value_assignment_0); |
57 COMPILE_ASSERT(IDLE < CREATING_STREAM, invalid_enum_value_assignment_1); | 58 COMPILE_ASSERT(IDLE < CREATING_STREAM, invalid_enum_value_assignment_1); |
58 COMPILE_ASSERT(CREATING_STREAM < PAUSED, invalid_enum_value_assignment_2); | 59 COMPILE_ASSERT(CREATING_STREAM < PAUSED, invalid_enum_value_assignment_2); |
59 COMPILE_ASSERT(PAUSED < PLAYING, invalid_enum_value_assignment_3); | 60 COMPILE_ASSERT(PAUSED < PLAYING, invalid_enum_value_assignment_3); |
60 } | 61 } |
61 | 62 |
| 63 void AudioOutputDevice::InitializeUnifiedStream(const AudioParameters& params, |
| 64 RenderCallback* callback, |
| 65 int session_id) { |
| 66 DCHECK(!callback_) << "Calling InitializeUnifiedStream() twice?"; |
| 67 DCHECK(params.IsValid()); |
| 68 audio_parameters_ = params; |
| 69 callback_ = callback; |
| 70 session_id_ = session_id; |
| 71 } |
| 72 |
62 void AudioOutputDevice::Initialize(const AudioParameters& params, | 73 void AudioOutputDevice::Initialize(const AudioParameters& params, |
63 RenderCallback* callback) { | 74 RenderCallback* callback) { |
64 DCHECK(!callback_) << "Calling Initialize() twice?"; | 75 InitializeUnifiedStream(params, callback, 0); |
65 DCHECK(params.IsValid()); | |
66 audio_parameters_ = params; | |
67 callback_ = callback; | |
68 } | 76 } |
69 | 77 |
70 AudioOutputDevice::~AudioOutputDevice() { | 78 AudioOutputDevice::~AudioOutputDevice() { |
71 // The current design requires that the user calls Stop() before deleting | 79 // The current design requires that the user calls Stop() before deleting |
72 // this class. | 80 // this class. |
73 DCHECK(audio_thread_.IsStopped()); | 81 DCHECK(audio_thread_.IsStopped()); |
74 } | 82 } |
75 | 83 |
76 void AudioOutputDevice::Start() { | 84 void AudioOutputDevice::Start() { |
77 DCHECK(callback_) << "Initialize hasn't been called"; | 85 DCHECK(callback_) << "Initialize hasn't been called"; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 return false; | 118 return false; |
111 } | 119 } |
112 | 120 |
113 return true; | 121 return true; |
114 } | 122 } |
115 | 123 |
116 void AudioOutputDevice::CreateStreamOnIOThread(const AudioParameters& params) { | 124 void AudioOutputDevice::CreateStreamOnIOThread(const AudioParameters& params) { |
117 DCHECK(message_loop()->BelongsToCurrentThread()); | 125 DCHECK(message_loop()->BelongsToCurrentThread()); |
118 if (state_ == IDLE) { | 126 if (state_ == IDLE) { |
119 state_ = CREATING_STREAM; | 127 state_ = CREATING_STREAM; |
120 ipc_->CreateStream(this, params); | 128 ipc_->CreateStream(this, params, session_id_); |
121 } | 129 } |
122 } | 130 } |
123 | 131 |
124 void AudioOutputDevice::PlayOnIOThread() { | 132 void AudioOutputDevice::PlayOnIOThread() { |
125 DCHECK(message_loop()->BelongsToCurrentThread()); | 133 DCHECK(message_loop()->BelongsToCurrentThread()); |
126 if (state_ == PAUSED) { | 134 if (state_ == PAUSED) { |
127 ipc_->PlayStream(); | 135 ipc_->PlayStream(); |
128 state_ = PLAYING; | 136 state_ = PLAYING; |
129 play_on_start_ = false; | 137 play_on_start_ = false; |
130 } else { | 138 } else { |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // TODO(dalecurtis): Technically this is not always correct. Due to channel | 344 // TODO(dalecurtis): Technically this is not always correct. Due to channel |
337 // padding for alignment, there may be more data available than this. We're | 345 // padding for alignment, there may be more data available than this. We're |
338 // relying on AudioSyncReader::Read() to parse this with that in mind. Rename | 346 // relying on AudioSyncReader::Read() to parse this with that in mind. Rename |
339 // these methods to Set/GetActualFrameCount(). | 347 // these methods to Set/GetActualFrameCount(). |
340 SetActualDataSizeInBytes( | 348 SetActualDataSizeInBytes( |
341 &shared_memory_, memory_length_, | 349 &shared_memory_, memory_length_, |
342 num_frames * sizeof(*output_bus_->channel(0)) * output_bus_->channels()); | 350 num_frames * sizeof(*output_bus_->channel(0)) * output_bus_->channels()); |
343 } | 351 } |
344 | 352 |
345 } // namespace media. | 353 } // namespace media. |
OLD | NEW |