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

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: Address comments from patch set #3 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..3a6eef959059a655717418b3fe93b61d2c65d181
--- /dev/null
+++ b/media/mpeg2/mpeg2ts_crc.cc
@@ -0,0 +1,43 @@
+// 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"
+
+#include "base/logging.h"
damienv1 2013/09/10 15:28:25 Not needed anymore, to be removed.
damienv1 2013/09/10 21:03:48 Done.
+
+namespace media {
+namespace mpeg2ts {
+
+Mpeg2TsCrc::Mpeg2TsCrc()
+ : crc_(0xffffffffu) {
+}
+
+void Mpeg2TsCrc::Update(uint8 data) {
+ const uint32_t kCrcPoly = 0x4c11db7;
+
+ // Align the bits to the MSB.
+ int nbits = 8;
+ uint32 data_msb_aligned = data;
+ data_msb_aligned <<= (32 - nbits);
+
+ while (nbits > 0) {
+ if ((data_msb_aligned ^ crc_) & 0x80000000) {
+ crc_ <<= 1;
+ crc_ ^= kCrcPoly;
+ } else {
+ crc_ <<= 1;
+ }
+
+ data_msb_aligned <<= 1;
+ nbits--;
+ }
+}
+
+bool Mpeg2TsCrc::IsValid() {
+ return (crc_ == 0);
+}
+
+} // namespace mpeg2ts
+} // namespace media
+

Powered by Google App Engine
This is Rietveld 408576698