| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 float frame_rate, | 29 float frame_rate, |
| 30 const BITMAPINFOHEADER& info_header) { | 30 const BITMAPINFOHEADER& info_header) { |
| 31 requested_pixel_format_ = pixel_format; | 31 requested_pixel_format_ = pixel_format; |
| 32 requested_frame_rate_ = frame_rate; | 32 requested_frame_rate_ = frame_rate; |
| 33 requested_info_header_ = info_header; | 33 requested_info_header_ = info_header; |
| 34 resulting_format_.frame_size.SetSize(0, 0); | 34 resulting_format_.frame_size.SetSize(0, 0); |
| 35 resulting_format_.frame_rate = 0; | 35 resulting_format_.frame_rate = 0; |
| 36 resulting_format_.pixel_format = PIXEL_FORMAT_UNKNOWN; | 36 resulting_format_.pixel_format = PIXEL_FORMAT_UNKNOWN; |
| 37 } | 37 } |
| 38 | 38 |
| 39 const VideoCaptureFormat& SinkInputPin::ResultingFormat() { |
| 40 return resulting_format_; |
| 41 } |
| 42 |
| 39 bool SinkInputPin::IsMediaTypeValid(const AM_MEDIA_TYPE* media_type) { | 43 bool SinkInputPin::IsMediaTypeValid(const AM_MEDIA_TYPE* media_type) { |
| 40 const GUID type = media_type->majortype; | 44 GUID type = media_type->majortype; |
| 41 if (type != MEDIATYPE_Video) | 45 if (type != MEDIATYPE_Video) |
| 42 return false; | 46 return false; |
| 43 | 47 |
| 44 const GUID format_type = media_type->formattype; | 48 GUID format_type = media_type->formattype; |
| 45 if (format_type != FORMAT_VideoInfo) | 49 if (format_type != FORMAT_VideoInfo) |
| 46 return false; | 50 return false; |
| 47 | 51 |
| 48 // Check for the sub types we support. | 52 // Check for the sub types we support. |
| 49 const GUID sub_type = media_type->subtype; | 53 GUID sub_type = media_type->subtype; |
| 50 VIDEOINFOHEADER* pvi = | 54 VIDEOINFOHEADER* pvi = |
| 51 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); | 55 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); |
| 52 if (pvi == NULL) | 56 if (pvi == NULL) |
| 53 return false; | 57 return false; |
| 54 | 58 |
| 55 // Store the incoming width and height. | 59 // Store the incoming width and height. |
| 56 resulting_format_.frame_size.SetSize(pvi->bmiHeader.biWidth, | 60 resulting_format_.frame_size.SetSize(pvi->bmiHeader.biWidth, |
| 57 abs(pvi->bmiHeader.biHeight)); | 61 abs(pvi->bmiHeader.biHeight)); |
| 58 if (pvi->AvgTimePerFrame > 0) { | 62 if (pvi->AvgTimePerFrame > 0) { |
| 59 resulting_format_.frame_rate = | 63 resulting_format_.frame_rate = |
| 60 static_cast<int>(kSecondsToReferenceTime / pvi->AvgTimePerFrame); | 64 static_cast<int>(kSecondsToReferenceTime / pvi->AvgTimePerFrame); |
| 61 } else { | 65 } else { |
| 62 resulting_format_.frame_rate = requested_frame_rate_; | 66 resulting_format_.frame_rate = requested_frame_rate_; |
| 63 } | 67 } |
| 64 if (sub_type == kMediaSubTypeI420 && | 68 if (sub_type == kMediaSubTypeI420 && |
| 65 pvi->bmiHeader.biCompression == MAKEFOURCC('I', '4', '2', '0')) { | 69 pvi->bmiHeader.biCompression == MAKEFOURCC('I', '4', '2', '0')) { |
| 66 resulting_format_.pixel_format = PIXEL_FORMAT_I420; | 70 resulting_format_.pixel_format = PIXEL_FORMAT_I420; |
| 67 return true; | 71 return true; |
| 68 } | 72 } |
| 69 if (sub_type == MEDIASUBTYPE_YUY2 && | 73 if (sub_type == MEDIASUBTYPE_YUY2 && |
| 70 pvi->bmiHeader.biCompression == MAKEFOURCC('Y', 'U', 'Y', '2')) { | 74 pvi->bmiHeader.biCompression == MAKEFOURCC('Y', 'U', 'Y', '2')) { |
| 71 resulting_format_.pixel_format = PIXEL_FORMAT_YUY2; | 75 resulting_format_.pixel_format = PIXEL_FORMAT_YUY2; |
| 72 return true; | 76 return true; |
| 73 } | 77 } |
| 74 // This format is added after http:/crbug.com/508413. | |
| 75 if (sub_type == MEDIASUBTYPE_UYVY && | |
| 76 pvi->bmiHeader.biCompression == MAKEFOURCC('U', 'Y', 'V', 'Y')) { | |
| 77 resulting_format_.pixel_format = PIXEL_FORMAT_UYVY; | |
| 78 return true; | |
| 79 } | |
| 80 if (sub_type == MEDIASUBTYPE_MJPG && | 78 if (sub_type == MEDIASUBTYPE_MJPG && |
| 81 pvi->bmiHeader.biCompression == MAKEFOURCC('M', 'J', 'P', 'G')) { | 79 pvi->bmiHeader.biCompression == MAKEFOURCC('M', 'J', 'P', 'G')) { |
| 82 resulting_format_.pixel_format = PIXEL_FORMAT_MJPEG; | 80 resulting_format_.pixel_format = PIXEL_FORMAT_MJPEG; |
| 83 return true; | 81 return true; |
| 84 } | 82 } |
| 85 if (sub_type == MEDIASUBTYPE_RGB24 && | 83 if (sub_type == MEDIASUBTYPE_RGB24 && |
| 86 pvi->bmiHeader.biCompression == BI_RGB) { | 84 pvi->bmiHeader.biCompression == BI_RGB) { |
| 87 resulting_format_.pixel_format = PIXEL_FORMAT_RGB24; | 85 resulting_format_.pixel_format = PIXEL_FORMAT_RGB24; |
| 88 return true; | 86 return true; |
| 89 } | 87 } |
| 90 if (sub_type == MEDIASUBTYPE_RGB32 && | 88 if (sub_type == MEDIASUBTYPE_RGB32 && |
| 91 pvi->bmiHeader.biCompression == BI_RGB) { | 89 pvi->bmiHeader.biCompression == BI_RGB) { |
| 92 resulting_format_.pixel_format = PIXEL_FORMAT_RGB32; | 90 resulting_format_.pixel_format = PIXEL_FORMAT_RGB32; |
| 93 return true; | 91 return true; |
| 94 } | 92 } |
| 95 | |
| 96 #ifndef NDEBUG | |
| 97 WCHAR guid_str[128]; | |
| 98 StringFromGUID2(sub_type, guid_str, arraysize(guid_str)); | |
| 99 DVLOG(2) << __FUNCTION__ << " unsupported media type: " << guid_str; | |
| 100 #endif | |
| 101 return false; | 93 return false; |
| 102 } | 94 } |
| 103 | 95 |
| 104 bool SinkInputPin::GetValidMediaType(int index, AM_MEDIA_TYPE* media_type) { | 96 bool SinkInputPin::GetValidMediaType(int index, AM_MEDIA_TYPE* media_type) { |
| 105 if (media_type->cbFormat < sizeof(VIDEOINFOHEADER)) | 97 if (media_type->cbFormat < sizeof(VIDEOINFOHEADER)) |
| 106 return false; | 98 return false; |
| 107 | 99 |
| 108 VIDEOINFOHEADER* const pvi = | 100 VIDEOINFOHEADER* pvi = |
| 109 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); | 101 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); |
| 110 | 102 |
| 111 ZeroMemory(pvi, sizeof(VIDEOINFOHEADER)); | 103 ZeroMemory(pvi, sizeof(VIDEOINFOHEADER)); |
| 112 pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | 104 pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
| 113 pvi->bmiHeader.biPlanes = 1; | 105 pvi->bmiHeader.biPlanes = 1; |
| 114 pvi->bmiHeader.biClrImportant = 0; | 106 pvi->bmiHeader.biClrImportant = 0; |
| 115 pvi->bmiHeader.biClrUsed = 0; | 107 pvi->bmiHeader.biClrUsed = 0; |
| 116 if (requested_frame_rate_ > 0) | 108 if (requested_frame_rate_ > 0) { |
| 117 pvi->AvgTimePerFrame = kSecondsToReferenceTime / requested_frame_rate_; | 109 pvi->AvgTimePerFrame = kSecondsToReferenceTime / requested_frame_rate_; |
| 110 } |
| 118 | 111 |
| 119 media_type->majortype = MEDIATYPE_Video; | 112 media_type->majortype = MEDIATYPE_Video; |
| 120 media_type->formattype = FORMAT_VideoInfo; | 113 media_type->formattype = FORMAT_VideoInfo; |
| 121 media_type->bTemporalCompression = FALSE; | 114 media_type->bTemporalCompression = FALSE; |
| 122 | 115 |
| 123 if (requested_pixel_format_ == PIXEL_FORMAT_MJPEG) { | 116 if (requested_pixel_format_ == PIXEL_FORMAT_MJPEG) { |
| 124 // If the requested pixel format is MJPEG, accept only MJPEG. | 117 // If the requested pixel format is MJPEG, accept only MJPEG. |
| 125 // This is ok since the capabilities of the capturer have been | 118 // This is ok since the capabilities of the capturer have been |
| 126 // enumerated and we know that it is supported. | 119 // enumerated and we know that it is supported. |
| 127 if (index != 0) | 120 if (index != 0) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 144 case 1: { | 137 case 1: { |
| 145 pvi->bmiHeader.biCompression = MAKEFOURCC('Y', 'U', 'Y', '2'); | 138 pvi->bmiHeader.biCompression = MAKEFOURCC('Y', 'U', 'Y', '2'); |
| 146 pvi->bmiHeader.biBitCount = 16; | 139 pvi->bmiHeader.biBitCount = 16; |
| 147 pvi->bmiHeader.biWidth = requested_info_header_.biWidth; | 140 pvi->bmiHeader.biWidth = requested_info_header_.biWidth; |
| 148 pvi->bmiHeader.biHeight = requested_info_header_.biHeight; | 141 pvi->bmiHeader.biHeight = requested_info_header_.biHeight; |
| 149 pvi->bmiHeader.biSizeImage = GetArea(requested_info_header_) * 2; | 142 pvi->bmiHeader.biSizeImage = GetArea(requested_info_header_) * 2; |
| 150 media_type->subtype = MEDIASUBTYPE_YUY2; | 143 media_type->subtype = MEDIASUBTYPE_YUY2; |
| 151 break; | 144 break; |
| 152 } | 145 } |
| 153 case 2: { | 146 case 2: { |
| 154 pvi->bmiHeader.biCompression = MAKEFOURCC('U', 'Y', 'V', 'Y'); | |
| 155 pvi->bmiHeader.biBitCount = 16; | |
| 156 pvi->bmiHeader.biWidth = requested_info_header_.biWidth; | |
| 157 pvi->bmiHeader.biHeight = requested_info_header_.biHeight; | |
| 158 pvi->bmiHeader.biSizeImage = GetArea(requested_info_header_) * 2; | |
| 159 media_type->subtype = MEDIASUBTYPE_UYVY; | |
| 160 break; | |
| 161 } | |
| 162 case 3: { | |
| 163 pvi->bmiHeader.biCompression = BI_RGB; | 147 pvi->bmiHeader.biCompression = BI_RGB; |
| 164 pvi->bmiHeader.biBitCount = 24; | 148 pvi->bmiHeader.biBitCount = 24; |
| 165 pvi->bmiHeader.biWidth = requested_info_header_.biWidth; | 149 pvi->bmiHeader.biWidth = requested_info_header_.biWidth; |
| 166 pvi->bmiHeader.biHeight = requested_info_header_.biHeight; | 150 pvi->bmiHeader.biHeight = requested_info_header_.biHeight; |
| 167 pvi->bmiHeader.biSizeImage = GetArea(requested_info_header_) * 3; | 151 pvi->bmiHeader.biSizeImage = GetArea(requested_info_header_) * 3; |
| 168 media_type->subtype = MEDIASUBTYPE_RGB24; | 152 media_type->subtype = MEDIASUBTYPE_RGB24; |
| 169 break; | 153 break; |
| 170 } | 154 } |
| 171 case 4: { | 155 case 3: { |
| 172 pvi->bmiHeader.biCompression = BI_RGB; | 156 pvi->bmiHeader.biCompression = BI_RGB; |
| 173 pvi->bmiHeader.biBitCount = 32; | 157 pvi->bmiHeader.biBitCount = 32; |
| 174 pvi->bmiHeader.biWidth = requested_info_header_.biWidth; | 158 pvi->bmiHeader.biWidth = requested_info_header_.biWidth; |
| 175 pvi->bmiHeader.biHeight = requested_info_header_.biHeight; | 159 pvi->bmiHeader.biHeight = requested_info_header_.biHeight; |
| 176 pvi->bmiHeader.biSizeImage = GetArea(requested_info_header_) * 4; | 160 pvi->bmiHeader.biSizeImage = GetArea(requested_info_header_) * 4; |
| 177 media_type->subtype = MEDIASUBTYPE_RGB32; | 161 media_type->subtype = MEDIASUBTYPE_RGB32; |
| 178 break; | 162 break; |
| 179 } | 163 } |
| 180 default: | 164 default: |
| 181 return false; | 165 return false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 199 return S_FALSE; | 183 return S_FALSE; |
| 200 | 184 |
| 201 observer_->FrameReceived(buffer, length); | 185 observer_->FrameReceived(buffer, length); |
| 202 return S_OK; | 186 return S_OK; |
| 203 } | 187 } |
| 204 | 188 |
| 205 SinkInputPin::~SinkInputPin() { | 189 SinkInputPin::~SinkInputPin() { |
| 206 } | 190 } |
| 207 | 191 |
| 208 } // namespace media | 192 } // namespace media |
| OLD | NEW |