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

Side by Side Diff: content/browser/renderer_host/media/audio_sync_reader.h

Issue 2330393002: Change sync primitives ownership for audio rendering. (Closed)
Patch Set: Remove incorrect comment. Created 4 years, 3 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 CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <memory>
10 11
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/process/process.h" 13 #include "base/process/process.h"
13 #include "base/sync_socket.h" 14 #include "base/sync_socket.h"
14 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "media/audio/audio_output_controller.h" 18 #include "media/audio/audio_output_controller.h"
18 #include "media/base/audio_bus.h" 19 #include "media/base/audio_bus.h"
19 20
20 #if defined(OS_POSIX) 21 #if defined(OS_POSIX)
21 #include "base/file_descriptor_posix.h" 22 #include "base/file_descriptor_posix.h"
22 #endif 23 #endif
23 24
24 namespace base { 25 namespace base {
25 class SharedMemory; 26 class SharedMemory;
26 } 27 }
27 28
28 namespace content { 29 namespace content {
29 30
30 // A AudioOutputController::SyncReader implementation using SyncSocket. This 31 // A AudioOutputController::SyncReader implementation using SyncSocket. This
31 // is used by AudioOutputController to provide a low latency data source for 32 // is used by AudioOutputController to provide a low latency data source for
32 // transmitting audio packets between the browser process and the renderer 33 // transmitting audio packets between the browser process and the renderer
33 // process. 34 // process.
34 class AudioSyncReader : public media::AudioOutputController::SyncReader { 35 class AudioSyncReader : public media::AudioOutputController::SyncReader {
35 public: 36 public:
36 AudioSyncReader(base::SharedMemory* shared_memory, 37 ~AudioSyncReader() override;
37 const media::AudioParameters& params);
38 38
39 ~AudioSyncReader() override; 39 // Returns null on failure.
40 static std::unique_ptr<AudioSyncReader> Create(
41 const media::AudioParameters& params);
42
43 base::SharedMemory* shared_memory() { return shared_memory_.get(); }
o1ka 2016/09/16 10:51:59 const method
Max Morin 2016/09/16 12:46:15 Done.
44 base::CancelableSyncSocket* foreign_socket() { return foreign_socket_.get(); }
o1ka 2016/09/16 10:51:59 const method
Max Morin 2016/09/16 12:46:15 Done.
40 45
41 // media::AudioOutputController::SyncReader implementations. 46 // media::AudioOutputController::SyncReader implementations.
42 void UpdatePendingBytes(uint32_t bytes, uint32_t frames_skipped) override; 47 void UpdatePendingBytes(uint32_t bytes, uint32_t frames_skipped) override;
43 void Read(media::AudioBus* dest) override; 48 void Read(media::AudioBus* dest) override;
44 void Close() override; 49 void Close() override;
45 50
46 bool Init(); 51 private:
47 bool PrepareForeignSocket(base::ProcessHandle process_handle, 52 AudioSyncReader(const media::AudioParameters& params,
48 base::SyncSocket::TransitDescriptor* descriptor); 53 std::unique_ptr<base::SharedMemory> shared_memory,
54 std::unique_ptr<base::CancelableSyncSocket> socket,
55 std::unique_ptr<base::CancelableSyncSocket> foreign_socket);
49 56
50 private:
51 // Blocks until data is ready for reading or a timeout expires. Returns false 57 // Blocks until data is ready for reading or a timeout expires. Returns false
52 // if an error or timeout occurs. 58 // if an error or timeout occurs.
53 bool WaitUntilDataIsReady(); 59 bool WaitUntilDataIsReady();
54 60
55 const base::SharedMemory* const shared_memory_; 61 std::unique_ptr<base::SharedMemory> shared_memory_;
56 62
57 // Mutes all incoming samples. This is used to prevent audible sound 63 // Mutes all incoming samples. This is used to prevent audible sound
58 // during automated testing. 64 // during automated testing.
59 const bool mute_audio_; 65 const bool mute_audio_;
60 66
61 // Socket for transmitting audio data. 67 // Socket for transmitting audio data.
62 std::unique_ptr<base::CancelableSyncSocket> socket_; 68 std::unique_ptr<base::CancelableSyncSocket> socket_;
63 69
64 // Socket to be used by the renderer. The reference is released after 70 // Socket to be used by the renderer.
65 // PrepareForeignSocketHandle() is called and ran successfully.
66 std::unique_ptr<base::CancelableSyncSocket> foreign_socket_; 71 std::unique_ptr<base::CancelableSyncSocket> foreign_socket_;
67 72
68 // Shared memory wrapper used for transferring audio data to Read() callers. 73 // Shared memory wrapper used for transferring audio data to Read() callers.
69 std::unique_ptr<media::AudioBus> output_bus_; 74 std::unique_ptr<media::AudioBus> output_bus_;
70 75
71 // Maximum amount of audio data which can be transferred in one Read() call. 76 // Maximum amount of audio data which can be transferred in one Read() call.
72 const int packet_size_; 77 const int packet_size_;
73 78
74 // Track the number of times the renderer missed its real-time deadline and 79 // Track the number of times the renderer missed its real-time deadline and
75 // report a UMA stat during destruction. 80 // report a UMA stat during destruction.
76 size_t renderer_callback_count_; 81 size_t renderer_callback_count_;
77 size_t renderer_missed_callback_count_; 82 size_t renderer_missed_callback_count_;
78 size_t trailing_renderer_missed_callback_count_; 83 size_t trailing_renderer_missed_callback_count_;
79 84
80 // The maximum amount of time to wait for data from the renderer. Calculated 85 // The maximum amount of time to wait for data from the renderer. Calculated
81 // from the parameters given at construction. 86 // from the parameters given at construction.
82 const base::TimeDelta maximum_wait_time_; 87 const base::TimeDelta maximum_wait_time_;
83 88
84 // The index of the audio buffer we're expecting to be sent from the renderer; 89 // The index of the audio buffer we're expecting to be sent from the renderer;
85 // used to block with timeout for audio data. 90 // used to block with timeout for audio data.
86 uint32_t buffer_index_; 91 uint32_t buffer_index_;
87 92
88 DISALLOW_COPY_AND_ASSIGN(AudioSyncReader); 93 DISALLOW_COPY_AND_ASSIGN(AudioSyncReader);
89 }; 94 };
90 95
91 } // namespace content 96 } // namespace content
92 97
93 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_ 98 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698