blob: 10760d223d8c7d244b2dc19f5cb2fcc341f3a1e2 [file] [log] [blame]
liberato5e0962e2017-03-08 19:21:361// Copyright 2017 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.
4
5#ifndef MEDIA_GPU_AVDA_SURFACE_BUNDLE_H_
6#define MEDIA_GPU_AVDA_SURFACE_BUNDLE_H_
7
8#include "base/memory/ref_counted.h"
liberatoc58e8f822017-03-10 19:45:489#include "media/base/android/android_overlay.h"
liberato5e0962e2017-03-08 19:21:3610#include "media/base/surface_manager.h"
liberato9432ee02017-05-03 07:18:1111#include "media/gpu/media_gpu_export.h"
liberato95c92822017-05-17 22:36:2112#include "media/gpu/surface_texture_gl_owner.h"
liberato5e0962e2017-03-08 19:21:3613#include "ui/gl/android/scoped_java_surface.h"
liberato5e0962e2017-03-08 19:21:3614
15namespace media {
16
17// AVDASurfaceBundle is a collection of everything that the producer-side of
18// the output surface needs. In other words, it's the surface, and any
19// SurfaceTexture that backs it. The SurfaceTexture isn't needed directly by
20// the producer, but destroying it causes the surface not to work.
21//
22// The idea is that a reference to this should be kept with the codec, even if
23// the codec is sent to another thread. This will prevent the output surface
24// from being destroyed while the codec depends on it.
25// While you may send a reference to this to other threads, be sure that it
26// doesn't drop the reference there without creating another one. This has to
27// be destroyed on the gpu main thread.
liberato9432ee02017-05-03 07:18:1128struct MEDIA_GPU_EXPORT AVDASurfaceBundle
29 : public base::RefCountedThreadSafe<AVDASurfaceBundle> {
liberato5e0962e2017-03-08 19:21:3630 public:
liberato9432ee02017-05-03 07:18:1131 // |overlay| is the overlay that we'll use, or nullptr for SurfaceTexture.
32 explicit AVDASurfaceBundle(std::unique_ptr<AndroidOverlay> overlay);
liberato5e0962e2017-03-08 19:21:3633
liberatoc58e8f822017-03-10 19:45:4834 // The surface that MediaCodec is configured to output to. This can be either
35 // a SurfaceTexture or other Surface provider.
36 // TODO(liberato): it would be nice if we had an abstraction that included
37 // SurfaceTexture and Overlay, but we don't right now.
38 const base::android::JavaRef<jobject>& j_surface() const {
39 if (overlay)
40 return overlay->GetJavaSurface();
41 else
42 return surface_texture_surface.j_surface();
43 }
44
liberato9432ee02017-05-03 07:18:1145 // If |overlay| is non-null, then |overlay| owns j_surface().
liberatoc58e8f822017-03-10 19:45:4846 std::unique_ptr<AndroidOverlay> overlay;
liberato5e0962e2017-03-08 19:21:3647
liberato9432ee02017-05-03 07:18:1148 // The SurfaceTexture attached to |surface()|, or nullptr if j_surface() is
liberato5e0962e2017-03-08 19:21:3649 // SurfaceView backed.
liberato95c92822017-05-17 22:36:2150 scoped_refptr<SurfaceTextureGLOwner> surface_texture;
liberato5e0962e2017-03-08 19:21:3651
liberatoc58e8f822017-03-10 19:45:4852 // If |surface_texture| is not null, then this is the surface for it.
liberatoc58e8f822017-03-10 19:45:4853 gl::ScopedJavaSurface surface_texture_surface;
54
liberato5e0962e2017-03-08 19:21:3655 private:
56 ~AVDASurfaceBundle();
57 friend class base::RefCountedThreadSafe<AVDASurfaceBundle>;
58
59 DISALLOW_COPY_AND_ASSIGN(AVDASurfaceBundle);
60};
61
62} // namespace media
63
64#endif // MEDIA_GPU_AVDA_SURFACE_BUNDLE_H_