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

Side by Side Diff: media/cast/logging/log_serializer.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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 // The serialization format is as follows: 5 // The serialization format is as follows:
6 // 16-bit integer describing the following LogMetadata proto size in bytes. 6 // 16-bit integer describing the following LogMetadata proto size in bytes.
7 // The LogMetadata proto. 7 // The LogMetadata proto.
8 // 32-bit integer describing number of frame events. 8 // 32-bit integer describing number of frame events.
9 // (The following repeated for number of frame events): 9 // (The following repeated for number of frame events):
10 // 16-bit integer describing the following AggregatedFrameEvent proto size 10 // 16-bit integer describing the following AggregatedFrameEvent proto size
(...skipping 29 matching lines...) Expand all
40 bool DoSerializeEvents(const LogMetadata& metadata, 40 bool DoSerializeEvents(const LogMetadata& metadata,
41 const FrameEventList& frame_events, 41 const FrameEventList& frame_events,
42 const PacketEventList& packet_events, 42 const PacketEventList& packet_events,
43 const int max_output_bytes, 43 const int max_output_bytes,
44 char* output, 44 char* output,
45 int* output_bytes) { 45 int* output_bytes) {
46 base::BigEndianWriter writer(output, max_output_bytes); 46 base::BigEndianWriter writer(output, max_output_bytes);
47 47
48 int proto_size = metadata.ByteSize(); 48 int proto_size = metadata.ByteSize();
49 DCHECK(proto_size <= kMaxSerializedProtoBytes); 49 DCHECK(proto_size <= kMaxSerializedProtoBytes);
50 if (!writer.WriteU16(static_cast<uint16>(proto_size))) 50 if (!writer.WriteU16(static_cast<uint16_t>(proto_size)))
51 return false; 51 return false;
52 if (!metadata.SerializeToArray(writer.ptr(), writer.remaining())) 52 if (!metadata.SerializeToArray(writer.ptr(), writer.remaining()))
53 return false; 53 return false;
54 if (!writer.Skip(proto_size)) 54 if (!writer.Skip(proto_size))
55 return false; 55 return false;
56 56
57 RtpTimestamp prev_rtp_timestamp = 0; 57 RtpTimestamp prev_rtp_timestamp = 0;
58 for (media::cast::FrameEventList::const_iterator it = frame_events.begin(); 58 for (media::cast::FrameEventList::const_iterator it = frame_events.begin();
59 it != frame_events.end(); 59 it != frame_events.end();
60 ++it) { 60 ++it) {
61 media::cast::proto::AggregatedFrameEvent frame_event(**it); 61 media::cast::proto::AggregatedFrameEvent frame_event(**it);
62 62
63 // Adjust relative RTP timestamp so that it is relative to previous frame, 63 // Adjust relative RTP timestamp so that it is relative to previous frame,
64 // rather than relative to first RTP timestamp. 64 // rather than relative to first RTP timestamp.
65 // This is done to improve encoding size. 65 // This is done to improve encoding size.
66 RtpTimestamp old_relative_rtp_timestamp = 66 RtpTimestamp old_relative_rtp_timestamp =
67 frame_event.relative_rtp_timestamp(); 67 frame_event.relative_rtp_timestamp();
68 frame_event.set_relative_rtp_timestamp( 68 frame_event.set_relative_rtp_timestamp(
69 old_relative_rtp_timestamp - prev_rtp_timestamp); 69 old_relative_rtp_timestamp - prev_rtp_timestamp);
70 prev_rtp_timestamp = old_relative_rtp_timestamp; 70 prev_rtp_timestamp = old_relative_rtp_timestamp;
71 71
72 proto_size = frame_event.ByteSize(); 72 proto_size = frame_event.ByteSize();
73 DCHECK(proto_size <= kMaxSerializedProtoBytes); 73 DCHECK(proto_size <= kMaxSerializedProtoBytes);
74 74
75 // Write size of the proto, then write the proto. 75 // Write size of the proto, then write the proto.
76 if (!writer.WriteU16(static_cast<uint16>(proto_size))) 76 if (!writer.WriteU16(static_cast<uint16_t>(proto_size)))
77 return false; 77 return false;
78 if (!frame_event.SerializeToArray(writer.ptr(), writer.remaining())) 78 if (!frame_event.SerializeToArray(writer.ptr(), writer.remaining()))
79 return false; 79 return false;
80 if (!writer.Skip(proto_size)) 80 if (!writer.Skip(proto_size))
81 return false; 81 return false;
82 } 82 }
83 83
84 // Write packet events. 84 // Write packet events.
85 prev_rtp_timestamp = 0; 85 prev_rtp_timestamp = 0;
86 for (media::cast::PacketEventList::const_iterator it = packet_events.begin(); 86 for (media::cast::PacketEventList::const_iterator it = packet_events.begin();
87 it != packet_events.end(); 87 it != packet_events.end();
88 ++it) { 88 ++it) {
89 media::cast::proto::AggregatedPacketEvent packet_event(**it); 89 media::cast::proto::AggregatedPacketEvent packet_event(**it);
90 RtpTimestamp old_relative_rtp_timestamp = 90 RtpTimestamp old_relative_rtp_timestamp =
91 packet_event.relative_rtp_timestamp(); 91 packet_event.relative_rtp_timestamp();
92 packet_event.set_relative_rtp_timestamp( 92 packet_event.set_relative_rtp_timestamp(
93 old_relative_rtp_timestamp - prev_rtp_timestamp); 93 old_relative_rtp_timestamp - prev_rtp_timestamp);
94 prev_rtp_timestamp = old_relative_rtp_timestamp; 94 prev_rtp_timestamp = old_relative_rtp_timestamp;
95 95
96 proto_size = packet_event.ByteSize(); 96 proto_size = packet_event.ByteSize();
97 DCHECK(proto_size <= kMaxSerializedProtoBytes); 97 DCHECK(proto_size <= kMaxSerializedProtoBytes);
98 98
99 // Write size of the proto, then write the proto. 99 // Write size of the proto, then write the proto.
100 if (!writer.WriteU16(static_cast<uint16>(proto_size))) 100 if (!writer.WriteU16(static_cast<uint16_t>(proto_size)))
101 return false; 101 return false;
102 if (!packet_event.SerializeToArray(writer.ptr(), writer.remaining())) 102 if (!packet_event.SerializeToArray(writer.ptr(), writer.remaining()))
103 return false; 103 return false;
104 if (!writer.Skip(proto_size)) 104 if (!writer.Skip(proto_size))
105 return false; 105 return false;
106 } 106 }
107 107
108 *output_bytes = max_output_bytes - writer.remaining(); 108 *output_bytes = max_output_bytes - writer.remaining();
109 return true; 109 return true;
110 } 110 }
111 111
112 bool Compress(char* uncompressed_buffer, 112 bool Compress(char* uncompressed_buffer,
113 int uncompressed_bytes, 113 int uncompressed_bytes,
114 int max_output_bytes, 114 int max_output_bytes,
115 char* output, 115 char* output,
116 int* output_bytes) { 116 int* output_bytes) {
117 z_stream stream = {0}; 117 z_stream stream = {0};
118 int result = deflateInit2(&stream, 118 int result = deflateInit2(&stream,
119 Z_DEFAULT_COMPRESSION, 119 Z_DEFAULT_COMPRESSION,
120 Z_DEFLATED, 120 Z_DEFLATED,
121 // 16 is added to produce a gzip header + trailer. 121 // 16 is added to produce a gzip header + trailer.
122 MAX_WBITS + 16, 122 MAX_WBITS + 16,
123 8, // memLevel = 8 is default. 123 8, // memLevel = 8 is default.
124 Z_DEFAULT_STRATEGY); 124 Z_DEFAULT_STRATEGY);
125 DCHECK_EQ(Z_OK, result); 125 DCHECK_EQ(Z_OK, result);
126 126
127 stream.next_in = reinterpret_cast<uint8*>(uncompressed_buffer); 127 stream.next_in = reinterpret_cast<uint8_t*>(uncompressed_buffer);
128 stream.avail_in = uncompressed_bytes; 128 stream.avail_in = uncompressed_bytes;
129 stream.next_out = reinterpret_cast<uint8*>(output); 129 stream.next_out = reinterpret_cast<uint8_t*>(output);
130 stream.avail_out = max_output_bytes; 130 stream.avail_out = max_output_bytes;
131 131
132 // Do a one-shot compression. This will return Z_STREAM_END only if |output| 132 // Do a one-shot compression. This will return Z_STREAM_END only if |output|
133 // is large enough to hold all compressed data. 133 // is large enough to hold all compressed data.
134 result = deflate(&stream, Z_FINISH); 134 result = deflate(&stream, Z_FINISH);
135 bool success = (result == Z_STREAM_END); 135 bool success = (result == Z_STREAM_END);
136 136
137 if (!success) 137 if (!success)
138 DVLOG(2) << "deflate() failed. Result: " << result; 138 DVLOG(2) << "deflate() failed. Result: " << result;
139 139
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 frame_events, 181 frame_events,
182 packet_events, 182 packet_events,
183 max_output_bytes, 183 max_output_bytes,
184 output, 184 output,
185 output_bytes); 185 output_bytes);
186 } 186 }
187 } 187 }
188 188
189 } // namespace cast 189 } // namespace cast
190 } // namespace media 190 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698