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

Side by Side Diff: content/browser/speech/audio_buffer.h

Issue 9861019: Speech refactoring: Turned AudioChunk into a refcounted class (CL1.4) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
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_SPEECH_AUDIO_BUFFER_H_ 5 #ifndef CONTENT_BROWSER_SPEECH_AUDIO_BUFFER_H_
6 #define CONTENT_BROWSER_SPEECH_AUDIO_BUFFER_H_ 6 #define CONTENT_BROWSER_SPEECH_AUDIO_BUFFER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <deque>
hans 2012/03/27 15:56:31 nit: header includes should be sorted alphabetical
Primiano Tucci (use gerrit) 2012/03/27 16:51:24 Oops.
10 11
11 #include "base/basictypes.h" 12 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_vector.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 15
16 namespace speech { 16 namespace speech {
17 17
18 // Models a chunk derived from an AudioBuffer. 18 // Models a chunk derived from an AudioBuffer.
19 class CONTENT_EXPORT AudioChunk { 19 class CONTENT_EXPORT AudioChunk :
20 public base::RefCountedThreadSafe<AudioChunk> {
hans 2012/03/27 15:56:31 just to double check: it needs to be thread safe b
Primiano Tucci (use gerrit) 2012/03/27 16:51:24 Right, it might happen that it is released and acq
20 public: 21 public:
21 explicit AudioChunk(int bytes_per_sample); 22 explicit AudioChunk(int bytes_per_sample);
22 AudioChunk(const uint8* data, size_t length, int bytes_per_sample); 23 AudioChunk(const uint8* data, size_t length, int bytes_per_sample);
23 24
24 bool IsEmpty() const; 25 bool IsEmpty() const;
25 int bytes_per_sample() const { return bytes_per_sample_; } 26 int bytes_per_sample() const { return bytes_per_sample_; }
26 size_t NumSamples() const; 27 size_t NumSamples() const;
27 const std::string& AsString() const; 28 const std::string& AsString() const;
28 int16 GetSample16(size_t index) const; 29 int16 GetSample16(size_t index) const;
29 const int16* SamplesData16() const; 30 const int16* SamplesData16() const;
30 friend class AudioBuffer; 31 friend class AudioBuffer;
31 32
32 private: 33 private:
34 ~AudioChunk() {}
35 friend class base::RefCountedThreadSafe<AudioChunk>;
36
33 std::string data_string_; 37 std::string data_string_;
34 int bytes_per_sample_; 38 int bytes_per_sample_;
35 39
36 DISALLOW_COPY_AND_ASSIGN(AudioChunk); 40 DISALLOW_COPY_AND_ASSIGN(AudioChunk);
37 }; 41 };
38 42
39 // Models an audio buffer. The current implementation relies on on-demand 43 // Models an audio buffer. The current implementation relies on on-demand
40 // allocations of AudioChunk(s) (which uses a string as storage). 44 // allocations of AudioChunk(s) (which uses a string as storage).
41 class AudioBuffer { 45 class AudioBuffer {
42 public: 46 public:
43 explicit AudioBuffer(int bytes_per_sample); 47 explicit AudioBuffer(int bytes_per_sample);
44 ~AudioBuffer(); 48 ~AudioBuffer();
45 49
46 // Enqueues a copy of |length| bytes of |data| buffer. 50 // Enqueues a copy of |length| bytes of |data| buffer.
47 void Enqueue(const uint8* data, size_t length); 51 void Enqueue(const uint8* data, size_t length);
48 52
49 // Dequeues, in FIFO order, a single chunk respecting the length of the 53 // Dequeues, in FIFO order, a single chunk respecting the length of the
50 // corresponding Enqueue call (in a nutshell: multiple Enqueue calls followed 54 // corresponding Enqueue call (in a nutshell: multiple Enqueue calls followed
51 // by Dequeue calls will return the individual chunks without merging them). 55 // by Dequeue calls will return the individual chunks without merging them).
52 scoped_ptr<AudioChunk> DequeueSingleChunk(); 56 scoped_refptr<AudioChunk> DequeueSingleChunk();
53 57
54 // Dequeues all previously enqueued chunks, merging them in a single chunk. 58 // Dequeues all previously enqueued chunks, merging them in a single chunk.
55 scoped_ptr<AudioChunk> DequeueAll(); 59 scoped_refptr<AudioChunk> DequeueAll();
56 60
57 // Removes and frees all the enqueued chunks. 61 // Removes and frees all the enqueued chunks.
58 void Clear(); 62 void Clear();
59 63
60 // Checks whether the buffer is empty. 64 // Checks whether the buffer is empty.
61 bool IsEmpty() const; 65 bool IsEmpty() const;
62 66
63 private: 67 private:
64 typedef ScopedVector<AudioChunk> ChunksContainer; 68 typedef std::deque<scoped_refptr<AudioChunk> > ChunksContainer;
65 ChunksContainer chunks_; 69 ChunksContainer chunks_;
66 int bytes_per_sample_; 70 int bytes_per_sample_;
67 71
68 DISALLOW_COPY_AND_ASSIGN(AudioBuffer); 72 DISALLOW_COPY_AND_ASSIGN(AudioBuffer);
69 }; 73 };
70 74
71 } // namespace speech 75 } // namespace speech
72 76
73 #endif // CONTENT_BROWSER_SPEECH_AUDIO_BUFFER_H_ 77 #endif // CONTENT_BROWSER_SPEECH_AUDIO_BUFFER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/speech/audio_buffer.cc » ('j') | content/browser/speech/audio_buffer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698