jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 9 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "media/base/videocommon.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
| 13 | #include <limits.h> // For INT_MAX |
| 14 | #include <math.h> |
| 15 | #include <sstream> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "rtc_base/arraysize.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | |
| 19 | namespace cricket { |
| 20 | |
| 21 | struct FourCCAliasEntry { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 22 | uint32_t alias; |
| 23 | uint32_t canonical; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | static const FourCCAliasEntry kFourCCAliases[] = { |
| 27 | {FOURCC_IYUV, FOURCC_I420}, |
| 28 | {FOURCC_YU16, FOURCC_I422}, |
| 29 | {FOURCC_YU24, FOURCC_I444}, |
| 30 | {FOURCC_YUYV, FOURCC_YUY2}, |
| 31 | {FOURCC_YUVS, FOURCC_YUY2}, |
| 32 | {FOURCC_HDYC, FOURCC_UYVY}, |
| 33 | {FOURCC_2VUY, FOURCC_UYVY}, |
| 34 | {FOURCC_JPEG, FOURCC_MJPG}, // Note: JPEG has DHT while MJPG does not. |
| 35 | {FOURCC_DMB1, FOURCC_MJPG}, |
| 36 | {FOURCC_BA81, FOURCC_BGGR}, |
| 37 | {FOURCC_RGB3, FOURCC_RAW}, |
| 38 | {FOURCC_BGR3, FOURCC_24BG}, |
| 39 | {FOURCC_CM32, FOURCC_BGRA}, |
| 40 | {FOURCC_CM24, FOURCC_RAW}, |
| 41 | }; |
| 42 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 43 | uint32_t CanonicalFourCC(uint32_t fourcc) { |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 44 | for (uint32_t i = 0; i < arraysize(kFourCCAliases); ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | if (kFourCCAliases[i].alias == fourcc) { |
| 46 | return kFourCCAliases[i].canonical; |
| 47 | } |
| 48 | } |
| 49 | // Not an alias, so return it as-is. |
| 50 | return fourcc; |
| 51 | } |
| 52 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | // The C++ standard requires a namespace-scope definition of static const |
| 54 | // integral types even when they are initialized in the declaration (see |
| 55 | // [class.static.data]/4), but MSVC with /Ze is non-conforming and treats that |
| 56 | // as a multiply defined symbol error. See Also: |
| 57 | // http://msdn.microsoft.com/en-us/library/34h23df8.aspx |
| 58 | #ifndef _MSC_EXTENSIONS |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 59 | const int64_t VideoFormat::kMinimumInterval; // Initialized in header. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | #endif |
| 61 | |
| 62 | std::string VideoFormat::ToString() const { |
| 63 | std::string fourcc_name = GetFourccName(fourcc) + " "; |
| 64 | for (std::string::const_iterator i = fourcc_name.begin(); |
| 65 | i < fourcc_name.end(); ++i) { |
| 66 | // Test character is printable; Avoid isprint() which asserts on negatives. |
| 67 | if (*i < 32 || *i >= 127) { |
| 68 | fourcc_name = ""; |
| 69 | break; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | std::ostringstream ss; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 74 | ss << fourcc_name << width << "x" << height << "x" |
| 75 | << IntervalToFpsFloat(interval); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | return ss.str(); |
| 77 | } |
| 78 | |
| 79 | } // namespace cricket |