blob: e5168b55ca4685d89d430945bfc3e0a6c04b42d5 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "media/base/videocommon.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012
13#include <limits.h> // For INT_MAX
14#include <math.h>
15#include <sstream>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "rtc_base/arraysize.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018
19namespace cricket {
20
21struct FourCCAliasEntry {
Peter Boström0c4e06b2015-10-07 12:23:21 +020022 uint32_t alias;
23 uint32_t canonical;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024};
25
26static 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öm0c4e06b2015-10-07 12:23:21 +020043uint32_t CanonicalFourCC(uint32_t fourcc) {
kjellandera96e2d72016-02-04 23:52:28 -080044 for (uint32_t i = 0; i < arraysize(kFourCCAliases); ++i) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045 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.org28e20752013-07-10 00:45:36 +000053// 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öm0c4e06b2015-10-07 12:23:21 +020059const int64_t VideoFormat::kMinimumInterval; // Initialized in header.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060#endif
61
62std::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.org4b26e2e2014-01-15 23:15:54 +000074 ss << fourcc_name << width << "x" << height << "x"
75 << IntervalToFpsFloat(interval);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076 return ss.str();
77}
78
79} // namespace cricket