| 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 "device/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/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "media/base/timestamp_constants.h" | 16 #include "media/base/timestamp_constants.h" |
| 17 | 17 |
| 18 namespace media { | 18 namespace device { |
| 19 | 19 |
| 20 const REFERENCE_TIME kSecondsToReferenceTime = 10000000; | 20 const REFERENCE_TIME kSecondsToReferenceTime = 10000000; |
| 21 | 21 |
| 22 static DWORD GetArea(const BITMAPINFOHEADER& info_header) { | 22 static DWORD GetArea(const BITMAPINFOHEADER& info_header) { |
| 23 return info_header.biWidth * info_header.biHeight; | 23 return info_header.biWidth * info_header.biHeight; |
| 24 } | 24 } |
| 25 | 25 |
| 26 SinkInputPin::SinkInputPin(IBaseFilter* filter, SinkFilterObserver* observer) | 26 SinkInputPin::SinkInputPin(IBaseFilter* filter, SinkFilterObserver* observer) |
| 27 : PinBase(filter), requested_frame_rate_(0), observer_(observer) { | 27 : PinBase(filter), requested_frame_rate_(0), observer_(observer) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 void SinkInputPin::SetRequestedMediaFormat( | 30 void SinkInputPin::SetRequestedMediaFormat( |
| 31 VideoPixelFormat pixel_format, | 31 VideoPixelFormat pixel_format, |
| 32 float frame_rate, | 32 float frame_rate, |
| 33 const BITMAPINFOHEADER& info_header) { | 33 const BITMAPINFOHEADER& info_header) { |
| 34 requested_pixel_format_ = pixel_format; | 34 requested_pixel_format_ = pixel_format; |
| 35 requested_frame_rate_ = frame_rate; | 35 requested_frame_rate_ = frame_rate; |
| 36 requested_info_header_ = info_header; | 36 requested_info_header_ = info_header; |
| 37 resulting_format_.frame_size.SetSize(0, 0); | 37 resulting_format_.frame_size.SetSize(0, 0); |
| 38 resulting_format_.frame_rate = 0; | 38 resulting_format_.frame_rate = 0; |
| 39 resulting_format_.pixel_format = PIXEL_FORMAT_UNKNOWN; | 39 resulting_format_.pixel_format = media::PIXEL_FORMAT_UNKNOWN; |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool SinkInputPin::IsMediaTypeValid(const AM_MEDIA_TYPE* media_type) { | 42 bool SinkInputPin::IsMediaTypeValid(const AM_MEDIA_TYPE* media_type) { |
| 43 const GUID type = media_type->majortype; | 43 const GUID type = media_type->majortype; |
| 44 if (type != MEDIATYPE_Video) | 44 if (type != MEDIATYPE_Video) |
| 45 return false; | 45 return false; |
| 46 | 46 |
| 47 const GUID format_type = media_type->formattype; | 47 const GUID format_type = media_type->formattype; |
| 48 if (format_type != FORMAT_VideoInfo) | 48 if (format_type != FORMAT_VideoInfo) |
| 49 return false; | 49 return false; |
| 50 | 50 |
| 51 // Check for the sub types we support. | 51 // Check for the sub types we support. |
| 52 const GUID sub_type = media_type->subtype; | 52 const GUID sub_type = media_type->subtype; |
| 53 VIDEOINFOHEADER* pvi = | 53 VIDEOINFOHEADER* pvi = |
| 54 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); | 54 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); |
| 55 if (pvi == NULL) | 55 if (pvi == NULL) |
| 56 return false; | 56 return false; |
| 57 | 57 |
| 58 // Store the incoming width and height. | 58 // Store the incoming width and height. |
| 59 resulting_format_.frame_size.SetSize(pvi->bmiHeader.biWidth, | 59 resulting_format_.frame_size.SetSize(pvi->bmiHeader.biWidth, |
| 60 abs(pvi->bmiHeader.biHeight)); | 60 abs(pvi->bmiHeader.biHeight)); |
| 61 if (pvi->AvgTimePerFrame > 0) { | 61 if (pvi->AvgTimePerFrame > 0) { |
| 62 resulting_format_.frame_rate = | 62 resulting_format_.frame_rate = |
| 63 static_cast<int>(kSecondsToReferenceTime / pvi->AvgTimePerFrame); | 63 static_cast<int>(kSecondsToReferenceTime / pvi->AvgTimePerFrame); |
| 64 } else { | 64 } else { |
| 65 resulting_format_.frame_rate = requested_frame_rate_; | 65 resulting_format_.frame_rate = requested_frame_rate_; |
| 66 } | 66 } |
| 67 if (sub_type == kMediaSubTypeI420 && | 67 if (sub_type == kMediaSubTypeI420 && |
| 68 pvi->bmiHeader.biCompression == MAKEFOURCC('I', '4', '2', '0')) { | 68 pvi->bmiHeader.biCompression == MAKEFOURCC('I', '4', '2', '0')) { |
| 69 resulting_format_.pixel_format = PIXEL_FORMAT_I420; | 69 resulting_format_.pixel_format = media::PIXEL_FORMAT_I420; |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 if (sub_type == MEDIASUBTYPE_YUY2 && | 72 if (sub_type == MEDIASUBTYPE_YUY2 && |
| 73 pvi->bmiHeader.biCompression == MAKEFOURCC('Y', 'U', 'Y', '2')) { | 73 pvi->bmiHeader.biCompression == MAKEFOURCC('Y', 'U', 'Y', '2')) { |
| 74 resulting_format_.pixel_format = PIXEL_FORMAT_YUY2; | 74 resulting_format_.pixel_format = media::PIXEL_FORMAT_YUY2; |
| 75 return true; | 75 return true; |
| 76 } | 76 } |
| 77 // This format is added after http:/crbug.com/508413. | 77 // This format is added after http:/crbug.com/508413. |
| 78 if (sub_type == MEDIASUBTYPE_UYVY && | 78 if (sub_type == MEDIASUBTYPE_UYVY && |
| 79 pvi->bmiHeader.biCompression == MAKEFOURCC('U', 'Y', 'V', 'Y')) { | 79 pvi->bmiHeader.biCompression == MAKEFOURCC('U', 'Y', 'V', 'Y')) { |
| 80 resulting_format_.pixel_format = PIXEL_FORMAT_UYVY; | 80 resulting_format_.pixel_format = media::PIXEL_FORMAT_UYVY; |
| 81 return true; | 81 return true; |
| 82 } | 82 } |
| 83 if (sub_type == MEDIASUBTYPE_MJPG && | 83 if (sub_type == MEDIASUBTYPE_MJPG && |
| 84 pvi->bmiHeader.biCompression == MAKEFOURCC('M', 'J', 'P', 'G')) { | 84 pvi->bmiHeader.biCompression == MAKEFOURCC('M', 'J', 'P', 'G')) { |
| 85 resulting_format_.pixel_format = PIXEL_FORMAT_MJPEG; | 85 resulting_format_.pixel_format = media::PIXEL_FORMAT_MJPEG; |
| 86 return true; | 86 return true; |
| 87 } | 87 } |
| 88 if (sub_type == MEDIASUBTYPE_RGB24 && | 88 if (sub_type == MEDIASUBTYPE_RGB24 && |
| 89 pvi->bmiHeader.biCompression == BI_RGB) { | 89 pvi->bmiHeader.biCompression == BI_RGB) { |
| 90 resulting_format_.pixel_format = PIXEL_FORMAT_RGB24; | 90 resulting_format_.pixel_format = media::PIXEL_FORMAT_RGB24; |
| 91 return true; | 91 return true; |
| 92 } | 92 } |
| 93 if (sub_type == MEDIASUBTYPE_RGB32 && | 93 if (sub_type == MEDIASUBTYPE_RGB32 && |
| 94 pvi->bmiHeader.biCompression == BI_RGB) { | 94 pvi->bmiHeader.biCompression == BI_RGB) { |
| 95 resulting_format_.pixel_format = PIXEL_FORMAT_RGB32; | 95 resulting_format_.pixel_format = media::PIXEL_FORMAT_RGB32; |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 #ifndef NDEBUG | 99 #ifndef NDEBUG |
| 100 WCHAR guid_str[128]; | 100 WCHAR guid_str[128]; |
| 101 StringFromGUID2(sub_type, guid_str, arraysize(guid_str)); | 101 StringFromGUID2(sub_type, guid_str, arraysize(guid_str)); |
| 102 DVLOG(2) << __func__ << " unsupported media type: " << guid_str; | 102 DVLOG(2) << __func__ << " unsupported media type: " << guid_str; |
| 103 #endif | 103 #endif |
| 104 return false; | 104 return false; |
| 105 } | 105 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 116 pvi->bmiHeader.biPlanes = 1; | 116 pvi->bmiHeader.biPlanes = 1; |
| 117 pvi->bmiHeader.biClrImportant = 0; | 117 pvi->bmiHeader.biClrImportant = 0; |
| 118 pvi->bmiHeader.biClrUsed = 0; | 118 pvi->bmiHeader.biClrUsed = 0; |
| 119 if (requested_frame_rate_ > 0) | 119 if (requested_frame_rate_ > 0) |
| 120 pvi->AvgTimePerFrame = kSecondsToReferenceTime / requested_frame_rate_; | 120 pvi->AvgTimePerFrame = kSecondsToReferenceTime / requested_frame_rate_; |
| 121 | 121 |
| 122 media_type->majortype = MEDIATYPE_Video; | 122 media_type->majortype = MEDIATYPE_Video; |
| 123 media_type->formattype = FORMAT_VideoInfo; | 123 media_type->formattype = FORMAT_VideoInfo; |
| 124 media_type->bTemporalCompression = FALSE; | 124 media_type->bTemporalCompression = FALSE; |
| 125 | 125 |
| 126 if (requested_pixel_format_ == PIXEL_FORMAT_MJPEG) { | 126 if (requested_pixel_format_ == media::PIXEL_FORMAT_MJPEG) { |
| 127 // If the requested pixel format is MJPEG, accept only MJPEG. | 127 // If the requested pixel format is MJPEG, accept only MJPEG. |
| 128 // This is ok since the capabilities of the capturer have been | 128 // This is ok since the capabilities of the capturer have been |
| 129 // enumerated and we know that it is supported. | 129 // enumerated and we know that it is supported. |
| 130 if (index != 0) | 130 if (index != 0) |
| 131 return false; | 131 return false; |
| 132 | 132 |
| 133 pvi->bmiHeader = requested_info_header_; | 133 pvi->bmiHeader = requested_info_header_; |
| 134 return true; | 134 return true; |
| 135 } | 135 } |
| 136 | 136 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 timestamp = base::TimeDelta::FromMicroseconds(start_time / 10); | 208 timestamp = base::TimeDelta::FromMicroseconds(start_time / 10); |
| 209 } | 209 } |
| 210 | 210 |
| 211 observer_->FrameReceived(buffer, length, timestamp); | 211 observer_->FrameReceived(buffer, length, timestamp); |
| 212 return S_OK; | 212 return S_OK; |
| 213 } | 213 } |
| 214 | 214 |
| 215 SinkInputPin::~SinkInputPin() { | 215 SinkInputPin::~SinkInputPin() { |
| 216 } | 216 } |
| 217 | 217 |
| 218 } // namespace media | 218 } // namespace device |
| OLD | NEW |