OLD | NEW |
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 MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_ | 5 #ifndef MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_ |
6 #define MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_ | 6 #define MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "media/base/bitstream_buffer.h" | 15 #include "media/base/bitstream_buffer.h" |
16 #include "media/base/surface_manager.h" | 16 #include "media/base/surface_manager.h" |
17 #include "media/base/video_decoder_config.h" | 17 #include "media/base/video_decoder_config.h" |
18 #include "media/video/picture.h" | 18 #include "media/video/picture.h" |
19 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 20 #include "ui/gfx/gpu_memory_buffer.h" |
20 | 21 |
21 typedef unsigned int GLenum; | 22 typedef unsigned int GLenum; |
22 | 23 |
23 namespace base { | 24 namespace base { |
24 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
25 } | 26 } |
26 | 27 |
27 namespace media { | 28 namespace media { |
28 | 29 |
29 // Video decoder interface. | 30 // Video decoder interface. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // failures, GPU library failures, browser programming errors, and so on. | 96 // failures, GPU library failures, browser programming errors, and so on. |
96 PLATFORM_FAILURE, | 97 PLATFORM_FAILURE, |
97 // Largest used enum. This should be adjusted when new errors are added. | 98 // Largest used enum. This should be adjusted when new errors are added. |
98 ERROR_MAX = PLATFORM_FAILURE, | 99 ERROR_MAX = PLATFORM_FAILURE, |
99 }; | 100 }; |
100 | 101 |
101 // Config structure contains parameters required for the VDA initialization. | 102 // Config structure contains parameters required for the VDA initialization. |
102 struct MEDIA_EXPORT Config { | 103 struct MEDIA_EXPORT Config { |
103 enum { kNoSurfaceID = SurfaceManager::kNoSurfaceID }; | 104 enum { kNoSurfaceID = SurfaceManager::kNoSurfaceID }; |
104 | 105 |
| 106 // Specifies the allocation and handling mode for output PictureBuffers. |
| 107 // When set to ALLOCATE, the VDA is expected to allocate backing memory |
| 108 // for PictureBuffers at the time of AssignPictureBuffers() call. |
| 109 // When set to IMPORT, the VDA will not allocate, but after receiving |
| 110 // AssignPictureBuffers() call, it will expect a call to |
| 111 // ImportBufferForPicture() for each PictureBuffer before use. |
| 112 enum class OutputMode { |
| 113 ALLOCATE, |
| 114 IMPORT, |
| 115 }; |
| 116 |
105 Config() = default; | 117 Config() = default; |
106 Config(VideoCodecProfile profile); | 118 Config(VideoCodecProfile profile); |
107 Config(const VideoDecoderConfig& video_decoder_config); | 119 Config(const VideoDecoderConfig& video_decoder_config); |
108 | 120 |
109 std::string AsHumanReadableString() const; | 121 std::string AsHumanReadableString() const; |
110 | 122 |
111 // |profile| combines the information about the codec and its profile. | 123 // |profile| combines the information about the codec and its profile. |
112 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; | 124 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; |
113 | 125 |
114 // The flag indicating whether the stream is encrypted. | 126 // The flag indicating whether the stream is encrypted. |
115 bool is_encrypted = false; | 127 bool is_encrypted = false; |
116 | 128 |
117 // The flag indicating whether the client supports deferred initialization | 129 // The flag indicating whether the client supports deferred initialization |
118 // or not. | 130 // or not. |
119 bool is_deferred_initialization_allowed = false; | 131 bool is_deferred_initialization_allowed = false; |
120 | 132 |
121 // An optional graphics surface that the VDA should render to. For setting | 133 // An optional graphics surface that the VDA should render to. For setting |
122 // an output SurfaceView on Android. It's only valid when not equal to | 134 // an output SurfaceView on Android. It's only valid when not equal to |
123 // |kNoSurfaceID|. | 135 // |kNoSurfaceID|. |
124 int surface_id = kNoSurfaceID; | 136 int surface_id = kNoSurfaceID; |
125 | 137 |
126 // Coded size of the video frame hint, subject to change. | 138 // Coded size of the video frame hint, subject to change. |
127 gfx::Size initial_expected_coded_size; | 139 gfx::Size initial_expected_coded_size; |
| 140 |
| 141 OutputMode output_mode = OutputMode::ALLOCATE; |
128 }; | 142 }; |
129 | 143 |
130 // Interface for collaborating with picture interface to provide memory for | 144 // Interface for collaborating with picture interface to provide memory for |
131 // output picture and blitting them. These callbacks will not be made unless | 145 // output picture and blitting them. These callbacks will not be made unless |
132 // Initialize() has returned successfully. | 146 // Initialize() has returned successfully. |
133 // This interface is extended by the various layers that relay messages back | 147 // This interface is extended by the various layers that relay messages back |
134 // to the plugin, through the PPP_VideoDecoder_Dev interface the plugin | 148 // to the plugin, through the PPP_VideoDecoder_Dev interface the plugin |
135 // implements. | 149 // implements. |
136 class MEDIA_EXPORT Client { | 150 class MEDIA_EXPORT Client { |
137 public: | 151 public: |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // is not allowed to deallocate the buffer before the DismissPictureBuffer | 237 // is not allowed to deallocate the buffer before the DismissPictureBuffer |
224 // callback has been initiated for a given buffer. | 238 // callback has been initiated for a given buffer. |
225 // | 239 // |
226 // Parameters: | 240 // Parameters: |
227 // |buffers| contains the allocated picture buffers for the output. Note | 241 // |buffers| contains the allocated picture buffers for the output. Note |
228 // that the count of buffers may be larger than the count requested through | 242 // that the count of buffers may be larger than the count requested through |
229 // the call to Client::ProvidePictureBuffers(). | 243 // the call to Client::ProvidePictureBuffers(). |
230 virtual void AssignPictureBuffers( | 244 virtual void AssignPictureBuffers( |
231 const std::vector<PictureBuffer>& buffers) = 0; | 245 const std::vector<PictureBuffer>& buffers) = 0; |
232 | 246 |
| 247 // Imports |gpu_memory_buffer_handles| as backing memory for picture buffer |
| 248 // associated with |picture_buffer_id|. The n-th element in |
| 249 // |gpu_memory_buffer_handles| should be a handle to a GpuMemoryBuffer backing |
| 250 // the n-th plane of the PictureBuffer. This can only be be used if the VDA |
| 251 // has been Initialize()d with config.output_mode = IMPORT, and should be |
| 252 // preceded by a call to AssignPictureBuffers() to set up the number of |
| 253 // PictureBuffers and their details. |
| 254 // After this call, the VDA becomes the owner of the GpuMemoryBufferHandles, |
| 255 // and is responsible for closing them after use, also on import failure. |
| 256 virtual void ImportBufferForPicture( |
| 257 int32_t picture_buffer_id, |
| 258 const std::vector<gfx::GpuMemoryBufferHandle>& gpu_memory_buffer_handles); |
| 259 |
233 // Sends picture buffers to be reused by the decoder. This needs to be called | 260 // Sends picture buffers to be reused by the decoder. This needs to be called |
234 // for each buffer that has been processed so that decoder may know onto which | 261 // for each buffer that has been processed so that decoder may know onto which |
235 // picture buffers it can write the output to. | 262 // picture buffers it can write the output to. |
236 // | 263 // |
237 // Parameters: | 264 // Parameters: |
238 // |picture_buffer_id| id of the picture buffer that is to be reused. | 265 // |picture_buffer_id| id of the picture buffer that is to be reused. |
239 virtual void ReusePictureBuffer(int32_t picture_buffer_id) = 0; | 266 virtual void ReusePictureBuffer(int32_t picture_buffer_id) = 0; |
240 | 267 |
241 // Flushes the decoder: all pending inputs will be decoded and pictures handed | 268 // Flushes the decoder: all pending inputs will be decoded and pictures handed |
242 // back to the client, followed by NotifyFlushDone() being called on the | 269 // back to the client, followed by NotifyFlushDone() being called on the |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // to run decode operations without GL context, which helps reduce latency and | 314 // to run decode operations without GL context, which helps reduce latency and |
288 // offloads the GPU Child thread. | 315 // offloads the GPU Child thread. |
289 virtual bool TryToSetupDecodeOnSeparateThread( | 316 virtual bool TryToSetupDecodeOnSeparateThread( |
290 const base::WeakPtr<Client>& decode_client, | 317 const base::WeakPtr<Client>& decode_client, |
291 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner); | 318 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner); |
292 | 319 |
293 // Windows creates a BGRA texture. | 320 // Windows creates a BGRA texture. |
294 // TODO(dshwang): after moving to D3D11, remove this. crbug.com/438691 | 321 // TODO(dshwang): after moving to D3D11, remove this. crbug.com/438691 |
295 virtual GLenum GetSurfaceInternalFormat() const; | 322 virtual GLenum GetSurfaceInternalFormat() const; |
296 | 323 |
| 324 // In IMPORT OutputMode, if supported by the VDA, return the format that it |
| 325 // requires for imported picture buffers. |
| 326 virtual VideoPixelFormat GetOutputFormat() const; |
| 327 |
297 protected: | 328 protected: |
298 // Do not delete directly; use Destroy() or own it with a scoped_ptr, which | 329 // Do not delete directly; use Destroy() or own it with a scoped_ptr, which |
299 // will Destroy() it properly by default. | 330 // will Destroy() it properly by default. |
300 virtual ~VideoDecodeAccelerator(); | 331 virtual ~VideoDecodeAccelerator(); |
301 }; | 332 }; |
302 | 333 |
303 } // namespace media | 334 } // namespace media |
304 | 335 |
305 namespace std { | 336 namespace std { |
306 | 337 |
307 // Specialize std::default_delete so that scoped_ptr<VideoDecodeAccelerator> | 338 // Specialize std::default_delete so that scoped_ptr<VideoDecodeAccelerator> |
308 // uses "Destroy()" instead of trying to use the destructor. | 339 // uses "Destroy()" instead of trying to use the destructor. |
309 template <> | 340 template <> |
310 struct MEDIA_EXPORT default_delete<media::VideoDecodeAccelerator> { | 341 struct MEDIA_EXPORT default_delete<media::VideoDecodeAccelerator> { |
311 void operator()(media::VideoDecodeAccelerator* vda) const; | 342 void operator()(media::VideoDecodeAccelerator* vda) const; |
312 }; | 343 }; |
313 | 344 |
314 } // namespace std | 345 } // namespace std |
315 | 346 |
316 #endif // MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_ | 347 #endif // MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |