OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" | 16 #include "base/bind.h" |
17 #include "base/callback.h" | 17 #include "base/callback.h" |
| 18 #include "base/compiler_specific.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/memory/ref_counted.h" |
19 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
20 #include "base/shared_memory.h" | 22 #include "base/shared_memory.h" |
21 #include "media/video/video_decode_accelerator.h" | 23 #include "media/video/video_decode_accelerator.h" |
22 #include "third_party/angle/include/EGL/egl.h" | 24 #include "third_party/angle/include/EGL/egl.h" |
23 #include "third_party/angle/include/EGL/eglext.h" | 25 #include "third_party/angle/include/EGL/eglext.h" |
24 #include "third_party/openmax/il/OMX_Component.h" | 26 #include "third_party/openmax/il/OMX_Component.h" |
25 #include "third_party/openmax/il/OMX_Core.h" | 27 #include "third_party/openmax/il/OMX_Core.h" |
26 #include "third_party/openmax/il/OMX_Video.h" | 28 #include "third_party/openmax/il/OMX_Video.h" |
27 | 29 |
28 // Class to wrap OpenMAX IL accelerator behind VideoDecodeAccelerator interface. | 30 // Class to wrap OpenMAX IL accelerator behind VideoDecodeAccelerator interface. |
29 // 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 |
30 // 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 |
31 // | 33 // |
32 // This class lives on a single thread and DCHECKs that it is never accessed | 34 // This class lives on a single thread and DCHECKs that it is never accessed |
33 // from any other. OMX callbacks are trampolined from the OMX component's | 35 // from any other. OMX callbacks are trampolined from the OMX component's |
34 // thread to maintain this invariant. | 36 // thread to maintain this invariant. The only exception to thread-unsafety is |
| 37 // that references can be added from any thread (practically used only by the |
| 38 // OMX thread). |
35 class OmxVideoDecodeAccelerator : public media::VideoDecodeAccelerator { | 39 class OmxVideoDecodeAccelerator : public media::VideoDecodeAccelerator { |
36 public: | 40 public: |
37 // Does not take ownership of |client| which must outlive |*this|. | 41 // Does not take ownership of |client| which must outlive |*this|. |
38 OmxVideoDecodeAccelerator(media::VideoDecodeAccelerator::Client* client); | 42 OmxVideoDecodeAccelerator(media::VideoDecodeAccelerator::Client* client); |
39 virtual ~OmxVideoDecodeAccelerator(); | |
40 | 43 |
41 // media::VideoDecodeAccelerator implementation. | 44 // media::VideoDecodeAccelerator implementation. |
42 bool Initialize(const std::vector<uint32>& config) OVERRIDE; | 45 bool Initialize(const std::vector<uint32>& config) OVERRIDE; |
43 void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | 46 void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; |
44 virtual void AssignGLESBuffers( | 47 virtual void AssignGLESBuffers( |
45 const std::vector<media::GLESBuffer>& buffers) OVERRIDE; | 48 const std::vector<media::GLESBuffer>& buffers) OVERRIDE; |
46 void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | 49 void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; |
47 void Flush() OVERRIDE; | 50 void Flush() OVERRIDE; |
48 void Reset() OVERRIDE; | 51 void Reset() OVERRIDE; |
49 void Destroy() OVERRIDE; | 52 void Destroy() OVERRIDE; |
50 | 53 |
51 void SetEglState(EGLDisplay egl_display, EGLContext egl_context); | 54 void SetEglState(EGLDisplay egl_display, EGLContext egl_context); |
52 | 55 |
53 private: | 56 private: |
| 57 virtual ~OmxVideoDecodeAccelerator(); |
| 58 |
54 // Because OMX state-transitions are described solely by the "state reached" | 59 // Because OMX state-transitions are described solely by the "state reached" |
55 // (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 |
56 // 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 |
57 // |*this| is in any state other than NO_TRANSITION. | 62 // |*this| is in any state other than NO_TRANSITION. |
58 enum CurrentStateChange { | 63 enum CurrentStateChange { |
59 NO_TRANSITION, // Not in the middle of a transition. | 64 NO_TRANSITION, // Not in the middle of a transition. |
60 INITIALIZING, | 65 INITIALIZING, |
61 FLUSHING, | 66 FLUSHING, |
62 RESETTING, | 67 RESETTING, |
63 DESTROYING, | 68 DESTROYING, |
(...skipping 13 matching lines...) Expand all Loading... |
77 typedef std::map<int32, OutputPicture> OutputPictureById; | 82 typedef std::map<int32, OutputPicture> OutputPictureById; |
78 | 83 |
79 // Verify that |config| is compatible with this class and hardware. | 84 // Verify that |config| is compatible with this class and hardware. |
80 bool VerifyConfigs(const std::vector<uint32>& configs); | 85 bool VerifyConfigs(const std::vector<uint32>& configs); |
81 | 86 |
82 MessageLoop* message_loop_; | 87 MessageLoop* message_loop_; |
83 OMX_HANDLETYPE component_handle_; | 88 OMX_HANDLETYPE component_handle_; |
84 | 89 |
85 // Create the Component for OMX. Handles all OMX initialization. | 90 // Create the Component for OMX. Handles all OMX initialization. |
86 bool CreateComponent(); | 91 bool CreateComponent(); |
87 void ShutdownComponent(); | |
88 // Buffer allocation/free methods for input and output buffers. | 92 // Buffer allocation/free methods for input and output buffers. |
89 bool AllocateInputBuffers(); | 93 bool AllocateInputBuffers(); |
90 bool AllocateOutputBuffers(); | 94 bool AllocateOutputBuffers(); |
91 void FreeInputBuffers(); | 95 void FreeInputBuffers(); |
92 void FreeOutputBuffers(); | 96 void FreeOutputBuffers(); |
93 | 97 |
94 // Methods to handle OMX state transitions. See section 3.1.1.2 of the spec. | 98 // Methods to handle OMX state transitions. See section 3.1.1.2 of the spec. |
95 // Request transitioning OMX component to some other state. | 99 // Request transitioning OMX component to some other state. |
96 void BeginTransitionToState(OMX_STATETYPE new_state); | 100 void BeginTransitionToState(OMX_STATETYPE new_state); |
97 // The callback received when the OMX component has transitioned. | 101 // The callback received when the OMX component has transitioned. |
98 void DispatchStateReached(OMX_STATETYPE reached); | 102 void DispatchStateReached(OMX_STATETYPE reached); |
99 // Callbacks handling transitioning to specific states during state changes. | 103 // Callbacks handling transitioning to specific states during state changes. |
100 // These follow a convention of OnReached<STATE>In<CurrentStateChange>(), | 104 // These follow a convention of OnReached<STATE>In<CurrentStateChange>(), |
101 // requiring that each pair of <reached-state>/CurrentStateChange is unique | 105 // requiring that each pair of <reached-state>/CurrentStateChange is unique |
102 // (i.e. the source state is uniquely defined by the pair). | 106 // (i.e. the source state is uniquely defined by the pair). |
103 void OnReachedIdleInInitializing(); | 107 void OnReachedIdleInInitializing(); |
104 void OnReachedExecutingInInitializing(); | 108 void OnReachedExecutingInInitializing(); |
105 void OnReachedPauseInFlushing(); | 109 void OnReachedPauseInFlushing(); |
106 void OnReachedExecutingInFlushing(); | 110 void OnReachedExecutingInFlushing(); |
107 void OnReachedPauseInResetting(); | 111 void OnReachedPauseInResetting(); |
108 void OnReachedExecutingInResetting(); | 112 void OnReachedExecutingInResetting(); |
109 void OnReachedIdleInDestroying(); | 113 void OnReachedIdleInDestroying(); |
110 void OnReachedLoadedInDestroying(); | 114 void OnReachedLoadedInDestroying(); |
111 void OnReachedEOSInFlushing(); | 115 void OnReachedEOSInFlushing(); |
112 void OnReachedInvalidInErroring(); | 116 void OnReachedInvalidInErroring(); |
| 117 void ShutdownComponent(); |
| 118 void BusyLoopInDestroying(); |
113 | 119 |
114 // Port-flushing helpers. | 120 // Port-flushing helpers. |
115 void FlushIOPorts(); | 121 void FlushIOPorts(); |
116 void InputPortFlushDone(); | 122 void InputPortFlushDone(); |
117 void OutputPortFlushDone(); | 123 void OutputPortFlushDone(); |
118 | 124 |
119 // Stop the component when any error is detected. | 125 // Stop the component when any error is detected. |
120 void StopOnError(media::VideoDecodeAccelerator::Error error); | 126 void StopOnError(media::VideoDecodeAccelerator::Error error); |
121 | 127 |
122 // Determine whether we can issue fill buffer to the decoder based on the | 128 // Determine whether we can issue fill buffer to the decoder based on the |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 OMX_PTR event_data); | 202 OMX_PTR event_data); |
197 static OMX_ERRORTYPE EmptyBufferCallback(OMX_HANDLETYPE component, | 203 static OMX_ERRORTYPE EmptyBufferCallback(OMX_HANDLETYPE component, |
198 OMX_PTR priv_data, | 204 OMX_PTR priv_data, |
199 OMX_BUFFERHEADERTYPE* buffer); | 205 OMX_BUFFERHEADERTYPE* buffer); |
200 static OMX_ERRORTYPE FillBufferCallback(OMX_HANDLETYPE component, | 206 static OMX_ERRORTYPE FillBufferCallback(OMX_HANDLETYPE component, |
201 OMX_PTR priv_data, | 207 OMX_PTR priv_data, |
202 OMX_BUFFERHEADERTYPE* buffer); | 208 OMX_BUFFERHEADERTYPE* buffer); |
203 }; | 209 }; |
204 | 210 |
205 #endif // CONTENT_COMMON_GPU_MEDIA_OMX_VIDEO_DECODE_ACCELERATOR_H_ | 211 #endif // CONTENT_COMMON_GPU_MEDIA_OMX_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |