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

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

Issue 1737253002: Handle Alpha channel in Canvas capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mcasas@ comments. Created 4 years, 9 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') | media/base/video_frame_pool.cc » ('j') | 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 #include <climits> 8 #include <climits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 return 1; 193 return 1;
194 case PIXEL_FORMAT_MJPEG: 194 case PIXEL_FORMAT_MJPEG:
195 return 0; 195 return 0;
196 case PIXEL_FORMAT_UNKNOWN: 196 case PIXEL_FORMAT_UNKNOWN:
197 break; 197 break;
198 } 198 }
199 NOTREACHED(); 199 NOTREACHED();
200 return 0; 200 return 0;
201 } 201 }
202 202
203 // Checks if |source_format| can be wrapped into a |target_format| frame.
204 static bool AreValidPixelFormatsForWrap(VideoPixelFormat source_format,
205 VideoPixelFormat target_format) {
206 if (source_format == target_format)
207 return true;
208
209 switch (source_format) {
210 case PIXEL_FORMAT_YV12A:
211 switch (target_format) {
212 case PIXEL_FORMAT_I420:
213 return true;
214 default:
215 return false;
216 }
217 default:
218 return false;
219 }
220 }
221
203 // static 222 // static
204 bool VideoFrame::IsValidConfig(VideoPixelFormat format, 223 bool VideoFrame::IsValidConfig(VideoPixelFormat format,
205 StorageType storage_type, 224 StorageType storage_type,
206 const gfx::Size& coded_size, 225 const gfx::Size& coded_size,
207 const gfx::Rect& visible_rect, 226 const gfx::Rect& visible_rect,
208 const gfx::Size& natural_size) { 227 const gfx::Size& natural_size) {
209 // Check maximum limits for all formats. 228 // Check maximum limits for all formats.
210 int coded_size_area = coded_size.GetCheckedArea().ValueOrDefault(INT_MAX); 229 int coded_size_area = coded_size.GetCheckedArea().ValueOrDefault(INT_MAX);
211 int natural_size_area = natural_size.GetCheckedArea().ValueOrDefault(INT_MAX); 230 int natural_size_area = natural_size.GetCheckedArea().ValueOrDefault(INT_MAX);
212 static_assert(limits::kMaxCanvas < INT_MAX, ""); 231 static_assert(limits::kMaxCanvas < INT_MAX, "");
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 scoped_refptr<VideoFrame> frame(new VideoFrame( 507 scoped_refptr<VideoFrame> frame(new VideoFrame(
489 format, storage, coded_size, visible_rect, natural_size, timestamp)); 508 format, storage, coded_size, visible_rect, natural_size, timestamp));
490 509
491 frame->cv_pixel_buffer_.reset(cv_pixel_buffer, base::scoped_policy::RETAIN); 510 frame->cv_pixel_buffer_.reset(cv_pixel_buffer, base::scoped_policy::RETAIN);
492 return frame; 511 return frame;
493 } 512 }
494 #endif 513 #endif
495 514
496 // static 515 // static
497 scoped_refptr<VideoFrame> VideoFrame::WrapVideoFrame( 516 scoped_refptr<VideoFrame> VideoFrame::WrapVideoFrame(
498 const scoped_refptr<VideoFrame>& frame, 517 const scoped_refptr<VideoFrame>& frame,
499 const gfx::Rect& visible_rect, 518 VideoPixelFormat format,
500 const gfx::Size& natural_size) { 519 const gfx::Rect& visible_rect,
520 const gfx::Size& natural_size) {
501 // Frames with textures need mailbox info propagated, and there's no support 521 // Frames with textures need mailbox info propagated, and there's no support
502 // for that here yet, see http://crbug/362521. 522 // for that here yet, see http://crbug/362521.
503 CHECK(!frame->HasTextures()); 523 CHECK(!frame->HasTextures());
504
505 DCHECK(frame->visible_rect().Contains(visible_rect)); 524 DCHECK(frame->visible_rect().Contains(visible_rect));
506 525
507 if (!IsValidConfig(frame->format(), frame->storage_type(), 526 if (!AreValidPixelFormatsForWrap(frame->format(), format)) {
508 frame->coded_size(), visible_rect, natural_size)) { 527 LOG(DFATAL) << __FUNCTION__ << " Invalid format conversions."
mcasas 2016/03/02 22:01:10 micro-nit: s/conversions./conversion: /
emircan 2016/03/03 22:05:58 Done.
528 << VideoPixelFormatToString(frame->format()) << " to "
529 << VideoPixelFormatToString(format);
530 return nullptr;
531 }
532
533 if (!IsValidConfig(format, frame->storage_type(), frame->coded_size(),
534 visible_rect, natural_size)) {
509 LOG(DFATAL) << __FUNCTION__ << " Invalid config." 535 LOG(DFATAL) << __FUNCTION__ << " Invalid config."
510 << ConfigToString(frame->format(), frame->storage_type(), 536 << ConfigToString(format, frame->storage_type(),
511 frame->coded_size(), visible_rect, 537 frame->coded_size(), visible_rect,
512 natural_size); 538 natural_size);
513 return nullptr; 539 return nullptr;
514 } 540 }
515 541
516 scoped_refptr<VideoFrame> wrapping_frame(new VideoFrame( 542 scoped_refptr<VideoFrame> wrapping_frame(
517 frame->format(), frame->storage_type(), frame->coded_size(), visible_rect, 543 new VideoFrame(format, frame->storage_type(), frame->coded_size(),
518 natural_size, frame->timestamp())); 544 visible_rect, natural_size, frame->timestamp()));
545 // Investigate if we can copy the whole metadata, see http://crbug/591138.
519 if (frame->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)) { 546 if (frame->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)) {
520 wrapping_frame->metadata()->SetBoolean(VideoFrameMetadata::END_OF_STREAM, 547 wrapping_frame->metadata()->SetBoolean(VideoFrameMetadata::END_OF_STREAM,
521 true); 548 true);
522 } 549 }
523 550
524 for (size_t i = 0; i < NumPlanes(frame->format()); ++i) { 551 for (size_t i = 0; i < NumPlanes(format); ++i) {
525 wrapping_frame->strides_[i] = frame->stride(i); 552 wrapping_frame->strides_[i] = frame->stride(i);
526 wrapping_frame->data_[i] = frame->data(i); 553 wrapping_frame->data_[i] = frame->data(i);
527 } 554 }
528 555
529 #if defined(OS_LINUX) 556 #if defined(OS_LINUX)
530 // If there are any |dmabuf_fds_| plugged in, we should duplicate them. 557 // If there are any |dmabuf_fds_| plugged in, we should duplicate them.
531 if (frame->storage_type() == STORAGE_DMABUFS) { 558 if (frame->storage_type() == STORAGE_DMABUFS) {
532 std::vector<int> original_fds; 559 std::vector<int> original_fds;
533 for (size_t i = 0; i < kMaxPlanes; ++i) 560 for (size_t i = 0; i < kMaxPlanes; ++i)
534 original_fds.push_back(frame->dmabuf_fd(i)); 561 original_fds.push_back(frame->dmabuf_fd(i));
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 if (zero_initialize_memory) 1107 if (zero_initialize_memory)
1081 memset(data, 0, data_size); 1108 memset(data, 0, data_size);
1082 1109
1083 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) 1110 for (size_t plane = 0; plane < NumPlanes(format_); ++plane)
1084 data_[plane] = data + offset[plane]; 1111 data_[plane] = data + offset[plane];
1085 1112
1086 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); 1113 AddDestructionObserver(base::Bind(&base::AlignedFree, data));
1087 } 1114 }
1088 1115
1089 } // namespace media 1116 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.h ('k') | media/base/video_frame_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698