Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: content/common/gpu/media/avda_shared_state.h

Issue 1963773003: Merge to M51: Various fixes to prevent playback hang on MotoX. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 CONTENT_COMMON_GPU_AVDA_SHARED_STATE_H_ 5 #ifndef CONTENT_COMMON_GPU_AVDA_SHARED_STATE_H_
6 #define CONTENT_COMMON_GPU_AVDA_SHARED_STATE_H_ 6 #define CONTENT_COMMON_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"
11 #include "media/base/android/sdk_media_codec_bridge.h" 11 #include "media/base/android/sdk_media_codec_bridge.h"
12 #include "ui/gl/gl_context.h" 12 #include "ui/gl/gl_context.h"
13 #include "ui/gl/gl_image.h" 13 #include "ui/gl/gl_image.h"
14 #include "ui/gl/gl_surface.h" 14 #include "ui/gl/gl_surface.h"
15 15
16 namespace gfx { 16 namespace gfx {
17 class SurfaceTexture; 17 class SurfaceTexture;
18 } 18 }
19 19
20 namespace media {
21 class MediaCodecBridge;
22 }
23
20 namespace content { 24 namespace content {
25 class AVDACodecImage;
21 26
22 // Shared state to allow communication between the AVDA and the 27 // Shared state to allow communication between the AVDA and the
23 // GLImages that configure GL for drawing the frames. 28 // GLImages that configure GL for drawing the frames.
24 class AVDASharedState : public base::RefCounted<AVDASharedState> { 29 class AVDASharedState : public base::RefCounted<AVDASharedState> {
25 public: 30 public:
26 AVDASharedState(); 31 AVDASharedState();
27 32
28 GLint surface_texture_service_id() const { 33 GLint surface_texture_service_id() const {
29 return surface_texture_service_id_; 34 return surface_texture_service_id_;
30 } 35 }
(...skipping 12 matching lines...) Expand all
43 // Context that the surface texture is bound to, or nullptr if it is not in 48 // Context that the surface texture is bound to, or nullptr if it is not in
44 // the attached state. 49 // the attached state.
45 gfx::GLContext* context() const { return context_.get(); } 50 gfx::GLContext* context() const { return context_.get(); }
46 51
47 gfx::GLSurface* surface() const { return surface_.get(); } 52 gfx::GLSurface* surface() const { return surface_.get(); }
48 53
49 bool surface_texture_is_attached() const { 54 bool surface_texture_is_attached() const {
50 return surface_texture_is_attached_; 55 return surface_texture_is_attached_;
51 } 56 }
52 57
58 // Iterates over all known codec images and updates the MediaCodec attached to
59 // each one.
60 void CodecChanged(media::MediaCodecBridge* codec);
61
62 // Methods for finding and updating the AVDACodecImage associated with a given
63 // picture buffer id. GetImageForPicture() will return null for unknown ids.
64 // Calling SetImageForPicture() with a nullptr will erase the entry.
65 void SetImageForPicture(int picture_buffer_id, AVDACodecImage* image);
66 AVDACodecImage* GetImageForPicture(int picture_buffer_id) const;
67
53 // TODO(liberato): move the surface texture here and make these calls 68 // TODO(liberato): move the surface texture here and make these calls
54 // attach / detach it also. There are several changes going on in avda 69 // attach / detach it also. There are several changes going on in avda
55 // concurrently, so I don't want to change that until the dust settles. 70 // concurrently, so I don't want to change that until the dust settles.
56 // AVDACodecImage would no longer hold the surface texture. 71 // AVDACodecImage would no longer hold the surface texture.
57 72
58 // Call this when the SurfaceTexture is attached to a GL context. This will 73 // Call this when the SurfaceTexture is attached to a GL context. This will
59 // update surface_texture_is_attached(), and set the context() and surface() 74 // update surface_texture_is_attached(), and set the context() and surface()
60 // to match. 75 // to match.
61 void DidAttachSurfaceTexture(); 76 void DidAttachSurfaceTexture();
62 77
63 // Call this when the SurfaceTexture is detached from its GL context. This 78 // Call this when the SurfaceTexture is detached from its GL context. This
64 // will cause us to forget the last binding. 79 // will cause us to forget the last binding.
65 void DidDetachSurfaceTexture(); 80 void DidDetachSurfaceTexture();
66 81
82 // Helper method for coordinating the interactions between
83 // MediaCodec::ReleaseOutputBuffer() and WaitForFrameAvailable() when
84 // rendering to a SurfaceTexture; this method should never be called when
85 // rendering to a SurfaceView.
86 //
87 // The release of the codec buffer to the surface texture is asynchronous, by
88 // using this helper we can attempt to let this process complete in a non
89 // blocking fashion before the SurfaceTexture is used.
90 //
91 // Clients should call this method to release the codec buffer for rendering
92 // and then call WaitForFrameAvailable() before using the SurfaceTexture. In
93 // the ideal case the SurfaceTexture has already been updated, otherwise the
94 // method will wait for a pro-rated amount of time based on elapsed time up
95 // to a short deadline.
96 //
97 // Some devices do not reliably notify frame availability, so we use a very
98 // short deadline of only a few milliseconds to avoid indefinite stalls.
99 void RenderCodecBufferToSurfaceTexture(media::MediaCodecBridge* codec,
100 int codec_buffer_index);
101
102 protected:
103 virtual ~AVDASharedState();
104
67 private: 105 private:
106 friend class base::RefCounted<AVDASharedState>;
107
68 // Platform gl texture Id for |surface_texture_|. This will be zero if 108 // Platform gl texture Id for |surface_texture_|. This will be zero if
69 // and only if |texture_owner_| is null. 109 // and only if |texture_owner_| is null.
70 // TODO(liberato): This should be GLuint, but we don't seem to have the type. 110 // TODO(liberato): This should be GLuint, but we don't seem to have the type.
71 GLint surface_texture_service_id_; 111 GLint surface_texture_service_id_;
72 112
73 // For signalling OnFrameAvailable(). 113 // For signalling OnFrameAvailable().
74 base::WaitableEvent frame_available_event_; 114 base::WaitableEvent frame_available_event_;
75 115
76 // True if and only if the surface texture is currently attached. 116 // True if and only if the surface texture is currently attached.
77 bool surface_texture_is_attached_; 117 bool surface_texture_is_attached_;
78 118
79 // Context and surface that the surface texture is attached to, if it is 119 // Context and surface that the surface texture is attached to, if it is
80 // currently attached. 120 // currently attached.
81 scoped_refptr<gfx::GLContext> context_; 121 scoped_refptr<gfx::GLContext> context_;
82 scoped_refptr<gfx::GLSurface> surface_; 122 scoped_refptr<gfx::GLSurface> surface_;
83 123
84 protected: 124 // Maps a picture buffer id to a AVDACodecImage.
85 virtual ~AVDASharedState(); 125 std::map<int, AVDACodecImage*> codec_images_;
86 126
87 private: 127 // The time of the last call to RenderCodecBufferToSurfaceTexture(), null if
88 friend class base::RefCounted<AVDASharedState>; 128 // if there has been no last call or WaitForFrameAvailable() has been called
129 // since the last call.
130 base::TimeTicks release_time_;
131
132 DISALLOW_COPY_AND_ASSIGN(AVDASharedState);
89 }; 133 };
90 134
91 } // namespace content 135 } // namespace content
92 136
93 #endif // CONTENT_COMMON_GPU_AVDA_SHARED_STATE_H_ 137 #endif // CONTENT_COMMON_GPU_AVDA_SHARED_STATE_H_
OLDNEW
« no previous file with comments | « content/common/gpu/media/avda_codec_image.cc ('k') | content/common/gpu/media/avda_shared_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698