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

Side by Side Diff: media/audio/audio_device_thread.cc

Issue 2640003002: Implement MojoAudioRendererSink and use it in UtilityMojoMediaClient (Closed)
Patch Set: Rebase Created 3 years, 10 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
« no previous file with comments | « media/audio/audio_device_thread.h ('k') | media/base/audio_bus.h » ('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 #include "media/audio/audio_device_thread.h" 5 #include "media/audio/audio_device_thread.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/bind.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/threading/thread.h"
10 12
11 namespace media { 13 namespace media {
12 14
13 // AudioDeviceThread::Callback implementation 15 // AudioDeviceThread::Callback implementation
14 16
15 AudioDeviceThread::Callback::Callback(const AudioParameters& audio_parameters, 17 AudioDeviceThread::Callback::Callback(const AudioParameters& audio_parameters,
16 base::SharedMemoryHandle memory, 18 base::SharedMemoryHandle memory,
17 int memory_length, 19 int memory_length,
18 int total_segments) 20 int total_segments)
19 : audio_parameters_(audio_parameters), 21 : audio_parameters_(audio_parameters),
(...skipping 19 matching lines...) Expand all
39 DCHECK(!shared_memory_.memory()); 41 DCHECK(!shared_memory_.memory());
40 MapSharedMemory(); 42 MapSharedMemory();
41 CHECK(shared_memory_.memory()); 43 CHECK(shared_memory_.memory());
42 } 44 }
43 45
44 // AudioDeviceThread implementation 46 // AudioDeviceThread implementation
45 47
46 AudioDeviceThread::AudioDeviceThread(Callback* callback, 48 AudioDeviceThread::AudioDeviceThread(Callback* callback,
47 base::SyncSocket::Handle socket, 49 base::SyncSocket::Handle socket,
48 const char* thread_name) 50 const char* thread_name)
49 : callback_(callback), thread_name_(thread_name), socket_(socket) { 51 : callback_(callback),
50 CHECK(base::PlatformThread::CreateWithPriority( 52 socket_(socket),
51 0, this, &thread_handle_, base::ThreadPriority::REALTIME_AUDIO)); 53 thread_(new base::Thread("AudioDevice")) {
52 DCHECK(!thread_handle_.is_null()); 54 base::Thread::Options options;
55 options.joinable = true;
56 options.priority = base::ThreadPriority::REALTIME_AUDIO;
57 thread_->StartWithOptions(options);
58 bool started = thread_->WaitUntilThreadStarted();
59 CHECK(started);
60
61 thread_->task_runner()->PostTask(
62 FROM_HERE,
63 base::Bind(&AudioDeviceThread::ThreadMain, base::Unretained(this)));
53 } 64 }
54 65
55 AudioDeviceThread::~AudioDeviceThread() { 66 AudioDeviceThread::~AudioDeviceThread() {
56 socket_.Shutdown(); 67 socket_.Shutdown();
57 if (thread_handle_.is_null()) 68 thread_->Stop();
58 return;
59 base::PlatformThread::Join(thread_handle_);
60 } 69 }
61 70
62 void AudioDeviceThread::ThreadMain() { 71 void AudioDeviceThread::ThreadMain() {
63 base::PlatformThread::SetName(thread_name_);
64 callback_->InitializeOnAudioThread(); 72 callback_->InitializeOnAudioThread();
65 73
66 uint32_t buffer_index = 0; 74 uint32_t buffer_index = 0;
67 while (true) { 75 while (true) {
68 uint32_t pending_data = 0; 76 uint32_t pending_data = 0;
69 size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data)); 77 size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data));
70 if (bytes_read != sizeof(pending_data)) 78 if (bytes_read != sizeof(pending_data))
71 break; 79 break;
72 80
73 // std::numeric_limits<uint32_t>::max() is a special signal which is 81 // std::numeric_limits<uint32_t>::max() is a special signal which is
(...skipping 18 matching lines...) Expand all
92 // expects. For more details on how this works see 100 // expects. For more details on how this works see
93 // AudioSyncReader::WaitUntilDataIsReady(). 101 // AudioSyncReader::WaitUntilDataIsReady().
94 ++buffer_index; 102 ++buffer_index;
95 size_t bytes_sent = socket_.Send(&buffer_index, sizeof(buffer_index)); 103 size_t bytes_sent = socket_.Send(&buffer_index, sizeof(buffer_index));
96 if (bytes_sent != sizeof(buffer_index)) 104 if (bytes_sent != sizeof(buffer_index))
97 break; 105 break;
98 } 106 }
99 } 107 }
100 108
101 } // namespace media. 109 } // namespace media.
OLDNEW
« no previous file with comments | « media/audio/audio_device_thread.h ('k') | media/base/audio_bus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698