OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/video/capture/win/sink_input_pin_win.h" | |
6 | |
7 // Avoid including strsafe.h via dshow as it will cause build warnings. | |
8 #define NO_DSHOW_STRSAFE | |
9 #include <dshow.h> | |
10 | |
11 #include "base/logging.h" | |
12 | |
13 namespace media { | |
14 | |
15 SinkInputPin::SinkInputPin(IBaseFilter* filter, | |
16 SinkFilter::SinkFilterObserver* observer) | |
17 : observer_(observer), | |
18 PinBase(filter) { | |
19 } | |
20 | |
21 SinkInputPin::~SinkInputPin() { | |
22 } | |
23 | |
24 bool SinkInputPin::GetValidMediaType(int index, AM_MEDIA_TYPE* media_type) { | |
25 if (media_type->cbFormat < sizeof(VIDEOINFOHEADER)) { | |
tommi (sloooow) - chröme
2011/06/23 14:05:56
nit: no need for braces
Per K
2011/06/27 11:47:50
Done.
| |
26 return false; | |
27 } | |
28 VIDEOINFOHEADER* pvi = | |
29 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); | |
30 | |
31 ZeroMemory(pvi, sizeof(VIDEOINFOHEADER)); | |
32 pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
33 pvi->bmiHeader.biPlanes = 1; | |
34 pvi->bmiHeader.biClrImportant = 0; | |
35 pvi->bmiHeader.biClrUsed = 0; | |
36 if (requested_capability_.frame_rate > 0) { | |
37 pvi->AvgTimePerFrame = kSecondsToReferenceTime / | |
38 requested_capability_.frame_rate; | |
39 } | |
40 | |
41 media_type->majortype = MEDIATYPE_Video; | |
42 media_type->formattype = FORMAT_VideoInfo; | |
43 media_type->bTemporalCompression = FALSE; | |
44 | |
45 switch (index) { | |
46 case 0: { | |
tommi (sloooow) - chröme
2011/06/23 14:05:56
enum values for the index? Instead of 0,1,2 maybe
Per K
2011/06/27 11:47:50
It called from TypeEnumerator::Next where index is
| |
47 pvi->bmiHeader.biCompression = MAKEFOURCC('I', '4', '2', '0'); | |
48 pvi->bmiHeader.biBitCount = 12; // bit per pixel | |
49 pvi->bmiHeader.biWidth = requested_capability_.width; | |
50 pvi->bmiHeader.biHeight = requested_capability_.height; | |
51 pvi->bmiHeader.biSizeImage = 3 * requested_capability_.height * | |
52 requested_capability_.width / 2; | |
53 media_type->subtype = kMediaSubTypeI420; | |
54 break; | |
55 } | |
56 case 1: { | |
57 pvi->bmiHeader.biCompression = MAKEFOURCC('Y', 'U', 'Y', '2'); | |
58 pvi->bmiHeader.biBitCount = 16; | |
59 pvi->bmiHeader.biWidth = requested_capability_.width; | |
60 pvi->bmiHeader.biHeight = requested_capability_.height; | |
61 pvi->bmiHeader.biSizeImage = 2 * requested_capability_.width * | |
62 requested_capability_.height; | |
63 media_type->subtype = MEDIASUBTYPE_YUY2; | |
64 break; | |
65 } | |
66 case 2: { | |
67 pvi->bmiHeader.biCompression = BI_RGB; | |
68 pvi->bmiHeader.biBitCount = 24; | |
69 pvi->bmiHeader.biWidth = requested_capability_.width; | |
70 pvi->bmiHeader.biHeight = requested_capability_.height; | |
71 pvi->bmiHeader.biSizeImage = 3 * requested_capability_.height * | |
72 requested_capability_.width; | |
73 media_type->subtype = MEDIASUBTYPE_RGB24; | |
74 break; | |
75 } | |
76 default: | |
77 return false; | |
78 } | |
79 | |
80 media_type->bFixedSizeSamples = TRUE; | |
81 media_type->lSampleSize = pvi->bmiHeader.biSizeImage; | |
82 return true; | |
83 } | |
84 | |
85 bool SinkInputPin::IsMediaTypeValid(const AM_MEDIA_TYPE* media_type) { | |
86 GUID type = media_type->majortype; | |
87 if (type != MEDIATYPE_Video) { | |
88 return false; | |
89 } | |
90 GUID format_type = media_type->formattype; | |
91 | |
92 // Check for the sub types we support. | |
93 GUID sub_type = media_type->subtype; | |
94 | |
95 if (format_type == FORMAT_VideoInfo) { | |
96 VIDEOINFOHEADER* pvi = | |
97 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); | |
tommi (sloooow) - chröme
2011/06/23 14:05:56
indent
Per K
2011/06/27 11:47:50
Done.
| |
98 if (pvi == NULL) { | |
99 return false; | |
100 } | |
101 | |
102 // Store the incoming width and height. | |
103 resulting_capability_.width = pvi->bmiHeader.biWidth; | |
104 resulting_capability_.height = abs(pvi->bmiHeader.biHeight); | |
105 if (pvi->AvgTimePerFrame > 0) { | |
106 resulting_capability_.frame_rate = | |
107 static_cast<int>(kSecondsToReferenceTime / pvi->AvgTimePerFrame); | |
108 } else { | |
109 resulting_capability_.frame_rate = requested_capability_.frame_rate; | |
110 } | |
111 if (sub_type == kMediaSubTypeI420 && | |
112 pvi->bmiHeader.biCompression == MAKEFOURCC('I', '4', '2', '0')) { | |
113 resulting_capability_.color = VideoCaptureDevice::kI420; | |
114 return true; // This format is acceptable. | |
115 } | |
116 if (sub_type == MEDIASUBTYPE_YUY2 && | |
117 pvi->bmiHeader.biCompression == MAKEFOURCC('Y', 'U', 'Y', '2')) { | |
118 resulting_capability_.color = VideoCaptureDevice::kYUY2; | |
119 ::Sleep(60); // Workaround for bad driver. | |
tommi (sloooow) - chröme
2011/06/23 14:05:56
is this a driver that's always installed or a 3rd
Per K
2011/06/27 11:47:50
This is an old fix that we unfortunately are not s
| |
120 return true; // This format is acceptable. | |
121 } | |
122 if (sub_type == MEDIASUBTYPE_RGB24 && | |
123 pvi->bmiHeader.biCompression == BI_RGB) { | |
124 resulting_capability_.color = VideoCaptureDevice::kRGB24; | |
125 return true; // This format is acceptable. | |
126 } | |
127 } | |
128 return false; | |
129 } | |
130 | |
131 HRESULT SinkInputPin::Receive(IMediaSample* media_sample) { | |
132 DCHECK(media_sample); | |
133 const int length = media_sample->GetActualDataLength(); | |
134 uint8* buffer = NULL; | |
135 if (FAILED(media_sample->GetPointer(&buffer))) { | |
136 return S_FALSE; | |
137 } | |
138 observer_->FrameReceived(buffer, length); | |
139 | |
140 return S_OK; | |
141 } | |
142 | |
143 void SinkInputPin::SetRequestedMediaCapability( | |
144 const VideoCaptureDevice::Capability& capability) { | |
145 requested_capability_ = capability; | |
146 resulting_capability_ = VideoCaptureDevice::Capability(); | |
147 } | |
148 | |
149 const VideoCaptureDevice::Capability& SinkInputPin::ResultingCapability() { | |
150 return resulting_capability_; | |
151 } | |
152 | |
153 } // namespace media | |
OLD | NEW |