1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved. 2 // 3 // Use of this source code is governed by a BSD-style license 4 // that can be found in the LICENSE file in the root of the source 5 // tree. An additional intellectual property rights grant can be found 6 // in the file PATENTS. All contributing project authors may 7 // be found in the AUTHORS file in the root of the source tree. 8 #include "common/video_frame.h" 9 10 #include <cstdio> 11 12 namespace libwebm { 13 Init(std::size_t new_length)14bool VideoFrame::Buffer::Init(std::size_t new_length) { 15 capacity = 0; 16 length = 0; 17 data.reset(new std::uint8_t[new_length]); 18 19 if (data.get() == nullptr) { 20 fprintf(stderr, "VideoFrame: Out of memory."); 21 return false; 22 } 23 24 capacity = new_length; 25 length = 0; 26 return true; 27 } 28 Init(std::size_t length)29bool VideoFrame::Init(std::size_t length) { return buffer_.Init(length); } 30 Init(std::size_t length,std::int64_t nano_pts,Codec codec)31bool VideoFrame::Init(std::size_t length, std::int64_t nano_pts, Codec codec) { 32 nanosecond_pts_ = nano_pts; 33 codec_ = codec; 34 return Init(length); 35 } 36 SetBufferLength(std::size_t length)37bool VideoFrame::SetBufferLength(std::size_t length) { 38 if (length > buffer_.capacity || buffer_.data.get() == nullptr) 39 return false; 40 41 buffer_.length = length; 42 return true; 43 } 44 45 } // namespace libwebm 46