tor-browser

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

FFmpegUtils.h (2334B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_MEDIA_PLATFORMS_FFMPEG_FFMPEGUTILS_H_
      8 #define DOM_MEDIA_PLATFORMS_FFMPEG_FFMPEGUTILS_H_
      9 
     10 #include <cstddef>
     11 
     12 #include "FFmpegLibWrapper.h"
     13 #include "nsStringFwd.h"
     14 
     15 // This must be the last header included
     16 #include "FFmpegLibs.h"
     17 
     18 namespace mozilla {
     19 
     20 #if LIBAVCODEC_VERSION_MAJOR >= 57
     21 using FFmpegBitRate = int64_t;
     22 constexpr size_t FFmpegErrorMaxStringSize = AV_ERROR_MAX_STRING_SIZE;
     23 #else
     24 using FFmpegBitRate = int;
     25 constexpr size_t FFmpegErrorMaxStringSize = 64;
     26 #endif
     27 
     28 nsCString MakeErrorString(const FFmpegLibWrapper* aLib, int aErrNum);
     29 
     30 template <typename T, typename F>
     31 void IterateZeroTerminated(const T& aList, F&& aLambda) {
     32  for (size_t i = 0; aList[i] != 0; i++) {
     33    aLambda(aList[i]);
     34  }
     35 }
     36 
     37 inline bool IsVideoCodec(AVCodecID aCodecID) {
     38  switch (aCodecID) {
     39    case AV_CODEC_ID_H264:
     40 #if LIBAVCODEC_VERSION_MAJOR >= 54
     41    case AV_CODEC_ID_VP8:
     42 #endif
     43 #if LIBAVCODEC_VERSION_MAJOR >= 55
     44    case AV_CODEC_ID_VP9:
     45    case AV_CODEC_ID_HEVC:
     46 #endif
     47 #if LIBAVCODEC_VERSION_MAJOR >= 59
     48    case AV_CODEC_ID_AV1:
     49 #endif
     50      return true;
     51    default:
     52      return false;
     53  }
     54 }
     55 
     56 // Access the correct location for the channel count, based on ffmpeg version.
     57 template <typename T>
     58 inline int& ChannelCount(T* aObject) {
     59 #if LIBAVCODEC_VERSION_MAJOR <= 59
     60  return aObject->channels;
     61 #else
     62  return aObject->ch_layout.nb_channels;
     63 #endif
     64 }
     65 
     66 // Access the correct location for the duration, based on ffmpeg version.
     67 template <typename T>
     68 inline int64_t& Duration(T* aObject) {
     69 #if LIBAVCODEC_VERSION_MAJOR < 61
     70  return aObject->pkt_duration;
     71 #else
     72  return aObject->duration;
     73 #endif
     74 }
     75 
     76 // Access the correct location for the duration, based on ffmpeg version.
     77 template <typename T>
     78 inline const int64_t& Duration(const T* aObject) {
     79 #if LIBAVCODEC_VERSION_MAJOR < 61
     80  return aObject->pkt_duration;
     81 #else
     82  return aObject->duration;
     83 #endif
     84 }
     85 
     86 const char* AVCodecToString(const AVCodecID& aCodec);
     87 
     88 }  // namespace mozilla
     89 
     90 #endif  // DOM_MEDIA_PLATFORMS_FFMPEG_FFMPEGUTILS_H_