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

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

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
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 #ifndef CHROMECAST_MEDIA_CMA_IPC_MEDIA_MESSAGE_H_ 5 #ifndef CHROMECAST_MEDIA_CMA_IPC_MEDIA_MESSAGE_H_
6 #define CHROMECAST_MEDIA_CMA_IPC_MEDIA_MESSAGE_H_ 6 #define CHROMECAST_MEDIA_CMA_IPC_MEDIA_MESSAGE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <memory>
12
11 #include "base/callback.h" 13 #include "base/callback.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 15
15 namespace chromecast { 16 namespace chromecast {
16 namespace media { 17 namespace media {
17 class MediaMemoryChunk; 18 class MediaMemoryChunk;
18 19
19 // MediaMessage - 20 // MediaMessage -
20 // Represents a media message, including: 21 // Represents a media message, including:
21 // - a message header that gives for example the message size or its type, 22 // - a message header that gives for example the message size or its type,
22 // - the content of the message, 23 // - the content of the message,
23 // - and some possible padding if the content does not occupy the whole 24 // - and some possible padding if the content does not occupy the whole
24 // reserved space. 25 // reserved space.
25 // 26 //
26 class MediaMessage { 27 class MediaMessage {
27 public: 28 public:
28 // Memory allocator: given a number of bytes to allocate, 29 // Memory allocator: given a number of bytes to allocate,
29 // return the pointer to the allocated block if successful 30 // return the pointer to the allocated block if successful
30 // or NULL if allocation failed. 31 // or NULL if allocation failed.
31 typedef base::Callback<scoped_ptr<MediaMemoryChunk>(size_t)> 32 typedef base::Callback<std::unique_ptr<MediaMemoryChunk>(size_t)>
32 MemoryAllocatorCB; 33 MemoryAllocatorCB;
33 34
34 // Creates a message with no associated memory for its content, i.e. 35 // Creates a message with no associated memory for its content, i.e.
35 // each write on this message is a dummy operation. 36 // each write on this message is a dummy operation.
36 // This type of message can be useful to calculate first the size of the 37 // This type of message can be useful to calculate first the size of the
37 // message, before allocating the real message. 38 // message, before allocating the real message.
38 static scoped_ptr<MediaMessage> CreateDummyMessage(uint32_t type); 39 static std::unique_ptr<MediaMessage> CreateDummyMessage(uint32_t type);
39 40
40 // Creates a message with a capacity of at least |msg_content_capacity| 41 // Creates a message with a capacity of at least |msg_content_capacity|
41 // bytes. The actual content size can be smaller than its capacity. 42 // bytes. The actual content size can be smaller than its capacity.
42 // The message can be populated with some Write functions. 43 // The message can be populated with some Write functions.
43 static scoped_ptr<MediaMessage> CreateMessage( 44 static std::unique_ptr<MediaMessage> CreateMessage(
44 uint32_t type, 45 uint32_t type,
45 const MemoryAllocatorCB& memory_allocator, 46 const MemoryAllocatorCB& memory_allocator,
46 size_t msg_content_capacity); 47 size_t msg_content_capacity);
47 48
48 // Creates a message of type |type| whose serialized structure is stored 49 // Creates a message of type |type| whose serialized structure is stored
49 // in |mem|. 50 // in |mem|.
50 static scoped_ptr<MediaMessage> CreateMessage( 51 static std::unique_ptr<MediaMessage> CreateMessage(
51 uint32_t type, 52 uint32_t type,
52 scoped_ptr<MediaMemoryChunk> mem); 53 std::unique_ptr<MediaMemoryChunk> mem);
53 54
54 // Creates a message from a memory area which already contains 55 // Creates a message from a memory area which already contains
55 // the serialized structure of the message. 56 // the serialized structure of the message.
56 // Only Read functions can be invoked on this type of message. 57 // Only Read functions can be invoked on this type of message.
57 static scoped_ptr<MediaMessage> MapMessage( 58 static std::unique_ptr<MediaMessage> MapMessage(
58 scoped_ptr<MediaMemoryChunk> mem); 59 std::unique_ptr<MediaMemoryChunk> mem);
59 60
60 // Return the minimum size of a message. 61 // Return the minimum size of a message.
61 static size_t minimum_msg_size() { 62 static size_t minimum_msg_size() {
62 return offsetof(SerializedMsg, content); 63 return offsetof(SerializedMsg, content);
63 } 64 }
64 65
65 ~MediaMessage(); 66 ~MediaMessage();
66 67
67 // Indicate whether the underlying serialized structure of the message is 68 // Indicate whether the underlying serialized structure of the message is
68 // available. 69 // available.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // and write it to |dst|. 106 // and write it to |dst|.
106 bool ReadBuffer(void* dst, size_t size); 107 bool ReadBuffer(void* dst, size_t size);
107 108
108 // Return a pointer to a buffer of size |size|. 109 // Return a pointer to a buffer of size |size|.
109 // Return NULL if not successful. 110 // Return NULL if not successful.
110 const void* GetBuffer(size_t size); 111 const void* GetBuffer(size_t size);
111 void* GetWritableBuffer(size_t size); 112 void* GetWritableBuffer(size_t size);
112 113
113 private: 114 private:
114 MediaMessage(uint32_t type, size_t msg_size); 115 MediaMessage(uint32_t type, size_t msg_size);
115 MediaMessage(uint32_t type, scoped_ptr<MediaMemoryChunk> memory); 116 MediaMessage(uint32_t type, std::unique_ptr<MediaMemoryChunk> memory);
116 MediaMessage(scoped_ptr<MediaMemoryChunk> memory); 117 MediaMessage(std::unique_ptr<MediaMemoryChunk> memory);
117 118
118 struct Header { 119 struct Header {
119 // Total size of the message (including both header & content). 120 // Total size of the message (including both header & content).
120 uint32_t size; 121 uint32_t size;
121 // Indicate the message type. 122 // Indicate the message type.
122 uint32_t type; 123 uint32_t type;
123 // Actual size of the content in the message. 124 // Actual size of the content in the message.
124 uint32_t content_size; 125 uint32_t content_size;
125 }; 126 };
126 127
(...skipping 17 matching lines...) Expand all
144 // issues. 145 // issues.
145 SerializedMsg cached_msg_; 146 SerializedMsg cached_msg_;
146 Header* const cached_header_; 147 Header* const cached_header_;
147 148
148 SerializedMsg* msg_; 149 SerializedMsg* msg_;
149 SerializedMsg* msg_read_only_; 150 SerializedMsg* msg_read_only_;
150 151
151 // Memory allocated to store the underlying serialized structure into memory. 152 // Memory allocated to store the underlying serialized structure into memory.
152 // Note: a dummy message has no underlying serialized structure: 153 // Note: a dummy message has no underlying serialized structure:
153 // |mem_| is a null pointer in that case. 154 // |mem_| is a null pointer in that case.
154 scoped_ptr<MediaMemoryChunk> mem_; 155 std::unique_ptr<MediaMemoryChunk> mem_;
155 156
156 // Read iterator into the message. 157 // Read iterator into the message.
157 size_t rd_offset_; 158 size_t rd_offset_;
158 159
159 DISALLOW_COPY_AND_ASSIGN(MediaMessage); 160 DISALLOW_COPY_AND_ASSIGN(MediaMessage);
160 }; 161 };
161 162
162 } // namespace media 163 } // namespace media
163 } // namespace chromecast 164 } // namespace chromecast
164 165
165 #endif 166 #endif
OLDNEW
« no previous file with comments | « chromecast/media/cma/decoder/cast_audio_decoder_linux.cc ('k') | chromecast/media/cma/ipc/media_message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698