OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 // This file contains an implementation of VideoDecoderAccelerator | |
6 // that utilizes hardware video decoder present on Intel CPUs. | |
7 | |
8 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | |
9 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | |
10 | |
11 #include "vaapi_h264_decoder.h" | |
12 | |
13 #include <map> | |
Ami GONE FROM CHROMIUM
2012/04/09 21:35:53
Unused.
(please make a pass on the CL to verify he
Pawel Osciak
2012/05/03 16:22:07
Done.
| |
14 #include <queue> | |
15 #include <utility> | |
16 #include <vector> | |
17 | |
18 #include <GL/glx.h> | |
19 | |
20 #include "base/logging.h" | |
21 #include "base/memory/ref_counted.h" | |
22 #include "base/message_loop.h" | |
23 #include "base/shared_memory.h" | |
24 #include "base/synchronization/waitable_event.h" | |
25 #include "base/threading/non_thread_safe.h" | |
26 #include "base/threading/thread.h" | |
27 #include "media/base/bitstream_buffer.h" | |
28 #include "media/video/picture.h" | |
29 #include "media/video/video_decode_accelerator.h" | |
30 | |
31 // Class to provide video decode acceleration for Intel systems with hardware | |
32 // support for it, and on which libva is available. | |
33 // Decoding tasks are performed in a separate decoding thread. | |
34 class VaapiVideoDecodeAccelerator | |
35 : public media::VideoDecodeAccelerator, | |
36 NON_EXPORTED_BASE(public base::NonThreadSafe) { | |
Ami GONE FROM CHROMIUM
2012/04/09 21:35:53
I don't think you understand what NonThreadSafe is
Pawel Osciak
2012/05/03 16:22:07
Kind of :) I used to use CalledOnValidThread() tho
| |
37 public: | |
38 | |
39 VaapiVideoDecodeAccelerator(media::VideoDecodeAccelerator::Client* client); | |
Ami GONE FROM CHROMIUM
2012/04/09 21:35:53
s/media::VideoDecodeAccelerator::// I think (since
Pawel Osciak
2012/05/03 16:22:07
Done.
| |
40 | |
41 // media::VideoDecodeAccelerator implementation. | |
42 bool Initialize(media::VideoCodecProfile profile) OVERRIDE; | |
Ami GONE FROM CHROMIUM
2012/04/09 21:35:53
missing "virtual" keyword from many methods.
Pawel Osciak
2012/05/03 16:22:07
Done.
| |
43 void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | |
44 virtual void AssignPictureBuffers( | |
45 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; | |
46 void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | |
47 void Flush() OVERRIDE; | |
48 void Reset() OVERRIDE; | |
49 void Destroy() OVERRIDE; | |
50 | |
51 // Used by user of this class to pass X/GLX state. | |
52 void SetGlxState(Display* x_display, GLXContext glx_context); | |
53 | |
54 private: | |
55 virtual ~VaapiVideoDecodeAccelerator(); | |
56 | |
57 // Notify the client that initialization is finished (successful or not). | |
Ami GONE FROM CHROMIUM
2012/04/09 21:35:53
See my comment in the .cc file, but I think you ca
Pawel Osciak
2012/05/03 16:22:07
As discussed, I can't do that after all...
| |
58 void NotifyInitializeDone(); | |
59 | |
60 // Notify the client that the input buffer has been consumed. | |
61 void NotifyInputBufferRead(int input_buffer_id); | |
62 | |
63 // Ensure data has been synced with the output texture and notify | |
64 // the client it is ready for displaying. | |
65 void SyncAndNotifyPictureReady(int32 input_id, int32 output_id); | |
66 | |
67 // Notify the client that Reset or Flush have finished. | |
68 void NotifyResetDone(); | |
69 void NotifyFlushDone(); | |
70 | |
71 // Ask the client to provide |num_pics| textures of size |width| per |height| | |
72 void RequestPictureBuffers(int num_pics, int width, int height); | |
73 | |
74 // Notify the client that an error has occured and decoding cannot continue. | |
75 void StopOnError(media::VideoDecodeAccelerator::Error error); | |
76 | |
77 // Map the received input buffer into this process' address space and | |
78 // queue it for use. | |
Ami GONE FROM CHROMIUM
2012/04/09 21:35:53
s/use/decode/
Pawel Osciak
2012/05/03 16:22:07
Done.
| |
79 void MapAndQueueNewInputBuffer( | |
80 const media::BitstreamBuffer& bitstream_buffer); | |
81 | |
82 // Request and sets up a new input stream buffer for decoder if available. | |
83 // Will release and give back the current input buffer, if present. | |
84 void TryGetNewInputBuffer(); | |
85 | |
86 // Decoding task, executed in decoder's thread context. | |
87 void DecodeTask(); | |
88 | |
89 // Give back an output buffer to the decoder after displaying it. | |
90 // Must be executed on the decoder thread. | |
91 void ReusePictureTask(int32 picture_buffer_id); | |
92 | |
93 // Force the decoder to flush all output pictures. | |
94 // Must be run on the decoder thread. | |
95 void FlushTask(); | |
96 | |
97 // Put the decoder into reset state. | |
98 // Must be run on the decoder thread. | |
99 void ResetTask(); | |
100 | |
101 // Used by the decoder thread to request more input stream. | |
Ami GONE FROM CHROMIUM
2012/04/09 21:35:53
s/stream/streams/
Pawel Osciak
2012/05/03 16:22:07
I chose "more of the input stream" instead.
| |
102 // Must be run on the decoder thread and will sleep until new input | |
103 // becomes available. | |
104 void WaitForInput(); | |
105 | |
106 // Client-provided X/GLX state. | |
107 Display* x_display_; | |
108 GLXContext glx_context_; | |
109 | |
110 // An input buffer awaiting consumption, provided by the client. | |
111 struct InputBuffer { | |
112 int32 id; | |
113 size_t size; | |
114 scoped_ptr<base::SharedMemory> shm; | |
115 }; | |
116 | |
117 // Queue for incoming input buffers. | |
118 typedef std::queue<InputBuffer*> InputBuffers; | |
119 InputBuffers input_buffers_; | |
120 // Current input buffer set in decoder. | |
Ami GONE FROM CHROMIUM
2012/04/09 21:35:53
s/set in/at/
Pawel Osciak
2012/05/03 16:22:07
Done.
| |
121 scoped_ptr<InputBuffer> curr_input_buffer_; | |
122 | |
123 // Signalled if a valid stream is set up in decoder. Used to synchronize | |
124 // between decoder and main thread to safely update current stream in decoder | |
125 // from the |input_buffers_| queue. | |
126 base::WaitableEvent input_ready_; | |
127 | |
Ami GONE FROM CHROMIUM
2012/04/09 21:35:53
In your quest to keep threading concerns out of th
Pawel Osciak
2012/05/03 16:22:07
Well, this is still contained to VAVDA, and does n
| |
128 // Main thread's message loop | |
129 MessageLoop* message_loop_; | |
130 | |
131 // To expose client callbacks from VideoDecodeAccelerator. | |
132 // NOTE: all calls to this object *MUST* be executed in message_loop_. | |
133 Client* client_; | |
134 | |
135 // True if output pictures have been requested from the client. | |
136 bool pictures_requested_; | |
137 | |
138 // True if we are after reset and need to resume. | |
139 bool after_reset_; | |
140 | |
141 // True if we are resetting. | |
142 bool resetting_; | |
143 | |
144 base::Thread decoder_thread_; | |
145 content::VaapiH264Decoder decoder_; | |
146 | |
147 // Callback passed to the decoder, which it will use to signal readiness | |
148 // of an output picture to be displayed. | |
149 static void OutputPicCallback(VaapiVideoDecodeAccelerator* vavda, | |
Ami GONE FROM CHROMIUM
2012/04/09 21:35:53
It's silly to use a static method and pass |this|
Pawel Osciak
2012/05/03 16:22:07
True, I'm not very much used to the Bind-style pro
| |
150 int32 input_id, | |
151 int32 output_id); | |
152 | |
153 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); | |
154 }; | |
155 | |
156 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | |
157 | |
OLD | NEW |