OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/capture/win/sink_input_pin_win.h" | 5 #include "media/video/capture/win/sink_input_pin_win.h" |
6 | 6 |
7 #include <cstring> | 7 #include <cstring> |
8 | 8 |
9 // Avoid including strsafe.h via dshow as it will cause build warnings. | 9 // Avoid including strsafe.h via dshow as it will cause build warnings. |
10 #define NO_DSHOW_STRSAFE | 10 #define NO_DSHOW_STRSAFE |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 pvi->bmiHeader = requested_info_header_; | 61 pvi->bmiHeader = requested_info_header_; |
62 return true; | 62 return true; |
63 } | 63 } |
64 | 64 |
65 switch (index) { | 65 switch (index) { |
66 case 0: { | 66 case 0: { |
67 pvi->bmiHeader.biCompression = MAKEFOURCC('I', '4', '2', '0'); | 67 pvi->bmiHeader.biCompression = MAKEFOURCC('I', '4', '2', '0'); |
68 pvi->bmiHeader.biBitCount = 12; // bit per pixel | 68 pvi->bmiHeader.biBitCount = 12; // bit per pixel |
69 pvi->bmiHeader.biWidth = requested_info_header_.biWidth; | 69 pvi->bmiHeader.biWidth = requested_info_header_.biWidth; |
70 pvi->bmiHeader.biHeight = requested_info_header_.biHeight; | 70 pvi->bmiHeader.biHeight = requested_info_header_.biHeight; |
71 pvi->bmiHeader.biSizeImage = | 71 pvi->bmiHeader.biSizeImage = GetArea(requested_info_header_) * 3 / 2; |
72 GetArea(requested_info_header_) * 3 / 2; | |
73 media_type->subtype = kMediaSubTypeI420; | 72 media_type->subtype = kMediaSubTypeI420; |
74 break; | 73 break; |
75 } | 74 } |
76 case 1: { | 75 case 1: { |
77 pvi->bmiHeader.biCompression = MAKEFOURCC('Y', 'U', 'Y', '2'); | 76 pvi->bmiHeader.biCompression = MAKEFOURCC('Y', 'U', 'Y', '2'); |
78 pvi->bmiHeader.biBitCount = 16; | 77 pvi->bmiHeader.biBitCount = 16; |
79 pvi->bmiHeader.biWidth = requested_info_header_.biWidth; | 78 pvi->bmiHeader.biWidth = requested_info_header_.biWidth; |
80 pvi->bmiHeader.biHeight = requested_info_header_.biHeight; | 79 pvi->bmiHeader.biHeight = requested_info_header_.biHeight; |
81 pvi->bmiHeader.biSizeImage = GetArea(requested_info_header_) * 2; | 80 pvi->bmiHeader.biSizeImage = GetArea(requested_info_header_) * 2; |
82 media_type->subtype = MEDIASUBTYPE_YUY2; | 81 media_type->subtype = MEDIASUBTYPE_YUY2; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 pvi->bmiHeader.biCompression == BI_RGB) { | 143 pvi->bmiHeader.biCompression == BI_RGB) { |
145 resulting_format_.pixel_format = PIXEL_FORMAT_RGB24; | 144 resulting_format_.pixel_format = PIXEL_FORMAT_RGB24; |
146 return true; // This format is acceptable. | 145 return true; // This format is acceptable. |
147 } | 146 } |
148 return false; | 147 return false; |
149 } | 148 } |
150 | 149 |
151 HRESULT SinkInputPin::Receive(IMediaSample* sample) { | 150 HRESULT SinkInputPin::Receive(IMediaSample* sample) { |
152 const int length = sample->GetActualDataLength(); | 151 const int length = sample->GetActualDataLength(); |
153 uint8* buffer = NULL; | 152 uint8* buffer = NULL; |
| 153 |
| 154 if (length <= 0) { |
| 155 DLOG(WARNING) << "Media sample length is 0 or less."; |
| 156 return S_FALSE; |
| 157 } |
| 158 |
154 if (FAILED(sample->GetPointer(&buffer))) | 159 if (FAILED(sample->GetPointer(&buffer))) |
155 return S_FALSE; | 160 return S_FALSE; |
156 | 161 |
157 observer_->FrameReceived(buffer, length); | 162 observer_->FrameReceived(buffer, length); |
158 return S_OK; | 163 return S_OK; |
159 } | 164 } |
160 | 165 |
161 void SinkInputPin::SetRequestedMediaFormat( | 166 void SinkInputPin::SetRequestedMediaFormat( |
162 VideoPixelFormat pixel_format, | 167 VideoPixelFormat pixel_format, |
163 float frame_rate, | 168 float frame_rate, |
164 const BITMAPINFOHEADER& info_header) { | 169 const BITMAPINFOHEADER& info_header) { |
165 requested_pixel_format_ = pixel_format; | 170 requested_pixel_format_ = pixel_format; |
166 requested_frame_rate_ = frame_rate; | 171 requested_frame_rate_ = frame_rate; |
167 requested_info_header_ = info_header; | 172 requested_info_header_ = info_header; |
168 resulting_format_.frame_size.SetSize(0, 0); | 173 resulting_format_.frame_size.SetSize(0, 0); |
169 resulting_format_.frame_rate = 0; | 174 resulting_format_.frame_rate = 0; |
170 resulting_format_.pixel_format = PIXEL_FORMAT_UNKNOWN; | 175 resulting_format_.pixel_format = PIXEL_FORMAT_UNKNOWN; |
171 } | 176 } |
172 | 177 |
173 const VideoCaptureFormat& SinkInputPin::ResultingFormat() { | 178 const VideoCaptureFormat& SinkInputPin::ResultingFormat() { |
174 return resulting_format_; | 179 return resulting_format_; |
175 } | 180 } |
176 | 181 |
177 } // namespace media | 182 } // namespace media |
OLD | NEW |