OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // This file contains an implementation of VideoDecodeAccelerator | 5 // This file contains an implementation of VideoDecodeAccelerator |
6 // that utilizes hardware video decoders, which expose Video4Linux 2 API | 6 // that utilizes hardware video decoders, which expose Video4Linux 2 API |
7 // (http://linuxtv.org/downloads/v4l-dvb-apis/). | 7 // (http://linuxtv.org/downloads/v4l-dvb-apis/). |
8 | 8 |
9 #ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ | 9 #ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ |
10 #define CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ | 10 #define CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ |
11 | 11 |
12 #include <queue> | 12 #include <queue> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
17 #include "base/memory/ref_counted.h" | |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
18 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
19 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
20 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
21 #include "content/common/gpu/media/v4l2_video_device.h" | 22 #include "content/common/gpu/media/v4l2_video_device.h" |
22 #include "media/base/limits.h" | 23 #include "media/base/limits.h" |
23 #include "media/base/video_decoder_config.h" | 24 #include "media/base/video_decoder_config.h" |
24 #include "media/video/picture.h" | 25 #include "media/video/picture.h" |
25 #include "media/video/video_decode_accelerator.h" | 26 #include "media/video/video_decode_accelerator.h" |
26 #include "ui/gfx/geometry/size.h" | 27 #include "ui/gfx/geometry/size.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 // subtle races (esp. if we get Reset() in the meantime), we block the decoder | 74 // subtle races (esp. if we get Reset() in the meantime), we block the decoder |
74 // thread while we wait for AssignPictureBuffers from the client. | 75 // thread while we wait for AssignPictureBuffers from the client. |
75 class CONTENT_EXPORT V4L2VideoDecodeAccelerator | 76 class CONTENT_EXPORT V4L2VideoDecodeAccelerator |
76 : public media::VideoDecodeAccelerator { | 77 : public media::VideoDecodeAccelerator { |
77 public: | 78 public: |
78 V4L2VideoDecodeAccelerator( | 79 V4L2VideoDecodeAccelerator( |
79 EGLDisplay egl_display, | 80 EGLDisplay egl_display, |
80 EGLContext egl_context, | 81 EGLContext egl_context, |
81 const base::WeakPtr<Client>& io_client_, | 82 const base::WeakPtr<Client>& io_client_, |
82 const base::Callback<bool(void)>& make_context_current, | 83 const base::Callback<bool(void)>& make_context_current, |
83 scoped_ptr<V4L2Device> device, | 84 scoped_refptr<V4L2Device> device, |
scherkus (not reviewing)
2015/01/13 01:25:00
const ref
Pawel Osciak
2015/01/13 11:33:35
Done.
| |
84 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy); | 85 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy); |
85 virtual ~V4L2VideoDecodeAccelerator(); | 86 virtual ~V4L2VideoDecodeAccelerator(); |
86 | 87 |
87 // media::VideoDecodeAccelerator implementation. | 88 // media::VideoDecodeAccelerator implementation. |
88 // Note: Initialize() and Destroy() are synchronous. | 89 // Note: Initialize() and Destroy() are synchronous. |
89 virtual bool Initialize(media::VideoCodecProfile profile, | 90 virtual bool Initialize(media::VideoCodecProfile profile, |
90 Client* client) override; | 91 Client* client) override; |
91 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) override; | 92 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) override; |
92 virtual void AssignPictureBuffers( | 93 virtual void AssignPictureBuffers( |
93 const std::vector<media::PictureBuffer>& buffers) override; | 94 const std::vector<media::PictureBuffer>& buffers) override; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 // The device task. | 255 // The device task. |
255 void DevicePollTask(bool poll_device); | 256 void DevicePollTask(bool poll_device); |
256 | 257 |
257 // | 258 // |
258 // Safe from any thread. | 259 // Safe from any thread. |
259 // | 260 // |
260 | 261 |
261 // Error notification (using PostTask() to child thread, if necessary). | 262 // Error notification (using PostTask() to child thread, if necessary). |
262 void NotifyError(Error error); | 263 void NotifyError(Error error); |
263 | 264 |
264 // Set the decoder_thread_ state (using PostTask to decoder thread, if | 265 // Set the decoder_state_ to kError and notify the client (if necessary). |
265 // necessary). | 266 void SetErrorState(Error error); |
266 void SetDecoderState(State state); | |
267 | 267 |
268 // | 268 // |
269 // Other utility functions. Called on decoder_thread_, unless | 269 // Other utility functions. Called on decoder_thread_, unless |
270 // decoder_thread_ is not yet started, in which case the child thread can call | 270 // decoder_thread_ is not yet started, in which case the child thread can call |
271 // these (e.g. in Initialize() or Destroy()). | 271 // these (e.g. in Initialize() or Destroy()). |
272 // | 272 // |
273 | 273 |
274 // Create the buffers we need. | 274 // Create the buffers we need. |
275 bool CreateInputBuffers(); | 275 bool CreateInputBuffers(); |
276 bool CreateOutputBuffers(); | 276 bool CreateOutputBuffers(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 // | 334 // |
335 | 335 |
336 // This thread services tasks posted from the VDA API entry points by the | 336 // This thread services tasks posted from the VDA API entry points by the |
337 // child thread and device service callbacks posted from the device thread. | 337 // child thread and device service callbacks posted from the device thread. |
338 base::Thread decoder_thread_; | 338 base::Thread decoder_thread_; |
339 // Decoder state machine state. | 339 // Decoder state machine state. |
340 State decoder_state_; | 340 State decoder_state_; |
341 // BitstreamBuffer we're presently reading. | 341 // BitstreamBuffer we're presently reading. |
342 scoped_ptr<BitstreamBufferRef> decoder_current_bitstream_buffer_; | 342 scoped_ptr<BitstreamBufferRef> decoder_current_bitstream_buffer_; |
343 // The V4L2Device this class is operating upon. | 343 // The V4L2Device this class is operating upon. |
344 scoped_ptr<V4L2Device> device_; | 344 scoped_refptr<V4L2Device> device_; |
345 // FlushTask() and ResetTask() should not affect buffers that have been | 345 // FlushTask() and ResetTask() should not affect buffers that have been |
346 // queued afterwards. For flushing or resetting the pipeline then, we will | 346 // queued afterwards. For flushing or resetting the pipeline then, we will |
347 // delay these buffers until after the flush or reset completes. | 347 // delay these buffers until after the flush or reset completes. |
348 int decoder_delay_bitstream_buffer_id_; | 348 int decoder_delay_bitstream_buffer_id_; |
349 // Input buffer we're presently filling. | 349 // Input buffer we're presently filling. |
350 int decoder_current_input_buffer_; | 350 int decoder_current_input_buffer_; |
351 // We track the number of buffer decode tasks we have scheduled, since each | 351 // We track the number of buffer decode tasks we have scheduled, since each |
352 // task execution should complete one buffer. If we fall behind (due to | 352 // task execution should complete one buffer. If we fall behind (due to |
353 // resource backpressure, etc.), we'll have to schedule more to catch up. | 353 // resource backpressure, etc.), we'll have to schedule more to catch up. |
354 int decoder_decode_buffer_tasks_scheduled_; | 354 int decoder_decode_buffer_tasks_scheduled_; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 | 443 |
444 // The WeakPtrFactory for |weak_this_|. | 444 // The WeakPtrFactory for |weak_this_|. |
445 base::WeakPtrFactory<V4L2VideoDecodeAccelerator> weak_this_factory_; | 445 base::WeakPtrFactory<V4L2VideoDecodeAccelerator> weak_this_factory_; |
446 | 446 |
447 DISALLOW_COPY_AND_ASSIGN(V4L2VideoDecodeAccelerator); | 447 DISALLOW_COPY_AND_ASSIGN(V4L2VideoDecodeAccelerator); |
448 }; | 448 }; |
449 | 449 |
450 } // namespace content | 450 } // namespace content |
451 | 451 |
452 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ | 452 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |