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

Side by Side Diff: chromecast/media/cma/ipc/media_message.cc

Issue 1875623002: Convert //chromecast from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « chromecast/media/cma/ipc/media_message.h ('k') | chromecast/media/cma/ipc/media_message_fifo.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromecast/media/cma/ipc/media_message.h" 5 #include "chromecast/media/cma/ipc/media_message.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "chromecast/media/cma/ipc/media_memory_chunk.h" 11 #include "chromecast/media/cma/ipc/media_memory_chunk.h"
12 12
13 namespace chromecast { 13 namespace chromecast {
14 namespace media { 14 namespace media {
15 15
16 // static 16 // static
17 scoped_ptr<MediaMessage> MediaMessage::CreateDummyMessage(uint32_t type) { 17 std::unique_ptr<MediaMessage> MediaMessage::CreateDummyMessage(uint32_t type) {
18 return scoped_ptr<MediaMessage>( 18 return std::unique_ptr<MediaMessage>(
19 new MediaMessage(type, std::numeric_limits<size_t>::max())); 19 new MediaMessage(type, std::numeric_limits<size_t>::max()));
20 } 20 }
21 21
22 // static 22 // static
23 scoped_ptr<MediaMessage> MediaMessage::CreateMessage( 23 std::unique_ptr<MediaMessage> MediaMessage::CreateMessage(
24 uint32_t type, 24 uint32_t type,
25 const MemoryAllocatorCB& memory_allocator, 25 const MemoryAllocatorCB& memory_allocator,
26 size_t msg_content_capacity) { 26 size_t msg_content_capacity) {
27 size_t msg_size = minimum_msg_size() + msg_content_capacity; 27 size_t msg_size = minimum_msg_size() + msg_content_capacity;
28 28
29 // Make the message size a multiple of the alignment 29 // Make the message size a multiple of the alignment
30 // so that if we have proper alignment for array of messages. 30 // so that if we have proper alignment for array of messages.
31 size_t end_alignment = msg_size % ALIGNOF(SerializedMsg); 31 size_t end_alignment = msg_size % ALIGNOF(SerializedMsg);
32 if (end_alignment != 0) 32 if (end_alignment != 0)
33 msg_size += ALIGNOF(SerializedMsg) - end_alignment; 33 msg_size += ALIGNOF(SerializedMsg) - end_alignment;
34 34
35 scoped_ptr<MediaMemoryChunk> memory(memory_allocator.Run(msg_size)); 35 std::unique_ptr<MediaMemoryChunk> memory(memory_allocator.Run(msg_size));
36 if (!memory) 36 if (!memory)
37 return scoped_ptr<MediaMessage>(); 37 return std::unique_ptr<MediaMessage>();
38 38
39 return scoped_ptr<MediaMessage>(new MediaMessage(type, std::move(memory))); 39 return std::unique_ptr<MediaMessage>(
40 new MediaMessage(type, std::move(memory)));
40 } 41 }
41 42
42 // static 43 // static
43 scoped_ptr<MediaMessage> MediaMessage::CreateMessage( 44 std::unique_ptr<MediaMessage> MediaMessage::CreateMessage(
44 uint32_t type, 45 uint32_t type,
45 scoped_ptr<MediaMemoryChunk> memory) { 46 std::unique_ptr<MediaMemoryChunk> memory) {
46 return scoped_ptr<MediaMessage>(new MediaMessage(type, std::move(memory))); 47 return std::unique_ptr<MediaMessage>(
48 new MediaMessage(type, std::move(memory)));
47 } 49 }
48 50
49 // static 51 // static
50 scoped_ptr<MediaMessage> MediaMessage::MapMessage( 52 std::unique_ptr<MediaMessage> MediaMessage::MapMessage(
51 scoped_ptr<MediaMemoryChunk> memory) { 53 std::unique_ptr<MediaMemoryChunk> memory) {
52 return scoped_ptr<MediaMessage>(new MediaMessage(std::move(memory))); 54 return std::unique_ptr<MediaMessage>(new MediaMessage(std::move(memory)));
53 } 55 }
54 56
55 MediaMessage::MediaMessage(uint32_t type, size_t msg_size) 57 MediaMessage::MediaMessage(uint32_t type, size_t msg_size)
56 : is_dummy_msg_(true), 58 : is_dummy_msg_(true),
57 cached_header_(&cached_msg_.header), 59 cached_header_(&cached_msg_.header),
58 msg_(&cached_msg_), 60 msg_(&cached_msg_),
59 msg_read_only_(&cached_msg_), 61 msg_read_only_(&cached_msg_),
60 rd_offset_(0) { 62 rd_offset_(0) {
61 cached_header_->size = msg_size; 63 cached_header_->size = msg_size;
62 cached_header_->type = type; 64 cached_header_->type = type;
63 cached_header_->content_size = 0; 65 cached_header_->content_size = 0;
64 } 66 }
65 67
66 MediaMessage::MediaMessage(uint32_t type, scoped_ptr<MediaMemoryChunk> memory) 68 MediaMessage::MediaMessage(uint32_t type,
69 std::unique_ptr<MediaMemoryChunk> memory)
67 : is_dummy_msg_(false), 70 : is_dummy_msg_(false),
68 cached_header_(&cached_msg_.header), 71 cached_header_(&cached_msg_.header),
69 msg_(static_cast<SerializedMsg*>(memory->data())), 72 msg_(static_cast<SerializedMsg*>(memory->data())),
70 msg_read_only_(msg_), 73 msg_read_only_(msg_),
71 mem_(std::move(memory)), 74 mem_(std::move(memory)),
72 rd_offset_(0) { 75 rd_offset_(0) {
73 CHECK(mem_->valid()); 76 CHECK(mem_->valid());
74 CHECK_GE(mem_->size(), minimum_msg_size()); 77 CHECK_GE(mem_->size(), minimum_msg_size());
75 78
76 // Check memory alignment: 79 // Check memory alignment:
77 // needed to cast properly |msg_dst| to a SerializedMsg. 80 // needed to cast properly |msg_dst| to a SerializedMsg.
78 CHECK_EQ( 81 CHECK_EQ(
79 reinterpret_cast<uintptr_t>(mem_->data()) % ALIGNOF(SerializedMsg), 0u); 82 reinterpret_cast<uintptr_t>(mem_->data()) % ALIGNOF(SerializedMsg), 0u);
80 83
81 // Make sure that |mem_->data()| + |mem_->size()| is also aligned correctly. 84 // Make sure that |mem_->data()| + |mem_->size()| is also aligned correctly.
82 // This is needed if we append a second serialized message next to this one. 85 // This is needed if we append a second serialized message next to this one.
83 // The second serialized message must be aligned correctly. 86 // The second serialized message must be aligned correctly.
84 // It is similar to what a compiler is doing for arrays of structures. 87 // It is similar to what a compiler is doing for arrays of structures.
85 CHECK_EQ(mem_->size() % ALIGNOF(SerializedMsg), 0u); 88 CHECK_EQ(mem_->size() % ALIGNOF(SerializedMsg), 0u);
86 89
87 cached_header_->size = mem_->size(); 90 cached_header_->size = mem_->size();
88 cached_header_->type = type; 91 cached_header_->type = type;
89 cached_header_->content_size = 0; 92 cached_header_->content_size = 0;
90 msg_->header = *cached_header_; 93 msg_->header = *cached_header_;
91 } 94 }
92 95
93 MediaMessage::MediaMessage(scoped_ptr<MediaMemoryChunk> memory) 96 MediaMessage::MediaMessage(std::unique_ptr<MediaMemoryChunk> memory)
94 : is_dummy_msg_(false), 97 : is_dummy_msg_(false),
95 cached_header_(&cached_msg_.header), 98 cached_header_(&cached_msg_.header),
96 msg_(NULL), 99 msg_(NULL),
97 msg_read_only_(static_cast<SerializedMsg*>(memory->data())), 100 msg_read_only_(static_cast<SerializedMsg*>(memory->data())),
98 mem_(std::move(memory)), 101 mem_(std::move(memory)),
99 rd_offset_(0) { 102 rd_offset_(0) {
100 CHECK(mem_->valid()); 103 CHECK(mem_->valid());
101 104
102 // Check memory alignment. 105 // Check memory alignment.
103 CHECK_EQ( 106 CHECK_EQ(
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 rd_offset_ += size; 191 rd_offset_ += size;
189 return rd_ptr; 192 return rd_ptr;
190 } 193 }
191 194
192 const void* MediaMessage::GetBuffer(size_t size) { 195 const void* MediaMessage::GetBuffer(size_t size) {
193 return GetWritableBuffer(size); 196 return GetWritableBuffer(size);
194 } 197 }
195 198
196 } // namespace media 199 } // namespace media
197 } // namespace chromecast 200 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/media/cma/ipc/media_message.h ('k') | chromecast/media/cma/ipc/media_message_fifo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698