OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_ | |
6 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_ | |
7 | |
8 #include <queue> | |
9 | |
10 #include "base/memory/linked_ptr.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "base/single_thread_task_runner.h" | |
13 #include "base/synchronization/lock.h" | |
14 #include "base/threading/non_thread_safe.h" | |
15 #include "base/threading/thread.h" | |
16 #include "content/common/content_export.h" | |
17 #include "content/common/gpu/media/vaapi_jpeg_decoder.h" | |
18 #include "content/common/gpu/media/vaapi_wrapper.h" | |
19 #include "media/base/bitstream_buffer.h" | |
20 #include "media/video/jpeg_decode_accelerator.h" | |
21 | |
22 namespace content { | |
23 | |
24 // Class to provide JPEG decode acceleration for Intel systems with hardware | |
25 // support for it, and on which libva is available. | |
26 // Decoding tasks are performed in a separate decoding thread. | |
27 // | |
28 // Threading/life-cycle: this object is created & destroyed on the GPU | |
29 // ChildThread. A few methods on it are called on the decoder thread which is | |
30 // stopped during |this->Destroy()|, so any tasks posted to the decoder thread | |
31 // can assume |*this| is still alive. See |weak_this_| below for more details. | |
32 class CONTENT_EXPORT VaapiJpegDecodeAccelerator | |
33 : public media::JpegDecodeAccelerator { | |
34 public: | |
35 VaapiJpegDecodeAccelerator( | |
36 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | |
37 ~VaapiJpegDecodeAccelerator() override; | |
38 | |
39 // media::JpegDecodeAccelerator implementation. | |
40 bool Initialize(media::JpegDecodeAccelerator::Client* client) override; | |
41 void Decode(const media::BitstreamBuffer& bitstream_buffer, | |
42 const scoped_refptr<media::VideoFrame>& video_frame) override; | |
43 | |
44 private: | |
45 // Notifies the client that an error has occurred and decoding cannot | |
46 // continue. | |
47 void NotifyError(int32_t bitstream_buffer_id, Error error); | |
48 void NotifyErrorFromDecoderThread(int32_t bitstream_buffer_id, Error error); | |
49 void VideoFrameReady(int32_t bitstream_buffer_id); | |
50 | |
51 // Processes one decode request in the queue. | |
Pawel Osciak
2015/05/28 09:13:18
s/queue/decode_requests_ queue/
kcwu
2015/05/28 12:10:28
Acknowledged.
| |
52 void DecodeTask(); | |
53 | |
54 // Helper for destroy, doing all the actual work except for deleting self. | |
Pawel Osciak
2015/05/28 09:13:18
Do we need this helper? It's only called once from
kcwu
2015/05/28 12:10:28
Done.
| |
55 void Cleanup(); | |
56 | |
57 // Puts contents of |va_surface| into given |video_frame|, releases the | |
58 // surface and passes the buffer id of the resulting picture to client for | |
Pawel Osciak
2015/05/28 09:13:18
s/buffer id/|input_buffer_id|/ ?
kcwu
2015/05/28 12:10:28
Done.
| |
59 // output. | |
60 bool OutputPicture(VASurfaceID va_surface_id, | |
61 int32_t input_buffer_id, | |
62 const scoped_refptr<media::VideoFrame>& video_frame); | |
63 | |
64 // Protects |decode_requests_| and |initialized_|. | |
Pawel Osciak
2015/05/28 09:13:18
Could we instead post a task to decoder thread to
kcwu
2015/05/28 12:10:28
Done.
| |
65 base::Lock lock_; | |
66 bool initialized_; | |
Pawel Osciak
2015/05/28 09:13:18
Since we Stop() the decoder thread before setting
kcwu
2015/05/28 12:10:28
Done.
| |
67 | |
68 // An input buffer and the corresponding output video frame awaiting | |
69 // consumption, provided by the client. | |
70 struct DecodeRequest { | |
71 DecodeRequest(const media::BitstreamBuffer& bitstream_buffer, | |
72 scoped_refptr<media::VideoFrame> video_frame); | |
73 ~DecodeRequest(); | |
74 | |
75 media::BitstreamBuffer bitstream_buffer; | |
76 scoped_refptr<media::VideoFrame> video_frame; | |
77 }; | |
78 | |
79 // Queue for incoming decode requests. | |
80 typedef std::queue<linked_ptr<DecodeRequest>> DecodeRequests; | |
Pawel Osciak
2015/05/28 09:13:18
You may want to use the new c++11 style (if you li
kcwu
2015/05/28 12:10:28
Acknowledged.
| |
81 DecodeRequests decode_requests_; | |
82 | |
83 // ChildThread's task runner. | |
84 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
85 | |
86 // GPU IO task runner. | |
87 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
88 | |
89 // The client of this class. | |
90 Client* client_; | |
Pawel Osciak
2015/05/28 09:13:18
Could we use a WeakPtr instead?
kcwu
2015/05/28 12:10:28
It was. And we found it could be not a WeakPtr fro
| |
91 | |
92 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder | |
93 // thread back to the ChildThread. Because the decoder thread is a member of | |
94 // this class, any task running on the decoder thread is guaranteed that this | |
95 // object is still alive. As a result, tasks posted from ChildThread to | |
96 // decoder thread should use base::Unretained(this), and tasks posted from the | |
97 // decoder thread to the ChildThread should use |weak_this_|. | |
98 base::WeakPtr<VaapiJpegDecodeAccelerator> weak_this_; | |
99 | |
100 scoped_ptr<VaapiWrapper> vaapi_wrapper_; | |
101 | |
102 // Comes after vaapi_wrapper_ to ensure its destructor is executed before | |
103 // |vaapi_wrapper_| is destroyed. | |
104 scoped_ptr<VaapiJpegDecoder> decoder_; | |
105 base::Thread decoder_thread_; | |
106 // Use this to post tasks to |decoder_thread_| instead of | |
107 // |decoder_thread_.task_runner()| because the latter will be NULL once | |
108 // |decoder_thread_.Stop()| returns. | |
109 scoped_refptr<base::SingleThreadTaskRunner> decoder_task_runner_; | |
110 | |
111 // The current VA surface for decoding. | |
112 VASurfaceID va_surface_; | |
Pawel Osciak
2015/05/28 09:13:18
s/va_surface_/va_surface_id_/
kcwu
2015/05/28 12:10:28
Done.
| |
113 // The coded size associated with |va_surface_|. | |
114 gfx::Size coded_size_; | |
115 | |
116 // The WeakPtrFactory for |weak_this_|. | |
117 base::WeakPtrFactory<VaapiJpegDecodeAccelerator> weak_this_factory_; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(VaapiJpegDecodeAccelerator); | |
120 }; | |
121 | |
122 } // namespace content | |
123 | |
124 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_ | |
OLD | NEW |