MobileFFmpegConfig.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Copyright (c) 2018 Taner Sener
  3. *
  4. * This file is part of MobileFFmpeg.
  5. *
  6. * MobileFFmpeg is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * MobileFFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <stdio.h>
  20. #include <pthread.h>
  21. #include <unistd.h>
  22. #include <Foundation/Foundation.h>
  23. #include "LogDelegate.h"
  24. #include "StatisticsDelegate.h"
  25. /** Common return code values */
  26. extern int const RETURN_CODE_SUCCESS;
  27. extern int const RETURN_CODE_CANCEL;
  28. /** Identifier used for IOS logging. */
  29. extern NSString *const LIB_NAME;
  30. /**
  31. * Print no output.
  32. */
  33. #define AV_LOG_QUIET -8
  34. /**
  35. * Something went really wrong and we will crash now.
  36. */
  37. #define AV_LOG_PANIC 0
  38. /**
  39. * Something went wrong and recovery is not possible.
  40. * For example, no header was found for a format which depends
  41. * on headers or an illegal combination of parameters is used.
  42. */
  43. #define AV_LOG_FATAL 8
  44. /**
  45. * Something went wrong and cannot losslessly be recovered.
  46. * However, not all future data is affected.
  47. */
  48. #define AV_LOG_ERROR 16
  49. /**
  50. * Something somehow does not look correct. This may or may not
  51. * lead to problems. An example would be the use of '-vstrict -2'.
  52. */
  53. #define AV_LOG_WARNING 24
  54. /**
  55. * Standard information.
  56. */
  57. #define AV_LOG_INFO 32
  58. /**
  59. * Detailed information.
  60. */
  61. #define AV_LOG_VERBOSE 40
  62. /**
  63. * Stuff which is only useful for libav* developers.
  64. */
  65. #define AV_LOG_DEBUG 48
  66. /**
  67. * This class is used to configure MobileFFmpeg library utilities/tools.
  68. *
  69. * 1. LogDelegate: This class redirects FFmpeg/FFprobe output to NSLog by default. As
  70. * an alternative, it is possible not to print messages to NSLog and pass them to a
  71. * LogDelegate function. This function can decide whether to print these logs, show them
  72. * inside another container or ignore them.
  73. *
  74. * 2. setLogLevel:/getLogLevel: Use this methods to set/get
  75. * FFmpeg/FFprobe log severity.
  76. *
  77. * 3. StatsDelegate: It is possible to receive statistics about ongoing
  78. * operation by defining a StatsDelegate or by calling
  79. * getLastReceivedStats method.
  80. *
  81. * 4. Font configuration: It is possible to register custom fonts with
  82. * setFontconfigConfigurationPath: and
  83. * setFontDirectory:with: methods.
  84. *
  85. */
  86. @interface MobileFFmpegConfig : NSObject
  87. /**
  88. * Enables log and statistics redirection.
  89. * When redirection is not enabled FFmpeg/FFprobe logs are printed to stderr. By enabling
  90. * redirection, they are routed to NSLog and can be routed further to a log delegate.
  91. * Statistics redirection behaviour is similar. Statistics are not printed at all if
  92. * redirection is not enabled. If it is enabled then it is possible to define a statistics
  93. * delegate but if you don't, they are not printed anywhere and only saved as
  94. * 'lastReceivedStatistics' data which can be polled with
  95. * '{@link #'getLastReceivedStatistics()'.
  96. * Note that redirection is enabled by default. If you do not want to use its functionality
  97. * please use 'disableRedirection()' to disable it.
  98. */
  99. + (void)enableRedirection;
  100. /**
  101. * Disables log and statistics redirection.
  102. */
  103. + (void)disableRedirection;
  104. /**
  105. * Returns log level.
  106. *
  107. * @return log level
  108. */
  109. + (int)getLogLevel;
  110. /**
  111. * Sets log level.
  112. *
  113. * @param level log level
  114. */
  115. + (void)setLogLevel:(int)level;
  116. /**
  117. * Converts int log level to string.
  118. *
  119. * @param level value
  120. * @return string value
  121. */
  122. + (NSString*)logLevelToString:(int)level;
  123. /**
  124. * Sets a LogDelegate. logCallback method inside LogDelegate is used to redirect logs.
  125. *
  126. * @param newLogDelegate log delegate or nil to disable a previously defined delegate
  127. */
  128. + (void)setLogDelegate:(id<LogDelegate>)newLogDelegate;
  129. /**
  130. * Sets a StatisticsDelegate. statisticsCallback method inside StatisticsDelegate is used to redirect statistics.
  131. *
  132. * @param newStatisticsDelegate statistics delegate or nil to disable a previously defined delegate
  133. */
  134. + (void)setStatisticsDelegate:(id<StatisticsDelegate>)newStatisticsDelegate;
  135. /**
  136. * Returns the last received statistics data. It is recommended to call it before starting a new execution.
  137. *
  138. * @return last received statistics data
  139. */
  140. + (Statistics*)getLastReceivedStatistics;
  141. /**
  142. * Resets last received statistics.
  143. */
  144. + (void)resetStatistics;
  145. /**
  146. * Sets and overrides fontconfig configuration directory.
  147. *
  148. * @param path directory which contains fontconfig configuration (fonts.conf)
  149. */
  150. + (void)setFontconfigConfigurationPath:(NSString*)path;
  151. /**
  152. * Registers fonts inside the given path, so they are available to use in FFmpeg filters.
  153. *
  154. * Note that you need to build MobileFFmpeg with fontconfig
  155. * enabled or use a prebuilt package with fontconfig inside to use this feature.
  156. *
  157. * @param fontDirectoryPath directory which contains fonts (.ttf and .otf files)
  158. * @param fontNameMapping custom font name mappings, useful to access your fonts with more friendly names
  159. */
  160. + (void)setFontDirectory:(NSString*)fontDirectoryPath with:(NSDictionary*)fontNameMapping;
  161. /**
  162. * Returns package name.
  163. *
  164. * @return guessed package name according to supported external libraries
  165. */
  166. + (NSString*)getPackageName;
  167. /**
  168. * Returns supported external libraries.
  169. *
  170. * @return array of supported external libraries
  171. */
  172. + (NSArray*)getExternalLibraries;
  173. /**
  174. * Creates a new named pipe to use in FFmpeg operations.
  175. *
  176. * Please note that creator is responsible of closing created pipes.
  177. *
  178. * @return the full path of named pipe
  179. */
  180. + (NSString*)registerNewFFmpegPipe;
  181. /**
  182. * Closes a previously created FFmpeg pipe.
  183. *
  184. * @param ffmpegPipePath full path of ffmpeg pipe
  185. */
  186. + (void)closeFFmpegPipe:(NSString*)ffmpegPipePath;
  187. /**
  188. * Returns FFmpeg version bundled within the library.
  189. *
  190. * @return FFmpeg version
  191. */
  192. + (NSString*)getFFmpegVersion;
  193. /**
  194. * Returns MobileFFmpeg library version.
  195. *
  196. * @return MobileFFmpeg version
  197. */
  198. + (NSString*)getVersion;
  199. /**
  200. * Returns MobileFFmpeg library build date.
  201. *
  202. * @return MobileFFmpeg library build date
  203. */
  204. + (NSString*)getBuildDate;
  205. /**
  206. * Returns return code of last executed command.
  207. *
  208. * @return return code of last executed command
  209. */
  210. + (int)getLastReturnCode;
  211. /**
  212. * Returns log output of last executed single FFmpeg/FFprobe command.
  213. *
  214. * This method does not support executing multiple concurrent commands. If you execute
  215. * multiple commands at the same time, this method will return output from all executions.
  216. *
  217. * Please note that disabling redirection using MobileFFmpegConfig.disableRedirection() method
  218. * also disables this functionality.
  219. *
  220. * @return output of last executed command
  221. */
  222. + (NSString*)getLastCommandOutput;
  223. /**
  224. * Registers a new ignored signal. Ignored signals are not handled by the library.
  225. *
  226. * By default, the following 5 signals are handled: SIGINT, SIGQUIT, SIGPIPE, SIGTERM and SIGXCPU. Any of them can be
  227. * ignored.
  228. *
  229. * @param signum signal number to ignore
  230. */
  231. + (void)ignoreSignal:(int)signum;
  232. @end