OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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_DVX_VIDEO_DECODE_ACCELERATOR_H_ |
| 6 #define CONTENT_COMMON_GPU_MEDIA_DVX_VIDEO_DECODE_ACCELERATOR_H_ |
| 7 |
| 8 #include <d3d9.h> |
| 9 #include <dxva2api.h> |
| 10 #include <map> |
| 11 #include <mfidl.h> |
| 12 #include <vector> |
| 13 |
| 14 #include "base/message_loop.h" |
| 15 #include "base/win/scoped_comptr.h" |
| 16 #include "media/video/video_decode_accelerator.h" |
| 17 #include "third_party/angle/include/EGL/egl.h" |
| 18 #include "third_party/angle/include/EGL/eglext.h" |
| 19 |
| 20 interface IMFSample; |
| 21 interface IDirect3DSurface9; |
| 22 |
| 23 // Class to provide a DXVA 2.0 based accelerator behind VideoDecodeAccelerator |
| 24 // interface. |
| 25 // This class lives on a single thread and DCHECKs that it is never accessed |
| 26 // from any other. |
| 27 class DXVAVideoDecodeAccelerator : public media::VideoDecodeAccelerator { |
| 28 public: |
| 29 typedef enum { |
| 30 kUninitialized, // un-initialized. |
| 31 kNormal, // normal playing state. |
| 32 kResetting, // upon received Reset(), before ResetDone() |
| 33 kEosDrain, // upon input EOS received. |
| 34 kStopped, // upon output EOS received. |
| 35 } State; |
| 36 |
| 37 struct DXVAPictureBuffer { |
| 38 DXVAPictureBuffer() |
| 39 : picture_buffer(0, gfx::Size(), 0) { |
| 40 available = false; |
| 41 } |
| 42 bool available; |
| 43 media::PictureBuffer picture_buffer; |
| 44 }; |
| 45 |
| 46 // Does not take ownership of |client| which must outlive |*this|. |
| 47 explicit DXVAVideoDecodeAccelerator( |
| 48 media::VideoDecodeAccelerator::Client* client); |
| 49 virtual ~DXVAVideoDecodeAccelerator(); |
| 50 |
| 51 // media::VideoDecodeAccelerator implementation. |
| 52 bool Initialize(Profile profile) OVERRIDE; |
| 53 void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; |
| 54 virtual void AssignPictureBuffers( |
| 55 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; |
| 56 void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; |
| 57 void Flush() OVERRIDE; |
| 58 void Reset() OVERRIDE; |
| 59 void Destroy() OVERRIDE; |
| 60 |
| 61 void SetEglState(EGLDisplay egl_display, EGLContext egl_context); |
| 62 |
| 63 private: |
| 64 bool CreateD3DDevManager(); |
| 65 bool InitDecoder(); |
| 66 bool CheckDecoderDxvaSupport(); |
| 67 bool SetDecoderMediaTypes(); |
| 68 bool SetDecoderInputMediaType(); |
| 69 bool SetDecoderOutputMediaType(const GUID& subtype); |
| 70 bool SendMFTMessage(MFT_MESSAGE_TYPE msg); |
| 71 bool GetStreamsInfoAndBufferReqs(); |
| 72 bool DoDecode(); |
| 73 bool ProcessOutputSample(IMFSample* sample); |
| 74 bool CopyOutputSampleDataToPictureBuffer(IMFSample* sample, |
| 75 IDirect3DSurface9* surface, |
| 76 media::PictureBuffer buffer); |
| 77 |
| 78 private: |
| 79 MessageLoop* message_loop_; |
| 80 // To expose client callbacks from VideoDecodeAccelerator. |
| 81 // NOTE: all calls to this object *MUST* be executed in message_loop_. |
| 82 media::VideoDecodeAccelerator::Client* client_; |
| 83 |
| 84 EGLDisplay egl_display_; |
| 85 EGLContext egl_context_; |
| 86 base::win::ScopedComPtr<IDirect3D9> d3d9_; |
| 87 base::win::ScopedComPtr<IDirect3DDevice9> device_; |
| 88 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; |
| 89 base::win::ScopedComPtr<IMFTransform> decoder_; |
| 90 |
| 91 UINT32 surface_width_; |
| 92 UINT32 surface_height_; |
| 93 |
| 94 State state_; |
| 95 |
| 96 // Encoded bitstream buffers awaiting decode. |
| 97 typedef std::vector<media::BitstreamBuffer> BitstreamBufferList; |
| 98 BitstreamBufferList queued_bitstream_buffers_; |
| 99 |
| 100 // Available output picture buffers released during Reset() and awaiting |
| 101 // re-use once Reset is done. Is empty most of the time and drained right |
| 102 // before NotifyResetDone is sent. |
| 103 std::vector<int> queued_picture_buffer_ids_; |
| 104 int input_buffers_at_component_; |
| 105 |
| 106 MFT_INPUT_STREAM_INFO input_stream_info_; |
| 107 MFT_OUTPUT_STREAM_INFO output_stream_info_; |
| 108 |
| 109 typedef std::vector<base::win::ScopedComPtr<IMFSample> > |
| 110 PendingOutputSamples; |
| 111 PendingOutputSamples pending_output_samples_; |
| 112 |
| 113 typedef std::map<int32, DXVAPictureBuffer> OutputBuffers; |
| 114 OutputBuffers available_pictures_; |
| 115 }; |
| 116 |
| 117 #endif // CONTENT_COMMON_GPU_MEDIA_DVX_VIDEO_DECODE_ACCELERATOR_H_ |
| 118 |
OLD | NEW |