OLD | NEW |
---|---|
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 "media/formats/webm/cluster_builder.h" | 5 #include "media/formats/webm/cluster_builder.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "media/base/data_buffer.h" | 8 #include "media/base/data_buffer.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
(...skipping 14 matching lines...) Expand all Loading... | |
25 static const uint8 kBlockGroupHeader[] = { | 25 static const uint8 kBlockGroupHeader[] = { |
26 0xA0, // BlockGroup ID | 26 0xA0, // BlockGroup ID |
27 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // BlockGroup(size = 0) | 27 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // BlockGroup(size = 0) |
28 0x9B, // BlockDuration ID | 28 0x9B, // BlockDuration ID |
29 0x88, // BlockDuration(size = 8) | 29 0x88, // BlockDuration(size = 8) |
30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // duration | 30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // duration |
31 0xA1, // Block ID | 31 0xA1, // Block ID |
32 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Block(size = 0) | 32 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Block(size = 0) |
33 }; | 33 }; |
34 | 34 |
35 static const uint8 kBlockGroupHeaderWithoutBlockDuration[] = { | |
36 0xA0, // BlockGroup ID | |
37 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // BlockGroup(size = 0) | |
38 0xA1, // Block ID | |
39 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Block(size = 0) | |
40 }; | |
41 | |
35 enum { | 42 enum { |
36 kClusterSizeOffset = 4, | 43 kClusterSizeOffset = 4, |
37 kClusterTimecodeOffset = 14, | 44 kClusterTimecodeOffset = 14, |
38 | 45 |
39 kSimpleBlockSizeOffset = 1, | 46 kSimpleBlockSizeOffset = 1, |
40 | 47 |
41 kBlockGroupSizeOffset = 1, | 48 kBlockGroupSizeOffset = 1, |
49 kBlockGroupWithoutBlockDurationBlockSizeOffset = 10, | |
42 kBlockGroupDurationOffset = 11, | 50 kBlockGroupDurationOffset = 11, |
43 kBlockGroupBlockSizeOffset = 20, | 51 kBlockGroupBlockSizeOffset = 20, |
44 | 52 |
45 kInitialBufferSize = 32768, | 53 kInitialBufferSize = 32768, |
46 }; | 54 }; |
47 | 55 |
48 Cluster::Cluster(scoped_ptr<uint8[]> data, int size) | 56 Cluster::Cluster(scoped_ptr<uint8[]> data, int size) |
49 : data_(data.Pass()), size_(size) {} | 57 : data_(data.Pass()), size_(size) {} |
50 Cluster::~Cluster() {} | 58 Cluster::~Cluster() {} |
51 | 59 |
(...skipping 26 matching lines...) Expand all Loading... | |
78 UpdateUInt64(block_offset + kSimpleBlockSizeOffset, block_size); | 86 UpdateUInt64(block_offset + kSimpleBlockSizeOffset, block_size); |
79 buf += sizeof(kSimpleBlockHeader); | 87 buf += sizeof(kSimpleBlockHeader); |
80 | 88 |
81 WriteBlock(buf, track_num, timecode, flags, data, size); | 89 WriteBlock(buf, track_num, timecode, flags, data, size); |
82 | 90 |
83 bytes_used_ += bytes_needed; | 91 bytes_used_ += bytes_needed; |
84 } | 92 } |
85 | 93 |
86 void ClusterBuilder::AddBlockGroup(int track_num, int64 timecode, int duration, | 94 void ClusterBuilder::AddBlockGroup(int track_num, int64 timecode, int duration, |
87 int flags, const uint8* data, int size) { | 95 int flags, const uint8* data, int size) { |
96 AddBlockGroupInternal(track_num, timecode, true, duration, flags, data, size); | |
97 } | |
98 | |
99 void ClusterBuilder::AddBlockGroupWithoutBlockDuration(int track_num, | |
100 int64 timecode, | |
101 int flags, | |
102 const uint8* data, | |
103 int size) { | |
104 AddBlockGroupInternal(track_num, timecode, false, 0, flags, data, size); | |
105 } | |
106 | |
107 | |
108 void ClusterBuilder::AddBlockGroupInternal(int track_num, int64 timecode, | |
109 bool include_block_duration, | |
110 int duration, int flags, | |
111 const uint8* data, int size) { | |
88 int block_size = size + 4; | 112 int block_size = size + 4; |
89 int bytes_needed = sizeof(kBlockGroupHeader) + block_size; | 113 int bytes_needed = block_size; |
114 if (include_block_duration) { | |
115 bytes_needed += sizeof(kBlockGroupHeader); | |
116 } else { | |
117 bytes_needed += sizeof(kBlockGroupHeaderWithoutBlockDuration); | |
118 } | |
119 | |
90 int block_group_size = bytes_needed - 9; | 120 int block_group_size = bytes_needed - 9; |
91 | 121 |
92 if (bytes_needed > (buffer_size_ - bytes_used_)) | 122 if (bytes_needed > (buffer_size_ - bytes_used_)) |
93 ExtendBuffer(bytes_needed); | 123 ExtendBuffer(bytes_needed); |
94 | 124 |
95 uint8* buf = buffer_.get() + bytes_used_; | 125 uint8* buf = buffer_.get() + bytes_used_; |
96 int block_group_offset = bytes_used_; | 126 int block_group_offset = bytes_used_; |
97 memcpy(buf, kBlockGroupHeader, sizeof(kBlockGroupHeader)); | 127 if (include_block_duration) { |
128 memcpy(buf, kBlockGroupHeader, sizeof(kBlockGroupHeader)); | |
129 UpdateUInt64(block_group_offset + kBlockGroupDurationOffset, duration); | |
130 UpdateUInt64(block_group_offset + kBlockGroupBlockSizeOffset, block_size); | |
131 buf += sizeof(kBlockGroupHeader); | |
132 } else { | |
133 memcpy(buf, kBlockGroupHeaderWithoutBlockDuration, | |
134 sizeof(kBlockGroupHeaderWithoutBlockDuration)); | |
135 UpdateUInt64(block_group_offset + | |
136 kBlockGroupWithoutBlockDurationBlockSizeOffset, | |
acolwell GONE FROM CHROMIUM
2014/04/15 00:32:24
nit: This indent looks wrong. newline after ( inst
wolenetz
2014/04/15 01:49:12
Done.
| |
137 block_size); | |
138 buf += sizeof(kBlockGroupHeaderWithoutBlockDuration); | |
139 } | |
140 | |
98 UpdateUInt64(block_group_offset + kBlockGroupSizeOffset, block_group_size); | 141 UpdateUInt64(block_group_offset + kBlockGroupSizeOffset, block_group_size); |
99 UpdateUInt64(block_group_offset + kBlockGroupDurationOffset, duration); | |
100 UpdateUInt64(block_group_offset + kBlockGroupBlockSizeOffset, block_size); | |
101 buf += sizeof(kBlockGroupHeader); | |
102 | 142 |
103 // Make sure the 4 most-significant bits are 0. | 143 // Make sure the 4 most-significant bits are 0. |
104 // http://www.matroska.org/technical/specs/index.html#block_structure | 144 // http://www.matroska.org/technical/specs/index.html#block_structure |
105 flags &= 0x0f; | 145 flags &= 0x0f; |
106 | 146 |
107 WriteBlock(buf, track_num, timecode, flags, data, size); | 147 WriteBlock(buf, track_num, timecode, flags, data, size); |
108 | 148 |
109 bytes_used_ += bytes_needed; | 149 bytes_used_ += bytes_needed; |
110 } | 150 } |
111 | 151 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 uint8* buf = buffer_.get() + offset; | 206 uint8* buf = buffer_.get() + offset; |
167 | 207 |
168 // Fill the last 7 bytes of size field in big-endian order. | 208 // Fill the last 7 bytes of size field in big-endian order. |
169 for (int i = 7; i > 0; i--) { | 209 for (int i = 7; i > 0; i--) { |
170 buf[i] = value & 0xff; | 210 buf[i] = value & 0xff; |
171 value >>= 8; | 211 value >>= 8; |
172 } | 212 } |
173 } | 213 } |
174 | 214 |
175 } // namespace media | 215 } // namespace media |
OLD | NEW |