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