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

Unified Diff: content/common/gpu/media/vaapi_delegate.h

Issue 14914009: VAVDA: Redesign stage 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/vaapi_delegate.h
diff --git a/content/common/gpu/media/vaapi_delegate.h b/content/common/gpu/media/vaapi_delegate.h
new file mode 100644
index 0000000000000000000000000000000000000000..73811238501c8be5332da084794c3a8535995dcb
--- /dev/null
+++ b/content/common/gpu/media/vaapi_delegate.h
@@ -0,0 +1,216 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// This file contains an implementation of VaapiDelegate, used by
+// VaapiVideoDecodeAccelerator and VaapiH264Decoder to interface
+// with libva (VA-API library for hardware video decode).
+
+#ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_DELEGATE_H_
+#define CONTENT_COMMON_GPU_MEDIA_VAAPI_DELEGATE_H_
+
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "base/synchronization/lock.h"
+#include "media/base/video_decoder_config.h"
+#include "third_party/libva/va/va.h"
+#include "third_party/libva/va/va_x11.h"
+#include "ui/gfx/size.h"
+
+namespace content {
+
+// This class handles VA-API calls and ensures proper locking of VA-API calls
+// to libva, the userspace shim to the HW decoder driver. libva is not
+// thread-safe, so we have to perform locking ourselves. This class is fully
+// synchronous and its methods can be called from any thread and may wait on
+// the va_lock_ while other, concurrent calls run.
+//
+// This class is responsible for managing VAAPI connection, contexts and state.
+// It is also responsible for managing and freeing VABuffers (not VASurfaces),
+// which are used to queue decode parameters and slice data to the HW decoder,
+// as well as underlying memory for VASurfaces themselves.
+class VaapiDelegate : public base::RefCountedThreadSafe<VaapiDelegate> {
Ami GONE FROM CHROMIUM 2013/05/22 23:59:47 please rename to wrapper. Delegate means a differ
Pawel Osciak 2013/05/24 01:46:39 Done. Lunch topic next time I visit KIR? ;)
+ public:
+ // |report_error_to_uma_cb| will be used to report errors for UMA purposes,
Ami GONE FROM CHROMIUM 2013/05/22 23:59:47 nit: with the gloriously informative new name, thi
Pawel Osciak 2013/05/24 01:46:39 Done.
+ // independently from reporting errors to clients.
+ static scoped_refptr<VaapiDelegate> Create(
+ media::VideoCodecProfile profile,
+ Display* x_display,
+ const base::Closure& report_error_to_uma_cb);
+
+ // Create |num_surfaces| backing surfaces in driver for VASurfaces, each
+ // of size |size|. Returns true when successful, with the created IDs in
+ // |va_surfaces| to be managed and later wrapped in VASurfaces.
+ // The client must DestroySurfaces() each time before calling this method
+ // again to free the allocated surfaces first, but is not required to do so
+ // at destruction time, as this will be done automatically from
+ // the destructor.
+ bool CreateSurfaces(gfx::Size size,
+ size_t num_surfaces,
+ std::vector<VASurfaceID>* va_surfaces);
+
+ // Free all memory allocated in CreateSurfaces.
+ void DestroySurfaces();
+
+ // Submit parameters or slice data of |va_buffer_type|, copying them from
+ // |buffer| of size |size|, into HW decoder. The data in |buffer| is no
+ // longer needed and can be freed after this method returns.
+ // Data submitted via this method awaits in the HW decoder until
+ // DecodeAndDestroyPendingBuffers is called to execute or
+ // DestroyPendingBuffers is used to cancel a pending decode.
+ bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer);
+
+ // Cancel and destroy all buffers queued to the HW decoder via SubmitBuffer.
+ // Useful when a pending decode is to be cancelled (on reset or error).
+ void DestroyPendingBuffers();
+
+ // Execute decode in hardware and destroy pending buffers.
Ami GONE FROM CHROMIUM 2013/05/22 23:59:47 what does a false return value mean? more data ne
Pawel Osciak 2013/05/24 01:46:39 Done.
+ bool DecodeAndDestroyPendingBuffers(VASurfaceID va_surface_id);
+
+
+ // Put data from |va_surface_id| into |x_pixmap| of size |size|,
+ // converting/scaling to it.
+ bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
+ Pixmap x_pixmap,
+ gfx::Size dest_size);
Ami GONE FROM CHROMIUM 2013/05/22 23:59:47 Is it ever the case that the pixmap & the surface
Pawel Osciak 2013/05/24 01:46:39 Not for us, but it's allowed, it'd be scaled then.
+
+ // Do any necessary initialization before the sandbox is enabled.
+ static void PreSandboxInitialization();
+
+ private:
+ friend class base::RefCountedThreadSafe<VaapiDelegate>;
+ VaapiDelegate();
+ ~VaapiDelegate();
+
+ bool Initialize(media::VideoCodecProfile profile,
+ Display* x_display,
+ const base::Closure& report_error__to_uma_cb);
+ void Deinitialize();
+
+ bool SubmitDecode(VASurfaceID va_surface_id);
Ami GONE FROM CHROMIUM 2013/05/22 23:59:47 ditto q about meaning of return false.
Pawel Osciak 2013/05/24 01:46:39 Done.
+
+ // Lazily initialize static data after sandbox is enabled. Return false on
+ // init failure.
+ static bool PostSandboxInitialization();
+
+ // Libva is not thread safe, so we have to do locking for it ourselves.
+ // This lock is to be taken for the duration of all VA-API calls and for
+ // the entire decode execution sequence in DecodeAndDestroyPendingBuffers().
+ base::Lock va_lock_;
+
+ // Allocated ids for VASurfaces.
+ std::vector<VASurfaceID> va_surface_ids_;
+
+ // VA handles.
+ // Both valid after successful Initialize() and until Deinitialize().
+ VADisplay va_display_;
+ VAConfigID va_config_id_;
+ // Created for the current set of va_surface_ids_ in CreateSurfaces() and
+ // valid until DestroySurfaces().
+ VAContextID va_context_id_;
+
+ // Data queued up for HW decoder, to be committed on next HW decode.
+ std::vector<VABufferID> pending_slice_bufs_;
+ std::vector<VABufferID> pending_va_bufs_;
+
+ // Called to report decoding errors to UMA. Errors to clients are reported via
+ // return values from public methods.
+ base::Closure report_error_to_uma_cb_;
+
+ // Has static initialization of pre-sandbox components completed successfully?
+ static bool pre_sandbox_init_done_;
+
+ DISALLOW_COPY_AND_ASSIGN(VaapiDelegate);
+};
+
Ami GONE FROM CHROMIUM 2013/05/22 23:59:47 nit: add an extra \n I think.
Pawel Osciak 2013/05/24 01:46:39 Moved out.
+// A VA-API-specific decode surface used by VaapiH264Decoder to decode into
+// and use as reference for decoding other surfaces. It is also handed by the
+// decoder to VaapiVideoDecodeAccelerator when the contents of the surface are
+// ready and should be displayed. VAVDA converts the surface contents into an
+// X Pixmap bound to a texture for display and releases its reference to it.
+// Decoder releases its references to the surface when it's done decoding and
+// using it as reference. Note that a surface may still be used for reference
+// after it's been sent to output and also after it is no longer used by VAVDA.
+// Thus, the surface can be in use by both VAVDA and the Decoder at the same
+// time, or by either of them, with the restriction that VAVDA will never get
+// the surface until the contents are ready, and it is guaranteed that the
+// contents will not change after that.
+// When both the decoder and VAVDA release their references to the surface,
+// it is freed and the release callback is executed to put the surface back
+// into available surfaces pool, which is managed externally.
+//
+// VASurfaceID is allocated in VaapiDelegate.
+// |
+// +----->|
+// | v
+// | VASurfaceID is put onto VaapiVideoDecodeAccelerator::available_va_surfaces_
+// | | list.
+// | v
+// | VASurfaceID is taken off of the VVDA:available_va_surfaces_ when
+// | | VaapiH264Decoder requests more output surfaces, is wrapped into
+// | | a VASurface and passed to VaapiH264Decoder.
+// | v
+// | VASurface is put onto VaapiH264Decoder::available_va_surfaces_, keeping
+// | | the only reference to it until it's needed for decoding.
+// | v
+// | VaapiH264Decoder starts decoding a new frame. It takes a VASurface off of
+// | | VHD::available_va_surfaces_ and assigns it to a DecodeSurface,
+// | | which now keeps the only reference.
+// | v
+// | DecodeSurface is used for decoding, putting data into associated VASurface.
+// | |
+// | |--------------------------------------------------+
+// | | |
+// | v v
+// | DecodeSurface is to be output. VaapiH264Decoder uses the
+// | VaapiH264Decoder passes the associated DecodeSurface and associated
+// | VASurface to VaapiVideoDecodeAccelerator, VASurface as reference for
+// | which stores it (taking a ref) on decoding more frames.
+// | pending_output_cbs_ queue until an output |
+// | TFPPicture becomes available. v
+// | | Once the DecodeSurface is not
+// | | needed as reference anymore,
+// | v it is released, releasing the
+// | A TFPPicture becomes available after associated VASurface reference.
+// | the client of VVDA returns |
+// | a PictureBuffer associated with it. VVDA |
+// | puts the contents of the VASurface into |
+// | it and releases the reference to VASurface. |
+// | | |
+// | '---------------------------------------'
+// | |
+// | v
+// | Neither VVDA nor VHD hold a reference to VASurface. VASurface is released,
+// | ReleaseCB gets called in its destructor, which puts the associated
+// | VASurfaceID back onto VVDA::available_va_surfaces_.
+// | |
+// '-------------------------------------|
+// |
+// v
+// VaapiDelegate frees VASurfaceID.
+//
+class VASurface : public base::RefCountedThreadSafe<VASurface> {
+ public:
+ // Provided by user, will be called when all references to the surface
+ // are released.
+ typedef base::Callback<void(VASurfaceID)> ReleaseCB;
+
+ VASurface(VASurfaceID va_surface_id, const ReleaseCB& release_cb);
+
+ VASurfaceID id() {
+ return va_surface_id_;
+ }
+
+ private:
+ friend class base::RefCountedThreadSafe<VASurface>;
+ ~VASurface();
+
+ const VASurfaceID va_surface_id_;
+ ReleaseCB release_cb_;
+
+ DISALLOW_COPY_AND_ASSIGN(VASurface);
+};
+
+} // namespace content
+
+#endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_DELEGATE_H_

Powered by Google App Engine
This is Rietveld 408576698