| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/video_frame.h" | 5 #include "media/base/video_frame.h" |
| 6 | 6 |
| 7 namespace media { | 7 namespace media { |
| 8 | 8 |
| 9 // static | 9 // static |
| 10 void VideoFrame::CreateFrame(VideoFrame::Format format, | 10 void VideoFrame::CreateFrame(VideoFrame::Format format, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 break; | 40 break; |
| 41 default: | 41 default: |
| 42 NOTREACHED(); | 42 NOTREACHED(); |
| 43 alloc_worked = false; | 43 alloc_worked = false; |
| 44 break; | 44 break; |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 *frame_out = alloc_worked ? frame : NULL; | 47 *frame_out = alloc_worked ? frame : NULL; |
| 48 } | 48 } |
| 49 | 49 |
| 50 void VideoFrame::CreateFrameExternal(VideoFrame::Format format, |
| 51 size_t width, |
| 52 size_t height, |
| 53 uint8* const data[kMaxPlanes], |
| 54 const int32 strides[kMaxPlanes], |
| 55 base::TimeDelta timestamp, |
| 56 base::TimeDelta duration, |
| 57 scoped_refptr<VideoFrame>* frame_out) { |
| 58 DCHECK(frame_out); |
| 59 scoped_refptr<VideoFrame> frame = |
| 60 new VideoFrame(VideoFrame::TYPE_SYSTEM_MEMORY, format, width, height); |
| 61 if (frame) { |
| 62 frame->SetTimestamp(timestamp); |
| 63 frame->SetDuration(duration); |
| 64 frame->external_memory_ = true; |
| 65 for (size_t i = 0; i < kMaxPlanes; ++i) { |
| 66 frame->data_[i] = data[i]; |
| 67 frame->strides_[i] = strides[i]; |
| 68 } |
| 69 } |
| 70 *frame_out = frame; |
| 71 } |
| 72 |
| 50 // static | 73 // static |
| 51 void VideoFrame::CreateEmptyFrame(scoped_refptr<VideoFrame>* frame_out) { | 74 void VideoFrame::CreateEmptyFrame(scoped_refptr<VideoFrame>* frame_out) { |
| 52 *frame_out = new VideoFrame(VideoFrame::TYPE_SYSTEM_MEMORY, | 75 *frame_out = new VideoFrame(VideoFrame::TYPE_SYSTEM_MEMORY, |
| 53 VideoFrame::EMPTY, 0, 0); | 76 VideoFrame::EMPTY, 0, 0); |
| 54 } | 77 } |
| 55 | 78 |
| 56 // static | 79 // static |
| 57 void VideoFrame::CreateBlackFrame(int width, int height, | 80 void VideoFrame::CreateBlackFrame(int width, int height, |
| 58 scoped_refptr<VideoFrame>* frame_out) { | 81 scoped_refptr<VideoFrame>* frame_out) { |
| 59 DCHECK_GT(width, 0); | 82 DCHECK_GT(width, 0); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 VideoFrame::Format format, | 195 VideoFrame::Format format, |
| 173 size_t width, | 196 size_t width, |
| 174 size_t height) { | 197 size_t height) { |
| 175 type_ = type; | 198 type_ = type; |
| 176 format_ = format; | 199 format_ = format; |
| 177 width_ = width; | 200 width_ = width; |
| 178 height_ = height; | 201 height_ = height; |
| 179 planes_ = 0; | 202 planes_ = 0; |
| 180 memset(&strides_, 0, sizeof(strides_)); | 203 memset(&strides_, 0, sizeof(strides_)); |
| 181 memset(&data_, 0, sizeof(data_)); | 204 memset(&data_, 0, sizeof(data_)); |
| 205 external_memory_ = false; |
| 182 private_buffer_ = NULL; | 206 private_buffer_ = NULL; |
| 183 } | 207 } |
| 184 | 208 |
| 185 VideoFrame::~VideoFrame() { | 209 VideoFrame::~VideoFrame() { |
| 186 // In multi-plane allocations, only a single block of memory is allocated | 210 // In multi-plane allocations, only a single block of memory is allocated |
| 187 // on the heap, and other |data| pointers point inside the same, single block | 211 // on the heap, and other |data| pointers point inside the same, single block |
| 188 // so just delete index 0. | 212 // so just delete index 0. |
| 189 delete[] data_[0]; | 213 if (!external_memory_) |
| 214 delete[] data_[0]; |
| 190 } | 215 } |
| 191 | 216 |
| 192 bool VideoFrame::IsEndOfStream() const { | 217 bool VideoFrame::IsEndOfStream() const { |
| 193 return format_ == VideoFrame::EMPTY; | 218 return format_ == VideoFrame::EMPTY; |
| 194 } | 219 } |
| 195 | 220 |
| 196 } // namespace media | 221 } // namespace media |
| OLD | NEW |