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

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

Issue 10749019: VideoDecodeAccelerator now SupportsWeakPtr instead of being RefCountedThreadSafe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pure rebase Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_MEDIA_OMX_VIDEO_DECODE_ACCELERATOR_H_ 5 #ifndef CONTENT_COMMON_GPU_MEDIA_OMX_VIDEO_DECODE_ACCELERATOR_H_
6 #define CONTENT_COMMON_GPU_MEDIA_OMX_VIDEO_DECODE_ACCELERATOR_H_ 6 #define CONTENT_COMMON_GPU_MEDIA_OMX_VIDEO_DECODE_ACCELERATOR_H_
7 7
8 #include <dlfcn.h> 8 #include <dlfcn.h>
9 #include <map> 9 #include <map>
10 #include <queue> 10 #include <queue>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/memory/ref_counted.h"
19 #include "base/message_loop.h" 18 #include "base/message_loop.h"
20 #include "base/shared_memory.h" 19 #include "base/shared_memory.h"
21 #include "content/common/content_export.h" 20 #include "content/common/content_export.h"
22 #include "media/video/video_decode_accelerator.h" 21 #include "media/video/video_decode_accelerator.h"
23 #include "third_party/angle/include/EGL/egl.h" 22 #include "third_party/angle/include/EGL/egl.h"
24 #include "third_party/angle/include/EGL/eglext.h" 23 #include "third_party/angle/include/EGL/eglext.h"
25 #include "third_party/openmax/il/OMX_Component.h" 24 #include "third_party/openmax/il/OMX_Component.h"
26 #include "third_party/openmax/il/OMX_Core.h" 25 #include "third_party/openmax/il/OMX_Core.h"
27 #include "third_party/openmax/il/OMX_Video.h" 26 #include "third_party/openmax/il/OMX_Video.h"
28 27
29 class Gles2TextureToEglImageTranslator; 28 class Gles2TextureToEglImageTranslator;
30 29
31 // Class to wrap OpenMAX IL accelerator behind VideoDecodeAccelerator interface. 30 // Class to wrap OpenMAX IL accelerator behind VideoDecodeAccelerator interface.
32 // The implementation assumes an OpenMAX IL 1.1.2 implementation conforming to 31 // The implementation assumes an OpenMAX IL 1.1.2 implementation conforming to
33 // http://www.khronos.org/registry/omxil/specs/OpenMAX_IL_1_1_2_Specification.pd f 32 // http://www.khronos.org/registry/omxil/specs/OpenMAX_IL_1_1_2_Specification.pd f
34 // 33 //
35 // This class lives on a single thread and DCHECKs that it is never accessed 34 // This class lives on a single thread (the GPU process ChildThread) and DCHECKs
36 // from any other. OMX callbacks are trampolined from the OMX component's 35 // that it is never accessed from any other. OMX callbacks are trampolined from
37 // thread to maintain this invariant. The only exception to thread-unsafety is 36 // the OMX component's thread to maintain this invariant, using |weak_this()|.
38 // that references can be added from any thread (practically used only by the
39 // OMX thread).
40 class CONTENT_EXPORT OmxVideoDecodeAccelerator : 37 class CONTENT_EXPORT OmxVideoDecodeAccelerator :
41 public media::VideoDecodeAccelerator { 38 public media::VideoDecodeAccelerator {
42 public: 39 public:
43 // Does not take ownership of |client| which must outlive |*this|. 40 // Does not take ownership of |client| which must outlive |*this|.
44 OmxVideoDecodeAccelerator(media::VideoDecodeAccelerator::Client* client); 41 OmxVideoDecodeAccelerator(media::VideoDecodeAccelerator::Client* client);
42 virtual ~OmxVideoDecodeAccelerator();
45 43
46 // media::VideoDecodeAccelerator implementation. 44 // media::VideoDecodeAccelerator implementation.
47 bool Initialize(media::VideoCodecProfile profile) OVERRIDE; 45 bool Initialize(media::VideoCodecProfile profile) OVERRIDE;
48 void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; 46 void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE;
49 virtual void AssignPictureBuffers( 47 virtual void AssignPictureBuffers(
50 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; 48 const std::vector<media::PictureBuffer>& buffers) OVERRIDE;
51 void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; 49 void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE;
52 void Flush() OVERRIDE; 50 void Flush() OVERRIDE;
53 void Reset() OVERRIDE; 51 void Reset() OVERRIDE;
54 void Destroy() OVERRIDE; 52 void Destroy(bool pass_ownership) OVERRIDE;
55 53
56 void SetEglState(EGLDisplay egl_display, EGLContext egl_context); 54 void SetEglState(EGLDisplay egl_display, EGLContext egl_context);
57 55
56 base::WeakPtr<OmxVideoDecodeAccelerator> weak_this() { return weak_this_; }
57
58 private: 58 private:
59 virtual ~OmxVideoDecodeAccelerator();
60
61 // Because OMX state-transitions are described solely by the "state reached" 59 // Because OMX state-transitions are described solely by the "state reached"
62 // (3.1.2.9.1, table 3-7 of the spec), we track what transition was requested 60 // (3.1.2.9.1, table 3-7 of the spec), we track what transition was requested
63 // using this enum. Note that it is an error to request a transition while 61 // using this enum. Note that it is an error to request a transition while
64 // |*this| is in any state other than NO_TRANSITION, unless requesting 62 // |*this| is in any state other than NO_TRANSITION, unless requesting
65 // DESTROYING or ERRORING. 63 // DESTROYING or ERRORING.
66 enum CurrentStateChange { 64 enum CurrentStateChange {
67 NO_TRANSITION, // Not in the middle of a transition. 65 NO_TRANSITION, // Not in the middle of a transition.
68 INITIALIZING, 66 INITIALIZING,
69 FLUSHING, 67 FLUSHING,
70 RESETTING, 68 RESETTING,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // (i.e. the source state is uniquely defined by the pair). 105 // (i.e. the source state is uniquely defined by the pair).
108 void OnReachedIdleInInitializing(); 106 void OnReachedIdleInInitializing();
109 void OnReachedExecutingInInitializing(); 107 void OnReachedExecutingInInitializing();
110 void OnReachedPauseInResetting(); 108 void OnReachedPauseInResetting();
111 void OnReachedExecutingInResetting(); 109 void OnReachedExecutingInResetting();
112 void OnReachedIdleInDestroying(); 110 void OnReachedIdleInDestroying();
113 void OnReachedLoadedInDestroying(); 111 void OnReachedLoadedInDestroying();
114 void OnReachedEOSInFlushing(); 112 void OnReachedEOSInFlushing();
115 void OnReachedInvalidInErroring(); 113 void OnReachedInvalidInErroring();
116 void ShutdownComponent(); 114 void ShutdownComponent();
117 void BusyLoopInDestroying(); 115 void BusyLoopInDestroying(scoped_ptr<OmxVideoDecodeAccelerator> self);
118 116
119 // Port-flushing helpers. 117 // Port-flushing helpers.
120 void FlushIOPorts(); 118 void FlushIOPorts();
121 void InputPortFlushDone(); 119 void InputPortFlushDone();
122 void OutputPortFlushDone(); 120 void OutputPortFlushDone();
123 121
124 // Stop the component when any error is detected. 122 // Stop the component when any error is detected.
125 void StopOnError(media::VideoDecodeAccelerator::Error error); 123 void StopOnError(media::VideoDecodeAccelerator::Error error);
126 124
127 // Determine whether we can issue fill buffer to the decoder based on the 125 // Determine whether we can issue fill buffer to the decoder based on the
128 // current state (and outstanding state change) of the component. 126 // current state (and outstanding state change) of the component.
129 bool CanFillBuffer(); 127 bool CanFillBuffer();
130 128
131 // Whenever port settings change, the first thing we must do is disable the 129 // Whenever port settings change, the first thing we must do is disable the
132 // port (see Figure 3-18 of the OpenMAX IL spec linked to above). When the 130 // port (see Figure 3-18 of the OpenMAX IL spec linked to above). When the
133 // port is disabled, the component will call us back here. We then re-enable 131 // port is disabled, the component will call us back here. We then re-enable
134 // the port once we have textures, and that's the second method below. 132 // the port once we have textures, and that's the second method below.
135 void OnOutputPortDisabled(); 133 void OnOutputPortDisabled();
136 void OnOutputPortEnabled(); 134 void OnOutputPortEnabled();
137 135
138 // Decode bitstream buffers that were queued (see queued_bitstream_buffers_). 136 // Decode bitstream buffers that were queued (see queued_bitstream_buffers_).
139 void DecodeQueuedBitstreamBuffers(); 137 void DecodeQueuedBitstreamBuffers();
140 138
139 // Weak pointer to |this|; used to safely trampoline calls from the OMX thread
140 // to the ChildThread. Since |this| is kept alive until OMX is fully shut
141 // down, only the OMX->Child thread direction needs to be guarded this way.
142 base::WeakPtr<OmxVideoDecodeAccelerator> weak_this_;
143
141 // True once Initialize() has returned true; before this point there's never a 144 // True once Initialize() has returned true; before this point there's never a
142 // point in calling client_->NotifyError(). 145 // point in calling client_->NotifyError().
143 bool init_begun_; 146 bool init_begun_;
144 147
145 // IL-client state. 148 // IL-client state.
146 OMX_STATETYPE client_state_; 149 OMX_STATETYPE client_state_;
147 // See comment on CurrentStateChange above. 150 // See comment on CurrentStateChange above.
148 CurrentStateChange current_state_change_; 151 CurrentStateChange current_state_change_;
149 152
150 // Following are input port related variables. 153 // Following are input port related variables.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 OMX_PTR event_data); 225 OMX_PTR event_data);
223 static OMX_ERRORTYPE EmptyBufferCallback(OMX_HANDLETYPE component, 226 static OMX_ERRORTYPE EmptyBufferCallback(OMX_HANDLETYPE component,
224 OMX_PTR priv_data, 227 OMX_PTR priv_data,
225 OMX_BUFFERHEADERTYPE* buffer); 228 OMX_BUFFERHEADERTYPE* buffer);
226 static OMX_ERRORTYPE FillBufferCallback(OMX_HANDLETYPE component, 229 static OMX_ERRORTYPE FillBufferCallback(OMX_HANDLETYPE component,
227 OMX_PTR priv_data, 230 OMX_PTR priv_data,
228 OMX_BUFFERHEADERTYPE* buffer); 231 OMX_BUFFERHEADERTYPE* buffer);
229 }; 232 };
230 233
231 #endif // CONTENT_COMMON_GPU_MEDIA_OMX_VIDEO_DECODE_ACCELERATOR_H_ 234 #endif // CONTENT_COMMON_GPU_MEDIA_OMX_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698