OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 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 // CompoundBuffer implements a data buffer that is composed of several pieces, | |
6 // each stored in a refcounted IOBuffer. It is needed for encoding/decoding | |
7 // video pipeline to represent data packet and minimize data copying. | |
8 // It is particularly useful for splitting data between multiple RTP packets | |
9 // and assembling them into one buffer on the receiving side. | |
awong
2010/11/12 02:40:06
Hmm...it feels like we just reimplemented rope. :P
Sergey Ulanov
2010/11/13 04:43:39
hmm, yeah. Except rope doesn't use IOBuffer, so yo
awong
2010/11/16 00:04:57
Yeah...that sucks. :-/
| |
10 // | |
11 // CompoundBuffer also implements ZeroCopyInputStream interface to be used by | |
12 // protobuf to decode bytes into a protocol buffer message. | |
13 | |
14 #ifndef REMOTING_BASE_COMPOUND_BUFFER_H_ | |
15 #define REMOTING_BASE_COMPOUND_BUFFER_H_ | |
16 | |
17 #include <deque> | |
18 | |
19 #include "base/basictypes.h" | |
20 #include "base/ref_counted.h" | |
21 #include "google/protobuf/io/zero_copy_stream.h" | |
22 | |
23 namespace net { | |
24 class IOBuffer; | |
25 class IOBufferWithSize; | |
26 } // namespace net | |
27 | |
28 namespace remoting { | |
29 | |
30 class CompoundBuffer : | |
31 public google::protobuf::io::ZeroCopyInputStream { | |
awong
2010/11/12 02:40:06
Isn't this just supposed to go in 4-spaces?
Sergey Ulanov
2010/11/13 04:43:39
":" must be on this line. Done.
| |
32 public: | |
33 CompoundBuffer(); | |
34 virtual ~CompoundBuffer(); | |
35 | |
36 void Clear(); | |
37 | |
38 // Adds new chunk to the buffer. |data| must point to start of the data | |
awong
2010/11/12 02:40:06
How about rename |data| to |start|?
Also, specify
Sergey Ulanov
2010/11/13 04:43:39
Done.
| |
39 // within |buffer|. | |
40 void Append(net::IOBuffer* buffer, int data_size); | |
41 void Append(net::IOBuffer* buffer, const char* data, int data_size); | |
awong
2010/11/12 02:40:06
overloading is frowned upon by the style guide. R
Sergey Ulanov
2010/11/13 04:43:39
I think this is a legal use of overloading, as bot
awong
2010/11/16 00:04:57
Yeah...I don't feel fully comfortable with it, but
| |
42 void Prepend(net::IOBuffer* buffer, int data_size); | |
43 void Prepend(net::IOBuffer* buffer, const char* data, int data_size); | |
44 | |
45 // Same as above, but creates new IOBuffer and copies the data. | |
46 void CopyAndAppend(const char* data, int data_size); | |
awong
2010/11/12 02:40:06
CopyFrom() below implies a clear. These do not.
Sergey Ulanov
2010/11/13 04:43:39
Done.
| |
47 void CopyAndPrepend(const char* data, int data_size); | |
48 | |
49 // Current size of the buffer. | |
50 int total_bytes() const { return total_bytes_; } | |
51 | |
52 // Assemble all chunks in one buffer. | |
awong
2010/11/12 02:40:06
The word "buffer" has too many meanings in this fi
Sergey Ulanov
2010/11/13 04:43:39
Done.
| |
53 net::IOBufferWithSize* Assemble() const; | |
54 void Assemble(char* data, int data_size) const; | |
awong
2010/11/12 02:40:06
How about the names:
OutputAsIOBufferWithSize()
T
Sergey Ulanov
2010/11/13 04:43:39
Renamed to ToIOBufferWithSize().
| |
55 | |
56 // Drops current content of the buffer, and initializes it with the interval | |
awong
2010/11/12 02:40:06
How about "Calls Clear(), and then initializes..."
Sergey Ulanov
2010/11/13 04:43:39
The fact that it calls Clear() is an implementatio
| |
57 // from |buffer| starting at |start| and ending at |end|. The data itself | |
58 // isn't copied. | |
59 void CopyFrom(const CompoundBuffer& source, int start, int end); | |
60 | |
61 // google::protobuf::io::ZeroCopyInputStream interface. | |
awong
2010/11/12 02:40:06
There seems to be some funky API interactions. Nam
Sergey Ulanov
2010/11/13 04:43:39
Done. Also added Lock() method to ensure that the
| |
62 virtual bool Next(const void** data, int* size); | |
63 virtual void BackUp(int count); | |
64 virtual bool Skip(int count); | |
65 virtual int64 ByteCount() const; | |
66 | |
67 private: | |
68 struct DataChunk { | |
69 DataChunk(net::IOBuffer* buffer, const char* data_start, int data_size); | |
70 | |
71 scoped_refptr<net::IOBuffer> buffer; | |
72 const char* data_start; | |
73 int data_size; | |
74 }; | |
75 typedef std::deque<DataChunk> DataChunkList; | |
76 | |
77 DataChunkList buffers_; | |
78 int total_bytes_; | |
79 | |
80 // Current position for ZeroCopyInputStream. | |
awong
2010/11/12 02:40:06
What happens to all this stuff if you start using
Sergey Ulanov
2010/11/13 04:43:39
Moved these to CompoundBufferInputStream
| |
81 size_t current_buffer_; | |
82 int current_buffer_position_; | |
83 int position_; | |
84 int last_returned_size_; | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(CompoundBuffer); | |
87 }; | |
88 | |
89 } // namespace remoting | |
90 | |
91 #endif // REMOTING_BASE_COMPOUND_BUFFER_H_ | |
OLD | NEW |