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

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: Reimplemented according to Satish suggestions. Created 8 years, 8 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
(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
16 namespace speech {
17
18 // Models a chunk-oriented byte buffer. The term chunk is herein defined as an
19 // arbitrary sequence of bytes that is preceeded by N header bytes, indicating
20 // its size. Data may be appended to the buffer with no particular respect of
21 // chunks boundaries. However, chunks can be extracted (FIFO) only when their
22 // content (according to their header) is fully available in the buffer.
23 // The current implementation support only 4 byte Big Endian headers.
24 // Empty chunks (i.e. the sequence 00 00 00 00) are NOT allowed.
25 //
26 // E.g. 00 00 00 04 xx xx xx xx 00 00 00 02 yy yy 00 00 00 04 zz zz zz zz
27 // [----- CHUNK 1 -------] [--- CHUNK 2 ---] [------ CHUNK 3 ------]
28 class ChunkedByteBuffer {
29 public:
30 ChunkedByteBuffer();
31 ~ChunkedByteBuffer();
32
33 // Appends |length| bytes starting from |start| to the buffer.
34 void Append(const uint8* start, size_t length);
35
36 // Appends bytes contained into the |string| to the buffer.
37 void Append(const std::string& string);
38
39 // Returns the length of the next complete chunk, or 0 if no complete chunk
40 // is available.
41 size_t GetNextChunkLength() const;
42
43 // If enough data is available, reads a chunk from the buffer, copying its
44 // start pointer in |start_ptr| and returning its length. Returns 0 if no
45 // complete chunk is available in the buffer.
46 // The chunk is NOT removed from the buffer after this call.
47 size_t GetNextChunk(const uint8** start_ptr) const;
Satish 2012/04/24 09:10:14 since this class doesn't allow iterating through a
48
49 // Shifts out the first chunk from the buffer.
50 void RemoveNextChunk();
51
52 // Clears all the content of the buffer.
53 void Clear();
54
55 // Returns the number of raw bytes (including headers) present.
56 size_t GetTotalLength() const { return total_bytes_stored_; }
57
58 private:
59 static uint32 ReadBigEndian32(const uint8* buffer);
60
61 struct Chunk {
62 Chunk() {}
Satish 2012/04/24 09:10:14 ctor/dtor shouldn't be inlined, move these to the
63 ~Chunk() {}
64
65 std::vector<uint8> header;
66 std::vector<uint8> content;
67 inline size_t ExpectedContentLength() const;
Satish 2012/04/24 09:10:14 remove 'inline'
68
69 private:
70 DISALLOW_COPY_AND_ASSIGN(Chunk);
71 };
72
73 ScopedVector<Chunk> chunks_;
74 scoped_ptr<Chunk> partial_chunk_;
75 size_t total_bytes_stored_;
76
77 DISALLOW_COPY_AND_ASSIGN(ChunkedByteBuffer);
78 };
79
80 } // namespace speech
81
82 #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') | content/browser/speech/chunked_byte_buffer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698