Index: services/media/framework/allocator.cc |
diff --git a/services/media/framework/allocator.cc b/services/media/framework/allocator.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d07697b847bee36d3ae2ce56fd2b6bf7577cbd6d |
--- /dev/null |
+++ b/services/media/framework/allocator.cc |
@@ -0,0 +1,68 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <cstdlib> |
+ |
+#include "base/logging.h" |
+#include "services/media/framework/allocator.h" |
+ |
+namespace mojo { |
+namespace media { |
+ |
+namespace { |
+ |
+class DefaultAllocator : public Allocator { |
+ public: |
+ // Allocator implementation. |
+ void* AllocatePayloadBuffer(uint64_t size) override; |
+ |
+ void ReleasePayloadBuffer(uint64_t size, void* buffer) override; |
+}; |
+ |
+void* DefaultAllocator::AllocatePayloadBuffer(uint64_t size) { |
+ DCHECK(size > 0); |
+ return std::malloc(static_cast<size_t>(size)); |
+} |
+ |
+void DefaultAllocator::ReleasePayloadBuffer(uint64_t size, void* buffer) { |
+ DCHECK(size > 0); |
+ DCHECK(buffer); |
+ std::free(buffer); |
+} |
+ |
+class NullAllocator : public Allocator { |
+ public: |
+ // Allocator implementation. |
+ void* AllocatePayloadBuffer(uint64_t size) override; |
+ |
+ void ReleasePayloadBuffer(uint64_t size, void* buffer) override; |
+}; |
+ |
+void* NullAllocator::AllocatePayloadBuffer(uint64_t size) { |
+ NOTREACHED(); |
+ return nullptr; |
+} |
+ |
+void NullAllocator::ReleasePayloadBuffer(uint64_t size, void* buffer) { |
+ DCHECK(size > 0); |
+ DCHECK(buffer); |
johngro
2016/01/28 19:14:54
Given that allocate is NOTREACHED, shouldn't this
dalesat
2016/01/29 01:08:29
NullAllocator is used when the packet packet paylo
johngro
2016/02/01 22:38:16
Acknowledged.
|
+} |
+ |
+static DefaultAllocator default_allocator; |
+static NullAllocator null_allocator; |
johngro
2016/01/28 19:14:55
quick reminder, remember to make the Null allocato
dalesat
2016/01/29 01:08:29
Done.
|
+ |
+} // namespace |
+ |
+// static |
+Allocator* Allocator::GetDefault() { |
+ return &default_allocator; |
+} |
+ |
+// static |
+Allocator* Allocator::GetNull() { |
+ return &null_allocator; |
+} |
+ |
+} // namespace media |
+} // namespace mojo |