OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/numerics/safe_math.h" | 10 #include "base/numerics/safe_math.h" |
11 #include "content/common/gpu/media/media_messages.h" | 11 #include "content/common/gpu/media/media_messages.h" |
12 | 12 |
13 namespace IPC { | 13 namespace IPC { |
14 | 14 |
15 void ParamTraits<media::BitstreamBuffer>::Write(base::Pickle* m, | 15 void ParamTraits<media::BitstreamBuffer>::Write(base::Pickle* m, |
16 const param_type& p) { | 16 const param_type& p) { |
17 WriteParam(m, p.id()); | 17 WriteParam(m, p.id()); |
18 WriteParam(m, static_cast<uint64_t>(p.size())); | 18 WriteParam(m, static_cast<uint64_t>(p.size())); |
| 19 DCHECK_GE(p.offset(), 0); |
| 20 WriteParam(m, static_cast<uint64_t>(p.offset())); |
19 WriteParam(m, p.presentation_timestamp()); | 21 WriteParam(m, p.presentation_timestamp()); |
20 WriteParam(m, p.key_id()); | 22 WriteParam(m, p.key_id()); |
21 if (!p.key_id().empty()) { | 23 if (!p.key_id().empty()) { |
22 WriteParam(m, p.iv()); | 24 WriteParam(m, p.iv()); |
23 WriteParam(m, p.subsamples()); | 25 WriteParam(m, p.subsamples()); |
24 } | 26 } |
25 WriteParam(m, p.handle()); | 27 WriteParam(m, p.handle()); |
26 } | 28 } |
27 | 29 |
28 bool ParamTraits<media::BitstreamBuffer>::Read(const base::Pickle* m, | 30 bool ParamTraits<media::BitstreamBuffer>::Read(const base::Pickle* m, |
29 base::PickleIterator* iter, | 31 base::PickleIterator* iter, |
30 param_type* r) { | 32 param_type* r) { |
31 DCHECK(r); | 33 DCHECK(r); |
32 uint64_t size = 0; | 34 uint64_t size = 0; |
| 35 uint64_t offset = 0; |
33 if (!(ReadParam(m, iter, &r->id_) && ReadParam(m, iter, &size) && | 36 if (!(ReadParam(m, iter, &r->id_) && ReadParam(m, iter, &size) && |
| 37 ReadParam(m, iter, &offset) && |
34 ReadParam(m, iter, &r->presentation_timestamp_) && | 38 ReadParam(m, iter, &r->presentation_timestamp_) && |
35 ReadParam(m, iter, &r->key_id_))) | 39 ReadParam(m, iter, &r->key_id_))) |
36 return false; | 40 return false; |
37 | 41 |
38 base::CheckedNumeric<size_t> checked_size(size); | 42 base::CheckedNumeric<size_t> checked_size(size); |
39 if (!checked_size.IsValid()) { | 43 if (!checked_size.IsValid()) { |
40 DLOG(ERROR) << "Invalid size: " << size; | 44 DLOG(ERROR) << "Invalid size: " << size; |
41 return false; | 45 return false; |
42 } | 46 } |
43 r->size_ = checked_size.ValueOrDie(); | 47 r->size_ = checked_size.ValueOrDie(); |
44 | 48 |
| 49 base::CheckedNumeric<off_t> checked_offset(offset); |
| 50 if (!checked_offset.IsValid()) { |
| 51 DLOG(ERROR) << "Invalid offset: " << offset; |
| 52 return false; |
| 53 } |
| 54 r->offset_ = checked_offset.ValueOrDie(); |
| 55 |
45 if (!r->key_id_.empty()) { | 56 if (!r->key_id_.empty()) { |
46 if (!(ReadParam(m, iter, &r->iv_) && ReadParam(m, iter, &r->subsamples_))) | 57 if (!(ReadParam(m, iter, &r->iv_) && ReadParam(m, iter, &r->subsamples_))) |
47 return false; | 58 return false; |
48 } | 59 } |
49 | 60 |
50 return ReadParam(m, iter, &r->handle_); | 61 return ReadParam(m, iter, &r->handle_); |
51 } | 62 } |
52 | 63 |
53 void ParamTraits<media::BitstreamBuffer>::Log(const param_type& p, | 64 void ParamTraits<media::BitstreamBuffer>::Log(const param_type& p, |
54 std::string* l) { | 65 std::string* l) { |
55 std::ostringstream oss; | 66 std::ostringstream oss; |
56 oss << "id=" << p.id() << ", size=" << p.size() << ", presentation_timestamp=" | 67 oss << "id=" << p.id() << ", size=" << p.size() << ", presentation_timestamp=" |
57 << p.presentation_timestamp().ToInternalValue(); | 68 << p.presentation_timestamp().ToInternalValue(); |
58 l->append(oss.str()); | 69 l->append(oss.str()); |
59 } | 70 } |
60 | 71 |
61 } // namespace IPC | 72 } // namespace IPC |
OLD | NEW |