Home | History | Annotate | Download | only in base
      1 // Copyright (c) 2012 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/data_buffer.h"
      6 
      7 #include "base/logging.h"
      8 
      9 namespace media {
     10 
     11 DataBuffer::DataBuffer(int buffer_size)
     12     : buffer_size_(buffer_size),
     13       data_size_(0) {
     14   CHECK_GE(buffer_size, 0);
     15   data_.reset(new uint8[buffer_size_]);
     16 }
     17 
     18 DataBuffer::DataBuffer(scoped_ptr<uint8[]> buffer, int buffer_size)
     19     : data_(buffer.Pass()),
     20       buffer_size_(buffer_size),
     21       data_size_(buffer_size) {
     22   CHECK(data_.get());
     23   CHECK_GE(buffer_size, 0);
     24 }
     25 
     26 DataBuffer::DataBuffer(const uint8* data, int data_size)
     27     : buffer_size_(data_size),
     28       data_size_(data_size) {
     29   if (!data) {
     30     CHECK_EQ(data_size, 0);
     31     return;
     32   }
     33 
     34   CHECK_GE(data_size, 0);
     35   data_.reset(new uint8[buffer_size_]);
     36   memcpy(data_.get(), data, data_size_);
     37 }
     38 
     39 DataBuffer::~DataBuffer() {}
     40 
     41 // static
     42 scoped_refptr<DataBuffer> DataBuffer::CopyFrom(const uint8* data, int size) {
     43   // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
     44   CHECK(data);
     45   return make_scoped_refptr(new DataBuffer(data, size));
     46 }
     47 
     48 // static
     49 scoped_refptr<DataBuffer> DataBuffer::CreateEOSBuffer() {
     50   return make_scoped_refptr(new DataBuffer(NULL, 0));
     51 }
     52 }  // namespace media
     53