| 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 #include <climits> | 8 #include <climits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // level, DmaBufs are not mappable from userspace. | 76 // level, DmaBufs are not mappable from userspace. |
| 77 storage_type != VideoFrame::STORAGE_DMABUFS && | 77 storage_type != VideoFrame::STORAGE_DMABUFS && |
| 78 #endif | 78 #endif |
| 79 (storage_type == VideoFrame::STORAGE_UNOWNED_MEMORY || | 79 (storage_type == VideoFrame::STORAGE_UNOWNED_MEMORY || |
| 80 storage_type == VideoFrame::STORAGE_OWNED_MEMORY || | 80 storage_type == VideoFrame::STORAGE_OWNED_MEMORY || |
| 81 storage_type == VideoFrame::STORAGE_SHMEM || | 81 storage_type == VideoFrame::STORAGE_SHMEM || |
| 82 storage_type == VideoFrame::STORAGE_GPU_MEMORY_BUFFERS || | 82 storage_type == VideoFrame::STORAGE_GPU_MEMORY_BUFFERS || |
| 83 storage_type == VideoFrame::STORAGE_MOJO_SHARED_BUFFER); | 83 storage_type == VideoFrame::STORAGE_MOJO_SHARED_BUFFER); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Checks if |source_format| can be wrapped into a |target_format| frame. |
| 87 static bool AreValidPixelFormatsForWrap(VideoPixelFormat source_format, |
| 88 VideoPixelFormat target_format) { |
| 89 if (source_format == target_format) |
| 90 return true; |
| 91 |
| 92 // It is possible to add other planar to planar format conversions here if the |
| 93 // use case is there. |
| 94 return source_format == PIXEL_FORMAT_YV12A && |
| 95 target_format == PIXEL_FORMAT_I420; |
| 96 } |
| 97 |
| 86 // static | 98 // static |
| 87 bool VideoFrame::IsValidConfig(VideoPixelFormat format, | 99 bool VideoFrame::IsValidConfig(VideoPixelFormat format, |
| 88 StorageType storage_type, | 100 StorageType storage_type, |
| 89 const gfx::Size& coded_size, | 101 const gfx::Size& coded_size, |
| 90 const gfx::Rect& visible_rect, | 102 const gfx::Rect& visible_rect, |
| 91 const gfx::Size& natural_size) { | 103 const gfx::Size& natural_size) { |
| 92 // Check maximum limits for all formats. | 104 // Check maximum limits for all formats. |
| 93 int coded_size_area = coded_size.GetCheckedArea().ValueOrDefault(INT_MAX); | 105 int coded_size_area = coded_size.GetCheckedArea().ValueOrDefault(INT_MAX); |
| 94 int natural_size_area = natural_size.GetCheckedArea().ValueOrDefault(INT_MAX); | 106 int natural_size_area = natural_size.GetCheckedArea().ValueOrDefault(INT_MAX); |
| 95 static_assert(limits::kMaxCanvas < INT_MAX, ""); | 107 static_assert(limits::kMaxCanvas < INT_MAX, ""); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 scoped_refptr<VideoFrame> frame(new VideoFrame( | 383 scoped_refptr<VideoFrame> frame(new VideoFrame( |
| 372 format, storage, coded_size, visible_rect, natural_size, timestamp)); | 384 format, storage, coded_size, visible_rect, natural_size, timestamp)); |
| 373 | 385 |
| 374 frame->cv_pixel_buffer_.reset(cv_pixel_buffer, base::scoped_policy::RETAIN); | 386 frame->cv_pixel_buffer_.reset(cv_pixel_buffer, base::scoped_policy::RETAIN); |
| 375 return frame; | 387 return frame; |
| 376 } | 388 } |
| 377 #endif | 389 #endif |
| 378 | 390 |
| 379 // static | 391 // static |
| 380 scoped_refptr<VideoFrame> VideoFrame::WrapVideoFrame( | 392 scoped_refptr<VideoFrame> VideoFrame::WrapVideoFrame( |
| 381 const scoped_refptr<VideoFrame>& frame, | 393 const scoped_refptr<VideoFrame>& frame, |
| 382 const gfx::Rect& visible_rect, | 394 VideoPixelFormat format, |
| 383 const gfx::Size& natural_size) { | 395 const gfx::Rect& visible_rect, |
| 396 const gfx::Size& natural_size) { |
| 384 // Frames with textures need mailbox info propagated, and there's no support | 397 // Frames with textures need mailbox info propagated, and there's no support |
| 385 // for that here yet, see http://crbug/362521. | 398 // for that here yet, see http://crbug/362521. |
| 386 CHECK(!frame->HasTextures()); | 399 CHECK(!frame->HasTextures()); |
| 387 | |
| 388 DCHECK(frame->visible_rect().Contains(visible_rect)); | 400 DCHECK(frame->visible_rect().Contains(visible_rect)); |
| 389 | 401 |
| 390 if (!IsValidConfig(frame->format(), frame->storage_type(), | 402 if (!AreValidPixelFormatsForWrap(frame->format(), format)) { |
| 391 frame->coded_size(), visible_rect, natural_size)) { | 403 LOG(DFATAL) << __FUNCTION__ << " Invalid format conversion." |
| 404 << VideoPixelFormatToString(frame->format()) << " to " |
| 405 << VideoPixelFormatToString(format); |
| 406 return nullptr; |
| 407 } |
| 408 |
| 409 if (!IsValidConfig(format, frame->storage_type(), frame->coded_size(), |
| 410 visible_rect, natural_size)) { |
| 392 LOG(DFATAL) << __FUNCTION__ << " Invalid config." | 411 LOG(DFATAL) << __FUNCTION__ << " Invalid config." |
| 393 << ConfigToString(frame->format(), frame->storage_type(), | 412 << ConfigToString(format, frame->storage_type(), |
| 394 frame->coded_size(), visible_rect, | 413 frame->coded_size(), visible_rect, |
| 395 natural_size); | 414 natural_size); |
| 396 return nullptr; | 415 return nullptr; |
| 397 } | 416 } |
| 398 | 417 |
| 399 scoped_refptr<VideoFrame> wrapping_frame(new VideoFrame( | 418 scoped_refptr<VideoFrame> wrapping_frame( |
| 400 frame->format(), frame->storage_type(), frame->coded_size(), visible_rect, | 419 new VideoFrame(format, frame->storage_type(), frame->coded_size(), |
| 401 natural_size, frame->timestamp())); | 420 visible_rect, natural_size, frame->timestamp())); |
| 402 | 421 |
| 403 // Copy all metadata to the wrapped frame. | 422 // Copy all metadata to the wrapped frame. |
| 404 wrapping_frame->metadata()->MergeMetadataFrom(frame->metadata()); | 423 wrapping_frame->metadata()->MergeMetadataFrom(frame->metadata()); |
| 405 | 424 |
| 406 for (size_t i = 0; i < NumPlanes(frame->format()); ++i) { | 425 for (size_t i = 0; i < NumPlanes(format); ++i) { |
| 407 wrapping_frame->strides_[i] = frame->stride(i); | 426 wrapping_frame->strides_[i] = frame->stride(i); |
| 408 wrapping_frame->data_[i] = frame->data(i); | 427 wrapping_frame->data_[i] = frame->data(i); |
| 409 } | 428 } |
| 410 | 429 |
| 411 #if defined(OS_LINUX) | 430 #if defined(OS_LINUX) |
| 412 // If there are any |dmabuf_fds_| plugged in, we should duplicate them. | 431 // If there are any |dmabuf_fds_| plugged in, we should duplicate them. |
| 413 if (frame->storage_type() == STORAGE_DMABUFS) { | 432 if (frame->storage_type() == STORAGE_DMABUFS) { |
| 414 std::vector<int> original_fds; | 433 std::vector<int> original_fds; |
| 415 for (size_t i = 0; i < kMaxPlanes; ++i) | 434 for (size_t i = 0; i < kMaxPlanes; ++i) |
| 416 original_fds.push_back(frame->dmabuf_fd(i)); | 435 original_fds.push_back(frame->dmabuf_fd(i)); |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 if (zero_initialize_memory) | 1115 if (zero_initialize_memory) |
| 1097 memset(data, 0, data_size); | 1116 memset(data, 0, data_size); |
| 1098 | 1117 |
| 1099 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) | 1118 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) |
| 1100 data_[plane] = data + offset[plane]; | 1119 data_[plane] = data + offset[plane]; |
| 1101 | 1120 |
| 1102 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); | 1121 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); |
| 1103 } | 1122 } |
| 1104 | 1123 |
| 1105 } // namespace media | 1124 } // namespace media |
| OLD | NEW |