Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / media / base / video_frame.h
index aa9c078..a3f296d 100644 (file)
@@ -5,9 +5,12 @@
 #ifndef MEDIA_BASE_VIDEO_FRAME_H_
 #define MEDIA_BASE_VIDEO_FRAME_H_
 
+#include <vector>
+
 #include "base/callback.h"
 #include "base/md5.h"
 #include "base/memory/shared_memory.h"
+#include "base/synchronization/lock.h"
 #include "media/base/buffers.h"
 #include "ui/gfx/rect.h"
 #include "ui/gfx/size.h"
@@ -33,6 +36,7 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> {
 
     kYPlane = 0,
     kUPlane = 1,
+    kUVPlane = kUPlane,
     kVPlane = 2,
     kAPlane = 3,
   };
@@ -52,7 +56,8 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> {
 #endif  // defined(VIDEO_HOLE)
     NATIVE_TEXTURE = 6,  // Native texture.  Pixel-format agnostic.
     YV12J = 7,  // JPEG color range version of YV12
-    FORMAT_MAX = YV12J,  // Must always be equal to largest entry logged.
+    NV12 = 8,  // 12bpp 1x1 Y plane followed by an interleaved 2x2 UV plane.
+    FORMAT_MAX = NV12,  // Must always be equal to largest entry logged.
   };
 
   // Returns the name of a Format as a string.
@@ -80,7 +85,7 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> {
 
   // CB to be called on the mailbox backing this frame when the frame is
   // destroyed.
-  typedef base::Callback<void(scoped_ptr<gpu::MailboxHolder>)> ReleaseMailboxCB;
+  typedef base::Callback<void(const std::vector<uint32>&)> ReleaseMailboxCB;
 
   // Wraps a native texture of the given parameters with a VideoFrame.  The
   // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|,
@@ -119,6 +124,27 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> {
       base::TimeDelta timestamp,
       const base::Closure& no_longer_needed_cb);
 
+#if defined(OS_POSIX)
+  // Wraps provided dmabufs
+  // (https://www.kernel.org/doc/Documentation/dma-buf-sharing.txt) with a
+  // VideoFrame. The dmabuf fds are dup()ed on creation, so that the VideoFrame
+  // retains a reference to them, and are automatically close()d on destruction,
+  // dropping the reference. The caller may safely close() its reference after
+  // calling WrapExternalDmabufs().
+  // The image data is only accessible via dmabuf fds, which are usually passed
+  // directly to a hardware device and/or to another process, or can also be
+  // mapped via mmap() for CPU access.
+  // When the frame is destroyed, |no_longer_needed_cb.Run()| will be called.
+  static scoped_refptr<VideoFrame> WrapExternalDmabufs(
+      Format format,
+      const gfx::Size& coded_size,
+      const gfx::Rect& visible_rect,
+      const gfx::Size& natural_size,
+      const std::vector<int> dmabuf_fds,
+      base::TimeDelta timestamp,
+      const base::Closure& no_longer_needed_cb);
+#endif
+
   // Wraps external YUV data of the given parameters with a VideoFrame.
   // The returned VideoFrame does not own the data passed in. When the frame
   // is destroyed |no_longer_needed_cb.Run()| will be called.
@@ -182,6 +208,9 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> {
                                     size_t plane,
                                     const gfx::Size& coded_size);
 
+  // Returns horizontal bits per pixel for given |plane| and |format|.
+  static int PlaneHorizontalBitsPerPixel(Format format, size_t plane);
+
   Format format() const { return format_; }
 
   const gfx::Size& coded_size() const { return coded_size_; }
@@ -204,21 +233,33 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> {
   // Returns the mailbox holder of the native texture wrapped by this frame.
   // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the
   // mailbox, the caller must wait for the included sync point.
-  gpu::MailboxHolder* mailbox_holder() const;
+  const gpu::MailboxHolder* mailbox_holder() const;
 
   // Returns the shared-memory handle, if present
   base::SharedMemoryHandle shared_memory_handle() const;
 
+#if defined(OS_POSIX)
+  // Returns backing dmabuf file descriptor for given |plane|, if present.
+  int dmabuf_fd(size_t plane) const;
+#endif
+
   // Returns true if this VideoFrame represents the end of the stream.
   bool end_of_stream() const { return end_of_stream_; }
 
-  base::TimeDelta GetTimestamp() const {
+  base::TimeDelta timestamp() const {
     return timestamp_;
   }
-  void SetTimestamp(const base::TimeDelta& timestamp) {
+  void set_timestamp(const base::TimeDelta& timestamp) {
     timestamp_ = timestamp;
   }
 
+  // Append |sync_point| into |release_sync_points_| which will be passed to
+  // the video decoder when |mailbox_holder_release_cb_| is called so that
+  // the video decoder waits for the sync points before reusing the mailbox.
+  // Multiple clients can append multiple sync points on one frame.
+  // This method is thread safe. Both blink and compositor threads can call it.
+  void AppendReleaseSyncPoint(uint32 sync_point);
+
   // Used to keep a running hash of seen frames.  Expects an initialized MD5
   // context.  Calls MD5Update with the context and the contents of the frame.
   void HashFrameForTesting(base::MD5Context* context);
@@ -230,6 +271,7 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> {
              const gfx::Size& coded_size,
              const gfx::Rect& visible_rect,
              const gfx::Size& natural_size,
+             scoped_ptr<gpu::MailboxHolder> mailbox_holder,
              base::TimeDelta timestamp,
              bool end_of_stream);
   virtual ~VideoFrame();
@@ -267,17 +309,26 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> {
   uint8* data_[kMaxPlanes];
 
   // Native texture mailbox, if this is a NATIVE_TEXTURE frame.
-  scoped_ptr<gpu::MailboxHolder> mailbox_holder_;
+  const scoped_ptr<gpu::MailboxHolder> mailbox_holder_;
   ReleaseMailboxCB mailbox_holder_release_cb_;
   ReadPixelsCB read_pixels_cb_;
 
   // Shared memory handle, if this frame was allocated from shared memory.
   base::SharedMemoryHandle shared_memory_handle_;
 
+#if defined(OS_POSIX)
+  // Dmabufs for each plane, if this frame is wrapping memory
+  // acquired via dmabuf.
+  base::ScopedFD dmabuf_fds_[kMaxPlanes];
+#endif
+
   base::Closure no_longer_needed_cb_;
 
   base::TimeDelta timestamp_;
 
+  base::Lock release_sync_point_lock_;
+  std::vector<uint32> release_sync_points_;
+
   const bool end_of_stream_;
 
   DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame);