Index: content/common/gpu/media/dxva_video_decode_accelerator.h |
=================================================================== |
--- content/common/gpu/media/dxva_video_decode_accelerator.h (revision 0) |
+++ content/common/gpu/media/dxva_video_decode_accelerator.h (revision 0) |
@@ -0,0 +1,132 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_COMMON_GPU_MEDIA_DVX_VIDEO_DECODE_ACCELERATOR_H_ |
+#define CONTENT_COMMON_GPU_MEDIA_DVX_VIDEO_DECODE_ACCELERATOR_H_ |
+ |
+#include <d3d9.h> |
+#include <dxva2api.h> |
+#include <map> |
+#include <mfidl.h> |
+#include <vector> |
+ |
+#include "base/message_loop.h" |
+#include "base/win/scoped_comptr.h" |
+#include "media/video/video_decode_accelerator.h" |
+#include "third_party/angle/include/EGL/egl.h" |
+#include "third_party/angle/include/EGL/eglext.h" |
+ |
+interface IMFSample; |
+interface IDirect3DSurface9; |
+ |
+// Class to provide a DXVA 2.0 based accelerator behind VideoDecodeAccelerator |
+// interface. |
+// This class lives on a single thread and DCHECKs that it is never accessed |
+// from any other. |
+class DXVAVideoDecodeAccelerator : public media::VideoDecodeAccelerator { |
+ public: |
+ typedef enum { |
+ kUninitialized, // un-initialized. |
+ kNormal, // normal playing state. |
+ kResetting, // upon received Reset(), before ResetDone() |
+ kEosDrain, // upon input EOS received. |
+ kStopped, // upon output EOS received. |
+ } State; |
+ |
+ // Does not take ownership of |client| which must outlive |*this|. |
+ explicit DXVAVideoDecodeAccelerator( |
+ media::VideoDecodeAccelerator::Client* client, |
+ base::ProcessHandle renderer_process); |
+ virtual ~DXVAVideoDecodeAccelerator(); |
+ |
+ // media::VideoDecodeAccelerator implementation. |
+ bool Initialize(Profile profile) OVERRIDE; |
+ void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; |
+ virtual void AssignPictureBuffers( |
+ const std::vector<media::PictureBuffer>& buffers) OVERRIDE; |
+ void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; |
+ void Flush() OVERRIDE; |
+ void Reset() OVERRIDE; |
+ void Destroy() OVERRIDE; |
+ |
+ private: |
+ bool CreateD3DDevManager(); |
+ bool InitDecoder(); |
+ bool CheckDecoderDxvaSupport(); |
+ bool SetDecoderMediaTypes(); |
+ bool SetDecoderInputMediaType(); |
+ bool SetDecoderOutputMediaType(const GUID& subtype); |
+ bool SendMFTMessage(MFT_MESSAGE_TYPE msg, int32 param); |
+ bool GetStreamsInfoAndBufferReqs(); |
+ bool DoDecode(); |
+ bool ProcessOutputSample(IMFSample* sample); |
+ bool CopyOutputSampleDataToPictureBuffer(IDirect3DSurface9* dest_surface, |
+ media::PictureBuffer buffer, |
+ int32 input_buffer_id); |
+ void ProcessPendingSamples(); |
+ |
+ private: |
+ MessageLoop* message_loop_; |
+ // To expose client callbacks from VideoDecodeAccelerator. |
+ // NOTE: all calls to this object *MUST* be executed in message_loop_. |
+ media::VideoDecodeAccelerator::Client* client_; |
+ |
+ base::win::ScopedComPtr<IDirect3D9> d3d9_; |
+ base::win::ScopedComPtr<IDirect3DDevice9> device_; |
+ base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; |
+ base::win::ScopedComPtr<IMFTransform> decoder_; |
+ |
+ UINT32 surface_width_; |
+ UINT32 surface_height_; |
+ |
+ // Current state of the decoder. |
+ State state_; |
+ |
+ MFT_INPUT_STREAM_INFO input_stream_info_; |
+ MFT_OUTPUT_STREAM_INFO output_stream_info_; |
+ |
+ // Contains information about a decoded sample. |
+ struct PendingSampleInfo { |
+ base::win::ScopedComPtr<IDirect3DSurface9> surface; |
+ int32 input_buffer_id; |
+ }; |
+ |
+ typedef std::vector<PendingSampleInfo> |
+ PendingOutputSamples; |
+ |
+ // List of output samples for rendering. |
+ PendingOutputSamples pending_output_samples_; |
+ |
+ // Maintains information about a DXVA picture buffer, i.e. whether it is |
+ // available for rendering, the texture information, etc. |
+ struct DXVAPictureBuffer { |
+ DXVAPictureBuffer() |
+ : picture_buffer(0, gfx::Size(), 0) { |
+ available = false; |
+ } |
+ bool available; |
+ media::PictureBuffer picture_buffer; |
+ }; |
+ |
+ typedef std::map<int32, DXVAPictureBuffer> OutputBuffers; |
+ OutputBuffers available_pictures_; |
+ |
+ // Set to true if we requested picture slots from the plugin. |
+ bool pictures_requested_; |
+ |
+ // Contains the list of input buffer ids which map to frame time from the |
+ // plugin. |
+ std::vector<int32> input_buffer_frame_times_; |
+ |
+ // Handle to the renderer process. |
+ base::ProcessHandle renderer_process_; |
+ |
+#if !defined(NDEBUG) |
+ uint32 decode_start_time_; |
+ int inputs_before_decode_; |
+#endif // !defined(NDEBUG) |
+}; |
+ |
+#endif // CONTENT_COMMON_GPU_MEDIA_DVX_VIDEO_DECODE_ACCELERATOR_H_ |
+ |