OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/video/mft_h264_decode_engine.h" | 5 #include "media/video/mft_h264_decode_engine.h" |
6 | 6 |
7 #include <d3d9.h> | 7 #include <d3d9.h> |
8 #include <dxva2api.h> | 8 #include <dxva2api.h> |
9 #include <initguid.h> | 9 #include <initguid.h> |
10 #include <mfapi.h> | 10 #include <mfapi.h> |
11 // Placed after mfapi.h to avoid linking strmiids.lib for MR_BUFFER_SERVICE. | 11 // Placed after mfapi.h to avoid linking strmiids.lib for MR_BUFFER_SERVICE. |
12 #include <evr.h> | 12 #include <evr.h> |
13 #include <mferror.h> | 13 #include <mferror.h> |
14 #include <wmcodecdsp.h> | 14 #include <wmcodecdsp.h> |
15 | 15 |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
18 #include "media/base/limits.h" | 18 #include "media/base/limits.h" |
19 #include "media/base/pipeline.h" | 19 #include "media/base/pipeline.h" |
20 #include "media/video/video_decode_context.h" | 20 #include "media/video/video_decode_context.h" |
21 | 21 |
22 #pragma comment(lib, "dxva2.lib") | 22 #pragma comment(lib, "dxva2.lib") |
23 #pragma comment(lib, "d3d9.lib") | 23 #pragma comment(lib, "d3d9.lib") |
24 #pragma comment(lib, "mf.lib") | 24 #pragma comment(lib, "mf.lib") |
25 #pragma comment(lib, "mfplat.lib") | 25 #pragma comment(lib, "mfplat.lib") |
26 | 26 |
27 using base::TimeDelta; | 27 using base::TimeDelta; |
28 | 28 |
29 namespace { | 29 namespace media { |
30 | 30 |
31 // Creates an empty Media Foundation sample with no buffers. | 31 // Creates an empty Media Foundation sample with no buffers. |
32 static IMFSample* CreateEmptySample() { | 32 static IMFSample* CreateEmptySample() { |
33 HRESULT hr; | 33 HRESULT hr; |
34 ScopedComPtr<IMFSample> sample; | 34 ScopedComPtr<IMFSample> sample; |
35 hr = MFCreateSample(sample.Receive()); | 35 hr = MFCreateSample(sample.Receive()); |
36 if (FAILED(hr)) { | 36 if (FAILED(hr)) { |
37 LOG(ERROR) << "Unable to create an empty sample"; | 37 LOG(ERROR) << "Unable to create an empty sample"; |
38 return NULL; | 38 return NULL; |
39 } | 39 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 CHECK(SUCCEEDED(buffer->Unlock())); | 125 CHECK(SUCCEEDED(buffer->Unlock())); |
126 hr = buffer->SetCurrentLength(size); | 126 hr = buffer->SetCurrentLength(size); |
127 if (FAILED(hr)) { | 127 if (FAILED(hr)) { |
128 LOG(ERROR) << "Failed to set current length to " << size; | 128 LOG(ERROR) << "Failed to set current length to " << size; |
129 return NULL; | 129 return NULL; |
130 } | 130 } |
131 VLOG(1) << __FUNCTION__ << " wrote " << size << " bytes into input sample"; | 131 VLOG(1) << __FUNCTION__ << " wrote " << size << " bytes into input sample"; |
132 return sample.Detach(); | 132 return sample.Detach(); |
133 } | 133 } |
134 | 134 |
135 const GUID ConvertVideoFrameFormatToGuid(media::VideoFrame::Format format) { | 135 const GUID ConvertVideoFrameFormatToGuid(VideoFrame::Format format) { |
136 switch (format) { | 136 switch (format) { |
137 case media::VideoFrame::NV12: | 137 case VideoFrame::NV12: |
138 return MFVideoFormat_NV12; | 138 return MFVideoFormat_NV12; |
139 case media::VideoFrame::YV12: | 139 case VideoFrame::YV12: |
140 return MFVideoFormat_YV12; | 140 return MFVideoFormat_YV12; |
141 default: | 141 default: |
142 NOTREACHED() << "Unsupported VideoFrame format"; | 142 NOTREACHED() << "Unsupported VideoFrame format"; |
143 return GUID_NULL; | 143 return GUID_NULL; |
144 } | 144 } |
145 NOTREACHED(); | 145 NOTREACHED(); |
146 return GUID_NULL; | 146 return GUID_NULL; |
147 } | 147 } |
148 | 148 |
149 } // namespace | |
150 | |
151 namespace media { | |
152 | |
153 // public methods | 149 // public methods |
154 | 150 |
155 MftH264DecodeEngine::MftH264DecodeEngine(bool use_dxva) | 151 MftH264DecodeEngine::MftH264DecodeEngine(bool use_dxva) |
156 : use_dxva_(use_dxva), | 152 : use_dxva_(use_dxva), |
157 state_(kUninitialized), | 153 state_(kUninitialized), |
158 event_handler_(NULL), | 154 event_handler_(NULL), |
159 context_(NULL) { | 155 context_(NULL) { |
160 memset(&input_stream_info_, 0, sizeof(input_stream_info_)); | 156 memset(&input_stream_info_, 0, sizeof(input_stream_info_)); |
161 memset(&output_stream_info_, 0, sizeof(output_stream_info_)); | 157 memset(&output_stream_info_, 0, sizeof(output_stream_info_)); |
162 memset(&config_, 0, sizeof(config_)); | 158 memset(&config_, 0, sizeof(config_)); |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 uint8* dst_y = static_cast<uint8*>(frame->data(VideoFrame::kYPlane)); | 678 uint8* dst_y = static_cast<uint8*>(frame->data(VideoFrame::kYPlane)); |
683 | 679 |
684 memcpy(dst_y, src_y, current_length); | 680 memcpy(dst_y, src_y, current_length); |
685 CHECK(SUCCEEDED(output_buffer->Unlock())); | 681 CHECK(SUCCEEDED(output_buffer->Unlock())); |
686 event_handler_->ConsumeVideoFrame(frame, statistics); | 682 event_handler_->ConsumeVideoFrame(frame, statistics); |
687 return true; | 683 return true; |
688 } | 684 } |
689 | 685 |
690 void MftH264DecodeEngine::OnUploadVideoFrameDone( | 686 void MftH264DecodeEngine::OnUploadVideoFrameDone( |
691 ScopedComPtr<IDirect3DSurface9, &IID_IDirect3DSurface9> surface, | 687 ScopedComPtr<IDirect3DSurface9, &IID_IDirect3DSurface9> surface, |
692 scoped_refptr<media::VideoFrame> frame, | 688 scoped_refptr<VideoFrame> frame, |
693 PipelineStatistics statistics) { | 689 PipelineStatistics statistics) { |
694 // After this method is exited the reference to surface is released. | 690 // After this method is exited the reference to surface is released. |
695 event_handler_->ConsumeVideoFrame(frame, statistics); | 691 event_handler_->ConsumeVideoFrame(frame, statistics); |
696 } | 692 } |
697 | 693 |
698 } // namespace media | 694 } // namespace media |
699 | 695 |
700 DISABLE_RUNNABLE_METHOD_REFCOUNT(media::MftH264DecodeEngine); | 696 DISABLE_RUNNABLE_METHOD_REFCOUNT(media::MftH264DecodeEngine); |
OLD | NEW |