OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 13 matching lines...) Expand all Loading... |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include "talk/media/base/videocommon.h" | 28 #include "talk/media/base/videocommon.h" |
29 | 29 |
30 #include <limits.h> // For INT_MAX | 30 #include <limits.h> // For INT_MAX |
31 #include <math.h> | 31 #include <math.h> |
32 #include <sstream> | 32 #include <sstream> |
33 | 33 |
| 34 #include "webrtc/base/arraysize.h" |
34 #include "webrtc/base/common.h" | 35 #include "webrtc/base/common.h" |
35 | 36 |
36 namespace cricket { | 37 namespace cricket { |
37 | 38 |
38 struct FourCCAliasEntry { | 39 struct FourCCAliasEntry { |
39 uint32_t alias; | 40 uint32_t alias; |
40 uint32_t canonical; | 41 uint32_t canonical; |
41 }; | 42 }; |
42 | 43 |
43 static const FourCCAliasEntry kFourCCAliases[] = { | 44 static const FourCCAliasEntry kFourCCAliases[] = { |
44 {FOURCC_IYUV, FOURCC_I420}, | 45 {FOURCC_IYUV, FOURCC_I420}, |
45 {FOURCC_YU16, FOURCC_I422}, | 46 {FOURCC_YU16, FOURCC_I422}, |
46 {FOURCC_YU24, FOURCC_I444}, | 47 {FOURCC_YU24, FOURCC_I444}, |
47 {FOURCC_YUYV, FOURCC_YUY2}, | 48 {FOURCC_YUYV, FOURCC_YUY2}, |
48 {FOURCC_YUVS, FOURCC_YUY2}, | 49 {FOURCC_YUVS, FOURCC_YUY2}, |
49 {FOURCC_HDYC, FOURCC_UYVY}, | 50 {FOURCC_HDYC, FOURCC_UYVY}, |
50 {FOURCC_2VUY, FOURCC_UYVY}, | 51 {FOURCC_2VUY, FOURCC_UYVY}, |
51 {FOURCC_JPEG, FOURCC_MJPG}, // Note: JPEG has DHT while MJPG does not. | 52 {FOURCC_JPEG, FOURCC_MJPG}, // Note: JPEG has DHT while MJPG does not. |
52 {FOURCC_DMB1, FOURCC_MJPG}, | 53 {FOURCC_DMB1, FOURCC_MJPG}, |
53 {FOURCC_BA81, FOURCC_BGGR}, | 54 {FOURCC_BA81, FOURCC_BGGR}, |
54 {FOURCC_RGB3, FOURCC_RAW}, | 55 {FOURCC_RGB3, FOURCC_RAW}, |
55 {FOURCC_BGR3, FOURCC_24BG}, | 56 {FOURCC_BGR3, FOURCC_24BG}, |
56 {FOURCC_CM32, FOURCC_BGRA}, | 57 {FOURCC_CM32, FOURCC_BGRA}, |
57 {FOURCC_CM24, FOURCC_RAW}, | 58 {FOURCC_CM24, FOURCC_RAW}, |
58 }; | 59 }; |
59 | 60 |
60 uint32_t CanonicalFourCC(uint32_t fourcc) { | 61 uint32_t CanonicalFourCC(uint32_t fourcc) { |
61 for (int i = 0; i < ARRAY_SIZE(kFourCCAliases); ++i) { | 62 for (int i = 0; i < arraysize(kFourCCAliases); ++i) { |
62 if (kFourCCAliases[i].alias == fourcc) { | 63 if (kFourCCAliases[i].alias == fourcc) { |
63 return kFourCCAliases[i].canonical; | 64 return kFourCCAliases[i].canonical; |
64 } | 65 } |
65 } | 66 } |
66 // Not an alias, so return it as-is. | 67 // Not an alias, so return it as-is. |
67 return fourcc; | 68 return fourcc; |
68 } | 69 } |
69 | 70 |
70 static float kScaleFactors[] = { | 71 static float kScaleFactors[] = { |
71 1.f / 1.f, // Full size. | 72 1.f / 1.f, // Full size. |
72 1.f / 2.f, // 1/2 scale. | 73 1.f / 2.f, // 1/2 scale. |
73 1.f / 4.f, // 1/4 scale. | 74 1.f / 4.f, // 1/4 scale. |
74 1.f / 8.f, // 1/8 scale. | 75 1.f / 8.f, // 1/8 scale. |
75 1.f / 16.f // 1/16 scale. | 76 1.f / 16.f // 1/16 scale. |
76 }; | 77 }; |
77 | 78 |
78 static const int kNumScaleFactors = ARRAY_SIZE(kScaleFactors); | 79 static const int kNumScaleFactors = arraysize(kScaleFactors); |
79 | 80 |
80 // Finds the scale factor that, when applied to width and height, produces | 81 // Finds the scale factor that, when applied to width and height, produces |
81 // fewer than num_pixels. | 82 // fewer than num_pixels. |
82 static float FindLowerScale(int width, int height, int target_num_pixels) { | 83 static float FindLowerScale(int width, int height, int target_num_pixels) { |
83 if (!target_num_pixels) { | 84 if (!target_num_pixels) { |
84 return 0.f; | 85 return 0.f; |
85 } | 86 } |
86 int best_distance = INT_MAX; | 87 int best_distance = INT_MAX; |
87 int best_index = kNumScaleFactors - 1; // Default to max scale. | 88 int best_index = kNumScaleFactors - 1; // Default to max scale. |
88 for (int i = 0; i < kNumScaleFactors; ++i) { | 89 for (int i = 0; i < kNumScaleFactors; ++i) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 238 } |
238 } | 239 } |
239 | 240 |
240 std::ostringstream ss; | 241 std::ostringstream ss; |
241 ss << fourcc_name << width << "x" << height << "x" | 242 ss << fourcc_name << width << "x" << height << "x" |
242 << IntervalToFpsFloat(interval); | 243 << IntervalToFpsFloat(interval); |
243 return ss.str(); | 244 return ss.str(); |
244 } | 245 } |
245 | 246 |
246 } // namespace cricket | 247 } // namespace cricket |
OLD | NEW |