15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "media/base/bit_reader.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace media {
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)BitReader::BitReader(const uint8* data, int size)
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : initial_size_(size),
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      data_(data),
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      bytes_left_(size),
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      bit_reader_core_(this) {
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK(data != NULL);
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK_GE(size, 0);
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BitReader::~BitReader() {}
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int BitReader::GetBytes(int max_nbytes, const uint8** out) {
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK_GE(max_nbytes, 0);
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK(out);
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int nbytes = max_nbytes;
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (nbytes > bytes_left_)
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    nbytes = bytes_left_;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  *out = data_;
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  data_ += nbytes;
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bytes_left_ -= nbytes;
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return nbytes;
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace media
35