Advertisement
Guest User

Untitled

a guest
Oct 11th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 KB | None | 0 0
  1. /*
  2. * ZoneMinder FFMPEG Interface, $Date$, $Revision$
  3. * Copyright (C) 2001-2008 Philip Coombes
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. #ifndef ZM_FFMPEG_H
  21. #define ZM_FFMPEG_H
  22. #include <stdint.h>
  23. #include "zm.h"
  24. #include "zm_image.h"
  25.  
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29.  
  30. // AVUTIL
  31. #if HAVE_LIBAVUTIL_AVUTIL_H
  32. #include <libavutil/avutil.h>
  33. #include <libavutil/base64.h>
  34. #include <libavutil/mathematics.h>
  35. #elif HAVE_FFMPEG_AVUTIL_H
  36. #include <ffmpeg/avutil.h>
  37. #include <ffmpeg/base64.h>
  38. #include <ffmpeg/mathematics.h>
  39. #endif
  40.  
  41. // AVCODEC
  42. #if HAVE_LIBAVCODEC_AVCODEC_H
  43. #include <libavcodec/avcodec.h>
  44. #elif HAVE_FFMPEG_AVCODEC_H
  45. #include <ffmpeg/avcodec.h>
  46. #endif
  47.  
  48. #if defined(HAVE_LIBAVCODEC_AVCODEC_H) && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54,25,0)
  49. #define _AVCODECID AVCodecID
  50. #else
  51. #define _AVCODECID CodecID
  52. #endif
  53.  
  54. // AVFORMAT
  55. #if HAVE_LIBAVFORMAT_AVFORMAT_H
  56. #include <libavformat/avformat.h>
  57. #elif HAVE_FFMPEG_AVFORMAT_H
  58. #include <ffmpeg/avformat.h>
  59. #endif
  60.  
  61. // AVDEVICE
  62. #if HAVE_LIBAVDEVICE_AVDEVICE_H
  63. #include <libavdevice/avdevice.h>
  64. #elif HAVE_FFMPEG_AVDEVICE_H
  65. #include <ffmpeg/avdevice.h>
  66. #endif
  67.  
  68. // SWSCALE
  69. #if HAVE_LIBSWSCALE_SWSCALE_H
  70. #include <libswscale/swscale.h>
  71. #elif HAVE_FFMPEG_SWSCALE_H
  72. #include <ffmpeg/swscale.h>
  73. #endif
  74.  
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78.  
  79. #if ( HAVE_LIBAVUTIL_AVUTIL_H || HAVE_LIBAVCODEC_AVCODEC_H || HAVE_LIBAVFORMAT_AVFORMAT_H || HAVE_LIBAVDEVICE_AVDEVICE_H )
  80.  
  81. #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 4, 0)
  82. #if defined(AVIO_WRONLY)
  83. #define AVIO_FLAG_WRITE AVIO_WRONLY
  84. #else
  85. #define AVIO_FLAG_WRITE URL_WRONLY
  86. #endif
  87. #endif
  88.  
  89. /* Fix for not having SWS_CPU_CAPS_SSE2 defined */
  90. #ifndef SWS_CPU_CAPS_SSE2
  91. #define SWS_CPU_CAPS_SSE2 0x02000000
  92. #endif
  93.  
  94.  
  95. #if HAVE_LIBAVUTIL
  96. enum PixelFormat GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixelorder);
  97. #endif // HAVE_LIBAVUTIL
  98.  
  99.  
  100. /* SWScale wrapper class to make our life easier and reduce code reuse */
  101. #if HAVE_LIBSWSCALE && HAVE_LIBAVUTIL
  102. class SWScale {
  103. public:
  104. SWScale();
  105. ~SWScale();
  106. int SetDefaults(enum PixelFormat in_pf, enum PixelFormat out_pf, unsigned int width, unsigned int height);
  107. int ConvertDefaults(const Image* img, uint8_t* out_buffer, const size_t out_buffer_size);
  108. int ConvertDefaults(const uint8_t* in_buffer, const size_t in_buffer_size, uint8_t* out_buffer, const size_t out_buffer_size);
  109. int Convert(const Image* img, uint8_t* out_buffer, const size_t out_buffer_size, enum PixelFormat in_pf, enum PixelFormat out_pf, unsigned int width, unsigned int height);
  110. int Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint8_t* out_buffer, const size_t out_buffer_size, enum PixelFormat in_pf, enum PixelFormat out_pf, unsigned int width, unsigned int height);
  111.  
  112. protected:
  113. bool gotdefaults;
  114. struct SwsContext* swscale_ctx;
  115. AVFrame* input_avframe;
  116. AVFrame* output_avframe;
  117. enum PixelFormat default_input_pf;
  118. enum PixelFormat default_output_pf;
  119. unsigned int default_width;
  120. unsigned int default_height;
  121. };
  122. #endif // HAVE_LIBSWSCALE && HAVE_LIBAVUTIL
  123.  
  124. #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 25, 0)
  125. #define AV_CODEC_ID_NONE CODEC_ID_NONE
  126. #define AV_CODEC_ID_PCM_MULAW CODEC_ID_PCM_MULAW
  127. #define AV_CODEC_ID_PCM_ALAW CODEC_ID_PCM_ALAW
  128. #define AV_CODEC_ID_PCM_S16BE CODEC_ID_PCM_S16BE
  129. #define AV_CODEC_ID_QCELP CODEC_ID_QCELP
  130. #define AV_CODEC_ID_MP2 CODEC_ID_MP2
  131. #define AV_CODEC_ID_MP3 CODEC_ID_MP3
  132. #define AV_CODEC_ID_MJPEG CODEC_ID_MJPEG
  133. #define AV_CODEC_ID_H261 CODEC_ID_H261
  134. #define AV_CODEC_ID_MPEG1VIDEO CODEC_ID_MPEG1VIDEO
  135. #define AV_CODEC_ID_MPEG2VIDEO CODEC_ID_MPEG2VIDEO
  136. #define AV_CODEC_ID_MPEG2TS CODEC_ID_MPEG2TS
  137. #define AV_CODEC_ID_H263 CODEC_ID_H263
  138. #define AV_CODEC_ID_H264 CODEC_ID_H264
  139. #define AV_CODEC_ID_MPEG4 CODEC_ID_MPEG4
  140. #define AV_CODEC_ID_AAC CODEC_ID_AAC
  141. #define AV_CODEC_ID_AMR_NB CODEC_ID_AMR_NB
  142. #endif
  143.  
  144. /*
  145. * Some versions of libav does not contain this definition.
  146. */
  147. #ifndef AV_ERROR_MAX_STRING_SIZE
  148. #define AV_ERROR_MAX_STRING_SIZE 64
  149. #endif
  150.  
  151. /*
  152. * C++ friendly version of av_err2str taken from http://libav-users.943685.n4.nabble.com/Libav-user-g-4-7-2-fails-to-compile-av-err2str-td4656417.html.
  153. * Newer g++ versions fail with "error: taking address of temporary array" when using native libav version.
  154. */
  155. #ifdef __cplusplus
  156.  
  157. inline static const std::string av_make_error_string(int errnum)
  158. {
  159. char errbuf[AV_ERROR_MAX_STRING_SIZE];
  160. #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(50, 12, 13)
  161. av_strerror(errnum, errbuf, AV_ERROR_MAX_STRING_SIZE);
  162. #else
  163. snprintf(errbuf, AV_ERROR_MAX_STRING_SIZE, "libav error %d", errnum);
  164. #endif
  165. return (std::string)errbuf;
  166. }
  167.  
  168. #undef av_err2str
  169. #define av_err2str(errnum) av_make_error_string(errnum).c_str()
  170.  
  171. #endif // __cplusplus
  172.  
  173.  
  174. #endif // ( HAVE_LIBAVUTIL_AVUTIL_H || HAVE_LIBAVCODEC_AVCODEC_H || HAVE_LIBAVFORMAT_AVFORMAT_H || HAVE_LIBAVDEVICE_AVDEVICE_H )
  175.  
  176. #endif // ZM_FFMPEG_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement