Chromium Code Reviews| 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 // Resets the last time for RenderCodecBufferToSurfaceTexture(). Should be | |
| 76 // called during codec changes. | |
| 77 void clear_release_time() { release_time_ = base::TimeTicks(); } | |
|
liberato (no reviews please)
2016/11/04 18:02:14
ClearReleaseTime()?
DaleCurtis
2016/11/04 19:42:42
Inline methods must always be hacker_style().
| |
| 78 | |
| 85 protected: | 79 protected: |
| 86 virtual ~AVDASharedState(); | 80 virtual ~AVDASharedState(); |
| 87 | 81 |
| 88 private: | 82 private: |
| 89 friend class base::RefCounted<AVDASharedState>; | 83 friend class base::RefCounted<AVDASharedState>; |
| 90 | 84 |
| 91 scoped_refptr<gl::SurfaceTexture> surface_texture_; | 85 scoped_refptr<gl::SurfaceTexture> surface_texture_; |
| 92 | 86 |
| 93 // Platform gl texture id for |surface_texture_|. | 87 // Platform gl texture id for |surface_texture_|. |
| 94 GLuint surface_texture_service_id_; | 88 GLuint surface_texture_service_id_; |
| 95 | 89 |
| 96 // For signalling OnFrameAvailable(). | 90 // For signalling OnFrameAvailable(). |
| 97 base::WaitableEvent frame_available_event_; | 91 base::WaitableEvent frame_available_event_; |
| 98 | 92 |
| 99 // Context and surface that |surface_texture_| is bound to, if | 93 // Context and surface that |surface_texture_| is bound to, if |
| 100 // |surface_texture_| is not null. | 94 // |surface_texture_| is not null. |
| 101 scoped_refptr<gl::GLContext> context_; | 95 scoped_refptr<gl::GLContext> context_; |
| 102 scoped_refptr<gl::GLSurface> surface_; | 96 scoped_refptr<gl::GLSurface> surface_; |
| 103 | 97 |
| 104 // Maps a picture buffer id to a AVDACodecImage. | |
| 105 std::map<int, AVDACodecImage*> codec_images_; | |
| 106 | |
| 107 // The time of the last call to RenderCodecBufferToSurfaceTexture(), null if | 98 // The time of the last call to RenderCodecBufferToSurfaceTexture(), null if |
| 108 // if there has been no last call or WaitForFrameAvailable() has been called | 99 // if there has been no last call or WaitForFrameAvailable() has been called |
| 109 // since the last call. | 100 // since the last call. |
| 110 base::TimeTicks release_time_; | 101 base::TimeTicks release_time_; |
| 111 | 102 |
| 112 // Texture matrix of the front buffer of the surface texture. | 103 // Texture matrix of the front buffer of the surface texture. |
| 113 float gl_matrix_[16]; | 104 float gl_matrix_[16]; |
| 114 | 105 |
| 106 class OnFrameAvailableHandler; | |
| 107 scoped_refptr<OnFrameAvailableHandler> on_frame_available_handler_; | |
| 108 | |
| 115 DISALLOW_COPY_AND_ASSIGN(AVDASharedState); | 109 DISALLOW_COPY_AND_ASSIGN(AVDASharedState); |
| 116 }; | 110 }; |
| 117 | 111 |
| 118 } // namespace media | 112 } // namespace media |
| 119 | 113 |
| 120 #endif // MEDIA_GPU_AVDA_SHARED_STATE_H_ | 114 #endif // MEDIA_GPU_AVDA_SHARED_STATE_H_ |
| OLD | NEW |