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

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: Comments 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() const { return shared_memory_.get(); }
44 base::CancelableSyncSocket* foreign_socket() const {
45 return foreign_socket_.get();
46 }
40 47
41 // media::AudioOutputController::SyncReader implementations. 48 // media::AudioOutputController::SyncReader implementations.
42 void UpdatePendingBytes(uint32_t bytes, uint32_t frames_skipped) override; 49 void UpdatePendingBytes(uint32_t bytes, uint32_t frames_skipped) override;
43 void Read(media::AudioBus* dest) override; 50 void Read(media::AudioBus* dest) override;
44 void Close() override; 51 void Close() override;
45 52
46 bool Init(); 53 private:
47 bool PrepareForeignSocket(base::ProcessHandle process_handle, 54 AudioSyncReader(const media::AudioParameters& params,
48 base::SyncSocket::TransitDescriptor* descriptor); 55 std::unique_ptr<base::SharedMemory> shared_memory,
56 std::unique_ptr<base::CancelableSyncSocket> socket,
57 std::unique_ptr<base::CancelableSyncSocket> foreign_socket);
49 58
50 private:
51 // Blocks until data is ready for reading or a timeout expires. Returns false 59 // Blocks until data is ready for reading or a timeout expires. Returns false
52 // if an error or timeout occurs. 60 // if an error or timeout occurs.
53 bool WaitUntilDataIsReady(); 61 bool WaitUntilDataIsReady();
54 62
55 const base::SharedMemory* const shared_memory_; 63 std::unique_ptr<base::SharedMemory> shared_memory_;
56 64
57 // Mutes all incoming samples. This is used to prevent audible sound 65 // Mutes all incoming samples. This is used to prevent audible sound
58 // during automated testing. 66 // during automated testing.
59 const bool mute_audio_; 67 const bool mute_audio_;
60 68
61 // Socket for transmitting audio data. 69 // Socket for transmitting audio data.
62 std::unique_ptr<base::CancelableSyncSocket> socket_; 70 std::unique_ptr<base::CancelableSyncSocket> socket_;
63 71
64 // Socket to be used by the renderer. The reference is released after 72 // Socket to be used by the renderer.
65 // PrepareForeignSocketHandle() is called and ran successfully.
66 std::unique_ptr<base::CancelableSyncSocket> foreign_socket_; 73 std::unique_ptr<base::CancelableSyncSocket> foreign_socket_;
67 74
68 // Shared memory wrapper used for transferring audio data to Read() callers. 75 // Shared memory wrapper used for transferring audio data to Read() callers.
69 std::unique_ptr<media::AudioBus> output_bus_; 76 std::unique_ptr<media::AudioBus> output_bus_;
70 77
71 // Maximum amount of audio data which can be transferred in one Read() call. 78 // Maximum amount of audio data which can be transferred in one Read() call.
72 const int packet_size_; 79 const int packet_size_;
73 80
74 // Track the number of times the renderer missed its real-time deadline and 81 // Track the number of times the renderer missed its real-time deadline and
75 // report a UMA stat during destruction. 82 // report a UMA stat during destruction.
76 size_t renderer_callback_count_; 83 size_t renderer_callback_count_;
77 size_t renderer_missed_callback_count_; 84 size_t renderer_missed_callback_count_;
78 size_t trailing_renderer_missed_callback_count_; 85 size_t trailing_renderer_missed_callback_count_;
79 86
80 // The maximum amount of time to wait for data from the renderer. Calculated 87 // The maximum amount of time to wait for data from the renderer. Calculated
81 // from the parameters given at construction. 88 // from the parameters given at construction.
82 const base::TimeDelta maximum_wait_time_; 89 const base::TimeDelta maximum_wait_time_;
83 90
84 // The index of the audio buffer we're expecting to be sent from the renderer; 91 // The index of the audio buffer we're expecting to be sent from the renderer;
85 // used to block with timeout for audio data. 92 // used to block with timeout for audio data.
86 uint32_t buffer_index_; 93 uint32_t buffer_index_;
87 94
88 DISALLOW_COPY_AND_ASSIGN(AudioSyncReader); 95 DISALLOW_COPY_AND_ASSIGN(AudioSyncReader);
89 }; 96 };
90 97
91 } // namespace content 98 } // namespace content
92 99
93 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_ 100 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698