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" |
| 11 | #include "ui/gl/android/scoped_java_surface.h" |
| 12 | #include "ui/gl/android/surface_texture.h" |
| 13 | |
| 14 | namespace media { |
| 15 | |
| 16 | // AVDASurfaceBundle is a collection of everything that the producer-side of |
| 17 | // the output surface needs. In other words, it's the surface, and any |
| 18 | // SurfaceTexture that backs it. The SurfaceTexture isn't needed directly by |
| 19 | // the producer, but destroying it causes the surface not to work. |
| 20 | // |
| 21 | // The idea is that a reference to this should be kept with the codec, even if |
| 22 | // the codec is sent to another thread. This will prevent the output surface |
| 23 | // from being destroyed while the codec depends on it. |
| 24 | // While you may send a reference to this to other threads, be sure that it |
| 25 | // doesn't drop the reference there without creating another one. This has to |
| 26 | // be destroyed on the gpu main thread. |
| 27 | class AVDASurfaceBundle : public base::RefCountedThreadSafe<AVDASurfaceBundle> { |
| 28 | public: |
| 29 | explicit AVDASurfaceBundle(int surface_id); |
| 30 | |
liberato | c58e8f82 | 2017-03-10 19:45:48 | [diff] [blame^] | 31 | // The surface that MediaCodec is configured to output to. This can be either |
| 32 | // a SurfaceTexture or other Surface provider. |
| 33 | // TODO(liberato): it would be nice if we had an abstraction that included |
| 34 | // SurfaceTexture and Overlay, but we don't right now. |
| 35 | const base::android::JavaRef<jobject>& j_surface() const { |
| 36 | if (overlay) |
| 37 | return overlay->GetJavaSurface(); |
| 38 | else |
| 39 | return surface_texture_surface.j_surface(); |
| 40 | } |
| 41 | |
liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 42 | int surface_id = SurfaceManager::kNoSurfaceID; |
| 43 | |
| 44 | // The surface onto which the codec is writing. |
liberato | c58e8f82 | 2017-03-10 19:45:48 | [diff] [blame^] | 45 | // TODO(liberato): this isn't true if we have an overlay. the overlay keeps |
| 46 | // the java surface. |
| 47 | // gl::ScopedJavaSurface surface; |
| 48 | |
| 49 | // If |overlay| is non-null, then |overlay| owns |surface|. |
| 50 | std::unique_ptr<AndroidOverlay> overlay; |
liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 51 | |
| 52 | // The SurfaceTexture attached to |surface|, or nullptr if |surface| is |
| 53 | // SurfaceView backed. |
| 54 | scoped_refptr<gl::SurfaceTexture> surface_texture; |
| 55 | |
liberato | c58e8f82 | 2017-03-10 19:45:48 | [diff] [blame^] | 56 | // If |surface_texture| is not null, then this is the surface for it. |
| 57 | // TODO(liberato): |surface| is the same thing, since overlays own their own |
| 58 | // surfaces anyway. |
| 59 | gl::ScopedJavaSurface surface_texture_surface; |
| 60 | |
liberato | 5e0962e | 2017-03-08 19:21:36 | [diff] [blame] | 61 | private: |
| 62 | ~AVDASurfaceBundle(); |
| 63 | friend class base::RefCountedThreadSafe<AVDASurfaceBundle>; |
| 64 | |
| 65 | DISALLOW_COPY_AND_ASSIGN(AVDASurfaceBundle); |
| 66 | }; |
| 67 | |
| 68 | } // namespace media |
| 69 | |
| 70 | #endif // MEDIA_GPU_AVDA_SURFACE_BUNDLE_H_ |