Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 // Data is accessible only via fds. | 271 // Data is accessible only via fds. |
| 272 frame->data_[i] = NULL; | 272 frame->data_[i] = NULL; |
| 273 frame->strides_[i] = 0; | 273 frame->strides_[i] = 0; |
| 274 } | 274 } |
| 275 | 275 |
| 276 frame->no_longer_needed_cb_ = no_longer_needed_cb; | 276 frame->no_longer_needed_cb_ = no_longer_needed_cb; |
| 277 return frame; | 277 return frame; |
| 278 } | 278 } |
| 279 #endif | 279 #endif |
| 280 | 280 |
| 281 #if defined(OS_MACOSX) | |
| 282 // static | |
| 283 scoped_refptr<VideoFrame> VideoFrame::WrapCVPixelBuffer( | |
| 284 CVPixelBufferRef cv_pixel_buffer, | |
| 285 base::TimeDelta timestamp) { | |
| 286 DCHECK(cv_pixel_buffer); | |
| 287 DCHECK(CFGetTypeID(cv_pixel_buffer) == CVPixelBufferGetTypeID()); | |
| 288 | |
| 289 OSType cv_format = CVPixelBufferGetPixelFormatType(cv_pixel_buffer); | |
| 290 Format format; | |
| 291 // There are very few compatible CV pixel formats, so just check each. | |
| 292 if (cv_format == kCVPixelFormatType_420YpCbCr8Planar) { | |
| 293 format = Format::I420; | |
| 294 } else if (cv_format == kCVPixelFormatType_444YpCbCr8) { | |
| 295 format = Format::YV24; | |
| 296 } | |
| 297 #if (__MAC_OS_X_VERSION_MIN_REQUIRED >= 1070) || \ | |
| 298 (__IPHONE_OS_VERSION_MIN_REQUIRED >= 40000) | |
|
Robert Sesek
2014/08/07 18:00:15
Does //media even get compiled on iOS? If not, rem
jfroy
2014/08/07 18:08:20
It is for my purpose. I can still switch to using
Robert Sesek
2014/08/07 18:14:44
If this code doesn't build on iOS, then remove the
| |
| 299 else if (cv_format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange) { | |
| 300 format = Format::NV12; | |
| 301 } | |
| 302 #endif | |
| 303 else { | |
| 304 DLOG(ERROR) << "CVPixelBuffer format not supported: " << cv_format; | |
| 305 return NULL; | |
| 306 } | |
| 307 | |
| 308 gfx::Size coded_size(CVImageBufferGetEncodedSize(cv_pixel_buffer)); | |
| 309 gfx::Rect visible_rect(CVImageBufferGetCleanRect(cv_pixel_buffer)); | |
| 310 gfx::Size natural_size(CVImageBufferGetDisplaySize(cv_pixel_buffer)); | |
| 311 | |
| 312 if (!IsValidConfig(format, coded_size, visible_rect, natural_size)) | |
| 313 return NULL; | |
| 314 | |
| 315 scoped_refptr<VideoFrame> frame( | |
| 316 new VideoFrame(format, | |
| 317 coded_size, | |
| 318 visible_rect, | |
| 319 natural_size, | |
| 320 scoped_ptr<gpu::MailboxHolder>(), | |
| 321 timestamp, | |
| 322 false)); | |
| 323 | |
| 324 frame->cv_pixel_buffer_.reset(cv_pixel_buffer, base::scoped_policy::RETAIN); | |
| 325 return frame; | |
| 326 } | |
| 327 #endif | |
| 328 | |
| 281 // static | 329 // static |
| 282 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData( | 330 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData( |
| 283 Format format, | 331 Format format, |
| 284 const gfx::Size& coded_size, | 332 const gfx::Size& coded_size, |
| 285 const gfx::Rect& visible_rect, | 333 const gfx::Rect& visible_rect, |
| 286 const gfx::Size& natural_size, | 334 const gfx::Size& natural_size, |
| 287 int32 y_stride, | 335 int32 y_stride, |
| 288 int32 u_stride, | 336 int32 u_stride, |
| 289 int32 v_stride, | 337 int32 v_stride, |
| 290 uint8* y_data, | 338 uint8* y_data, |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 client->WaitSyncPoint(release_sync_point_); | 893 client->WaitSyncPoint(release_sync_point_); |
| 846 release_sync_point_ = client->InsertSyncPoint(); | 894 release_sync_point_ = client->InsertSyncPoint(); |
| 847 } | 895 } |
| 848 | 896 |
| 849 #if defined(OS_POSIX) | 897 #if defined(OS_POSIX) |
| 850 int VideoFrame::dmabuf_fd(size_t plane) const { | 898 int VideoFrame::dmabuf_fd(size_t plane) const { |
| 851 return dmabuf_fds_[plane].get(); | 899 return dmabuf_fds_[plane].get(); |
| 852 } | 900 } |
| 853 #endif | 901 #endif |
| 854 | 902 |
| 903 #if defined(OS_MACOSX) | |
| 904 CVPixelBufferRef VideoFrame::cv_pixel_buffer() const { | |
| 905 return cv_pixel_buffer_.get(); | |
| 906 } | |
| 907 #endif | |
| 908 | |
| 855 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { | 909 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { |
| 856 for (int plane = 0; plane < kMaxPlanes; ++plane) { | 910 for (int plane = 0; plane < kMaxPlanes; ++plane) { |
| 857 if (!IsValidPlane(plane)) | 911 if (!IsValidPlane(plane)) |
| 858 break; | 912 break; |
| 859 for (int row = 0; row < rows(plane); ++row) { | 913 for (int row = 0; row < rows(plane); ++row) { |
| 860 base::MD5Update(context, base::StringPiece( | 914 base::MD5Update(context, base::StringPiece( |
| 861 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 915 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
| 862 row_bytes(plane))); | 916 row_bytes(plane))); |
| 863 } | 917 } |
| 864 } | 918 } |
| 865 } | 919 } |
| 866 | 920 |
| 867 } // namespace media | 921 } // namespace media |
| OLD | NEW |