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

Side by Side Diff: services/media/common/media_pipe_base.cc

Issue 1509323002: Mojom updates for Motown. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: sync Created 4 years, 11 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 | « services/media/audio/platform/linux/alsa_output.cc ('k') | shell/BUILD.gn » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "services/media/common/media_pipe_base.h" 6 #include "services/media/common/media_pipe_base.h"
7 7
8 namespace mojo { 8 namespace mojo {
9 namespace media { 9 namespace media {
10 10
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (!buffer_) { 94 if (!buffer_) {
95 cbk.Run(MediaResult::BAD_STATE); 95 cbk.Run(MediaResult::BAD_STATE);
96 return; 96 return;
97 } 97 }
98 DCHECK(buffer_size_); 98 DCHECK(buffer_size_);
99 99
100 // The offset(s) and size(s) of this payload must to reside within the space 100 // The offset(s) and size(s) of this payload must to reside within the space
101 // of the shared buffer. If any does not, this send operation is not valid. 101 // of the shared buffer. If any does not, this send operation is not valid.
102 const MediaPacketRegionPtr* r = &packet->payload; 102 const MediaPacketRegionPtr* r = &packet->payload;
103 size_t i = 0; 103 size_t i = 0;
104 size_t extra_payload_size =
105 packet->extra_payload.is_null() ? 0 : packet->extra_payload.size();
104 while (true) { 106 while (true) {
105 if ((*r).is_null()) { 107 if ((*r).is_null()) {
106 cbk.Run(MediaResult::INVALID_ARGUMENT); 108 cbk.Run(MediaResult::INVALID_ARGUMENT);
107 return; 109 return;
108 } 110 }
109 111
110 auto offset = (*r)->offset; 112 auto offset = (*r)->offset;
111 auto length = (*r)->length; 113 auto length = (*r)->length;
112 if ((offset > buffer_size_) || (length > (buffer_size_ - offset))) { 114 if ((offset > buffer_size_) || (length > (buffer_size_ - offset))) {
113 cbk.Run(MediaResult::INVALID_ARGUMENT); 115 cbk.Run(MediaResult::INVALID_ARGUMENT);
114 return; 116 return;
115 } 117 }
116 118
117 if (i >= packet->extra_payload.size()) { 119 if (i >= extra_payload_size) {
118 break; 120 break;
119 } 121 }
120 122
123 DCHECK(packet->extra_payload);
121 r = &packet->extra_payload[i++]; 124 r = &packet->extra_payload[i++];
122 } 125 }
123 126
124 // Looks good, send this packet up to the implementation layer. 127 // Looks good, send this packet up to the implementation layer.
125 MediaPacketStatePtr ptr(new MediaPacketState(packet.Pass(), cbk)); 128 MediaPacketStatePtr ptr(new MediaPacketState(packet.Pass(), cbk));
126 OnPacketReceived(std::move(ptr)); 129 OnPacketReceived(std::move(ptr));
127 } 130 }
128 131
129 void MediaPipeBase::Flush(const FlushCallback& cbk) { 132 void MediaPipeBase::Flush(const FlushCallback& cbk) {
130 // If we have not been successfully initialized, then we should not be getting 133 // If we have not been successfully initialized, then we should not be getting
(...skipping 18 matching lines...) Expand all
149 } 152 }
150 153
151 MediaPipeBase::MediaPacketState::MediaPacketState( 154 MediaPipeBase::MediaPacketState::MediaPacketState(
152 MediaPacketPtr packet, 155 MediaPacketPtr packet,
153 const SendPacketCallback& cbk) 156 const SendPacketCallback& cbk)
154 : packet_(packet.Pass()) 157 : packet_(packet.Pass())
155 , cbk_(cbk) 158 , cbk_(cbk)
156 , result_(MediaResult::OK) { 159 , result_(MediaResult::OK) {
157 DCHECK(packet_); 160 DCHECK(packet_);
158 DCHECK(packet_->payload); 161 DCHECK(packet_->payload);
159 DCHECK(packet_->extra_payload);
160 } 162 }
161 163
162 MediaPipeBase::MediaPacketState::~MediaPacketState() { 164 MediaPipeBase::MediaPacketState::~MediaPacketState() {
163 cbk_.Run(result_); 165 cbk_.Run(result_);
164 } 166 }
165 167
166 void MediaPipeBase::MediaPacketState::SetResult(MediaResult result) { 168 void MediaPipeBase::MediaPacketState::SetResult(MediaResult result) {
167 MediaResult tmp = MediaResult::OK; 169 MediaResult tmp = MediaResult::OK;
168 result_.compare_exchange_strong(tmp, result); 170 result_.compare_exchange_strong(tmp, result);
169 } 171 }
170 172
171 } // namespace media 173 } // namespace media
172 } // namespace mojo 174 } // namespace mojo
OLDNEW
« no previous file with comments | « services/media/audio/platform/linux/alsa_output.cc ('k') | shell/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698