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 } else if (cv_format == '420v') { | |
297 // TODO(jfroy): Use kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange when the | |
miu
2014/08/25 18:39:35
I've seen others solve this problem by using #ifde
Robert Sesek
2014/08/25 18:42:07
There was already back-and-forth about this on the
| |
298 // minimum OS X and iOS SDKs permits it. | |
299 format = Format::NV12; | |
300 } else { | |
301 DLOG(ERROR) << "CVPixelBuffer format not supported: " << cv_format; | |
302 return NULL; | |
303 } | |
304 | |
305 gfx::Size coded_size(CVImageBufferGetEncodedSize(cv_pixel_buffer)); | |
306 gfx::Rect visible_rect(CVImageBufferGetCleanRect(cv_pixel_buffer)); | |
307 gfx::Size natural_size(CVImageBufferGetDisplaySize(cv_pixel_buffer)); | |
308 | |
309 if (!IsValidConfig(format, coded_size, visible_rect, natural_size)) | |
310 return NULL; | |
311 | |
312 scoped_refptr<VideoFrame> frame( | |
313 new VideoFrame(format, | |
314 coded_size, | |
315 visible_rect, | |
316 natural_size, | |
317 scoped_ptr<gpu::MailboxHolder>(), | |
318 timestamp, | |
319 false)); | |
320 | |
321 frame->cv_pixel_buffer_.reset(cv_pixel_buffer, base::scoped_policy::RETAIN); | |
322 return frame; | |
323 } | |
324 #endif | |
325 | |
281 // static | 326 // static |
282 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData( | 327 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData( |
283 Format format, | 328 Format format, |
284 const gfx::Size& coded_size, | 329 const gfx::Size& coded_size, |
285 const gfx::Rect& visible_rect, | 330 const gfx::Rect& visible_rect, |
286 const gfx::Size& natural_size, | 331 const gfx::Size& natural_size, |
287 int32 y_stride, | 332 int32 y_stride, |
288 int32 u_stride, | 333 int32 u_stride, |
289 int32 v_stride, | 334 int32 v_stride, |
290 uint8* y_data, | 335 uint8* y_data, |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
850 client->WaitSyncPoint(release_sync_point_); | 895 client->WaitSyncPoint(release_sync_point_); |
851 release_sync_point_ = client->InsertSyncPoint(); | 896 release_sync_point_ = client->InsertSyncPoint(); |
852 } | 897 } |
853 | 898 |
854 #if defined(OS_POSIX) | 899 #if defined(OS_POSIX) |
855 int VideoFrame::dmabuf_fd(size_t plane) const { | 900 int VideoFrame::dmabuf_fd(size_t plane) const { |
856 return dmabuf_fds_[plane].get(); | 901 return dmabuf_fds_[plane].get(); |
857 } | 902 } |
858 #endif | 903 #endif |
859 | 904 |
905 #if defined(OS_MACOSX) | |
906 CVPixelBufferRef VideoFrame::cv_pixel_buffer() const { | |
907 return cv_pixel_buffer_.get(); | |
908 } | |
909 #endif | |
910 | |
860 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { | 911 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { |
861 for (int plane = 0; plane < kMaxPlanes; ++plane) { | 912 for (int plane = 0; plane < kMaxPlanes; ++plane) { |
862 if (!IsValidPlane(plane, format_)) | 913 if (!IsValidPlane(plane, format_)) |
863 break; | 914 break; |
864 for (int row = 0; row < rows(plane); ++row) { | 915 for (int row = 0; row < rows(plane); ++row) { |
865 base::MD5Update(context, base::StringPiece( | 916 base::MD5Update(context, base::StringPiece( |
866 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 917 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
867 row_bytes(plane))); | 918 row_bytes(plane))); |
868 } | 919 } |
869 } | 920 } |
870 } | 921 } |
871 | 922 |
872 } // namespace media | 923 } // namespace media |
OLD | NEW |