liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 1 | // 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" |
liberato | c58e8f82 | 2017-03-10 19:45:48 | [diff] [blame] | 9 | #include "media/base/android/android_overlay.h" |
liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 10 | #include "media/base/surface_manager.h" |
liberato | 9432ee0 | 2017-05-03 07:18:11 | [diff] [blame] | 11 | #include "media/gpu/media_gpu_export.h" |
liberato | 95c9282 | 2017-05-17 22:36:21 | [diff] [blame^] | 12 | #include "media/gpu/surface_texture_gl_owner.h" |
liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 13 | #include "ui/gl/android/scoped_java_surface.h" |
liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 14 | |
| 15 | namespace 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. |
liberato | 9432ee0 | 2017-05-03 07:18:11 | [diff] [blame] | 28 | struct MEDIA_GPU_EXPORT AVDASurfaceBundle |
| 29 | : public base::RefCountedThreadSafe<AVDASurfaceBundle> { |
liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 30 | public: |
liberato | 9432ee0 | 2017-05-03 07:18:11 | [diff] [blame] | 31 | // |overlay| is the overlay that we'll use, or nullptr for SurfaceTexture. |
| 32 | explicit AVDASurfaceBundle(std::unique_ptr<AndroidOverlay> overlay); |
liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 33 | |
liberato | c58e8f82 | 2017-03-10 19:45:48 | [diff] [blame] | 34 | // 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 | |
liberato | 9432ee0 | 2017-05-03 07:18:11 | [diff] [blame] | 45 | // If |overlay| is non-null, then |overlay| owns j_surface(). |
liberato | c58e8f82 | 2017-03-10 19:45:48 | [diff] [blame] | 46 | std::unique_ptr<AndroidOverlay> overlay; |
liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 47 | |
liberato | 9432ee0 | 2017-05-03 07:18:11 | [diff] [blame] | 48 | // The SurfaceTexture attached to |surface()|, or nullptr if j_surface() is |
liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 49 | // SurfaceView backed. |
liberato | 95c9282 | 2017-05-17 22:36:21 | [diff] [blame^] | 50 | scoped_refptr<SurfaceTextureGLOwner> surface_texture; |
liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 51 | |
liberato | c58e8f82 | 2017-03-10 19:45:48 | [diff] [blame] | 52 | // If |surface_texture| is not null, then this is the surface for it. |
liberato | c58e8f82 | 2017-03-10 19:45:48 | [diff] [blame] | 53 | gl::ScopedJavaSurface surface_texture_surface; |
| 54 | |
liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 55 | 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_ |