| 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/capture/video/win/sink_input_pin_win.h" | 5 #include "media/capture/video/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 |
| 11 #include <dshow.h> | 11 #include <dshow.h> |
| 12 #include <stdint.h> | 12 #include <stdint.h> |
| 13 | 13 |
| 14 #include "base/big_endian.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "media/base/timestamp_constants.h" | 17 #include "media/base/timestamp_constants.h" |
| 17 | 18 |
| 18 namespace media { | 19 namespace media { |
| 19 | 20 |
| 20 const REFERENCE_TIME kSecondsToReferenceTime = 10000000; | 21 const REFERENCE_TIME kSecondsToReferenceTime = 10000000; |
| 21 | 22 |
| 22 static DWORD GetArea(const BITMAPINFOHEADER& info_header) { | 23 static DWORD GetArea(const BITMAPINFOHEADER& info_header) { |
| 23 return info_header.biWidth * info_header.biHeight; | 24 return info_header.biWidth * info_header.biHeight; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 pvi->bmiHeader.biCompression == BI_RGB) { | 90 pvi->bmiHeader.biCompression == BI_RGB) { |
| 90 resulting_format_.pixel_format = PIXEL_FORMAT_RGB24; | 91 resulting_format_.pixel_format = PIXEL_FORMAT_RGB24; |
| 91 return true; | 92 return true; |
| 92 } | 93 } |
| 93 if (sub_type == MEDIASUBTYPE_RGB32 && | 94 if (sub_type == MEDIASUBTYPE_RGB32 && |
| 94 pvi->bmiHeader.biCompression == BI_RGB) { | 95 pvi->bmiHeader.biCompression == BI_RGB) { |
| 95 resulting_format_.pixel_format = PIXEL_FORMAT_RGB32; | 96 resulting_format_.pixel_format = PIXEL_FORMAT_RGB32; |
| 96 return true; | 97 return true; |
| 97 } | 98 } |
| 98 | 99 |
| 100 if (sub_type.Data1 == pvi->bmiHeader.biCompression) { |
| 101 // TODO(astojilj) Define GUIDs and move this to common place as the code is |
| 102 // replicated around. |
| 103 uint32_t fourcc; |
| 104 base::ReadBigEndian(reinterpret_cast<const char*>(&sub_type.Data1), |
| 105 &fourcc); |
| 106 if (fourcc == 'Z16 ' || fourcc == 'INVZ') { |
| 107 resulting_format_.pixel_format = PIXEL_FORMAT_Y16; |
| 108 return true; |
| 109 } else if (fourcc == 'Y8 ') { |
| 110 resulting_format_.pixel_format = PIXEL_FORMAT_Y8; |
| 111 return true; |
| 112 } |
| 113 } |
| 114 |
| 99 #ifndef NDEBUG | 115 #ifndef NDEBUG |
| 100 WCHAR guid_str[128]; | 116 WCHAR guid_str[128]; |
| 101 StringFromGUID2(sub_type, guid_str, arraysize(guid_str)); | 117 StringFromGUID2(sub_type, guid_str, arraysize(guid_str)); |
| 102 DVLOG(2) << __func__ << " unsupported media type: " << guid_str; | 118 DVLOG(2) << __func__ << " unsupported media type: " << guid_str; |
| 103 #endif | 119 #endif |
| 104 return false; | 120 return false; |
| 105 } | 121 } |
| 106 | 122 |
| 107 bool SinkInputPin::GetValidMediaType(int index, AM_MEDIA_TYPE* media_type) { | 123 bool SinkInputPin::GetValidMediaType(int index, AM_MEDIA_TYPE* media_type) { |
| 108 if (media_type->cbFormat < sizeof(VIDEOINFOHEADER)) | 124 if (media_type->cbFormat < sizeof(VIDEOINFOHEADER)) |
| 109 return false; | 125 return false; |
| 110 | 126 |
| 111 VIDEOINFOHEADER* const pvi = | 127 VIDEOINFOHEADER* const pvi = |
| 112 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); | 128 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); |
| 113 | 129 |
| 114 ZeroMemory(pvi, sizeof(VIDEOINFOHEADER)); | 130 ZeroMemory(pvi, sizeof(VIDEOINFOHEADER)); |
| 115 pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | 131 pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
| 116 pvi->bmiHeader.biPlanes = 1; | 132 pvi->bmiHeader.biPlanes = 1; |
| 117 pvi->bmiHeader.biClrImportant = 0; | 133 pvi->bmiHeader.biClrImportant = 0; |
| 118 pvi->bmiHeader.biClrUsed = 0; | 134 pvi->bmiHeader.biClrUsed = 0; |
| 119 if (requested_frame_rate_ > 0) | 135 if (requested_frame_rate_ > 0) |
| 120 pvi->AvgTimePerFrame = kSecondsToReferenceTime / requested_frame_rate_; | 136 pvi->AvgTimePerFrame = kSecondsToReferenceTime / requested_frame_rate_; |
| 121 | 137 |
| 122 media_type->majortype = MEDIATYPE_Video; | 138 media_type->majortype = MEDIATYPE_Video; |
| 123 media_type->formattype = FORMAT_VideoInfo; | 139 media_type->formattype = FORMAT_VideoInfo; |
| 124 media_type->bTemporalCompression = FALSE; | 140 media_type->bTemporalCompression = FALSE; |
| 125 | 141 |
| 126 if (requested_pixel_format_ == PIXEL_FORMAT_MJPEG) { | 142 if (requested_pixel_format_ == PIXEL_FORMAT_MJPEG || |
| 143 requested_pixel_format_ == PIXEL_FORMAT_Y8 || |
| 144 requested_pixel_format_ == PIXEL_FORMAT_Y16) { |
| 127 // If the requested pixel format is MJPEG, accept only MJPEG. | 145 // If the requested pixel format is MJPEG, accept only MJPEG. |
| 146 // If the requested pixel format is Y16 or Y8, accept only those. |
| 128 // This is ok since the capabilities of the capturer have been | 147 // This is ok since the capabilities of the capturer have been |
| 129 // enumerated and we know that it is supported. | 148 // enumerated and we know that it is supported. |
| 130 if (index != 0) | 149 if (index != 0) |
| 131 return false; | 150 return false; |
| 132 | 151 |
| 133 pvi->bmiHeader = requested_info_header_; | 152 pvi->bmiHeader = requested_info_header_; |
| 134 return true; | 153 return true; |
| 135 } | 154 } |
| 136 | 155 |
| 137 switch (index) { | 156 switch (index) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 228 } |
| 210 | 229 |
| 211 observer_->FrameReceived(buffer, length, timestamp); | 230 observer_->FrameReceived(buffer, length, timestamp); |
| 212 return S_OK; | 231 return S_OK; |
| 213 } | 232 } |
| 214 | 233 |
| 215 SinkInputPin::~SinkInputPin() { | 234 SinkInputPin::~SinkInputPin() { |
| 216 } | 235 } |
| 217 | 236 |
| 218 } // namespace media | 237 } // namespace media |
| OLD | NEW |