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

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

Issue 1302423006: Ensure that data is not overwritten in the audio input shared memory ring buffer that sits on the b… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed log call expectations for Android in unit test. Rebase. Created 5 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_INPUT_SYNC_WRITER_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_
7 7
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/process/process.h" 9 #include "base/process/process.h"
10 #include "base/sync_socket.h" 10 #include "base/sync_socket.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "content/common/content_export.h"
12 #include "media/audio/audio_input_controller.h" 13 #include "media/audio/audio_input_controller.h"
13 #include "media/audio/audio_parameters.h" 14 #include "media/audio/audio_parameters.h"
14 #include "media/base/audio_bus.h" 15 #include "media/base/audio_bus.h"
15 16
16 #if defined(OS_POSIX) 17 #if defined(OS_POSIX)
17 #include "base/file_descriptor_posix.h" 18 #include "base/file_descriptor_posix.h"
18 #endif 19 #endif
19 20
20 namespace base { 21 namespace content {
21 class SharedMemory;
22 }
23 22
24 namespace content {
25 // A AudioInputController::SyncWriter implementation using SyncSocket. This 23 // A AudioInputController::SyncWriter implementation using SyncSocket. This
26 // is used by AudioInputController to provide a low latency data source for 24 // is used by AudioInputController to provide a low latency data source for
27 // transmitting audio packets between the browser process and the renderer 25 // transmitting audio packets between the browser process and the renderer
28 // process. 26 // process.
29 class AudioInputSyncWriter : public media::AudioInputController::SyncWriter { 27 class CONTENT_EXPORT AudioInputSyncWriter
28 : public media::AudioInputController::SyncWriter {
30 public: 29 public:
31 explicit AudioInputSyncWriter(base::SharedMemory* shared_memory, 30 AudioInputSyncWriter(void* shared_memory,
32 int shared_memory_segment_count, 31 size_t shared_memory_size,
33 const media::AudioParameters& params); 32 int shared_memory_segment_count,
33 const media::AudioParameters& params);
34 34
35 ~AudioInputSyncWriter() override; 35 ~AudioInputSyncWriter() override;
36 36
37 // media::AudioInputController::SyncWriter implementation. 37 // media::AudioInputController::SyncWriter implementation.
38 void Write(const media::AudioBus* data, 38 void Write(const media::AudioBus* data,
39 double volume, 39 double volume,
40 bool key_pressed, 40 bool key_pressed,
41 uint32 hardware_delay_bytes) override; 41 uint32 hardware_delay_bytes) override;
42 void Close() override; 42 void Close() override;
43 43
44 bool Init(); 44 bool Init();
45 bool PrepareForeignSocket(base::ProcessHandle process_handle, 45 bool PrepareForeignSocket(base::ProcessHandle process_handle,
46 base::SyncSocket::TransitDescriptor* descriptor); 46 base::SyncSocket::TransitDescriptor* descriptor);
47 47
48 protected:
49 // Socket for transmitting audio data.
50 scoped_ptr<base::CancelableSyncSocket> socket_;
51
48 private: 52 private:
49 base::SharedMemory* shared_memory_; 53 // Virtual function for native logging to be able to override in tests.
54 virtual void AddToNativeLog(const std::string& message);
55
56 uint8* shared_memory_;
50 uint32 shared_memory_segment_size_; 57 uint32 shared_memory_segment_size_;
51 uint32 shared_memory_segment_count_; 58 uint32 shared_memory_segment_count_;
52 uint32 current_segment_id_; 59 uint32 current_segment_id_;
53 60
54 // Socket for transmitting audio data.
55 scoped_ptr<base::CancelableSyncSocket> socket_;
56
57 // Socket to be used by the renderer. The reference is released after 61 // Socket to be used by the renderer. The reference is released after
58 // PrepareForeignSocketHandle() is called and ran successfully. 62 // PrepareForeignSocketHandle() is called and ran successfully.
59 scoped_ptr<base::CancelableSyncSocket> foreign_socket_; 63 scoped_ptr<base::CancelableSyncSocket> foreign_socket_;
60 64
61 // The time of the creation of this object. 65 // The time of the creation of this object.
62 base::Time creation_time_; 66 base::Time creation_time_;
63 67
64 // The time of the last Write call. 68 // The time of the last Write call.
65 base::Time last_write_time_; 69 base::Time last_write_time_;
66 70
67 // Size in bytes of each audio bus. 71 // Size in bytes of each audio bus.
68 const int audio_bus_memory_size_; 72 const int audio_bus_memory_size_;
69 73
70 // Increasing ID used for audio buffers correct sequence at read side. 74 // Increasing ID used for checking audio buffers are in correct sequence at
75 // read side.
71 uint32_t next_buffer_id_; 76 uint32_t next_buffer_id_;
72 77
78 // Next expected audio buffer index to have been read at the other side. We
79 // will get the index read at the other side over the socket. Note that this
80 // index does not correspond to |next_buffer_id_|, it's two separate counters.
81 uint32_t next_read_buffer_index_;
82
83 // Keeps track of number of filled buffer segments in the ring buffer to
84 // ensure the we don't overwrite data that hasn't been read yet.
85 int number_of_filled_segments_;
86
87 // Counts the total number of calls to Write() and number of failures due to
88 // ring buffer being full.
89 size_t write_count_;
90 size_t write_error_count_;
91
73 // Vector of audio buses allocated during construction and deleted in the 92 // Vector of audio buses allocated during construction and deleted in the
74 // destructor. 93 // destructor.
75 ScopedVector<media::AudioBus> audio_buses_; 94 ScopedVector<media::AudioBus> audio_buses_;
76 95
77 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputSyncWriter); 96 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputSyncWriter);
78 }; 97 };
79 98
80 } // namespace content 99 } // namespace content
81 100
82 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_ 101 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698