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