blob: 1035757af1b60effae01814ed038321b11cc76c0 [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved.
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * 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.org5f93d0a2015-01-20 21:36:13 +00009 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000010
Steve Anton10542f22019-01-11 09:11:00 -080011#include "media/base/video_common.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012
Yves Gerey3e707812018-11-28 16:47:49 +010013#include "api/array_view.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "rtc_base/arraysize.h"
Jonas Olsson88c99562018-05-03 11:45:33 +020015#include "rtc_base/strings/string_builder.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
17namespace cricket {
18
19struct FourCCAliasEntry {
Peter Boström0c4e06b2015-10-07 12:23:21 +020020 uint32_t alias;
21 uint32_t canonical;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000022};
23
24static const FourCCAliasEntry kFourCCAliases[] = {
Yves Gerey665174f2018-06-19 15:03:05 +020025 {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.org28e20752013-07-10 00:45:36 +000039};
40
Peter Boström0c4e06b2015-10-07 12:23:21 +020041uint32_t CanonicalFourCC(uint32_t fourcc) {
kjellandera96e2d72016-02-04 23:52:28 -080042 for (uint32_t i = 0; i < arraysize(kFourCCAliases); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043 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.org28e20752013-07-10 00:45:36 +000051// 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öm0c4e06b2015-10-07 12:23:21 +020057const int64_t VideoFormat::kMinimumInterval; // Initialized in header.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058#endif
59
60std::string VideoFormat::ToString() const {
61 std::string fourcc_name = GetFourccName(fourcc) + " ";
62 for (std::string::const_iterator i = fourcc_name.begin();
Yves Gerey665174f2018-06-19 15:03:05 +020063 i < fourcc_name.end(); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064 // 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 Olsson88c99562018-05-03 11:45:33 +020071 char buf[256];
72 rtc::SimpleStringBuilder sb(buf);
73 sb << fourcc_name << width << "x" << height << "x"
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000074 << IntervalToFpsFloat(interval);
Jonas Olsson88c99562018-05-03 11:45:33 +020075 return sb.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076}
77
78} // namespace cricket