| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // Maximum pixels limit is set to Retina MacBookPro 15" resolution of | 127 // Maximum pixels limit is set to Retina MacBookPro 15" resolution of |
| 128 // 2880 x 1800 as of 4/18/2013. | 128 // 2880 x 1800 as of 4/18/2013. |
| 129 // For high fps, maximum pixels limit is set based on common 24" monitor | 129 // For high fps, maximum pixels limit is set based on common 24" monitor |
| 130 // resolution of 2048 x 1280 as of 6/13/2013. The Retina resolution is | 130 // resolution of 2048 x 1280 as of 6/13/2013. The Retina resolution is |
| 131 // therefore reduced to 1440 x 900. | 131 // therefore reduced to 1440 x 900. |
| 132 int max_pixels = (fps > 5) ? 2048 * 1280 : 2880 * 1800; | 132 int max_pixels = (fps > 5) ? 2048 * 1280 : 2880 * 1800; |
| 133 ComputeScaleMaxPixels( | 133 ComputeScaleMaxPixels( |
| 134 frame_width, frame_height, max_pixels, scaled_width, scaled_height); | 134 frame_width, frame_height, max_pixels, scaled_width, scaled_height); |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Compute size to crop video frame to. | |
| 138 // If cropped_format_* is 0, return the frame_* size as is. | |
| 139 void ComputeCrop(int cropped_format_width, int cropped_format_height, | |
| 140 int frame_width, int frame_height, | |
| 141 int pixel_width, int pixel_height, | |
| 142 int rotation, | |
| 143 int* cropped_width, int* cropped_height) { | |
| 144 // Transform screen crop to camera space if rotated. | |
| 145 if (rotation == 90 || rotation == 270) { | |
| 146 std::swap(cropped_format_width, cropped_format_height); | |
| 147 } | |
| 148 ASSERT(cropped_format_width >= 0); | |
| 149 ASSERT(cropped_format_height >= 0); | |
| 150 ASSERT(frame_width > 0); | |
| 151 ASSERT(frame_height > 0); | |
| 152 ASSERT(pixel_width >= 0); | |
| 153 ASSERT(pixel_height >= 0); | |
| 154 ASSERT(rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270); | |
| 155 ASSERT(cropped_width != NULL); | |
| 156 ASSERT(cropped_height != NULL); | |
| 157 if (!pixel_width) { | |
| 158 pixel_width = 1; | |
| 159 } | |
| 160 if (!pixel_height) { | |
| 161 pixel_height = 1; | |
| 162 } | |
| 163 // if cropped_format is 0x0 disable cropping. | |
| 164 if (!cropped_format_height) { | |
| 165 cropped_format_height = 1; | |
| 166 } | |
| 167 float frame_aspect = static_cast<float>(frame_width * pixel_width) / | |
| 168 static_cast<float>(frame_height * pixel_height); | |
| 169 float crop_aspect = static_cast<float>(cropped_format_width) / | |
| 170 static_cast<float>(cropped_format_height); | |
| 171 // kAspectThresh is the maximum aspect ratio difference that we'll accept | |
| 172 // for cropping. The value 1.34 allows cropping from 4:3 to 16:9. | |
| 173 // Set to zero to disable cropping entirely. | |
| 174 // TODO(fbarchard): crop to multiple of 16 width for better performance. | |
| 175 const float kAspectThresh = 1.34f; | |
| 176 // Wide aspect - crop horizontally | |
| 177 if (frame_aspect > crop_aspect && | |
| 178 frame_aspect < crop_aspect * kAspectThresh) { | |
| 179 // Round width down to multiple of 4 to avoid odd chroma width. | |
| 180 // Width a multiple of 4 allows a half size image to have chroma channel | |
| 181 // that avoids rounding errors. | |
| 182 frame_width = static_cast<int>((crop_aspect * frame_height * | |
| 183 pixel_height) / pixel_width + 0.5f) & ~3; | |
| 184 } else if (frame_aspect < crop_aspect && | |
| 185 frame_aspect > crop_aspect / kAspectThresh) { | |
| 186 frame_height = static_cast<int>((frame_width * pixel_width) / | |
| 187 (crop_aspect * pixel_height) + 0.5f) & ~1; | |
| 188 } | |
| 189 *cropped_width = frame_width; | |
| 190 *cropped_height = frame_height; | |
| 191 } | |
| 192 | |
| 193 // Compute the frame size that makes pixels square pixel aspect ratio. | |
| 194 void ComputeScaleToSquarePixels(int in_width, int in_height, | |
| 195 int pixel_width, int pixel_height, | |
| 196 int* scaled_width, int* scaled_height) { | |
| 197 *scaled_width = in_width; // Keep width the same. | |
| 198 *scaled_height = in_height * pixel_height / pixel_width; | |
| 199 } | |
| 200 | |
| 201 // The C++ standard requires a namespace-scope definition of static const | 137 // The C++ standard requires a namespace-scope definition of static const |
| 202 // integral types even when they are initialized in the declaration (see | 138 // integral types even when they are initialized in the declaration (see |
| 203 // [class.static.data]/4), but MSVC with /Ze is non-conforming and treats that | 139 // [class.static.data]/4), but MSVC with /Ze is non-conforming and treats that |
| 204 // as a multiply defined symbol error. See Also: | 140 // as a multiply defined symbol error. See Also: |
| 205 // http://msdn.microsoft.com/en-us/library/34h23df8.aspx | 141 // http://msdn.microsoft.com/en-us/library/34h23df8.aspx |
| 206 #ifndef _MSC_EXTENSIONS | 142 #ifndef _MSC_EXTENSIONS |
| 207 const int64_t VideoFormat::kMinimumInterval; // Initialized in header. | 143 const int64_t VideoFormat::kMinimumInterval; // Initialized in header. |
| 208 #endif | 144 #endif |
| 209 | 145 |
| 210 std::string VideoFormat::ToString() const { | 146 std::string VideoFormat::ToString() const { |
| 211 std::string fourcc_name = GetFourccName(fourcc) + " "; | 147 std::string fourcc_name = GetFourccName(fourcc) + " "; |
| 212 for (std::string::const_iterator i = fourcc_name.begin(); | 148 for (std::string::const_iterator i = fourcc_name.begin(); |
| 213 i < fourcc_name.end(); ++i) { | 149 i < fourcc_name.end(); ++i) { |
| 214 // Test character is printable; Avoid isprint() which asserts on negatives. | 150 // Test character is printable; Avoid isprint() which asserts on negatives. |
| 215 if (*i < 32 || *i >= 127) { | 151 if (*i < 32 || *i >= 127) { |
| 216 fourcc_name = ""; | 152 fourcc_name = ""; |
| 217 break; | 153 break; |
| 218 } | 154 } |
| 219 } | 155 } |
| 220 | 156 |
| 221 std::ostringstream ss; | 157 std::ostringstream ss; |
| 222 ss << fourcc_name << width << "x" << height << "x" | 158 ss << fourcc_name << width << "x" << height << "x" |
| 223 << IntervalToFpsFloat(interval); | 159 << IntervalToFpsFloat(interval); |
| 224 return ss.str(); | 160 return ss.str(); |
| 225 } | 161 } |
| 226 | 162 |
| 227 } // namespace cricket | 163 } // namespace cricket |
| OLD | NEW |