Shaka Player Embedded
dynamic_buffer.h
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHAKA_EMBEDDED_UTIL_DYNAMIC_BUFFER_H_
16 #define SHAKA_EMBEDDED_UTIL_DYNAMIC_BUFFER_H_
17 
18 #include <list>
19 #include <memory>
20 #include <string>
21 
22 namespace shaka {
23 namespace util {
24 
32  public:
33  DynamicBuffer();
35 
36  DynamicBuffer(const DynamicBuffer&) = delete;
38  DynamicBuffer& operator=(const DynamicBuffer&) = delete;
40 
42  size_t Size() const;
43 
45  void Clear() {
46  buffers_.clear();
47  }
48 
50  void AppendCopy(const void* buffer, size_t size);
51 
52 
54  std::string CreateString() const;
55 
57  void CopyDataTo(uint8_t* dest, size_t size) const;
58 
59  private:
60  friend class DynamicBufferTest;
61 
62  static constexpr const size_t kMinBufferSize = 64 * 1024;
63 
64  struct SubBuffer {
65  SubBuffer(uint8_t* buffer, size_t used, size_t capacity);
66  ~SubBuffer();
67 
68  std::unique_ptr<uint8_t[]> buffer;
69  size_t used;
70  size_t capacity;
71  };
72 
73  std::list<SubBuffer> buffers_;
74 };
75 
76 } // namespace util
77 } // namespace shaka
78 
79 #endif // SHAKA_EMBEDDED_UTIL_DYNAMIC_BUFFER_H_
const char * dest
Definition: media_utils.cc:31
void CopyDataTo(uint8_t *dest, size_t size) const
std::string CreateString() const
void AppendCopy(const void *buffer, size_t size)
DynamicBuffer & operator=(const DynamicBuffer &)=delete