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

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

Issue 2395913003: Cleanup of passing GpuMemoryBuffer backed video frames (Closed)
Patch Set: Rebase Created 4 years, 2 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/gpu/ipc/client/gpu_video_encode_accelerator_host.h » ('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/atomic_sequence_num.h" 10 #include "base/atomic_sequence_num.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 case VideoFrame::STORAGE_UNOWNED_MEMORY: 50 case VideoFrame::STORAGE_UNOWNED_MEMORY:
51 return "UNOWNED_MEMORY"; 51 return "UNOWNED_MEMORY";
52 case VideoFrame::STORAGE_OWNED_MEMORY: 52 case VideoFrame::STORAGE_OWNED_MEMORY:
53 return "OWNED_MEMORY"; 53 return "OWNED_MEMORY";
54 case VideoFrame::STORAGE_SHMEM: 54 case VideoFrame::STORAGE_SHMEM:
55 return "SHMEM"; 55 return "SHMEM";
56 #if defined(OS_LINUX) 56 #if defined(OS_LINUX)
57 case VideoFrame::STORAGE_DMABUFS: 57 case VideoFrame::STORAGE_DMABUFS:
58 return "DMABUFS"; 58 return "DMABUFS";
59 #endif 59 #endif
60 case VideoFrame::STORAGE_GPU_MEMORY_BUFFERS:
61 return "GPU_MEMORY_BUFFERS";
62 case VideoFrame::STORAGE_MOJO_SHARED_BUFFER: 60 case VideoFrame::STORAGE_MOJO_SHARED_BUFFER:
63 return "MOJO_SHARED_BUFFER"; 61 return "MOJO_SHARED_BUFFER";
64 } 62 }
65 63
66 NOTREACHED() << "Invalid StorageType provided: " << storage_type; 64 NOTREACHED() << "Invalid StorageType provided: " << storage_type;
67 return "INVALID"; 65 return "INVALID";
68 } 66 }
69 67
70 // Returns true if |frame| is accesible mapped in the VideoFrame memory space. 68 // Returns true if |frame| is accesible mapped in the VideoFrame memory space.
71 // static 69 // static
72 static bool IsStorageTypeMappable(VideoFrame::StorageType storage_type) { 70 static bool IsStorageTypeMappable(VideoFrame::StorageType storage_type) {
73 return 71 return
74 #if defined(OS_LINUX) 72 #if defined(OS_LINUX)
75 // This is not strictly needed but makes explicit that, at VideoFrame 73 // This is not strictly needed but makes explicit that, at VideoFrame
76 // level, DmaBufs are not mappable from userspace. 74 // level, DmaBufs are not mappable from userspace.
77 storage_type != VideoFrame::STORAGE_DMABUFS && 75 storage_type != VideoFrame::STORAGE_DMABUFS &&
78 #endif 76 #endif
79 (storage_type == VideoFrame::STORAGE_UNOWNED_MEMORY || 77 (storage_type == VideoFrame::STORAGE_UNOWNED_MEMORY ||
80 storage_type == VideoFrame::STORAGE_OWNED_MEMORY || 78 storage_type == VideoFrame::STORAGE_OWNED_MEMORY ||
81 storage_type == VideoFrame::STORAGE_SHMEM || 79 storage_type == VideoFrame::STORAGE_SHMEM ||
82 storage_type == VideoFrame::STORAGE_GPU_MEMORY_BUFFERS ||
83 storage_type == VideoFrame::STORAGE_MOJO_SHARED_BUFFER); 80 storage_type == VideoFrame::STORAGE_MOJO_SHARED_BUFFER);
84 } 81 }
85 82
86 // Checks if |source_format| can be wrapped into a |target_format| frame. 83 // Checks if |source_format| can be wrapped into a |target_format| frame.
87 static bool AreValidPixelFormatsForWrap(VideoPixelFormat source_format, 84 static bool AreValidPixelFormatsForWrap(VideoPixelFormat source_format,
88 VideoPixelFormat target_format) { 85 VideoPixelFormat target_format) {
89 if (source_format == target_format) 86 if (source_format == target_format)
90 return true; 87 return true;
91 88
92 // It is possible to add other planar to planar format conversions here if the 89 // It is possible to add other planar to planar format conversions here if the
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 frame->strides_[kYPlane] = y_stride; 236 frame->strides_[kYPlane] = y_stride;
240 frame->strides_[kUPlane] = u_stride; 237 frame->strides_[kUPlane] = u_stride;
241 frame->strides_[kVPlane] = v_stride; 238 frame->strides_[kVPlane] = v_stride;
242 frame->data_[kYPlane] = y_data; 239 frame->data_[kYPlane] = y_data;
243 frame->data_[kUPlane] = u_data; 240 frame->data_[kUPlane] = u_data;
244 frame->data_[kVPlane] = v_data; 241 frame->data_[kVPlane] = v_data;
245 return frame; 242 return frame;
246 } 243 }
247 244
248 // static 245 // static
249 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvGpuMemoryBuffers(
250 VideoPixelFormat format,
251 const gfx::Size& coded_size,
252 const gfx::Rect& visible_rect,
253 const gfx::Size& natural_size,
254 int32_t y_stride,
255 int32_t u_stride,
256 int32_t v_stride,
257 uint8_t* y_data,
258 uint8_t* u_data,
259 uint8_t* v_data,
260 const gfx::GpuMemoryBufferHandle& y_handle,
261 const gfx::GpuMemoryBufferHandle& u_handle,
262 const gfx::GpuMemoryBufferHandle& v_handle,
263 base::TimeDelta timestamp) {
264 const StorageType storage = STORAGE_GPU_MEMORY_BUFFERS;
265 if (!IsValidConfig(format, storage, coded_size, visible_rect, natural_size)) {
266 LOG(DFATAL) << __func__ << " Invalid config."
267 << ConfigToString(format, storage, coded_size, visible_rect,
268 natural_size);
269 return nullptr;
270 }
271
272 scoped_refptr<VideoFrame> frame(new VideoFrame(
273 format, storage, coded_size, visible_rect, natural_size, timestamp));
274 frame->strides_[kYPlane] = y_stride;
275 frame->strides_[kUPlane] = u_stride;
276 frame->strides_[kVPlane] = v_stride;
277 frame->data_[kYPlane] = y_data;
278 frame->data_[kUPlane] = u_data;
279 frame->data_[kVPlane] = v_data;
280 frame->gpu_memory_buffer_handles_.push_back(y_handle);
281 frame->gpu_memory_buffer_handles_.push_back(u_handle);
282 frame->gpu_memory_buffer_handles_.push_back(v_handle);
283 return frame;
284 }
285
286 // static
287 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvaData( 246 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvaData(
288 VideoPixelFormat format, 247 VideoPixelFormat format,
289 const gfx::Size& coded_size, 248 const gfx::Size& coded_size,
290 const gfx::Rect& visible_rect, 249 const gfx::Rect& visible_rect,
291 const gfx::Size& natural_size, 250 const gfx::Size& natural_size,
292 int32_t y_stride, 251 int32_t y_stride,
293 int32_t u_stride, 252 int32_t u_stride,
294 int32_t v_stride, 253 int32_t v_stride,
295 int32_t a_stride, 254 int32_t a_stride,
296 uint8_t* y_data, 255 uint8_t* y_data,
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 DCHECK(shared_memory_handle_ != base::SharedMemory::NULLHandle()); 674 DCHECK(shared_memory_handle_ != base::SharedMemory::NULLHandle());
716 return shared_memory_handle_; 675 return shared_memory_handle_;
717 } 676 }
718 677
719 size_t VideoFrame::shared_memory_offset() const { 678 size_t VideoFrame::shared_memory_offset() const {
720 DCHECK_EQ(storage_type_, STORAGE_SHMEM); 679 DCHECK_EQ(storage_type_, STORAGE_SHMEM);
721 DCHECK(shared_memory_handle_ != base::SharedMemory::NULLHandle()); 680 DCHECK(shared_memory_handle_ != base::SharedMemory::NULLHandle());
722 return shared_memory_offset_; 681 return shared_memory_offset_;
723 } 682 }
724 683
725 const std::vector<gfx::GpuMemoryBufferHandle>&
726 VideoFrame::gpu_memory_buffer_handles() const {
727 DCHECK_EQ(storage_type_, STORAGE_GPU_MEMORY_BUFFERS);
728 DCHECK(!gpu_memory_buffer_handles_.empty());
729 return gpu_memory_buffer_handles_;
730 }
731
732 #if defined(OS_LINUX) 684 #if defined(OS_LINUX)
733 int VideoFrame::dmabuf_fd(size_t plane) const { 685 int VideoFrame::dmabuf_fd(size_t plane) const {
734 DCHECK_EQ(storage_type_, STORAGE_DMABUFS); 686 DCHECK_EQ(storage_type_, STORAGE_DMABUFS);
735 DCHECK(IsValidPlane(plane, format_)); 687 DCHECK(IsValidPlane(plane, format_));
736 return dmabuf_fds_[plane].get(); 688 return dmabuf_fds_[plane].get();
737 } 689 }
738 690
739 bool VideoFrame::DuplicateFileDescriptors(const std::vector<int>& in_fds) { 691 bool VideoFrame::DuplicateFileDescriptors(const std::vector<int>& in_fds) {
740 // TODO(mcasas): Support offsets for e.g. multiplanar inside a single |in_fd|. 692 // TODO(mcasas): Support offsets for e.g. multiplanar inside a single |in_fd|.
741 693
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 if (zero_initialize_memory) 1095 if (zero_initialize_memory)
1144 memset(data, 0, data_size); 1096 memset(data, 0, data_size);
1145 1097
1146 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) 1098 for (size_t plane = 0; plane < NumPlanes(format_); ++plane)
1147 data_[plane] = data + offset[plane]; 1099 data_[plane] = data + offset[plane];
1148 1100
1149 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); 1101 AddDestructionObserver(base::Bind(&base::AlignedFree, data));
1150 } 1102 }
1151 1103
1152 } // namespace media 1104 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.h ('k') | media/gpu/ipc/client/gpu_video_encode_accelerator_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698