Chromium Code Reviews| Index: media/mpeg2/mpeg2ts_crc.cc |
| diff --git a/media/mpeg2/mpeg2ts_crc.cc b/media/mpeg2/mpeg2ts_crc.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bb0c10e96f0e001241ce391dcd4e81c94b39105a |
| --- /dev/null |
| +++ b/media/mpeg2/mpeg2ts_crc.cc |
| @@ -0,0 +1,39 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/mpeg2/mpeg2ts_crc.h" |
| + |
| +namespace media { |
| +namespace mpeg2ts { |
| + |
| +Mpeg2TsCrc::Mpeg2TsCrc() |
| + : crc_(0xffffffffu) { |
| +} |
| + |
| +void Mpeg2TsCrc::Update(uint32 data, int nbits) { |
|
damienv1
2013/09/05 01:58:29
DCHECK_LE(nbits, 32);
damienv1
2013/09/09 23:29:46
Done.
|
| + const uint32_t kCrcPoly = 0x4c11db7; |
| + |
| + // Align the bits to the MSB. |
| + data = data << (32 - nbits); |
| + |
| + while (nbits > 0) { |
| + if ((data ^ crc_) & 0x80000000) { |
| + crc_ <<= 1; |
| + crc_ ^= kCrcPoly; |
| + } else { |
| + crc_ <<= 1; |
| + } |
| + |
| + data <<= 1; |
| + nbits--; |
| + } |
| +} |
| + |
| +bool Mpeg2TsCrc::IsValid() { |
| + return (crc_ == 0); |
| +} |
| + |
| +} // namespace mpeg2ts |
| +} // namespace media |
| + |