| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_impl.h" | 5 #include "media/base/video_frame_impl.h" |
| 6 | 6 |
| 7 namespace media { | 7 namespace media { |
| 8 | 8 |
| 9 // static | 9 // static |
| 10 void VideoFrameImpl::CreateFrame(VideoSurface::Format format, | 10 void VideoFrameImpl::CreateFrame(VideoSurface::Format format, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 *frame_out = alloc_worked ? frame : NULL; | 47 *frame_out = alloc_worked ? frame : NULL; |
| 48 } | 48 } |
| 49 | 49 |
| 50 // static | 50 // static |
| 51 void VideoFrameImpl::CreateEmptyFrame(scoped_refptr<VideoFrame>* frame_out) { | 51 void VideoFrameImpl::CreateEmptyFrame(scoped_refptr<VideoFrame>* frame_out) { |
| 52 *frame_out = new VideoFrameImpl(VideoSurface::EMPTY, 0, 0); | 52 *frame_out = new VideoFrameImpl(VideoSurface::EMPTY, 0, 0); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // static |
| 56 void VideoFrameImpl::CreateBlackFrame(int width, int height, |
| 57 scoped_refptr<VideoFrame>* frame_out) { |
| 58 DCHECK_GT(width, 0); |
| 59 DCHECK_GT(height, 0); |
| 60 |
| 61 // Create our frame. |
| 62 scoped_refptr<VideoFrame> frame; |
| 63 const base::TimeDelta kZero; |
| 64 VideoFrameImpl::CreateFrame(VideoSurface::YV12, width, height, kZero, kZero, |
| 65 &frame); |
| 66 DCHECK(frame); |
| 67 |
| 68 // Now set the data to YUV(0,128,128). |
| 69 const uint8 kBlackY = 0x00; |
| 70 const uint8 kBlackUV = 0x80; |
| 71 VideoSurface surface; |
| 72 frame->Lock(&surface); |
| 73 DCHECK_EQ(VideoSurface::YV12, surface.format) << "Expected YV12 surface"; |
| 74 |
| 75 // Fill the Y plane. |
| 76 for (size_t i = 0; i < surface.height; ++i) { |
| 77 memset(surface.data[VideoSurface::kYPlane], kBlackY, surface.width); |
| 78 surface.data[VideoSurface::kYPlane] |
| 79 += surface.strides[VideoSurface::kYPlane]; |
| 80 } |
| 81 |
| 82 // Fill the U and V planes. |
| 83 for (size_t i = 0; i < (surface.height / 2); ++i) { |
| 84 memset(surface.data[VideoSurface::kUPlane], kBlackUV, surface.width / 2); |
| 85 memset(surface.data[VideoSurface::kVPlane], kBlackUV, surface.width / 2); |
| 86 surface.data[VideoSurface::kUPlane] += |
| 87 surface.strides[VideoSurface::kUPlane]; |
| 88 surface.data[VideoSurface::kVPlane] += |
| 89 surface.strides[VideoSurface::kVPlane]; |
| 90 } |
| 91 frame->Unlock(); |
| 92 |
| 93 // Success! |
| 94 *frame_out = frame; |
| 95 } |
| 96 |
| 55 static inline size_t RoundUp(size_t value, size_t alignment) { | 97 static inline size_t RoundUp(size_t value, size_t alignment) { |
| 56 // Check that |alignment| is a power of 2. | 98 // Check that |alignment| is a power of 2. |
| 57 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); | 99 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); |
| 58 return ((value + (alignment - 1)) & ~(alignment-1)); | 100 return ((value + (alignment - 1)) & ~(alignment-1)); |
| 59 } | 101 } |
| 60 | 102 |
| 61 bool VideoFrameImpl::AllocateRGB(size_t bytes_per_pixel) { | 103 bool VideoFrameImpl::AllocateRGB(size_t bytes_per_pixel) { |
| 62 // Round up to align at a 64-bit (8 byte) boundary for each row. This | 104 // Round up to align at a 64-bit (8 byte) boundary for each row. This |
| 63 // is sufficient for MMX reads (movq). | 105 // is sufficient for MMX reads (movq). |
| 64 size_t bytes_per_row = RoundUp(surface_.width * bytes_per_pixel, 8); | 106 size_t bytes_per_row = RoundUp(surface_.width * bytes_per_pixel, 8); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 DCHECK(locked_); | 184 DCHECK(locked_); |
| 143 DCHECK_NE(surface_.format, VideoSurface::EMPTY); | 185 DCHECK_NE(surface_.format, VideoSurface::EMPTY); |
| 144 locked_ = false; | 186 locked_ = false; |
| 145 } | 187 } |
| 146 | 188 |
| 147 bool VideoFrameImpl::IsEndOfStream() const { | 189 bool VideoFrameImpl::IsEndOfStream() const { |
| 148 return surface_.format == VideoSurface::EMPTY; | 190 return surface_.format == VideoSurface::EMPTY; |
| 149 } | 191 } |
| 150 | 192 |
| 151 } // namespace media | 193 } // namespace media |
| OLD | NEW |