1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file contains the definition of VASurface class, used for decoding by
6 // VaapiVideoDecodeAccelerator and VaapiH264Decoder.
8 #ifndef CONTENT_COMMON_GPU_MEDIA_VA_SURFACE_H_
9 #define CONTENT_COMMON_GPU_MEDIA_VA_SURFACE_H_
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "content/common/content_export.h"
14 #include "third_party/libva/va/va.h"
15 #include "ui/gfx/geometry/size.h"
19 // A VA-API-specific decode surface used by VaapiH264Decoder to decode into
20 // and use as reference for decoding other surfaces. It is also handed by the
21 // decoder to VaapiVideoDecodeAccelerator when the contents of the surface are
22 // ready and should be displayed. VAVDA converts the surface contents into an
23 // X/Drm Pixmap bound to a texture for display and releases its reference to it.
24 // Decoder releases its references to the surface when it's done decoding and
25 // using it as reference. Note that a surface may still be used for reference
26 // after it's been sent to output and also after it is no longer used by VAVDA.
27 // Thus, the surface can be in use by both VAVDA and the Decoder at the same
28 // time, or by either of them, with the restriction that VAVDA will never get
29 // the surface until the contents are ready, and it is guaranteed that the
30 // contents will not change after that.
31 // When both the decoder and VAVDA release their references to the surface,
32 // it is freed and the release callback is executed to put the surface back
33 // into available surfaces pool, which is managed externally.
35 // VASurfaceID is allocated in VaapiWrapper.
39 // | VASurfaceID is put onto VaapiVideoDecodeAccelerator::available_va_surfaces_
42 // | VASurfaceID is taken off of the VVDA:available_va_surfaces_ when
43 // | | VaapiH264Decoder requests more output surfaces, is wrapped into
44 // | | a VASurface and passed to VaapiH264Decoder.
46 // | VASurface is put onto VaapiH264Decoder::available_va_surfaces_, keeping
47 // | | the only reference to it until it's needed for decoding.
49 // | VaapiH264Decoder starts decoding a new frame. It takes a VASurface off of
50 // | | VHD::available_va_surfaces_ and assigns it to a DecodeSurface,
51 // | | which now keeps the only reference.
53 // | DecodeSurface is used for decoding, putting data into associated VASurface.
55 // | |--------------------------------------------------+
58 // | DecodeSurface is to be output. VaapiH264Decoder uses the
59 // | VaapiH264Decoder passes the associated DecodeSurface and associated
60 // | VASurface to VaapiVideoDecodeAccelerator, VASurface as reference for
61 // | which stores it (taking a ref) on decoding more frames.
62 // | pending_output_cbs_ queue until an output |
63 // | VaapiPicture becomes available. v
64 // | | Once the DecodeSurface is not
65 // | | needed as reference anymore,
66 // | v it is released, releasing the
67 // | A VaapiPicture becomes available after associated VASurface reference.
68 // | the client of VVDA returns |
69 // | a PictureBuffer associated with it. VVDA |
70 // | puts the contents of the VASurface into |
71 // | it and releases the reference to VASurface. |
73 // | '---------------------------------------'
76 // | Neither VVDA nor VHD hold a reference to VASurface. VASurface is released,
77 // | ReleaseCB gets called in its destructor, which puts the associated
78 // | VASurfaceID back onto VVDA::available_va_surfaces_.
80 // '-------------------------------------|
83 // VaapiWrapper frees VASurfaceID.
85 class CONTENT_EXPORT VASurface
: public base::RefCountedThreadSafe
<VASurface
> {
87 // Provided by user, will be called when all references to the surface
89 typedef base::Callback
<void(VASurfaceID
)> ReleaseCB
;
91 VASurface(VASurfaceID va_surface_id
,
92 const gfx::Size
& size
,
93 const ReleaseCB
& release_cb
);
96 return va_surface_id_
;
99 const gfx::Size
& size() const { return size_
; }
102 friend class base::RefCountedThreadSafe
<VASurface
>;
105 const VASurfaceID va_surface_id_
;
107 ReleaseCB release_cb_
;
109 DISALLOW_COPY_AND_ASSIGN(VASurface
);
112 } // namespace content
114 #endif // CONTENT_COMMON_GPU_MEDIA_VA_SURFACE_H_