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

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

Issue 10123008: Introduced ChunkedByteBuffer class which will be needed by next speech recognition CLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added CONTENT_EXPORT to fix compilation issues on win bots. Created 8 years, 7 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
« no previous file with comments | « no previous file | content/browser/speech/chunked_byte_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_SPEECH_CHUNKED_BYTE_BUFFER_H_
6 #define CONTENT_BROWSER_SPEECH_CHUNKED_BYTE_BUFFER_H_
7 #pragma once
8
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "content/common/content_export.h"
16
17 namespace speech {
18
19 // Models a chunk-oriented byte buffer. The term chunk is herein defined as an
20 // arbitrary sequence of bytes that is preceeded by N header bytes, indicating
21 // its size. Data may be appended to the buffer with no particular respect of
22 // chunks boundaries. However, chunks can be extracted (FIFO) only when their
23 // content (according to their header) is fully available in the buffer.
24 // The current implementation support only 4 byte Big Endian headers.
25 // Empty chunks (i.e. the sequence 00 00 00 00) are NOT allowed.
26 //
27 // E.g. 00 00 00 04 xx xx xx xx 00 00 00 02 yy yy 00 00 00 04 zz zz zz zz
28 // [----- CHUNK 1 -------] [--- CHUNK 2 ---] [------ CHUNK 3 ------]
29 class CONTENT_EXPORT ChunkedByteBuffer {
30 public:
31 ChunkedByteBuffer();
32 ~ChunkedByteBuffer();
33
34 // Appends |length| bytes starting from |start| to the buffer.
35 void Append(const uint8* start, size_t length);
36
37 // Appends bytes contained in the |string| to the buffer.
38 void Append(const std::string& string);
39
40 // Checks whether one or more complete chunks are available in the buffer.
41 bool HasChunks() const;
42
43 // If enough data is available, reads and removes the first complete chunk
44 // from the buffer. Returns a NULL pointer if no complete chunk is available.
45 scoped_ptr< std::vector<uint8> > PopChunk();
46
47 // Clears all the content of the buffer.
48 void Clear();
49
50 // Returns the number of raw bytes (including headers) present.
51 size_t GetTotalLength() const { return total_bytes_stored_; }
52
53 private:
54 struct Chunk {
55 Chunk();
56 ~Chunk();
57
58 std::vector<uint8> header;
59 scoped_ptr< std::vector<uint8> > content;
60 size_t ExpectedContentLength() const;
61
62 private:
63 DISALLOW_COPY_AND_ASSIGN(Chunk);
64 };
65
66 ScopedVector<Chunk> chunks_;
67 scoped_ptr<Chunk> partial_chunk_;
68 size_t total_bytes_stored_;
69
70 DISALLOW_COPY_AND_ASSIGN(ChunkedByteBuffer);
71 };
72
73
74 } // namespace speech
75
76 #endif // CONTENT_BROWSER_SPEECH_CHUNKED_BYTE_BUFFER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/speech/chunked_byte_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698