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

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

Issue 850993002: gpu video: optimize HW video to SW canvas and implement it for WebRTC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
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 #ifndef MEDIA_BASE_VIDEO_FRAME_H_ 5 #ifndef MEDIA_BASE_VIDEO_FRAME_H_
6 #define MEDIA_BASE_VIDEO_FRAME_H_ 6 #define MEDIA_BASE_VIDEO_FRAME_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/md5.h" 11 #include "base/md5.h"
12 #include "base/memory/shared_memory.h" 12 #include "base/memory/shared_memory.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "media/base/buffers.h" 14 #include "media/base/buffers.h"
15 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/size.h" 16 #include "ui/gfx/geometry/size.h"
17 17
18 #if defined(OS_MACOSX) 18 #if defined(OS_MACOSX)
19 #include <CoreVideo/CVPixelBuffer.h> 19 #include <CoreVideo/CVPixelBuffer.h>
20 #include "base/mac/scoped_cftyperef.h" 20 #include "base/mac/scoped_cftyperef.h"
21 #endif 21 #endif
22 22
23 class SkBitmap;
24
25 namespace gpu { 23 namespace gpu {
26 struct MailboxHolder; 24 struct MailboxHolder;
27 } // namespace gpu 25 } // namespace gpu
28 26
29 namespace media { 27 namespace media {
30 28
31 class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { 29 class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> {
32 public: 30 public:
33 enum { 31 enum {
34 kFrameSizeAlignment = 16, 32 kFrameSizeAlignment = 16,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // can be used to DCHECK() plane parameters. 83 // can be used to DCHECK() plane parameters.
86 static bool IsValidPlane(size_t plane, VideoFrame::Format format); 84 static bool IsValidPlane(size_t plane, VideoFrame::Format format);
87 85
88 // Call prior to CreateFrame to ensure validity of frame configuration. Called 86 // Call prior to CreateFrame to ensure validity of frame configuration. Called
89 // automatically by VideoDecoderConfig::IsValidConfig(). 87 // automatically by VideoDecoderConfig::IsValidConfig().
90 // TODO(scherkus): VideoDecoderConfig shouldn't call this method 88 // TODO(scherkus): VideoDecoderConfig shouldn't call this method
91 static bool IsValidConfig(Format format, const gfx::Size& coded_size, 89 static bool IsValidConfig(Format format, const gfx::Size& coded_size,
92 const gfx::Rect& visible_rect, 90 const gfx::Rect& visible_rect,
93 const gfx::Size& natural_size); 91 const gfx::Size& natural_size);
94 92
95 // CB to write pixels from the texture backing this frame into the
96 // |const SkBitmap&| parameter.
97 typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB;
98
99 // CB to be called on the mailbox backing this frame when the frame is 93 // CB to be called on the mailbox backing this frame when the frame is
100 // destroyed. 94 // destroyed.
101 typedef base::Callback<void(uint32)> ReleaseMailboxCB; 95 typedef base::Callback<void(uint32)> ReleaseMailboxCB;
102 96
103 // Wraps a native texture of the given parameters with a VideoFrame. The 97 // Wraps a native texture of the given parameters with a VideoFrame. The
104 // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|, 98 // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|,
105 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the 99 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the
106 // argument when the VideoFrame is to be destroyed. 100 // argument when the VideoFrame is to be destroyed.
107 // |read_pixels_cb| may be used to do (slow!) readbacks from the 101 // |read_pixels_cb| may be used to do (slow!) readbacks from the
108 // texture to main memory. 102 // texture to main memory.
109 static scoped_refptr<VideoFrame> WrapNativeTexture( 103 static scoped_refptr<VideoFrame> WrapNativeTexture(
110 scoped_ptr<gpu::MailboxHolder> mailbox_holder, 104 scoped_ptr<gpu::MailboxHolder> mailbox_holder,
111 const ReleaseMailboxCB& mailbox_holder_release_cb, 105 const ReleaseMailboxCB& mailbox_holder_release_cb,
112 const gfx::Size& coded_size, 106 const gfx::Size& coded_size,
113 const gfx::Rect& visible_rect, 107 const gfx::Rect& visible_rect,
114 const gfx::Size& natural_size, 108 const gfx::Size& natural_size,
115 base::TimeDelta timestamp, 109 base::TimeDelta timestamp);
116 const ReadPixelsCB& read_pixels_cb);
117
118 #if !defined(MEDIA_FOR_CAST_IOS)
119 // Read pixels from the native texture backing |*this| and write
120 // them to |pixels| as BGRA. |pixels| must point to a buffer at
121 // least as large as 4 * visible_rect().size().GetArea().
122 void ReadPixelsFromNativeTexture(const SkBitmap& pixels);
123 #endif
124 110
125 // Wraps packed image data residing in a memory buffer with a VideoFrame. 111 // Wraps packed image data residing in a memory buffer with a VideoFrame.
126 // The image data resides in |data| and is assumed to be packed tightly in a 112 // The image data resides in |data| and is assumed to be packed tightly in a
127 // buffer of logical dimensions |coded_size| with the appropriate bit depth 113 // buffer of logical dimensions |coded_size| with the appropriate bit depth
128 // and plane count as given by |format|. The shared memory handle of the 114 // and plane count as given by |format|. The shared memory handle of the
129 // backing allocation, if present, can be passed in with |handle|. When the 115 // backing allocation, if present, can be passed in with |handle|. When the
130 // frame is destroyed, |no_longer_needed_cb.Run()| will be called. 116 // frame is destroyed, |no_longer_needed_cb.Run()| will be called.
131 // Returns NULL on failure. 117 // Returns NULL on failure.
132 static scoped_refptr<VideoFrame> WrapExternalPackedMemory( 118 static scoped_refptr<VideoFrame> WrapExternalPackedMemory(
133 Format format, 119 Format format,
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 // of the surface divided by the horizontal sampling period. Note that 363 // of the surface divided by the horizontal sampling period. Note that
378 // strides can be negative. 364 // strides can be negative.
379 int32 strides_[kMaxPlanes]; 365 int32 strides_[kMaxPlanes];
380 366
381 // Array of data pointers to each plane. 367 // Array of data pointers to each plane.
382 uint8* data_[kMaxPlanes]; 368 uint8* data_[kMaxPlanes];
383 369
384 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. 370 // Native texture mailbox, if this is a NATIVE_TEXTURE frame.
385 const scoped_ptr<gpu::MailboxHolder> mailbox_holder_; 371 const scoped_ptr<gpu::MailboxHolder> mailbox_holder_;
386 ReleaseMailboxCB mailbox_holder_release_cb_; 372 ReleaseMailboxCB mailbox_holder_release_cb_;
387 ReadPixelsCB read_pixels_cb_;
388 373
389 // Shared memory handle, if this frame was allocated from shared memory. 374 // Shared memory handle, if this frame was allocated from shared memory.
390 base::SharedMemoryHandle shared_memory_handle_; 375 base::SharedMemoryHandle shared_memory_handle_;
391 376
392 #if defined(OS_POSIX) 377 #if defined(OS_POSIX)
393 // Dmabufs for each plane, if this frame is wrapping memory 378 // Dmabufs for each plane, if this frame is wrapping memory
394 // acquired via dmabuf. 379 // acquired via dmabuf.
395 base::ScopedFD dmabuf_fds_[kMaxPlanes]; 380 base::ScopedFD dmabuf_fds_[kMaxPlanes];
396 #endif 381 #endif
397 382
(...skipping 10 matching lines...) Expand all
408 uint32 release_sync_point_; 393 uint32 release_sync_point_;
409 394
410 const bool end_of_stream_; 395 const bool end_of_stream_;
411 396
412 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); 397 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame);
413 }; 398 };
414 399
415 } // namespace media 400 } // namespace media
416 401
417 #endif // MEDIA_BASE_VIDEO_FRAME_H_ 402 #endif // MEDIA_BASE_VIDEO_FRAME_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698