update header file to FFmpeg4.2

update header file to FFmpeg4.2
pull/166/head
xufulong 5 years ago
parent 729333f8c0
commit 97e2746d2e
  1. 36
      app/src/main/cpp/include/libavcodec/ac3_parser.h
  2. 37
      app/src/main/cpp/include/libavcodec/adts_parser.h
  3. 2488
      app/src/main/cpp/include/libavcodec/avcodec.h
  4. 45
      app/src/main/cpp/include/libavcodec/mathops.h
  5. 13
      app/src/main/cpp/include/libavcodec/mediacodec.h
  6. 117
      app/src/main/cpp/include/libavcodec/vaapi.h
  7. 79
      app/src/main/cpp/include/libavcodec/vdpau.h
  8. 170
      app/src/main/cpp/include/libavcodec/version.h
  9. 3
      app/src/main/cpp/include/libavcodec/videotoolbox.h
  10. 4
      app/src/main/cpp/include/libavcodec/vorbis_parser.h
  11. 253
      app/src/main/cpp/include/libavfilter/avfilter.h
  12. 28
      app/src/main/cpp/include/libavfilter/buffersink.h
  13. 84
      app/src/main/cpp/include/libavfilter/buffersrc.h
  14. 25
      app/src/main/cpp/include/libavfilter/version.h
  15. 516
      app/src/main/cpp/include/libavformat/avformat.h
  16. 193
      app/src/main/cpp/include/libavformat/avio.h
  17. 65
      app/src/main/cpp/include/libavformat/version.h
  18. 13
      app/src/main/cpp/include/libavutil/adler32.h
  19. 7
      app/src/main/cpp/include/libavutil/aes_ctr.h
  20. 19
      app/src/main/cpp/include/libavutil/attributes.h
  21. 17
      app/src/main/cpp/include/libavutil/audio_fifo.h
  22. 11
      app/src/main/cpp/include/libavutil/avassert.h
  23. 5
      app/src/main/cpp/include/libavutil/avconfig.h
  24. 13
      app/src/main/cpp/include/libavutil/avstring.h
  25. 42
      app/src/main/cpp/include/libavutil/avutil.h
  26. 9
      app/src/main/cpp/include/libavutil/base64.h
  27. 19
      app/src/main/cpp/include/libavutil/buffer.h
  28. 21
      app/src/main/cpp/include/libavutil/channel_layout.h
  29. 38
      app/src/main/cpp/include/libavutil/common.h
  30. 19
      app/src/main/cpp/include/libavutil/cpu.h
  31. 21
      app/src/main/cpp/include/libavutil/crc.h
  32. 10
      app/src/main/cpp/include/libavutil/dict.h
  33. 28
      app/src/main/cpp/include/libavutil/display.h
  34. 205
      app/src/main/cpp/include/libavutil/encryption_info.h
  35. 2
      app/src/main/cpp/include/libavutil/ffversion.h
  36. 3
      app/src/main/cpp/include/libavutil/file.h
  37. 320
      app/src/main/cpp/include/libavutil/frame.h
  38. 197
      app/src/main/cpp/include/libavutil/hash.h
  39. 343
      app/src/main/cpp/include/libavutil/hdr_dynamic_metadata.h
  40. 2
      app/src/main/cpp/include/libavutil/hmac.h
  41. 163
      app/src/main/cpp/include/libavutil/hwcontext.h
  42. 6
      app/src/main/cpp/include/libavutil/hwcontext_cuda.h
  43. 169
      app/src/main/cpp/include/libavutil/hwcontext_d3d11va.h
  44. 169
      app/src/main/cpp/include/libavutil/hwcontext_drm.h
  45. 3
      app/src/main/cpp/include/libavutil/hwcontext_dxva2.h
  46. 36
      app/src/main/cpp/include/libavutil/hwcontext_mediacodec.h
  47. 35
      app/src/main/cpp/include/libavutil/hwcontext_vaapi.h
  48. 54
      app/src/main/cpp/include/libavutil/hwcontext_videotoolbox.h
  49. 70
      app/src/main/cpp/include/libavutil/imgutils.h
  50. 43
      app/src/main/cpp/include/libavutil/intreadwrite.h
  51. 9
      app/src/main/cpp/include/libavutil/lfg.h
  52. 27
      app/src/main/cpp/include/libavutil/log.h
  53. 41
      app/src/main/cpp/include/libavutil/mastering_display_metadata.h
  54. 145
      app/src/main/cpp/include/libavutil/mathematics.h
  55. 19
      app/src/main/cpp/include/libavutil/md5.h
  56. 732
      app/src/main/cpp/include/libavutil/mem.h
  57. 88
      app/src/main/cpp/include/libavutil/murmur3.h
  58. 26
      app/src/main/cpp/include/libavutil/opt.h
  59. 256
      app/src/main/cpp/include/libavutil/pixdesc.h
  60. 179
      app/src/main/cpp/include/libavutil/pixfmt.h
  61. 119
      app/src/main/cpp/include/libavutil/rational.h
  62. 1
      app/src/main/cpp/include/libavutil/replaygain.h
  63. 28
      app/src/main/cpp/include/libavutil/reverse.h
  64. 14
      app/src/main/cpp/include/libavutil/ripemd.h
  65. 3
      app/src/main/cpp/include/libavutil/samplefmt.h
  66. 27
      app/src/main/cpp/include/libavutil/sha.h
  67. 26
      app/src/main/cpp/include/libavutil/sha512.h
  68. 232
      app/src/main/cpp/include/libavutil/spherical.h
  69. 81
      app/src/main/cpp/include/libavutil/stereo3d.h
  70. 173
      app/src/main/cpp/include/libavutil/thread.h
  71. 24
      app/src/main/cpp/include/libavutil/threadmessage.h
  72. 6
      app/src/main/cpp/include/libavutil/time_internal.h
  73. 2
      app/src/main/cpp/include/libavutil/timecode.h
  74. 93
      app/src/main/cpp/include/libavutil/timer.h
  75. 2
      app/src/main/cpp/include/libavutil/timestamp.h
  76. 6
      app/src/main/cpp/include/libavutil/tree.h
  77. 81
      app/src/main/cpp/include/libavutil/tx.h
  78. 71
      app/src/main/cpp/include/libavutil/version.h
  79. 4
      app/src/main/cpp/include/libpostproc/postprocess.h
  80. 8
      app/src/main/cpp/include/libpostproc/version.h
  81. 40
      app/src/main/cpp/include/libswresample/swresample.h
  82. 6
      app/src/main/cpp/include/libswresample/version.h
  83. 44
      app/src/main/cpp/include/libswscale/swscale.h
  84. 8
      app/src/main/cpp/include/libswscale/version.h

@ -0,0 +1,36 @@
/*
* AC-3 parser prototypes
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_AC3_PARSER_H
#define AVCODEC_AC3_PARSER_H
#include <stddef.h>
#include <stdint.h>
/**
* Extract the bitstream ID and the frame size from AC-3 data.
*/
int av_ac3_parse_header(const uint8_t *buf, size_t size,
uint8_t *bitstream_id, uint16_t *frame_size);
#endif /* AVCODEC_AC3_PARSER_H */

@ -0,0 +1,37 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_ADTS_PARSER_H
#define AVCODEC_ADTS_PARSER_H
#include <stddef.h>
#include <stdint.h>
#define AV_AAC_ADTS_HEADER_SIZE 7
/**
* Extract the number of samples and frames from AAC data.
* @param[in] buf pointer to AAC data buffer
* @param[out] samples Pointer to where number of samples is written
* @param[out] frames Pointer to where number of frames is written
* @return Returns 0 on success, error code on failure.
*/
int av_adts_header_parse(const uint8_t *buf, uint32_t *samples,
uint8_t *frames);
#endif /* AVCODEC_ADTS_PARSER_H */

File diff suppressed because it is too large Load Diff

@ -25,7 +25,8 @@
#include <stdint.h> #include <stdint.h>
#include "libavutil/common.h" #include "libavutil/common.h"
#include "ffmpeg/config.h" #include "libavutil/reverse.h"
#include "config.h"
#define MAX_NEG_CROP 1024 #define MAX_NEG_CROP 1024
@ -35,19 +36,17 @@ extern const uint8_t ff_crop_tab[256 + 2 * MAX_NEG_CROP];
extern const uint8_t ff_zigzag_direct[64]; extern const uint8_t ff_zigzag_direct[64];
extern const uint8_t ff_zigzag_scan[16+1]; extern const uint8_t ff_zigzag_scan[16+1];
//TODO #if ARCH_ARM
#include "libavcodec/arm/mathops.h" # include "arm/mathops.h"
//#if ARCH_ARM #elif ARCH_AVR32
//# include "arm/mathops.h" # include "avr32/mathops.h"
//#elif ARCH_AVR32 #elif ARCH_MIPS
//# include "avr32/mathops.h" # include "mips/mathops.h"
//#elif ARCH_MIPS #elif ARCH_PPC
//# include "mips/mathops.h" # include "ppc/mathops.h"
//#elif ARCH_PPC #elif ARCH_X86
//# include "ppc/mathops.h" # include "x86/mathops.h"
//#elif ARCH_X86 #endif
//# include "x86/mathops.h"
//#endif
/* generic implementation */ /* generic implementation */
@ -98,15 +97,6 @@ static av_always_inline unsigned UMULH(unsigned a, unsigned b){
#define mid_pred mid_pred #define mid_pred mid_pred
static inline av_const int mid_pred(int a, int b, int c) static inline av_const int mid_pred(int a, int b, int c)
{ {
#if 0
int t= (a-b)&((a-b)>>31);
a-=t;
b+=t;
b-= (b-c)&((b-c)>>31);
b+= (a-b)&((a-b)>>31);
return b;
#else
if(a>b){ if(a>b){
if(c>b){ if(c>b){
if(c>a) b=a; if(c>a) b=a;
@ -119,7 +109,6 @@ static inline av_const int mid_pred(int a, int b, int c)
} }
} }
return b; return b;
#endif
} }
#endif #endif
@ -251,4 +240,12 @@ static inline int8_t ff_u8_to_s8(uint8_t a)
return b.s8; return b.s8;
} }
static av_always_inline uint32_t bitswap_32(uint32_t x)
{
return (uint32_t)ff_reverse[ x & 0xFF] << 24 |
(uint32_t)ff_reverse[(x >> 8) & 0xFF] << 16 |
(uint32_t)ff_reverse[(x >> 16) & 0xFF] << 8 |
(uint32_t)ff_reverse[ x >> 24];
}
#endif /* AVCODEC_MATHOPS_H */ #endif /* AVCODEC_MATHOPS_H */

@ -85,4 +85,17 @@ typedef struct MediaCodecBuffer AVMediaCodecBuffer;
*/ */
int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render); int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render);
/**
* Release a MediaCodec buffer and render it at the given time to the surface
* that is associated with the decoder. The timestamp must be within one second
* of the current java/lang/System#nanoTime() (which is implemented using
* CLOCK_MONOTONIC on Android). See the Android MediaCodec documentation
* of android/media/MediaCodec#releaseOutputBuffer(int,long) for more details.
*
* @param buffer the buffer to render
* @param time timestamp in nanoseconds of when to render the buffer
* @return 0 on success, < 0 otherwise
*/
int av_mediacodec_render_buffer_at_time(AVMediaCodecBuffer *buffer, int64_t time);
#endif /* AVCODEC_MEDIACODEC_H */ #endif /* AVCODEC_MEDIACODEC_H */

@ -34,6 +34,8 @@
#include "libavutil/attributes.h" #include "libavutil/attributes.h"
#include "version.h" #include "version.h"
#if FF_API_STRUCT_VAAPI_CONTEXT
/** /**
* @defgroup lavc_codec_hwaccel_vaapi VA API Decoding * @defgroup lavc_codec_hwaccel_vaapi VA API Decoding
* @ingroup lavc_codec_hwaccel * @ingroup lavc_codec_hwaccel
@ -48,8 +50,10 @@
* during initialization or through each AVCodecContext.get_buffer() * during initialization or through each AVCodecContext.get_buffer()
* function call. In any case, they must be valid prior to calling * function call. In any case, they must be valid prior to calling
* decoding functions. * decoding functions.
*
* Deprecated: use AVCodecContext.hw_frames_ctx instead.
*/ */
struct vaapi_context { struct attribute_deprecated vaapi_context {
/** /**
* Window system dependent data * Window system dependent data
* *
@ -73,117 +77,10 @@ struct vaapi_context {
* - decoding: Set by user * - decoding: Set by user
*/ */
uint32_t context_id; uint32_t context_id;
#if FF_API_VAAPI_CONTEXT
/**
* VAPictureParameterBuffer ID
*
* - encoding: unused
* - decoding: Set by libavcodec
*/
attribute_deprecated
uint32_t pic_param_buf_id;
/**
* VAIQMatrixBuffer ID
*
* - encoding: unused
* - decoding: Set by libavcodec
*/
attribute_deprecated
uint32_t iq_matrix_buf_id;
/**
* VABitPlaneBuffer ID (for VC-1 decoding)
*
* - encoding: unused
* - decoding: Set by libavcodec
*/
attribute_deprecated
uint32_t bitplane_buf_id;
/**
* Slice parameter/data buffer IDs
*
* - encoding: unused
* - decoding: Set by libavcodec
*/
attribute_deprecated
uint32_t *slice_buf_ids;
/**
* Number of effective slice buffer IDs to send to the HW
*
* - encoding: unused
* - decoding: Set by libavcodec
*/
attribute_deprecated
unsigned int n_slice_buf_ids;
/**
* Size of pre-allocated slice_buf_ids
*
* - encoding: unused
* - decoding: Set by libavcodec
*/
attribute_deprecated
unsigned int slice_buf_ids_alloc;
/**
* Pointer to VASliceParameterBuffers
*
* - encoding: unused
* - decoding: Set by libavcodec
*/
attribute_deprecated
void *slice_params;
/**
* Size of a VASliceParameterBuffer element
*
* - encoding: unused
* - decoding: Set by libavcodec
*/
attribute_deprecated
unsigned int slice_param_size;
/**
* Size of pre-allocated slice_params
*
* - encoding: unused
* - decoding: Set by libavcodec
*/
attribute_deprecated
unsigned int slice_params_alloc;
/**
* Number of slices currently filled in
*
* - encoding: unused
* - decoding: Set by libavcodec
*/
attribute_deprecated
unsigned int slice_count;
/**
* Pointer to slice data buffer base
* - encoding: unused
* - decoding: Set by libavcodec
*/
attribute_deprecated
const uint8_t *slice_data;
/**
* Current size of slice data
*
* - encoding: unused
* - decoding: Set by libavcodec
*/
attribute_deprecated
uint32_t slice_data_size;
#endif
}; };
/* @} */ /* @} */
#endif /* FF_API_STRUCT_VAAPI_CONTEXT */
#endif /* AVCODEC_VAAPI_H */ #endif /* AVCODEC_VAAPI_H */

@ -50,22 +50,13 @@
*/ */
#include <vdpau/vdpau.h> #include <vdpau/vdpau.h>
#include <vdpau/vdpau_x11.h>
#include "libavutil/avconfig.h" #include "libavutil/avconfig.h"
#include "libavutil/attributes.h" #include "libavutil/attributes.h"
#include "avcodec.h" #include "avcodec.h"
#include "version.h" #include "version.h"
#if FF_API_BUFS_VDPAU
union AVVDPAUPictureInfo {
VdpPictureInfoH264 h264;
VdpPictureInfoMPEG1Or2 mpeg;
VdpPictureInfoVC1 vc1;
VdpPictureInfoMPEG4Part2 mpeg4;
};
#endif
struct AVCodecContext; struct AVCodecContext;
struct AVFrame; struct AVFrame;
@ -102,40 +93,6 @@ typedef struct AVVDPAUContext {
*/ */
VdpDecoderRender *render; VdpDecoderRender *render;
#if FF_API_BUFS_VDPAU
/**
* VDPAU picture information
*
* Set by libavcodec.
*/
attribute_deprecated
union AVVDPAUPictureInfo info;
/**
* Allocated size of the bitstream_buffers table.
*
* Set by libavcodec.
*/
attribute_deprecated
int bitstream_buffers_allocated;
/**
* Useful bitstream buffers in the bitstream buffers table.
*
* Set by libavcodec.
*/
attribute_deprecated
int bitstream_buffers_used;
/**
* Table of bitstream buffers.
* The user is responsible for freeing this buffer using av_freep().
*
* Set by libavcodec.
*/
attribute_deprecated
VdpBitstreamBuffer *bitstream_buffers;
#endif
AVVDPAU_Render2 render2; AVVDPAU_Render2 render2;
} AVVDPAUContext; } AVVDPAUContext;
@ -214,40 +171,6 @@ attribute_deprecated
int av_vdpau_get_profile(AVCodecContext *avctx, VdpDecoderProfile *profile); int av_vdpau_get_profile(AVCodecContext *avctx, VdpDecoderProfile *profile);
#endif #endif
#if FF_API_CAP_VDPAU
/** @brief The videoSurface is used for rendering. */
#define FF_VDPAU_STATE_USED_FOR_RENDER 1
/**
* @brief The videoSurface is needed for reference/prediction.
* The codec manipulates this.
*/
#define FF_VDPAU_STATE_USED_FOR_REFERENCE 2
/**
* @brief This structure is used as a callback between the FFmpeg
* decoder (vd_) and presentation (vo_) module.
* This is used for defining a video frame containing surface,
* picture parameter, bitstream information etc which are passed
* between the FFmpeg decoder and its clients.
*/
struct vdpau_render_state {
VdpVideoSurface surface; ///< Used as rendered surface, never changed.
int state; ///< Holds FF_VDPAU_STATE_* values.
/** picture parameter information for all supported codecs */
union AVVDPAUPictureInfo info;
/** Describe size/location of the compressed video data.
Set to 0 when freeing bitstream_buffers. */
int bitstream_buffers_allocated;
int bitstream_buffers_used;
/** The user is responsible for freeing this buffer using av_freep(). */
VdpBitstreamBuffer *bitstream_buffers;
};
#endif
/* @}*/ /* @}*/
#endif /* AVCODEC_VDPAU_H */ #endif /* AVCODEC_VDPAU_H */

@ -1,5 +1,4 @@
/* /*
*
* This file is part of FFmpeg. * This file is part of FFmpeg.
* *
* FFmpeg is free software; you can redistribute it and/or * FFmpeg is free software; you can redistribute it and/or
@ -28,9 +27,9 @@
#include "libavutil/version.h" #include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 57 #define LIBAVCODEC_VERSION_MAJOR 58
#define LIBAVCODEC_VERSION_MINOR 24 #define LIBAVCODEC_VERSION_MINOR 54
#define LIBAVCODEC_VERSION_MICRO 102 #define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \ LIBAVCODEC_VERSION_MINOR, \
@ -52,136 +51,18 @@
* at once through the bump. This improves the git bisect-ability of the change. * at once through the bump. This improves the git bisect-ability of the change.
*/ */
#ifndef FF_API_VIMA_DECODER
#define FF_API_VIMA_DECODER (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_AUDIO_CONVERT
#define FF_API_AUDIO_CONVERT (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_AVCODEC_RESAMPLE
#define FF_API_AVCODEC_RESAMPLE FF_API_AUDIO_CONVERT
#endif
#ifndef FF_API_GETCHROMA
#define FF_API_GETCHROMA (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_MISSING_SAMPLE
#define FF_API_MISSING_SAMPLE (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_LOWRES #ifndef FF_API_LOWRES
#define FF_API_LOWRES (LIBAVCODEC_VERSION_MAJOR < 58) #define FF_API_LOWRES (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_CAP_VDPAU
#define FF_API_CAP_VDPAU (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_BUFS_VDPAU
#define FF_API_BUFS_VDPAU (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_VOXWARE
#define FF_API_VOXWARE (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_SET_DIMENSIONS
#define FF_API_SET_DIMENSIONS (LIBAVCODEC_VERSION_MAJOR < 58)
#endif #endif
#ifndef FF_API_DEBUG_MV #ifndef FF_API_DEBUG_MV
#define FF_API_DEBUG_MV (LIBAVCODEC_VERSION_MAJOR < 58) #define FF_API_DEBUG_MV (LIBAVCODEC_VERSION_MAJOR < 58)
#endif #endif
#ifndef FF_API_AC_VLC
#define FF_API_AC_VLC (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_OLD_MSMPEG4
#define FF_API_OLD_MSMPEG4 (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_ASPECT_EXTENDED
#define FF_API_ASPECT_EXTENDED (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_ARCH_ALPHA
#define FF_API_ARCH_ALPHA (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_XVMC
#define FF_API_XVMC (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_ERROR_RATE
#define FF_API_ERROR_RATE (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_QSCALE_TYPE
#define FF_API_QSCALE_TYPE (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_MB_TYPE
#define FF_API_MB_TYPE (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_MAX_BFRAMES
#define FF_API_MAX_BFRAMES (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_NEG_LINESIZES
#define FF_API_NEG_LINESIZES (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_EMU_EDGE
#define FF_API_EMU_EDGE (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_ARCH_SH4
#define FF_API_ARCH_SH4 (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_ARCH_SPARC
#define FF_API_ARCH_SPARC (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_UNUSED_MEMBERS
#define FF_API_UNUSED_MEMBERS (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_IDCT_XVIDMMX
#define FF_API_IDCT_XVIDMMX (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_INPUT_PRESERVED
#define FF_API_INPUT_PRESERVED (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_NORMALIZE_AQP
#define FF_API_NORMALIZE_AQP (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_GMC
#define FF_API_GMC (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_MV0
#define FF_API_MV0 (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_CODEC_NAME
#define FF_API_CODEC_NAME (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_AFD
#define FF_API_AFD (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_VISMV
/* XXX: don't forget to drop the -vismv documentation */
#define FF_API_VISMV (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_AUDIOENC_DELAY
#define FF_API_AUDIOENC_DELAY (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_VAAPI_CONTEXT
#define FF_API_VAAPI_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_AVCTX_TIMEBASE #ifndef FF_API_AVCTX_TIMEBASE
#define FF_API_AVCTX_TIMEBASE (LIBAVCODEC_VERSION_MAJOR < 59) #define FF_API_AVCTX_TIMEBASE (LIBAVCODEC_VERSION_MAJOR < 59)
#endif #endif
#ifndef FF_API_MPV_OPT
#define FF_API_MPV_OPT (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_STREAM_CODEC_TAG
#define FF_API_STREAM_CODEC_TAG (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_QUANT_BIAS
#define FF_API_QUANT_BIAS (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_RC_STRATEGY
#define FF_API_RC_STRATEGY (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_CODED_FRAME #ifndef FF_API_CODED_FRAME
#define FF_API_CODED_FRAME (LIBAVCODEC_VERSION_MAJOR < 59) #define FF_API_CODED_FRAME (LIBAVCODEC_VERSION_MAJOR < 59)
#endif #endif
#ifndef FF_API_MOTION_EST
#define FF_API_MOTION_EST (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_WITHOUT_PREFIX
#define FF_API_WITHOUT_PREFIX (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_SIDEDATA_ONLY_PKT #ifndef FF_API_SIDEDATA_ONLY_PKT
#define FF_API_SIDEDATA_ONLY_PKT (LIBAVCODEC_VERSION_MAJOR < 59) #define FF_API_SIDEDATA_ONLY_PKT (LIBAVCODEC_VERSION_MAJOR < 59)
#endif #endif
@ -212,5 +93,48 @@
#ifndef FF_API_PRIVATE_OPT #ifndef FF_API_PRIVATE_OPT
#define FF_API_PRIVATE_OPT (LIBAVCODEC_VERSION_MAJOR < 59) #define FF_API_PRIVATE_OPT (LIBAVCODEC_VERSION_MAJOR < 59)
#endif #endif
#ifndef FF_API_ASS_TIMING
#define FF_API_ASS_TIMING (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_OLD_BSF
#define FF_API_OLD_BSF (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_COPY_CONTEXT
#define FF_API_COPY_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_GET_CONTEXT_DEFAULTS
#define FF_API_GET_CONTEXT_DEFAULTS (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_NVENC_OLD_NAME
#define FF_API_NVENC_OLD_NAME (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_STRUCT_VAAPI_CONTEXT
#define FF_API_STRUCT_VAAPI_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_MERGE_SD_API
#define FF_API_MERGE_SD_API (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_TAG_STRING
#define FF_API_TAG_STRING (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_GETCHROMA
#define FF_API_GETCHROMA (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_CODEC_GET_SET
#define FF_API_CODEC_GET_SET (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_USER_VISIBLE_AVHWACCEL
#define FF_API_USER_VISIBLE_AVHWACCEL (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_LOCKMGR
#define FF_API_LOCKMGR (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_NEXT
#define FF_API_NEXT (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_UNSANITIZED_BITRATES
#define FF_API_UNSANITIZED_BITRATES (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#endif /* AVCODEC_VERSION_H */ #endif /* AVCODEC_VERSION_H */

@ -58,7 +58,8 @@ typedef struct AVVideotoolboxContext {
/** /**
* CVPixelBuffer Format Type that Videotoolbox will use for decoded frames. * CVPixelBuffer Format Type that Videotoolbox will use for decoded frames.
* set by the caller. * set by the caller. If this is set to 0, then no specific format is
* requested from the decoder, and its native format is output.
*/ */
OSType cv_pix_fmt_type; OSType cv_pix_fmt_type;

@ -1,5 +1,4 @@
/* /*
*
* This file is part of FFmpeg. * This file is part of FFmpeg.
* *
* FFmpeg is free software; you can redistribute it and/or * FFmpeg is free software; you can redistribute it and/or
@ -33,9 +32,6 @@ typedef struct AVVorbisParseContext AVVorbisParseContext;
/** /**
* Allocate and initialize the Vorbis parser using headers in the extradata. * Allocate and initialize the Vorbis parser using headers in the extradata.
*
* @param avctx codec context
* @param s Vorbis parser context
*/ */
AVVorbisParseContext *av_vorbis_parse_init(const uint8_t *extradata, AVVorbisParseContext *av_vorbis_parse_init(const uint8_t *extradata,
int extradata_size); int extradata_size);

@ -29,7 +29,9 @@
*/ */
/** /**
* @defgroup lavfi Libavfilter - graph-based frame editing library * @defgroup lavfi libavfilter
* Graph-based frame editing library.
*
* @{ * @{
*/ */
@ -37,6 +39,7 @@
#include "libavutil/attributes.h" #include "libavutil/attributes.h"
#include "libavutil/avutil.h" #include "libavutil/avutil.h"
#include "libavutil/buffer.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "libavutil/frame.h" #include "libavutil/frame.h"
#include "libavutil/log.h" #include "libavutil/log.h"
@ -191,6 +194,21 @@ typedef struct AVFilter {
***************************************************************** *****************************************************************
*/ */
/**
* Filter pre-initialization function
*
* This callback will be called immediately after the filter context is
* allocated, to allow allocating and initing sub-objects.
*
* If this callback is not NULL, the uninit callback will be called on
* allocation failure.
*
* @return 0 on success,
* AVERROR code on failure (but the code will be
* dropped and treated as ENOMEM by the calling code)
*/
int (*preinit)(AVFilterContext *ctx);
/** /**
* Filter initialization function. * Filter initialization function.
* *
@ -265,6 +283,8 @@ typedef struct AVFilter {
int priv_size; ///< size of private data to allocate for the filter int priv_size; ///< size of private data to allocate for the filter
int flags_internal; ///< Additional flags for avfilter internal use only.
/** /**
* Used by the filter registration system. Must not be touched by any other * Used by the filter registration system. Must not be touched by any other
* code. * code.
@ -291,6 +311,20 @@ typedef struct AVFilter {
* used for providing binary data. * used for providing binary data.
*/ */
int (*init_opaque)(AVFilterContext *ctx, void *opaque); int (*init_opaque)(AVFilterContext *ctx, void *opaque);
/**
* Filter activation function.
*
* Called when any processing is needed from the filter, instead of any
* filter_frame and request_frame on pads.
*
* The function must examine inlinks and outlinks and perform a single
* step of processing. If there is nothing to do, the function must do
* nothing and not return an error. If more steps are or may be
* possible, it must use ff_filter_set_ready() to schedule another
* activation.
*/
int (*activate)(AVFilterContext *ctx);
} AVFilter; } AVFilter;
/** /**
@ -349,6 +383,45 @@ struct AVFilterContext {
void *enable; ///< parsed expression (AVExpr*) void *enable; ///< parsed expression (AVExpr*)
double *var_values; ///< variable values for the enable expression double *var_values; ///< variable values for the enable expression
int is_disabled; ///< the enabled state from the last expression evaluation int is_disabled; ///< the enabled state from the last expression evaluation
/**
* For filters which will create hardware frames, sets the device the
* filter should create them in. All other filters will ignore this field:
* in particular, a filter which consumes or processes hardware frames will
* instead use the hw_frames_ctx field in AVFilterLink to carry the
* hardware context information.
*/
AVBufferRef *hw_device_ctx;
/**
* Max number of threads allowed in this filter instance.
* If <= 0, its value is ignored.
* Overrides global number of threads set per filter graph.
*/
int nb_threads;
/**
* Ready status of the filter.
* A non-0 value means that the filter needs activating;
* a higher value suggests a more urgent activation.
*/
unsigned ready;
/**
* Sets the number of extra hardware frames which the filter will
* allocate on its output links for use in following filters or by
* the caller.
*
* Some hardware filters require all frames that they will use for
* output to be defined in advance before filtering starts. For such
* filters, any hardware frame pools used for output must therefore be
* of fixed size. The extra frames set here are on top of any number
* that the filter needs internally in order to operate normally.
*
* This field must be set before the graph containing this filter is
* configured.
*/
int extra_hw_frames;
}; };
/** /**
@ -357,6 +430,11 @@ struct AVFilterContext {
* the pads involved. In addition, this link also contains the parameters * the pads involved. In addition, this link also contains the parameters
* which have been negotiated and agreed upon between the filter, such as * which have been negotiated and agreed upon between the filter, such as
* image dimensions, format, etc. * image dimensions, format, etc.
*
* Applications must not normally access the link structure directly.
* Use the buffersrc and buffersink API instead.
* In the future, access to the header may be reserved for filters
* implementation.
*/ */
struct AVFilterLink { struct AVFilterLink {
AVFilterContext *src; ///< source filter AVFilterContext *src; ///< source filter
@ -489,18 +567,6 @@ struct AVFilterLink {
*/ */
int max_samples; int max_samples;
/**
* Link status.
* If not zero, all attempts of filter_frame or request_frame
* will fail with the corresponding code, and if necessary the reference
* will be destroyed.
* If request_frame returns an error, the status is set on the
* corresponding link.
* It can be set also be set by either the source or the destination
* filter.
*/
int status;
/** /**
* Number of channels. * Number of channels.
*/ */
@ -514,19 +580,12 @@ struct AVFilterLink {
/** /**
* Number of past frames sent through the link. * Number of past frames sent through the link.
*/ */
int64_t frame_count; int64_t frame_count_in, frame_count_out;
/**
* A pointer to a FFVideoFramePool struct.
*/
void *video_frame_pool;
/** /**
* True if a frame is currently wanted on the input of this filter. * A pointer to a FFFramePool struct.
* Set when ff_request_frame() is called by the output,
* cleared when the request is handled or forwarded.
*/ */
int frame_wanted_in; void *frame_pool;
/** /**
* True if a frame is currently wanted on the output of this filter. * True if a frame is currently wanted on the output of this filter.
@ -534,6 +593,57 @@ struct AVFilterLink {
* cleared when a frame is filtered. * cleared when a frame is filtered.
*/ */
int frame_wanted_out; int frame_wanted_out;
/**
* For hwaccel pixel formats, this should be a reference to the
* AVHWFramesContext describing the frames.
*/
AVBufferRef *hw_frames_ctx;
#ifndef FF_INTERNAL_FIELDS
/**
* Internal structure members.
* The fields below this limit are internal for libavfilter's use
* and must in no way be accessed by applications.
*/
char reserved[0xF000];
#else /* FF_INTERNAL_FIELDS */
/**
* Queue of frames waiting to be filtered.
*/
FFFrameQueue fifo;
/**
* If set, the source filter can not generate a frame as is.
* The goal is to avoid repeatedly calling the request_frame() method on
* the same link.
*/
int frame_blocked_in;
/**
* Link input status.
* If not zero, all attempts of filter_frame will fail with the
* corresponding code.
*/
int status_in;
/**
* Timestamp of the input status change.
*/
int64_t status_in_pts;
/**
* Link output status.
* If not zero, all attempts of request_frame will fail with the
* corresponding code.
*/
int status_out;
#endif /* FF_INTERNAL_FIELDS */
}; };
/** /**
@ -553,10 +663,14 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
*/ */
void avfilter_link_free(AVFilterLink **link); void avfilter_link_free(AVFilterLink **link);
#if FF_API_FILTER_GET_SET
/** /**
* Get the number of channels of a link. * Get the number of channels of a link.
* @deprecated Use av_buffersink_get_channels()
*/ */
attribute_deprecated
int avfilter_link_get_channels(AVFilterLink *link); int avfilter_link_get_channels(AVFilterLink *link);
#endif
/** /**
* Set the closed field of a link. * Set the closed field of a link.
@ -583,14 +697,21 @@ int avfilter_config_links(AVFilterContext *filter);
*/ */
int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags); int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
/** Initialize the filter system. Register all builtin filters. */ /**
void avfilter_register_all(void); * Iterate over all registered filters.
*
* @param opaque a pointer where libavfilter will store the iteration state. Must
* point to NULL to start the iteration.
*
* @return the next registered filter or NULL when the iteration is
* finished
*/
const AVFilter *av_filter_iterate(void **opaque);
#if FF_API_OLD_FILTER_REGISTER #if FF_API_NEXT
/** Uninitialize the filter system. Unregister all filters. */ /** Initialize the filter system. Register all builtin filters. */
attribute_deprecated attribute_deprecated
void avfilter_uninit(void); void avfilter_register_all(void);
#endif
/** /**
* Register a filter. This is only needed if you plan to use * Register a filter. This is only needed if you plan to use
@ -602,70 +723,28 @@ void avfilter_uninit(void);
* @return 0 if the registration was successful, a negative value * @return 0 if the registration was successful, a negative value
* otherwise * otherwise
*/ */
attribute_deprecated
int avfilter_register(AVFilter *filter); int avfilter_register(AVFilter *filter);
/**
* Get a filter definition matching the given name.
*
* @param name the filter name to find
* @return the filter definition, if any matching one is registered.
* NULL if none found.
*/
#if !FF_API_NOCONST_GET_NAME
const
#endif
AVFilter *avfilter_get_by_name(const char *name);
/** /**
* Iterate over all registered filters. * Iterate over all registered filters.
* @return If prev is non-NULL, next registered filter after prev or NULL if * @return If prev is non-NULL, next registered filter after prev or NULL if
* prev is the last filter. If prev is NULL, return the first registered filter. * prev is the last filter. If prev is NULL, return the first registered filter.
*/ */
const AVFilter *avfilter_next(const AVFilter *prev);
#if FF_API_OLD_FILTER_REGISTER
/**
* If filter is NULL, returns a pointer to the first registered filter pointer,
* if filter is non-NULL, returns the next pointer after filter.
* If the returned pointer points to NULL, the last registered filter
* was already reached.
* @deprecated use avfilter_next()
*/
attribute_deprecated attribute_deprecated
AVFilter **av_filter_next(AVFilter **filter); const AVFilter *avfilter_next(const AVFilter *prev);
#endif #endif
#if FF_API_AVFILTER_OPEN
/** /**
* Create a filter instance. * Get a filter definition matching the given name.
* *
* @param filter_ctx put here a pointer to the created filter context * @param name the filter name to find
* on success, NULL on failure * @return the filter definition, if any matching one is registered.
* @param filter the filter to create an instance of * NULL if none found.
* @param inst_name Name to give to the new instance. Can be NULL for none.
* @return >= 0 in case of success, a negative error code otherwise
* @deprecated use avfilter_graph_alloc_filter() instead
*/ */
attribute_deprecated const AVFilter *avfilter_get_by_name(const char *name);
int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
#endif
#if FF_API_AVFILTER_INIT_FILTER
/**
* Initialize a filter.
*
* @param filter the filter to initialize
* @param args A string of parameters to use when initializing the filter.
* The format and meaning of this string varies by filter.
* @param opaque Any extra non-string data needed by the filter. The meaning
* of this parameter varies by filter.
* @return zero on success
*/
attribute_deprecated
int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
#endif
/** /**
* Initialize a filter with the supplied parameters. * Initialize a filter with the supplied parameters.
* *
@ -764,7 +843,9 @@ typedef struct AVFilterGraph {
unsigned nb_filters; unsigned nb_filters;
char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
char *resample_lavr_opts; ///< libavresample options to use for the auto-inserted resample filters #if FF_API_LAVR_OPTS
attribute_deprecated char *resample_lavr_opts; ///< libavresample options to use for the auto-inserted resample filters
#endif
/** /**
* Type of multithreading allowed for filters in this graph. A combination * Type of multithreading allowed for filters in this graph. A combination
@ -863,20 +944,6 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
*/ */
AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, const char *name); AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, const char *name);
#if FF_API_AVFILTER_OPEN
/**
* Add an existing filter instance to a filter graph.
*
* @param graphctx the filter graph
* @param filter the filter to be added
*
* @deprecated use avfilter_graph_alloc_filter() to allocate a filter in a
* filter graph
*/
attribute_deprecated
int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
#endif
/** /**
* Create and add a filter instance into an existing graph. * Create and add a filter instance into an existing graph.
* The filter instance is created from the filter filt and inited * The filter instance is created from the filter filt and inited

@ -62,7 +62,7 @@ int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flag
/** /**
* Struct to use for initializing a buffersink context. * Struct to use for initializing a buffersink context.
*/ */
typedef struct { typedef struct AVBufferSinkParams {
const enum AVPixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by AV_PIX_FMT_NONE const enum AVPixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by AV_PIX_FMT_NONE
} AVBufferSinkParams; } AVBufferSinkParams;
@ -76,7 +76,7 @@ AVBufferSinkParams *av_buffersink_params_alloc(void);
/** /**
* Struct to use for initializing an abuffersink context. * Struct to use for initializing an abuffersink context.
*/ */
typedef struct { typedef struct AVABufferSinkParams {
const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
const int64_t *channel_layouts; ///< list of allowed channel layouts, terminated by -1 const int64_t *channel_layouts; ///< list of allowed channel layouts, terminated by -1
const int *channel_counts; ///< list of allowed channel counts, terminated by -1 const int *channel_counts; ///< list of allowed channel counts, terminated by -1
@ -101,9 +101,27 @@ AVABufferSinkParams *av_abuffersink_params_alloc(void);
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size); void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size);
/** /**
* Get the frame rate of the input. * @defgroup lavfi_buffersink_accessors Buffer sink accessors
* Get the properties of the stream
* @{
*/ */
AVRational av_buffersink_get_frame_rate(AVFilterContext *ctx);
enum AVMediaType av_buffersink_get_type (const AVFilterContext *ctx);
AVRational av_buffersink_get_time_base (const AVFilterContext *ctx);
int av_buffersink_get_format (const AVFilterContext *ctx);
AVRational av_buffersink_get_frame_rate (const AVFilterContext *ctx);
int av_buffersink_get_w (const AVFilterContext *ctx);
int av_buffersink_get_h (const AVFilterContext *ctx);
AVRational av_buffersink_get_sample_aspect_ratio (const AVFilterContext *ctx);
int av_buffersink_get_channels (const AVFilterContext *ctx);
uint64_t av_buffersink_get_channel_layout (const AVFilterContext *ctx);
int av_buffersink_get_sample_rate (const AVFilterContext *ctx);
AVBufferRef * av_buffersink_get_hw_frames_ctx (const AVFilterContext *ctx);
/** @} */
/** /**
* Get a frame with filtered data from sink and put it in frame. * Get a frame with filtered data from sink and put it in frame.
@ -133,7 +151,7 @@ int av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame);
* the end of stream, when it can contain less than nb_samples. * the end of stream, when it can contain less than nb_samples.
* *
* @return The return codes have the same meaning as for * @return The return codes have the same meaning as for
* av_buffersink_get_samples(). * av_buffersink_get_frame().
* *
* @warning do not mix this function with av_buffersink_get_frame(). Use only one or * @warning do not mix this function with av_buffersink_get_frame(). Use only one or
* the other with a single sink, not both. * the other with a single sink, not both.

@ -1,5 +1,4 @@
/* /*
*
* This file is part of FFmpeg. * This file is part of FFmpeg.
* *
* FFmpeg is free software; you can redistribute it and/or * FFmpeg is free software; you can redistribute it and/or
@ -26,7 +25,6 @@
* Memory buffer source API. * Memory buffer source API.
*/ */
#include "libavcodec/avcodec.h"
#include "avfilter.h" #include "avfilter.h"
/** /**
@ -65,6 +63,80 @@ enum {
*/ */
unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src); unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src);
/**
* This structure contains the parameters describing the frames that will be
* passed to this filter.
*
* It should be allocated with av_buffersrc_parameters_alloc() and freed with
* av_free(). All the allocated fields in it remain owned by the caller.
*/
typedef struct AVBufferSrcParameters {
/**
* video: the pixel format, value corresponds to enum AVPixelFormat
* audio: the sample format, value corresponds to enum AVSampleFormat
*/
int format;
/**
* The timebase to be used for the timestamps on the input frames.
*/
AVRational time_base;
/**
* Video only, the display dimensions of the input frames.
*/
int width, height;
/**
* Video only, the sample (pixel) aspect ratio.
*/
AVRational sample_aspect_ratio;
/**
* Video only, the frame rate of the input video. This field must only be
* set to a non-zero value if input stream has a known constant framerate
* and should be left at its initial value if the framerate is variable or
* unknown.
*/
AVRational frame_rate;
/**
* Video with a hwaccel pixel format only. This should be a reference to an
* AVHWFramesContext instance describing the input frames.
*/
AVBufferRef *hw_frames_ctx;
/**
* Audio only, the audio sampling rate in samples per second.
*/
int sample_rate;
/**
* Audio only, the audio channel layout
*/
uint64_t channel_layout;
} AVBufferSrcParameters;
/**
* Allocate a new AVBufferSrcParameters instance. It should be freed by the
* caller with av_free().
*/
AVBufferSrcParameters *av_buffersrc_parameters_alloc(void);
/**
* Initialize the buffersrc or abuffersrc filter with the provided parameters.
* This function may be called multiple times, the later calls override the
* previous ones. Some of the parameters may also be set through AVOptions, then
* whatever method is used last takes precedence.
*
* @param ctx an instance of the buffersrc or abuffersrc filter
* @param param the stream parameters. The frames later passed to this filter
* must conform to those parameters. All the allocated fields in
* param remain owned by the caller, libavfilter will make internal
* copies or references when necessary.
* @return 0 on success, a negative AVERROR code on failure.
*/
int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *param);
/** /**
* Add a frame to the buffer source. * Add a frame to the buffer source.
* *
@ -121,6 +193,14 @@ av_warn_unused_result
int av_buffersrc_add_frame_flags(AVFilterContext *buffer_src, int av_buffersrc_add_frame_flags(AVFilterContext *buffer_src,
AVFrame *frame, int flags); AVFrame *frame, int flags);
/**
* Close the buffer source after EOF.
*
* This is similar to passing NULL to av_buffersrc_add_frame_flags()
* except it takes the timestamp of the EOF, i.e. the timestamp of the end
* of the last frame.
*/
int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags);
/** /**
* @} * @}

@ -29,10 +29,11 @@
#include "libavutil/version.h" #include "libavutil/version.h"
#define LIBAVFILTER_VERSION_MAJOR 6 #define LIBAVFILTER_VERSION_MAJOR 7
#define LIBAVFILTER_VERSION_MINOR 31 #define LIBAVFILTER_VERSION_MINOR 57
#define LIBAVFILTER_VERSION_MICRO 100 #define LIBAVFILTER_VERSION_MICRO 100
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \ LIBAVFILTER_VERSION_MINOR, \
LIBAVFILTER_VERSION_MICRO) LIBAVFILTER_VERSION_MICRO)
@ -49,23 +50,17 @@
* the public API and may change, break or disappear at any time. * the public API and may change, break or disappear at any time.
*/ */
#ifndef FF_API_OLD_FILTER_OPTS
#define FF_API_OLD_FILTER_OPTS (LIBAVFILTER_VERSION_MAJOR < 7)
#endif
#ifndef FF_API_OLD_FILTER_OPTS_ERROR #ifndef FF_API_OLD_FILTER_OPTS_ERROR
#define FF_API_OLD_FILTER_OPTS_ERROR (LIBAVFILTER_VERSION_MAJOR < 7) #define FF_API_OLD_FILTER_OPTS_ERROR (LIBAVFILTER_VERSION_MAJOR < 8)
#endif
#ifndef FF_API_AVFILTER_OPEN
#define FF_API_AVFILTER_OPEN (LIBAVFILTER_VERSION_MAJOR < 7)
#endif #endif
#ifndef FF_API_AVFILTER_INIT_FILTER #ifndef FF_API_LAVR_OPTS
#define FF_API_AVFILTER_INIT_FILTER (LIBAVFILTER_VERSION_MAJOR < 7) #define FF_API_LAVR_OPTS (LIBAVFILTER_VERSION_MAJOR < 8)
#endif #endif
#ifndef FF_API_OLD_FILTER_REGISTER #ifndef FF_API_FILTER_GET_SET
#define FF_API_OLD_FILTER_REGISTER (LIBAVFILTER_VERSION_MAJOR < 7) #define FF_API_FILTER_GET_SET (LIBAVFILTER_VERSION_MAJOR < 8)
#endif #endif
#ifndef FF_API_NOCONST_GET_NAME #ifndef FF_API_NEXT
#define FF_API_NOCONST_GET_NAME (LIBAVFILTER_VERSION_MAJOR < 7) #define FF_API_NEXT (LIBAVFILTER_VERSION_MAJOR < 8)
#endif #endif
#endif /* AVFILTER_VERSION_H */ #endif /* AVFILTER_VERSION_H */

File diff suppressed because it is too large Load Diff

@ -34,7 +34,15 @@
#include "libavformat/version.h" #include "libavformat/version.h"
#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */ /**
* Seeking works like for a local file.
*/
#define AVIO_SEEKABLE_NORMAL (1 << 0)
/**
* Seeking by timestamp with avio_seek_time() is possible.
*/
#define AVIO_SEEKABLE_TIME (1 << 1)
/** /**
* Callback for checking whether to abort blocking functions. * Callback for checking whether to abort blocking functions.
@ -96,6 +104,48 @@ typedef struct AVIODirContext {
struct URLContext *url_context; struct URLContext *url_context;
} AVIODirContext; } AVIODirContext;
/**
* Different data types that can be returned via the AVIO
* write_data_type callback.
*/
enum AVIODataMarkerType {
/**
* Header data; this needs to be present for the stream to be decodeable.
*/
AVIO_DATA_MARKER_HEADER,
/**
* A point in the output bytestream where a decoder can start decoding
* (i.e. a keyframe). A demuxer/decoder given the data flagged with
* AVIO_DATA_MARKER_HEADER, followed by any AVIO_DATA_MARKER_SYNC_POINT,
* should give decodeable results.
*/
AVIO_DATA_MARKER_SYNC_POINT,
/**
* A point in the output bytestream where a demuxer can start parsing
* (for non self synchronizing bytestream formats). That is, any
* non-keyframe packet start point.
*/
AVIO_DATA_MARKER_BOUNDARY_POINT,
/**
* This is any, unlabelled data. It can either be a muxer not marking
* any positions at all, it can be an actual boundary/sync point
* that the muxer chooses not to mark, or a later part of a packet/fragment
* that is cut into multiple write callbacks due to limited IO buffer size.
*/
AVIO_DATA_MARKER_UNKNOWN,
/**
* Trailer data, which doesn't contain actual content, but only for
* finalizing the output file.
*/
AVIO_DATA_MARKER_TRAILER,
/**
* A point in the output bytestream where the underlying AVIOContext might
* flush the buffer depending on latency or buffering requirements. Typically
* means the end of a packet.
*/
AVIO_DATA_MARKER_FLUSH_POINT,
};
/** /**
* Bytestream IO Context. * Bytestream IO Context.
* New fields can be added to the end with minor version bumps. * New fields can be added to the end with minor version bumps.
@ -124,8 +174,9 @@ typedef struct AVIOContext {
const AVClass *av_class; const AVClass *av_class;
/* /*
* The following shows the relationship between buffer, buf_ptr, buf_end, buf_size, * The following shows the relationship between buffer, buf_ptr,
* and pos, when reading and when writing (since AVIOContext is used for both): * buf_ptr_max, buf_end, buf_size, and pos, when reading and when writing
* (since AVIOContext is used for both):
* *
********************************************************************************** **********************************************************************************
* READING * READING
@ -152,21 +203,24 @@ typedef struct AVIOContext {
* WRITING * WRITING
********************************************************************************** **********************************************************************************
* *
* | buffer_size | * | buffer_size |
* |-------------------------------| * |--------------------------------------|
* | | * | |
* *
* buffer buf_ptr buf_end * buf_ptr_max
* +-------------------+-----------+ * buffer (buf_ptr) buf_end
* |/ / / / / / / / / /| | * +-----------------------+--------------+
* write buffer: | / to be flushed / | | * |/ / / / / / / / / / / /| |
* |/ / / / / / / / / /| | * write buffer: | / / to be flushed / / | |
* +-------------------+-----------+ * |/ / / / / / / / / / / /| |
* +-----------------------+--------------+
* buf_ptr can be in this
* due to a backward seek
* *
* pos * pos
* +--------------------------+-----------------------------------+ * +-------------+----------------------------------------------+
* output file: | | | * output file: | | |
* +--------------------------+-----------------------------------+ * +-------------+----------------------------------------------+
* *
*/ */
unsigned char *buffer; /**< Start of the buffer. */ unsigned char *buffer; /**< Start of the buffer. */
@ -182,8 +236,7 @@ typedef struct AVIOContext {
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size); int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
int64_t (*seek)(void *opaque, int64_t offset, int whence); int64_t (*seek)(void *opaque, int64_t offset, int whence);
int64_t pos; /**< position in the file of the current buffer */ int64_t pos; /**< position in the file of the current buffer */
int must_flush; /**< true if the next seek should flush */ int eof_reached; /**< true if was unable to read due to error or eof */
int eof_reached; /**< true if eof reached */
int write_flag; /**< true if open for writing */ int write_flag; /**< true if open for writing */
int max_packet_size; int max_packet_size;
unsigned long checksum; unsigned long checksum;
@ -254,9 +307,49 @@ typedef struct AVIOContext {
* ',' separated list of allowed protocols. * ',' separated list of allowed protocols.
*/ */
const char *protocol_whitelist; const char *protocol_whitelist;
} AVIOContext;
/* unbuffered I/O */ /**
* ',' separated list of disallowed protocols.
*/
const char *protocol_blacklist;
/**
* A callback that is used instead of write_packet.
*/
int (*write_data_type)(void *opaque, uint8_t *buf, int buf_size,
enum AVIODataMarkerType type, int64_t time);
/**
* If set, don't call write_data_type separately for AVIO_DATA_MARKER_BOUNDARY_POINT,
* but ignore them and treat them as AVIO_DATA_MARKER_UNKNOWN (to avoid needlessly
* small chunks of data returned from the callback).
*/
int ignore_boundary_point;
/**
* Internal, not meant to be used from outside of AVIOContext.
*/
enum AVIODataMarkerType current_type;
int64_t last_time;
/**
* A callback that is used instead of short_seek_threshold.
* This is current internal only, do not use from outside.
*/
int (*short_seek_get)(void *opaque);
int64_t written;
/**
* Maximum reached position before a backward seek in the write buffer,
* used keeping track of already written data for a later flush.
*/
unsigned char *buf_ptr_max;
/**
* Try to buffer at least this amount of data before flushing it
*/
int min_packet_size;
} AVIOContext;
/** /**
* Return the name of the protocol that will handle the passed URL. * Return the name of the protocol that will handle the passed URL.
@ -345,7 +438,7 @@ void avio_free_directory_entry(AVIODirEntry **entry);
/** /**
* Allocate and initialize an AVIOContext for buffered I/O. It must be later * Allocate and initialize an AVIOContext for buffered I/O. It must be later
* freed with av_free(). * freed with avio_context_free().
* *
* @param buffer Memory block for input/output operations via AVIOContext. * @param buffer Memory block for input/output operations via AVIOContext.
* The buffer must be allocated with av_malloc() and friends. * The buffer must be allocated with av_malloc() and friends.
@ -358,6 +451,8 @@ void avio_free_directory_entry(AVIODirEntry **entry);
* @param write_flag Set to 1 if the buffer should be writable, 0 otherwise. * @param write_flag Set to 1 if the buffer should be writable, 0 otherwise.
* @param opaque An opaque pointer to user-specific data. * @param opaque An opaque pointer to user-specific data.
* @param read_packet A function for refilling the buffer, may be NULL. * @param read_packet A function for refilling the buffer, may be NULL.
* For stream protocols, must never return 0 but rather
* a proper AVERROR code.
* @param write_packet A function for writing the buffer contents, may be NULL. * @param write_packet A function for writing the buffer contents, may be NULL.
* The function may not change the input buffers content. * The function may not change the input buffers content.
* @param seek A function for seeking to specified byte position, may be NULL. * @param seek A function for seeking to specified byte position, may be NULL.
@ -373,6 +468,14 @@ AVIOContext *avio_alloc_context(
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
int64_t (*seek)(void *opaque, int64_t offset, int whence)); int64_t (*seek)(void *opaque, int64_t offset, int whence));
/**
* Free the supplied IO context and everything associated with it.
*
* @param s Double pointer to the IO context. This function will write NULL
* into s.
*/
void avio_context_free(AVIOContext **s);
void avio_w8(AVIOContext *s, int b); void avio_w8(AVIOContext *s, int b);
void avio_write(AVIOContext *s, const unsigned char *buf, int size); void avio_write(AVIOContext *s, const unsigned char *buf, int size);
void avio_wl64(AVIOContext *s, uint64_t val); void avio_wl64(AVIOContext *s, uint64_t val);
@ -409,14 +512,26 @@ int avio_put_str16le(AVIOContext *s, const char *str);
int avio_put_str16be(AVIOContext *s, const char *str); int avio_put_str16be(AVIOContext *s, const char *str);
/** /**
* Passing this as the "whence" parameter to a seek function causes it to * Mark the written bytestream as a specific type.
*
* Zero-length ranges are omitted from the output.
*
* @param time the stream time the current bytestream pos corresponds to
* (in AV_TIME_BASE units), or AV_NOPTS_VALUE if unknown or not
* applicable
* @param type the kind of data written starting at the current pos
*/
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type);
/**
* ORing this as the "whence" parameter to a seek function causes it to
* return the filesize without seeking anywhere. Supporting this is optional. * return the filesize without seeking anywhere. Supporting this is optional.
* If it is not supported then the seek function will return <0. * If it is not supported then the seek function will return <0.
*/ */
#define AVSEEK_SIZE 0x10000 #define AVSEEK_SIZE 0x10000
/** /**
* Oring this flag as into the "whence" parameter to a seek function causes it to * Passing this flag as the "whence" parameter to a seek function causes it to
* seek by any means (like reopening and linear reading) or other normally unreasonable * seek by any means (like reopening and linear reading) or other normally unreasonable
* means that can be extremely slow. * means that can be extremely slow.
* This may be ignored by the seek code. * This may be ignored by the seek code.
@ -451,17 +566,10 @@ static av_always_inline int64_t avio_tell(AVIOContext *s)
int64_t avio_size(AVIOContext *s); int64_t avio_size(AVIOContext *s);
/** /**
* feof() equivalent for AVIOContext. * Similar to feof() but also returns nonzero on read errors.
* @return non zero if and only if end of file * @return non zero if and only if at end of file or a read error happened when reading.
*/ */
int avio_feof(AVIOContext *s); int avio_feof(AVIOContext *s);
#if FF_API_URL_FEOF
/**
* @deprecated use avio_feof()
*/
attribute_deprecated
int url_feof(AVIOContext *s);
#endif
/** @warning Writes up to 4 KiB per call */ /** @warning Writes up to 4 KiB per call */
int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3); int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
@ -484,6 +592,15 @@ void avio_flush(AVIOContext *s);
*/ */
int avio_read(AVIOContext *s, unsigned char *buf, int size); int avio_read(AVIOContext *s, unsigned char *buf, int size);
/**
* Read size bytes from AVIOContext into buf. Unlike avio_read(), this is allowed
* to read fewer bytes than requested. The missing bytes can be read in the next
* call. This always tries to read at least 1 byte.
* Useful to reduce latency in certain cases.
* @return number of bytes read or AVERROR
*/
int avio_read_partial(AVIOContext *s, unsigned char *buf, int size);
/** /**
* @name Functions for reading from AVIOContext * @name Functions for reading from AVIOContext
* @{ * @{
@ -634,6 +751,18 @@ int avio_closep(AVIOContext **s);
*/ */
int avio_open_dyn_buf(AVIOContext **s); int avio_open_dyn_buf(AVIOContext **s);
/**
* Return the written size and a pointer to the buffer.
* The AVIOContext stream is left intact.
* The buffer must NOT be freed.
* No padding is added to the buffer.
*
* @param s IO context
* @param pbuffer pointer to a byte buffer
* @return the length of the byte buffer
*/
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
/** /**
* Return the written size and a pointer to the buffer. The buffer * Return the written size and a pointer to the buffer. The buffer
* must be freed with av_free(). * must be freed with av_free().

@ -29,8 +29,10 @@
#include "libavutil/version.h" #include "libavutil/version.h"
#define LIBAVFORMAT_VERSION_MAJOR 57 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
#define LIBAVFORMAT_VERSION_MINOR 25 // Also please add any ticket numbers that you believe might be affected here
#define LIBAVFORMAT_VERSION_MAJOR 58
#define LIBAVFORMAT_VERSION_MINOR 29
#define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
@ -53,27 +55,58 @@
* at once through the bump. This improves the git bisect-ability of the change. * at once through the bump. This improves the git bisect-ability of the change.
* *
*/ */
#ifndef FF_API_LAVF_BITEXACT #ifndef FF_API_COMPUTE_PKT_FIELDS2
#define FF_API_LAVF_BITEXACT (LIBAVFORMAT_VERSION_MAJOR < 58) #define FF_API_COMPUTE_PKT_FIELDS2 (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif #endif
#ifndef FF_API_LAVF_FRAC #ifndef FF_API_OLD_OPEN_CALLBACKS
#define FF_API_LAVF_FRAC (LIBAVFORMAT_VERSION_MAJOR < 58) #define FF_API_OLD_OPEN_CALLBACKS (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif #endif
#ifndef FF_API_LAVF_CODEC_TB #ifndef FF_API_LAVF_AVCTX
#define FF_API_LAVF_CODEC_TB (LIBAVFORMAT_VERSION_MAJOR < 58) #define FF_API_LAVF_AVCTX (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif #endif
#ifndef FF_API_URL_FEOF #ifndef FF_API_HTTP_USER_AGENT
#define FF_API_URL_FEOF (LIBAVFORMAT_VERSION_MAJOR < 58) #define FF_API_HTTP_USER_AGENT (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif #endif
#ifndef FF_API_LAVF_FMT_RAWPICTURE #ifndef FF_API_HLS_WRAP
#define FF_API_LAVF_FMT_RAWPICTURE (LIBAVFORMAT_VERSION_MAJOR < 58) #define FF_API_HLS_WRAP (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif #endif
#ifndef FF_API_COMPUTE_PKT_FIELDS2 #ifndef FF_API_HLS_USE_LOCALTIME
#define FF_API_COMPUTE_PKT_FIELDS2 (LIBAVFORMAT_VERSION_MAJOR < 58) #define FF_API_HLS_USE_LOCALTIME (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif #endif
#ifndef FF_API_OLD_OPEN_CALLBACKS #ifndef FF_API_LAVF_KEEPSIDE_FLAG
#define FF_API_OLD_OPEN_CALLBACKS (LIBAVFORMAT_VERSION_MAJOR < 58) #define FF_API_LAVF_KEEPSIDE_FLAG (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_OLD_ROTATE_API
#define FF_API_OLD_ROTATE_API (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_FORMAT_GET_SET
#define FF_API_FORMAT_GET_SET (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_OLD_AVIO_EOF_0
#define FF_API_OLD_AVIO_EOF_0 (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_LAVF_FFSERVER
#define FF_API_LAVF_FFSERVER (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif #endif
#ifndef FF_API_FORMAT_FILENAME
#define FF_API_FORMAT_FILENAME (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_OLD_RTSP_OPTIONS
#define FF_API_OLD_RTSP_OPTIONS (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_NEXT
#define FF_API_NEXT (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_DASH_MIN_SEG_DURATION
#define FF_API_DASH_MIN_SEG_DURATION (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_LAVF_MP4A_LATM
#define FF_API_LAVF_MP4A_LATM (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_AVIOFORMAT
#define FF_API_AVIOFORMAT (LIBAVFORMAT_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_R_FRAME_RATE #ifndef FF_API_R_FRAME_RATE
#define FF_API_R_FRAME_RATE 1 #define FF_API_R_FRAME_RATE 1

@ -18,6 +18,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* @file
* @ingroup lavu_adler32
* Public header for Adler-32 hash function implementation.
*/
#ifndef AVUTIL_ADLER32_H #ifndef AVUTIL_ADLER32_H
#define AVUTIL_ADLER32_H #define AVUTIL_ADLER32_H
@ -25,11 +31,10 @@
#include "attributes.h" #include "attributes.h"
/** /**
* @file * @defgroup lavu_adler32 Adler-32
* Public header for libavutil Adler32 hasher * @ingroup lavu_hash
* Adler-32 hash function implementation.
* *
* @defgroup lavu_adler32 Adler32
* @ingroup lavu_crypto
* @{ * @{
*/ */

@ -67,10 +67,15 @@ const uint8_t* av_aes_ctr_get_iv(struct AVAESCTR *a);
void av_aes_ctr_set_random_iv(struct AVAESCTR *a); void av_aes_ctr_set_random_iv(struct AVAESCTR *a);
/** /**
* Forcefully change the iv * Forcefully change the 8-byte iv
*/ */
void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t* iv); void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t* iv);
/**
* Forcefully change the "full" 16-byte iv, including the counter
*/
void av_aes_ctr_set_full_iv(struct AVAESCTR *a, const uint8_t* iv);
/** /**
* Increment the top 64 bit of the iv (performed after each frame) * Increment the top 64 bit of the iv (performed after each frame)
*/ */

@ -66,19 +66,19 @@
# define av_noinline # define av_noinline
#endif #endif
#if AV_GCC_VERSION_AT_LEAST(3,1) #if AV_GCC_VERSION_AT_LEAST(3,1) || defined(__clang__)
# define av_pure __attribute__((pure)) # define av_pure __attribute__((pure))
#else #else
# define av_pure # define av_pure
#endif #endif
#if AV_GCC_VERSION_AT_LEAST(2,6) #if AV_GCC_VERSION_AT_LEAST(2,6) || defined(__clang__)
# define av_const __attribute__((const)) # define av_const __attribute__((const))
#else #else
# define av_const # define av_const
#endif #endif
#if AV_GCC_VERSION_AT_LEAST(4,3) #if AV_GCC_VERSION_AT_LEAST(4,3) || defined(__clang__)
# define av_cold __attribute__((cold)) # define av_cold __attribute__((cold))
#else #else
# define av_cold # define av_cold
@ -121,8 +121,7 @@
#endif #endif
#endif #endif
#if defined(__GNUC__) || defined(__clang__)
#if defined(__GNUC__)
# define av_unused __attribute__((unused)) # define av_unused __attribute__((unused))
#else #else
# define av_unused # define av_unused
@ -133,25 +132,25 @@
* away. This is useful for variables accessed only from inline * away. This is useful for variables accessed only from inline
* assembler without the compiler being aware. * assembler without the compiler being aware.
*/ */
#if AV_GCC_VERSION_AT_LEAST(3,1) #if AV_GCC_VERSION_AT_LEAST(3,1) || defined(__clang__)
# define av_used __attribute__((used)) # define av_used __attribute__((used))
#else #else
# define av_used # define av_used
#endif #endif
#if AV_GCC_VERSION_AT_LEAST(3,3) #if AV_GCC_VERSION_AT_LEAST(3,3) || defined(__clang__)
# define av_alias __attribute__((may_alias)) # define av_alias __attribute__((may_alias))
#else #else
# define av_alias # define av_alias
#endif #endif
#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__) #if (defined(__GNUC__) || defined(__clang__)) && !defined(__INTEL_COMPILER)
# define av_uninit(x) x=x # define av_uninit(x) x=x
#else #else
# define av_uninit(x) x # define av_uninit(x) x
#endif #endif
#ifdef __GNUC__ #if defined(__GNUC__) || defined(__clang__)
# define av_builtin_constant_p __builtin_constant_p # define av_builtin_constant_p __builtin_constant_p
# define av_printf_format(fmtpos, attrpos) __attribute__((__format__(__printf__, fmtpos, attrpos))) # define av_printf_format(fmtpos, attrpos) __attribute__((__format__(__printf__, fmtpos, attrpos)))
#else #else
@ -159,7 +158,7 @@
# define av_printf_format(fmtpos, attrpos) # define av_printf_format(fmtpos, attrpos)
#endif #endif
#if AV_GCC_VERSION_AT_LEAST(2,5) #if AV_GCC_VERSION_AT_LEAST(2,5) || defined(__clang__)
# define av_noreturn __attribute__((noreturn)) # define av_noreturn __attribute__((noreturn))
#else #else
# define av_noreturn # define av_noreturn

@ -110,6 +110,23 @@ int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples);
*/ */
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples); int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples);
/**
* Peek data from an AVAudioFifo.
*
* @see enum AVSampleFormat
* The documentation for AVSampleFormat describes the data layout.
*
* @param af AVAudioFifo to read from
* @param data audio data plane pointers
* @param nb_samples number of samples to peek
* @param offset offset from current read position
* @return number of samples actually peek, or negative AVERROR code
* on failure. The number of samples actually peek will not
* be greater than nb_samples, and will only be less than
* nb_samples if av_audio_fifo_size is less than nb_samples.
*/
int av_audio_fifo_peek_at(AVAudioFifo *af, void **data, int nb_samples, int offset);
/** /**
* Read data from an AVAudioFifo. * Read data from an AVAudioFifo.
* *

@ -45,7 +45,7 @@
/** /**
* assert() equivalent, that does not lie in speed critical code. * assert() equivalent, that does not lie in speed critical code.
* These asserts() thus can be enabled without fearing speedloss. * These asserts() thus can be enabled without fearing speed loss.
*/ */
#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 0 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 0
#define av_assert1(cond) av_assert0(cond) #define av_assert1(cond) av_assert0(cond)
@ -59,8 +59,17 @@
*/ */
#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
#define av_assert2(cond) av_assert0(cond) #define av_assert2(cond) av_assert0(cond)
#define av_assert2_fpu() av_assert0_fpu()
#else #else
#define av_assert2(cond) ((void)0) #define av_assert2(cond) ((void)0)
#define av_assert2_fpu() ((void)0)
#endif #endif
/**
* Assert that floating point operations can be executed.
*
* This will av_assert0() that the cpu is not in MMX state on X86
*/
void av_assert0_fpu(void);
#endif /* AVUTIL_AVASSERT_H */ #endif /* AVUTIL_AVASSERT_H */

@ -1,7 +1,6 @@
/* Generated by ffconf */ /* Generated by ffmpeg configure */
#ifndef AVUTIL_AVCONFIG_H #ifndef AVUTIL_AVCONFIG_H
#define AVUTIL_AVCONFIG_H #define AVUTIL_AVCONFIG_H
#define AV_HAVE_BIGENDIAN 0 #define AV_HAVE_BIGENDIAN 0
#define AV_HAVE_FAST_UNALIGNED 0 #define AV_HAVE_FAST_UNALIGNED 1
#define AV_HAVE_INCOMPATIBLE_LIBAV_ABI 0
#endif /* AVUTIL_AVCONFIG_H */ #endif /* AVUTIL_AVCONFIG_H */

@ -156,7 +156,7 @@ static inline size_t av_strnlen(const char *s, size_t len)
char *av_asprintf(const char *fmt, ...) av_printf_format(1, 2); char *av_asprintf(const char *fmt, ...) av_printf_format(1, 2);
/** /**
* Convert a number to a av_malloced string. * Convert a number to an av_malloced string.
*/ */
char *av_d2str(double d); char *av_d2str(double d);
@ -266,6 +266,11 @@ int av_strcasecmp(const char *a, const char *b);
*/ */
int av_strncasecmp(const char *a, const char *b, size_t n); int av_strncasecmp(const char *a, const char *b, size_t n);
/**
* Locale-independent strings replace.
* @note This means only ASCII-range characters are replace
*/
char *av_strireplace(const char *str, const char *from, const char *to);
/** /**
* Thread safe basename. * Thread safe basename.
@ -395,6 +400,12 @@ int av_utf8_decode(int32_t *codep, const uint8_t **bufp, const uint8_t *buf_end,
*/ */
int av_match_list(const char *name, const char *list, char separator); int av_match_list(const char *name, const char *list, char separator);
/**
* See libc sscanf manual for more information.
* Locale-independent sscanf implementation.
*/
int av_sscanf(const char *string, const char *format, ...);
/** /**
* @} * @}
*/ */

@ -23,7 +23,8 @@
/** /**
* @file * @file
* external API header * @ingroup lavu
* Convenience header that includes @ref lavu "libavutil"'s core.
*/ */
/** /**
@ -78,14 +79,15 @@
*/ */
/** /**
* @defgroup lavu Common utility functions * @defgroup lavu libavutil
* Common code shared across all FFmpeg libraries.
* *
* @brief * @note
* libavutil contains the code shared across all the other FFmpeg * libavutil is designed to be modular. In most cases, in order to use the
* libraries * functions provided by one component of libavutil you must explicitly include
* * the specific header containing that feature. If you are only using
* @note In order to use the functions provided by avutil you must include * media-related components, you could simply include libavutil/avutil.h, which
* the specific header. * brings in most of the "core" components.
* *
* @{ * @{
* *
@ -94,7 +96,7 @@
* @{ * @{
* @} * @}
* *
* @defgroup lavu_math Maths * @defgroup lavu_math Mathematics
* @{ * @{
* *
* @} * @}
@ -116,6 +118,12 @@
* *
* @} * @}
* *
* @defgroup lavu_video Video related
*
* @{
*
* @}
*
* @defgroup lavu_audio Audio related * @defgroup lavu_audio Audio related
* *
* @{ * @{
@ -266,7 +274,7 @@ enum AVPictureType {
AV_PICTURE_TYPE_I, ///< Intra AV_PICTURE_TYPE_I, ///< Intra
AV_PICTURE_TYPE_P, ///< Predicted AV_PICTURE_TYPE_P, ///< Predicted
AV_PICTURE_TYPE_B, ///< Bi-dir predicted AV_PICTURE_TYPE_B, ///< Bi-dir predicted
AV_PICTURE_TYPE_S, ///< S(GMC)-VOP MPEG4 AV_PICTURE_TYPE_S, ///< S(GMC)-VOP MPEG-4
AV_PICTURE_TYPE_SI, ///< Switching Intra AV_PICTURE_TYPE_SI, ///< Switching Intra
AV_PICTURE_TYPE_SP, ///< Switching Predicted AV_PICTURE_TYPE_SP, ///< Switching Predicted
AV_PICTURE_TYPE_BI, ///< BI type AV_PICTURE_TYPE_BI, ///< BI type
@ -335,6 +343,20 @@ FILE *av_fopen_utf8(const char *path, const char *mode);
*/ */
AVRational av_get_time_base_q(void); AVRational av_get_time_base_q(void);
#define AV_FOURCC_MAX_STRING_SIZE 32
#define av_fourcc2str(fourcc) av_fourcc_make_string((char[AV_FOURCC_MAX_STRING_SIZE]){0}, fourcc)
/**
* Fill the provided buffer with a string containing a FourCC (four-character
* code) representation.
*
* @param buf a buffer with size in bytes of at least AV_FOURCC_MAX_STRING_SIZE
* @param fourcc the fourcc to represent
* @return the buffer in input
*/
char *av_fourcc_make_string(char *buf, uint32_t fourcc);
/** /**
* @} * @}
* @} * @}

@ -29,19 +29,24 @@
* @{ * @{
*/ */
/** /**
* Decode a base64-encoded string. * Decode a base64-encoded string.
* *
* @param out buffer for decoded data * @param out buffer for decoded data
* @param in null-terminated input string * @param in null-terminated input string
* @param out_size size in bytes of the out buffer, must be at * @param out_size size in bytes of the out buffer, must be at
* least 3/4 of the length of in * least 3/4 of the length of in, that is AV_BASE64_DECODE_SIZE(strlen(in))
* @return number of bytes written, or a negative value in case of * @return number of bytes written, or a negative value in case of
* invalid input * invalid input
*/ */
int av_base64_decode(uint8_t *out, const char *in, int out_size); int av_base64_decode(uint8_t *out, const char *in, int out_size);
/**
* Calculate the output size in bytes needed to decode a base64 string
* with length x to a data buffer.
*/
#define AV_BASE64_DECODE_SIZE(x) ((x) * 3LL / 4)
/** /**
* Encode data to base64 and null-terminate. * Encode data to base64 and null-terminate.
* *

@ -248,6 +248,24 @@ typedef struct AVBufferPool AVBufferPool;
*/ */
AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)); AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size));
/**
* Allocate and initialize a buffer pool with a more complex allocator.
*
* @param size size of each buffer in this pool
* @param opaque arbitrary user data used by the allocator
* @param alloc a function that will be used to allocate new buffers when the
* pool is empty.
* @param pool_free a function that will be called immediately before the pool
* is freed. I.e. after av_buffer_pool_uninit() is called
* by the caller and all the frames are returned to the pool
* and freed. It is intended to uninitialize the user opaque
* data.
* @return newly created buffer pool on success, NULL on error.
*/
AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
AVBufferRef* (*alloc)(void *opaque, int size),
void (*pool_free)(void *opaque));
/** /**
* Mark the pool as being available for freeing. It will actually be freed only * Mark the pool as being available for freeing. It will actually be freed only
* once all the allocated buffers associated with the pool are released. Thus it * once all the allocated buffers associated with the pool are released. Thus it
@ -255,7 +273,6 @@ AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size));
* in use. * in use.
* *
* @param pool pointer to the pool to be freed. It will be set to NULL. * @param pool pointer to the pool to be freed. It will be set to NULL.
* @see av_buffer_pool_can_uninit()
*/ */
void av_buffer_pool_uninit(AVBufferPool **pool); void av_buffer_pool_uninit(AVBufferPool **pool);

@ -131,21 +131,30 @@ enum AVMatrixEncoding {
* 5.0(side), 5.1, 5.1(side), 7.1, 7.1(wide), downmix); * 5.0(side), 5.1, 5.1(side), 7.1, 7.1(wide), downmix);
* - the name of a single channel (FL, FR, FC, LFE, BL, BR, FLC, FRC, BC, * - the name of a single channel (FL, FR, FC, LFE, BL, BR, FLC, FRC, BC,
* SL, SR, TC, TFL, TFC, TFR, TBL, TBC, TBR, DL, DR); * SL, SR, TC, TFL, TFC, TFR, TBL, TBC, TBR, DL, DR);
* - a number of channels, in decimal, optionally followed by 'c', yielding * - a number of channels, in decimal, followed by 'c', yielding
* the default channel layout for that number of channels (@see * the default channel layout for that number of channels (@see
* av_get_default_channel_layout); * av_get_default_channel_layout);
* - a channel layout mask, in hexadecimal starting with "0x" (see the * - a channel layout mask, in hexadecimal starting with "0x" (see the
* AV_CH_* macros). * AV_CH_* macros).
* *
* @warning Starting from the next major bump the trailing character
* 'c' to specify a number of channels will be required, while a
* channel layout mask could also be specified as a decimal number
* (if and only if not followed by "c").
*
* Example: "stereo+FC" = "2c+FC" = "2c+1c" = "0x7" * Example: "stereo+FC" = "2c+FC" = "2c+1c" = "0x7"
*/ */
uint64_t av_get_channel_layout(const char *name); uint64_t av_get_channel_layout(const char *name);
/**
* Return a channel layout and the number of channels based on the specified name.
*
* This function is similar to (@see av_get_channel_layout), but can also parse
* unknown channel layout specifications.
*
* @param[in] name channel layout specification string
* @param[out] channel_layout parsed channel layout (0 if unknown)
* @param[out] nb_channels number of channels
*
* @return 0 on success, AVERROR(EINVAL) if the parsing fails.
*/
int av_get_extended_channel_layout(const char *name, uint64_t* channel_layout, int* nb_channels);
/** /**
* Return a description of a channel layout. * Return a description of a channel layout.
* If nb_channels is <= 0, it is guessed from the channel_layout. * If nb_channels is <= 0, it is guessed from the channel_layout.

@ -158,7 +158,7 @@ static av_always_inline av_const int64_t av_clip64_c(int64_t a, int64_t amin, in
*/ */
static av_always_inline av_const uint8_t av_clip_uint8_c(int a) static av_always_inline av_const uint8_t av_clip_uint8_c(int a)
{ {
if (a&(~0xFF)) return (-a)>>31; if (a&(~0xFF)) return (~a)>>31;
else return a; else return a;
} }
@ -180,7 +180,7 @@ static av_always_inline av_const int8_t av_clip_int8_c(int a)
*/ */
static av_always_inline av_const uint16_t av_clip_uint16_c(int a) static av_always_inline av_const uint16_t av_clip_uint16_c(int a)
{ {
if (a&(~0xFFFF)) return (-a)>>31; if (a&(~0xFFFF)) return (~a)>>31;
else return a; else return a;
} }
@ -228,7 +228,7 @@ static av_always_inline av_const int av_clip_intp2_c(int a, int p)
*/ */
static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p) static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
{ {
if (a & ~((1<<p) - 1)) return -a >> 31 & ((1<<p) - 1); if (a & ~((1<<p) - 1)) return (~a) >> 31 & ((1<<p) - 1);
else return a; else return a;
} }
@ -260,13 +260,37 @@ static av_always_inline int av_sat_add32_c(int a, int b)
* *
* @param a first value * @param a first value
* @param b value doubled and added to a * @param b value doubled and added to a
* @return sum with signed saturation * @return sum sat(a + sat(2*b)) with signed saturation
*/ */
static av_always_inline int av_sat_dadd32_c(int a, int b) static av_always_inline int av_sat_dadd32_c(int a, int b)
{ {
return av_sat_add32(a, av_sat_add32(b, b)); return av_sat_add32(a, av_sat_add32(b, b));
} }
/**
* Subtract two signed 32-bit values with saturation.
*
* @param a one value
* @param b another value
* @return difference with signed saturation
*/
static av_always_inline int av_sat_sub32_c(int a, int b)
{
return av_clipl_int32((int64_t)a - b);
}
/**
* Subtract a doubled value from another value with saturation at both stages.
*
* @param a first value
* @param b value doubled and subtracted from a
* @return difference sat(a - sat(2*b)) with signed saturation
*/
static av_always_inline int av_sat_dsub32_c(int a, int b)
{
return av_sat_sub32(a, av_sat_add32(b, b));
}
/** /**
* Clip a float value into the amin-amax range. * Clip a float value into the amin-amax range.
* @param a value to clip * @param a value to clip
@ -513,6 +537,12 @@ static av_always_inline av_const int av_parity_c(uint32_t v)
#ifndef av_sat_dadd32 #ifndef av_sat_dadd32
# define av_sat_dadd32 av_sat_dadd32_c # define av_sat_dadd32 av_sat_dadd32_c
#endif #endif
#ifndef av_sat_sub32
# define av_sat_sub32 av_sat_sub32_c
#endif
#ifndef av_sat_dsub32
# define av_sat_dsub32 av_sat_dsub32_c
#endif
#ifndef av_clipf #ifndef av_clipf
# define av_clipf av_clipf_c # define av_clipf av_clipf_c
#endif #endif

@ -21,6 +21,8 @@
#ifndef AVUTIL_CPU_H #ifndef AVUTIL_CPU_H
#define AVUTIL_CPU_H #define AVUTIL_CPU_H
#include <stddef.h>
#include "attributes.h" #include "attributes.h"
#define AV_CPU_FLAG_FORCE 0x80000000 /* force usage of selected flags (OR) */ #define AV_CPU_FLAG_FORCE 0x80000000 /* force usage of selected flags (OR) */
@ -39,6 +41,7 @@
#define AV_CPU_FLAG_SSE3SLOW 0x20000000 ///< SSE3 supported, but usually not faster #define AV_CPU_FLAG_SSE3SLOW 0x20000000 ///< SSE3 supported, but usually not faster
///< than regular MMX/SSE (e.g. Core1) ///< than regular MMX/SSE (e.g. Core1)
#define AV_CPU_FLAG_SSSE3 0x0080 ///< Conroe SSSE3 functions #define AV_CPU_FLAG_SSSE3 0x0080 ///< Conroe SSSE3 functions
#define AV_CPU_FLAG_SSSE3SLOW 0x4000000 ///< SSSE3 supported, but usually not faster
#define AV_CPU_FLAG_ATOM 0x10000000 ///< Atom processor, some SSSE3 instructions are slower #define AV_CPU_FLAG_ATOM 0x10000000 ///< Atom processor, some SSSE3 instructions are slower
#define AV_CPU_FLAG_SSE4 0x0100 ///< Penryn SSE4.1 functions #define AV_CPU_FLAG_SSE4 0x0100 ///< Penryn SSE4.1 functions
#define AV_CPU_FLAG_SSE42 0x0200 ///< Nehalem SSE4.2 functions #define AV_CPU_FLAG_SSE42 0x0200 ///< Nehalem SSE4.2 functions
@ -52,6 +55,7 @@
#define AV_CPU_FLAG_FMA3 0x10000 ///< Haswell FMA3 functions #define AV_CPU_FLAG_FMA3 0x10000 ///< Haswell FMA3 functions
#define AV_CPU_FLAG_BMI1 0x20000 ///< Bit Manipulation Instruction Set 1 #define AV_CPU_FLAG_BMI1 0x20000 ///< Bit Manipulation Instruction Set 1
#define AV_CPU_FLAG_BMI2 0x40000 ///< Bit Manipulation Instruction Set 2 #define AV_CPU_FLAG_BMI2 0x40000 ///< Bit Manipulation Instruction Set 2
#define AV_CPU_FLAG_AVX512 0x100000 ///< AVX-512 functions: requires OS support even if YMM/ZMM registers aren't used
#define AV_CPU_FLAG_ALTIVEC 0x0001 ///< standard #define AV_CPU_FLAG_ALTIVEC 0x0001 ///< standard
#define AV_CPU_FLAG_VSX 0x0002 ///< ISA 2.06 #define AV_CPU_FLAG_VSX 0x0002 ///< ISA 2.06
@ -70,7 +74,7 @@
/** /**
* Return the flags which specify extensions supported by the CPU. * Return the flags which specify extensions supported by the CPU.
* The returned value is affected by av_force_cpu_flags() if that was used * The returned value is affected by av_force_cpu_flags() if that was used
* before. So av_get_cpu_flags() can easily be used in a application to * before. So av_get_cpu_flags() can easily be used in an application to
* detect the enabled cpu flags. * detect the enabled cpu flags.
*/ */
int av_get_cpu_flags(void); int av_get_cpu_flags(void);
@ -85,8 +89,6 @@ void av_force_cpu_flags(int flags);
* Set a mask on flags returned by av_get_cpu_flags(). * Set a mask on flags returned by av_get_cpu_flags().
* This function is mainly useful for testing. * This function is mainly useful for testing.
* Please use av_force_cpu_flags() and av_get_cpu_flags() instead which are more flexible * Please use av_force_cpu_flags() and av_get_cpu_flags() instead which are more flexible
*
* @warning this function is not thread safe.
*/ */
attribute_deprecated void av_set_cpu_flags_mask(int mask); attribute_deprecated void av_set_cpu_flags_mask(int mask);
@ -114,4 +116,15 @@ int av_parse_cpu_caps(unsigned *flags, const char *s);
*/ */
int av_cpu_count(void); int av_cpu_count(void);
/**
* Get the maximum data alignment that may be required by FFmpeg.
*
* Note that this is affected by the build configuration and the CPU flags mask,
* so e.g. if the CPU supports AVX, but libavutil has been built with
* --disable-avx or the AV_CPU_FLAG_AVX flag has been disabled through
* av_set_cpu_flags_mask(), then this function will behave as if AVX is not
* present.
*/
size_t av_cpu_max_align(void);
#endif /* AVUTIL_CPU_H */ #endif /* AVUTIL_CPU_H */

@ -18,6 +18,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* @file
* @ingroup lavu_crc32
* Public header for CRC hash function implementation.
*/
#ifndef AVUTIL_CRC_H #ifndef AVUTIL_CRC_H
#define AVUTIL_CRC_H #define AVUTIL_CRC_H
@ -27,8 +33,14 @@
#include "version.h" #include "version.h"
/** /**
* @defgroup lavu_crc32 CRC32 * @defgroup lavu_crc32 CRC
* @ingroup lavu_crypto * @ingroup lavu_hash
* CRC (Cyclic Redundancy Check) hash function implementation.
*
* This module supports numerous CRC polynomials, in addition to the most
* widely used CRC-32-IEEE. See @ref AVCRCId for a list of available
* polynomials.
*
* @{ * @{
*/ */
@ -41,11 +53,8 @@ typedef enum {
AV_CRC_32_IEEE, AV_CRC_32_IEEE,
AV_CRC_32_IEEE_LE, /*< reversed bitorder version of AV_CRC_32_IEEE */ AV_CRC_32_IEEE_LE, /*< reversed bitorder version of AV_CRC_32_IEEE */
AV_CRC_16_ANSI_LE, /*< reversed bitorder version of AV_CRC_16_ANSI */ AV_CRC_16_ANSI_LE, /*< reversed bitorder version of AV_CRC_16_ANSI */
#if FF_API_CRC_BIG_TABLE
AV_CRC_24_IEEE = 12,
#else
AV_CRC_24_IEEE, AV_CRC_24_IEEE,
#endif /* FF_API_CRC_BIG_TABLE */ AV_CRC_8_EBU,
AV_CRC_MAX, /*< Not part of public API! Do not use outside libavutil. */ AV_CRC_MAX, /*< Not part of public API! Do not use outside libavutil. */
}AVCRCId; }AVCRCId;

@ -1,5 +1,4 @@
/* /*
*
* This file is part of FFmpeg. * This file is part of FFmpeg.
* *
* FFmpeg is free software; you can redistribute it and/or * FFmpeg is free software; you can redistribute it and/or
@ -65,7 +64,6 @@
} }
av_dict_free(&d); av_dict_free(&d);
@endcode @endcode
*
*/ */
#define AV_DICT_MATCH_CASE 1 /**< Only get an entry with exact-case key match. Only relevant in av_dict_get(). */ #define AV_DICT_MATCH_CASE 1 /**< Only get an entry with exact-case key match. Only relevant in av_dict_get(). */
@ -78,6 +76,7 @@
#define AV_DICT_DONT_OVERWRITE 16 ///< Don't overwrite existing entries. #define AV_DICT_DONT_OVERWRITE 16 ///< Don't overwrite existing entries.
#define AV_DICT_APPEND 32 /**< If the entry already exists, append to it. Note that no #define AV_DICT_APPEND 32 /**< If the entry already exists, append to it. Note that no
delimiter is added, the strings are simply concatenated. */ delimiter is added, the strings are simply concatenated. */
#define AV_DICT_MULTIKEY 64 /**< Allow to store several equal keys in the dictionary */
typedef struct AVDictionaryEntry { typedef struct AVDictionaryEntry {
char *key; char *key;
@ -118,10 +117,13 @@ int av_dict_count(const AVDictionary *m);
* Note: If AV_DICT_DONT_STRDUP_KEY or AV_DICT_DONT_STRDUP_VAL is set, * Note: If AV_DICT_DONT_STRDUP_KEY or AV_DICT_DONT_STRDUP_VAL is set,
* these arguments will be freed on error. * these arguments will be freed on error.
* *
* Warning: Adding a new entry to a dictionary invalidates all existing entries
* previously returned with av_dict_get.
*
* @param pm pointer to a pointer to a dictionary struct. If *pm is NULL * @param pm pointer to a pointer to a dictionary struct. If *pm is NULL
* a dictionary struct is allocated and put in *pm. * a dictionary struct is allocated and put in *pm.
* @param key entry key to add to *pm (will be av_strduped depending on flags) * @param key entry key to add to *pm (will either be av_strduped or added as a new key depending on flags)
* @param value entry value to add to *pm (will be av_strduped depending on flags). * @param value entry value to add to *pm (will be av_strduped or added as a new key depending on flags).
* Passing a NULL value will cause an existing entry to be deleted. * Passing a NULL value will cause an existing entry to be deleted.
* @return >= 0 on success otherwise an error code <0 * @return >= 0 on success otherwise an error code <0
*/ */

@ -18,21 +18,38 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* @file
* Display matrix
*/
#ifndef AVUTIL_DISPLAY_H #ifndef AVUTIL_DISPLAY_H
#define AVUTIL_DISPLAY_H #define AVUTIL_DISPLAY_H
#include <stdint.h> #include <stdint.h>
#include "common.h"
/**
* @addtogroup lavu_video
* @{
*
* @defgroup lavu_video_display Display transformation matrix functions
* @{
*/
/** /**
* @addtogroup lavu_video_display
* The display transformation matrix specifies an affine transformation that * The display transformation matrix specifies an affine transformation that
* should be applied to video frames for correct presentation. It is compatible * should be applied to video frames for correct presentation. It is compatible
* with the matrices stored in the ISO/IEC 14496-12 container format. * with the matrices stored in the ISO/IEC 14496-12 container format.
* *
* The data is a 3x3 matrix represented as a 9-element array: * The data is a 3x3 matrix represented as a 9-element array:
* *
* @code{.unparsed}
* | a b u | * | a b u |
* (a, b, u, c, d, v, x, y, w) -> | c d v | * (a, b, u, c, d, v, x, y, w) -> | c d v |
* | x y w | * | x y w |
* @endcode
* *
* All numbers are stored in native endianness, as 16.16 fixed-point values, * All numbers are stored in native endianness, as 16.16 fixed-point values,
* except for u, v and w, which are stored as 2.30 fixed-point values. * except for u, v and w, which are stored as 2.30 fixed-point values.
@ -40,15 +57,21 @@
* The transformation maps a point (p, q) in the source (pre-transformation) * The transformation maps a point (p, q) in the source (pre-transformation)
* frame to the point (p', q') in the destination (post-transformation) frame as * frame to the point (p', q') in the destination (post-transformation) frame as
* follows: * follows:
*
* @code{.unparsed}
* | a b u | * | a b u |
* (p, q, 1) . | c d v | = z * (p', q', 1) * (p, q, 1) . | c d v | = z * (p', q', 1)
* | x y w | * | x y w |
* @endcode
* *
* The transformation can also be more explicitly written in components as * The transformation can also be more explicitly written in components as
* follows: * follows:
*
* @code{.unparsed}
* p' = (a * p + c * q + x) / z; * p' = (a * p + c * q + x) / z;
* q' = (b * p + d * q + y) / z; * q' = (b * p + d * q + y) / z;
* z = u * p + v * q + w * z = u * p + v * q + w
* @endcode
*/ */
/** /**
@ -83,4 +106,9 @@ void av_display_rotation_set(int32_t matrix[9], double angle);
*/ */
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip); void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip);
/**
* @}
* @}
*/
#endif /* AVUTIL_DISPLAY_H */ #endif /* AVUTIL_DISPLAY_H */

@ -0,0 +1,205 @@
/**
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVUTIL_ENCRYPTION_INFO_H
#define AVUTIL_ENCRYPTION_INFO_H
#include <stddef.h>
#include <stdint.h>
typedef struct AVSubsampleEncryptionInfo {
/** The number of bytes that are clear. */
unsigned int bytes_of_clear_data;
/**
* The number of bytes that are protected. If using pattern encryption,
* the pattern applies to only the protected bytes; if not using pattern
* encryption, all these bytes are encrypted.
*/
unsigned int bytes_of_protected_data;
} AVSubsampleEncryptionInfo;
/**
* This describes encryption info for a packet. This contains frame-specific
* info for how to decrypt the packet before passing it to the decoder.
*
* The size of this struct is not part of the public ABI.
*/
typedef struct AVEncryptionInfo {
/** The fourcc encryption scheme, in big-endian byte order. */
uint32_t scheme;
/**
* Only used for pattern encryption. This is the number of 16-byte blocks
* that are encrypted.
*/
uint32_t crypt_byte_block;
/**
* Only used for pattern encryption. This is the number of 16-byte blocks
* that are clear.
*/
uint32_t skip_byte_block;
/**
* The ID of the key used to encrypt the packet. This should always be
* 16 bytes long, but may be changed in the future.
*/
uint8_t *key_id;
uint32_t key_id_size;
/**
* The initialization vector. This may have been zero-filled to be the
* correct block size. This should always be 16 bytes long, but may be
* changed in the future.
*/
uint8_t *iv;
uint32_t iv_size;
/**
* An array of subsample encryption info specifying how parts of the sample
* are encrypted. If there are no subsamples, then the whole sample is
* encrypted.
*/
AVSubsampleEncryptionInfo *subsamples;
uint32_t subsample_count;
} AVEncryptionInfo;
/**
* This describes info used to initialize an encryption key system.
*
* The size of this struct is not part of the public ABI.
*/
typedef struct AVEncryptionInitInfo {
/**
* A unique identifier for the key system this is for, can be NULL if it
* is not known. This should always be 16 bytes, but may change in the
* future.
*/
uint8_t* system_id;
uint32_t system_id_size;
/**
* An array of key IDs this initialization data is for. All IDs are the
* same length. Can be NULL if there are no known key IDs.
*/
uint8_t** key_ids;
/** The number of key IDs. */
uint32_t num_key_ids;
/**
* The number of bytes in each key ID. This should always be 16, but may
* change in the future.
*/
uint32_t key_id_size;
/**
* Key-system specific initialization data. This data is copied directly
* from the file and the format depends on the specific key system. This
* can be NULL if there is no initialization data; in that case, there
* will be at least one key ID.
*/
uint8_t* data;
uint32_t data_size;
/**
* An optional pointer to the next initialization info in the list.
*/
struct AVEncryptionInitInfo *next;
} AVEncryptionInitInfo;
/**
* Allocates an AVEncryptionInfo structure and sub-pointers to hold the given
* number of subsamples. This will allocate pointers for the key ID, IV,
* and subsample entries, set the size members, and zero-initialize the rest.
*
* @param subsample_count The number of subsamples.
* @param key_id_size The number of bytes in the key ID, should be 16.
* @param iv_size The number of bytes in the IV, should be 16.
*
* @return The new AVEncryptionInfo structure, or NULL on error.
*/
AVEncryptionInfo *av_encryption_info_alloc(uint32_t subsample_count, uint32_t key_id_size, uint32_t iv_size);
/**
* Allocates an AVEncryptionInfo structure with a copy of the given data.
* @return The new AVEncryptionInfo structure, or NULL on error.
*/
AVEncryptionInfo *av_encryption_info_clone(const AVEncryptionInfo *info);
/**
* Frees the given encryption info object. This MUST NOT be used to free the
* side-data data pointer, that should use normal side-data methods.
*/
void av_encryption_info_free(AVEncryptionInfo *info);
/**
* Creates a copy of the AVEncryptionInfo that is contained in the given side
* data. The resulting object should be passed to av_encryption_info_free()
* when done.
*
* @return The new AVEncryptionInfo structure, or NULL on error.
*/
AVEncryptionInfo *av_encryption_info_get_side_data(const uint8_t *side_data, size_t side_data_size);
/**
* Allocates and initializes side data that holds a copy of the given encryption
* info. The resulting pointer should be either freed using av_free or given
* to av_packet_add_side_data().
*
* @return The new side-data pointer, or NULL.
*/
uint8_t *av_encryption_info_add_side_data(
const AVEncryptionInfo *info, size_t *side_data_size);
/**
* Allocates an AVEncryptionInitInfo structure and sub-pointers to hold the
* given sizes. This will allocate pointers and set all the fields.
*
* @return The new AVEncryptionInitInfo structure, or NULL on error.
*/
AVEncryptionInitInfo *av_encryption_init_info_alloc(
uint32_t system_id_size, uint32_t num_key_ids, uint32_t key_id_size, uint32_t data_size);
/**
* Frees the given encryption init info object. This MUST NOT be used to free
* the side-data data pointer, that should use normal side-data methods.
*/
void av_encryption_init_info_free(AVEncryptionInitInfo* info);
/**
* Creates a copy of the AVEncryptionInitInfo that is contained in the given
* side data. The resulting object should be passed to
* av_encryption_init_info_free() when done.
*
* @return The new AVEncryptionInitInfo structure, or NULL on error.
*/
AVEncryptionInitInfo *av_encryption_init_info_get_side_data(
const uint8_t* side_data, size_t side_data_size);
/**
* Allocates and initializes side data that holds a copy of the given encryption
* init info. The resulting pointer should be either freed using av_free or
* given to av_packet_add_side_data().
*
* @return The new side-data pointer, or NULL.
*/
uint8_t *av_encryption_init_info_add_side_data(
const AVEncryptionInitInfo *info, size_t *side_data_size);
#endif /* AVUTIL_ENCRYPTION_INFO_H */

@ -1,5 +1,5 @@
/* Automatically generated by version.sh, do not manually edit! */ /* Automatically generated by version.sh, do not manually edit! */
#ifndef AVUTIL_FFVERSION_H #ifndef AVUTIL_FFVERSION_H
#define AVUTIL_FFVERSION_H #define AVUTIL_FFVERSION_H
#define FFMPEG_VERSION "3.0.3" #define FFMPEG_VERSION "r2.9.6-875-g7d430423d"
#endif /* AVUTIL_FFVERSION_H */ #endif /* AVUTIL_FFVERSION_H */

@ -33,6 +33,8 @@
* allocated buffer or map it with mmap() when available. * allocated buffer or map it with mmap() when available.
* In case of success set *bufptr to the read or mmapped buffer, and * In case of success set *bufptr to the read or mmapped buffer, and
* *size to the size in bytes of the buffer in *bufptr. * *size to the size in bytes of the buffer in *bufptr.
* Unlike mmap this function succeeds with zero sized files, in this
* case *bufptr will be set to NULL and *size will be set to 0.
* The returned buffer must be released with av_file_unmap(). * The returned buffer must be released with av_file_unmap().
* *
* @param log_offset loglevel offset used for logging * @param log_offset loglevel offset used for logging
@ -62,6 +64,7 @@ void av_file_unmap(uint8_t *bufptr, size_t size);
* @note On very old libcs it is necessary to set a secure umask before * @note On very old libcs it is necessary to set a secure umask before
* calling this, av_tempfile() can't call umask itself as it is used in * calling this, av_tempfile() can't call umask itself as it is used in
* libraries and could interfere with the calling application. * libraries and could interfere with the calling application.
* @deprecated as fd numbers cannot be passed saftely between libs on some platforms
*/ */
int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx); int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx);

@ -1,5 +1,4 @@
/* /*
*
* This file is part of FFmpeg. * This file is part of FFmpeg.
* *
* FFmpeg is free software; you can redistribute it and/or * FFmpeg is free software; you can redistribute it and/or
@ -26,6 +25,7 @@
#ifndef AVUTIL_FRAME_H #ifndef AVUTIL_FRAME_H
#define AVUTIL_FRAME_H #define AVUTIL_FRAME_H
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "avutil.h" #include "avutil.h"
@ -121,7 +121,64 @@ enum AVFrameSideDataType {
* The GOP timecode in 25 bit timecode format. Data format is 64-bit integer. * The GOP timecode in 25 bit timecode format. Data format is 64-bit integer.
* This is set on the first frame of a GOP that has a temporal reference of 0. * This is set on the first frame of a GOP that has a temporal reference of 0.
*/ */
AV_FRAME_DATA_GOP_TIMECODE AV_FRAME_DATA_GOP_TIMECODE,
/**
* The data represents the AVSphericalMapping structure defined in
* libavutil/spherical.h.
*/
AV_FRAME_DATA_SPHERICAL,
/**
* Content light level (based on CTA-861.3). This payload contains data in
* the form of the AVContentLightMetadata struct.
*/
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
/**
* The data contains an ICC profile as an opaque octet buffer following the
* format described by ISO 15076-1 with an optional name defined in the
* metadata key entry "name".
*/
AV_FRAME_DATA_ICC_PROFILE,
#if FF_API_FRAME_QP
/**
* Implementation-specific description of the format of AV_FRAME_QP_TABLE_DATA.
* The contents of this side data are undocumented and internal; use
* av_frame_set_qp_table() and av_frame_get_qp_table() to access this in a
* meaningful way instead.
*/
AV_FRAME_DATA_QP_TABLE_PROPERTIES,
/**
* Raw QP table data. Its format is described by
* AV_FRAME_DATA_QP_TABLE_PROPERTIES. Use av_frame_set_qp_table() and
* av_frame_get_qp_table() to access this instead.
*/
AV_FRAME_DATA_QP_TABLE_DATA,
#endif
/**
* Timecode which conforms to SMPTE ST 12-1. The data is an array of 4 uint32_t
* where the first uint32_t describes how many (1-3) of the other timecodes are used.
* The timecode format is described in the av_timecode_get_smpte_from_framenum()
* function in libavutil/timecode.c.
*/
AV_FRAME_DATA_S12M_TIMECODE,
/**
* HDR dynamic metadata associated with a video frame. The payload is
* an AVDynamicHDRPlus type and contains information for color
* volume transform - application 4 of SMPTE 2094-40:2016 standard.
*/
AV_FRAME_DATA_DYNAMIC_HDR_PLUS,
/**
* Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of
* array element is implied by AVFrameSideData.size / AVRegionOfInterest.self_size.
*/
AV_FRAME_DATA_REGIONS_OF_INTEREST,
}; };
enum AVActiveFormatDescription { enum AVActiveFormatDescription {
@ -149,6 +206,62 @@ typedef struct AVFrameSideData {
AVBufferRef *buf; AVBufferRef *buf;
} AVFrameSideData; } AVFrameSideData;
/**
* Structure describing a single Region Of Interest.
*
* When multiple regions are defined in a single side-data block, they
* should be ordered from most to least important - some encoders are only
* capable of supporting a limited number of distinct regions, so will have
* to truncate the list.
*
* When overlapping regions are defined, the first region containing a given
* area of the frame applies.
*/
typedef struct AVRegionOfInterest {
/**
* Must be set to the size of this data structure (that is,
* sizeof(AVRegionOfInterest)).
*/
uint32_t self_size;
/**
* Distance in pixels from the top edge of the frame to the top and
* bottom edges and from the left edge of the frame to the left and
* right edges of the rectangle defining this region of interest.
*
* The constraints on a region are encoder dependent, so the region
* actually affected may be slightly larger for alignment or other
* reasons.
*/
int top;
int bottom;
int left;
int right;
/**
* Quantisation offset.
*
* Must be in the range -1 to +1. A value of zero indicates no quality
* change. A negative value asks for better quality (less quantisation),
* while a positive value asks for worse quality (greater quantisation).
*
* The range is calibrated so that the extreme values indicate the
* largest possible offset - if the rest of the frame is encoded with the
* worst possible quality, an offset of -1 indicates that this region
* should be encoded with the best possible quality anyway. Intermediate
* values are then interpolated in some codec-dependent way.
*
* For example, in 10-bit H.264 the quantisation parameter varies between
* -12 and 51. A typical qoffset value of -1/10 therefore indicates that
* this region should be encoded with a QP around one-tenth of the full
* range better than the rest of the frame. So, if most of the frame
* were to be encoded with a QP of around 30, this region would get a QP
* of around 24 (an offset of approximately -1/10 * (51 - -12) = -6.3).
* An extreme value of -1 would indicate that this region should be
* encoded with the best possible quality regardless of the treatment of
* the rest of the frame - that is, should be encoded at a QP of -12.
*/
AVRational qoffset;
} AVRegionOfInterest;
/** /**
* This structure describes decoded (raw) audio or video data. * This structure describes decoded (raw) audio or video data.
* *
@ -174,9 +287,10 @@ typedef struct AVFrameSideData {
* *
* sizeof(AVFrame) is not a part of the public ABI, so new fields may be added * sizeof(AVFrame) is not a part of the public ABI, so new fields may be added
* to the end with a minor bump. * to the end with a minor bump.
* Similarly fields that are marked as to be only accessed by *
* av_opt_ptr() can be reordered. This allows 2 forks to add fields * Fields can be accessed through AVOptions, the name string used, matches the
* without breaking compatibility with each other. * C structure field name for fields accessible through AVOptions. The AVClass
* for AVFrame can be obtained from avcodec_get_frame_class()
*/ */
typedef struct AVFrame { typedef struct AVFrame {
#define AV_NUM_DATA_POINTERS 8 #define AV_NUM_DATA_POINTERS 8
@ -188,6 +302,9 @@ typedef struct AVFrame {
* see avcodec_align_dimensions2(). Some filters and swscale can read * see avcodec_align_dimensions2(). Some filters and swscale can read
* up to 16 bytes beyond the planes, if these filters are to be used, * up to 16 bytes beyond the planes, if these filters are to be used,
* then 16 extra bytes must be allocated. * then 16 extra bytes must be allocated.
*
* NOTE: Except for hwaccel formats, pointers not needed by the format
* MUST be set to NULL.
*/ */
uint8_t *data[AV_NUM_DATA_POINTERS]; uint8_t *data[AV_NUM_DATA_POINTERS];
@ -225,9 +342,18 @@ typedef struct AVFrame {
uint8_t **extended_data; uint8_t **extended_data;
/** /**
* width and height of the video frame * @name Video dimensions
* Video frames only. The coded dimensions (in pixels) of the video frame,
* i.e. the size of the rectangle that contains some well-defined values.
*
* @note The part of the frame intended for display/presentation is further
* restricted by the @ref cropping "Cropping rectangle".
* @{
*/ */
int width, height; int width, height;
/**
* @}
*/
/** /**
* number of audio samples (per channel) described by this frame * number of audio samples (per channel) described by this frame
@ -261,10 +387,14 @@ typedef struct AVFrame {
*/ */
int64_t pts; int64_t pts;
#if FF_API_PKT_PTS
/** /**
* PTS copied from the AVPacket that was decoded to produce this frame. * PTS copied from the AVPacket that was decoded to produce this frame.
* @deprecated use the pts field instead
*/ */
attribute_deprecated
int64_t pkt_pts; int64_t pkt_pts;
#endif
/** /**
* DTS copied from the AVPacket that triggered returning this frame. (if frame threading isn't used) * DTS copied from the AVPacket that triggered returning this frame. (if frame threading isn't used)
@ -322,13 +452,12 @@ typedef struct AVFrame {
int palette_has_changed; int palette_has_changed;
/** /**
* reordered opaque 64bit (generally an integer or a double precision float * reordered opaque 64 bits (generally an integer or a double precision float
* PTS but can be anything). * PTS but can be anything).
* The user sets AVCodecContext.reordered_opaque to represent the input at * The user sets AVCodecContext.reordered_opaque to represent the input at
* that time, * that time,
* the decoder reorders values as needed and sets AVFrame.reordered_opaque * the decoder reorders values as needed and sets AVFrame.reordered_opaque
* to exactly one of the values provided by the user through AVCodecContext.reordered_opaque * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
* @deprecated in favor of pkt_pts
*/ */
int64_t reordered_opaque; int64_t reordered_opaque;
@ -379,6 +508,7 @@ typedef struct AVFrame {
/** /**
* @defgroup lavu_frame_flags AV_FRAME_FLAGS * @defgroup lavu_frame_flags AV_FRAME_FLAGS
* @ingroup lavu_frame
* Flags describing additional frame properties. * Flags describing additional frame properties.
* *
* @{ * @{
@ -388,6 +518,10 @@ typedef struct AVFrame {
* The frame data may be corrupted, e.g. due to decoding errors. * The frame data may be corrupted, e.g. due to decoding errors.
*/ */
#define AV_FRAME_FLAG_CORRUPT (1 << 0) #define AV_FRAME_FLAG_CORRUPT (1 << 0)
/**
* A flag to mark the frames which need to be decoded, but shouldn't be output.
*/
#define AV_FRAME_FLAG_DISCARD (1 << 2)
/** /**
* @} * @}
*/ */
@ -399,8 +533,6 @@ typedef struct AVFrame {
/** /**
* MPEG vs JPEG YUV range. * MPEG vs JPEG YUV range.
* It must be accessed using av_frame_get_color_range() and
* av_frame_set_color_range().
* - encoding: Set by user * - encoding: Set by user
* - decoding: Set by libavcodec * - decoding: Set by libavcodec
*/ */
@ -412,8 +544,6 @@ typedef struct AVFrame {
/** /**
* YUV colorspace type. * YUV colorspace type.
* It must be accessed using av_frame_get_colorspace() and
* av_frame_set_colorspace().
* - encoding: Set by user * - encoding: Set by user
* - decoding: Set by libavcodec * - decoding: Set by libavcodec
*/ */
@ -423,8 +553,6 @@ typedef struct AVFrame {
/** /**
* frame timestamp estimated using various heuristics, in stream time base * frame timestamp estimated using various heuristics, in stream time base
* Code outside libavutil should access this field using:
* av_frame_get_best_effort_timestamp(frame)
* - encoding: unused * - encoding: unused
* - decoding: set by libavcodec, read by user. * - decoding: set by libavcodec, read by user.
*/ */
@ -432,8 +560,6 @@ typedef struct AVFrame {
/** /**
* reordered pos from the last AVPacket that has been input into the decoder * reordered pos from the last AVPacket that has been input into the decoder
* Code outside libavutil should access this field using:
* av_frame_get_pkt_pos(frame)
* - encoding: unused * - encoding: unused
* - decoding: Read by user. * - decoding: Read by user.
*/ */
@ -442,8 +568,6 @@ typedef struct AVFrame {
/** /**
* duration of the corresponding packet, expressed in * duration of the corresponding packet, expressed in
* AVStream->time_base units, 0 if unknown. * AVStream->time_base units, 0 if unknown.
* Code outside libavutil should access this field using:
* av_frame_get_pkt_duration(frame)
* - encoding: unused * - encoding: unused
* - decoding: Read by user. * - decoding: Read by user.
*/ */
@ -451,8 +575,6 @@ typedef struct AVFrame {
/** /**
* metadata. * metadata.
* Code outside libavutil should access this field using:
* av_frame_get_metadata(frame)
* - encoding: Set by user. * - encoding: Set by user.
* - decoding: Set by libavcodec. * - decoding: Set by libavcodec.
*/ */
@ -462,19 +584,17 @@ typedef struct AVFrame {
* decode error flags of the frame, set to a combination of * decode error flags of the frame, set to a combination of
* FF_DECODE_ERROR_xxx flags if the decoder produced a frame, but there * FF_DECODE_ERROR_xxx flags if the decoder produced a frame, but there
* were errors during the decoding. * were errors during the decoding.
* Code outside libavutil should access this field using:
* av_frame_get_decode_error_flags(frame)
* - encoding: unused * - encoding: unused
* - decoding: set by libavcodec, read by user. * - decoding: set by libavcodec, read by user.
*/ */
int decode_error_flags; int decode_error_flags;
#define FF_DECODE_ERROR_INVALID_BITSTREAM 1 #define FF_DECODE_ERROR_INVALID_BITSTREAM 1
#define FF_DECODE_ERROR_MISSING_REFERENCE 2 #define FF_DECODE_ERROR_MISSING_REFERENCE 2
#define FF_DECODE_ERROR_CONCEALMENT_ACTIVE 4
#define FF_DECODE_ERROR_DECODE_SLICES 8
/** /**
* number of audio channels, only used for audio. * number of audio channels, only used for audio.
* Code outside libavutil should access this field using:
* av_frame_get_channels(frame)
* - encoding: unused * - encoding: unused
* - decoding: Read by user. * - decoding: Read by user.
*/ */
@ -482,8 +602,7 @@ typedef struct AVFrame {
/** /**
* size of the corresponding packet containing the compressed * size of the corresponding packet containing the compressed
* frame. It must be accessed using av_frame_get_pkt_size() and * frame.
* av_frame_set_pkt_size().
* It is set to a negative value if unknown. * It is set to a negative value if unknown.
* - encoding: unused * - encoding: unused
* - decoding: set by libavcodec, read by user. * - decoding: set by libavcodec, read by user.
@ -493,13 +612,11 @@ typedef struct AVFrame {
#if FF_API_FRAME_QP #if FF_API_FRAME_QP
/** /**
* QP table * QP table
* Not to be accessed directly from outside libavutil
*/ */
attribute_deprecated attribute_deprecated
int8_t *qscale_table; int8_t *qscale_table;
/** /**
* QP store stride * QP store stride
* Not to be accessed directly from outside libavutil
*/ */
attribute_deprecated attribute_deprecated
int qstride; int qstride;
@ -507,45 +624,112 @@ typedef struct AVFrame {
attribute_deprecated attribute_deprecated
int qscale_type; int qscale_type;
/** attribute_deprecated
* Not to be accessed directly from outside libavutil
*/
AVBufferRef *qp_table_buf; AVBufferRef *qp_table_buf;
#endif #endif
/**
* For hwaccel-format frames, this should be a reference to the
* AVHWFramesContext describing the frame.
*/
AVBufferRef *hw_frames_ctx;
/**
* AVBufferRef for free use by the API user. FFmpeg will never check the
* contents of the buffer ref. FFmpeg calls av_buffer_unref() on it when
* the frame is unreferenced. av_frame_copy_props() calls create a new
* reference with av_buffer_ref() for the target frame's opaque_ref field.
*
* This is unrelated to the opaque field, although it serves a similar
* purpose.
*/
AVBufferRef *opaque_ref;
/**
* @anchor cropping
* @name Cropping
* Video frames only. The number of pixels to discard from the the
* top/bottom/left/right border of the frame to obtain the sub-rectangle of
* the frame intended for presentation.
* @{
*/
size_t crop_top;
size_t crop_bottom;
size_t crop_left;
size_t crop_right;
/**
* @}
*/
/**
* AVBufferRef for internal use by a single libav* library.
* Must not be used to transfer data between libraries.
* Has to be NULL when ownership of the frame leaves the respective library.
*
* Code outside the FFmpeg libs should never check or change the contents of the buffer ref.
*
* FFmpeg calls av_buffer_unref() on it when the frame is unreferenced.
* av_frame_copy_props() calls create a new reference with av_buffer_ref()
* for the target frame's private_ref field.
*/
AVBufferRef *private_ref;
} AVFrame; } AVFrame;
#if FF_API_FRAME_GET_SET
/** /**
* Accessors for some AVFrame fields. * Accessors for some AVFrame fields. These used to be provided for ABI
* The position of these field in the structure is not part of the ABI, * compatibility, and do not need to be used anymore.
* they should not be accessed directly outside libavutil.
*/ */
attribute_deprecated
int64_t av_frame_get_best_effort_timestamp(const AVFrame *frame); int64_t av_frame_get_best_effort_timestamp(const AVFrame *frame);
attribute_deprecated
void av_frame_set_best_effort_timestamp(AVFrame *frame, int64_t val); void av_frame_set_best_effort_timestamp(AVFrame *frame, int64_t val);
attribute_deprecated
int64_t av_frame_get_pkt_duration (const AVFrame *frame); int64_t av_frame_get_pkt_duration (const AVFrame *frame);
attribute_deprecated
void av_frame_set_pkt_duration (AVFrame *frame, int64_t val); void av_frame_set_pkt_duration (AVFrame *frame, int64_t val);
attribute_deprecated
int64_t av_frame_get_pkt_pos (const AVFrame *frame); int64_t av_frame_get_pkt_pos (const AVFrame *frame);
attribute_deprecated
void av_frame_set_pkt_pos (AVFrame *frame, int64_t val); void av_frame_set_pkt_pos (AVFrame *frame, int64_t val);
attribute_deprecated
int64_t av_frame_get_channel_layout (const AVFrame *frame); int64_t av_frame_get_channel_layout (const AVFrame *frame);
attribute_deprecated
void av_frame_set_channel_layout (AVFrame *frame, int64_t val); void av_frame_set_channel_layout (AVFrame *frame, int64_t val);
attribute_deprecated
int av_frame_get_channels (const AVFrame *frame); int av_frame_get_channels (const AVFrame *frame);
attribute_deprecated
void av_frame_set_channels (AVFrame *frame, int val); void av_frame_set_channels (AVFrame *frame, int val);
attribute_deprecated
int av_frame_get_sample_rate (const AVFrame *frame); int av_frame_get_sample_rate (const AVFrame *frame);
attribute_deprecated
void av_frame_set_sample_rate (AVFrame *frame, int val); void av_frame_set_sample_rate (AVFrame *frame, int val);
attribute_deprecated
AVDictionary *av_frame_get_metadata (const AVFrame *frame); AVDictionary *av_frame_get_metadata (const AVFrame *frame);
attribute_deprecated
void av_frame_set_metadata (AVFrame *frame, AVDictionary *val); void av_frame_set_metadata (AVFrame *frame, AVDictionary *val);
attribute_deprecated
int av_frame_get_decode_error_flags (const AVFrame *frame); int av_frame_get_decode_error_flags (const AVFrame *frame);
attribute_deprecated
void av_frame_set_decode_error_flags (AVFrame *frame, int val); void av_frame_set_decode_error_flags (AVFrame *frame, int val);
attribute_deprecated
int av_frame_get_pkt_size(const AVFrame *frame); int av_frame_get_pkt_size(const AVFrame *frame);
attribute_deprecated
void av_frame_set_pkt_size(AVFrame *frame, int val); void av_frame_set_pkt_size(AVFrame *frame, int val);
AVDictionary **avpriv_frame_get_metadatap(AVFrame *frame);
#if FF_API_FRAME_QP #if FF_API_FRAME_QP
attribute_deprecated
int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type); int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type);
attribute_deprecated
int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int type); int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int type);
#endif #endif
attribute_deprecated
enum AVColorSpace av_frame_get_colorspace(const AVFrame *frame); enum AVColorSpace av_frame_get_colorspace(const AVFrame *frame);
attribute_deprecated
void av_frame_set_colorspace(AVFrame *frame, enum AVColorSpace val); void av_frame_set_colorspace(AVFrame *frame, enum AVColorSpace val);
attribute_deprecated
enum AVColorRange av_frame_get_color_range(const AVFrame *frame); enum AVColorRange av_frame_get_color_range(const AVFrame *frame);
attribute_deprecated
void av_frame_set_color_range(AVFrame *frame, enum AVColorRange val); void av_frame_set_color_range(AVFrame *frame, enum AVColorRange val);
#endif
/** /**
* Get the name of a colorspace. * Get the name of a colorspace.
@ -583,6 +767,10 @@ void av_frame_free(AVFrame **frame);
* If src is not reference counted, new buffers are allocated and the data is * If src is not reference counted, new buffers are allocated and the data is
* copied. * copied.
* *
* @warning: dst MUST have been either unreferenced with av_frame_unref(dst),
* or newly allocated with av_frame_alloc() before calling this
* function, or undefined behavior will occur.
*
* @return 0 on success, a negative AVERROR on error * @return 0 on success, a negative AVERROR on error
*/ */
int av_frame_ref(AVFrame *dst, const AVFrame *src); int av_frame_ref(AVFrame *dst, const AVFrame *src);
@ -603,6 +791,10 @@ void av_frame_unref(AVFrame *frame);
/** /**
* Move everything contained in src to dst and reset src. * Move everything contained in src to dst and reset src.
*
* @warning: dst is not unreferenced, but directly overwritten without reading
* or deallocating its contents. Call av_frame_unref(dst) manually
* before calling this function to ensure that no memory is leaked.
*/ */
void av_frame_move_ref(AVFrame *dst, AVFrame *src); void av_frame_move_ref(AVFrame *dst, AVFrame *src);
@ -618,8 +810,14 @@ void av_frame_move_ref(AVFrame *dst, AVFrame *src);
* necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf. * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.
* For planar formats, one buffer will be allocated for each plane. * For planar formats, one buffer will be allocated for each plane.
* *
* @warning: if frame already has been allocated, calling this function will
* leak memory. In addition, undefined behavior can occur in certain
* cases.
*
* @param frame frame in which to store the new buffers. * @param frame frame in which to store the new buffers.
* @param align required buffer size alignment * @param align Required buffer size alignment. If equal to 0, alignment will be
* chosen automatically for the current CPU. It is highly
* recommended to pass 0 here unless you know what you are doing.
* *
* @return 0 on success, a negative AVERROR on error. * @return 0 on success, a negative AVERROR on error.
*/ */
@ -698,6 +896,22 @@ AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
enum AVFrameSideDataType type, enum AVFrameSideDataType type,
int size); int size);
/**
* Add a new side data to a frame from an existing AVBufferRef
*
* @param frame a frame to which the side data should be added
* @param type the type of the added side data
* @param buf an AVBufferRef to add as side data. The ownership of
* the reference is transferred to the frame.
*
* @return newly added side data on success, NULL on error. On failure
* the frame is unchanged and the AVBufferRef remains owned by
* the caller.
*/
AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
enum AVFrameSideDataType type,
AVBufferRef *buf);
/** /**
* @return a pointer to the side data of a given type on success, NULL if there * @return a pointer to the side data of a given type on success, NULL if there
* is no side data with such type in this frame. * is no side data with such type in this frame.
@ -711,6 +925,40 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
*/ */
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type); void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);
/**
* Flags for frame cropping.
*/
enum {
/**
* Apply the maximum possible cropping, even if it requires setting the
* AVFrame.data[] entries to unaligned pointers. Passing unaligned data
* to FFmpeg API is generally not allowed, and causes undefined behavior
* (such as crashes). You can pass unaligned data only to FFmpeg APIs that
* are explicitly documented to accept it. Use this flag only if you
* absolutely know what you are doing.
*/
AV_FRAME_CROP_UNALIGNED = 1 << 0,
};
/**
* Crop the given video AVFrame according to its crop_left/crop_top/crop_right/
* crop_bottom fields. If cropping is successful, the function will adjust the
* data pointers and the width/height fields, and set the crop fields to 0.
*
* In all cases, the cropping boundaries will be rounded to the inherent
* alignment of the pixel format. In some cases, such as for opaque hwaccel
* formats, the left/top cropping is ignored. The crop fields are set to 0 even
* if the cropping was rounded or ignored.
*
* @param frame the frame which should be cropped
* @param flags Some combination of AV_FRAME_CROP_* flags, or 0.
*
* @return >= 0 on success, a negative AVERROR on error. If the cropping fields
* were invalid, AVERROR(ERANGE) is returned, and nothing is changed.
*/
int av_frame_apply_cropping(AVFrame *frame, int flags);
/** /**
* @return a string identifying the side data type * @return a string identifying the side data type
*/ */

@ -18,18 +18,110 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* @file
* @ingroup lavu_hash_generic
* Generic hashing API
*/
#ifndef AVUTIL_HASH_H #ifndef AVUTIL_HASH_H
#define AVUTIL_HASH_H #define AVUTIL_HASH_H
#include <stdint.h> #include <stdint.h>
#include "version.h"
/**
* @defgroup lavu_hash Hash Functions
* @ingroup lavu_crypto
* Hash functions useful in multimedia.
*
* Hash functions are widely used in multimedia, from error checking and
* concealment to internal regression testing. libavutil has efficient
* implementations of a variety of hash functions that may be useful for
* FFmpeg and other multimedia applications.
*
* @{
*
* @defgroup lavu_hash_generic Generic Hashing API
* An abstraction layer for all hash functions supported by libavutil.
*
* If your application needs to support a wide range of different hash
* functions, then the Generic Hashing API is for you. It provides a generic,
* reusable API for @ref lavu_hash "all hash functions" implemented in libavutil.
* If you just need to use one particular hash function, use the @ref lavu_hash
* "individual hash" directly.
*
* @section Sample Code
*
* A basic template for using the Generic Hashing API follows:
*
* @code
* struct AVHashContext *ctx = NULL;
* const char *hash_name = NULL;
* uint8_t *output_buf = NULL;
*
* // Select from a string returned by av_hash_names()
* hash_name = ...;
*
* // Allocate a hash context
* ret = av_hash_alloc(&ctx, hash_name);
* if (ret < 0)
* return ret;
*
* // Initialize the hash context
* av_hash_init(ctx);
*
* // Update the hash context with data
* while (data_left) {
* av_hash_update(ctx, data, size);
* }
*
* // Now we have no more data, so it is time to finalize the hash and get the
* // output. But we need to first allocate an output buffer. Note that you can
* // use any memory allocation function, including malloc(), not just
* // av_malloc().
* output_buf = av_malloc(av_hash_get_size(ctx));
* if (!output_buf)
* return AVERROR(ENOMEM);
*
* // Finalize the hash context.
* // You can use any of the av_hash_final*() functions provided, for other
* // output formats. If you do so, be sure to adjust the memory allocation
* // above. See the function documentation below for the exact amount of extra
* // memory needed.
* av_hash_final(ctx, output_buffer);
*
* // Free the context
* av_hash_freep(&ctx);
* @endcode
*
* @section Hash Function-Specific Information
* If the CRC32 hash is selected, the #AV_CRC_32_IEEE polynomial will be
* used.
*
* If the Murmur3 hash is selected, the default seed will be used. See @ref
* lavu_murmur3_seedinfo "Murmur3" for more information.
*
* @{
*/
/**
* @example ffhash.c
* This example is a simple command line application that takes one or more
* arguments. It demonstrates a typical use of the hashing API with allocation,
* initialization, updating, and finalizing.
*/
struct AVHashContext; struct AVHashContext;
/** /**
* Allocate a hash context for the algorithm specified by name. * Allocate a hash context for the algorithm specified by name.
* *
* @return >= 0 for success, a negative error code for failure * @return >= 0 for success, a negative error code for failure
* @note The context is not initialized, you must call av_hash_init(). *
* @note The context is not initialized after a call to this function; you must
* call av_hash_init() to do so.
*/ */
int av_hash_alloc(struct AVHashContext **ctx, const char *name); int av_hash_alloc(struct AVHashContext **ctx, const char *name);
@ -38,8 +130,8 @@ int av_hash_alloc(struct AVHashContext **ctx, const char *name);
* *
* This function can be used to enumerate the algorithms. * This function can be used to enumerate the algorithms.
* *
* @param i index of the hash algorithm, starting from 0 * @param[in] i Index of the hash algorithm, starting from 0
* @return a pointer to a static string or NULL if i is out of range * @return Pointer to a static string or `NULL` if `i` is out of range
*/ */
const char *av_hash_names(int i); const char *av_hash_names(int i);
@ -49,64 +141,129 @@ const char *av_hash_names(int i);
const char *av_hash_get_name(const struct AVHashContext *ctx); const char *av_hash_get_name(const struct AVHashContext *ctx);
/** /**
* Maximum value that av_hash_get_size will currently return. * Maximum value that av_hash_get_size() will currently return.
* *
* You can use this if you absolutely want or need to use static allocation * You can use this if you absolutely want or need to use static allocation for
* and are fine with not supporting hashes newly added to libavutil without * the output buffer and are fine with not supporting hashes newly added to
* recompilation. * libavutil without recompilation.
* Note that you still need to check against av_hash_get_size, adding new hashes *
* with larger sizes will not be considered an ABI change and should not cause * @warning
* your code to overflow a buffer. * Adding new hashes with larger sizes, and increasing the macro while doing
* so, will not be considered an ABI change. To prevent your code from
* overflowing a buffer, either dynamically allocate the output buffer with
* av_hash_get_size(), or limit your use of the Hashing API to hashes that are
* already in FFmpeg during the time of compilation.
*/ */
#define AV_HASH_MAX_SIZE 64 #define AV_HASH_MAX_SIZE 64
/** /**
* Get the size of the resulting hash value in bytes. * Get the size of the resulting hash value in bytes.
* *
* The pointer passed to av_hash_final have space for at least this many bytes. * The maximum value this function will currently return is available as macro
* #AV_HASH_MAX_SIZE.
*
* @param[in] ctx Hash context
* @return Size of the hash value in bytes
*/ */
int av_hash_get_size(const struct AVHashContext *ctx); int av_hash_get_size(const struct AVHashContext *ctx);
/** /**
* Initialize or reset a hash context. * Initialize or reset a hash context.
*
* @param[in,out] ctx Hash context
*/ */
void av_hash_init(struct AVHashContext *ctx); void av_hash_init(struct AVHashContext *ctx);
/** /**
* Update a hash context with additional data. * Update a hash context with additional data.
*
* @param[in,out] ctx Hash context
* @param[in] src Data to be added to the hash context
* @param[in] len Size of the additional data
*/ */
#if FF_API_CRYPTO_SIZE_T
void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, int len); void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, int len);
#else
void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, size_t len);
#endif
/** /**
* Finalize a hash context and compute the actual hash value. * Finalize a hash context and compute the actual hash value.
*
* The minimum size of `dst` buffer is given by av_hash_get_size() or
* #AV_HASH_MAX_SIZE. The use of the latter macro is discouraged.
*
* It is not safe to update or finalize a hash context again, if it has already
* been finalized.
*
* @param[in,out] ctx Hash context
* @param[out] dst Where the final hash value will be stored
*
* @see av_hash_final_bin() provides an alternative API
*/ */
void av_hash_final(struct AVHashContext *ctx, uint8_t *dst); void av_hash_final(struct AVHashContext *ctx, uint8_t *dst);
/** /**
* Finalize a hash context and compute the actual hash value. * Finalize a hash context and store the actual hash value in a buffer.
* If size is smaller than the hash size, the hash is truncated; *
* if size is larger, the buffer is padded with 0. * It is not safe to update or finalize a hash context again, if it has already
* been finalized.
*
* If `size` is smaller than the hash size (given by av_hash_get_size()), the
* hash is truncated; if size is larger, the buffer is padded with 0.
*
* @param[in,out] ctx Hash context
* @param[out] dst Where the final hash value will be stored
* @param[in] size Number of bytes to write to `dst`
*/ */
void av_hash_final_bin(struct AVHashContext *ctx, uint8_t *dst, int size); void av_hash_final_bin(struct AVHashContext *ctx, uint8_t *dst, int size);
/** /**
* Finalize a hash context and compute the actual hash value as a hex string. * Finalize a hash context and store the hexadecimal representation of the
* actual hash value as a string.
*
* It is not safe to update or finalize a hash context again, if it has already
* been finalized.
*
* The string is always 0-terminated. * The string is always 0-terminated.
* If size is smaller than 2 * hash_size + 1, the hex string is truncated. *
* If `size` is smaller than `2 * hash_size + 1`, where `hash_size` is the
* value returned by av_hash_get_size(), the string will be truncated.
*
* @param[in,out] ctx Hash context
* @param[out] dst Where the string will be stored
* @param[in] size Maximum number of bytes to write to `dst`
*/ */
void av_hash_final_hex(struct AVHashContext *ctx, uint8_t *dst, int size); void av_hash_final_hex(struct AVHashContext *ctx, uint8_t *dst, int size);
/** /**
* Finalize a hash context and compute the actual hash value as a base64 string. * Finalize a hash context and store the Base64 representation of the
* actual hash value as a string.
*
* It is not safe to update or finalize a hash context again, if it has already
* been finalized.
*
* The string is always 0-terminated. * The string is always 0-terminated.
* If size is smaller than AV_BASE64_SIZE(hash_size), the base64 string is *
* truncated. * If `size` is smaller than AV_BASE64_SIZE(hash_size), where `hash_size` is
* the value returned by av_hash_get_size(), the string will be truncated.
*
* @param[in,out] ctx Hash context
* @param[out] dst Where the final hash value will be stored
* @param[in] size Maximum number of bytes to write to `dst`
*/ */
void av_hash_final_b64(struct AVHashContext *ctx, uint8_t *dst, int size); void av_hash_final_b64(struct AVHashContext *ctx, uint8_t *dst, int size);
/** /**
* Free hash context. * Free hash context and set hash context pointer to `NULL`.
*
* @param[in,out] ctx Pointer to hash context
*/ */
void av_hash_freep(struct AVHashContext **ctx); void av_hash_freep(struct AVHashContext **ctx);
/**
* @}
* @}
*/
#endif /* AVUTIL_HASH_H */ #endif /* AVUTIL_HASH_H */

@ -0,0 +1,343 @@
/*
* Copyright (c) 2018 Mohammad Izadi <moh.izadi at gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVUTIL_HDR_DYNAMIC_METADATA_H
#define AVUTIL_HDR_DYNAMIC_METADATA_H
#include "frame.h"
#include "rational.h"
/**
* Option for overlapping elliptical pixel selectors in an image.
*/
enum AVHDRPlusOverlapProcessOption {
AV_HDR_PLUS_OVERLAP_PROCESS_WEIGHTED_AVERAGING = 0,
AV_HDR_PLUS_OVERLAP_PROCESS_LAYERING = 1,
};
/**
* Represents the percentile at a specific percentage in
* a distribution.
*/
typedef struct AVHDRPlusPercentile {
/**
* The percentage value corresponding to a specific percentile linearized
* RGB value in the processing window in the scene. The value shall be in
* the range of 0 to100, inclusive.
*/
uint8_t percentage;
/**
* The linearized maxRGB value at a specific percentile in the processing
* window in the scene. The value shall be in the range of 0 to 1, inclusive
* and in multiples of 0.00001.
*/
AVRational percentile;
} AVHDRPlusPercentile;
/**
* Color transform parameters at a processing window in a dynamic metadata for
* SMPTE 2094-40.
*/
typedef struct AVHDRPlusColorTransformParams {
/**
* The relative x coordinate of the top left pixel of the processing
* window. The value shall be in the range of 0 and 1, inclusive and
* in multiples of 1/(width of Picture - 1). The value 1 corresponds
* to the absolute coordinate of width of Picture - 1. The value for
* first processing window shall be 0.
*/
AVRational window_upper_left_corner_x;
/**
* The relative y coordinate of the top left pixel of the processing
* window. The value shall be in the range of 0 and 1, inclusive and
* in multiples of 1/(height of Picture - 1). The value 1 corresponds
* to the absolute coordinate of height of Picture - 1. The value for
* first processing window shall be 0.
*/
AVRational window_upper_left_corner_y;
/**
* The relative x coordinate of the bottom right pixel of the processing
* window. The value shall be in the range of 0 and 1, inclusive and
* in multiples of 1/(width of Picture - 1). The value 1 corresponds
* to the absolute coordinate of width of Picture - 1. The value for
* first processing window shall be 1.
*/
AVRational window_lower_right_corner_x;
/**
* The relative y coordinate of the bottom right pixel of the processing
* window. The value shall be in the range of 0 and 1, inclusive and
* in multiples of 1/(height of Picture - 1). The value 1 corresponds
* to the absolute coordinate of height of Picture - 1. The value for
* first processing window shall be 1.
*/
AVRational window_lower_right_corner_y;
/**
* The x coordinate of the center position of the concentric internal and
* external ellipses of the elliptical pixel selector in the processing
* window. The value shall be in the range of 0 to (width of Picture - 1),
* inclusive and in multiples of 1 pixel.
*/
uint16_t center_of_ellipse_x;
/**
* The y coordinate of the center position of the concentric internal and
* external ellipses of the elliptical pixel selector in the processing
* window. The value shall be in the range of 0 to (height of Picture - 1),
* inclusive and in multiples of 1 pixel.
*/
uint16_t center_of_ellipse_y;
/**
* The clockwise rotation angle in degree of arc with respect to the
* positive direction of the x-axis of the concentric internal and external
* ellipses of the elliptical pixel selector in the processing window. The
* value shall be in the range of 0 to 180, inclusive and in multiples of 1.
*/
uint8_t rotation_angle;
/**
* The semi-major axis value of the internal ellipse of the elliptical pixel
* selector in amount of pixels in the processing window. The value shall be
* in the range of 1 to 65535, inclusive and in multiples of 1 pixel.
*/
uint16_t semimajor_axis_internal_ellipse;
/**
* The semi-major axis value of the external ellipse of the elliptical pixel
* selector in amount of pixels in the processing window. The value
* shall not be less than semimajor_axis_internal_ellipse of the current
* processing window. The value shall be in the range of 1 to 65535,
* inclusive and in multiples of 1 pixel.
*/
uint16_t semimajor_axis_external_ellipse;
/**
* The semi-minor axis value of the external ellipse of the elliptical pixel
* selector in amount of pixels in the processing window. The value shall be
* in the range of 1 to 65535, inclusive and in multiples of 1 pixel.
*/
uint16_t semiminor_axis_external_ellipse;
/**
* Overlap process option indicates one of the two methods of combining
* rendered pixels in the processing window in an image with at least one
* elliptical pixel selector. For overlapping elliptical pixel selectors
* in an image, overlap_process_option shall have the same value.
*/
enum AVHDRPlusOverlapProcessOption overlap_process_option;
/**
* The maximum of the color components of linearized RGB values in the
* processing window in the scene. The values should be in the range of 0 to
* 1, inclusive and in multiples of 0.00001. maxscl[ 0 ], maxscl[ 1 ], and
* maxscl[ 2 ] are corresponding to R, G, B color components respectively.
*/
AVRational maxscl[3];
/**
* The average of linearized maxRGB values in the processing window in the
* scene. The value should be in the range of 0 to 1, inclusive and in
* multiples of 0.00001.
*/
AVRational average_maxrgb;
/**
* The number of linearized maxRGB values at given percentiles in the
* processing window in the scene. The maximum value shall be 15.
*/
uint8_t num_distribution_maxrgb_percentiles;
/**
* The linearized maxRGB values at given percentiles in the
* processing window in the scene.
*/
AVHDRPlusPercentile distribution_maxrgb[15];
/**
* The fraction of selected pixels in the image that contains the brightest
* pixel in the scene. The value shall be in the range of 0 to 1, inclusive
* and in multiples of 0.001.
*/
AVRational fraction_bright_pixels;
/**
* This flag indicates that the metadata for the tone mapping function in
* the processing window is present (for value of 1).
*/
uint8_t tone_mapping_flag;
/**
* The x coordinate of the separation point between the linear part and the
* curved part of the tone mapping function. The value shall be in the range
* of 0 to 1, excluding 0 and in multiples of 1/4095.
*/
AVRational knee_point_x;
/**
* The y coordinate of the separation point between the linear part and the
* curved part of the tone mapping function. The value shall be in the range
* of 0 to 1, excluding 0 and in multiples of 1/4095.
*/
AVRational knee_point_y;
/**
* The number of the intermediate anchor parameters of the tone mapping
* function in the processing window. The maximum value shall be 15.
*/
uint8_t num_bezier_curve_anchors;
/**
* The intermediate anchor parameters of the tone mapping function in the
* processing window in the scene. The values should be in the range of 0
* to 1, inclusive and in multiples of 1/1023.
*/
AVRational bezier_curve_anchors[15];
/**
* This flag shall be equal to 0 in bitstreams conforming to this version of
* this Specification. Other values are reserved for future use.
*/
uint8_t color_saturation_mapping_flag;
/**
* The color saturation gain in the processing window in the scene. The
* value shall be in the range of 0 to 63/8, inclusive and in multiples of
* 1/8. The default value shall be 1.
*/
AVRational color_saturation_weight;
} AVHDRPlusColorTransformParams;
/**
* This struct represents dynamic metadata for color volume transform -
* application 4 of SMPTE 2094-40:2016 standard.
*
* To be used as payload of a AVFrameSideData or AVPacketSideData with the
* appropriate type.
*
* @note The struct should be allocated with
* av_dynamic_hdr_plus_alloc() and its size is not a part of
* the public ABI.
*/
typedef struct AVDynamicHDRPlus {
/**
* Country code by Rec. ITU-T T.35 Annex A. The value shall be 0xB5.
*/
uint8_t itu_t_t35_country_code;
/**
* Application version in the application defining document in ST-2094
* suite. The value shall be set to 0.
*/
uint8_t application_version;
/**
* The number of processing windows. The value shall be in the range
* of 1 to 3, inclusive.
*/
uint8_t num_windows;
/**
* The color transform parameters for every processing window.
*/
AVHDRPlusColorTransformParams params[3];
/**
* The nominal maximum display luminance of the targeted system display,
* in units of 0.0001 candelas per square metre. The value shall be in
* the range of 0 to 10000, inclusive.
*/
AVRational targeted_system_display_maximum_luminance;
/**
* This flag shall be equal to 0 in bit streams conforming to this version
* of this Specification. The value 1 is reserved for future use.
*/
uint8_t targeted_system_display_actual_peak_luminance_flag;
/**
* The number of rows in the targeted system_display_actual_peak_luminance
* array. The value shall be in the range of 2 to 25, inclusive.
*/
uint8_t num_rows_targeted_system_display_actual_peak_luminance;
/**
* The number of columns in the
* targeted_system_display_actual_peak_luminance array. The value shall be
* in the range of 2 to 25, inclusive.
*/
uint8_t num_cols_targeted_system_display_actual_peak_luminance;
/**
* The normalized actual peak luminance of the targeted system display. The
* values should be in the range of 0 to 1, inclusive and in multiples of
* 1/15.
*/
AVRational targeted_system_display_actual_peak_luminance[25][25];
/**
* This flag shall be equal to 0 in bitstreams conforming to this version of
* this Specification. The value 1 is reserved for future use.
*/
uint8_t mastering_display_actual_peak_luminance_flag;
/**
* The number of rows in the mastering_display_actual_peak_luminance array.
* The value shall be in the range of 2 to 25, inclusive.
*/
uint8_t num_rows_mastering_display_actual_peak_luminance;
/**
* The number of columns in the mastering_display_actual_peak_luminance
* array. The value shall be in the range of 2 to 25, inclusive.
*/
uint8_t num_cols_mastering_display_actual_peak_luminance;
/**
* The normalized actual peak luminance of the mastering display used for
* mastering the image essence. The values should be in the range of 0 to 1,
* inclusive and in multiples of 1/15.
*/
AVRational mastering_display_actual_peak_luminance[25][25];
} AVDynamicHDRPlus;
/**
* Allocate an AVDynamicHDRPlus structure and set its fields to
* default values. The resulting struct can be freed using av_freep().
*
* @return An AVDynamicHDRPlus filled with default values or NULL
* on failure.
*/
AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size);
/**
* Allocate a complete AVDynamicHDRPlus and add it to the frame.
* @param frame The frame which side data is added to.
*
* @return The AVDynamicHDRPlus structure to be filled by caller or NULL
* on failure.
*/
AVDynamicHDRPlus *av_dynamic_hdr_plus_create_side_data(AVFrame *frame);
#endif /* AVUTIL_HDR_DYNAMIC_METADATA_H */

@ -35,7 +35,7 @@ enum AVHMACType {
AV_HMAC_SHA1, AV_HMAC_SHA1,
AV_HMAC_SHA224, AV_HMAC_SHA224,
AV_HMAC_SHA256, AV_HMAC_SHA256,
AV_HMAC_SHA384 = 12, AV_HMAC_SHA384,
AV_HMAC_SHA512, AV_HMAC_SHA512,
}; };

@ -25,11 +25,17 @@
#include "pixfmt.h" #include "pixfmt.h"
enum AVHWDeviceType { enum AVHWDeviceType {
AV_HWDEVICE_TYPE_NONE,
AV_HWDEVICE_TYPE_VDPAU, AV_HWDEVICE_TYPE_VDPAU,
AV_HWDEVICE_TYPE_CUDA, AV_HWDEVICE_TYPE_CUDA,
AV_HWDEVICE_TYPE_VAAPI, AV_HWDEVICE_TYPE_VAAPI,
AV_HWDEVICE_TYPE_DXVA2, AV_HWDEVICE_TYPE_DXVA2,
AV_HWDEVICE_TYPE_QSV, AV_HWDEVICE_TYPE_QSV,
AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
AV_HWDEVICE_TYPE_D3D11VA,
AV_HWDEVICE_TYPE_DRM,
AV_HWDEVICE_TYPE_OPENCL,
AV_HWDEVICE_TYPE_MEDIACODEC,
}; };
typedef struct AVHWDeviceInternal AVHWDeviceInternal; typedef struct AVHWDeviceInternal AVHWDeviceInternal;
@ -223,10 +229,36 @@ typedef struct AVHWFramesContext {
} AVHWFramesContext; } AVHWFramesContext;
/** /**
* Allocate an AVHWDeviceContext for a given pixel format. * Look up an AVHWDeviceType by name.
* *
* @param format a hwaccel pixel format (AV_PIX_FMT_FLAG_HWACCEL must be set * @param name String name of the device type (case-insensitive).
* on the corresponding format descriptor) * @return The type from enum AVHWDeviceType, or AV_HWDEVICE_TYPE_NONE if
* not found.
*/
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name);
/** Get the string name of an AVHWDeviceType.
*
* @param type Type from enum AVHWDeviceType.
* @return Pointer to a static string containing the name, or NULL if the type
* is not valid.
*/
const char *av_hwdevice_get_type_name(enum AVHWDeviceType type);
/**
* Iterate over supported device types.
*
* @param type AV_HWDEVICE_TYPE_NONE initially, then the previous type
* returned by this function in subsequent iterations.
* @return The next usable device type from enum AVHWDeviceType, or
* AV_HWDEVICE_TYPE_NONE if there are no more.
*/
enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev);
/**
* Allocate an AVHWDeviceContext for a given hardware type.
*
* @param type the type of the hardware device to allocate.
* @return a reference to the newly created AVHWDeviceContext on success or NULL * @return a reference to the newly created AVHWDeviceContext on success or NULL
* on failure. * on failure.
*/ */
@ -270,6 +302,32 @@ int av_hwdevice_ctx_init(AVBufferRef *ref);
int av_hwdevice_ctx_create(AVBufferRef **device_ctx, enum AVHWDeviceType type, int av_hwdevice_ctx_create(AVBufferRef **device_ctx, enum AVHWDeviceType type,
const char *device, AVDictionary *opts, int flags); const char *device, AVDictionary *opts, int flags);
/**
* Create a new device of the specified type from an existing device.
*
* If the source device is a device of the target type or was originally
* derived from such a device (possibly through one or more intermediate
* devices of other types), then this will return a reference to the
* existing device of the same type as is requested.
*
* Otherwise, it will attempt to derive a new device from the given source
* device. If direct derivation to the new type is not implemented, it will
* attempt the same derivation from each ancestor of the source device in
* turn looking for an implemented derivation method.
*
* @param dst_ctx On success, a reference to the newly-created
* AVHWDeviceContext.
* @param type The type of the new device to create.
* @param src_ctx A reference to an existing AVHWDeviceContext which will be
* used to create the new device.
* @param flags Currently unused; should be set to zero.
* @return Zero on success, a negative AVERROR code on failure.
*/
int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ctx,
enum AVHWDeviceType type,
AVBufferRef *src_ctx, int flags);
/** /**
* Allocate an AVHWFramesContext tied to a given device context. * Allocate an AVHWFramesContext tied to a given device context.
* *
@ -318,6 +376,14 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ctx, AVFrame *frame, int flags);
* If dst->format is set, then this format will be used, otherwise (when * If dst->format is set, then this format will be used, otherwise (when
* dst->format is AV_PIX_FMT_NONE) the first acceptable format will be chosen. * dst->format is AV_PIX_FMT_NONE) the first acceptable format will be chosen.
* *
* The two frames must have matching allocated dimensions (i.e. equal to
* AVHWFramesContext.width/height), since not all device types support
* transferring a sub-rectangle of the whole surface. The display dimensions
* (i.e. AVFrame.width/height) may be smaller than the allocated dimensions, but
* also have to be equal for both frames. When the display dimensions are
* smaller than the allocated dimensions, the content of the padding in the
* destination frame is unspecified.
*
* @param dst the destination frame. dst is not touched on failure. * @param dst the destination frame. dst is not touched on failure.
* @param src the source frame. * @param src the source frame.
* @param flags currently unused, should be set to zero * @param flags currently unused, should be set to zero
@ -410,7 +476,7 @@ void *av_hwdevice_hwconfig_alloc(AVBufferRef *device_ctx);
* configuration is provided, returns the maximum possible capabilities * configuration is provided, returns the maximum possible capabilities
* of the device. * of the device.
* *
* @param device_ctx a reference to the associated AVHWDeviceContext. * @param ref a reference to the associated AVHWDeviceContext.
* @param hwconfig a filled HW-specific configuration structure, or NULL * @param hwconfig a filled HW-specific configuration structure, or NULL
* to return the maximum possible capabilities of the device. * to return the maximum possible capabilities of the device.
* @return AVHWFramesConstraints structure describing the constraints * @return AVHWFramesConstraints structure describing the constraints
@ -426,4 +492,93 @@ AVHWFramesConstraints *av_hwdevice_get_hwframe_constraints(AVBufferRef *ref,
*/ */
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints); void av_hwframe_constraints_free(AVHWFramesConstraints **constraints);
/**
* Flags to apply to frame mappings.
*/
enum {
/**
* The mapping must be readable.
*/
AV_HWFRAME_MAP_READ = 1 << 0,
/**
* The mapping must be writeable.
*/
AV_HWFRAME_MAP_WRITE = 1 << 1,
/**
* The mapped frame will be overwritten completely in subsequent
* operations, so the current frame data need not be loaded. Any values
* which are not overwritten are unspecified.
*/
AV_HWFRAME_MAP_OVERWRITE = 1 << 2,
/**
* The mapping must be direct. That is, there must not be any copying in
* the map or unmap steps. Note that performance of direct mappings may
* be much lower than normal memory.
*/
AV_HWFRAME_MAP_DIRECT = 1 << 3,
};
/**
* Map a hardware frame.
*
* This has a number of different possible effects, depending on the format
* and origin of the src and dst frames. On input, src should be a usable
* frame with valid buffers and dst should be blank (typically as just created
* by av_frame_alloc()). src should have an associated hwframe context, and
* dst may optionally have a format and associated hwframe context.
*
* If src was created by mapping a frame from the hwframe context of dst,
* then this function undoes the mapping - dst is replaced by a reference to
* the frame that src was originally mapped from.
*
* If both src and dst have an associated hwframe context, then this function
* attempts to map the src frame from its hardware context to that of dst and
* then fill dst with appropriate data to be usable there. This will only be
* possible if the hwframe contexts and associated devices are compatible -
* given compatible devices, av_hwframe_ctx_create_derived() can be used to
* create a hwframe context for dst in which mapping should be possible.
*
* If src has a hwframe context but dst does not, then the src frame is
* mapped to normal memory and should thereafter be usable as a normal frame.
* If the format is set on dst, then the mapping will attempt to create dst
* with that format and fail if it is not possible. If format is unset (is
* AV_PIX_FMT_NONE) then dst will be mapped with whatever the most appropriate
* format to use is (probably the sw_format of the src hwframe context).
*
* A return value of AVERROR(ENOSYS) indicates that the mapping is not
* possible with the given arguments and hwframe setup, while other return
* values indicate that it failed somehow.
*
* @param dst Destination frame, to contain the mapping.
* @param src Source frame, to be mapped.
* @param flags Some combination of AV_HWFRAME_MAP_* flags.
* @return Zero on success, negative AVERROR code on failure.
*/
int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags);
/**
* Create and initialise an AVHWFramesContext as a mapping of another existing
* AVHWFramesContext on a different device.
*
* av_hwframe_ctx_init() should not be called after this.
*
* @param derived_frame_ctx On success, a reference to the newly created
* AVHWFramesContext.
* @param derived_device_ctx A reference to the device to create the new
* AVHWFramesContext on.
* @param source_frame_ctx A reference to an existing AVHWFramesContext
* which will be mapped to the derived context.
* @param flags Some combination of AV_HWFRAME_MAP_* flags, defining the
* mapping parameters to apply to frames which are allocated
* in the derived device.
* @return Zero on success, negative AVERROR code on failure.
*/
int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
enum AVPixelFormat format,
AVBufferRef *derived_device_ctx,
AVBufferRef *source_frame_ctx,
int flags);
#endif /* AVUTIL_HWCONTEXT_H */ #endif /* AVUTIL_HWCONTEXT_H */

@ -20,7 +20,9 @@
#ifndef AVUTIL_HWCONTEXT_CUDA_H #ifndef AVUTIL_HWCONTEXT_CUDA_H
#define AVUTIL_HWCONTEXT_CUDA_H #define AVUTIL_HWCONTEXT_CUDA_H
#ifndef CUDA_VERSION
#include <cuda.h> #include <cuda.h>
#endif
#include "pixfmt.h" #include "pixfmt.h"
@ -32,11 +34,15 @@
* AVBufferRefs whose data pointer is a CUdeviceptr. * AVBufferRefs whose data pointer is a CUdeviceptr.
*/ */
typedef struct AVCUDADeviceContextInternal AVCUDADeviceContextInternal;
/** /**
* This struct is allocated as AVHWDeviceContext.hwctx * This struct is allocated as AVHWDeviceContext.hwctx
*/ */
typedef struct AVCUDADeviceContext { typedef struct AVCUDADeviceContext {
CUcontext cuda_ctx; CUcontext cuda_ctx;
CUstream stream;
AVCUDADeviceContextInternal *internal;
} AVCUDADeviceContext; } AVCUDADeviceContext;
/** /**

@ -0,0 +1,169 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVUTIL_HWCONTEXT_D3D11VA_H
#define AVUTIL_HWCONTEXT_D3D11VA_H
/**
* @file
* An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
*
* The default pool implementation will be fixed-size if initial_pool_size is
* set (and allocate elements from an array texture). Otherwise it will allocate
* individual textures. Be aware that decoding requires a single array texture.
*
* Using sw_format==AV_PIX_FMT_YUV420P has special semantics, and maps to
* DXGI_FORMAT_420_OPAQUE. av_hwframe_transfer_data() is not supported for
* this format. Refer to MSDN for details.
*
* av_hwdevice_ctx_create() for this device type supports a key named "debug"
* for the AVDictionary entry. If this is set to any value, the device creation
* code will try to load various supported D3D debugging layers.
*/
#include <d3d11.h>
#include <stdint.h>
/**
* This struct is allocated as AVHWDeviceContext.hwctx
*/
typedef struct AVD3D11VADeviceContext {
/**
* Device used for texture creation and access. This can also be used to
* set the libavcodec decoding device.
*
* Must be set by the user. This is the only mandatory field - the other
* device context fields are set from this and are available for convenience.
*
* Deallocating the AVHWDeviceContext will always release this interface,
* and it does not matter whether it was user-allocated.
*/
ID3D11Device *device;
/**
* If unset, this will be set from the device field on init.
*
* Deallocating the AVHWDeviceContext will always release this interface,
* and it does not matter whether it was user-allocated.
*/
ID3D11DeviceContext *device_context;
/**
* If unset, this will be set from the device field on init.
*
* Deallocating the AVHWDeviceContext will always release this interface,
* and it does not matter whether it was user-allocated.
*/
ID3D11VideoDevice *video_device;
/**
* If unset, this will be set from the device_context field on init.
*
* Deallocating the AVHWDeviceContext will always release this interface,
* and it does not matter whether it was user-allocated.
*/
ID3D11VideoContext *video_context;
/**
* Callbacks for locking. They protect accesses to device_context and
* video_context calls. They also protect access to the internal staging
* texture (for av_hwframe_transfer_data() calls). They do NOT protect
* access to hwcontext or decoder state in general.
*
* If unset on init, the hwcontext implementation will set them to use an
* internal mutex.
*
* The underlying lock must be recursive. lock_ctx is for free use by the
* locking implementation.
*/
void (*lock)(void *lock_ctx);
void (*unlock)(void *lock_ctx);
void *lock_ctx;
} AVD3D11VADeviceContext;
/**
* D3D11 frame descriptor for pool allocation.
*
* In user-allocated pools, AVHWFramesContext.pool must return AVBufferRefs
* with the data pointer pointing at an object of this type describing the
* planes of the frame.
*
* This has no use outside of custom allocation, and AVFrame AVBufferRef do not
* necessarily point to an instance of this struct.
*/
typedef struct AVD3D11FrameDescriptor {
/**
* The texture in which the frame is located. The reference count is
* managed by the AVBufferRef, and destroying the reference will release
* the interface.
*
* Normally stored in AVFrame.data[0].
*/
ID3D11Texture2D *texture;
/**
* The index into the array texture element representing the frame, or 0
* if the texture is not an array texture.
*
* Normally stored in AVFrame.data[1] (cast from intptr_t).
*/
intptr_t index;
} AVD3D11FrameDescriptor;
/**
* This struct is allocated as AVHWFramesContext.hwctx
*/
typedef struct AVD3D11VAFramesContext {
/**
* The canonical texture used for pool allocation. If this is set to NULL
* on init, the hwframes implementation will allocate and set an array
* texture if initial_pool_size > 0.
*
* The only situation when the API user should set this is:
* - the user wants to do manual pool allocation (setting
* AVHWFramesContext.pool), instead of letting AVHWFramesContext
* allocate the pool
* - of an array texture
* - and wants it to use it for decoding
* - this has to be done before calling av_hwframe_ctx_init()
*
* Deallocating the AVHWFramesContext will always release this interface,
* and it does not matter whether it was user-allocated.
*
* This is in particular used by the libavcodec D3D11VA hwaccel, which
* requires a single array texture. It will create ID3D11VideoDecoderOutputView
* objects for each array texture element on decoder initialization.
*/
ID3D11Texture2D *texture;
/**
* D3D11_TEXTURE2D_DESC.BindFlags used for texture creation. The user must
* at least set D3D11_BIND_DECODER if the frames context is to be used for
* video decoding.
* This field is ignored/invalid if a user-allocated texture is provided.
*/
UINT BindFlags;
/**
* D3D11_TEXTURE2D_DESC.MiscFlags used for texture creation.
* This field is ignored/invalid if a user-allocated texture is provided.
*/
UINT MiscFlags;
} AVD3D11VAFramesContext;
#endif /* AVUTIL_HWCONTEXT_D3D11VA_H */

@ -0,0 +1,169 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVUTIL_HWCONTEXT_DRM_H
#define AVUTIL_HWCONTEXT_DRM_H
#include <stddef.h>
#include <stdint.h>
/**
* @file
* API-specific header for AV_HWDEVICE_TYPE_DRM.
*
* Internal frame allocation is not currently supported - all frames
* must be allocated by the user. Thus AVHWFramesContext is always
* NULL, though this may change if support for frame allocation is
* added in future.
*/
enum {
/**
* The maximum number of layers/planes in a DRM frame.
*/
AV_DRM_MAX_PLANES = 4
};
/**
* DRM object descriptor.
*
* Describes a single DRM object, addressing it as a PRIME file
* descriptor.
*/
typedef struct AVDRMObjectDescriptor {
/**
* DRM PRIME fd for the object.
*/
int fd;
/**
* Total size of the object.
*
* (This includes any parts not which do not contain image data.)
*/
size_t size;
/**
* Format modifier applied to the object (DRM_FORMAT_MOD_*).
*
* If the format modifier is unknown then this should be set to
* DRM_FORMAT_MOD_INVALID.
*/
uint64_t format_modifier;
} AVDRMObjectDescriptor;
/**
* DRM plane descriptor.
*
* Describes a single plane of a layer, which is contained within
* a single object.
*/
typedef struct AVDRMPlaneDescriptor {
/**
* Index of the object containing this plane in the objects
* array of the enclosing frame descriptor.
*/
int object_index;
/**
* Offset within that object of this plane.
*/
ptrdiff_t offset;
/**
* Pitch (linesize) of this plane.
*/
ptrdiff_t pitch;
} AVDRMPlaneDescriptor;
/**
* DRM layer descriptor.
*
* Describes a single layer within a frame. This has the structure
* defined by its format, and will contain one or more planes.
*/
typedef struct AVDRMLayerDescriptor {
/**
* Format of the layer (DRM_FORMAT_*).
*/
uint32_t format;
/**
* Number of planes in the layer.
*
* This must match the number of planes required by format.
*/
int nb_planes;
/**
* Array of planes in this layer.
*/
AVDRMPlaneDescriptor planes[AV_DRM_MAX_PLANES];
} AVDRMLayerDescriptor;
/**
* DRM frame descriptor.
*
* This is used as the data pointer for AV_PIX_FMT_DRM_PRIME frames.
* It is also used by user-allocated frame pools - allocating in
* AVHWFramesContext.pool must return AVBufferRefs which contain
* an object of this type.
*
* The fields of this structure should be set such it can be
* imported directly by EGL using the EGL_EXT_image_dma_buf_import
* and EGL_EXT_image_dma_buf_import_modifiers extensions.
* (Note that the exact layout of a particular format may vary between
* platforms - we only specify that the same platform should be able
* to import it.)
*
* The total number of planes must not exceed AV_DRM_MAX_PLANES, and
* the order of the planes by increasing layer index followed by
* increasing plane index must be the same as the order which would
* be used for the data pointers in the equivalent software format.
*/
typedef struct AVDRMFrameDescriptor {
/**
* Number of DRM objects making up this frame.
*/
int nb_objects;
/**
* Array of objects making up the frame.
*/
AVDRMObjectDescriptor objects[AV_DRM_MAX_PLANES];
/**
* Number of layers in the frame.
*/
int nb_layers;
/**
* Array of layers in the frame.
*/
AVDRMLayerDescriptor layers[AV_DRM_MAX_PLANES];
} AVDRMFrameDescriptor;
/**
* DRM device.
*
* Allocated as AVHWDeviceContext.hwctx.
*/
typedef struct AVDRMDeviceContext {
/**
* File descriptor of DRM device.
*
* This is used as the device to create frames on, and may also be
* used in some derivation and mapping operations.
*
* If no device is required, set to -1.
*/
int fd;
} AVDRMDeviceContext;
#endif /* AVUTIL_HWCONTEXT_DRM_H */

@ -65,6 +65,9 @@ typedef struct AVDXVA2FramesContext {
* *
* If it is non-NULL, libavutil will call IDirectXVideoDecoder_Release() on * If it is non-NULL, libavutil will call IDirectXVideoDecoder_Release() on
* it just before the internal surface pool is freed. * it just before the internal surface pool is freed.
*
* This is for convenience only. Some code uses other methods to manage the
* decoder reference.
*/ */
IDirectXVideoDecoder *decoder_to_release; IDirectXVideoDecoder *decoder_to_release;
} AVDXVA2FramesContext; } AVDXVA2FramesContext;

@ -0,0 +1,36 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVUTIL_HWCONTEXT_MEDIACODEC_H
#define AVUTIL_HWCONTEXT_MEDIACODEC_H
/**
* MediaCodec details.
*
* Allocated as AVHWDeviceContext.hwctx
*/
typedef struct AVMediaCodecDeviceContext {
/**
* android/view/Surface handle, to be filled by the user.
*
* This is the default surface used by decoders on this device.
*/
void *surface;
} AVMediaCodecDeviceContext;
#endif /* AVUTIL_HWCONTEXT_MEDIACODEC_H */

@ -33,6 +33,33 @@
* with the data pointer set to a VASurfaceID. * with the data pointer set to a VASurfaceID.
*/ */
enum {
/**
* The quirks field has been set by the user and should not be detected
* automatically by av_hwdevice_ctx_init().
*/
AV_VAAPI_DRIVER_QUIRK_USER_SET = (1 << 0),
/**
* The driver does not destroy parameter buffers when they are used by
* vaRenderPicture(). Additional code will be required to destroy them
* separately afterwards.
*/
AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS = (1 << 1),
/**
* The driver does not support the VASurfaceAttribMemoryType attribute,
* so the surface allocation code will not try to use it.
*/
AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE = (1 << 2),
/**
* The driver does not support surface attributes at all.
* The surface allocation code will never pass them to surface allocation,
* and the results of the vaQuerySurfaceAttributes() call will be faked.
*/
AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = (1 << 3),
};
/** /**
* VAAPI connection details. * VAAPI connection details.
* *
@ -43,6 +70,14 @@ typedef struct AVVAAPIDeviceContext {
* The VADisplay handle, to be filled by the user. * The VADisplay handle, to be filled by the user.
*/ */
VADisplay display; VADisplay display;
/**
* Driver quirks to apply - this is filled by av_hwdevice_ctx_init(),
* with reference to a table of known drivers, unless the
* AV_VAAPI_DRIVER_QUIRK_USER_SET bit is already present. The user
* may need to refer to this field when performing any later
* operations using VAAPI with the same VADisplay.
*/
unsigned int driver_quirks;
} AVVAAPIDeviceContext; } AVVAAPIDeviceContext;
/** /**

@ -0,0 +1,54 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVUTIL_HWCONTEXT_VIDEOTOOLBOX_H
#define AVUTIL_HWCONTEXT_VIDEOTOOLBOX_H
#include <stdint.h>
#include <VideoToolbox/VideoToolbox.h>
#include "pixfmt.h"
/**
* @file
* An API-specific header for AV_HWDEVICE_TYPE_VIDEOTOOLBOX.
*
* This API currently does not support frame allocation, as the raw VideoToolbox
* API does allocation, and FFmpeg itself never has the need to allocate frames.
*
* If the API user sets a custom pool, AVHWFramesContext.pool must return
* AVBufferRefs whose data pointer is a CVImageBufferRef or CVPixelBufferRef.
*
* Currently AVHWDeviceContext.hwctx and AVHWFramesContext.hwctx are always
* NULL.
*/
/**
* Convert a VideoToolbox (actually CoreVideo) format to AVPixelFormat.
* Returns AV_PIX_FMT_NONE if no known equivalent was found.
*/
enum AVPixelFormat av_map_videotoolbox_format_to_pixfmt(uint32_t cv_fmt);
/**
* Convert an AVPixelFormat to a VideoToolbox (actually CoreVideo) format.
* Returns 0 if no known equivalent was found.
*/
uint32_t av_map_videotoolbox_format_from_pixfmt(enum AVPixelFormat pix_fmt);
#endif /* AVUTIL_HWCONTEXT_VIDEOTOOLBOX_H */

@ -120,6 +120,24 @@ void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4],
const uint8_t *src_data[4], const int src_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4],
enum AVPixelFormat pix_fmt, int width, int height); enum AVPixelFormat pix_fmt, int width, int height);
/**
* Copy image data located in uncacheable (e.g. GPU mapped) memory. Where
* available, this function will use special functionality for reading from such
* memory, which may result in greatly improved performance compared to plain
* av_image_copy().
*
* The data pointers and the linesizes must be aligned to the maximum required
* by the CPU architecture.
*
* @note The linesize parameters have the type ptrdiff_t here, while they are
* int for av_image_copy().
* @note On x86, the linesizes currently need to be aligned to the cacheline
* size (i.e. 64) to get improved performance.
*/
void av_image_copy_uc_from(uint8_t *dst_data[4], const ptrdiff_t dst_linesizes[4],
const uint8_t *src_data[4], const ptrdiff_t src_linesizes[4],
enum AVPixelFormat pix_fmt, int width, int height);
/** /**
* Setup the data pointers and linesizes based on the specified image * Setup the data pointers and linesizes based on the specified image
* parameters and the provided array. * parameters and the provided array.
@ -137,7 +155,7 @@ void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4],
* one call, use av_image_alloc(). * one call, use av_image_alloc().
* *
* @param dst_data data pointers to be filled in * @param dst_data data pointers to be filled in
* @param dst_linesizes linesizes for the image in dst_data to be filled in * @param dst_linesize linesizes for the image in dst_data to be filled in
* @param src buffer which will contain or contains the actual image data, can be NULL * @param src buffer which will contain or contains the actual image data, can be NULL
* @param pix_fmt the pixel format of the image * @param pix_fmt the pixel format of the image
* @param width the width of the image in pixels * @param width the width of the image in pixels
@ -154,7 +172,11 @@ int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4],
* Return the size in bytes of the amount of data required to store an * Return the size in bytes of the amount of data required to store an
* image with the given parameters. * image with the given parameters.
* *
* @param[in] align the assumed linesize alignment * @param pix_fmt the pixel format of the image
* @param width the width of the image in pixels
* @param height the height of the image in pixels
* @param align the assumed linesize alignment
* @return the buffer size in bytes, a negative error code in case of failure
*/ */
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align); int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align);
@ -167,7 +189,7 @@ int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height,
* @param dst a buffer into which picture data will be copied * @param dst a buffer into which picture data will be copied
* @param dst_size the size in bytes of dst * @param dst_size the size in bytes of dst
* @param src_data pointers containing the source image data * @param src_data pointers containing the source image data
* @param src_linesizes linesizes for the image in src_data * @param src_linesize linesizes for the image in src_data
* @param pix_fmt the pixel format of the source image * @param pix_fmt the pixel format of the source image
* @param width the width of the source image in pixels * @param width the width of the source image in pixels
* @param height the height of the source image in pixels * @param height the height of the source image in pixels
@ -191,6 +213,21 @@ int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
*/ */
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx); int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx);
/**
* Check if the given dimension of an image is valid, meaning that all
* bytes of a plane of an image with the specified pix_fmt can be addressed
* with a signed int.
*
* @param w the width of the picture
* @param h the height of the picture
* @param max_pixels the maximum number of pixels the user wants to accept
* @param pix_fmt the pixel format, can be AV_PIX_FMT_NONE if unknown.
* @param log_offset the offset to sum to the log level for logging with log_ctx
* @param log_ctx the parent logging context, it may be NULL
* @return >= 0 if valid, a negative error code otherwise
*/
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx);
/** /**
* Check if the given sample aspect ratio of an image is valid. * Check if the given sample aspect ratio of an image is valid.
* *
@ -205,6 +242,33 @@ int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *lo
*/ */
int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar); int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar);
/**
* Overwrite the image data with black. This is suitable for filling a
* sub-rectangle of an image, meaning the padding between the right most pixel
* and the left most pixel on the next line will not be overwritten. For some
* formats, the image size might be rounded up due to inherent alignment.
*
* If the pixel format has alpha, the alpha is cleared to opaque.
*
* This can return an error if the pixel format is not supported. Normally, all
* non-hwaccel pixel formats should be supported.
*
* Passing NULL for dst_data is allowed. Then the function returns whether the
* operation would have succeeded. (It can return an error if the pix_fmt is
* not supported.)
*
* @param dst_data data pointers to destination image
* @param dst_linesize linesizes for the destination image
* @param pix_fmt the pixel format of the image
* @param range the color range of the image (important for colorspaces such as YUV)
* @param width the width of the image in pixels
* @param height the height of the image in pixels
* @return 0 if the image data was cleared, a negative AVERROR code otherwise
*/
int av_image_fill_black(uint8_t *dst_data[4], const ptrdiff_t dst_linesize[4],
enum AVPixelFormat pix_fmt, enum AVColorRange range,
int width, int height);
/** /**
* @} * @}
*/ */

@ -215,7 +215,7 @@ typedef union {
* by per-arch headers. * by per-arch headers.
*/ */
#if defined(__GNUC__) && !defined(__TI_COMPILER_VERSION__) #if defined(__GNUC__)
union unaligned_64 { uint64_t l; } __attribute__((packed)) av_alias; union unaligned_64 { uint64_t l; } __attribute__((packed)) av_alias;
union unaligned_32 { uint32_t l; } __attribute__((packed)) av_alias; union unaligned_32 { uint32_t l; } __attribute__((packed)) av_alias;
@ -224,7 +224,7 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
# define AV_RN(s, p) (((const union unaligned_##s *) (p))->l) # define AV_RN(s, p) (((const union unaligned_##s *) (p))->l)
# define AV_WN(s, p, v) ((((union unaligned_##s *) (p))->l) = (v)) # define AV_WN(s, p, v) ((((union unaligned_##s *) (p))->l) = (v))
#elif defined(__DECC) #elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_X64) || defined(_M_ARM64)) && AV_HAVE_FAST_UNALIGNED
# define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p))) # define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
# define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v)) # define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
@ -242,8 +242,8 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
((const uint8_t*)(x))[1]) ((const uint8_t*)(x))[1])
#endif #endif
#ifndef AV_WB16 #ifndef AV_WB16
# define AV_WB16(p, darg) do { \ # define AV_WB16(p, val) do { \
unsigned d = (darg); \ uint16_t d = (val); \
((uint8_t*)(p))[1] = (d); \ ((uint8_t*)(p))[1] = (d); \
((uint8_t*)(p))[0] = (d)>>8; \ ((uint8_t*)(p))[0] = (d)>>8; \
} while(0) } while(0)
@ -255,8 +255,8 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
((const uint8_t*)(x))[0]) ((const uint8_t*)(x))[0])
#endif #endif
#ifndef AV_WL16 #ifndef AV_WL16
# define AV_WL16(p, darg) do { \ # define AV_WL16(p, val) do { \
unsigned d = (darg); \ uint16_t d = (val); \
((uint8_t*)(p))[0] = (d); \ ((uint8_t*)(p))[0] = (d); \
((uint8_t*)(p))[1] = (d)>>8; \ ((uint8_t*)(p))[1] = (d)>>8; \
} while(0) } while(0)
@ -270,8 +270,8 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
((const uint8_t*)(x))[3]) ((const uint8_t*)(x))[3])
#endif #endif
#ifndef AV_WB32 #ifndef AV_WB32
# define AV_WB32(p, darg) do { \ # define AV_WB32(p, val) do { \
unsigned d = (darg); \ uint32_t d = (val); \
((uint8_t*)(p))[3] = (d); \ ((uint8_t*)(p))[3] = (d); \
((uint8_t*)(p))[2] = (d)>>8; \ ((uint8_t*)(p))[2] = (d)>>8; \
((uint8_t*)(p))[1] = (d)>>16; \ ((uint8_t*)(p))[1] = (d)>>16; \
@ -287,8 +287,8 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
((const uint8_t*)(x))[0]) ((const uint8_t*)(x))[0])
#endif #endif
#ifndef AV_WL32 #ifndef AV_WL32
# define AV_WL32(p, darg) do { \ # define AV_WL32(p, val) do { \
unsigned d = (darg); \ uint32_t d = (val); \
((uint8_t*)(p))[0] = (d); \ ((uint8_t*)(p))[0] = (d); \
((uint8_t*)(p))[1] = (d)>>8; \ ((uint8_t*)(p))[1] = (d)>>8; \
((uint8_t*)(p))[2] = (d)>>16; \ ((uint8_t*)(p))[2] = (d)>>16; \
@ -308,8 +308,8 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
(uint64_t)((const uint8_t*)(x))[7]) (uint64_t)((const uint8_t*)(x))[7])
#endif #endif
#ifndef AV_WB64 #ifndef AV_WB64
# define AV_WB64(p, darg) do { \ # define AV_WB64(p, val) do { \
uint64_t d = (darg); \ uint64_t d = (val); \
((uint8_t*)(p))[7] = (d); \ ((uint8_t*)(p))[7] = (d); \
((uint8_t*)(p))[6] = (d)>>8; \ ((uint8_t*)(p))[6] = (d)>>8; \
((uint8_t*)(p))[5] = (d)>>16; \ ((uint8_t*)(p))[5] = (d)>>16; \
@ -333,8 +333,8 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
(uint64_t)((const uint8_t*)(x))[0]) (uint64_t)((const uint8_t*)(x))[0])
#endif #endif
#ifndef AV_WL64 #ifndef AV_WL64
# define AV_WL64(p, darg) do { \ # define AV_WL64(p, val) do { \
uint64_t d = (darg); \ uint64_t d = (val); \
((uint8_t*)(p))[0] = (d); \ ((uint8_t*)(p))[0] = (d); \
((uint8_t*)(p))[1] = (d)>>8; \ ((uint8_t*)(p))[1] = (d)>>8; \
((uint8_t*)(p))[2] = (d)>>16; \ ((uint8_t*)(p))[2] = (d)>>16; \
@ -542,6 +542,21 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
# define AV_WN64A(p, v) AV_WNA(64, p, v) # define AV_WN64A(p, v) AV_WNA(64, p, v)
#endif #endif
#if AV_HAVE_BIGENDIAN
# define AV_RLA(s, p) av_bswap##s(AV_RN##s##A(p))
# define AV_WLA(s, p, v) AV_WN##s##A(p, av_bswap##s(v))
#else
# define AV_RLA(s, p) AV_RN##s##A(p)
# define AV_WLA(s, p, v) AV_WN##s##A(p, v)
#endif
#ifndef AV_RL64A
# define AV_RL64A(p) AV_RLA(64, p)
#endif
#ifndef AV_WL64A
# define AV_WL64A(p, v) AV_WLA(64, p, v)
#endif
/* /*
* The AV_COPYxxU macros are suitable for copying data to/from unaligned * The AV_COPYxxU macros are suitable for copying data to/from unaligned
* memory locations. * memory locations.

@ -22,6 +22,8 @@
#ifndef AVUTIL_LFG_H #ifndef AVUTIL_LFG_H
#define AVUTIL_LFG_H #define AVUTIL_LFG_H
#include <stdint.h>
typedef struct AVLFG { typedef struct AVLFG {
unsigned int state[64]; unsigned int state[64];
int index; int index;
@ -29,6 +31,13 @@ typedef struct AVLFG {
void av_lfg_init(AVLFG *c, unsigned int seed); void av_lfg_init(AVLFG *c, unsigned int seed);
/**
* Seed the state of the ALFG using binary data.
*
* Return value: 0 on success, negative value (AVERROR) on failure.
*/
int av_lfg_init_from_data(AVLFG *c, const uint8_t *data, unsigned int length);
/** /**
* Get the next random unsigned 32-bit number using an ALFG. * Get the next random unsigned 32-bit number using an ALFG.
* *

@ -44,7 +44,7 @@ typedef enum {
AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT, AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT,
AV_CLASS_CATEGORY_DEVICE_OUTPUT, AV_CLASS_CATEGORY_DEVICE_OUTPUT,
AV_CLASS_CATEGORY_DEVICE_INPUT, AV_CLASS_CATEGORY_DEVICE_INPUT,
AV_CLASS_CATEGORY_NB, ///< not part of ABI/API AV_CLASS_CATEGORY_NB ///< not part of ABI/API
}AVClassCategory; }AVClassCategory;
#define AV_IS_INPUT_DEVICE(category) \ #define AV_IS_INPUT_DEVICE(category) \
@ -317,19 +317,22 @@ AVClassCategory av_default_get_category(void *ptr);
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
char *line, int line_size, int *print_prefix); char *line, int line_size, int *print_prefix);
#if FF_API_DLOG
/** /**
* av_dlog macros * Format a line of log the same way as the default callback.
* @deprecated unused * @param line buffer to receive the formatted line;
* Useful to print debug messages that shouldn't get compiled in normally. * may be NULL if line_size is 0
* @param line_size size of the buffer; at most line_size-1 characters will
* be written to the buffer, plus one null terminator
* @param print_prefix used to store whether the prefix must be printed;
* must point to a persistent integer initially set to 1
* @return Returns a negative value if an error occurred, otherwise returns
* the number of characters that would have been written for a
* sufficiently large buffer, not including the terminating null
* character. If the return value is not less than line_size, it means
* that the log message was truncated to fit the buffer.
*/ */
int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,
#ifdef DEBUG char *line, int line_size, int *print_prefix);
# define av_dlog(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
#else
# define av_dlog(pctx, ...) do { if (0) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
#endif
#endif /* FF_API_DLOG */
/** /**
* Skip repeated messages, this requires the user app to use av_log() instead of * Skip repeated messages, this requires the user app to use av_log() instead of

@ -1,4 +1,4 @@
/** /*
* Copyright (c) 2016 Neil Birkbeck <neil.birkbeck@gmail.com> * Copyright (c) 2016 Neil Birkbeck <neil.birkbeck@gmail.com>
* *
* This file is part of FFmpeg. * This file is part of FFmpeg.
@ -86,4 +86,43 @@ AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc(void);
*/ */
AVMasteringDisplayMetadata *av_mastering_display_metadata_create_side_data(AVFrame *frame); AVMasteringDisplayMetadata *av_mastering_display_metadata_create_side_data(AVFrame *frame);
/**
* Content light level needed by to transmit HDR over HDMI (CTA-861.3).
*
* To be used as payload of a AVFrameSideData or AVPacketSideData with the
* appropriate type.
*
* @note The struct should be allocated with av_content_light_metadata_alloc()
* and its size is not a part of the public ABI.
*/
typedef struct AVContentLightMetadata {
/**
* Max content light level (cd/m^2).
*/
unsigned MaxCLL;
/**
* Max average light level per frame (cd/m^2).
*/
unsigned MaxFALL;
} AVContentLightMetadata;
/**
* Allocate an AVContentLightMetadata structure and set its fields to
* default values. The resulting struct can be freed using av_freep().
*
* @return An AVContentLightMetadata filled with default values or NULL
* on failure.
*/
AVContentLightMetadata *av_content_light_metadata_alloc(size_t *size);
/**
* Allocate a complete AVContentLightMetadata and add it to the frame.
*
* @param frame The frame which side data is added to.
*
* @return The AVContentLightMetadata structure to be filled by caller.
*/
AVContentLightMetadata *av_content_light_metadata_create_side_data(AVFrame *frame);
#endif /* AVUTIL_MASTERING_DISPLAY_METADATA_H */ #endif /* AVUTIL_MASTERING_DISPLAY_METADATA_H */

@ -18,6 +18,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* @file
* @addtogroup lavu_math
* Mathematical utilities for working with timestamp and time base.
*/
#ifndef AVUTIL_MATHEMATICS_H #ifndef AVUTIL_MATHEMATICS_H
#define AVUTIL_MATHEMATICS_H #define AVUTIL_MATHEMATICS_H
@ -63,84 +69,155 @@
/** /**
* @addtogroup lavu_math * @addtogroup lavu_math
*
* @{ * @{
*/ */
/**
* Rounding methods.
*/
enum AVRounding { enum AVRounding {
AV_ROUND_ZERO = 0, ///< Round toward zero. AV_ROUND_ZERO = 0, ///< Round toward zero.
AV_ROUND_INF = 1, ///< Round away from zero. AV_ROUND_INF = 1, ///< Round away from zero.
AV_ROUND_DOWN = 2, ///< Round toward -infinity. AV_ROUND_DOWN = 2, ///< Round toward -infinity.
AV_ROUND_UP = 3, ///< Round toward +infinity. AV_ROUND_UP = 3, ///< Round toward +infinity.
AV_ROUND_NEAR_INF = 5, ///< Round to nearest and halfway cases away from zero. AV_ROUND_NEAR_INF = 5, ///< Round to nearest and halfway cases away from zero.
AV_ROUND_PASS_MINMAX = 8192, ///< Flag to pass INT64_MIN/MAX through instead of rescaling, this avoids special cases for AV_NOPTS_VALUE /**
* Flag telling rescaling functions to pass `INT64_MIN`/`MAX` through
* unchanged, avoiding special cases for #AV_NOPTS_VALUE.
*
* Unlike other values of the enumeration AVRounding, this value is a
* bitmask that must be used in conjunction with another value of the
* enumeration through a bitwise OR, in order to set behavior for normal
* cases.
*
* @code{.c}
* av_rescale_rnd(3, 1, 2, AV_ROUND_UP | AV_ROUND_PASS_MINMAX);
* // Rescaling 3:
* // Calculating 3 * 1 / 2
* // 3 / 2 is rounded up to 2
* // => 2
*
* av_rescale_rnd(AV_NOPTS_VALUE, 1, 2, AV_ROUND_UP | AV_ROUND_PASS_MINMAX);
* // Rescaling AV_NOPTS_VALUE:
* // AV_NOPTS_VALUE == INT64_MIN
* // AV_NOPTS_VALUE is passed through
* // => AV_NOPTS_VALUE
* @endcode
*/
AV_ROUND_PASS_MINMAX = 8192,
}; };
/** /**
* Compute the greatest common divisor of a and b. * Compute the greatest common divisor of two integer operands.
* *
* @return gcd of a and b up to sign; if a >= 0 and b >= 0, return value is >= 0; * @param a,b Operands
* @return GCD of a and b up to sign; if a >= 0 and b >= 0, return value is >= 0;
* if a == 0 and b == 0, returns 0. * if a == 0 and b == 0, returns 0.
*/ */
int64_t av_const av_gcd(int64_t a, int64_t b); int64_t av_const av_gcd(int64_t a, int64_t b);
/** /**
* Rescale a 64-bit integer with rounding to nearest. * Rescale a 64-bit integer with rounding to nearest.
* A simple a*b/c isn't possible as it can overflow. *
* The operation is mathematically equivalent to `a * b / c`, but writing that
* directly can overflow.
*
* This function is equivalent to av_rescale_rnd() with #AV_ROUND_NEAR_INF.
*
* @see av_rescale_rnd(), av_rescale_q(), av_rescale_q_rnd()
*/ */
int64_t av_rescale(int64_t a, int64_t b, int64_t c) av_const; int64_t av_rescale(int64_t a, int64_t b, int64_t c) av_const;
/** /**
* Rescale a 64-bit integer with specified rounding. * Rescale a 64-bit integer with specified rounding.
* A simple a*b/c isn't possible as it can overflow.
* *
* @return rescaled value a, or if AV_ROUND_PASS_MINMAX is set and a is * The operation is mathematically equivalent to `a * b / c`, but writing that
* INT64_MIN or INT64_MAX then a is passed through unchanged. * directly can overflow, and does not support different rounding methods.
*
* @see av_rescale(), av_rescale_q(), av_rescale_q_rnd()
*/ */
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_const; int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd) av_const;
/** /**
* Rescale a 64-bit integer by 2 rational numbers. * Rescale a 64-bit integer by 2 rational numbers.
*
* The operation is mathematically equivalent to `a * bq / cq`.
*
* This function is equivalent to av_rescale_q_rnd() with #AV_ROUND_NEAR_INF.
*
* @see av_rescale(), av_rescale_rnd(), av_rescale_q_rnd()
*/ */
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const; int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
/** /**
* Rescale a 64-bit integer by 2 rational numbers with specified rounding. * Rescale a 64-bit integer by 2 rational numbers with specified rounding.
* *
* @return rescaled value a, or if AV_ROUND_PASS_MINMAX is set and a is * The operation is mathematically equivalent to `a * bq / cq`.
* INT64_MIN or INT64_MAX then a is passed through unchanged. *
* @see av_rescale(), av_rescale_rnd(), av_rescale_q()
*/ */
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq,
enum AVRounding) av_const; enum AVRounding rnd) av_const;
/** /**
* Compare 2 timestamps each in its own timebases. * Compare two timestamps each in its own time base.
* The result of the function is undefined if one of the timestamps *
* is outside the int64_t range when represented in the others timebase. * @return One of the following values:
* @return -1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position * - -1 if `ts_a` is before `ts_b`
* - 1 if `ts_a` is after `ts_b`
* - 0 if they represent the same position
*
* @warning
* The result of the function is undefined if one of the timestamps is outside
* the `int64_t` range when represented in the other's timebase.
*/ */
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b); int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b);
/** /**
* Compare 2 integers modulo mod. * Compare the remainders of two integer operands divided by a common divisor.
* That is we compare integers a and b for which only the least *
* significant log2(mod) bits are known. * In other words, compare the least significant `log2(mod)` bits of integers
* * `a` and `b`.
* @param mod must be a power of 2 *
* @return a negative value if a is smaller than b * @code{.c}
* a positive value if a is greater than b * av_compare_mod(0x11, 0x02, 0x10) < 0 // since 0x11 % 0x10 (0x1) < 0x02 % 0x10 (0x2)
* 0 if a equals b * av_compare_mod(0x11, 0x02, 0x20) > 0 // since 0x11 % 0x20 (0x11) > 0x02 % 0x20 (0x02)
* @endcode
*
* @param a,b Operands
* @param mod Divisor; must be a power of 2
* @return
* - a negative value if `a % mod < b % mod`
* - a positive value if `a % mod > b % mod`
* - zero if `a % mod == b % mod`
*/ */
int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod); int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod);
/** /**
* Rescale a timestamp while preserving known durations. * Rescale a timestamp while preserving known durations.
* *
* @param in_ts Input timestamp * This function is designed to be called per audio packet to scale the input
* @param in_tb Input timebase * timestamp to a different time base. Compared to a simple av_rescale_q()
* @param fs_tb Duration and *last timebase * call, this function is robust against possible inconsistent frame durations.
* @param duration duration till the next call *
* @param out_tb Output timebase * The `last` parameter is a state variable that must be preserved for all
* subsequent calls for the same stream. For the first call, `*last` should be
* initialized to #AV_NOPTS_VALUE.
*
* @param[in] in_tb Input time base
* @param[in] in_ts Input timestamp
* @param[in] fs_tb Duration time base; typically this is finer-grained
* (greater) than `in_tb` and `out_tb`
* @param[in] duration Duration till the next call to this function (i.e.
* duration of the current packet/frame)
* @param[in,out] last Pointer to a timestamp expressed in terms of
* `fs_tb`, acting as a state variable
* @param[in] out_tb Output timebase
* @return Timestamp expressed in terms of `out_tb`
*
* @note In the context of this function, "duration" is in term of samples, not
* seconds.
*/ */
int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb); int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb);
@ -150,15 +227,15 @@ int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int
* This function guarantees that when the same value is repeatly added that * This function guarantees that when the same value is repeatly added that
* no accumulation of rounding errors occurs. * no accumulation of rounding errors occurs.
* *
* @param ts Input timestamp * @param[in] ts Input timestamp
* @param ts_tb Input timestamp timebase * @param[in] ts_tb Input timestamp time base
* @param inc value to add to ts * @param[in] inc Value to be added
* @param inc_tb inc timebase * @param[in] inc_tb Time base of `inc`
*/ */
int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc); int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc);
/** /**
* @} * @}
*/ */

@ -18,9 +18,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* @file
* @ingroup lavu_md5
* Public header for MD5 hash function implementation.
*/
#ifndef AVUTIL_MD5_H #ifndef AVUTIL_MD5_H
#define AVUTIL_MD5_H #define AVUTIL_MD5_H
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "attributes.h" #include "attributes.h"
@ -28,7 +35,9 @@
/** /**
* @defgroup lavu_md5 MD5 * @defgroup lavu_md5 MD5
* @ingroup lavu_crypto * @ingroup lavu_hash
* MD5 hash function implementation.
*
* @{ * @{
*/ */
@ -55,7 +64,11 @@ void av_md5_init(struct AVMD5 *ctx);
* @param src input data to update hash with * @param src input data to update hash with
* @param len input data length * @param len input data length
*/ */
#if FF_API_CRYPTO_SIZE_T
void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, int len); void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, int len);
#else
void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, size_t len);
#endif
/** /**
* Finish hashing and output digest value. * Finish hashing and output digest value.
@ -72,7 +85,11 @@ void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
* @param src The data to hash * @param src The data to hash
* @param len The length of the data, in bytes * @param len The length of the data, in bytes
*/ */
#if FF_API_CRYPTO_SIZE_T
void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len); void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len);
#else
void av_md5_sum(uint8_t *dst, const uint8_t *src, size_t len);
#endif
/** /**
* @} * @}

@ -20,7 +20,8 @@
/** /**
* @file * @file
* memory handling functions * @ingroup lavu_mem
* Memory handling functions
*/ */
#ifndef AVUTIL_MEM_H #ifndef AVUTIL_MEM_H
@ -35,37 +36,133 @@
/** /**
* @addtogroup lavu_mem * @addtogroup lavu_mem
* Utilities for manipulating memory.
*
* FFmpeg has several applications of memory that are not required of a typical
* program. For example, the computing-heavy components like video decoding and
* encoding can be sped up significantly through the use of aligned memory.
*
* However, for each of FFmpeg's applications of memory, there might not be a
* recognized or standardized API for that specific use. Memory alignment, for
* instance, varies wildly depending on operating systems, architectures, and
* compilers. Hence, this component of @ref libavutil is created to make
* dealing with memory consistently possible on all platforms.
*
* @{
*
* @defgroup lavu_mem_macros Alignment Macros
* Helper macros for declaring aligned variables.
* @{ * @{
*/ */
/**
* @def DECLARE_ALIGNED(n,t,v)
* Declare a variable that is aligned in memory.
*
* @code{.c}
* DECLARE_ALIGNED(16, uint16_t, aligned_int) = 42;
* DECLARE_ALIGNED(32, uint8_t, aligned_array)[128];
*
* // The default-alignment equivalent would be
* uint16_t aligned_int = 42;
* uint8_t aligned_array[128];
* @endcode
*
* @param n Minimum alignment in bytes
* @param t Type of the variable (or array element)
* @param v Name of the variable
*/
/**
* @def DECLARE_ASM_ALIGNED(n,t,v)
* Declare an aligned variable appropriate for use in inline assembly code.
*
* @code{.c}
* DECLARE_ASM_ALIGNED(16, uint64_t, pw_08) = UINT64_C(0x0008000800080008);
* @endcode
*
* @param n Minimum alignment in bytes
* @param t Type of the variable (or array element)
* @param v Name of the variable
*/
/**
* @def DECLARE_ASM_CONST(n,t,v)
* Declare a static constant aligned variable appropriate for use in inline
* assembly code.
*
* @code{.c}
* DECLARE_ASM_CONST(16, uint64_t, pw_08) = UINT64_C(0x0008000800080008);
* @endcode
*
* @param n Minimum alignment in bytes
* @param t Type of the variable (or array element)
* @param v Name of the variable
*/
#if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C) #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
#define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
#define DECLARE_ASM_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
#define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
#elif defined(__TI_COMPILER_VERSION__) #elif defined(__DJGPP__)
#define DECLARE_ALIGNED(n,t,v) \ #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (FFMIN(n, 16)))) v
AV_PRAGMA(DATA_ALIGN(v,n)) \ #define DECLARE_ASM_ALIGNED(n,t,v) t av_used __attribute__ ((aligned (FFMIN(n, 16)))) v
t __attribute__((aligned(n))) v #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (FFMIN(n, 16)))) v
#define DECLARE_ASM_CONST(n,t,v) \ #elif defined(__GNUC__) || defined(__clang__)
AV_PRAGMA(DATA_ALIGN(v,n)) \
static const t __attribute__((aligned(n))) v
#elif defined(__GNUC__)
#define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
#define DECLARE_ASM_ALIGNED(n,t,v) t av_used __attribute__ ((aligned (n))) v
#define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (n))) v #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (n))) v
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
#define DECLARE_ASM_ALIGNED(n,t,v) __declspec(align(n)) t v
#define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
#else #else
#define DECLARE_ALIGNED(n,t,v) t v #define DECLARE_ALIGNED(n,t,v) t v
#define DECLARE_ASM_ALIGNED(n,t,v) t v
#define DECLARE_ASM_CONST(n,t,v) static const t v #define DECLARE_ASM_CONST(n,t,v) static const t v
#endif #endif
/**
* @}
*/
/**
* @defgroup lavu_mem_attrs Function Attributes
* Function attributes applicable to memory handling functions.
*
* These function attributes can help compilers emit more useful warnings, or
* generate better code.
* @{
*/
/**
* @def av_malloc_attrib
* Function attribute denoting a malloc-like function.
*
* @see <a href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-g_t_0040code_007bmalloc_007d-function-attribute-3251">Function attribute `malloc` in GCC's documentation</a>
*/
#if AV_GCC_VERSION_AT_LEAST(3,1) #if AV_GCC_VERSION_AT_LEAST(3,1)
#define av_malloc_attrib __attribute__((__malloc__)) #define av_malloc_attrib __attribute__((__malloc__))
#else #else
#define av_malloc_attrib #define av_malloc_attrib
#endif #endif
/**
* @def av_alloc_size(...)
* Function attribute used on a function that allocates memory, whose size is
* given by the specified parameter(s).
*
* @code{.c}
* void *av_malloc(size_t size) av_alloc_size(1);
* void *av_calloc(size_t nmemb, size_t size) av_alloc_size(1, 2);
* @endcode
*
* @param ... One or two parameter indexes, separated by a comma
*
* @see <a href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-g_t_0040code_007balloc_005fsize_007d-function-attribute-3220">Function attribute `alloc_size` in GCC's documentation</a>
*/
#if AV_GCC_VERSION_AT_LEAST(4,3) #if AV_GCC_VERSION_AT_LEAST(4,3)
#define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__))) #define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
#else #else
@ -73,204 +170,423 @@
#endif #endif
/** /**
* Allocate a block of size bytes with alignment suitable for all * @}
* memory accesses (including vectors if available on the CPU). */
* @param size Size in bytes for the memory block to be allocated.
* @return Pointer to the allocated block, NULL if the block cannot /**
* be allocated. * @defgroup lavu_mem_funcs Heap Management
* Functions responsible for allocating, freeing, and copying memory.
*
* All memory allocation functions have a built-in upper limit of `INT_MAX`
* bytes. This may be changed with av_max_alloc(), although exercise extreme
* caution when doing so.
*
* @{
*/
/**
* Allocate a memory block with alignment suitable for all memory accesses
* (including vectors if available on the CPU).
*
* @param size Size in bytes for the memory block to be allocated
* @return Pointer to the allocated block, or `NULL` if the block cannot
* be allocated
* @see av_mallocz() * @see av_mallocz()
*/ */
void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1); void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
/** /**
* Allocate a block of size * nmemb bytes with av_malloc(). * Allocate a memory block with alignment suitable for all memory accesses
* @param nmemb Number of elements * (including vectors if available on the CPU) and zero all the bytes of the
* @param size Size of the single element * block.
* @return Pointer to the allocated block, NULL if the block cannot *
* be allocated. * @param size Size in bytes for the memory block to be allocated
* @return Pointer to the allocated block, or `NULL` if it cannot be allocated
* @see av_malloc() * @see av_malloc()
*/ */
av_alloc_size(1, 2) static inline void *av_malloc_array(size_t nmemb, size_t size) void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
{
if (!size || nmemb >= INT_MAX / size) /**
return NULL; * Allocate a memory block for an array with av_malloc().
return av_malloc(nmemb * size); *
} * The allocated memory will have size `size * nmemb` bytes.
*
* @param nmemb Number of element
* @param size Size of a single element
* @return Pointer to the allocated block, or `NULL` if the block cannot
* be allocated
* @see av_malloc()
*/
av_alloc_size(1, 2) void *av_malloc_array(size_t nmemb, size_t size);
/** /**
* Allocate or reallocate a block of memory. * Allocate a memory block for an array with av_mallocz().
* If ptr is NULL and size > 0, allocate a new block. If *
* size is zero, free the memory block pointed to by ptr. * The allocated memory will have size `size * nmemb` bytes.
* @param ptr Pointer to a memory block already allocated with *
* av_realloc() or NULL. * @param nmemb Number of elements
* @param size Size of the single element
* @return Pointer to the allocated block, or `NULL` if the block cannot
* be allocated
*
* @see av_mallocz()
* @see av_malloc_array()
*/
av_alloc_size(1, 2) void *av_mallocz_array(size_t nmemb, size_t size);
/**
* Non-inlined equivalent of av_mallocz_array().
*
* Created for symmetry with the calloc() C function.
*/
void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
/**
* Allocate, reallocate, or free a block of memory.
*
* If `ptr` is `NULL` and `size` > 0, allocate a new block. If `size` is
* zero, free the memory block pointed to by `ptr`. Otherwise, expand or
* shrink that block of memory according to `size`.
*
* @param ptr Pointer to a memory block already allocated with
* av_realloc() or `NULL`
* @param size Size in bytes of the memory block to be allocated or * @param size Size in bytes of the memory block to be allocated or
* reallocated. * reallocated
* @return Pointer to a newly-reallocated block or NULL if the block *
* cannot be reallocated or the function is used to free the memory block. * @return Pointer to a newly-reallocated block or `NULL` if the block
* @warning Pointers originating from the av_malloc() family of functions must * cannot be reallocated or the function is used to free the memory block
* not be passed to av_realloc(). The former can be implemented using *
* memalign() (or other functions), and there is no guarantee that * @warning Unlike av_malloc(), the returned pointer is not guaranteed to be
* pointers from such functions can be passed to realloc() at all. * correctly aligned.
* The situation is undefined according to POSIX and may crash with
* some libc implementations.
* @see av_fast_realloc() * @see av_fast_realloc()
* @see av_reallocp()
*/ */
void *av_realloc(void *ptr, size_t size) av_alloc_size(2); void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
/** /**
* Allocate or reallocate a block of memory. * Allocate, reallocate, or free a block of memory through a pointer to a
* This function does the same thing as av_realloc, except: * pointer.
* - It takes two arguments and checks the result of the multiplication for *
* integer overflow. * If `*ptr` is `NULL` and `size` > 0, allocate a new block. If `size` is
* - It frees the input block in case of failure, thus avoiding the memory * zero, free the memory block pointed to by `*ptr`. Otherwise, expand or
* leak with the classic "buf = realloc(buf); if (!buf) return -1;". * shrink that block of memory according to `size`.
*
* @param[in,out] ptr Pointer to a pointer to a memory block already allocated
* with av_realloc(), or a pointer to `NULL`. The pointer
* is updated on success, or freed on failure.
* @param[in] size Size in bytes for the memory block to be allocated or
* reallocated
*
* @return Zero on success, an AVERROR error code on failure
*
* @warning Unlike av_malloc(), the allocated memory is not guaranteed to be
* correctly aligned.
*/ */
void *av_realloc_f(void *ptr, size_t nelem, size_t elsize); av_warn_unused_result
int av_reallocp(void *ptr, size_t size);
/** /**
* Allocate or reallocate a block of memory. * Allocate, reallocate, or free a block of memory.
* If *ptr is NULL and size > 0, allocate a new block. If *
* size is zero, free the memory block pointed to by ptr. * This function does the same thing as av_realloc(), except:
* @param ptr Pointer to a pointer to a memory block already allocated * - It takes two size arguments and allocates `nelem * elsize` bytes,
* with av_realloc(), or pointer to a pointer to NULL. * after checking the result of the multiplication for integer overflow.
* The pointer is updated on success, or freed on failure. * - It frees the input block in case of failure, thus avoiding the memory
* @param size Size in bytes for the memory block to be allocated or * leak with the classic
* reallocated * @code{.c}
* @return Zero on success, an AVERROR error code on failure. * buf = realloc(buf);
* @warning Pointers originating from the av_malloc() family of functions must * if (!buf)
* not be passed to av_reallocp(). The former can be implemented using * return -1;
* memalign() (or other functions), and there is no guarantee that * @endcode
* pointers from such functions can be passed to realloc() at all. * pattern.
* The situation is undefined according to POSIX and may crash with
* some libc implementations.
*/ */
av_warn_unused_result void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
int av_reallocp(void *ptr, size_t size);
/** /**
* Allocate or reallocate an array. * Allocate, reallocate, or free an array.
* If ptr is NULL and nmemb > 0, allocate a new block. If *
* nmemb is zero, free the memory block pointed to by ptr. * If `ptr` is `NULL` and `nmemb` > 0, allocate a new block. If
* @param ptr Pointer to a memory block already allocated with * `nmemb` is zero, free the memory block pointed to by `ptr`.
* av_realloc() or NULL. *
* @param nmemb Number of elements * @param ptr Pointer to a memory block already allocated with
* @param size Size of the single element * av_realloc() or `NULL`
* @param nmemb Number of elements in the array
* @param size Size of the single element of the array
*
* @return Pointer to a newly-reallocated block or NULL if the block * @return Pointer to a newly-reallocated block or NULL if the block
* cannot be reallocated or the function is used to free the memory block. * cannot be reallocated or the function is used to free the memory block
* @warning Pointers originating from the av_malloc() family of functions must *
* not be passed to av_realloc(). The former can be implemented using * @warning Unlike av_malloc(), the allocated memory is not guaranteed to be
* memalign() (or other functions), and there is no guarantee that * correctly aligned.
* pointers from such functions can be passed to realloc() at all. * @see av_reallocp_array()
* The situation is undefined according to POSIX and may crash with
* some libc implementations.
*/ */
av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size); av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size);
/** /**
* Allocate or reallocate an array through a pointer to a pointer. * Allocate, reallocate, or free an array through a pointer to a pointer.
* If *ptr is NULL and nmemb > 0, allocate a new block. If *
* nmemb is zero, free the memory block pointed to by ptr. * If `*ptr` is `NULL` and `nmemb` > 0, allocate a new block. If `nmemb` is
* @param ptr Pointer to a pointer to a memory block already allocated * zero, free the memory block pointed to by `*ptr`.
* with av_realloc(), or pointer to a pointer to NULL. *
* The pointer is updated on success, or freed on failure. * @param[in,out] ptr Pointer to a pointer to a memory block already
* @param nmemb Number of elements * allocated with av_realloc(), or a pointer to `NULL`.
* @param size Size of the single element * The pointer is updated on success, or freed on failure.
* @return Zero on success, an AVERROR error code on failure. * @param[in] nmemb Number of elements
* @warning Pointers originating from the av_malloc() family of functions must * @param[in] size Size of the single element
* not be passed to av_realloc(). The former can be implemented using *
* memalign() (or other functions), and there is no guarantee that * @return Zero on success, an AVERROR error code on failure
* pointers from such functions can be passed to realloc() at all. *
* The situation is undefined according to POSIX and may crash with * @warning Unlike av_malloc(), the allocated memory is not guaranteed to be
* some libc implementations. * correctly aligned.
*/ */
av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size); int av_reallocp_array(void *ptr, size_t nmemb, size_t size);
/** /**
* Free a memory block which has been allocated with av_malloc(z)() or * Reallocate the given buffer if it is not large enough, otherwise do nothing.
* av_realloc(). *
* @param ptr Pointer to the memory block which should be freed. * If the given buffer is `NULL`, then a new uninitialized buffer is allocated.
* @note ptr = NULL is explicitly allowed. *
* @note It is recommended that you use av_freep() instead. * If the given buffer is not large enough, and reallocation fails, `NULL` is
* @see av_freep() * returned and `*size` is set to 0, but the original buffer is not changed or
* freed.
*
* A typical use pattern follows:
*
* @code{.c}
* uint8_t *buf = ...;
* uint8_t *new_buf = av_fast_realloc(buf, &current_size, size_needed);
* if (!new_buf) {
* // Allocation failed; clean up original buffer
* av_freep(&buf);
* return AVERROR(ENOMEM);
* }
* @endcode
*
* @param[in,out] ptr Already allocated buffer, or `NULL`
* @param[in,out] size Pointer to the size of buffer `ptr`. `*size` is
* updated to the new allocated size, in particular 0
* in case of failure.
* @param[in] min_size Desired minimal size of buffer `ptr`
* @return `ptr` if the buffer is large enough, a pointer to newly reallocated
* buffer if the buffer was not large enough, or `NULL` in case of
* error
* @see av_realloc()
* @see av_fast_malloc()
*/ */
void av_free(void *ptr); void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
/** /**
* Allocate a block of size bytes with alignment suitable for all * Allocate a buffer, reusing the given one if large enough.
* memory accesses (including vectors if available on the CPU) and *
* zero all the bytes of the block. * Contrary to av_fast_realloc(), the current buffer contents might not be
* @param size Size in bytes for the memory block to be allocated. * preserved and on error the old buffer is freed, thus no special handling to
* @return Pointer to the allocated block, NULL if it cannot be allocated. * avoid memleaks is necessary.
* @see av_malloc() *
* `*ptr` is allowed to be `NULL`, in which case allocation always happens if
* `size_needed` is greater than 0.
*
* @code{.c}
* uint8_t *buf = ...;
* av_fast_malloc(&buf, &current_size, size_needed);
* if (!buf) {
* // Allocation failed; buf already freed
* return AVERROR(ENOMEM);
* }
* @endcode
*
* @param[in,out] ptr Pointer to pointer to an already allocated buffer.
* `*ptr` will be overwritten with pointer to new
* buffer on success or `NULL` on failure
* @param[in,out] size Pointer to the size of buffer `*ptr`. `*size` is
* updated to the new allocated size, in particular 0
* in case of failure.
* @param[in] min_size Desired minimal size of buffer `*ptr`
* @see av_realloc()
* @see av_fast_mallocz()
*/ */
void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1); void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
/** /**
* Allocate a block of nmemb * size bytes with alignment suitable for all * Allocate and clear a buffer, reusing the given one if large enough.
* memory accesses (including vectors if available on the CPU) and *
* zero all the bytes of the block. * Like av_fast_malloc(), but all newly allocated space is initially cleared.
* The allocation will fail if nmemb * size is greater than or equal * Reused buffer is not cleared.
* to INT_MAX. *
* @param nmemb * `*ptr` is allowed to be `NULL`, in which case allocation always happens if
* @param size * `size_needed` is greater than 0.
* @return Pointer to the allocated block, NULL if it cannot be allocated. *
* @param[in,out] ptr Pointer to pointer to an already allocated buffer.
* `*ptr` will be overwritten with pointer to new
* buffer on success or `NULL` on failure
* @param[in,out] size Pointer to the size of buffer `*ptr`. `*size` is
* updated to the new allocated size, in particular 0
* in case of failure.
* @param[in] min_size Desired minimal size of buffer `*ptr`
* @see av_fast_malloc()
*/ */
void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib; void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size);
/** /**
* Allocate a block of size * nmemb bytes with av_mallocz(). * Free a memory block which has been allocated with a function of av_malloc()
* @param nmemb Number of elements * or av_realloc() family.
* @param size Size of the single element *
* @return Pointer to the allocated block, NULL if the block cannot * @param ptr Pointer to the memory block which should be freed.
* be allocated. *
* @see av_mallocz() * @note `ptr = NULL` is explicitly allowed.
* @see av_malloc_array() * @note It is recommended that you use av_freep() instead, to prevent leaving
* behind dangling pointers.
* @see av_freep()
*/ */
av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb, size_t size) void av_free(void *ptr);
{
if (!size || nmemb >= INT_MAX / size) /**
return NULL; * Free a memory block which has been allocated with a function of av_malloc()
return av_mallocz(nmemb * size); * or av_realloc() family, and set the pointer pointing to it to `NULL`.
} *
* @code{.c}
* uint8_t *buf = av_malloc(16);
* av_free(buf);
* // buf now contains a dangling pointer to freed memory, and accidental
* // dereference of buf will result in a use-after-free, which may be a
* // security risk.
*
* uint8_t *buf = av_malloc(16);
* av_freep(&buf);
* // buf is now NULL, and accidental dereference will only result in a
* // NULL-pointer dereference.
* @endcode
*
* @param ptr Pointer to the pointer to the memory block which should be freed
* @note `*ptr = NULL` is safe and leads to no action.
* @see av_free()
*/
void av_freep(void *ptr);
/** /**
* Duplicate the string s. * Duplicate a string.
* @param s string to be duplicated *
* @param s String to be duplicated
* @return Pointer to a newly-allocated string containing a * @return Pointer to a newly-allocated string containing a
* copy of s or NULL if the string cannot be allocated. * copy of `s` or `NULL` if the string cannot be allocated
* @see av_strndup()
*/ */
char *av_strdup(const char *s) av_malloc_attrib; char *av_strdup(const char *s) av_malloc_attrib;
/** /**
* Duplicate a substring of the string s. * Duplicate a substring of a string.
* @param s string to be duplicated *
* @param len the maximum length of the resulting string (not counting the * @param s String to be duplicated
* terminating byte). * @param len Maximum length of the resulting string (not counting the
* terminating byte)
* @return Pointer to a newly-allocated string containing a * @return Pointer to a newly-allocated string containing a
* copy of s or NULL if the string cannot be allocated. * substring of `s` or `NULL` if the string cannot be allocated
*/ */
char *av_strndup(const char *s, size_t len) av_malloc_attrib; char *av_strndup(const char *s, size_t len) av_malloc_attrib;
/** /**
* Duplicate the buffer p. * Duplicate a buffer with av_malloc().
* @param p buffer to be duplicated *
* @param p Buffer to be duplicated
* @param size Size in bytes of the buffer copied
* @return Pointer to a newly allocated buffer containing a * @return Pointer to a newly allocated buffer containing a
* copy of p or NULL if the buffer cannot be allocated. * copy of `p` or `NULL` if the buffer cannot be allocated
*/ */
void *av_memdup(const void *p, size_t size); void *av_memdup(const void *p, size_t size);
/** /**
* Free a memory block which has been allocated with av_malloc(z)() or * Overlapping memcpy() implementation.
* av_realloc() and set the pointer pointing to it to NULL. *
* @param ptr Pointer to the pointer to the memory block which should * @param dst Destination buffer
* be freed. * @param back Number of bytes back to start copying (i.e. the initial size of
* @note passing a pointer to a NULL pointer is safe and leads to no action. * the overlapping window); must be > 0
* @see av_free() * @param cnt Number of bytes to copy; must be >= 0
*
* @note `cnt > back` is valid, this will copy the bytes we just copied,
* thus creating a repeating pattern with a period length of `back`.
*/ */
void av_freep(void *ptr); void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
/** /**
* Add an element to a dynamic array. * @}
*/
/**
* @defgroup lavu_mem_dynarray Dynamic Array
*
* Utilities to make an array grow when needed.
*
* Sometimes, the programmer would want to have an array that can grow when
* needed. The libavutil dynamic array utilities fill that need.
*
* libavutil supports two systems of appending elements onto a dynamically
* allocated array, the first one storing the pointer to the value in the
* array, and the second storing the value directly. In both systems, the
* caller is responsible for maintaining a variable containing the length of
* the array, as well as freeing of the array after use.
*
* The first system stores pointers to values in a block of dynamically
* allocated memory. Since only pointers are stored, the function does not need
* to know the size of the type. Both av_dynarray_add() and
* av_dynarray_add_nofree() implement this system.
*
* @code
* type **array = NULL; //< an array of pointers to values
* int nb = 0; //< a variable to keep track of the length of the array
*
* type to_be_added = ...;
* type to_be_added2 = ...;
*
* av_dynarray_add(&array, &nb, &to_be_added);
* if (nb == 0)
* return AVERROR(ENOMEM);
*
* av_dynarray_add(&array, &nb, &to_be_added2);
* if (nb == 0)
* return AVERROR(ENOMEM);
*
* // Now:
* // nb == 2
* // &to_be_added == array[0]
* // &to_be_added2 == array[1]
*
* av_freep(&array);
* @endcode
*
* The second system stores the value directly in a block of memory. As a
* result, the function has to know the size of the type. av_dynarray2_add()
* implements this mechanism.
*
* @code
* type *array = NULL; //< an array of values
* int nb = 0; //< a variable to keep track of the length of the array
*
* type to_be_added = ...;
* type to_be_added2 = ...;
*
* type *addr = av_dynarray2_add((void **)&array, &nb, sizeof(*array), NULL);
* if (!addr)
* return AVERROR(ENOMEM);
* memcpy(addr, &to_be_added, sizeof(to_be_added));
*
* // Shortcut of the above.
* type *addr = av_dynarray2_add((void **)&array, &nb, sizeof(*array),
* (const void *)&to_be_added2);
* if (!addr)
* return AVERROR(ENOMEM);
*
* // Now:
* // nb == 2
* // to_be_added == array[0]
* // to_be_added2 == array[1]
*
* av_freep(&array);
* @endcode
*
* @{
*/
/**
* Add the pointer to an element to a dynamic array.
* *
* The array to grow is supposed to be an array of pointers to * The array to grow is supposed to be an array of pointers to
* structures, and the element to add must be a pointer to an already * structures, and the element to add must be a pointer to an already
@ -280,14 +596,14 @@ void av_freep(void *ptr);
* Therefore, the amortized cost of adding an element is constant. * Therefore, the amortized cost of adding an element is constant.
* *
* In case of success, the pointer to the array is updated in order to * In case of success, the pointer to the array is updated in order to
* point to the new grown array, and the number pointed to by nb_ptr * point to the new grown array, and the number pointed to by `nb_ptr`
* is incremented. * is incremented.
* In case of failure, the array is freed, *tab_ptr is set to NULL and * In case of failure, the array is freed, `*tab_ptr` is set to `NULL` and
* *nb_ptr is set to 0. * `*nb_ptr` is set to 0.
* *
* @param tab_ptr pointer to the array to grow * @param[in,out] tab_ptr Pointer to the array to grow
* @param nb_ptr pointer to the number of elements in the array * @param[in,out] nb_ptr Pointer to the number of elements in the array
* @param elem element to add * @param[in] elem Element to add
* @see av_dynarray_add_nofree(), av_dynarray2_add() * @see av_dynarray_add_nofree(), av_dynarray2_add()
*/ */
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem); void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
@ -299,107 +615,85 @@ void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
* but it doesn't free memory on fails. It returns error code * but it doesn't free memory on fails. It returns error code
* instead and leave current buffer untouched. * instead and leave current buffer untouched.
* *
* @param tab_ptr pointer to the array to grow * @return >=0 on success, negative otherwise
* @param nb_ptr pointer to the number of elements in the array
* @param elem element to add
* @return >=0 on success, negative otherwise.
* @see av_dynarray_add(), av_dynarray2_add() * @see av_dynarray_add(), av_dynarray2_add()
*/ */
av_warn_unused_result av_warn_unused_result
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem); int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem);
/** /**
* Add an element of size elem_size to a dynamic array. * Add an element of size `elem_size` to a dynamic array.
* *
* The array is reallocated when its number of elements reaches powers of 2. * The array is reallocated when its number of elements reaches powers of 2.
* Therefore, the amortized cost of adding an element is constant. * Therefore, the amortized cost of adding an element is constant.
* *
* In case of success, the pointer to the array is updated in order to * In case of success, the pointer to the array is updated in order to
* point to the new grown array, and the number pointed to by nb_ptr * point to the new grown array, and the number pointed to by `nb_ptr`
* is incremented. * is incremented.
* In case of failure, the array is freed, *tab_ptr is set to NULL and * In case of failure, the array is freed, `*tab_ptr` is set to `NULL` and
* *nb_ptr is set to 0. * `*nb_ptr` is set to 0.
* *
* @param tab_ptr pointer to the array to grow * @param[in,out] tab_ptr Pointer to the array to grow
* @param nb_ptr pointer to the number of elements in the array * @param[in,out] nb_ptr Pointer to the number of elements in the array
* @param elem_size size in bytes of the elements in the array * @param[in] elem_size Size in bytes of an element in the array
* @param elem_data pointer to the data of the element to add. If NULL, the space of * @param[in] elem_data Pointer to the data of the element to add. If
* the new added element is not filled. * `NULL`, the space of the newly added element is
* @return pointer to the data of the element to copy in the new allocated space. * allocated but left uninitialized.
* If NULL, the new allocated space is left uninitialized." *
* @return Pointer to the data of the element to copy in the newly allocated
* space
* @see av_dynarray_add(), av_dynarray_add_nofree() * @see av_dynarray_add(), av_dynarray_add_nofree()
*/ */
void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
const uint8_t *elem_data); const uint8_t *elem_data);
/** /**
* Multiply two size_t values checking for overflow. * @}
* @return 0 if success, AVERROR(EINVAL) if overflow.
*/
static inline int av_size_mult(size_t a, size_t b, size_t *r)
{
size_t t = a * b;
/* Hack inspired from glibc: only try the division if nelem and elsize
* are both greater than sqrt(SIZE_MAX). */
if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
return AVERROR(EINVAL);
*r = t;
return 0;
}
/**
* Set the maximum size that may me allocated in one block.
*/ */
void av_max_alloc(size_t max);
/** /**
* deliberately overlapping memcpy implementation * @defgroup lavu_mem_misc Miscellaneous Functions
* @param dst destination buffer *
* @param back how many bytes back we start (the initial size of the overlapping window), must be > 0 * Other functions related to memory allocation.
* @param cnt number of bytes to copy, must be >= 0
* *
* cnt > back is valid, this will copy the bytes we just copied, * @{
* thus creating a repeating pattern with a period length of back.
*/ */
void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
/** /**
* Reallocate the given block if it is not large enough, otherwise do nothing. * Multiply two `size_t` values checking for overflow.
* *
* @see av_realloc * @param[in] a,b Operands of multiplication
* @param[out] r Pointer to the result of the operation
* @return 0 on success, AVERROR(EINVAL) on overflow
*/ */
void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size); static inline int av_size_mult(size_t a, size_t b, size_t *r)
{
size_t t = a * b;
/* Hack inspired from glibc: don't try the division if nelem and elsize
* are both less than sqrt(SIZE_MAX). */
if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
return AVERROR(EINVAL);
*r = t;
return 0;
}
/** /**
* Allocate a buffer, reusing the given one if large enough. * Set the maximum size that may be allocated in one block.
* *
* Contrary to av_fast_realloc the current buffer contents might not be * The value specified with this function is effective for all libavutil's @ref
* preserved and on error the old buffer is freed, thus no special * lavu_mem_funcs "heap management functions."
* handling to avoid memleaks is necessary.
* *
* @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer * By default, the max value is defined as `INT_MAX`.
* @param size size of the buffer *ptr points to
* @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
* *size 0 if an error occurred.
*/
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
/**
* Allocate a buffer, reusing the given one if large enough.
* *
* All newly allocated space is initially cleared * @param max Value to be set as the new maximum size
* Contrary to av_fast_realloc the current buffer contents might not be
* preserved and on error the old buffer is freed, thus no special
* handling to avoid memleaks is necessary.
* *
* @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer * @warning Exercise extreme caution when using this function. Don't touch
* @param size size of the buffer *ptr points to * this if you do not understand the full consequence of doing so.
* @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
* *size 0 if an error occurred.
*/ */
void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size); void av_max_alloc(size_t max);
/** /**
* @}
* @} * @}
*/ */

@ -18,15 +18,103 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* @file
* @ingroup lavu_murmur3
* Public header for MurmurHash3 hash function implementation.
*/
#ifndef AVUTIL_MURMUR3_H #ifndef AVUTIL_MURMUR3_H
#define AVUTIL_MURMUR3_H #define AVUTIL_MURMUR3_H
#include <stdint.h> #include <stdint.h>
#include "version.h"
/**
* @defgroup lavu_murmur3 Murmur3
* @ingroup lavu_hash
* MurmurHash3 hash function implementation.
*
* MurmurHash3 is a non-cryptographic hash function, of which three
* incompatible versions were created by its inventor Austin Appleby:
*
* - 32-bit output
* - 128-bit output for 32-bit platforms
* - 128-bit output for 64-bit platforms
*
* FFmpeg only implements the last variant: 128-bit output designed for 64-bit
* platforms. Even though the hash function was designed for 64-bit platforms,
* the function in reality works on 32-bit systems too, only with reduced
* performance.
*
* @anchor lavu_murmur3_seedinfo
* By design, MurmurHash3 requires a seed to operate. In response to this,
* libavutil provides two functions for hash initiation, one that requires a
* seed (av_murmur3_init_seeded()) and one that uses a fixed arbitrary integer
* as the seed, and therefore does not (av_murmur3_init()).
*
* To make hashes comparable, you should provide the same seed for all calls to
* this hash function -- if you are supplying one yourself, that is.
*
* @{
*/
/**
* Allocate an AVMurMur3 hash context.
*
* @return Uninitialized hash context or `NULL` in case of error
*/
struct AVMurMur3 *av_murmur3_alloc(void); struct AVMurMur3 *av_murmur3_alloc(void);
/**
* Initialize or reinitialize an AVMurMur3 hash context with a seed.
*
* @param[out] c Hash context
* @param[in] seed Random seed
*
* @see av_murmur3_init()
* @see @ref lavu_murmur3_seedinfo "Detailed description" on a discussion of
* seeds for MurmurHash3.
*/
void av_murmur3_init_seeded(struct AVMurMur3 *c, uint64_t seed); void av_murmur3_init_seeded(struct AVMurMur3 *c, uint64_t seed);
/**
* Initialize or reinitialize an AVMurMur3 hash context.
*
* Equivalent to av_murmur3_init_seeded() with a built-in seed.
*
* @param[out] c Hash context
*
* @see av_murmur3_init_seeded()
* @see @ref lavu_murmur3_seedinfo "Detailed description" on a discussion of
* seeds for MurmurHash3.
*/
void av_murmur3_init(struct AVMurMur3 *c); void av_murmur3_init(struct AVMurMur3 *c);
/**
* Update hash context with new data.
*
* @param[out] c Hash context
* @param[in] src Input data to update hash with
* @param[in] len Number of bytes to read from `src`
*/
#if FF_API_CRYPTO_SIZE_T
void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, int len); void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, int len);
#else
void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, size_t len);
#endif
/**
* Finish hashing and output digest value.
*
* @param[in,out] c Hash context
* @param[out] dst Buffer where output digest value is stored
*/
void av_murmur3_final(struct AVMurMur3 *c, uint8_t dst[16]); void av_murmur3_final(struct AVMurMur3 *c, uint8_t dst[16]);
/**
* @}
*/
#endif /* AVUTIL_MURMUR3_H */ #endif /* AVUTIL_MURMUR3_H */

@ -228,15 +228,16 @@ enum AVOptionType{
AV_OPT_TYPE_RATIONAL, AV_OPT_TYPE_RATIONAL,
AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
AV_OPT_TYPE_DICT, AV_OPT_TYPE_DICT,
AV_OPT_TYPE_CONST = 128, AV_OPT_TYPE_UINT64,
AV_OPT_TYPE_IMAGE_SIZE = MKBETAG('S','I','Z','E'), ///< offset must point to two consecutive integers AV_OPT_TYPE_CONST,
AV_OPT_TYPE_PIXEL_FMT = MKBETAG('P','F','M','T'), AV_OPT_TYPE_IMAGE_SIZE, ///< offset must point to two consecutive integers
AV_OPT_TYPE_SAMPLE_FMT = MKBETAG('S','F','M','T'), AV_OPT_TYPE_PIXEL_FMT,
AV_OPT_TYPE_VIDEO_RATE = MKBETAG('V','R','A','T'), ///< offset must point to AVRational AV_OPT_TYPE_SAMPLE_FMT,
AV_OPT_TYPE_DURATION = MKBETAG('D','U','R',' '), AV_OPT_TYPE_VIDEO_RATE, ///< offset must point to AVRational
AV_OPT_TYPE_COLOR = MKBETAG('C','O','L','R'), AV_OPT_TYPE_DURATION,
AV_OPT_TYPE_CHANNEL_LAYOUT = MKBETAG('C','H','L','A'), AV_OPT_TYPE_COLOR,
AV_OPT_TYPE_BOOL = MKBETAG('B','O','O','L'), AV_OPT_TYPE_CHANNEL_LAYOUT,
AV_OPT_TYPE_BOOL,
}; };
/** /**
@ -274,14 +275,11 @@ typedef struct AVOption {
int flags; int flags;
#define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding #define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding
#define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding #define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding
#if FF_API_OPT_TYPE_METADATA
#define AV_OPT_FLAG_METADATA 4 ///< some data extracted or inserted into the file like title, comment, ...
#endif
#define AV_OPT_FLAG_AUDIO_PARAM 8 #define AV_OPT_FLAG_AUDIO_PARAM 8
#define AV_OPT_FLAG_VIDEO_PARAM 16 #define AV_OPT_FLAG_VIDEO_PARAM 16
#define AV_OPT_FLAG_SUBTITLE_PARAM 32 #define AV_OPT_FLAG_SUBTITLE_PARAM 32
/** /**
* The option is inteded for exporting values to the caller. * The option is intended for exporting values to the caller.
*/ */
#define AV_OPT_FLAG_EXPORT 64 #define AV_OPT_FLAG_EXPORT 64
/** /**
@ -289,7 +287,9 @@ typedef struct AVOption {
* This flag only makes sense when AV_OPT_FLAG_EXPORT is also set. * This flag only makes sense when AV_OPT_FLAG_EXPORT is also set.
*/ */
#define AV_OPT_FLAG_READONLY 128 #define AV_OPT_FLAG_READONLY 128
#define AV_OPT_FLAG_BSF_PARAM (1<<8) ///< a generic parameter which can be set by the user for bit stream filtering
#define AV_OPT_FLAG_FILTERING_PARAM (1<<16) ///< a generic parameter which can be set by the user for filtering #define AV_OPT_FLAG_FILTERING_PARAM (1<<16) ///< a generic parameter which can be set by the user for filtering
#define AV_OPT_FLAG_DEPRECATED (1<<17) ///< set if option is deprecated, users should refer to AVOption.help text for more information
//FIXME think about enc-audio, ... style flags //FIXME think about enc-audio, ... style flags
/** /**

@ -85,16 +85,16 @@ typedef struct AVPixFmtDescriptor {
/** /**
* Amount to shift the luma width right to find the chroma width. * Amount to shift the luma width right to find the chroma width.
* For YV12 this is 1 for example. * For YV12 this is 1 for example.
* chroma_width = -((-luma_width) >> log2_chroma_w) * chroma_width = AV_CEIL_RSHIFT(luma_width, log2_chroma_w)
* The note above is needed to ensure rounding up. * The note above is needed to ensure rounding up.
* This value only refers to the chroma components. * This value only refers to the chroma components.
*/ */
uint8_t log2_chroma_w; ///< chroma_width = -((-luma_width )>>log2_chroma_w) uint8_t log2_chroma_w;
/** /**
* Amount to shift the luma height right to find the chroma height. * Amount to shift the luma height right to find the chroma height.
* For YV12 this is 1 for example. * For YV12 this is 1 for example.
* chroma_height= -((-luma_height) >> log2_chroma_h) * chroma_height= AV_CEIL_RSHIFT(luma_height, log2_chroma_h)
* The note above is needed to ensure rounding up. * The note above is needed to ensure rounding up.
* This value only refers to the chroma components. * This value only refers to the chroma components.
*/ */
@ -154,17 +154,21 @@ typedef struct AVPixFmtDescriptor {
* in some cases be simpler. Or the data can be interpreted purely based on * in some cases be simpler. Or the data can be interpreted purely based on
* the pixel format without using the palette. * the pixel format without using the palette.
* An example of a pseudo-paletted format is AV_PIX_FMT_GRAY8 * An example of a pseudo-paletted format is AV_PIX_FMT_GRAY8
*
* @deprecated This flag is deprecated, and will be removed. When it is removed,
* the extra palette allocation in AVFrame.data[1] is removed as well. Only
* actual paletted formats (as indicated by AV_PIX_FMT_FLAG_PAL) will have a
* palette. Starting with FFmpeg versions which have this flag deprecated, the
* extra "pseudo" palette is already ignored, and API users are not required to
* allocate a palette for AV_PIX_FMT_FLAG_PSEUDOPAL formats (it was required
* before the deprecation, though).
*/ */
#define AV_PIX_FMT_FLAG_PSEUDOPAL (1 << 6) #define AV_PIX_FMT_FLAG_PSEUDOPAL (1 << 6)
/** /**
* The pixel format has an alpha channel. This is set on all formats that * The pixel format has an alpha channel. This is set on all formats that
* support alpha in some way. The exception is AV_PIX_FMT_PAL8, which can * support alpha in some way, including AV_PIX_FMT_PAL8. The alpha is always
* carry alpha as part of the palette. Details are explained in the * straight, never pre-multiplied.
* AVPixelFormat enum, and are also encoded in the corresponding
* AVPixFmtDescriptor.
*
* The alpha is always straight, never pre-multiplied.
* *
* If a codec or a filter does not support alpha, it should set all alpha to * If a codec or a filter does not support alpha, it should set all alpha to
* opaque, or use the equivalent pixel formats without alpha component, e.g. * opaque, or use the equivalent pixel formats without alpha component, e.g.
@ -173,76 +177,15 @@ typedef struct AVPixFmtDescriptor {
#define AV_PIX_FMT_FLAG_ALPHA (1 << 7) #define AV_PIX_FMT_FLAG_ALPHA (1 << 7)
/** /**
* Read a line from an image, and write the values of the * The pixel format is following a Bayer pattern
* pixel format component c to dst.
*
* @param data the array containing the pointers to the planes of the image
* @param linesize the array containing the linesizes of the image
* @param desc the pixel format descriptor for the image
* @param x the horizontal coordinate of the first pixel to read
* @param y the vertical coordinate of the first pixel to read
* @param w the width of the line to read, that is the number of
* values to write to dst
* @param read_pal_component if not zero and the format is a paletted
* format writes the values corresponding to the palette
* component c in data[1] to dst, rather than the palette indexes in
* data[0]. The behavior is undefined if the format is not paletted.
*/ */
void av_read_image_line(uint16_t *dst, const uint8_t *data[4], #define AV_PIX_FMT_FLAG_BAYER (1 << 8)
const int linesize[4], const AVPixFmtDescriptor *desc,
int x, int y, int c, int w, int read_pal_component);
/** /**
* Write the values from src to the pixel format component c of an * The pixel format contains IEEE-754 floating point values. Precision (double,
* image line. * single, or half) should be determined by the pixel size (64, 32, or 16 bits).
*
* @param src array containing the values to write
* @param data the array containing the pointers to the planes of the
* image to write into. It is supposed to be zeroed.
* @param linesize the array containing the linesizes of the image
* @param desc the pixel format descriptor for the image
* @param x the horizontal coordinate of the first pixel to write
* @param y the vertical coordinate of the first pixel to write
* @param w the width of the line to write, that is the number of
* values to write to the image line
*/
void av_write_image_line(const uint16_t *src, uint8_t *data[4],
const int linesize[4], const AVPixFmtDescriptor *desc,
int x, int y, int c, int w);
/**
* Return the pixel format corresponding to name.
*
* If there is no pixel format with name name, then looks for a
* pixel format with the name corresponding to the native endian
* format of name.
* For example in a little-endian system, first looks for "gray16",
* then for "gray16le".
*
* Finally if no pixel format has been found, returns AV_PIX_FMT_NONE.
*/ */
enum AVPixelFormat av_get_pix_fmt(const char *name); #define AV_PIX_FMT_FLAG_FLOAT (1 << 9)
/**
* Return the short name for a pixel format, NULL in case pix_fmt is
* unknown.
*
* @see av_get_pix_fmt(), av_get_pix_fmt_string()
*/
const char *av_get_pix_fmt_name(enum AVPixelFormat pix_fmt);
/**
* Print in buf the string corresponding to the pixel format with
* number pix_fmt, or a header if pix_fmt is negative.
*
* @param buf the buffer where to write the string
* @param buf_size the size of buf
* @param pix_fmt the number of the pixel format to print the
* corresponding info string, or a negative value to print the
* corresponding header.
*/
char *av_get_pix_fmt_string(char *buf, int buf_size,
enum AVPixelFormat pix_fmt);
/** /**
* Return the number of bits per pixel used by the pixel format * Return the number of bits per pixel used by the pixel format
@ -286,11 +229,6 @@ enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc);
* Utility function to access log2_chroma_w log2_chroma_h from * Utility function to access log2_chroma_w log2_chroma_h from
* the pixel format AVPixFmtDescriptor. * the pixel format AVPixFmtDescriptor.
* *
* See av_get_chroma_sub_sample() for a function that asserts a
* valid pixel format instead of returning an error code.
* Its recommended that you use avcodec_get_chroma_sub_sample unless
* you do check the return code!
*
* @param[in] pix_fmt the pixel format * @param[in] pix_fmt the pixel format
* @param[out] h_shift store log2_chroma_w (horizontal/width shift) * @param[out] h_shift store log2_chroma_w (horizontal/width shift)
* @param[out] v_shift store log2_chroma_h (vertical/height shift) * @param[out] v_shift store log2_chroma_h (vertical/height shift)
@ -306,6 +244,139 @@ int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt,
*/ */
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt); int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt);
/**
* @return the name for provided color range or NULL if unknown.
*/
const char *av_color_range_name(enum AVColorRange range);
/**
* @return the AVColorRange value for name or an AVError if not found.
*/
int av_color_range_from_name(const char *name);
/**
* @return the name for provided color primaries or NULL if unknown.
*/
const char *av_color_primaries_name(enum AVColorPrimaries primaries);
/**
* @return the AVColorPrimaries value for name or an AVError if not found.
*/
int av_color_primaries_from_name(const char *name);
/**
* @return the name for provided color transfer or NULL if unknown.
*/
const char *av_color_transfer_name(enum AVColorTransferCharacteristic transfer);
/**
* @return the AVColorTransferCharacteristic value for name or an AVError if not found.
*/
int av_color_transfer_from_name(const char *name);
/**
* @return the name for provided color space or NULL if unknown.
*/
const char *av_color_space_name(enum AVColorSpace space);
/**
* @return the AVColorSpace value for name or an AVError if not found.
*/
int av_color_space_from_name(const char *name);
/**
* @return the name for provided chroma location or NULL if unknown.
*/
const char *av_chroma_location_name(enum AVChromaLocation location);
/**
* @return the AVChromaLocation value for name or an AVError if not found.
*/
int av_chroma_location_from_name(const char *name);
/**
* Return the pixel format corresponding to name.
*
* If there is no pixel format with name name, then looks for a
* pixel format with the name corresponding to the native endian
* format of name.
* For example in a little-endian system, first looks for "gray16",
* then for "gray16le".
*
* Finally if no pixel format has been found, returns AV_PIX_FMT_NONE.
*/
enum AVPixelFormat av_get_pix_fmt(const char *name);
/**
* Return the short name for a pixel format, NULL in case pix_fmt is
* unknown.
*
* @see av_get_pix_fmt(), av_get_pix_fmt_string()
*/
const char *av_get_pix_fmt_name(enum AVPixelFormat pix_fmt);
/**
* Print in buf the string corresponding to the pixel format with
* number pix_fmt, or a header if pix_fmt is negative.
*
* @param buf the buffer where to write the string
* @param buf_size the size of buf
* @param pix_fmt the number of the pixel format to print the
* corresponding info string, or a negative value to print the
* corresponding header.
*/
char *av_get_pix_fmt_string(char *buf, int buf_size,
enum AVPixelFormat pix_fmt);
/**
* Read a line from an image, and write the values of the
* pixel format component c to dst.
*
* @param data the array containing the pointers to the planes of the image
* @param linesize the array containing the linesizes of the image
* @param desc the pixel format descriptor for the image
* @param x the horizontal coordinate of the first pixel to read
* @param y the vertical coordinate of the first pixel to read
* @param w the width of the line to read, that is the number of
* values to write to dst
* @param read_pal_component if not zero and the format is a paletted
* format writes the values corresponding to the palette
* component c in data[1] to dst, rather than the palette indexes in
* data[0]. The behavior is undefined if the format is not paletted.
* @param dst_element_size size of elements in dst array (2 or 4 byte)
*/
void av_read_image_line2(void *dst, const uint8_t *data[4],
const int linesize[4], const AVPixFmtDescriptor *desc,
int x, int y, int c, int w, int read_pal_component,
int dst_element_size);
void av_read_image_line(uint16_t *dst, const uint8_t *data[4],
const int linesize[4], const AVPixFmtDescriptor *desc,
int x, int y, int c, int w, int read_pal_component);
/**
* Write the values from src to the pixel format component c of an
* image line.
*
* @param src array containing the values to write
* @param data the array containing the pointers to the planes of the
* image to write into. It is supposed to be zeroed.
* @param linesize the array containing the linesizes of the image
* @param desc the pixel format descriptor for the image
* @param x the horizontal coordinate of the first pixel to write
* @param y the vertical coordinate of the first pixel to write
* @param w the width of the line to write, that is the number of
* values to write to the image line
* @param src_element_size size of elements in src array (2 or 4 byte)
*/
void av_write_image_line2(const void *src, uint8_t *data[4],
const int linesize[4], const AVPixFmtDescriptor *desc,
int x, int y, int c, int w, int src_element_size);
void av_write_image_line(const uint16_t *src, uint8_t *data[4],
const int linesize[4], const AVPixFmtDescriptor *desc,
int x, int y, int c, int w);
/** /**
* Utility function to swap the endianness of a pixel format. * Utility function to swap the endianness of a pixel format.
* *
@ -366,29 +437,4 @@ int av_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt,
enum AVPixelFormat av_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2, enum AVPixelFormat av_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2,
enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr); enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr);
/**
* @return the name for provided color range or NULL if unknown.
*/
const char *av_color_range_name(enum AVColorRange range);
/**
* @return the name for provided color primaries or NULL if unknown.
*/
const char *av_color_primaries_name(enum AVColorPrimaries primaries);
/**
* @return the name for provided color transfer or NULL if unknown.
*/
const char *av_color_transfer_name(enum AVColorTransferCharacteristic transfer);
/**
* @return the name for provided color space or NULL if unknown.
*/
const char *av_color_space_name(enum AVColorSpace space);
/**
* @return the name for provided chroma location or NULL if unknown.
*/
const char *av_chroma_location_name(enum AVChromaLocation location);
#endif /* AVUTIL_PIXDESC_H */ #endif /* AVUTIL_PIXDESC_H */

@ -24,7 +24,6 @@
/** /**
* @file * @file
* pixel format definitions * pixel format definitions
*
*/ */
#include "libavutil/avconfig.h" #include "libavutil/avconfig.h"
@ -43,6 +42,10 @@
* This is stored as BGRA on little-endian CPU architectures and ARGB on * This is stored as BGRA on little-endian CPU architectures and ARGB on
* big-endian CPUs. * big-endian CPUs.
* *
* @note
* If the resolution is not a multiple of the chroma subsampling factor
* then the chroma plane resolution must be rounded up.
*
* @par * @par
* When the pixel format is palettized RGB32 (AV_PIX_FMT_PAL8), the palettized * When the pixel format is palettized RGB32 (AV_PIX_FMT_PAL8), the palettized
* image data is stored in AVFrame.data[0]. The palette is transported in * image data is stored in AVFrame.data[0]. The palette is transported in
@ -54,7 +57,7 @@
* to run on the IBM VGA graphics adapter use 6-bit palette components. * to run on the IBM VGA graphics adapter use 6-bit palette components.
* *
* @par * @par
* For all the 8bit per pixel formats, an RGB32 palette is in data[1] like * For all the 8 bits per pixel formats, an RGB32 palette is in data[1] like
* for pal8. This palette is filled in automatically by the function * for pal8. This palette is filled in automatically by the function
* allocating the picture. * allocating the picture.
*/ */
@ -71,15 +74,10 @@ enum AVPixelFormat {
AV_PIX_FMT_GRAY8, ///< Y , 8bpp AV_PIX_FMT_GRAY8, ///< Y , 8bpp
AV_PIX_FMT_MONOWHITE, ///< Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb AV_PIX_FMT_MONOWHITE, ///< Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb
AV_PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb AV_PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb
AV_PIX_FMT_PAL8, ///< 8 bit with AV_PIX_FMT_RGB32 palette AV_PIX_FMT_PAL8, ///< 8 bits with AV_PIX_FMT_RGB32 palette
AV_PIX_FMT_YUVJ420P, ///< planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting color_range AV_PIX_FMT_YUVJ420P, ///< planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting color_range
AV_PIX_FMT_YUVJ422P, ///< planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting color_range AV_PIX_FMT_YUVJ422P, ///< planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting color_range
AV_PIX_FMT_YUVJ444P, ///< planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting color_range AV_PIX_FMT_YUVJ444P, ///< planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting color_range
#if FF_API_XVMC
AV_PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing
AV_PIX_FMT_XVMC_MPEG2_IDCT,
#define AV_PIX_FMT_XVMC AV_PIX_FMT_XVMC_MPEG2_IDCT
#endif /* FF_API_XVMC */
AV_PIX_FMT_UYVY422, ///< packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1 AV_PIX_FMT_UYVY422, ///< packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
AV_PIX_FMT_UYYVYY411, ///< packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3 AV_PIX_FMT_UYYVYY411, ///< packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
AV_PIX_FMT_BGR8, ///< packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb) AV_PIX_FMT_BGR8, ///< packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
@ -101,13 +99,6 @@ enum AVPixelFormat {
AV_PIX_FMT_YUV440P, ///< planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples) AV_PIX_FMT_YUV440P, ///< planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
AV_PIX_FMT_YUVJ440P, ///< planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range AV_PIX_FMT_YUVJ440P, ///< planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
AV_PIX_FMT_YUVA420P, ///< planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples) AV_PIX_FMT_YUVA420P, ///< planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#if FF_API_VDPAU
AV_PIX_FMT_VDPAU_H264,///< H.264 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
AV_PIX_FMT_VDPAU_MPEG1,///< MPEG-1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
AV_PIX_FMT_VDPAU_MPEG2,///< MPEG-2 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
AV_PIX_FMT_VDPAU_WMV3,///< WMV3 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
AV_PIX_FMT_VDPAU_VC1, ///< VC-1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
#endif
AV_PIX_FMT_RGB48BE, ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big-endian AV_PIX_FMT_RGB48BE, ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big-endian
AV_PIX_FMT_RGB48LE, ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as little-endian AV_PIX_FMT_RGB48LE, ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as little-endian
@ -126,7 +117,7 @@ enum AVPixelFormat {
/**@{*/ /**@{*/
AV_PIX_FMT_VAAPI_MOCO, ///< HW acceleration through VA API at motion compensation entry-point, Picture.data[3] contains a vaapi_render_state struct which contains macroblocks as well as various fields extracted from headers AV_PIX_FMT_VAAPI_MOCO, ///< HW acceleration through VA API at motion compensation entry-point, Picture.data[3] contains a vaapi_render_state struct which contains macroblocks as well as various fields extracted from headers
AV_PIX_FMT_VAAPI_IDCT, ///< HW acceleration through VA API at IDCT entry-point, Picture.data[3] contains a vaapi_render_state struct which contains fields extracted from headers AV_PIX_FMT_VAAPI_IDCT, ///< HW acceleration through VA API at IDCT entry-point, Picture.data[3] contains a vaapi_render_state struct which contains fields extracted from headers
AV_PIX_FMT_VAAPI_VLD, ///< HW decoding through VA API, Picture.data[3] contains a vaapi_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers AV_PIX_FMT_VAAPI_VLD, ///< HW decoding through VA API, Picture.data[3] contains a VASurfaceID
/**@}*/ /**@}*/
AV_PIX_FMT_VAAPI = AV_PIX_FMT_VAAPI_VLD, AV_PIX_FMT_VAAPI = AV_PIX_FMT_VAAPI_VLD,
#else #else
@ -143,16 +134,13 @@ enum AVPixelFormat {
AV_PIX_FMT_YUV422P16BE, ///< planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian AV_PIX_FMT_YUV422P16BE, ///< planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
AV_PIX_FMT_YUV444P16LE, ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian AV_PIX_FMT_YUV444P16LE, ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
AV_PIX_FMT_YUV444P16BE, ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian AV_PIX_FMT_YUV444P16BE, ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
#if FF_API_VDPAU
AV_PIX_FMT_VDPAU_MPEG4, ///< MPEG4 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
#endif
AV_PIX_FMT_DXVA2_VLD, ///< HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer AV_PIX_FMT_DXVA2_VLD, ///< HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer
AV_PIX_FMT_RGB444LE, ///< packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), little-endian, X=unused/undefined AV_PIX_FMT_RGB444LE, ///< packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), little-endian, X=unused/undefined
AV_PIX_FMT_RGB444BE, ///< packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), big-endian, X=unused/undefined AV_PIX_FMT_RGB444BE, ///< packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), big-endian, X=unused/undefined
AV_PIX_FMT_BGR444LE, ///< packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), little-endian, X=unused/undefined AV_PIX_FMT_BGR444LE, ///< packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), little-endian, X=unused/undefined
AV_PIX_FMT_BGR444BE, ///< packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), big-endian, X=unused/undefined AV_PIX_FMT_BGR444BE, ///< packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), big-endian, X=unused/undefined
AV_PIX_FMT_YA8, ///< 8bit gray, 8bit alpha AV_PIX_FMT_YA8, ///< 8 bits gray, 8 bits alpha
AV_PIX_FMT_Y400A = AV_PIX_FMT_YA8, ///< alias for AV_PIX_FMT_YA8 AV_PIX_FMT_Y400A = AV_PIX_FMT_YA8, ///< alias for AV_PIX_FMT_YA8
AV_PIX_FMT_GRAY8A= AV_PIX_FMT_YA8, ///< alias for AV_PIX_FMT_YA8 AV_PIX_FMT_GRAY8A= AV_PIX_FMT_YA8, ///< alias for AV_PIX_FMT_YA8
@ -177,8 +165,8 @@ enum AVPixelFormat {
AV_PIX_FMT_YUV444P10LE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian AV_PIX_FMT_YUV444P10LE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
AV_PIX_FMT_YUV422P9BE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian AV_PIX_FMT_YUV422P9BE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
AV_PIX_FMT_YUV422P9LE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian AV_PIX_FMT_YUV422P9LE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
AV_PIX_FMT_VDA_VLD, ///< hardware decoding through VDA
AV_PIX_FMT_GBRP, ///< planar GBR 4:4:4 24bpp AV_PIX_FMT_GBRP, ///< planar GBR 4:4:4 24bpp
AV_PIX_FMT_GBR24P = AV_PIX_FMT_GBRP, // alias for #AV_PIX_FMT_GBRP
AV_PIX_FMT_GBRP9BE, ///< planar GBR 4:4:4 27bpp, big-endian AV_PIX_FMT_GBRP9BE, ///< planar GBR 4:4:4 27bpp, big-endian
AV_PIX_FMT_GBRP9LE, ///< planar GBR 4:4:4 27bpp, little-endian AV_PIX_FMT_GBRP9LE, ///< planar GBR 4:4:4 27bpp, little-endian
AV_PIX_FMT_GBRP10BE, ///< planar GBR 4:4:4 30bpp, big-endian AV_PIX_FMT_GBRP10BE, ///< planar GBR 4:4:4 30bpp, big-endian
@ -221,10 +209,8 @@ enum AVPixelFormat {
AV_PIX_FMT_YVYU422, ///< packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb AV_PIX_FMT_YVYU422, ///< packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
AV_PIX_FMT_VDA, ///< HW acceleration through VDA, data[3] contains a CVPixelBufferRef AV_PIX_FMT_YA16BE, ///< 16 bits gray, 16 bits alpha (big-endian)
AV_PIX_FMT_YA16LE, ///< 16 bits gray, 16 bits alpha (little-endian)
AV_PIX_FMT_YA16BE, ///< 16bit gray, 16bit alpha (big-endian)
AV_PIX_FMT_YA16LE, ///< 16bit gray, 16bit alpha (little-endian)
AV_PIX_FMT_GBRAP, ///< planar GBRA 4:4:4:4 32bpp AV_PIX_FMT_GBRAP, ///< planar GBRA 4:4:4:4 32bpp
AV_PIX_FMT_GBRAP16BE, ///< planar GBRA 4:4:4:4 64bpp, big-endian AV_PIX_FMT_GBRAP16BE, ///< planar GBRA 4:4:4:4 64bpp, big-endian
@ -240,9 +226,15 @@ enum AVPixelFormat {
*/ */
AV_PIX_FMT_MMAL, AV_PIX_FMT_MMAL,
AV_PIX_FMT_D3D11VA_VLD, ///< HW decoding through Direct3D11, Picture.data[3] contains a ID3D11VideoDecoderOutputView pointer AV_PIX_FMT_D3D11VA_VLD, ///< HW decoding through Direct3D11 via old API, Picture.data[3] contains a ID3D11VideoDecoderOutputView pointer
/**
* HW acceleration through CUDA. data[i] contain CUdeviceptr pointers
* exactly as for system memory frames.
*/
AV_PIX_FMT_CUDA,
AV_PIX_FMT_0RGB=0x123+4,///< packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined AV_PIX_FMT_0RGB, ///< packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
AV_PIX_FMT_RGB0, ///< packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined AV_PIX_FMT_RGB0, ///< packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
AV_PIX_FMT_0BGR, ///< packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined AV_PIX_FMT_0BGR, ///< packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
AV_PIX_FMT_BGR0, ///< packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined AV_PIX_FMT_BGR0, ///< packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ -277,9 +269,9 @@ enum AVPixelFormat {
AV_PIX_FMT_BAYER_GBRG16BE, ///< bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, big-endian */ AV_PIX_FMT_BAYER_GBRG16BE, ///< bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, big-endian */
AV_PIX_FMT_BAYER_GRBG16LE, ///< bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, little-endian */ AV_PIX_FMT_BAYER_GRBG16LE, ///< bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, little-endian */
AV_PIX_FMT_BAYER_GRBG16BE, ///< bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, big-endian */ AV_PIX_FMT_BAYER_GRBG16BE, ///< bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, big-endian */
#if !FF_API_XVMC
AV_PIX_FMT_XVMC,///< XVideo Motion Acceleration via common packet passing AV_PIX_FMT_XVMC,///< XVideo Motion Acceleration via common packet passing
#endif /* !FF_API_XVMC */
AV_PIX_FMT_YUV440P10LE, ///< planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian AV_PIX_FMT_YUV440P10LE, ///< planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
AV_PIX_FMT_YUV440P10BE, ///< planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian AV_PIX_FMT_YUV440P10BE, ///< planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian
AV_PIX_FMT_YUV440P12LE, ///< planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian AV_PIX_FMT_YUV440P12LE, ///< planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
@ -292,11 +284,72 @@ enum AVPixelFormat {
AV_PIX_FMT_P010LE, ///< like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, little-endian AV_PIX_FMT_P010LE, ///< like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, little-endian
AV_PIX_FMT_P010BE, ///< like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, big-endian AV_PIX_FMT_P010BE, ///< like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, big-endian
AV_PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions AV_PIX_FMT_GBRAP12BE, ///< planar GBR 4:4:4:4 48bpp, big-endian
}; AV_PIX_FMT_GBRAP12LE, ///< planar GBR 4:4:4:4 48bpp, little-endian
AV_PIX_FMT_GBRAP10BE, ///< planar GBR 4:4:4:4 40bpp, big-endian
AV_PIX_FMT_GBRAP10LE, ///< planar GBR 4:4:4:4 40bpp, little-endian
#define AV_PIX_FMT_Y400A AV_PIX_FMT_GRAY8A AV_PIX_FMT_MEDIACODEC, ///< hardware decoding through MediaCodec
#define AV_PIX_FMT_GBR24P AV_PIX_FMT_GBRP
AV_PIX_FMT_GRAY12BE, ///< Y , 12bpp, big-endian
AV_PIX_FMT_GRAY12LE, ///< Y , 12bpp, little-endian
AV_PIX_FMT_GRAY10BE, ///< Y , 10bpp, big-endian
AV_PIX_FMT_GRAY10LE, ///< Y , 10bpp, little-endian
AV_PIX_FMT_P016LE, ///< like NV12, with 16bpp per component, little-endian
AV_PIX_FMT_P016BE, ///< like NV12, with 16bpp per component, big-endian
/**
* Hardware surfaces for Direct3D11.
*
* This is preferred over the legacy AV_PIX_FMT_D3D11VA_VLD. The new D3D11
* hwaccel API and filtering support AV_PIX_FMT_D3D11 only.
*
* data[0] contains a ID3D11Texture2D pointer, and data[1] contains the
* texture array index of the frame as intptr_t if the ID3D11Texture2D is
* an array texture (or always 0 if it's a normal texture).
*/
AV_PIX_FMT_D3D11,
AV_PIX_FMT_GRAY9BE, ///< Y , 9bpp, big-endian
AV_PIX_FMT_GRAY9LE, ///< Y , 9bpp, little-endian
AV_PIX_FMT_GBRPF32BE, ///< IEEE-754 single precision planar GBR 4:4:4, 96bpp, big-endian
AV_PIX_FMT_GBRPF32LE, ///< IEEE-754 single precision planar GBR 4:4:4, 96bpp, little-endian
AV_PIX_FMT_GBRAPF32BE, ///< IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, big-endian
AV_PIX_FMT_GBRAPF32LE, ///< IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, little-endian
/**
* DRM-managed buffers exposed through PRIME buffer sharing.
*
* data[0] points to an AVDRMFrameDescriptor.
*/
AV_PIX_FMT_DRM_PRIME,
/**
* Hardware surfaces for OpenCL.
*
* data[i] contain 2D image objects (typed in C as cl_mem, used
* in OpenCL as image2d_t) for each plane of the surface.
*/
AV_PIX_FMT_OPENCL,
AV_PIX_FMT_GRAY14BE, ///< Y , 14bpp, big-endian
AV_PIX_FMT_GRAY14LE, ///< Y , 14bpp, little-endian
AV_PIX_FMT_GRAYF32BE, ///< IEEE-754 single precision Y, 32bpp, big-endian
AV_PIX_FMT_GRAYF32LE, ///< IEEE-754 single precision Y, 32bpp, little-endian
AV_PIX_FMT_YUVA422P12BE, ///< planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), 12b alpha, big-endian
AV_PIX_FMT_YUVA422P12LE, ///< planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), 12b alpha, little-endian
AV_PIX_FMT_YUVA444P12BE, ///< planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), 12b alpha, big-endian
AV_PIX_FMT_YUVA444P12LE, ///< planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), 12b alpha, little-endian
AV_PIX_FMT_NV24, ///< planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (first byte U and the following byte V)
AV_PIX_FMT_NV42, ///< as above, but U and V bytes are swapped
AV_PIX_FMT_NB ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
};
#if AV_HAVE_BIGENDIAN #if AV_HAVE_BIGENDIAN
# define AV_PIX_FMT_NE(be, le) AV_PIX_FMT_##be # define AV_PIX_FMT_NE(be, le) AV_PIX_FMT_##be
@ -311,6 +364,10 @@ enum AVPixelFormat {
#define AV_PIX_FMT_0RGB32 AV_PIX_FMT_NE(0RGB, BGR0) #define AV_PIX_FMT_0RGB32 AV_PIX_FMT_NE(0RGB, BGR0)
#define AV_PIX_FMT_0BGR32 AV_PIX_FMT_NE(0BGR, RGB0) #define AV_PIX_FMT_0BGR32 AV_PIX_FMT_NE(0BGR, RGB0)
#define AV_PIX_FMT_GRAY9 AV_PIX_FMT_NE(GRAY9BE, GRAY9LE)
#define AV_PIX_FMT_GRAY10 AV_PIX_FMT_NE(GRAY10BE, GRAY10LE)
#define AV_PIX_FMT_GRAY12 AV_PIX_FMT_NE(GRAY12BE, GRAY12LE)
#define AV_PIX_FMT_GRAY14 AV_PIX_FMT_NE(GRAY14BE, GRAY14LE)
#define AV_PIX_FMT_GRAY16 AV_PIX_FMT_NE(GRAY16BE, GRAY16LE) #define AV_PIX_FMT_GRAY16 AV_PIX_FMT_NE(GRAY16BE, GRAY16LE)
#define AV_PIX_FMT_YA16 AV_PIX_FMT_NE(YA16BE, YA16LE) #define AV_PIX_FMT_YA16 AV_PIX_FMT_NE(YA16BE, YA16LE)
#define AV_PIX_FMT_RGB48 AV_PIX_FMT_NE(RGB48BE, RGB48LE) #define AV_PIX_FMT_RGB48 AV_PIX_FMT_NE(RGB48BE, RGB48LE)
@ -347,6 +404,8 @@ enum AVPixelFormat {
#define AV_PIX_FMT_GBRP12 AV_PIX_FMT_NE(GBRP12BE, GBRP12LE) #define AV_PIX_FMT_GBRP12 AV_PIX_FMT_NE(GBRP12BE, GBRP12LE)
#define AV_PIX_FMT_GBRP14 AV_PIX_FMT_NE(GBRP14BE, GBRP14LE) #define AV_PIX_FMT_GBRP14 AV_PIX_FMT_NE(GBRP14BE, GBRP14LE)
#define AV_PIX_FMT_GBRP16 AV_PIX_FMT_NE(GBRP16BE, GBRP16LE) #define AV_PIX_FMT_GBRP16 AV_PIX_FMT_NE(GBRP16BE, GBRP16LE)
#define AV_PIX_FMT_GBRAP10 AV_PIX_FMT_NE(GBRAP10BE, GBRAP10LE)
#define AV_PIX_FMT_GBRAP12 AV_PIX_FMT_NE(GBRAP12BE, GBRAP12LE)
#define AV_PIX_FMT_GBRAP16 AV_PIX_FMT_NE(GBRAP16BE, GBRAP16LE) #define AV_PIX_FMT_GBRAP16 AV_PIX_FMT_NE(GBRAP16BE, GBRAP16LE)
#define AV_PIX_FMT_BAYER_BGGR16 AV_PIX_FMT_NE(BAYER_BGGR16BE, BAYER_BGGR16LE) #define AV_PIX_FMT_BAYER_BGGR16 AV_PIX_FMT_NE(BAYER_BGGR16BE, BAYER_BGGR16LE)
@ -354,6 +413,10 @@ enum AVPixelFormat {
#define AV_PIX_FMT_BAYER_GBRG16 AV_PIX_FMT_NE(BAYER_GBRG16BE, BAYER_GBRG16LE) #define AV_PIX_FMT_BAYER_GBRG16 AV_PIX_FMT_NE(BAYER_GBRG16BE, BAYER_GBRG16LE)
#define AV_PIX_FMT_BAYER_GRBG16 AV_PIX_FMT_NE(BAYER_GRBG16BE, BAYER_GRBG16LE) #define AV_PIX_FMT_BAYER_GRBG16 AV_PIX_FMT_NE(BAYER_GRBG16BE, BAYER_GRBG16LE)
#define AV_PIX_FMT_GBRPF32 AV_PIX_FMT_NE(GBRPF32BE, GBRPF32LE)
#define AV_PIX_FMT_GBRAPF32 AV_PIX_FMT_NE(GBRAPF32BE, GBRAPF32LE)
#define AV_PIX_FMT_GRAYF32 AV_PIX_FMT_NE(GRAYF32BE, GRAYF32LE)
#define AV_PIX_FMT_YUVA420P9 AV_PIX_FMT_NE(YUVA420P9BE , YUVA420P9LE) #define AV_PIX_FMT_YUVA420P9 AV_PIX_FMT_NE(YUVA420P9BE , YUVA420P9LE)
#define AV_PIX_FMT_YUVA422P9 AV_PIX_FMT_NE(YUVA422P9BE , YUVA422P9LE) #define AV_PIX_FMT_YUVA422P9 AV_PIX_FMT_NE(YUVA422P9BE , YUVA422P9LE)
@ -361,6 +424,8 @@ enum AVPixelFormat {
#define AV_PIX_FMT_YUVA420P10 AV_PIX_FMT_NE(YUVA420P10BE, YUVA420P10LE) #define AV_PIX_FMT_YUVA420P10 AV_PIX_FMT_NE(YUVA420P10BE, YUVA420P10LE)
#define AV_PIX_FMT_YUVA422P10 AV_PIX_FMT_NE(YUVA422P10BE, YUVA422P10LE) #define AV_PIX_FMT_YUVA422P10 AV_PIX_FMT_NE(YUVA422P10BE, YUVA422P10LE)
#define AV_PIX_FMT_YUVA444P10 AV_PIX_FMT_NE(YUVA444P10BE, YUVA444P10LE) #define AV_PIX_FMT_YUVA444P10 AV_PIX_FMT_NE(YUVA444P10BE, YUVA444P10LE)
#define AV_PIX_FMT_YUVA422P12 AV_PIX_FMT_NE(YUVA422P12BE, YUVA422P12LE)
#define AV_PIX_FMT_YUVA444P12 AV_PIX_FMT_NE(YUVA444P12BE, YUVA444P12LE)
#define AV_PIX_FMT_YUVA420P16 AV_PIX_FMT_NE(YUVA420P16BE, YUVA420P16LE) #define AV_PIX_FMT_YUVA420P16 AV_PIX_FMT_NE(YUVA420P16BE, YUVA420P16LE)
#define AV_PIX_FMT_YUVA422P16 AV_PIX_FMT_NE(YUVA422P16BE, YUVA422P16LE) #define AV_PIX_FMT_YUVA422P16 AV_PIX_FMT_NE(YUVA422P16BE, YUVA422P16LE)
#define AV_PIX_FMT_YUVA444P16 AV_PIX_FMT_NE(YUVA444P16BE, YUVA444P16LE) #define AV_PIX_FMT_YUVA444P16 AV_PIX_FMT_NE(YUVA444P16BE, YUVA444P16LE)
@ -369,9 +434,11 @@ enum AVPixelFormat {
#define AV_PIX_FMT_NV20 AV_PIX_FMT_NE(NV20BE, NV20LE) #define AV_PIX_FMT_NV20 AV_PIX_FMT_NE(NV20BE, NV20LE)
#define AV_PIX_FMT_AYUV64 AV_PIX_FMT_NE(AYUV64BE, AYUV64LE) #define AV_PIX_FMT_AYUV64 AV_PIX_FMT_NE(AYUV64BE, AYUV64LE)
#define AV_PIX_FMT_P010 AV_PIX_FMT_NE(P010BE, P010LE) #define AV_PIX_FMT_P010 AV_PIX_FMT_NE(P010BE, P010LE)
#define AV_PIX_FMT_P016 AV_PIX_FMT_NE(P016BE, P016LE)
/** /**
* Chromaticity coordinates of the source primaries. * Chromaticity coordinates of the source primaries.
* These values match the ones defined by ISO/IEC 23001-8_2013 § 7.1.
*/ */
enum AVColorPrimaries { enum AVColorPrimaries {
AVCOL_PRI_RESERVED0 = 0, AVCOL_PRI_RESERVED0 = 0,
@ -385,12 +452,17 @@ enum AVColorPrimaries {
AVCOL_PRI_SMPTE240M = 7, ///< functionally identical to above AVCOL_PRI_SMPTE240M = 7, ///< functionally identical to above
AVCOL_PRI_FILM = 8, ///< colour filters using Illuminant C AVCOL_PRI_FILM = 8, ///< colour filters using Illuminant C
AVCOL_PRI_BT2020 = 9, ///< ITU-R BT2020 AVCOL_PRI_BT2020 = 9, ///< ITU-R BT2020
AVCOL_PRI_SMPTEST428_1= 10, ///< SMPTE ST 428-1 (CIE 1931 XYZ) AVCOL_PRI_SMPTE428 = 10, ///< SMPTE ST 428-1 (CIE 1931 XYZ)
AVCOL_PRI_NB, ///< Not part of ABI AVCOL_PRI_SMPTEST428_1 = AVCOL_PRI_SMPTE428,
AVCOL_PRI_SMPTE431 = 11, ///< SMPTE ST 431-2 (2011) / DCI P3
AVCOL_PRI_SMPTE432 = 12, ///< SMPTE ST 432-1 (2010) / P3 D65 / Display P3
AVCOL_PRI_JEDEC_P22 = 22, ///< JEDEC P22 phosphors
AVCOL_PRI_NB ///< Not part of ABI
}; };
/** /**
* Color Transfer Characteristic. * Color Transfer Characteristic.
* These values match the ones defined by ISO/IEC 23001-8_2013 § 7.2.
*/ */
enum AVColorTransferCharacteristic { enum AVColorTransferCharacteristic {
AVCOL_TRC_RESERVED0 = 0, AVCOL_TRC_RESERVED0 = 0,
@ -407,15 +479,19 @@ enum AVColorTransferCharacteristic {
AVCOL_TRC_IEC61966_2_4 = 11, ///< IEC 61966-2-4 AVCOL_TRC_IEC61966_2_4 = 11, ///< IEC 61966-2-4
AVCOL_TRC_BT1361_ECG = 12, ///< ITU-R BT1361 Extended Colour Gamut AVCOL_TRC_BT1361_ECG = 12, ///< ITU-R BT1361 Extended Colour Gamut
AVCOL_TRC_IEC61966_2_1 = 13, ///< IEC 61966-2-1 (sRGB or sYCC) AVCOL_TRC_IEC61966_2_1 = 13, ///< IEC 61966-2-1 (sRGB or sYCC)
AVCOL_TRC_BT2020_10 = 14, ///< ITU-R BT2020 for 10 bit system AVCOL_TRC_BT2020_10 = 14, ///< ITU-R BT2020 for 10-bit system
AVCOL_TRC_BT2020_12 = 15, ///< ITU-R BT2020 for 12 bit system AVCOL_TRC_BT2020_12 = 15, ///< ITU-R BT2020 for 12-bit system
AVCOL_TRC_SMPTEST2084 = 16, ///< SMPTE ST 2084 for 10, 12, 14 and 16 bit systems AVCOL_TRC_SMPTE2084 = 16, ///< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems
AVCOL_TRC_SMPTEST428_1 = 17, ///< SMPTE ST 428-1 AVCOL_TRC_SMPTEST2084 = AVCOL_TRC_SMPTE2084,
AVCOL_TRC_NB, ///< Not part of ABI AVCOL_TRC_SMPTE428 = 17, ///< SMPTE ST 428-1
AVCOL_TRC_SMPTEST428_1 = AVCOL_TRC_SMPTE428,
AVCOL_TRC_ARIB_STD_B67 = 18, ///< ARIB STD-B67, known as "Hybrid log-gamma"
AVCOL_TRC_NB ///< Not part of ABI
}; };
/** /**
* YUV colorspace type. * YUV colorspace type.
* These values match the ones defined by ISO/IEC 23001-8_2013 § 7.3.
*/ */
enum AVColorSpace { enum AVColorSpace {
AVCOL_SPC_RGB = 0, ///< order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB) AVCOL_SPC_RGB = 0, ///< order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
@ -424,15 +500,18 @@ enum AVColorSpace {
AVCOL_SPC_RESERVED = 3, AVCOL_SPC_RESERVED = 3,
AVCOL_SPC_FCC = 4, ///< FCC Title 47 Code of Federal Regulations 73.682 (a)(20) AVCOL_SPC_FCC = 4, ///< FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
AVCOL_SPC_BT470BG = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 AVCOL_SPC_BT470BG = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
AVCOL_SPC_SMPTE170M = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above AVCOL_SPC_SMPTE170M = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
AVCOL_SPC_SMPTE240M = 7, AVCOL_SPC_SMPTE240M = 7, ///< functionally identical to above
AVCOL_SPC_YCOCG = 8, ///< Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16 AVCOL_SPC_YCGCO = 8, ///< Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
AVCOL_SPC_YCOCG = AVCOL_SPC_YCGCO,
AVCOL_SPC_BT2020_NCL = 9, ///< ITU-R BT2020 non-constant luminance system AVCOL_SPC_BT2020_NCL = 9, ///< ITU-R BT2020 non-constant luminance system
AVCOL_SPC_BT2020_CL = 10, ///< ITU-R BT2020 constant luminance system AVCOL_SPC_BT2020_CL = 10, ///< ITU-R BT2020 constant luminance system
AVCOL_SPC_NB, ///< Not part of ABI AVCOL_SPC_SMPTE2085 = 11, ///< SMPTE 2085, Y'D'zD'x
AVCOL_SPC_CHROMA_DERIVED_NCL = 12, ///< Chromaticity-derived non-constant luminance system
AVCOL_SPC_CHROMA_DERIVED_CL = 13, ///< Chromaticity-derived constant luminance system
AVCOL_SPC_ICTCP = 14, ///< ITU-R BT.2100-0, ICtCp
AVCOL_SPC_NB ///< Not part of ABI
}; };
#define AVCOL_SPC_YCGCO AVCOL_SPC_YCOCG
/** /**
* MPEG vs JPEG YUV range. * MPEG vs JPEG YUV range.
@ -441,7 +520,7 @@ enum AVColorRange {
AVCOL_RANGE_UNSPECIFIED = 0, AVCOL_RANGE_UNSPECIFIED = 0,
AVCOL_RANGE_MPEG = 1, ///< the normal 219*2^(n-8) "MPEG" YUV ranges AVCOL_RANGE_MPEG = 1, ///< the normal 219*2^(n-8) "MPEG" YUV ranges
AVCOL_RANGE_JPEG = 2, ///< the normal 2^n-1 "JPEG" YUV ranges AVCOL_RANGE_JPEG = 2, ///< the normal 2^n-1 "JPEG" YUV ranges
AVCOL_RANGE_NB, ///< Not part of ABI AVCOL_RANGE_NB ///< Not part of ABI
}; };
/** /**
@ -461,13 +540,13 @@ enum AVColorRange {
*/ */
enum AVChromaLocation { enum AVChromaLocation {
AVCHROMA_LOC_UNSPECIFIED = 0, AVCHROMA_LOC_UNSPECIFIED = 0,
AVCHROMA_LOC_LEFT = 1, ///< mpeg2/4 4:2:0, h264 default for 4:2:0 AVCHROMA_LOC_LEFT = 1, ///< MPEG-2/4 4:2:0, H.264 default for 4:2:0
AVCHROMA_LOC_CENTER = 2, ///< mpeg1 4:2:0, jpeg 4:2:0, h263 4:2:0 AVCHROMA_LOC_CENTER = 2, ///< MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0
AVCHROMA_LOC_TOPLEFT = 3, ///< ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2 AVCHROMA_LOC_TOPLEFT = 3, ///< ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2
AVCHROMA_LOC_TOP = 4, AVCHROMA_LOC_TOP = 4,
AVCHROMA_LOC_BOTTOMLEFT = 5, AVCHROMA_LOC_BOTTOMLEFT = 5,
AVCHROMA_LOC_BOTTOM = 6, AVCHROMA_LOC_BOTTOM = 6,
AVCHROMA_LOC_NB, ///< Not part of ABI AVCHROMA_LOC_NB ///< Not part of ABI
}; };
#endif /* AVUTIL_PIXFMT_H */ #endif /* AVUTIL_PIXFMT_H */

@ -21,7 +21,8 @@
/** /**
* @file * @file
* rational numbers * @ingroup lavu_math_rational
* Utilties for rational number calculation.
* @author Michael Niedermayer <michaelni@gmx.at> * @author Michael Niedermayer <michaelni@gmx.at>
*/ */
@ -33,22 +34,39 @@
#include "attributes.h" #include "attributes.h"
/** /**
* @addtogroup lavu_math * @defgroup lavu_math_rational AVRational
* @ingroup lavu_math
* Rational number calculation.
*
* While rational numbers can be expressed as floating-point numbers, the
* conversion process is a lossy one, so are floating-point operations. On the
* other hand, the nature of FFmpeg demands highly accurate calculation of
* timestamps. This set of rational number utilities serves as a generic
* interface for manipulating rational numbers as pairs of numerators and
* denominators.
*
* Many of the functions that operate on AVRational's have the suffix `_q`, in
* reference to the mathematical symbol "" (Q) which denotes the set of all
* rational numbers.
*
* @{ * @{
*/ */
/** /**
* rational number numerator/denominator * Rational number (pair of numerator and denominator).
*/ */
typedef struct AVRational{ typedef struct AVRational{
int num; ///< numerator int num; ///< Numerator
int den; ///< denominator int den; ///< Denominator
} AVRational; } AVRational;
/** /**
* Create a rational. * Create an AVRational.
*
* Useful for compilers that do not support compound literals. * Useful for compilers that do not support compound literals.
* @note The return value is not reduced. *
* @note The return value is not reduced.
* @see av_reduce()
*/ */
static inline AVRational av_make_q(int num, int den) static inline AVRational av_make_q(int num, int den)
{ {
@ -58,10 +76,15 @@ static inline AVRational av_make_q(int num, int den)
/** /**
* Compare two rationals. * Compare two rationals.
* @param a first rational *
* @param b second rational * @param a First rational
* @return 0 if a==b, 1 if a>b, -1 if a<b, and INT_MIN if one of the * @param b Second rational
* values is of the form 0/0 *
* @return One of the following values:
* - 0 if `a == b`
* - 1 if `a > b`
* - -1 if `a < b`
* - `INT_MIN` if one of the values is of the form `0 / 0`
*/ */
static inline int av_cmp_q(AVRational a, AVRational b){ static inline int av_cmp_q(AVRational a, AVRational b){
const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den; const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
@ -73,9 +96,10 @@ static inline int av_cmp_q(AVRational a, AVRational b){
} }
/** /**
* Convert rational to double. * Convert an AVRational to a `double`.
* @param a rational to convert * @param a AVRational to convert
* @return (double) a * @return `a` in floating-point form
* @see av_d2q()
*/ */
static inline double av_q2d(AVRational a){ static inline double av_q2d(AVRational a){
return a.num / (double) a.den; return a.num / (double) a.den;
@ -83,44 +107,46 @@ static inline double av_q2d(AVRational a){
/** /**
* Reduce a fraction. * Reduce a fraction.
*
* This is useful for framerate calculations. * This is useful for framerate calculations.
* @param dst_num destination numerator *
* @param dst_den destination denominator * @param[out] dst_num Destination numerator
* @param num source numerator * @param[out] dst_den Destination denominator
* @param den source denominator * @param[in] num Source numerator
* @param max the maximum allowed for dst_num & dst_den * @param[in] den Source denominator
* @return 1 if exact, 0 otherwise * @param[in] max Maximum allowed values for `dst_num` & `dst_den`
* @return 1 if the operation is exact, 0 otherwise
*/ */
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max); int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max);
/** /**
* Multiply two rationals. * Multiply two rationals.
* @param b first rational * @param b First rational
* @param c second rational * @param c Second rational
* @return b*c * @return b*c
*/ */
AVRational av_mul_q(AVRational b, AVRational c) av_const; AVRational av_mul_q(AVRational b, AVRational c) av_const;
/** /**
* Divide one rational by another. * Divide one rational by another.
* @param b first rational * @param b First rational
* @param c second rational * @param c Second rational
* @return b/c * @return b/c
*/ */
AVRational av_div_q(AVRational b, AVRational c) av_const; AVRational av_div_q(AVRational b, AVRational c) av_const;
/** /**
* Add two rationals. * Add two rationals.
* @param b first rational * @param b First rational
* @param c second rational * @param c Second rational
* @return b+c * @return b+c
*/ */
AVRational av_add_q(AVRational b, AVRational c) av_const; AVRational av_add_q(AVRational b, AVRational c) av_const;
/** /**
* Subtract one rational from another. * Subtract one rational from another.
* @param b first rational * @param b First rational
* @param c second rational * @param c Second rational
* @return b-c * @return b-c
*/ */
AVRational av_sub_q(AVRational b, AVRational c) av_const; AVRational av_sub_q(AVRational b, AVRational c) av_const;
@ -138,31 +164,46 @@ static av_always_inline AVRational av_inv_q(AVRational q)
/** /**
* Convert a double precision floating point number to a rational. * Convert a double precision floating point number to a rational.
* inf is expressed as {1,0} or {-1,0} depending on the sign.
* *
* @param d double to convert * In case of infinity, the returned value is expressed as `{1, 0}` or
* @param max the maximum allowed numerator and denominator * `{-1, 0}` depending on the sign.
* @return (AVRational) d *
* @param d `double` to convert
* @param max Maximum allowed numerator and denominator
* @return `d` in AVRational form
* @see av_q2d()
*/ */
AVRational av_d2q(double d, int max) av_const; AVRational av_d2q(double d, int max) av_const;
/** /**
* @return 1 if q1 is nearer to q than q2, -1 if q2 is nearer * Find which of the two rationals is closer to another rational.
* than q1, 0 if they have the same distance. *
* @param q Rational to be compared against
* @param q1,q2 Rationals to be tested
* @return One of the following values:
* - 1 if `q1` is nearer to `q` than `q2`
* - -1 if `q2` is nearer to `q` than `q1`
* - 0 if they have the same distance
*/ */
int av_nearer_q(AVRational q, AVRational q1, AVRational q2); int av_nearer_q(AVRational q, AVRational q1, AVRational q2);
/** /**
* Find the nearest value in q_list to q. * Find the value in a list of rationals nearest a given reference rational.
* @param q_list an array of rationals terminated by {0, 0} *
* @return the index of the nearest value found in the array * @param q Reference rational
* @param q_list Array of rationals terminated by `{0, 0}`
* @return Index of the nearest value found in the array
*/ */
int av_find_nearest_q_idx(AVRational q, const AVRational* q_list); int av_find_nearest_q_idx(AVRational q, const AVRational* q_list);
/** /**
* Converts a AVRational to a IEEE 32bit float. * Convert an AVRational to a IEEE 32-bit `float` expressed in fixed-point
* format.
* *
* The float is returned in a uint32_t and its value is platform indepenant. * @param q Rational to be converted
* @return Equivalent floating-point value, expressed as an unsigned 32-bit
* integer.
* @note The returned value is platform-indepedant.
*/ */
uint32_t av_q2intfloat(AVRational q); uint32_t av_q2intfloat(AVRational q);

@ -1,5 +1,4 @@
/* /*
*
* This file is part of FFmpeg. * This file is part of FFmpeg.
* *
* FFmpeg is free software; you can redistribute it and/or * FFmpeg is free software; you can redistribute it and/or

@ -0,0 +1,28 @@
/*
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVUTIL_REVERSE_H
#define AVUTIL_REVERSE_H
#include <stdint.h>
extern const uint8_t ff_reverse[256];
#endif /* AVUTIL_REVERSE_H */

@ -19,6 +19,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* @file
* @ingroup lavu_ripemd
* Public header for RIPEMD hash function implementation.
*/
#ifndef AVUTIL_RIPEMD_H #ifndef AVUTIL_RIPEMD_H
#define AVUTIL_RIPEMD_H #define AVUTIL_RIPEMD_H
@ -29,7 +35,9 @@
/** /**
* @defgroup lavu_ripemd RIPEMD * @defgroup lavu_ripemd RIPEMD
* @ingroup lavu_crypto * @ingroup lavu_hash
* RIPEMD hash function implementation.
*
* @{ * @{
*/ */
@ -58,7 +66,11 @@ int av_ripemd_init(struct AVRIPEMD* context, int bits);
* @param data input data to update hash with * @param data input data to update hash with
* @param len input data length * @param len input data length
*/ */
#if FF_API_CRYPTO_SIZE_T
void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, unsigned int len); void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, unsigned int len);
#else
void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, size_t len);
#endif
/** /**
* Finish hashing and output digest value. * Finish hashing and output digest value.

@ -32,7 +32,6 @@
* *
* Audio sample format enumeration and related convenience functions. * Audio sample format enumeration and related convenience functions.
* @{ * @{
*
*/ */
/** /**
@ -69,6 +68,8 @@ enum AVSampleFormat {
AV_SAMPLE_FMT_S32P, ///< signed 32 bits, planar AV_SAMPLE_FMT_S32P, ///< signed 32 bits, planar
AV_SAMPLE_FMT_FLTP, ///< float, planar AV_SAMPLE_FMT_FLTP, ///< float, planar
AV_SAMPLE_FMT_DBLP, ///< double, planar AV_SAMPLE_FMT_DBLP, ///< double, planar
AV_SAMPLE_FMT_S64, ///< signed 64 bits
AV_SAMPLE_FMT_S64P, ///< signed 64 bits, planar
AV_SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if linking dynamically AV_SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if linking dynamically
}; };

@ -18,9 +18,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* @file
* @ingroup lavu_sha
* Public header for SHA-1 & SHA-256 hash function implementations.
*/
#ifndef AVUTIL_SHA_H #ifndef AVUTIL_SHA_H
#define AVUTIL_SHA_H #define AVUTIL_SHA_H
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "attributes.h" #include "attributes.h"
@ -28,7 +35,17 @@
/** /**
* @defgroup lavu_sha SHA * @defgroup lavu_sha SHA
* @ingroup lavu_crypto * @ingroup lavu_hash
* SHA-1 and SHA-256 (Secure Hash Algorithm) hash function implementations.
*
* This module supports the following SHA hash functions:
*
* - SHA-1: 160 bits
* - SHA-224: 224 bits, as a variant of SHA-2
* - SHA-256: 256 bits, as a variant of SHA-2
*
* @see For SHA-384, SHA-512, and variants thereof, see @ref lavu_sha512.
*
* @{ * @{
*/ */
@ -53,11 +70,15 @@ int av_sha_init(struct AVSHA* context, int bits);
/** /**
* Update hash value. * Update hash value.
* *
* @param context hash function context * @param ctx hash function context
* @param data input data to update hash with * @param data input data to update hash with
* @param len input data length * @param len input data length
*/ */
void av_sha_update(struct AVSHA* context, const uint8_t* data, unsigned int len); #if FF_API_CRYPTO_SIZE_T
void av_sha_update(struct AVSHA *ctx, const uint8_t *data, unsigned int len);
#else
void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len);
#endif
/** /**
* Finish hashing and output digest value. * Finish hashing and output digest value.

@ -19,17 +19,35 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* @file
* @ingroup lavu_sha512
* Public header for SHA-512 implementation.
*/
#ifndef AVUTIL_SHA512_H #ifndef AVUTIL_SHA512_H
#define AVUTIL_SHA512_H #define AVUTIL_SHA512_H
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "attributes.h" #include "attributes.h"
#include "version.h" #include "version.h"
/** /**
* @defgroup lavu_sha512 SHA512 * @defgroup lavu_sha512 SHA-512
* @ingroup lavu_crypto * @ingroup lavu_hash
* SHA-512 (Secure Hash Algorithm) hash function implementations.
*
* This module supports the following SHA-2 hash functions:
*
* - SHA-512/224: 224 bits
* - SHA-512/256: 256 bits
* - SHA-384: 384 bits
* - SHA-512: 512 bits
*
* @see For SHA-1, SHA-256, and variants thereof, see @ref lavu_sha.
*
* @{ * @{
*/ */
@ -58,7 +76,11 @@ int av_sha512_init(struct AVSHA512* context, int bits);
* @param data input data to update hash with * @param data input data to update hash with
* @param len input data length * @param len input data length
*/ */
#if FF_API_CRYPTO_SIZE_T
void av_sha512_update(struct AVSHA512* context, const uint8_t* data, unsigned int len); void av_sha512_update(struct AVSHA512* context, const uint8_t* data, unsigned int len);
#else
void av_sha512_update(struct AVSHA512* context, const uint8_t* data, size_t len);
#endif
/** /**
* Finish hashing and output digest value. * Finish hashing and output digest value.

@ -0,0 +1,232 @@
/*
* Copyright (c) 2016 Vittorio Giovara <vittorio.giovara@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Spherical video
*/
#ifndef AVUTIL_SPHERICAL_H
#define AVUTIL_SPHERICAL_H
#include <stddef.h>
#include <stdint.h>
/**
* @addtogroup lavu_video
* @{
*
* @defgroup lavu_video_spherical Spherical video mapping
* @{
*/
/**
* @addtogroup lavu_video_spherical
* A spherical video file contains surfaces that need to be mapped onto a
* sphere. Depending on how the frame was converted, a different distortion
* transformation or surface recomposition function needs to be applied before
* the video should be mapped and displayed.
*/
/**
* Projection of the video surface(s) on a sphere.
*/
enum AVSphericalProjection {
/**
* Video represents a sphere mapped on a flat surface using
* equirectangular projection.
*/
AV_SPHERICAL_EQUIRECTANGULAR,
/**
* Video frame is split into 6 faces of a cube, and arranged on a
* 3x2 layout. Faces are oriented upwards for the front, left, right,
* and back faces. The up face is oriented so the top of the face is
* forwards and the down face is oriented so the top of the face is
* to the back.
*/
AV_SPHERICAL_CUBEMAP,
/**
* Video represents a portion of a sphere mapped on a flat surface
* using equirectangular projection. The @ref bounding fields indicate
* the position of the current video in a larger surface.
*/
AV_SPHERICAL_EQUIRECTANGULAR_TILE,
};
/**
* This structure describes how to handle spherical videos, outlining
* information about projection, initial layout, and any other view modifier.
*
* @note The struct must be allocated with av_spherical_alloc() and
* its size is not a part of the public ABI.
*/
typedef struct AVSphericalMapping {
/**
* Projection type.
*/
enum AVSphericalProjection projection;
/**
* @name Initial orientation
* @{
* There fields describe additional rotations applied to the sphere after
* the video frame is mapped onto it. The sphere is rotated around the
* viewer, who remains stationary. The order of transformation is always
* yaw, followed by pitch, and finally by roll.
*
* The coordinate system matches the one defined in OpenGL, where the
* forward vector (z) is coming out of screen, and it is equivalent to
* a rotation matrix of R = r_y(yaw) * r_x(pitch) * r_z(roll).
*
* A positive yaw rotates the portion of the sphere in front of the viewer
* toward their right. A positive pitch rotates the portion of the sphere
* in front of the viewer upwards. A positive roll tilts the portion of
* the sphere in front of the viewer to the viewer's right.
*
* These values are exported as 16.16 fixed point.
*
* See this equirectangular projection as example:
*
* @code{.unparsed}
* Yaw
* -180 0 180
* 90 +-------------+-------------+ 180
* | | | up
* P | | | y| forward
* i | ^ | | /z
* t 0 +-------------X-------------+ 0 Roll | /
* c | | | | /
* h | | | 0|/_____right
* | | | x
* -90 +-------------+-------------+ -180
*
* X - the default camera center
* ^ - the default up vector
* @endcode
*/
int32_t yaw; ///< Rotation around the up vector [-180, 180].
int32_t pitch; ///< Rotation around the right vector [-90, 90].
int32_t roll; ///< Rotation around the forward vector [-180, 180].
/**
* @}
*/
/**
* @name Bounding rectangle
* @anchor bounding
* @{
* These fields indicate the location of the current tile, and where
* it should be mapped relative to the original surface. They are
* exported as 0.32 fixed point, and can be converted to classic
* pixel values with av_spherical_bounds().
*
* @code{.unparsed}
* +----------------+----------+
* | |bound_top |
* | +--------+ |
* | bound_left |tile | |
* +<---------->| |<--->+bound_right
* | +--------+ |
* | | |
* | bound_bottom| |
* +----------------+----------+
* @endcode
*
* If needed, the original video surface dimensions can be derived
* by adding the current stream or frame size to the related bounds,
* like in the following example:
*
* @code{c}
* original_width = tile->width + bound_left + bound_right;
* original_height = tile->height + bound_top + bound_bottom;
* @endcode
*
* @note These values are valid only for the tiled equirectangular
* projection type (@ref AV_SPHERICAL_EQUIRECTANGULAR_TILE),
* and should be ignored in all other cases.
*/
uint32_t bound_left; ///< Distance from the left edge
uint32_t bound_top; ///< Distance from the top edge
uint32_t bound_right; ///< Distance from the right edge
uint32_t bound_bottom; ///< Distance from the bottom edge
/**
* @}
*/
/**
* Number of pixels to pad from the edge of each cube face.
*
* @note This value is valid for only for the cubemap projection type
* (@ref AV_SPHERICAL_CUBEMAP), and should be ignored in all other
* cases.
*/
uint32_t padding;
} AVSphericalMapping;
/**
* Allocate a AVSphericalVideo structure and initialize its fields to default
* values.
*
* @return the newly allocated struct or NULL on failure
*/
AVSphericalMapping *av_spherical_alloc(size_t *size);
/**
* Convert the @ref bounding fields from an AVSphericalVideo
* from 0.32 fixed point to pixels.
*
* @param map The AVSphericalVideo map to read bound values from.
* @param width Width of the current frame or stream.
* @param height Height of the current frame or stream.
* @param left Pixels from the left edge.
* @param top Pixels from the top edge.
* @param right Pixels from the right edge.
* @param bottom Pixels from the bottom edge.
*/
void av_spherical_tile_bounds(const AVSphericalMapping *map,
size_t width, size_t height,
size_t *left, size_t *top,
size_t *right, size_t *bottom);
/**
* Provide a human-readable name of a given AVSphericalProjection.
*
* @param projection The input AVSphericalProjection.
*
* @return The name of the AVSphericalProjection, or "unknown".
*/
const char *av_spherical_projection_name(enum AVSphericalProjection projection);
/**
* Get the AVSphericalProjection form a human-readable name.
*
* @param name The input string.
*
* @return The AVSphericalProjection value, or -1 if not found.
*/
int av_spherical_from_name(const char *name);
/**
* @}
* @}
*/
#endif /* AVUTIL_SPHERICAL_H */

@ -18,6 +18,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* @file
* Stereoscopic video
*/
#ifndef AVUTIL_STEREO3D_H #ifndef AVUTIL_STEREO3D_H
#define AVUTIL_STEREO3D_H #define AVUTIL_STEREO3D_H
@ -25,6 +30,21 @@
#include "frame.h" #include "frame.h"
/**
* @addtogroup lavu_video
* @{
*
* @defgroup lavu_video_stereo3d Stereo3D types and functions
* @{
*/
/**
* @addtogroup lavu_video_stereo3d
* A stereoscopic video file consists in multiple views embedded in a single
* frame, usually describing two views of a scene. This file describes all
* possible codec-independent view arrangements.
* */
/** /**
* List of possible 3D Types * List of possible 3D Types
*/ */
@ -37,41 +57,49 @@ enum AVStereo3DType {
/** /**
* Views are next to each other. * Views are next to each other.
* *
* @code{.unparsed}
* LLLLRRRR * LLLLRRRR
* LLLLRRRR * LLLLRRRR
* LLLLRRRR * LLLLRRRR
* ... * ...
* @endcode
*/ */
AV_STEREO3D_SIDEBYSIDE, AV_STEREO3D_SIDEBYSIDE,
/** /**
* Views are on top of each other. * Views are on top of each other.
* *
* @code{.unparsed}
* LLLLLLLL * LLLLLLLL
* LLLLLLLL * LLLLLLLL
* RRRRRRRR * RRRRRRRR
* RRRRRRRR * RRRRRRRR
* @endcode
*/ */
AV_STEREO3D_TOPBOTTOM, AV_STEREO3D_TOPBOTTOM,
/** /**
* Views are alternated temporally. * Views are alternated temporally.
* *
* @code{.unparsed}
* frame0 frame1 frame2 ... * frame0 frame1 frame2 ...
* LLLLLLLL RRRRRRRR LLLLLLLL * LLLLLLLL RRRRRRRR LLLLLLLL
* LLLLLLLL RRRRRRRR LLLLLLLL * LLLLLLLL RRRRRRRR LLLLLLLL
* LLLLLLLL RRRRRRRR LLLLLLLL * LLLLLLLL RRRRRRRR LLLLLLLL
* ... ... ... * ... ... ...
* @endcode
*/ */
AV_STEREO3D_FRAMESEQUENCE, AV_STEREO3D_FRAMESEQUENCE,
/** /**
* Views are packed in a checkerboard-like structure per pixel. * Views are packed in a checkerboard-like structure per pixel.
* *
* @code{.unparsed}
* LRLRLRLR * LRLRLRLR
* RLRLRLRL * RLRLRLRL
* LRLRLRLR * LRLRLRLR
* ... * ...
* @endcode
*/ */
AV_STEREO3D_CHECKERBOARD, AV_STEREO3D_CHECKERBOARD,
@ -79,34 +107,59 @@ enum AVStereo3DType {
* Views are next to each other, but when upscaling * Views are next to each other, but when upscaling
* apply a checkerboard pattern. * apply a checkerboard pattern.
* *
* @code{.unparsed}
* LLLLRRRR L L L L R R R R * LLLLRRRR L L L L R R R R
* LLLLRRRR => L L L L R R R R * LLLLRRRR => L L L L R R R R
* LLLLRRRR L L L L R R R R * LLLLRRRR L L L L R R R R
* LLLLRRRR L L L L R R R R * LLLLRRRR L L L L R R R R
* @endcode
*/ */
AV_STEREO3D_SIDEBYSIDE_QUINCUNX, AV_STEREO3D_SIDEBYSIDE_QUINCUNX,
/** /**
* Views are packed per line, as if interlaced. * Views are packed per line, as if interlaced.
* *
* @code{.unparsed}
* LLLLLLLL * LLLLLLLL
* RRRRRRRR * RRRRRRRR
* LLLLLLLL * LLLLLLLL
* ... * ...
* @endcode
*/ */
AV_STEREO3D_LINES, AV_STEREO3D_LINES,
/** /**
* Views are packed per column. * Views are packed per column.
* *
* @code{.unparsed}
* LRLRLRLR * LRLRLRLR
* LRLRLRLR * LRLRLRLR
* LRLRLRLR * LRLRLRLR
* ... * ...
* @endcode
*/ */
AV_STEREO3D_COLUMNS, AV_STEREO3D_COLUMNS,
}; };
/**
* List of possible view types.
*/
enum AVStereo3DView {
/**
* Frame contains two packed views.
*/
AV_STEREO3D_VIEW_PACKED,
/**
* Frame contains only the left view.
*/
AV_STEREO3D_VIEW_LEFT,
/**
* Frame contains only the right view.
*/
AV_STEREO3D_VIEW_RIGHT,
};
/** /**
* Inverted views, Right/Bottom represents the left view. * Inverted views, Right/Bottom represents the left view.
@ -130,6 +183,11 @@ typedef struct AVStereo3D {
* Additional information about the frame packing. * Additional information about the frame packing.
*/ */
int flags; int flags;
/**
* Determines which views are packed.
*/
enum AVStereo3DView view;
} AVStereo3D; } AVStereo3D;
/** /**
@ -149,4 +207,27 @@ AVStereo3D *av_stereo3d_alloc(void);
*/ */
AVStereo3D *av_stereo3d_create_side_data(AVFrame *frame); AVStereo3D *av_stereo3d_create_side_data(AVFrame *frame);
/**
* Provide a human-readable name of a given stereo3d type.
*
* @param type The input stereo3d type value.
*
* @return The name of the stereo3d value, or "unknown".
*/
const char *av_stereo3d_type_name(unsigned int type);
/**
* Get the AVStereo3DType form a human-readable name.
*
* @param name The input string.
*
* @return The AVStereo3DType value, or -1 if not found.
*/
int av_stereo3d_from_name(const char *name);
/**
* @}
* @}
*/
#endif /* AVUTIL_STEREO3D_H */ #endif /* AVUTIL_STEREO3D_H */

@ -0,0 +1,173 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
// This header should only be used to simplify code where
// threading is optional, not as a generic threading abstraction.
#ifndef AVUTIL_THREAD_H
#define AVUTIL_THREAD_H
#include "ffmpeg/config.h"
#if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
#if HAVE_PTHREADS
#include <pthread.h>
#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
#include "log.h"
#define ASSERT_PTHREAD_NORET(func, ...) do { \
int ret = func(__VA_ARGS__); \
if (ret) { \
char errbuf[AV_ERROR_MAX_STRING_SIZE] = ""; \
av_log(NULL, AV_LOG_FATAL, AV_STRINGIFY(func) \
" failed with error: %s\n", \
av_make_error_string(errbuf, AV_ERROR_MAX_STRING_SIZE, \
AVERROR(ret))); \
abort(); \
} \
} while (0)
#define ASSERT_PTHREAD(func, ...) do { \
ASSERT_PTHREAD_NORET(func, __VA_ARGS__); \
return 0; \
} while (0)
static inline int strict_pthread_join(pthread_t thread, void **value_ptr)
{
ASSERT_PTHREAD(pthread_join, thread, value_ptr);
}
static inline int strict_pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
{
if (attr) {
ASSERT_PTHREAD_NORET(pthread_mutex_init, mutex, attr);
} else {
pthread_mutexattr_t local_attr;
ASSERT_PTHREAD_NORET(pthread_mutexattr_init, &local_attr);
ASSERT_PTHREAD_NORET(pthread_mutexattr_settype, &local_attr, PTHREAD_MUTEX_ERRORCHECK);
ASSERT_PTHREAD_NORET(pthread_mutex_init, mutex, &local_attr);
ASSERT_PTHREAD_NORET(pthread_mutexattr_destroy, &local_attr);
}
return 0;
}
static inline int strict_pthread_mutex_destroy(pthread_mutex_t *mutex)
{
ASSERT_PTHREAD(pthread_mutex_destroy, mutex);
}
static inline int strict_pthread_mutex_lock(pthread_mutex_t *mutex)
{
ASSERT_PTHREAD(pthread_mutex_lock, mutex);
}
static inline int strict_pthread_mutex_unlock(pthread_mutex_t *mutex)
{
ASSERT_PTHREAD(pthread_mutex_unlock, mutex);
}
static inline int strict_pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
{
ASSERT_PTHREAD(pthread_cond_init, cond, attr);
}
static inline int strict_pthread_cond_destroy(pthread_cond_t *cond)
{
ASSERT_PTHREAD(pthread_cond_destroy, cond);
}
static inline int strict_pthread_cond_signal(pthread_cond_t *cond)
{
ASSERT_PTHREAD(pthread_cond_signal, cond);
}
static inline int strict_pthread_cond_broadcast(pthread_cond_t *cond)
{
ASSERT_PTHREAD(pthread_cond_broadcast, cond);
}
static inline int strict_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
ASSERT_PTHREAD(pthread_cond_wait, cond, mutex);
}
static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
{
ASSERT_PTHREAD(pthread_once, once_control, init_routine);
}
#define pthread_join strict_pthread_join
#define pthread_mutex_init strict_pthread_mutex_init
#define pthread_mutex_destroy strict_pthread_mutex_destroy
#define pthread_mutex_lock strict_pthread_mutex_lock
#define pthread_mutex_unlock strict_pthread_mutex_unlock
#define pthread_cond_init strict_pthread_cond_init
#define pthread_cond_destroy strict_pthread_cond_destroy
#define pthread_cond_signal strict_pthread_cond_signal
#define pthread_cond_broadcast strict_pthread_cond_broadcast
#define pthread_cond_wait strict_pthread_cond_wait
#define pthread_once strict_pthread_once
#endif
#elif HAVE_OS2THREADS
#include "compat/os2threads.h"
#else
#include "compat/w32pthreads.h"
#endif
#define AVMutex pthread_mutex_t
#define AV_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#define ff_mutex_init pthread_mutex_init
#define ff_mutex_lock pthread_mutex_lock
#define ff_mutex_unlock pthread_mutex_unlock
#define ff_mutex_destroy pthread_mutex_destroy
#define AVOnce pthread_once_t
#define AV_ONCE_INIT PTHREAD_ONCE_INIT
#define ff_thread_once(control, routine) pthread_once(control, routine)
#else
#define AVMutex char
#define AV_MUTEX_INITIALIZER 0
static inline int ff_mutex_init(AVMutex *mutex, const void *attr){ return 0; }
static inline int ff_mutex_lock(AVMutex *mutex){ return 0; }
static inline int ff_mutex_unlock(AVMutex *mutex){ return 0; }
static inline int ff_mutex_destroy(AVMutex *mutex){ return 0; }
#define AVOnce char
#define AV_ONCE_INIT 0
static inline int ff_thread_once(char *control, void (*routine)(void))
{
if (!*control) {
routine();
*control = 1;
}
return 0;
}
#endif
#endif /* AVUTIL_THREAD_H */

@ -69,10 +69,10 @@ int av_thread_message_queue_recv(AVThreadMessageQueue *mq,
/** /**
* Set the sending error code. * Set the sending error code.
* *
* If the error code is set to non-zero, av_thread_message_queue_recv() will * If the error code is set to non-zero, av_thread_message_queue_send() will
* return it immediately when there are no longer available messages. * return it immediately. Conventional values, such as AVERROR_EOF or
* Conventional values, such as AVERROR_EOF or AVERROR(EAGAIN), can be used * AVERROR(EAGAIN), can be used to cause the sending thread to stop or
* to cause the receiving thread to stop or suspend its operation. * suspend its operation.
*/ */
void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq, void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq,
int err); int err);
@ -80,10 +80,10 @@ void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq,
/** /**
* Set the receiving error code. * Set the receiving error code.
* *
* If the error code is set to non-zero, av_thread_message_queue_send() will * If the error code is set to non-zero, av_thread_message_queue_recv() will
* return it immediately. Conventional values, such as AVERROR_EOF or * return it immediately when there are no longer available messages.
* AVERROR(EAGAIN), can be used to cause the sending thread to stop or * Conventional values, such as AVERROR_EOF or AVERROR(EAGAIN), can be used
* suspend its operation. * to cause the receiving thread to stop or suspend its operation.
*/ */
void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
int err); int err);
@ -95,6 +95,14 @@ void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq, void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq,
void (*free_func)(void *msg)); void (*free_func)(void *msg));
/**
* Return the current number of messages in the queue.
*
* @return the current number of messages or AVERROR(ENOSYS) if lavu was built
* without thread support
*/
int av_thread_message_queue_nb_elems(AVThreadMessageQueue *mq);
/** /**
* Flush the message queue * Flush the message queue
* *

@ -23,7 +23,7 @@
#include "ffmpeg/config.h" #include "ffmpeg/config.h"
#if !HAVE_GMTIME_R && !defined(gmtime_r) #if !HAVE_GMTIME_R && !defined(gmtime_r)
static inline struct tm *gmtime_r(const time_t* clock, struct tm *result) static inline struct tm *ff_gmtime_r(const time_t* clock, struct tm *result)
{ {
struct tm *ptr = gmtime(clock); struct tm *ptr = gmtime(clock);
if (!ptr) if (!ptr)
@ -31,10 +31,11 @@ static inline struct tm *gmtime_r(const time_t* clock, struct tm *result)
*result = *ptr; *result = *ptr;
return result; return result;
} }
#define gmtime_r ff_gmtime_r
#endif #endif
#if !HAVE_LOCALTIME_R && !defined(localtime_r) #if !HAVE_LOCALTIME_R && !defined(localtime_r)
static inline struct tm *localtime_r(const time_t* clock, struct tm *result) static inline struct tm *ff_localtime_r(const time_t* clock, struct tm *result)
{ {
struct tm *ptr = localtime(clock); struct tm *ptr = localtime(clock);
if (!ptr) if (!ptr)
@ -42,6 +43,7 @@ static inline struct tm *localtime_r(const time_t* clock, struct tm *result)
*result = *ptr; *result = *ptr;
return result; return result;
} }
#define localtime_r ff_localtime_r
#endif #endif
#endif /* AVUTIL_TIME_INTERNAL_H */ #endif /* AVUTIL_TIME_INTERNAL_H */

@ -30,7 +30,7 @@
#include <stdint.h> #include <stdint.h>
#include "rational.h" #include "rational.h"
#define AV_TIMECODE_STR_SIZE 16 #define AV_TIMECODE_STR_SIZE 23
enum AVTimecodeFlag { enum AVTimecodeFlag {
AV_TIMECODE_FLAG_DROPFRAME = 1<<0, ///< timecode is drop frame AV_TIMECODE_FLAG_DROPFRAME = 1<<0, ///< timecode is drop frame

@ -26,29 +26,37 @@
#ifndef AVUTIL_TIMER_H #ifndef AVUTIL_TIMER_H
#define AVUTIL_TIMER_H #define AVUTIL_TIMER_H
#include "config.h"
#if CONFIG_LINUX_PERF
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif
# include <unistd.h> // read(3)
# include <sys/ioctl.h>
# include <asm/unistd.h>
# include <linux/perf_event.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <inttypes.h> #include <inttypes.h>
#include "ffmpeg/config.h" #if HAVE_MACH_ABSOLUTE_TIME
#if HAVE_MACH_MACH_TIME_H
#include <mach/mach_time.h> #include <mach/mach_time.h>
#endif #endif
#include "log.h" #include "log.h"
//TODO #if ARCH_AARCH64
#include "libavutil/arm/timer.h" # include "aarch64/timer.h"
//#if ARCH_AARCH64 #elif ARCH_ARM
//# include "aarch64/timer.h" # include "arm/timer.h"
//#elif ARCH_ARM #elif ARCH_PPC
//# include "arm/timer.h" # include "ppc/timer.h"
//#elif ARCH_PPC #elif ARCH_X86
//# include "ppc/timer.h" # include "x86/timer.h"
//#elif ARCH_X86 #endif
//# include "x86/timer.h"
//#endif
#if !defined(AV_READ_TIME) #if !defined(AV_READ_TIME)
# if HAVE_GETHRTIME # if HAVE_GETHRTIME
@ -62,23 +70,17 @@
# define FF_TIMER_UNITS "UNITS" # define FF_TIMER_UNITS "UNITS"
#endif #endif
#ifdef AV_READ_TIME #define TIMER_REPORT(id, tdiff) \
#define START_TIMER \
uint64_t tend; \
uint64_t tstart = AV_READ_TIME(); \
#define STOP_TIMER(id) \
tend = AV_READ_TIME(); \
{ \ { \
static uint64_t tsum = 0; \ static uint64_t tsum = 0; \
static int tcount = 0; \ static int tcount = 0; \
static int tskip_count = 0; \ static int tskip_count = 0; \
static int thistogram[32] = {0}; \ static int thistogram[32] = {0}; \
thistogram[av_log2(tend - tstart)]++; \ thistogram[av_log2(tdiff)]++; \
if (tcount < 2 || \ if (tcount < 2 || \
tend - tstart < 8 * tsum / tcount || \ (tdiff) < 8 * tsum / tcount || \
tend - tstart < 2000) { \ (tdiff) < 2000) { \
tsum+= tend - tstart; \ tsum += (tdiff); \
tcount++; \ tcount++; \
} else \ } else \
tskip_count++; \ tskip_count++; \
@ -92,6 +94,45 @@
av_log(NULL, AV_LOG_ERROR, "\n"); \ av_log(NULL, AV_LOG_ERROR, "\n"); \
} \ } \
} }
#if CONFIG_LINUX_PERF
#define START_TIMER \
static int linux_perf_fd; \
uint64_t tperf; \
if (!linux_perf_fd) { \
struct perf_event_attr attr = { \
.type = PERF_TYPE_HARDWARE, \
.size = sizeof(struct perf_event_attr), \
.config = PERF_COUNT_HW_CPU_CYCLES, \
.disabled = 1, \
.exclude_kernel = 1, \
.exclude_hv = 1, \
}; \
linux_perf_fd = syscall(__NR_perf_event_open, &attr, \
0, -1, -1, 0); \
} \
if (linux_perf_fd == -1) { \
av_log(NULL, AV_LOG_ERROR, "perf_event_open failed: %s\n", \
av_err2str(AVERROR(errno))); \
} else { \
ioctl(linux_perf_fd, PERF_EVENT_IOC_RESET, 0); \
ioctl(linux_perf_fd, PERF_EVENT_IOC_ENABLE, 0); \
}
#define STOP_TIMER(id) \
ioctl(linux_perf_fd, PERF_EVENT_IOC_DISABLE, 0); \
read(linux_perf_fd, &tperf, sizeof(tperf)); \
TIMER_REPORT(id, tperf)
#elif defined(AV_READ_TIME)
#define START_TIMER \
uint64_t tend; \
uint64_t tstart = AV_READ_TIME(); \
#define STOP_TIMER(id) \
tend = AV_READ_TIME(); \
TIMER_REPORT(id, tend - tstart)
#else #else
#define START_TIMER #define START_TIMER
#define STOP_TIMER(id) { } #define STOP_TIMER(id) { }

@ -43,7 +43,7 @@
static inline char *av_ts_make_string(char *buf, int64_t ts) static inline char *av_ts_make_string(char *buf, int64_t ts)
{ {
if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS"); if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
else snprintf(buf, AV_TS_MAX_STRING_SIZE, "%"PRId64, ts); else snprintf(buf, AV_TS_MAX_STRING_SIZE, "%" PRId64, ts);
return buf; return buf;
} }

@ -58,7 +58,7 @@ struct AVTreeNode *av_tree_node_alloc(void);
* then the corresponding entry in next is unchanged. * then the corresponding entry in next is unchanged.
* @param cmp compare function used to compare elements in the tree, * @param cmp compare function used to compare elements in the tree,
* API identical to that of Standard C's qsort * API identical to that of Standard C's qsort
* It is guranteed that the first and only the first argument to cmp() * It is guaranteed that the first and only the first argument to cmp()
* will be the key parameter to av_tree_find(), thus it could if the * will be the key parameter to av_tree_find(), thus it could if the
* user wants, be a different type (like an opaque context). * user wants, be a different type (like an opaque context).
* @return An element with cmp(key, elem) == 0 or NULL if no such element * @return An element with cmp(key, elem) == 0 or NULL if no such element
@ -120,8 +120,8 @@ void av_tree_destroy(struct AVTreeNode *t);
/** /**
* Apply enu(opaque, &elem) to all the elements in the tree in a given range. * Apply enu(opaque, &elem) to all the elements in the tree in a given range.
* *
* @param cmp a comparison function that returns < 0 for a element below the * @param cmp a comparison function that returns < 0 for an element below the
* range, > 0 for a element above the range and == 0 for a * range, > 0 for an element above the range and == 0 for an
* element inside the range * element inside the range
* *
* @note The cmp function should use the same ordering used to construct the * @note The cmp function should use the same ordering used to construct the

@ -0,0 +1,81 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVUTIL_TX_H
#define AVUTIL_TX_H
#include <stdint.h>
#include <stddef.h>
typedef struct AVTXContext AVTXContext;
typedef struct AVComplexFloat {
float re, im;
} AVComplexFloat;
enum AVTXType {
/**
* Standard complex to complex FFT with sample data type AVComplexFloat.
* Scaling currently unsupported
*/
AV_TX_FLOAT_FFT = 0,
/**
* Standard MDCT with sample data type of float and a scale type of
* float. Length is the frame size, not the window size (which is 2x frame)
*/
AV_TX_FLOAT_MDCT = 1,
};
/**
* Function pointer to a function to perform the transform.
*
* @note Using a different context than the one allocated during av_tx_init()
* is not allowed.
*
* @param s the transform context
* @param out the output array
* @param in the input array
* @param stride the input or output stride (depending on transform direction)
* in bytes, currently implemented for all MDCT transforms
*/
typedef void (*av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride);
/**
* Initialize a transform context with the given configuration
* Currently power of two lengths from 4 to 131072 are supported, along with
* any length decomposable to a power of two and either 3, 5 or 15.
*
* @param ctx the context to allocate, will be NULL on error
* @param tx pointer to the transform function pointer to set
* @param type type the type of transform
* @param inv whether to do an inverse or a forward transform
* @param len the size of the transform in samples
* @param scale pointer to the value to scale the output if supported by type
* @param flags currently unused
*
* @return 0 on success, negative error code on failure
*/
int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type,
int inv, int len, const void *scale, uint64_t flags);
/**
* Frees a context and sets ctx to NULL, does nothing when ctx == NULL
*/
void av_tx_uninit(AVTXContext **ctx);
#endif /* AVUTIL_TX_H */

@ -18,6 +18,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* @file
* @ingroup lavu
* Libavutil version macros
*/
#ifndef AVUTIL_VERSION_H #ifndef AVUTIL_VERSION_H
#define AVUTIL_VERSION_H #define AVUTIL_VERSION_H
@ -29,6 +35,21 @@
* Useful to check and match library version in order to maintain * Useful to check and match library version in order to maintain
* backward compatibility. * backward compatibility.
* *
* The FFmpeg libraries follow a versioning sheme very similar to
* Semantic Versioning (http://semver.org/)
* The difference is that the component called PATCH is called MICRO in FFmpeg
* and its value is reset to 100 instead of 0 to keep it above or equal to 100.
* Also we do not increase MICRO for every bugfix or change in git master.
*
* Prior to FFmpeg 3.2 point releases did not change any lib version number to
* avoid aliassing different git master checkouts.
* Starting with FFmpeg 3.2, the released library versions will occupy
* a separate MAJOR.MINOR that is not used on the master development branch.
* That is if we branch a release of master 55.10.123 we will bump to 55.11.100
* for the release and master will continue at 55.12.100 after it. Each new
* point release will then bump the MICRO improving the usefulness of the lib
* versions.
*
* @{ * @{
*/ */
@ -48,12 +69,6 @@
* @} * @}
*/ */
/**
* @file
* @ingroup lavu
* Libavutil version macros
*/
/** /**
* @defgroup lavu_ver Version and Build diagnostics * @defgroup lavu_ver Version and Build diagnostics
* *
@ -63,9 +78,9 @@
* @{ * @{
*/ */
#define LIBAVUTIL_VERSION_MAJOR 55 #define LIBAVUTIL_VERSION_MAJOR 56
#define LIBAVUTIL_VERSION_MINOR 17 #define LIBAVUTIL_VERSION_MINOR 31
#define LIBAVUTIL_VERSION_MICRO 103 #define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \ LIBAVUTIL_VERSION_MINOR, \
@ -78,9 +93,7 @@
#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION) #define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)
/** /**
* @} * @defgroup lavu_depr_guards Deprecation Guards
*
* @defgroup depr_guards Deprecation guards
* FF_API_* defines may be placed below to indicate public API that will be * FF_API_* defines may be placed below to indicate public API that will be
* dropped at a future version bump. The defines themselves are not part of * dropped at a future version bump. The defines themselves are not part of
* the public API and may change, break or disappear at any time. * the public API and may change, break or disappear at any time.
@ -92,36 +105,34 @@
* @{ * @{
*/ */
#ifndef FF_API_VDPAU
#define FF_API_VDPAU (LIBAVUTIL_VERSION_MAJOR < 56)
#endif
#ifndef FF_API_XVMC
#define FF_API_XVMC (LIBAVUTIL_VERSION_MAJOR < 56)
#endif
#ifndef FF_API_OPT_TYPE_METADATA
#define FF_API_OPT_TYPE_METADATA (LIBAVUTIL_VERSION_MAJOR < 56)
#endif
#ifndef FF_API_DLOG
#define FF_API_DLOG (LIBAVUTIL_VERSION_MAJOR < 56)
#endif
#ifndef FF_API_VAAPI #ifndef FF_API_VAAPI
#define FF_API_VAAPI (LIBAVUTIL_VERSION_MAJOR < 56) #define FF_API_VAAPI (LIBAVUTIL_VERSION_MAJOR < 57)
#endif #endif
#ifndef FF_API_FRAME_QP #ifndef FF_API_FRAME_QP
#define FF_API_FRAME_QP (LIBAVUTIL_VERSION_MAJOR < 56) #define FF_API_FRAME_QP (LIBAVUTIL_VERSION_MAJOR < 57)
#endif #endif
#ifndef FF_API_PLUS1_MINUS1 #ifndef FF_API_PLUS1_MINUS1
#define FF_API_PLUS1_MINUS1 (LIBAVUTIL_VERSION_MAJOR < 56) #define FF_API_PLUS1_MINUS1 (LIBAVUTIL_VERSION_MAJOR < 57)
#endif #endif
#ifndef FF_API_ERROR_FRAME #ifndef FF_API_ERROR_FRAME
#define FF_API_ERROR_FRAME (LIBAVUTIL_VERSION_MAJOR < 56) #define FF_API_ERROR_FRAME (LIBAVUTIL_VERSION_MAJOR < 57)
#endif
#ifndef FF_API_PKT_PTS
#define FF_API_PKT_PTS (LIBAVUTIL_VERSION_MAJOR < 57)
#endif #endif
#ifndef FF_API_CRC_BIG_TABLE #ifndef FF_API_CRYPTO_SIZE_T
#define FF_API_CRC_BIG_TABLE (LIBAVUTIL_VERSION_MAJOR < 56) #define FF_API_CRYPTO_SIZE_T (LIBAVUTIL_VERSION_MAJOR < 57)
#endif
#ifndef FF_API_FRAME_GET_SET
#define FF_API_FRAME_GET_SET (LIBAVUTIL_VERSION_MAJOR < 57)
#endif
#ifndef FF_API_PSEUDOPAL
#define FF_API_PSEUDOPAL (LIBAVUTIL_VERSION_MAJOR < 57)
#endif #endif
/** /**
* @}
* @} * @}
*/ */

@ -53,10 +53,6 @@ const char *postproc_license(void);
#define PP_QUALITY_MAX 6 #define PP_QUALITY_MAX 6
#if FF_API_QP_TYPE
#define QP_STORE_T int8_t //deprecated
#endif
#include <inttypes.h> #include <inttypes.h>
typedef void pp_context; typedef void pp_context;

@ -28,8 +28,8 @@
#include "libavutil/avutil.h" #include "libavutil/avutil.h"
#define LIBPOSTPROC_VERSION_MAJOR 54 #define LIBPOSTPROC_VERSION_MAJOR 55
#define LIBPOSTPROC_VERSION_MINOR 1 #define LIBPOSTPROC_VERSION_MINOR 5
#define LIBPOSTPROC_VERSION_MICRO 100 #define LIBPOSTPROC_VERSION_MICRO 100
#define LIBPOSTPROC_VERSION_INT AV_VERSION_INT(LIBPOSTPROC_VERSION_MAJOR, \ #define LIBPOSTPROC_VERSION_INT AV_VERSION_INT(LIBPOSTPROC_VERSION_MAJOR, \
@ -42,8 +42,4 @@
#define LIBPOSTPROC_IDENT "postproc" AV_STRINGIFY(LIBPOSTPROC_VERSION) #define LIBPOSTPROC_IDENT "postproc" AV_STRINGIFY(LIBPOSTPROC_VERSION)
#ifndef FF_API_QP_TYPE
#define FF_API_QP_TYPE (LIBPOSTPROC_VERSION_MAJOR < 55)
#endif
#endif /* POSTPROC_VERSION_H */ #endif /* POSTPROC_VERSION_H */

@ -28,11 +28,10 @@
*/ */
/** /**
* @defgroup lswr Libswresample * @defgroup lswr libswresample
* @{ * @{
* *
* Libswresample (lswr) is a library that handles audio resampling, sample * Audio resampling, sample format conversion and mixing library.
* format conversion and mixing.
* *
* Interaction with lswr is done through SwrContext, which is * Interaction with lswr is done through SwrContext, which is
* allocated with swr_alloc() or swr_alloc_set_opts(). It is opaque, so all parameters * allocated with swr_alloc() or swr_alloc_set_opts(). It is opaque, so all parameters
@ -121,15 +120,12 @@
*/ */
#include <stdint.h> #include <stdint.h>
#include "libavutil/channel_layout.h"
#include "libavutil/frame.h" #include "libavutil/frame.h"
#include "libavutil/samplefmt.h" #include "libavutil/samplefmt.h"
#include "libswresample/version.h" #include "libswresample/version.h"
#if LIBSWRESAMPLE_VERSION_MAJOR < 1
#define SWR_CH_MAX 32 ///< Maximum number of channels
#endif
/** /**
* @name Option constants * @name Option constants
* These constants are used for the @ref avoptions interface for lswr. * These constants are used for the @ref avoptions interface for lswr.
@ -366,6 +362,36 @@ int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensatio
*/ */
int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map); int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
/**
* Generate a channel mixing matrix.
*
* This function is the one used internally by libswresample for building the
* default mixing matrix. It is made public just as a utility function for
* building custom matrices.
*
* @param in_layout input channel layout
* @param out_layout output channel layout
* @param center_mix_level mix level for the center channel
* @param surround_mix_level mix level for the surround channel(s)
* @param lfe_mix_level mix level for the low-frequency effects channel
* @param rematrix_maxval if 1.0, coefficients will be normalized to prevent
* overflow. if INT_MAX, coefficients will not be
* normalized.
* @param[out] matrix mixing coefficients; matrix[i + stride * o] is
* the weight of input channel i in output channel o.
* @param stride distance between adjacent input channels in the
* matrix array
* @param matrix_encoding matrixed stereo downmix mode (e.g. dplii)
* @param log_ctx parent logging context, can be NULL
* @return 0 on success, negative AVERROR code on failure
*/
int swr_build_matrix(uint64_t in_layout, uint64_t out_layout,
double center_mix_level, double surround_mix_level,
double lfe_mix_level, double rematrix_maxval,
double rematrix_volume, double *matrix,
int stride, enum AVMatrixEncoding matrix_encoding,
void *log_ctx);
/** /**
* Set a customized remix matrix. * Set a customized remix matrix.
* *

@ -28,9 +28,9 @@
#include "libavutil/avutil.h" #include "libavutil/avutil.h"
#define LIBSWRESAMPLE_VERSION_MAJOR 2 #define LIBSWRESAMPLE_VERSION_MAJOR 3
#define LIBSWRESAMPLE_VERSION_MINOR 0 #define LIBSWRESAMPLE_VERSION_MINOR 5
#define LIBSWRESAMPLE_VERSION_MICRO 101 #define LIBSWRESAMPLE_VERSION_MICRO 100
#define LIBSWRESAMPLE_VERSION_INT AV_VERSION_INT(LIBSWRESAMPLE_VERSION_MAJOR, \ #define LIBSWRESAMPLE_VERSION_INT AV_VERSION_INT(LIBSWRESAMPLE_VERSION_MAJOR, \
LIBSWRESAMPLE_VERSION_MINOR, \ LIBSWRESAMPLE_VERSION_MINOR, \

@ -35,7 +35,9 @@
#include "version.h" #include "version.h"
/** /**
* @defgroup libsws Color conversion and scaling * @defgroup libsws libswscale
* Color conversion and scaling library.
*
* @{ * @{
* *
* Return the LIBSWSCALE_VERSION_INT constant. * Return the LIBSWSCALE_VERSION_INT constant.
@ -73,7 +75,7 @@ const char *swscale_license(void);
#define SWS_PRINT_INFO 0x1000 #define SWS_PRINT_INFO 0x1000
//the following 3 flags are not completely implemented //the following 3 flags are not completely implemented
//internal chrominace subsampling info //internal chrominance subsampling info
#define SWS_FULL_CHR_H_INT 0x2000 #define SWS_FULL_CHR_H_INT 0x2000
//input subsampling info //input subsampling info
#define SWS_FULL_CHR_H_INP 0x4000 #define SWS_FULL_CHR_H_INP 0x4000
@ -91,6 +93,7 @@ const char *swscale_license(void);
#define SWS_CS_SMPTE170M 5 #define SWS_CS_SMPTE170M 5
#define SWS_CS_SMPTE240M 7 #define SWS_CS_SMPTE240M 7
#define SWS_CS_DEFAULT 5 #define SWS_CS_DEFAULT 5
#define SWS_CS_BT2020 9
/** /**
* Return a pointer to yuv<->rgb coefficients for the given colorspace * Return a pointer to yuv<->rgb coefficients for the given colorspace
@ -247,18 +250,6 @@ SwsVector *sws_allocVec(int length);
*/ */
SwsVector *sws_getGaussianVec(double variance, double quality); SwsVector *sws_getGaussianVec(double variance, double quality);
/**
* Allocate and return a vector with length coefficients, all
* with the same value c.
*/
SwsVector *sws_getConstVec(double c, int length);
/**
* Allocate and return a vector with just one coefficient, with
* value 1.0.
*/
SwsVector *sws_getIdentityVec(void);
/** /**
* Scale all the coefficients of a by the scalar value. * Scale all the coefficients of a by the scalar value.
*/ */
@ -268,22 +259,17 @@ void sws_scaleVec(SwsVector *a, double scalar);
* Scale all the coefficients of a so that their sum equals height. * Scale all the coefficients of a so that their sum equals height.
*/ */
void sws_normalizeVec(SwsVector *a, double height); void sws_normalizeVec(SwsVector *a, double height);
void sws_convVec(SwsVector *a, SwsVector *b);
void sws_addVec(SwsVector *a, SwsVector *b);
void sws_subVec(SwsVector *a, SwsVector *b);
void sws_shiftVec(SwsVector *a, int shift);
/**
* Allocate and return a clone of the vector a, that is a vector
* with the same coefficients as a.
*/
SwsVector *sws_cloneVec(SwsVector *a);
/** #if FF_API_SWS_VECTOR
* Print with av_log() a textual representation of the vector a attribute_deprecated SwsVector *sws_getConstVec(double c, int length);
* if log_level <= av_log_level. attribute_deprecated SwsVector *sws_getIdentityVec(void);
*/ attribute_deprecated void sws_convVec(SwsVector *a, SwsVector *b);
void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level); attribute_deprecated void sws_addVec(SwsVector *a, SwsVector *b);
attribute_deprecated void sws_subVec(SwsVector *a, SwsVector *b);
attribute_deprecated void sws_shiftVec(SwsVector *a, int shift);
attribute_deprecated SwsVector *sws_cloneVec(SwsVector *a);
attribute_deprecated void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level);
#endif
void sws_freeVec(SwsVector *a); void sws_freeVec(SwsVector *a);

@ -26,8 +26,8 @@
#include "libavutil/version.h" #include "libavutil/version.h"
#define LIBSWSCALE_VERSION_MAJOR 4 #define LIBSWSCALE_VERSION_MAJOR 5
#define LIBSWSCALE_VERSION_MINOR 0 #define LIBSWSCALE_VERSION_MINOR 5
#define LIBSWSCALE_VERSION_MICRO 100 #define LIBSWSCALE_VERSION_MICRO 100
#define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \ #define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \
@ -46,4 +46,8 @@
* the public API and may change, break or disappear at any time. * the public API and may change, break or disappear at any time.
*/ */
#ifndef FF_API_SWS_VECTOR
#define FF_API_SWS_VECTOR (LIBSWSCALE_VERSION_MAJOR < 6)
#endif
#endif /* SWSCALE_VERSION_H */ #endif /* SWSCALE_VERSION_H */

Loading…
Cancel
Save