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

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: 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
« media/base/video_frame.h ('K') | « 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/aligned_memory.h" 12 #include "base/memory/aligned_memory.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "gpu/command_buffer/common/mailbox_holder.h" 14 #include "gpu/command_buffer/common/mailbox_holder.h"
15 #include "media/base/limits.h" 15 #include "media/base/limits.h"
16 #include "media/base/video_util.h" 16 #include "media/base/video_util.h"
17 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
18 18
19 #if defined(OS_MACOSX)
20 #include <CoreVideo/CoreVideo.h>
21 #endif
22
19 namespace media { 23 namespace media {
20 24
21 static inline size_t RoundUp(size_t value, size_t alignment) { 25 static inline size_t RoundUp(size_t value, size_t alignment) {
22 // Check that |alignment| is a power of 2. 26 // Check that |alignment| is a power of 2.
23 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); 27 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1)));
24 return ((value + (alignment - 1)) & ~(alignment - 1)); 28 return ((value + (alignment - 1)) & ~(alignment - 1));
25 } 29 }
26 30
27 // Rounds up |coded_size| if necessary for |format|. 31 // Rounds up |coded_size| if necessary for |format|.
28 static gfx::Size AdjustCodedSize(VideoFrame::Format format, 32 static gfx::Size AdjustCodedSize(VideoFrame::Format format,
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // Data is accessible only via fds. 275 // Data is accessible only via fds.
272 frame->data_[i] = NULL; 276 frame->data_[i] = NULL;
273 frame->strides_[i] = 0; 277 frame->strides_[i] = 0;
274 } 278 }
275 279
276 frame->no_longer_needed_cb_ = no_longer_needed_cb; 280 frame->no_longer_needed_cb_ = no_longer_needed_cb;
277 return frame; 281 return frame;
278 } 282 }
279 #endif 283 #endif
280 284
285 #if defined(OS_MACOSX)
286 // static
287 scoped_refptr<VideoFrame> VideoFrame::WrapCVPixelBuffer(
288 CVPixelBufferRef cv_pixel_buffer,
289 base::TimeDelta timestamp) {
290 DCHECK(cv_pixel_buffer);
291 DCHECK(CFGetTypeID(cv_pixel_buffer) == CVPixelBufferGetTypeID());
292
293 OSType cv_format = CVPixelBufferGetPixelFormatType(cv_pixel_buffer);
294 Format format;
295 // there are very few compatible CV pixel formats, so just check each
Robert Sesek 2014/08/07 16:12:57 nit: capitalization and punctuation
jfroy 2014/08/07 16:22:14 Acknowledged.
296 if (cv_format == kCVPixelFormatType_420YpCbCr8Planar) {
297 format = Format::I420;
298 } else if (cv_format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange) {
Robert Sesek 2014/08/07 16:12:57 This is only available on 10.7 and later. This wil
jfroy 2014/08/07 16:22:14 Wow, are you telling me Chrome needs to build on 1
Robert Sesek 2014/08/07 16:34:42 Yes. Build and run. This has been the requirement
jfroy 2014/08/07 16:52:45 I'm brand new to Chrome development, I didn't know
Robert Sesek 2014/08/07 18:00:15 Actually, it's quite trivial. You just need go/mac
299 format = Format::NV12;
300 } else if (cv_format == kCVPixelFormatType_444YpCbCr8) {
301 format = Format::YV24;
302 } else {
303 DLOG(ERROR) << "CVPixelBuffer format not supported: " << cv_format;
304 return NULL;
305 }
306
307 gfx::Size coded_size(CVImageBufferGetEncodedSize(cv_pixel_buffer));
308 gfx::Rect visible_rect(CVImageBufferGetCleanRect(cv_pixel_buffer));
309 gfx::Size natural_size(CVImageBufferGetDisplaySize(cv_pixel_buffer));
310
311 if (!IsValidConfig(format, coded_size, visible_rect, natural_size))
312 return NULL;
313
314 scoped_refptr<VideoFrame> frame(
315 new VideoFrame(format,
316 coded_size,
317 visible_rect,
318 natural_size,
319 scoped_ptr<gpu::MailboxHolder>(),
320 timestamp,
321 false));
322
323 frame->cv_pixel_buffer_.reset(cv_pixel_buffer, base::scoped_policy::RETAIN);
324 return frame;
325 }
326 #endif
327
281 // static 328 // static
282 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData( 329 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData(
283 Format format, 330 Format format,
284 const gfx::Size& coded_size, 331 const gfx::Size& coded_size,
285 const gfx::Rect& visible_rect, 332 const gfx::Rect& visible_rect,
286 const gfx::Size& natural_size, 333 const gfx::Size& natural_size,
287 int32 y_stride, 334 int32 y_stride,
288 int32 u_stride, 335 int32 u_stride,
289 int32 v_stride, 336 int32 v_stride,
290 uint8* y_data, 337 uint8* y_data,
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 client->WaitSyncPoint(release_sync_point_); 892 client->WaitSyncPoint(release_sync_point_);
846 release_sync_point_ = client->InsertSyncPoint(); 893 release_sync_point_ = client->InsertSyncPoint();
847 } 894 }
848 895
849 #if defined(OS_POSIX) 896 #if defined(OS_POSIX)
850 int VideoFrame::dmabuf_fd(size_t plane) const { 897 int VideoFrame::dmabuf_fd(size_t plane) const {
851 return dmabuf_fds_[plane].get(); 898 return dmabuf_fds_[plane].get();
852 } 899 }
853 #endif 900 #endif
854 901
902 #if defined(OS_MACOSX)
903 CVPixelBufferRef VideoFrame::cv_pixel_buffer() const {
904 return cv_pixel_buffer_.get();
905 }
906 #endif
907
855 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { 908 void VideoFrame::HashFrameForTesting(base::MD5Context* context) {
856 for (int plane = 0; plane < kMaxPlanes; ++plane) { 909 for (int plane = 0; plane < kMaxPlanes; ++plane) {
857 if (!IsValidPlane(plane)) 910 if (!IsValidPlane(plane))
858 break; 911 break;
859 for (int row = 0; row < rows(plane); ++row) { 912 for (int row = 0; row < rows(plane); ++row) {
860 base::MD5Update(context, base::StringPiece( 913 base::MD5Update(context, base::StringPiece(
861 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 914 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
862 row_bytes(plane))); 915 row_bytes(plane)));
863 } 916 }
864 } 917 }
865 } 918 }
866 919
867 } // namespace media 920 } // namespace media
OLDNEW
« media/base/video_frame.h ('K') | « media/base/video_frame.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698