| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" // For OS_WIN. | 5 #include "build/build_config.h" // For OS_WIN. |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 | 8 |
| 9 #include "media/mf/mft_h264_decoder.h" | 9 #include "media/mf/mft_h264_decoder.h" |
| 10 | 10 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return; | 165 return; |
| 166 } | 166 } |
| 167 if (!message_loop || !event_handler) { | 167 if (!message_loop || !event_handler) { |
| 168 LOG(ERROR) << "MftH264Decoder::Initialize: parameters cannot be NULL"; | 168 LOG(ERROR) << "MftH264Decoder::Initialize: parameters cannot be NULL"; |
| 169 return; | 169 return; |
| 170 } | 170 } |
| 171 | 171 |
| 172 config_ = config; | 172 config_ = config; |
| 173 event_handler_ = event_handler; | 173 event_handler_ = event_handler; |
| 174 | 174 |
| 175 info_.provides_buffers_ = true; | 175 info_.provides_buffers = true; |
| 176 | 176 |
| 177 // TODO(jiesun): Actually it is more likely an NV12 D3DSuface9. | 177 // TODO(jiesun): Actually it is more likely an NV12 D3DSuface9. |
| 178 // Until we had hardware composition working. | 178 // Until we had hardware composition working. |
| 179 if (use_dxva_) { | 179 if (use_dxva_) { |
| 180 info_.stream_info_.surface_format_ = VideoFrame::YV12; | 180 info_.stream_info.surface_format = VideoFrame::YV12; |
| 181 info_.stream_info_.surface_type_ = VideoFrame::TYPE_SYSTEM_MEMORY; | 181 info_.stream_info.surface_type = VideoFrame::TYPE_SYSTEM_MEMORY; |
| 182 } else { | 182 } else { |
| 183 info_.stream_info_.surface_format_ = VideoFrame::YV12; | 183 info_.stream_info.surface_format = VideoFrame::YV12; |
| 184 info_.stream_info_.surface_type_ = VideoFrame::TYPE_SYSTEM_MEMORY; | 184 info_.stream_info.surface_type = VideoFrame::TYPE_SYSTEM_MEMORY; |
| 185 } | 185 } |
| 186 | 186 |
| 187 // codec_info.stream_info_.surface_width_/height_ are initialized | 187 // codec_info.stream_info_.surface_width_/height_ are initialized |
| 188 // in InitInternal(). | 188 // in InitInternal(). |
| 189 info_.success_ = InitInternal(); | 189 info_.success = InitInternal(); |
| 190 if (info_.success_) { | 190 if (info_.success) { |
| 191 state_ = kNormal; | 191 state_ = kNormal; |
| 192 event_handler_->OnInitializeComplete(info_); | 192 event_handler_->OnInitializeComplete(info_); |
| 193 } else { | 193 } else { |
| 194 LOG(ERROR) << "MftH264Decoder::Initialize failed"; | 194 LOG(ERROR) << "MftH264Decoder::Initialize failed"; |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 void MftH264Decoder::Uninitialize() { | 198 void MftH264Decoder::Uninitialize() { |
| 199 LOG(INFO) << "MftH264Decoder::Uninitialize"; | 199 LOG(INFO) << "MftH264Decoder::Uninitialize"; |
| 200 if (state_ == kUninitialized) { | 200 if (state_ == kUninitialized) { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 GUID out_subtype; | 484 GUID out_subtype; |
| 485 HRESULT hr = out_media_type->GetGUID(MF_MT_SUBTYPE, &out_subtype); | 485 HRESULT hr = out_media_type->GetGUID(MF_MT_SUBTYPE, &out_subtype); |
| 486 if (FAILED(hr)) { | 486 if (FAILED(hr)) { |
| 487 LOG(ERROR) << "Failed to GetGUID() on GetOutputAvailableType() " << i; | 487 LOG(ERROR) << "Failed to GetGUID() on GetOutputAvailableType() " << i; |
| 488 out_media_type->Release(); | 488 out_media_type->Release(); |
| 489 continue; | 489 continue; |
| 490 } | 490 } |
| 491 if (out_subtype == subtype) { | 491 if (out_subtype == subtype) { |
| 492 hr = decoder_->SetOutputType(0, out_media_type, 0); // No flags | 492 hr = decoder_->SetOutputType(0, out_media_type, 0); // No flags |
| 493 hr = MFGetAttributeSize(out_media_type, MF_MT_FRAME_SIZE, | 493 hr = MFGetAttributeSize(out_media_type, MF_MT_FRAME_SIZE, |
| 494 reinterpret_cast<UINT32*>(&info_.stream_info_.surface_width_), | 494 reinterpret_cast<UINT32*>(&info_.stream_info.surface_width), |
| 495 reinterpret_cast<UINT32*>(&info_.stream_info_.surface_height_)); | 495 reinterpret_cast<UINT32*>(&info_.stream_info.surface_height)); |
| 496 config_.width_ = info_.stream_info_.surface_width_; | 496 config_.width = info_.stream_info.surface_width; |
| 497 config_.height_ = info_.stream_info_.surface_height_; | 497 config_.height = info_.stream_info.surface_height; |
| 498 if (FAILED(hr)) { | 498 if (FAILED(hr)) { |
| 499 LOG(ERROR) << "Failed to SetOutputType to |subtype| or obtain " | 499 LOG(ERROR) << "Failed to SetOutputType to |subtype| or obtain " |
| 500 << "width/height " << std::hex << hr; | 500 << "width/height " << std::hex << hr; |
| 501 } else { | 501 } else { |
| 502 out_media_type->Release(); | 502 out_media_type->Release(); |
| 503 return true; | 503 return true; |
| 504 } | 504 } |
| 505 } | 505 } |
| 506 i++; | 506 i++; |
| 507 out_media_type->Release(); | 507 out_media_type->Release(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 if (events != NULL) { | 588 if (events != NULL) { |
| 589 LOG(INFO) << "Got events from ProcessOuput, but discarding"; | 589 LOG(INFO) << "Got events from ProcessOuput, but discarding"; |
| 590 events->Release(); | 590 events->Release(); |
| 591 } | 591 } |
| 592 | 592 |
| 593 if (FAILED(hr)) { | 593 if (FAILED(hr)) { |
| 594 if (hr == MF_E_TRANSFORM_STREAM_CHANGE) { | 594 if (hr == MF_E_TRANSFORM_STREAM_CHANGE) { |
| 595 hr = SetDecoderOutputMediaType(use_dxva_ ? MFVideoFormat_NV12 | 595 hr = SetDecoderOutputMediaType(use_dxva_ ? MFVideoFormat_NV12 |
| 596 : MFVideoFormat_YV12); | 596 : MFVideoFormat_YV12); |
| 597 if (SUCCEEDED(hr)) { | 597 if (SUCCEEDED(hr)) { |
| 598 event_handler_->OnFormatChange(info_.stream_info_); | 598 event_handler_->OnFormatChange(info_.stream_info); |
| 599 return true; | 599 return true; |
| 600 } else { | 600 } else { |
| 601 event_handler_->OnError(); | 601 event_handler_->OnError(); |
| 602 return false; | 602 return false; |
| 603 } | 603 } |
| 604 } else if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) { | 604 } else if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) { |
| 605 if (state_ == kEosDrain) { | 605 if (state_ == kEosDrain) { |
| 606 // No more output from the decoder. Notify EOS and stop playback. | 606 // No more output from the decoder. Notify EOS and stop playback. |
| 607 scoped_refptr<VideoFrame> frame; | 607 scoped_refptr<VideoFrame> frame; |
| 608 VideoFrame::CreateEmptyFrame(&frame); | 608 VideoFrame::CreateEmptyFrame(&frame); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 return true; | 649 return true; |
| 650 } | 650 } |
| 651 | 651 |
| 652 ScopedComPtr<IMFMediaBuffer> output_buffer; | 652 ScopedComPtr<IMFMediaBuffer> output_buffer; |
| 653 hr = output_sample->GetBufferByIndex(0, output_buffer.Receive()); | 653 hr = output_sample->GetBufferByIndex(0, output_buffer.Receive()); |
| 654 if (FAILED(hr)) { | 654 if (FAILED(hr)) { |
| 655 LOG(ERROR) << "Failed to get buffer from sample"; | 655 LOG(ERROR) << "Failed to get buffer from sample"; |
| 656 return true; | 656 return true; |
| 657 } | 657 } |
| 658 | 658 |
| 659 VideoFrame::CreateFrame(info_.stream_info_.surface_format_, | 659 VideoFrame::CreateFrame(info_.stream_info.surface_format, |
| 660 info_.stream_info_.surface_width_, | 660 info_.stream_info.surface_width, |
| 661 info_.stream_info_.surface_height_, | 661 info_.stream_info.surface_height, |
| 662 base::TimeDelta::FromMicroseconds(timestamp), | 662 base::TimeDelta::FromMicroseconds(timestamp), |
| 663 base::TimeDelta::FromMicroseconds(duration), | 663 base::TimeDelta::FromMicroseconds(duration), |
| 664 &frame); | 664 &frame); |
| 665 if (!frame.get()) { | 665 if (!frame.get()) { |
| 666 LOG(ERROR) << "Failed to allocate video frame"; | 666 LOG(ERROR) << "Failed to allocate video frame"; |
| 667 event_handler_->OnError(); | 667 event_handler_->OnError(); |
| 668 return true; | 668 return true; |
| 669 } | 669 } |
| 670 | 670 |
| 671 if (use_dxva_) { | 671 if (use_dxva_) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 689 } | 689 } |
| 690 D3DSURFACE_DESC desc; | 690 D3DSURFACE_DESC desc; |
| 691 hr = surface->GetDesc(&desc); | 691 hr = surface->GetDesc(&desc); |
| 692 if (FAILED(hr)) { | 692 if (FAILED(hr)) { |
| 693 LOG(ERROR) << "GetDesc"; | 693 LOG(ERROR) << "GetDesc"; |
| 694 CHECK(SUCCEEDED(surface->UnlockRect())); | 694 CHECK(SUCCEEDED(surface->UnlockRect())); |
| 695 return true; | 695 return true; |
| 696 } | 696 } |
| 697 | 697 |
| 698 uint32 src_stride = d3dlocked_rect.Pitch; | 698 uint32 src_stride = d3dlocked_rect.Pitch; |
| 699 uint32 dst_stride = config_.width_; | 699 uint32 dst_stride = config_.width; |
| 700 uint8* src_y = static_cast<uint8*>(d3dlocked_rect.pBits); | 700 uint8* src_y = static_cast<uint8*>(d3dlocked_rect.pBits); |
| 701 uint8* src_uv = src_y + src_stride * desc.Height; | 701 uint8* src_uv = src_y + src_stride * desc.Height; |
| 702 uint8* dst_y = static_cast<uint8*>(frame->data(VideoFrame::kYPlane)); | 702 uint8* dst_y = static_cast<uint8*>(frame->data(VideoFrame::kYPlane)); |
| 703 uint8* dst_u = static_cast<uint8*>(frame->data(VideoFrame::kVPlane)); | 703 uint8* dst_u = static_cast<uint8*>(frame->data(VideoFrame::kVPlane)); |
| 704 uint8* dst_v = static_cast<uint8*>(frame->data(VideoFrame::kUPlane)); | 704 uint8* dst_v = static_cast<uint8*>(frame->data(VideoFrame::kUPlane)); |
| 705 | 705 |
| 706 for (int y = 0; y < config_.height_; ++y) { | 706 for (int y = 0; y < config_.height; ++y) { |
| 707 for (int x = 0; x < config_.width_; ++x) { | 707 for (int x = 0; x < config_.width; ++x) { |
| 708 dst_y[x] = src_y[x]; | 708 dst_y[x] = src_y[x]; |
| 709 if (!(y & 1)) { | 709 if (!(y & 1)) { |
| 710 if (x & 1) | 710 if (x & 1) |
| 711 dst_v[x>>1] = src_uv[x]; | 711 dst_v[x>>1] = src_uv[x]; |
| 712 else | 712 else |
| 713 dst_u[x>>1] = src_uv[x]; | 713 dst_u[x>>1] = src_uv[x]; |
| 714 } | 714 } |
| 715 } | 715 } |
| 716 dst_y += dst_stride; | 716 dst_y += dst_stride; |
| 717 src_y += src_stride; | 717 src_y += src_stride; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 735 CHECK(SUCCEEDED(output_buffer->Unlock())); | 735 CHECK(SUCCEEDED(output_buffer->Unlock())); |
| 736 } | 736 } |
| 737 // TODO(jiesun): non-System memory case | 737 // TODO(jiesun): non-System memory case |
| 738 event_handler_->ConsumeVideoFrame(frame); | 738 event_handler_->ConsumeVideoFrame(frame); |
| 739 return true; | 739 return true; |
| 740 } | 740 } |
| 741 | 741 |
| 742 } // namespace media | 742 } // namespace media |
| 743 | 743 |
| 744 #endif // defined(OS_WIN) | 744 #endif // defined(OS_WIN) |
| OLD | NEW |