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

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..e7a2ed1c520d78c97998403e6eabaa2c31a0661a
--- /dev/null
+++ b/content/common/gpu/media/vaapi_delegate.h
@@ -0,0 +1,156 @@
+// 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"
+
+namespace content {
+
+// A VA-API-specific decode surface used by VaapiH264Decoder to decode into
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Since this class isn't used in this .h (or .cc fil
Pawel Osciak 2013/05/21 22:32:35 Didn't want to create a separate header for it, I'
Ami GONE FROM CHROMIUM 2013/05/22 23:59:47 I think this is a bad tradeoff. It's a separate t
Pawel Osciak 2013/05/24 01:46:39 Done.
+// 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.
+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();
+
+ VASurfaceID va_surface_id_;
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 const, if you like
Pawel Osciak 2013/05/21 22:32:35 Done.
+ ReleaseCB release_cb_;
+
+ DISALLOW_COPY_AND_ASSIGN(VASurface);
+};
+
+// 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.
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Does this mean the public methods of this class ma
Pawel Osciak 2013/05/21 22:32:35 It's safe to call from any thread, things will not
+//
+// 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.
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Does this translate to "none of the other files in
Pawel Osciak 2013/05/21 22:32:35 Correct.
+class VaapiDelegate : public base::RefCountedThreadSafe<VaapiDelegate> {
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Is this actually a VaapiWrapper?
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Why refcount? (in particular, can VAVDA hold a sco
Pawel Osciak 2013/05/21 22:32:35 Currently yes, as the decoder doesn't do anything
Pawel Osciak 2013/05/21 22:32:35 For me delegate and wrapper are almost synonymous
Ami GONE FROM CHROMIUM 2013/05/22 23:59:47 Refcounting abdicates responsibility for ownership
Pawel Osciak 2013/05/24 01:46:39 Done.
+ public:
+ // |report_error_cb| will be used to report errors for UMA purposes, not
+ // to report errors to clients.
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Why not rename it to something clearer, then? re
Pawel Osciak 2013/05/21 22:32:35 Done.
+ static scoped_refptr<VaapiDelegate> Create(
+ media::VideoCodecProfile profile,
+ Display* x_display,
+ const base::Closure& report_error_cb);
+
+ // Create |num_surfaces| backing surfaces in driver for VASurfaces, each
+ // of size |width|x|height|, and return their IDs to be managed and later
+ // wrapped in VASurfaces.
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Returns success.
Pawel Osciak 2013/05/21 22:32:35 Done.
+ bool CreateSurfaces(int width, int height,
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 here and elsewhere, better to use a gfx::Size than
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 The impl of this assumes that this method is calle
Pawel Osciak 2013/05/21 22:32:35 Done, here and in other places.
Pawel Osciak 2013/05/21 22:32:35 Not exactly. CreateSurfaces() -> DestroySurfaces()
+ size_t num_surfaces,
+ std::vector<VASurfaceID>& va_surfaces);
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Non non-const references. Here and elsewhere, wh
Pawel Osciak 2013/05/21 22:32:35 Done.
+
+ // Free all memory allocated in CreateSurfaces.
+ void DestroySurfaces();
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Should be private.
Pawel Osciak 2013/05/21 22:32:35 See above (l.78).
+
+ // 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.
+ bool DecodeAndDestroyPendingBuffers(VASurfaceID va_surface_id);
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Why is "Destroy" part of the name of this function
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 What does the bool return value mean? I can imagin
Pawel Osciak 2013/05/21 22:32:35 I felt documentation for SubmitBuffer explained it
Pawel Osciak 2013/05/21 22:32:35 Decode() is for exactly one picture in vaapi. So t
+
+
+ // Put data from |va_surface_id| into x_pixmap of size |width|x|height|,
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 |x_pixmap|
Pawel Osciak 2013/05/21 22:32:35 Done.
+ // converting/scaling to appropriate size.
+ bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Does this require making a context current (or som
Pawel Osciak 2013/05/21 22:32:35 No, thankfully. It's not a GL call.
+ Pixmap x_pixmap,
+ int width, int height);
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 dest_width & dest_height ?
Pawel Osciak 2013/05/21 22:32:35 dest_size :)
+
+ // 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,
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Should be private, and can be inlined into Create(
Pawel Osciak 2013/05/21 22:32:35 It is private :) I didn't want to inline, because
+ Display* x_display,
+ const base::Closure& report_error_cb);
+ void Deinitialize();
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 inline into dtor, since it's the only callsite and
Pawel Osciak 2013/05/21 22:32:35 I'd prefer to keep it this way, makes the destruct
+
+ bool SubmitDecode(VASurfaceID va_surface_id);
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 doco methods whose purpose is unclear. For exampl
Pawel Osciak 2013/05/21 22:32:35 To be honest I don't feel that way: SubmitBuffer(
+
+ // 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
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 I think the only API that makes sense is that ever
Pawel Osciak 2013/05/21 22:32:35 Done.
+ // the entire decode execution sequence in DecodeAndDestroyPendingBuffers().
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 ...and yet, it is not (see comment there).
Pawel Osciak 2013/05/21 22:32:35 See comment there please. Destroy() doesn't have t
+ base::Lock va_lock_;
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 naming this va_lock_ implies it should be held onl
Pawel Osciak 2013/05/21 22:32:35 This is a lock around each libva call or calls tha
+
+ // Allocated backing memory ids for VASurfaces.
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 This comment emphasizes "allocated" in a surprisin
Pawel Osciak 2013/05/21 22:32:35 Well, this was also kind-of documenting what the i
+ scoped_ptr<VASurfaceID[]> va_surface_ids_;
+ size_t num_va_surfaces_;
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 why not std::vector<VASurfaceID> instead and avoid
Pawel Osciak 2013/05/21 22:32:35 Yeah, I know this full well, and I even thought ab
+
+ // VA handles.
+ VADisplay va_display_;
+ VAConfigID va_config_id_;
+ VAContextID va_context_id_;
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Would be useful to annotate these with when in the
Pawel Osciak 2013/05/21 22:32:35 Done.
+
+ // 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_;
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 Do these really need to be separate? (AFAICT they'
Pawel Osciak 2013/05/21 22:32:35 All the code that used VAAPI that I've seen, inclu
Ami GONE FROM CHROMIUM 2013/05/22 23:59:47 You just gave a great definition of what it means
Pawel Osciak 2013/05/24 01:46:39 Not exactly. I'm saying that even if it was ok to
+
+ // Called to report decoding error to UMA, not used to indicate errors
+ // to clients.
+ base::Closure report_error_cb_;
+
+ // Lazily initialize static data after sandbox is enabled. Return false on
+ // init failure.
+ static bool PostSandboxInitialization();
Ami GONE FROM CHROMIUM 2013/05/17 23:19:15 methods go above members
Pawel Osciak 2013/05/21 22:32:35 Done.
+
+ // Has static initialization of pre-sandbox components completed successfully?
+ static bool pre_sandbox_init_done_;
+
+ DISALLOW_COPY_AND_ASSIGN(VaapiDelegate);
+};
+
+} // namespace content
+
+#endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_DELEGATE_H_

Powered by Google App Engine
This is Rietveld 408576698