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

Unified Diff: media/mpeg2/mpeg2ts_crc.cc

Issue 23566013: Mpeg2 TS stream parser for media source. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add basic unit tests + Cleanup Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
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
+

Powered by Google App Engine
This is Rietveld 408576698