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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "media/base/video_common.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include "api/array_view.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "rtc_base/arraysize.h" |
Jonas Olsson | 88c9956 | 2018-05-03 11:45:33 +0200 | [diff] [blame] | 15 | #include "rtc_base/strings/string_builder.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 16 | |
| 17 | namespace cricket { |
| 18 | |
| 19 | struct FourCCAliasEntry { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 20 | uint32_t alias; |
| 21 | uint32_t canonical; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | static const FourCCAliasEntry kFourCCAliases[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 25 | {FOURCC_IYUV, FOURCC_I420}, |
| 26 | {FOURCC_YU16, FOURCC_I422}, |
| 27 | {FOURCC_YU24, FOURCC_I444}, |
| 28 | {FOURCC_YUYV, FOURCC_YUY2}, |
| 29 | {FOURCC_YUVS, FOURCC_YUY2}, |
| 30 | {FOURCC_HDYC, FOURCC_UYVY}, |
| 31 | {FOURCC_2VUY, FOURCC_UYVY}, |
| 32 | {FOURCC_JPEG, FOURCC_MJPG}, // Note: JPEG has DHT while MJPG does not. |
| 33 | {FOURCC_DMB1, FOURCC_MJPG}, |
| 34 | {FOURCC_BA81, FOURCC_BGGR}, |
| 35 | {FOURCC_RGB3, FOURCC_RAW}, |
| 36 | {FOURCC_BGR3, FOURCC_24BG}, |
| 37 | {FOURCC_CM32, FOURCC_BGRA}, |
| 38 | {FOURCC_CM24, FOURCC_RAW}, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 41 | uint32_t CanonicalFourCC(uint32_t fourcc) { |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 42 | for (uint32_t i = 0; i < arraysize(kFourCCAliases); ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | if (kFourCCAliases[i].alias == fourcc) { |
| 44 | return kFourCCAliases[i].canonical; |
| 45 | } |
| 46 | } |
| 47 | // Not an alias, so return it as-is. |
| 48 | return fourcc; |
| 49 | } |
| 50 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 51 | // The C++ standard requires a namespace-scope definition of static const |
| 52 | // integral types even when they are initialized in the declaration (see |
| 53 | // [class.static.data]/4), but MSVC with /Ze is non-conforming and treats that |
| 54 | // as a multiply defined symbol error. See Also: |
| 55 | // http://msdn.microsoft.com/en-us/library/34h23df8.aspx |
| 56 | #ifndef _MSC_EXTENSIONS |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 57 | const int64_t VideoFormat::kMinimumInterval; // Initialized in header. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
| 60 | std::string VideoFormat::ToString() const { |
| 61 | std::string fourcc_name = GetFourccName(fourcc) + " "; |
| 62 | for (std::string::const_iterator i = fourcc_name.begin(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 63 | i < fourcc_name.end(); ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 64 | // Test character is printable; Avoid isprint() which asserts on negatives. |
| 65 | if (*i < 32 || *i >= 127) { |
| 66 | fourcc_name = ""; |
| 67 | break; |
| 68 | } |
| 69 | } |
| 70 | |
Jonas Olsson | 88c9956 | 2018-05-03 11:45:33 +0200 | [diff] [blame] | 71 | char buf[256]; |
| 72 | rtc::SimpleStringBuilder sb(buf); |
| 73 | sb << fourcc_name << width << "x" << height << "x" |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 74 | << IntervalToFpsFloat(interval); |
Jonas Olsson | 88c9956 | 2018-05-03 11:45:33 +0200 | [diff] [blame] | 75 | return sb.str(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | } // namespace cricket |