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> |
| 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) { |
| 37 public: |
| 38 |
| 39 VaapiVideoDecodeAccelerator(media::VideoDecodeAccelerator::Client* client); |
| 40 |
| 41 // media::VideoDecodeAccelerator implementation. |
| 42 bool Initialize(Profile profile) OVERRIDE; |
| 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). |
| 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. |
| 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. |
| 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. |
| 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 |
| 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 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(void* priv, int32 input_id, int32 output_id); |
| 150 |
| 151 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); |
| 152 }; |
| 153 |
| 154 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
| 155 |
OLD | NEW |