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

Side by Side Diff: media/base/bit_reader_h264.cc

Issue 112343011: Split the bit reader functionalities from the byte stream provider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit test for the removal of the emulation prevention byte. Created 6 years, 11 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/base/bit_reader_h264.h"
6
7 namespace media {
8
9 namespace {
10
11 class H264ByteStreamProvider : public BitReaderCore::ByteStreamProvider {
12 public:
13 H264ByteStreamProvider(const uint8* data, off_t size);
14 virtual ~H264ByteStreamProvider();
15
16 // BitReaderCore::ByteStreamProvider implementation.
17 virtual int GetBytes(int min_n,
18 int max_n,
19 const uint8** out) OVERRIDE;
20 virtual int GetBytesLeft() const OVERRIDE;
21
22 private:
23 // Pointer to the next unread byte in the stream.
24 // Does not include bits held in the bit registers.
acolwell GONE FROM CHROMIUM 2013/12/28 01:54:42 nit: Remove this comment since this code shouldn't
damienv1 2013/12/28 02:26:17 Will do.
25 const uint8* data_;
26
27 // Bytes left in the stream.
28 // Does not include bits held in the bit registers.
acolwell GONE FROM CHROMIUM 2013/12/28 01:54:42 ditto?
damienv1 2013/12/28 02:26:17 Will do.
29 int bytes_left_;
30
31 // Array used to return some bytes when emulation prevention bytes
damienv1 2013/12/28 01:32:25 when *some* ...
damienv1 2013/12/28 02:26:17 Done.
32 // are detected.
33 uint8 data_window_[8];
34
35 // Last two bytes read from the stream.
36 int prev_two_bytes_;
37 };
38
39 H264ByteStreamProvider::H264ByteStreamProvider(const uint8* data, off_t size)
40 : data_(data),
41 bytes_left_(size),
42 prev_two_bytes_(0xffff) {
43 DCHECK(data_ != NULL && bytes_left_ > 0);
44 }
45
46 H264ByteStreamProvider::~H264ByteStreamProvider() {
47 }
48
49 int H264ByteStreamProvider::GetBytes(
50 int min_nbytes, int max_nbytes, const uint8** out) {
acolwell GONE FROM CHROMIUM 2013/12/28 01:54:42 nit: This implementation and the one used by BitRe
damienv1 2013/12/28 02:26:17 Should be able to remove it. Didn't do it right aw
51 DCHECK_LE(max_nbytes, static_cast<int>(sizeof(data_window_)));
52
53 const uint8* start = data_;
54 bool epb = false;
acolwell GONE FROM CHROMIUM 2013/12/28 01:54:42 nit:s/epb/copy_to_data_window/ or something simila
damienv1 2013/12/28 04:02:23 Done.
55
56 int nbytes = 0;
57 *out = data_;
58
59 while (nbytes < max_nbytes && bytes_left_ > 0) {
60 // Emulation prevention three-byte detection.
61 // If a sequence of 0x000003 is found, skip (ignore) the last byte (0x03)
62 // and starts copying data to |data_window_| which is used as the output.
63 if (*data_ == 0x3 && (prev_two_bytes_ & 0xffff) == 0) {
64 if (!epb && nbytes > 0)
65 memcpy(data_window_, start, nbytes);
66 epb = true;
67 *out = data_window_;
68 // Need another full three bytes before we can detect the sequence again.
69 prev_two_bytes_ = 0xffff;
70 } else {
71 if (epb)
72 data_window_[nbytes] = *data_;
73 prev_two_bytes_ = (prev_two_bytes_ << 8) | static_cast<int>(*data_);
acolwell GONE FROM CHROMIUM 2013/12/28 01:54:42 If you make prev_two_bytes_ unsigned does it remov
damienv1 2013/12/28 02:26:17 Will check.
74 ++nbytes;
75 }
76
77 ++data_;
78 --bytes_left_;
79 }
80
81 return nbytes;
82 }
83
84 int H264ByteStreamProvider::GetBytesLeft() const {
85 return bytes_left_;
acolwell GONE FROM CHROMIUM 2013/12/28 01:54:42 This doesn't seem right. Shouldn't this be returni
damienv1 2013/12/28 02:26:17 I implemented this one to be inline with the curre
86 }
87
88 } // namespace
89
90 BitReaderH264::BitReaderH264(const uint8* data, off_t size)
91 : byte_stream_provider_(new H264ByteStreamProvider(data, size)),
92 bit_reader_core_(byte_stream_provider_.get()) {
93 }
94
95 BitReaderH264::~BitReaderH264() {}
96
97 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698