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