xbmc
FFmpeg.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "ServiceBroker.h"
12 #include "utils/CPUInfo.h"
13 #include "utils/StringUtils.h"
14 
15 extern "C" {
16 #include <libavcodec/avcodec.h>
17 #include <libavformat/avformat.h>
18 #include <libavutil/avutil.h>
19 #include <libavutil/log.h>
20 #include <libavutil/ffversion.h>
21 #include <libavfilter/avfilter.h>
22 #include <libpostproc/postprocess.h>
23 }
24 
25 #include <tuple>
26 
27 namespace FFMPEG_HELP_TOOLS
28 {
29 
30 struct FFMpegException : public std::exception
31 {
32  std::string s;
33  template<typename... Args>
34  FFMpegException(const std::string& fmt, Args&&... args)
35  : s(StringUtils::Format(fmt, std::forward<Args>(args)...))
36  {
37  }
38  const char* what() const noexcept override { return s.c_str(); }
39 };
40 
41 std::string FFMpegErrorToString(int err);
42 
43 } // namespace FFMPEG_HELP_TOOLS
44 
45 inline int PPCPUFlags()
46 {
47  unsigned int cpuFeatures = CServiceBroker::GetCPUInfo()->GetCPUFeatures();
48  int flags = 0;
49 
50  if (cpuFeatures & CPU_FEATURE_MMX)
51  flags |= PP_CPU_CAPS_MMX;
52  if (cpuFeatures & CPU_FEATURE_MMX2)
53  flags |= PP_CPU_CAPS_MMX2;
54  if (cpuFeatures & CPU_FEATURE_3DNOW)
55  flags |= PP_CPU_CAPS_3DNOW;
56  if (cpuFeatures & CPU_FEATURE_ALTIVEC)
57  flags |= PP_CPU_CAPS_ALTIVEC;
58 
59  return flags;
60 }
61 
62 // callback used for logging
63 void ff_avutil_log(void* ptr, int level, const char* format, va_list va);
64 void ff_flush_avutil_log_buffers(void);
65 
67 {
68 public:
69  static void SetLogLevel(int level);
70  static int GetLogLevel();
71  static void ClearLogLevel();
72  int level;
73 };
74 
76 {
77 public:
78  FFmpegExtraData() = default;
79  explicit FFmpegExtraData(size_t size);
80  FFmpegExtraData(const uint8_t* data, size_t size);
81  FFmpegExtraData(const FFmpegExtraData& other);
82  FFmpegExtraData(FFmpegExtraData&& other) noexcept;
83 
84  ~FFmpegExtraData();
85 
86  FFmpegExtraData& operator=(const FFmpegExtraData& other);
87  FFmpegExtraData& operator=(FFmpegExtraData&& other) noexcept;
88 
89  bool operator==(const FFmpegExtraData& other) const;
90  bool operator!=(const FFmpegExtraData& other) const;
91 
92  operator bool() const { return m_data != nullptr && m_size != 0; }
93  uint8_t* GetData() { return m_data; }
94  const uint8_t* GetData() const { return m_data; }
95  size_t GetSize() const { return m_size; }
104  uint8_t* TakeData();
105 
106 private:
107  uint8_t* m_data{nullptr};
108  size_t m_size{};
109 };
110 
111 FFmpegExtraData GetPacketExtradata(const AVPacket* pkt, const AVCodecParameters* codecPar);
Definition: FFmpeg.h:75
Definition: FFmpeg.h:30
static std::string Format(const std::string &fmt, Args &&... args)
Get a formatted string similar to sprintf.
Definition: StringUtils.h:79
Definition: FFmpeg.h:66
Definition: FFmpeg.cpp:29