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

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

Issue 2060833002: Implementation of 'AudioContext.getOutputTimestamp' method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added implementation for ALSA. Created 4 years, 5 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
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 MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ 5 #ifndef MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
6 #define MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ 6 #define MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/shared_memory.h" 11 #include "base/memory/shared_memory.h"
12 #include "base/sync_socket.h" 12 #include "base/sync_socket.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "media/audio/audio_io.h"
15 #include "media/base/audio_parameters.h" 16 #include "media/base/audio_parameters.h"
16 #include "media/base/media_export.h" 17 #include "media/base/media_export.h"
17 18
18 namespace media { 19 namespace media {
20 struct AudioTimestamp;
19 21
20 // Data transfer between browser and render process uses a combination 22 // Data transfer between browser and render process uses a combination
21 // 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
22 // 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
23 // 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
24 // audio thread via the AudioDeviceThread::Callback interface/class. 26 // audio thread via the AudioDeviceThread::Callback interface/class.
25 class MEDIA_EXPORT AudioDeviceThread : public base::PlatformThread::Delegate { 27 class MEDIA_EXPORT AudioDeviceThread : public base::PlatformThread::Delegate {
26 public: 28 public:
27 // This is the callback interface/base class that Audio[Output|Input]Device 29 // This is the callback interface/base class that Audio[Output|Input]Device
28 // implements to render input/output data. The callbacks run on the 30 // implements to render input/output data. The callbacks run on the
29 // thread owned by AudioDeviceThread. 31 // thread owned by AudioDeviceThread.
30 class Callback { 32 class Callback {
31 public: 33 public:
32 Callback(const AudioParameters& audio_parameters, 34 Callback(const AudioParameters& audio_parameters,
33 base::SharedMemoryHandle memory, 35 base::SharedMemoryHandle memory,
34 int memory_length, 36 int memory_length,
35 int total_segments); 37 int total_segments);
36 38
37 // One time initialization for the callback object on the audio thread. 39 // One time initialization for the callback object on the audio thread.
38 void InitializeOnAudioThread(); 40 void InitializeOnAudioThread();
39 41
40 // Derived implementations must call shared_memory_.Map appropriately 42 // Derived implementations must call shared_memory_.Map appropriately
41 // before Process can be called. 43 // before Process can be called.
42 virtual void MapSharedMemory() = 0; 44 virtual void MapSharedMemory() = 0;
43 45
44 // Called whenever we receive notifications about pending input data. 46 // Called whenever we receive notifications about pending input data.
45 virtual void Process(uint32_t pending_data) = 0; 47 // It also provides the current audio stream timestamp on the device.
48 virtual void Process(uint32_t pending_data,
49 const AudioTimestamp& timestamp) = 0;
46 50
47 protected: 51 protected:
48 virtual ~Callback(); 52 virtual ~Callback();
49 53
50 // Protected so that derived classes can access directly. 54 // Protected so that derived classes can access directly.
51 // The variables are 'const' since values are calculated/set in the 55 // The variables are 'const' since values are calculated/set in the
52 // constructor and must never change. 56 // constructor and must never change.
53 const AudioParameters audio_parameters_; 57 const AudioParameters audio_parameters_;
54 58
55 base::SharedMemory shared_memory_; 59 base::SharedMemory shared_memory_;
(...skipping 12 matching lines...) Expand all
68 72
69 // Creates and automatically starts the audio thread. 73 // Creates and automatically starts the audio thread.
70 AudioDeviceThread(Callback* callback, 74 AudioDeviceThread(Callback* callback,
71 base::SyncSocket::Handle socket, 75 base::SyncSocket::Handle socket,
72 const char* thread_name); 76 const char* thread_name);
73 77
74 // This tells the audio thread to stop and clean up the data; this is a 78 // This tells the audio thread to stop and clean up the data; this is a
75 // synchronous process and the thread will stop before the method returns. 79 // synchronous process and the thread will stop before the method returns.
76 ~AudioDeviceThread() override; 80 ~AudioDeviceThread() override;
77 81
82 // Represents a data packet to be received via the socket.
83 struct Packet {
84 uint32_t pending_data;
85 AudioTimestamp timestamp;
86 };
87
78 private: 88 private:
79 void ThreadMain() final; 89 void ThreadMain() final;
80 90
81 Callback* const callback_; 91 Callback* const callback_;
82 const char* thread_name_; 92 const char* thread_name_;
83 base::CancelableSyncSocket socket_; 93 base::CancelableSyncSocket socket_;
84 base::PlatformThreadHandle thread_handle_; 94 base::PlatformThreadHandle thread_handle_;
85 95
86 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread); 96 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread);
87 }; 97 };
88 98
89 } // namespace media. 99 } // namespace media.
90 100
91 #endif // MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ 101 #endif // MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698