Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: media/base/video_frame.cc

Issue 446163003: Extend media::VideoFrame to wrap CVPixelBuffer on OS X and iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use literal value of kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange instead of (wrong) availabilit… Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/video_frame.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // NOTE: kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
Robert Sesek 2014/08/12 00:09:40 TODO(jfroy): Use kCVPixelFormatType_420YpCbCr8BiPl
jfroy 2014/08/12 00:46:54 Acknowledged.
298 format = Format::NV12;
299 } else {
300 DLOG(ERROR) << "CVPixelBuffer format not supported: " << cv_format;
301 return NULL;
302 }
303
304 gfx::Size coded_size(CVImageBufferGetEncodedSize(cv_pixel_buffer));
305 gfx::Rect visible_rect(CVImageBufferGetCleanRect(cv_pixel_buffer));
306 gfx::Size natural_size(CVImageBufferGetDisplaySize(cv_pixel_buffer));
307
308 if (!IsValidConfig(format, coded_size, visible_rect, natural_size))
309 return NULL;
310
311 scoped_refptr<VideoFrame> frame(
312 new VideoFrame(format,
313 coded_size,
314 visible_rect,
315 natural_size,
316 scoped_ptr<gpu::MailboxHolder>(),
317 timestamp,
318 false));
319
320 frame->cv_pixel_buffer_.reset(cv_pixel_buffer, base::scoped_policy::RETAIN);
321 return frame;
322 }
323 #endif
324
281 // static 325 // static
282 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData( 326 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData(
283 Format format, 327 Format format,
284 const gfx::Size& coded_size, 328 const gfx::Size& coded_size,
285 const gfx::Rect& visible_rect, 329 const gfx::Rect& visible_rect,
286 const gfx::Size& natural_size, 330 const gfx::Size& natural_size,
287 int32 y_stride, 331 int32 y_stride,
288 int32 u_stride, 332 int32 u_stride,
289 int32 v_stride, 333 int32 v_stride,
290 uint8* y_data, 334 uint8* y_data,
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 client->WaitSyncPoint(release_sync_point_); 889 client->WaitSyncPoint(release_sync_point_);
846 release_sync_point_ = client->InsertSyncPoint(); 890 release_sync_point_ = client->InsertSyncPoint();
847 } 891 }
848 892
849 #if defined(OS_POSIX) 893 #if defined(OS_POSIX)
850 int VideoFrame::dmabuf_fd(size_t plane) const { 894 int VideoFrame::dmabuf_fd(size_t plane) const {
851 return dmabuf_fds_[plane].get(); 895 return dmabuf_fds_[plane].get();
852 } 896 }
853 #endif 897 #endif
854 898
899 #if defined(OS_MACOSX)
900 CVPixelBufferRef VideoFrame::cv_pixel_buffer() const {
901 return cv_pixel_buffer_.get();
902 }
903 #endif
904
855 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { 905 void VideoFrame::HashFrameForTesting(base::MD5Context* context) {
856 for (int plane = 0; plane < kMaxPlanes; ++plane) { 906 for (int plane = 0; plane < kMaxPlanes; ++plane) {
857 if (!IsValidPlane(plane)) 907 if (!IsValidPlane(plane))
858 break; 908 break;
859 for (int row = 0; row < rows(plane); ++row) { 909 for (int row = 0; row < rows(plane); ++row) {
860 base::MD5Update(context, base::StringPiece( 910 base::MD5Update(context, base::StringPiece(
861 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 911 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
862 row_bytes(plane))); 912 row_bytes(plane)));
863 } 913 }
864 } 914 }
865 } 915 }
866 916
867 } // namespace media 917 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698