| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_piece.h" | 8 #include "base/string_piece.h" |
| 9 #include "media/base/limits.h" | 9 #include "media/base/limits.h" |
| 10 #include "media/base/video_util.h" | 10 #include "media/base/video_util.h" |
| 11 #if !defined(OS_ANDROID) | 11 #if !defined(OS_ANDROID) |
| 12 #include "media/ffmpeg/ffmpeg_common.h" | 12 #include "media/ffmpeg/ffmpeg_common.h" |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 | 18 |
| 19 // static | 19 // static |
| 20 scoped_refptr<VideoFrame> VideoFrame::CreateFrame( | 20 scoped_refptr<VideoFrame> VideoFrame::CreateFrame( |
| 21 VideoFrame::Format format, | 21 VideoFrame::Format format, |
| 22 size_t width, | 22 size_t width, |
| 23 size_t height, | 23 size_t height, |
| 24 base::TimeDelta timestamp, | 24 base::TimeDelta timestamp) { |
| 25 base::TimeDelta duration) { | |
| 26 DCHECK(IsValidConfig(format, width, height)); | 25 DCHECK(IsValidConfig(format, width, height)); |
| 27 scoped_refptr<VideoFrame> frame(new VideoFrame( | 26 scoped_refptr<VideoFrame> frame(new VideoFrame( |
| 28 format, width, height, timestamp, duration)); | 27 format, width, height, timestamp)); |
| 29 switch (format) { | 28 switch (format) { |
| 30 case VideoFrame::RGB32: | 29 case VideoFrame::RGB32: |
| 31 frame->AllocateRGB(4u); | 30 frame->AllocateRGB(4u); |
| 32 break; | 31 break; |
| 33 case VideoFrame::YV12: | 32 case VideoFrame::YV12: |
| 34 case VideoFrame::YV16: | 33 case VideoFrame::YV16: |
| 35 frame->AllocateYUV(); | 34 frame->AllocateYUV(); |
| 36 break; | 35 break; |
| 37 default: | 36 default: |
| 38 LOG(FATAL) << "Unsupported frame format: " << format; | 37 LOG(FATAL) << "Unsupported frame format: " << format; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 52 width * height <= limits::kMaxCanvas); | 51 width * height <= limits::kMaxCanvas); |
| 53 } | 52 } |
| 54 | 53 |
| 55 // static | 54 // static |
| 56 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( | 55 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( |
| 57 uint32 texture_id, | 56 uint32 texture_id, |
| 58 uint32 texture_target, | 57 uint32 texture_target, |
| 59 size_t width, | 58 size_t width, |
| 60 size_t height, | 59 size_t height, |
| 61 base::TimeDelta timestamp, | 60 base::TimeDelta timestamp, |
| 62 base::TimeDelta duration, | |
| 63 const base::Closure& no_longer_needed) { | 61 const base::Closure& no_longer_needed) { |
| 64 scoped_refptr<VideoFrame> frame( | 62 scoped_refptr<VideoFrame> frame( |
| 65 new VideoFrame(NATIVE_TEXTURE, width, height, timestamp, duration)); | 63 new VideoFrame(NATIVE_TEXTURE, width, height, timestamp)); |
| 66 frame->texture_id_ = texture_id; | 64 frame->texture_id_ = texture_id; |
| 67 frame->texture_target_ = texture_target; | 65 frame->texture_target_ = texture_target; |
| 68 frame->texture_no_longer_needed_ = no_longer_needed; | 66 frame->texture_no_longer_needed_ = no_longer_needed; |
| 69 return frame; | 67 return frame; |
| 70 } | 68 } |
| 71 | 69 |
| 72 // static | 70 // static |
| 73 scoped_refptr<VideoFrame> VideoFrame::CreateEmptyFrame() { | 71 scoped_refptr<VideoFrame> VideoFrame::CreateEmptyFrame() { |
| 74 return new VideoFrame( | 72 return new VideoFrame( |
| 75 VideoFrame::EMPTY, 0, 0, base::TimeDelta(), base::TimeDelta()); | 73 VideoFrame::EMPTY, 0, 0, base::TimeDelta()); |
| 76 } | 74 } |
| 77 | 75 |
| 78 // static | 76 // static |
| 79 scoped_refptr<VideoFrame> VideoFrame::CreateBlackFrame(int width, int height) { | 77 scoped_refptr<VideoFrame> VideoFrame::CreateBlackFrame(int width, int height) { |
| 80 DCHECK_GT(width, 0); | 78 DCHECK_GT(width, 0); |
| 81 DCHECK_GT(height, 0); | 79 DCHECK_GT(height, 0); |
| 82 | 80 |
| 83 // Create our frame. | 81 // Create our frame. |
| 84 const base::TimeDelta kZero; | 82 const base::TimeDelta kZero; |
| 85 scoped_refptr<VideoFrame> frame = | 83 scoped_refptr<VideoFrame> frame = |
| 86 VideoFrame::CreateFrame(VideoFrame::YV12, width, height, kZero, kZero); | 84 VideoFrame::CreateFrame(VideoFrame::YV12, width, height, kZero); |
| 87 | 85 |
| 88 // Now set the data to YUV(0,128,128). | 86 // Now set the data to YUV(0,128,128). |
| 89 const uint8 kBlackY = 0x00; | 87 const uint8 kBlackY = 0x00; |
| 90 const uint8 kBlackUV = 0x80; | 88 const uint8 kBlackUV = 0x80; |
| 91 FillYUV(frame, kBlackY, kBlackUV, kBlackUV); | 89 FillYUV(frame, kBlackY, kBlackUV, kBlackUV); |
| 92 return frame; | 90 return frame; |
| 93 } | 91 } |
| 94 | 92 |
| 95 static inline size_t RoundUp(size_t value, size_t alignment) { | 93 static inline size_t RoundUp(size_t value, size_t alignment) { |
| 96 // Check that |alignment| is a power of 2. | 94 // Check that |alignment| is a power of 2. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 data_[VideoFrame::kUPlane] = data + y_bytes; | 158 data_[VideoFrame::kUPlane] = data + y_bytes; |
| 161 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; | 159 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; |
| 162 strides_[VideoFrame::kYPlane] = y_stride; | 160 strides_[VideoFrame::kYPlane] = y_stride; |
| 163 strides_[VideoFrame::kUPlane] = uv_stride; | 161 strides_[VideoFrame::kUPlane] = uv_stride; |
| 164 strides_[VideoFrame::kVPlane] = uv_stride; | 162 strides_[VideoFrame::kVPlane] = uv_stride; |
| 165 } | 163 } |
| 166 | 164 |
| 167 VideoFrame::VideoFrame(VideoFrame::Format format, | 165 VideoFrame::VideoFrame(VideoFrame::Format format, |
| 168 size_t width, | 166 size_t width, |
| 169 size_t height, | 167 size_t height, |
| 170 base::TimeDelta timestamp, | 168 base::TimeDelta timestamp) |
| 171 base::TimeDelta duration) | |
| 172 : format_(format), | 169 : format_(format), |
| 173 width_(width), | 170 width_(width), |
| 174 height_(height), | 171 height_(height), |
| 175 texture_id_(0), | 172 texture_id_(0), |
| 176 texture_target_(0), | 173 texture_target_(0), |
| 177 timestamp_(timestamp), | 174 timestamp_(timestamp) { |
| 178 duration_(duration) { | |
| 179 memset(&strides_, 0, sizeof(strides_)); | 175 memset(&strides_, 0, sizeof(strides_)); |
| 180 memset(&data_, 0, sizeof(data_)); | 176 memset(&data_, 0, sizeof(data_)); |
| 181 } | 177 } |
| 182 | 178 |
| 183 VideoFrame::~VideoFrame() { | 179 VideoFrame::~VideoFrame() { |
| 184 if (format_ == NATIVE_TEXTURE && !texture_no_longer_needed_.is_null()) { | 180 if (format_ == NATIVE_TEXTURE && !texture_no_longer_needed_.is_null()) { |
| 185 texture_no_longer_needed_.Run(); | 181 texture_no_longer_needed_.Run(); |
| 186 texture_no_longer_needed_.Reset(); | 182 texture_no_longer_needed_.Reset(); |
| 187 } | 183 } |
| 188 | 184 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 break; | 290 break; |
| 295 for(int row = 0; row < rows(plane); row++) { | 291 for(int row = 0; row < rows(plane); row++) { |
| 296 base::MD5Update(context, base::StringPiece( | 292 base::MD5Update(context, base::StringPiece( |
| 297 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 293 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
| 298 row_bytes(plane))); | 294 row_bytes(plane))); |
| 299 } | 295 } |
| 300 } | 296 } |
| 301 } | 297 } |
| 302 | 298 |
| 303 } // namespace media | 299 } // namespace media |
| OLD | NEW |