tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

video_common.cc (3001B)


      1 /*
      2 *  Copyright (c) 2010 The WebRTC project authors. All Rights Reserved.
      3 *
      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.
      9 */
     10 
     11 #include "media/base/video_common.h"
     12 
     13 #include <cstdint>
     14 #include <numeric>
     15 #include <string>
     16 
     17 #include "api/array_view.h"
     18 #include "rtc_base/checks.h"
     19 #include "rtc_base/strings/string_builder.h"
     20 
     21 namespace webrtc {
     22 
     23 struct FourCCAliasEntry {
     24  uint32_t alias;
     25  uint32_t canonical;
     26 };
     27 
     28 static const FourCCAliasEntry kFourCCAliases[] = {
     29    {.alias = FOURCC_IYUV, .canonical = FOURCC_I420},
     30    {.alias = FOURCC_YU16, .canonical = FOURCC_I422},
     31    {.alias = FOURCC_YU24, .canonical = FOURCC_I444},
     32    {.alias = FOURCC_YUYV, .canonical = FOURCC_YUY2},
     33    {.alias = FOURCC_YUVS, .canonical = FOURCC_YUY2},
     34    {.alias = FOURCC_HDYC, .canonical = FOURCC_UYVY},
     35    {.alias = FOURCC_2VUY, .canonical = FOURCC_UYVY},
     36    {.alias = FOURCC_JPEG,
     37     .canonical = FOURCC_MJPG},  // Note: JPEG has DHT while MJPG does not.
     38    {.alias = FOURCC_DMB1, .canonical = FOURCC_MJPG},
     39    {.alias = FOURCC_BA81, .canonical = FOURCC_BGGR},
     40    {.alias = FOURCC_RGB3, .canonical = FOURCC_RAW},
     41    {.alias = FOURCC_BGR3, .canonical = FOURCC_24BG},
     42    {.alias = FOURCC_CM32, .canonical = FOURCC_BGRA},
     43    {.alias = FOURCC_CM24, .canonical = FOURCC_RAW},
     44 };
     45 
     46 uint32_t CanonicalFourCC(uint32_t fourcc) {
     47  for (const FourCCAliasEntry& entry : kFourCCAliases) {
     48    if (entry.alias == fourcc) {
     49      return entry.canonical;
     50    }
     51  }
     52  // Not an alias, so return it as-is.
     53  return fourcc;
     54 }
     55 
     56 // The C++ standard requires a namespace-scope definition of static const
     57 // integral types even when they are initialized in the declaration (see
     58 // [class.static.data]/4), but MSVC with /Ze is non-conforming and treats that
     59 // as a multiply defined symbol error. See Also:
     60 // http://msdn.microsoft.com/en-us/library/34h23df8.aspx
     61 #ifndef _MSC_EXTENSIONS
     62 const int64_t VideoFormat::kMinimumInterval;  // Initialized in header.
     63 #endif
     64 
     65 std::string VideoFormat::ToString() const {
     66  std::string fourcc_name = GetFourccName(fourcc) + " ";
     67  for (std::string::const_iterator i = fourcc_name.begin();
     68       i < fourcc_name.end(); ++i) {
     69    // Test character is printable; Avoid isprint() which asserts on negatives.
     70    if (*i < 32 || *i >= 127) {
     71      fourcc_name = "";
     72      break;
     73    }
     74  }
     75 
     76  char buf[256];
     77  SimpleStringBuilder sb(buf);
     78  sb << fourcc_name << width << "x" << height << "x"
     79     << IntervalToFpsFloat(interval);
     80  return sb.str();
     81 }
     82 
     83 int GreatestCommonDivisor(int a, int b) {
     84  RTC_DCHECK_GE(a, 0);
     85  RTC_DCHECK_GT(b, 0);
     86  return std::gcd(a, b);
     87 }
     88 
     89 int LeastCommonMultiple(int a, int b) {
     90  RTC_DCHECK_GT(a, 0);
     91  RTC_DCHECK_GT(b, 0);
     92  return std::lcm(a, b);
     93 }
     94 
     95 }  // namespace webrtc