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 | |
50 // Processes one decode request in the queue. | |
51 void DecodeTask(); | |
52 | |
53 // Helper for destroy, doing all the actual work except for deleting self. | |
54 void Cleanup(); | |
55 | |
56 // Puts contents of |va_surface| into given |video_frame|, releases the | |
57 // surface and passes the buffer id of the resulting picture to client for | |
58 // output. | |
59 bool OutputPicture(VASurfaceID va_surface_id, | |
60 int32_t input_buffer_id, | |
61 const scoped_refptr<media::VideoFrame>& video_frame); | |
62 | |
63 // Protects |decode_requests_| and |initialized_|. | |
64 base::Lock lock_; | |
piman
2015/05/26 23:31:53
I think you can remove this lock altogether, if yo
kcwu
2015/05/28 12:10:26
Done.
| |
65 bool initialized_; | |
66 | |
67 // An input buffer and the corresponding output video frame awaiting | |
68 // consumption, provided by the client. | |
69 struct DecodeRequest { | |
70 DecodeRequest(const media::BitstreamBuffer& bitstream_buffer, | |
71 scoped_refptr<media::VideoFrame> video_frame); | |
72 ~DecodeRequest(); | |
73 | |
74 media::BitstreamBuffer bitstream_buffer; | |
75 scoped_refptr<media::VideoFrame> video_frame; | |
76 }; | |
77 | |
78 // Queue for incoming decode requests. | |
79 typedef std::queue<linked_ptr<DecodeRequest>> DecodeRequests; | |
80 DecodeRequests decode_requests_; | |
81 | |
82 // ChildThread's task runner. | |
83 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
84 | |
85 // GPU IO task runner. | |
86 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
87 | |
88 // The client of this class. | |
89 Client* client_; | |
90 | |
91 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder | |
92 // thread back to the ChildThread. Because the decoder thread is a member of | |
93 // this class, any task running on the decoder thread is guaranteed that this | |
94 // object is still alive. As a result, tasks posted from ChildThread to | |
95 // decoder thread should use base::Unretained(this), and tasks posted from the | |
96 // decoder thread to the ChildThread should use |weak_this_|. | |
97 base::WeakPtr<VaapiJpegDecodeAccelerator> weak_this_; | |
98 | |
99 scoped_ptr<VaapiWrapper> vaapi_wrapper_; | |
100 | |
101 // Comes after vaapi_wrapper_ to ensure its destructor is executed before | |
102 // |vaapi_wrapper_| is destroyed. | |
103 scoped_ptr<VaapiJpegDecoder> decoder_; | |
104 base::Thread decoder_thread_; | |
105 // Use this to post tasks to |decoder_thread_| instead of | |
106 // |decoder_thread_.task_runner()| because the latter will be NULL once | |
107 // |decoder_thread_.Stop()| returns. | |
108 scoped_refptr<base::SingleThreadTaskRunner> decoder_task_runner_; | |
109 | |
110 // The current VA surface for decoding. | |
111 VASurfaceID va_surface_; | |
112 // The coded size associated with |va_surface_|. | |
113 gfx::Size coded_size_; | |
114 | |
115 // The WeakPtrFactory for |weak_this_|. | |
116 base::WeakPtrFactory<VaapiJpegDecodeAccelerator> weak_this_factory_; | |
117 | |
118 DISALLOW_COPY_AND_ASSIGN(VaapiJpegDecodeAccelerator); | |
119 }; | |
120 | |
121 } // namespace content | |
122 | |
123 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_ | |
OLD | NEW |