OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_GPU_AVDA_SHARED_STATE_H_ | 5 #ifndef MEDIA_GPU_AVDA_SHARED_STATE_H_ |
6 #define MEDIA_GPU_AVDA_SHARED_STATE_H_ | 6 #define MEDIA_GPU_AVDA_SHARED_STATE_H_ |
7 | 7 |
8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
10 #include "media/base/android/media_codec_bridge.h" | 10 #include "media/base/android/media_codec_bridge.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 void SetSurfaceTexture(scoped_refptr<gl::SurfaceTexture> surface_texture, | 39 void SetSurfaceTexture(scoped_refptr<gl::SurfaceTexture> surface_texture, |
40 GLuint attached_service_id); | 40 GLuint attached_service_id); |
41 | 41 |
42 // Context and surface that |surface_texture_| is bound to, if | 42 // Context and surface that |surface_texture_| is bound to, if |
43 // |surface_texture_| is not null. | 43 // |surface_texture_| is not null. |
44 gl::GLContext* context() const { return context_.get(); } | 44 gl::GLContext* context() const { return context_.get(); } |
45 | 45 |
46 gl::GLSurface* surface() const { return surface_.get(); } | 46 gl::GLSurface* surface() const { return surface_.get(); } |
47 | 47 |
48 // Iterates over all known codec images and updates the MediaCodec attached to | |
49 // each one. | |
50 void CodecChanged(MediaCodecBridge* codec); | |
51 | |
52 // Methods for finding and updating the AVDACodecImage associated with a given | |
53 // picture buffer id. GetImageForPicture() will return null for unknown ids. | |
54 // Calling SetImageForPicture() with a nullptr will erase the entry. | |
55 void SetImageForPicture(int picture_buffer_id, AVDACodecImage* image); | |
56 AVDACodecImage* GetImageForPicture(int picture_buffer_id) const; | |
57 | |
58 // Helper method for coordinating the interactions between | 48 // Helper method for coordinating the interactions between |
59 // MediaCodec::ReleaseOutputBuffer() and WaitForFrameAvailable() when | 49 // MediaCodec::ReleaseOutputBuffer() and WaitForFrameAvailable() when |
60 // rendering to a SurfaceTexture; this method should never be called when | 50 // rendering to a SurfaceTexture; this method should never be called when |
61 // rendering to a SurfaceView. | 51 // rendering to a SurfaceView. |
62 // | 52 // |
63 // The release of the codec buffer to the surface texture is asynchronous, by | 53 // The release of the codec buffer to the surface texture is asynchronous, by |
64 // using this helper we can attempt to let this process complete in a non | 54 // using this helper we can attempt to let this process complete in a non |
65 // blocking fashion before the SurfaceTexture is used. | 55 // blocking fashion before the SurfaceTexture is used. |
66 // | 56 // |
67 // Clients should call this method to release the codec buffer for rendering | 57 // Clients should call this method to release the codec buffer for rendering |
68 // and then call WaitForFrameAvailable() before using the SurfaceTexture. In | 58 // and then call WaitForFrameAvailable() before using the SurfaceTexture. In |
69 // the ideal case the SurfaceTexture has already been updated, otherwise the | 59 // the ideal case the SurfaceTexture has already been updated, otherwise the |
70 // method will wait for a pro-rated amount of time based on elapsed time up | 60 // method will wait for a pro-rated amount of time based on elapsed time up |
71 // to a short deadline. | 61 // to a short deadline. |
72 // | 62 // |
73 // Some devices do not reliably notify frame availability, so we use a very | 63 // Some devices do not reliably notify frame availability, so we use a very |
74 // short deadline of only a few milliseconds to avoid indefinite stalls. | 64 // short deadline of only a few milliseconds to avoid indefinite stalls. |
75 void RenderCodecBufferToSurfaceTexture(MediaCodecBridge* codec, | 65 void RenderCodecBufferToSurfaceTexture(MediaCodecBridge* codec, |
76 int codec_buffer_index); | 66 int codec_buffer_index); |
77 | 67 |
78 // Helper methods for interacting with |surface_texture_|. See | 68 // Helper methods for interacting with |surface_texture_|. See |
79 // gfx::SurfaceTexture for method details. | 69 // gfx::SurfaceTexture for method details. |
80 void UpdateTexImage(); | 70 void UpdateTexImage(); |
81 // Returns a matrix that needs to be y flipped in order to match the | 71 // Returns a matrix that needs to be y flipped in order to match the |
82 // StreamTextureMatrix contract. See GLStreamTextureImage::YInvertMatrix(). | 72 // StreamTextureMatrix contract. See GLStreamTextureImage::YInvertMatrix(). |
83 void GetTransformMatrix(float matrix[16]) const; | 73 void GetTransformMatrix(float matrix[16]) const; |
84 | 74 |
| 75 void clear_release_time() { release_time_ = base::TimeTicks(); } |
| 76 |
85 protected: | 77 protected: |
86 virtual ~AVDASharedState(); | 78 virtual ~AVDASharedState(); |
87 | 79 |
88 private: | 80 private: |
89 friend class base::RefCounted<AVDASharedState>; | 81 friend class base::RefCounted<AVDASharedState>; |
90 | 82 |
91 scoped_refptr<gl::SurfaceTexture> surface_texture_; | 83 scoped_refptr<gl::SurfaceTexture> surface_texture_; |
92 | 84 |
93 // Platform gl texture id for |surface_texture_|. | 85 // Platform gl texture id for |surface_texture_|. |
94 GLuint surface_texture_service_id_; | 86 GLuint surface_texture_service_id_; |
(...skipping 10 matching lines...) Expand all Loading... |
105 std::map<int, AVDACodecImage*> codec_images_; | 97 std::map<int, AVDACodecImage*> codec_images_; |
106 | 98 |
107 // The time of the last call to RenderCodecBufferToSurfaceTexture(), null if | 99 // The time of the last call to RenderCodecBufferToSurfaceTexture(), null if |
108 // if there has been no last call or WaitForFrameAvailable() has been called | 100 // if there has been no last call or WaitForFrameAvailable() has been called |
109 // since the last call. | 101 // since the last call. |
110 base::TimeTicks release_time_; | 102 base::TimeTicks release_time_; |
111 | 103 |
112 // Texture matrix of the front buffer of the surface texture. | 104 // Texture matrix of the front buffer of the surface texture. |
113 float gl_matrix_[16]; | 105 float gl_matrix_[16]; |
114 | 106 |
| 107 class OnFrameAvailableHandler; |
| 108 scoped_refptr<OnFrameAvailableHandler> on_frame_available_handler_; |
| 109 |
115 DISALLOW_COPY_AND_ASSIGN(AVDASharedState); | 110 DISALLOW_COPY_AND_ASSIGN(AVDASharedState); |
116 }; | 111 }; |
117 | 112 |
118 } // namespace media | 113 } // namespace media |
119 | 114 |
120 #endif // MEDIA_GPU_AVDA_SHARED_STATE_H_ | 115 #endif // MEDIA_GPU_AVDA_SHARED_STATE_H_ |
OLD | NEW |