OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 #include <cstdlib> | |
6 | |
7 #include "base/logging.h" | |
8 #include "services/media/framework/allocator.h" | |
9 | |
10 namespace mojo { | |
11 namespace media { | |
12 | |
13 namespace { | |
14 | |
15 class DefaultAllocator : public Allocator { | |
16 public: | |
17 // Allocator implementation. | |
18 void* AllocatePayloadBuffer(uint64_t size) override; | |
19 | |
20 void ReleasePayloadBuffer(uint64_t size, void* buffer) override; | |
21 }; | |
22 | |
23 void* DefaultAllocator::AllocatePayloadBuffer(uint64_t size) { | |
24 DCHECK(size > 0); | |
25 return std::malloc(static_cast<size_t>(size)); | |
26 } | |
27 | |
28 void DefaultAllocator::ReleasePayloadBuffer(uint64_t size, void* buffer) { | |
29 DCHECK(size > 0); | |
30 DCHECK(buffer); | |
31 std::free(buffer); | |
32 } | |
33 | |
34 class NullAllocator : public Allocator { | |
35 public: | |
36 // Allocator implementation. | |
37 void* AllocatePayloadBuffer(uint64_t size) override; | |
38 | |
39 void ReleasePayloadBuffer(uint64_t size, void* buffer) override; | |
40 }; | |
41 | |
42 void* NullAllocator::AllocatePayloadBuffer(uint64_t size) { | |
43 NOTREACHED(); | |
44 return nullptr; | |
45 } | |
46 | |
47 void NullAllocator::ReleasePayloadBuffer(uint64_t size, void* buffer) { | |
48 DCHECK(size > 0); | |
49 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.
| |
50 } | |
51 | |
52 static DefaultAllocator default_allocator; | |
53 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.
| |
54 | |
55 } // namespace | |
56 | |
57 // static | |
58 Allocator* Allocator::GetDefault() { | |
59 return &default_allocator; | |
60 } | |
61 | |
62 // static | |
63 Allocator* Allocator::GetNull() { | |
64 return &null_allocator; | |
65 } | |
66 | |
67 } // namespace media | |
68 } // namespace mojo | |
OLD | NEW |