Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: media/video/capture/win/sink_input_pin_win.cc

Issue 83633008: Reland: Reorganize media::VideoCapture* types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/video/capture/win/sink_input_pin_win.h" 5 #include "media/video/capture/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 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 14
15 namespace media { 15 namespace media {
16 16
17 const REFERENCE_TIME kSecondsToReferenceTime = 10000000; 17 const REFERENCE_TIME kSecondsToReferenceTime = 10000000;
18 18
19 SinkInputPin::SinkInputPin(IBaseFilter* filter, 19 SinkInputPin::SinkInputPin(IBaseFilter* filter,
20 SinkFilterObserver* observer) 20 SinkFilterObserver* observer)
21 : observer_(observer), 21 : observer_(observer),
22 PinBase(filter) { 22 PinBase(filter) {
23 memset(&requested_capability_, 0, sizeof(requested_capability_));
24 memset(&resulting_capability_, 0, sizeof(resulting_capability_));
25 } 23 }
26 24
27 SinkInputPin::~SinkInputPin() {} 25 SinkInputPin::~SinkInputPin() {}
28 26
29 bool SinkInputPin::GetValidMediaType(int index, AM_MEDIA_TYPE* media_type) { 27 bool SinkInputPin::GetValidMediaType(int index, AM_MEDIA_TYPE* media_type) {
30 if (media_type->cbFormat < sizeof(VIDEOINFOHEADER)) 28 if (media_type->cbFormat < sizeof(VIDEOINFOHEADER))
31 return false; 29 return false;
32 30
33 VIDEOINFOHEADER* pvi = 31 VIDEOINFOHEADER* pvi =
34 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); 32 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat);
35 33
36 ZeroMemory(pvi, sizeof(VIDEOINFOHEADER)); 34 ZeroMemory(pvi, sizeof(VIDEOINFOHEADER));
37 pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 35 pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
38 pvi->bmiHeader.biPlanes = 1; 36 pvi->bmiHeader.biPlanes = 1;
39 pvi->bmiHeader.biClrImportant = 0; 37 pvi->bmiHeader.biClrImportant = 0;
40 pvi->bmiHeader.biClrUsed = 0; 38 pvi->bmiHeader.biClrUsed = 0;
41 if (requested_capability_.frame_rate > 0) { 39 if (requested_format_.frame_rate > 0) {
42 pvi->AvgTimePerFrame = kSecondsToReferenceTime / 40 pvi->AvgTimePerFrame =
43 requested_capability_.frame_rate; 41 kSecondsToReferenceTime / requested_format_.frame_rate;
44 } 42 }
45 43
46 media_type->majortype = MEDIATYPE_Video; 44 media_type->majortype = MEDIATYPE_Video;
47 media_type->formattype = FORMAT_VideoInfo; 45 media_type->formattype = FORMAT_VideoInfo;
48 media_type->bTemporalCompression = FALSE; 46 media_type->bTemporalCompression = FALSE;
49 47
50 switch (index) { 48 switch (index) {
51 case 0: { 49 case 0: {
52 pvi->bmiHeader.biCompression = MAKEFOURCC('I', '4', '2', '0'); 50 pvi->bmiHeader.biCompression = MAKEFOURCC('I', '4', '2', '0');
53 pvi->bmiHeader.biBitCount = 12; // bit per pixel 51 pvi->bmiHeader.biBitCount = 12; // bit per pixel
54 pvi->bmiHeader.biWidth = requested_capability_.width; 52 pvi->bmiHeader.biWidth = requested_format_.frame_size.width();
55 pvi->bmiHeader.biHeight = requested_capability_.height; 53 pvi->bmiHeader.biHeight = requested_format_.frame_size.height();
56 pvi->bmiHeader.biSizeImage = 3 * requested_capability_.height * 54 pvi->bmiHeader.biSizeImage =
57 requested_capability_.width / 2; 55 requested_format_.frame_size.GetArea() * 3 / 2;
58 media_type->subtype = kMediaSubTypeI420; 56 media_type->subtype = kMediaSubTypeI420;
59 break; 57 break;
60 } 58 }
61 case 1: { 59 case 1: {
62 pvi->bmiHeader.biCompression = MAKEFOURCC('Y', 'U', 'Y', '2'); 60 pvi->bmiHeader.biCompression = MAKEFOURCC('Y', 'U', 'Y', '2');
63 pvi->bmiHeader.biBitCount = 16; 61 pvi->bmiHeader.biBitCount = 16;
64 pvi->bmiHeader.biWidth = requested_capability_.width; 62 pvi->bmiHeader.biWidth = requested_format_.frame_size.width();
65 pvi->bmiHeader.biHeight = requested_capability_.height; 63 pvi->bmiHeader.biHeight = requested_format_.frame_size.height();
66 pvi->bmiHeader.biSizeImage = 2 * requested_capability_.width * 64 pvi->bmiHeader.biSizeImage = requested_format_.frame_size.GetArea() * 2;
67 requested_capability_.height;
68 media_type->subtype = MEDIASUBTYPE_YUY2; 65 media_type->subtype = MEDIASUBTYPE_YUY2;
69 break; 66 break;
70 } 67 }
71 case 2: { 68 case 2: {
72 pvi->bmiHeader.biCompression = BI_RGB; 69 pvi->bmiHeader.biCompression = BI_RGB;
73 pvi->bmiHeader.biBitCount = 24; 70 pvi->bmiHeader.biBitCount = 24;
74 pvi->bmiHeader.biWidth = requested_capability_.width; 71 pvi->bmiHeader.biWidth = requested_format_.frame_size.width();
75 pvi->bmiHeader.biHeight = requested_capability_.height; 72 pvi->bmiHeader.biHeight = requested_format_.frame_size.height();
76 pvi->bmiHeader.biSizeImage = 3 * requested_capability_.height * 73 pvi->bmiHeader.biSizeImage = requested_format_.frame_size.GetArea() * 3;
77 requested_capability_.width;
78 media_type->subtype = MEDIASUBTYPE_RGB24; 74 media_type->subtype = MEDIASUBTYPE_RGB24;
79 break; 75 break;
80 } 76 }
81 default: 77 default:
82 return false; 78 return false;
83 } 79 }
84 80
85 media_type->bFixedSizeSamples = TRUE; 81 media_type->bFixedSizeSamples = TRUE;
86 media_type->lSampleSize = pvi->bmiHeader.biSizeImage; 82 media_type->lSampleSize = pvi->bmiHeader.biSizeImage;
87 return true; 83 return true;
88 } 84 }
89 85
90 bool SinkInputPin::IsMediaTypeValid(const AM_MEDIA_TYPE* media_type) { 86 bool SinkInputPin::IsMediaTypeValid(const AM_MEDIA_TYPE* media_type) {
91 GUID type = media_type->majortype; 87 GUID type = media_type->majortype;
92 if (type != MEDIATYPE_Video) 88 if (type != MEDIATYPE_Video)
93 return false; 89 return false;
94 90
95 GUID format_type = media_type->formattype; 91 GUID format_type = media_type->formattype;
96 if (format_type != FORMAT_VideoInfo) 92 if (format_type != FORMAT_VideoInfo)
97 return false; 93 return false;
98 94
99 // Check for the sub types we support. 95 // Check for the sub types we support.
100 GUID sub_type = media_type->subtype; 96 GUID sub_type = media_type->subtype;
101 VIDEOINFOHEADER* pvi = 97 VIDEOINFOHEADER* pvi =
102 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); 98 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat);
103 if (pvi == NULL) 99 if (pvi == NULL)
104 return false; 100 return false;
105 101
106 // Store the incoming width and height. 102 // Store the incoming width and height.
107 resulting_capability_.width = pvi->bmiHeader.biWidth; 103 resulting_format_.frame_size.SetSize(pvi->bmiHeader.biWidth,
108 resulting_capability_.height = abs(pvi->bmiHeader.biHeight); 104 abs(pvi->bmiHeader.biHeight));
109 if (pvi->AvgTimePerFrame > 0) { 105 if (pvi->AvgTimePerFrame > 0) {
110 resulting_capability_.frame_rate = 106 resulting_format_.frame_rate =
111 static_cast<int>(kSecondsToReferenceTime / pvi->AvgTimePerFrame); 107 static_cast<int>(kSecondsToReferenceTime / pvi->AvgTimePerFrame);
112 } else { 108 } else {
113 resulting_capability_.frame_rate = requested_capability_.frame_rate; 109 resulting_format_.frame_rate = requested_format_.frame_rate;
114 } 110 }
115 if (sub_type == kMediaSubTypeI420 && 111 if (sub_type == kMediaSubTypeI420 &&
116 pvi->bmiHeader.biCompression == MAKEFOURCC('I', '4', '2', '0')) { 112 pvi->bmiHeader.biCompression == MAKEFOURCC('I', '4', '2', '0')) {
117 resulting_capability_.color = PIXEL_FORMAT_I420; 113 resulting_format_.pixel_format = PIXEL_FORMAT_I420;
118 return true; // This format is acceptable. 114 return true; // This format is acceptable.
119 } 115 }
120 if (sub_type == MEDIASUBTYPE_YUY2 && 116 if (sub_type == MEDIASUBTYPE_YUY2 &&
121 pvi->bmiHeader.biCompression == MAKEFOURCC('Y', 'U', 'Y', '2')) { 117 pvi->bmiHeader.biCompression == MAKEFOURCC('Y', 'U', 'Y', '2')) {
122 resulting_capability_.color = PIXEL_FORMAT_YUY2; 118 resulting_format_.pixel_format = PIXEL_FORMAT_YUY2;
123 return true; // This format is acceptable. 119 return true; // This format is acceptable.
124 } 120 }
125 if (sub_type == MEDIASUBTYPE_RGB24 && 121 if (sub_type == MEDIASUBTYPE_RGB24 &&
126 pvi->bmiHeader.biCompression == BI_RGB) { 122 pvi->bmiHeader.biCompression == BI_RGB) {
127 resulting_capability_.color = PIXEL_FORMAT_RGB24; 123 resulting_format_.pixel_format = PIXEL_FORMAT_RGB24;
128 return true; // This format is acceptable. 124 return true; // This format is acceptable.
129 } 125 }
130 return false; 126 return false;
131 } 127 }
132 128
133 HRESULT SinkInputPin::Receive(IMediaSample* sample) { 129 HRESULT SinkInputPin::Receive(IMediaSample* sample) {
134 const int length = sample->GetActualDataLength(); 130 const int length = sample->GetActualDataLength();
135 uint8* buffer = NULL; 131 uint8* buffer = NULL;
136 if (FAILED(sample->GetPointer(&buffer))) 132 if (FAILED(sample->GetPointer(&buffer)))
137 return S_FALSE; 133 return S_FALSE;
138 134
139 observer_->FrameReceived(buffer, length); 135 observer_->FrameReceived(buffer, length);
140 return S_OK; 136 return S_OK;
141 } 137 }
142 138
143 void SinkInputPin::SetRequestedMediaCapability( 139 void SinkInputPin::SetRequestedMediaFormat(const VideoCaptureFormat& format) {
144 const VideoCaptureCapability& capability) { 140 requested_format_ = format;
145 requested_capability_ = capability; 141 resulting_format_.frame_size.SetSize(0, 0);
146 resulting_capability_.width = 0; 142 resulting_format_.frame_rate = 0;
147 resulting_capability_.height = 0; 143 resulting_format_.pixel_format = PIXEL_FORMAT_UNKNOWN;
148 resulting_capability_.frame_rate = 0;
149 resulting_capability_.color = PIXEL_FORMAT_UNKNOWN;
150 } 144 }
151 145
152 const VideoCaptureCapability& SinkInputPin::ResultingCapability() { 146 const VideoCaptureFormat& SinkInputPin::ResultingFormat() {
153 return resulting_capability_; 147 return resulting_format_;
154 } 148 }
155 149
156 } // namespace media 150 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/win/sink_input_pin_win.h ('k') | media/video/capture/win/video_capture_device_mf_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698