Audacity  3.0.3
Classes | Macros | Typedefs | Functions
FFmpeg.h File Reference
#include "widgets/wxPanelWrapper.h"
#include <errno.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/error.h>
#include <libavutil/fifo.h>
#include <libavutil/mathematics.h>
#include "ShuttleGui.h"
#include "Prefs.h"
#include "Identifier.h"
Include dependency graph for FFmpeg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  FFmpegNotFoundDialog
 
class  FFmpegLibs
 Class used to dynamically load FFmpeg libraries. More...
 
struct  FFmpegContext
 
struct  AVPacketEx
 
struct  AV_Deleter< T, R, Fn >
 AV_Deleter is part of FFmpeg support. It's used with the RAII idiom. More...
 
struct  AV_Deleter< T, void, Fn >
 
struct  AV_Deleterp< T, R, Fn >
 
struct  UFileHolder
 FFmpeg structure to hold a file pointer and provide a return value when closing the file. More...
 
struct  streamContext
 

Macros

#define IS_FFMPEG_PROJECT   1
 
#define AV_CODEC_FLAG_QSCALE   CODEC_FLAG_QSCALE
 
#define AV_CODEC_FLAG_GLOBAL_HEADER   CODEC_FLAG_GLOBAL_HEADER
 
#define AV_CODEC_CAP_SMALL_LAST_FRAME   CODEC_CAP_SMALL_LAST_FRAME
 
#define FFX   extern
 
#define FFMPEG_FUNCTION_WITH_RETURN(r, n, a, p)
 
#define FFMPEG_FUNCTION_NO_RETURN(n, a, p)
 
#define FFMPEG_INITDYN(w, f)
 
#define FFMPEG_INITALT(w, f, x, a)
 

Typedefs

using AVFrameHolder = std::unique_ptr< AVFrame, AV_Deleterp< AVFrame, void, av_frame_free > >
 
using AVFifoBufferHolder = std::unique_ptr< AVFifoBuffer, AV_Deleter< AVFifoBuffer, void, av_fifo_free > >
 
using AVFormatContextHolder = std::unique_ptr< AVFormatContext, AV_Deleter< AVFormatContext, void, avformat_free_context > >
 
using AVCodecContextHolder = std::unique_ptr< AVCodecContext, AV_Deleter< AVCodecContext, int, avcodec_close > >
 
using AVDictionaryCleanup = std::unique_ptr< AVDictionary *, AV_Deleter< AVDictionary *, void, av_dict_free > >
 
template<typename T >
using AVMallocHolder = std::unique_ptr< T, AV_Deleter< void, void, av_free > >
 
using Scs = ArrayOf< std::unique_ptr< streamContext > >
 
using ScsPtr = std::shared_ptr< Scs >
 

Functions

void av_log_wx_callback (void *ptr, int level, const char *fmt, va_list vl)
 Callback function to catch FFmpeg log messages. More...
 
TranslatableString GetFFmpegVersion ()
 
void FFmpegStartup ()
 
bool LoadFFmpeg (bool showerror)
 
FFmpegLibsPickFFmpegLibs ()
 
void DropFFmpegLibs ()
 
int ufile_fopen (AVIOContext **s, const FilePath &name, int flags)
 
int ufile_fopen_input (std::unique_ptr< FFmpegContext > &context_ptr, FilePath &name)
 
int ufile_close (AVIOContext *pb)
 
streamContextimport_ffmpeg_read_next_frame (AVFormatContext *formatContext, streamContext **streams, unsigned int numStreams)
 
int import_ffmpeg_decode_frame (streamContext *sc, bool flushing)
 
 FFMPEG_FUNCTION_WITH_RETURN (unsigned, avutil_version,(void),())
 
 FFMPEG_FUNCTION_NO_RETURN (av_log_set_callback,(void(*cb)(void *, int, const char *, va_list)),(cb))
 
 FFMPEG_FUNCTION_NO_RETURN (av_log_default_callback,(void *ptr, int level, const char *fmt, va_list vl),(ptr, level, fmt, vl))
 
 FFMPEG_FUNCTION_NO_RETURN (av_free,(void *ptr),(ptr))
 
 FFMPEG_FUNCTION_WITH_RETURN (int64_t, av_get_default_channel_layout,(int nb_channels),(nb_channels))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_strerror,(int errnum, char *errbuf, size_t errbuf_size),(errnum, errbuf, errbuf_size))
 
 FFMPEG_FUNCTION_WITH_RETURN (unsigned, avcodec_version,(void),())
 
 FFMPEG_FUNCTION_WITH_RETURN (AVCodec *, avcodec_find_encoder,(enum AVCodecID id),(id))
 
 FFMPEG_FUNCTION_WITH_RETURN (AVCodec *, avcodec_find_encoder_by_name,(const char *name),(name))
 
 FFMPEG_FUNCTION_WITH_RETURN (AVCodec *, avcodec_find_decoder,(enum AVCodecID id),(id))
 
 FFMPEG_FUNCTION_WITH_RETURN (const char *, avcodec_get_name,(enum AVCodecID id),(id))
 
 FFMPEG_FUNCTION_WITH_RETURN (unsigned int, av_codec_get_tag,(const struct AVCodecTag *const *tags, enum AVCodecID id),(tags, id))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, avcodec_open2,(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options),(avctx, codec, options);)
 
 FFMPEG_FUNCTION_WITH_RETURN (int, avcodec_decode_audio4,(AVCodecContext *avctx, AVFrame *frame, int *got_output, const AVPacket *avpkt),(avctx, frame, got_output, avpkt))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, avcodec_encode_audio2,(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_output),(avctx, pkt, frame, got_output))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, avcodec_close,(AVCodecContext *avctx),(avctx))
 
 FFMPEG_FUNCTION_NO_RETURN (avcodec_register_all,(void),())
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_get_bytes_per_sample,(enum AVSampleFormat sample_fmt),(sample_fmt))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, avcodec_fill_audio_frame,(AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align),(frame, nb_channels, sample_fmt, buf, buf_size, align))
 
 FFMPEG_FUNCTION_WITH_RETURN (unsigned, avformat_version,(void),())
 
 FFMPEG_FUNCTION_WITH_RETURN (int, avformat_open_input,(AVFormatContext **ic_ptr, const char *filename, AVInputFormat *fmt, AVDictionary **options),(ic_ptr, filename, fmt, options))
 
 FFMPEG_FUNCTION_NO_RETURN (av_register_all,(void),())
 
 FFMPEG_FUNCTION_WITH_RETURN (int, avformat_find_stream_info,(AVFormatContext *ic, AVDictionary **options),(ic, options))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_read_frame,(AVFormatContext *s, AVPacket *pkt),(s, pkt))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_seek_frame,(AVFormatContext *s, int stream_index, int64_t timestamp, int flags),(s, stream_index, timestamp, flags))
 
 FFMPEG_FUNCTION_NO_RETURN (avformat_close_input,(AVFormatContext **s),(s))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, avformat_write_header,(AVFormatContext *s, AVDictionary **options),(s, options))
 
 FFMPEG_FUNCTION_WITH_RETURN (AVOutputFormat *, av_oformat_next,(const AVOutputFormat *f),(f))
 
 FFMPEG_FUNCTION_WITH_RETURN (AVCodec *, av_codec_next,(const AVCodec *c),(c))
 
 FFMPEG_FUNCTION_WITH_RETURN (AVStream *, avformat_new_stream,(AVFormatContext *s, const AVCodec *c),(s, c))
 
 FFMPEG_FUNCTION_WITH_RETURN (AVFormatContext *, avformat_alloc_context,(void),())
 
 FFMPEG_FUNCTION_WITH_RETURN (AVOutputFormat *, av_guess_format,(const char *short_name, const char *filename, const char *mime_type),(short_name, filename, mime_type))
 
 FFMPEG_FUNCTION_NO_RETURN (avformat_free_context,(AVFormatContext *s),(s))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_write_trailer,(AVFormatContext *s),(s))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_interleaved_write_frame,(AVFormatContext *s, AVPacket *pkt),(s, pkt))
 
 FFMPEG_FUNCTION_NO_RETURN (av_init_packet,(AVPacket *pkt),(pkt))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_fifo_generic_write,(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int)),(f, src, size, func))
 
 FFMPEG_FUNCTION_NO_RETURN (av_fifo_free,(AVFifoBuffer *f),(f))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_fifo_size,(AVFifoBuffer *f),(f))
 
 FFMPEG_FUNCTION_WITH_RETURN (void *, av_malloc,(size_t size),(size))
 
 FFMPEG_FUNCTION_WITH_RETURN (int64_t, av_rescale_q,(int64_t a, AVRational bq, AVRational cq),(a, bq, cq))
 
 FFMPEG_FUNCTION_NO_RETURN (av_free_packet,(AVPacket *pkt),(pkt))
 
 FFMPEG_FUNCTION_WITH_RETURN (AVFifoBuffer *, av_fifo_alloc,(unsigned int size),(size))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_fifo_generic_read,(AVFifoBuffer *f, void *buf, int buf_size, void(*func)(void *, void *, int)),(f, buf, buf_size, func))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_fifo_realloc2,(AVFifoBuffer *f, unsigned int size),(f, size))
 
 FFMPEG_FUNCTION_NO_RETURN (av_dict_free,(AVDictionary **m),(m))
 
 FFMPEG_FUNCTION_WITH_RETURN (AVDictionaryEntry *, av_dict_get,(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags),(m, key, prev, flags))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_dict_set,(AVDictionary **pm, const char *key, const char *value, int flags),(pm, key, value, flags))
 
 FFMPEG_FUNCTION_WITH_RETURN (int64_t, avio_size,(AVIOContext *s),(s))
 
 FFMPEG_FUNCTION_WITH_RETURN (AVIOContext *, avio_alloc_context,(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_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)),(buffer, buffer_size, write_flag, opaque, read_packet, write_packet, seek))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_codec_is_encoder,(const AVCodec *codec),(codec))
 
 FFMPEG_FUNCTION_WITH_RETURN (AVFrame *, av_frame_alloc,(void),())
 
 FFMPEG_FUNCTION_NO_RETURN (av_frame_free,(AVFrame **frame),(frame))
 
 FFMPEG_FUNCTION_WITH_RETURN (int, av_samples_get_buffer_size,(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align),(linesize, nb_channels, nb_samples, sample_fmt, align))
 
FFmpegLibsFFmpegLibsInst ()
 

Macro Definition Documentation

◆ AV_CODEC_CAP_SMALL_LAST_FRAME

#define AV_CODEC_CAP_SMALL_LAST_FRAME   CODEC_CAP_SMALL_LAST_FRAME

Definition at line 142 of file FFmpeg.h.

◆ AV_CODEC_FLAG_GLOBAL_HEADER

#define AV_CODEC_FLAG_GLOBAL_HEADER   CODEC_FLAG_GLOBAL_HEADER

Definition at line 139 of file FFmpeg.h.

◆ AV_CODEC_FLAG_QSCALE

#define AV_CODEC_FLAG_QSCALE   CODEC_FLAG_QSCALE

Definition at line 136 of file FFmpeg.h.

◆ FFMPEG_FUNCTION_NO_RETURN

#define FFMPEG_FUNCTION_NO_RETURN (   n,
  a,
 
)
Value:
extern "C" \
{ \
FFX void (*n ## _fp) a; \
inline void n a \
{ \
n ## _fp p; \
} \
}

Definition at line 457 of file FFmpeg.h.

◆ FFMPEG_FUNCTION_WITH_RETURN

#define FFMPEG_FUNCTION_WITH_RETURN (   r,
  n,
  a,
 
)
Value:
extern "C" \
{ \
FFX r (*n ## _fp) a; \
inline r n a \
{ \
return n ## _fp p; \
} \
}

Definition at line 447 of file FFmpeg.h.

◆ FFMPEG_INITALT

#define FFMPEG_INITALT (   w,
  f,
  x,
 
)
Value:
{ \
wxLogNull off; \
*(void**)&f ## _fp = (void*)w->GetSymbol(wxT(#f)); \
} \
if (f ## _fp == NULL) \
{ \
{ \
wxLogNull off; \
*(void**)&f ## _fp = (void*)x->GetSymbol(wxT(#a)); \
} \
if (f ## _fp == NULL) \
{ \
wxLogError(wxT("Failed to load symbol ") wxT(#f)); \
return false; \
} \
}

Definition at line 478 of file FFmpeg.h.

◆ FFMPEG_INITDYN

#define FFMPEG_INITDYN (   w,
 
)
Value:
{ \
wxLogNull off; \
*(void**)&f ## _fp = (void*)w->GetSymbol(wxT(#f)); \
} \
if (f ## _fp == NULL) \
{ \
wxLogError(wxT("Failed to load symbol ") wxT(#f)); \
return false; \
}

Definition at line 467 of file FFmpeg.h.

◆ FFX

#define FFX   extern

Definition at line 444 of file FFmpeg.h.

◆ IS_FFMPEG_PROJECT

#define IS_FFMPEG_PROJECT   1

Definition at line 31 of file FFmpeg.h.

Typedef Documentation

◆ AVCodecContextHolder

using AVCodecContextHolder = std::unique_ptr< AVCodecContext, AV_Deleter<AVCodecContext, int, avcodec_close> >

Definition at line 971 of file FFmpeg.h.

◆ AVDictionaryCleanup

using AVDictionaryCleanup = std::unique_ptr< AVDictionary*, AV_Deleter<AVDictionary*, void, av_dict_free> >

Definition at line 974 of file FFmpeg.h.

◆ AVFifoBufferHolder

using AVFifoBufferHolder = std::unique_ptr< AVFifoBuffer, AV_Deleter<AVFifoBuffer, void, av_fifo_free> >

Definition at line 965 of file FFmpeg.h.

◆ AVFormatContextHolder

using AVFormatContextHolder = std::unique_ptr< AVFormatContext, AV_Deleter<AVFormatContext, void, avformat_free_context> >

Definition at line 968 of file FFmpeg.h.

◆ AVFrameHolder

using AVFrameHolder = std::unique_ptr< AVFrame, AV_Deleterp<AVFrame, void, av_frame_free> >

Definition at line 962 of file FFmpeg.h.

◆ AVMallocHolder

template<typename T >
using AVMallocHolder = std::unique_ptr< T, AV_Deleter<void, void, av_free> >

Definition at line 1000 of file FFmpeg.h.

◆ Scs

using Scs = ArrayOf<std::unique_ptr<streamContext> >

Definition at line 1035 of file FFmpeg.h.

◆ ScsPtr

using ScsPtr = std::shared_ptr<Scs>

Definition at line 1036 of file FFmpeg.h.

Function Documentation

◆ av_log_wx_callback()

void av_log_wx_callback ( void *  ptr,
int  level,
const char *  fmt,
va_list  vl 
)

Callback function to catch FFmpeg log messages.

Definition at line 128 of file FFmpeg.cpp.

129 {
130  //Most of this stuff is taken from FFmpeg tutorials and FFmpeg itself
131  int av_log_level = AV_LOG_INFO;
132  AVClass* avc = ptr ? *(AVClass**)ptr : NULL;
133  if (level > av_log_level)
134  return;
135  wxString printstring(wxT(""));
136 
137  if (avc) {
138  printstring.Append(wxString::Format(wxT("[%s @ %p] "), wxString::FromUTF8(avc->item_name(ptr)), avc));
139  }
140 
141  wxString frm(fmt,wxConvLibc);
142 
143  printstring.Append(wxString::FormatV(frm,vl));
144  wxString cpt;
145  switch (level)
146  {
147  case 0: cpt = wxT("Error"); break;
148  case 1: cpt = wxT("Info"); break;
149  case 2: cpt = wxT("Debug"); break;
150  default: cpt = wxT("Log"); break;
151  }
152  wxLogDebug(wxT("%s: %s"),cpt,printstring);
153 }

Referenced by FFmpegImportFileHandle::Init(), and ExportFFmpeg::Init().

Here is the caller graph for this function:

◆ DropFFmpegLibs()

void DropFFmpegLibs ( )

! Helper function - destroys FFmpegLibs object if there is no need for it anymore, or just decrements its reference count

Definition at line 61 of file FFmpeg.cpp.

62 {
63  if (FFmpegLibsPtr)
64  {
65  FFmpegLibsPtr->refcount--;
66  if (FFmpegLibsPtr->refcount == 0)
67  FFmpegLibsPtr.reset();
68  }
69 }

References FFmpegLibsPtr.

Referenced by CheckFFmpegPresence(), GetFFmpegVersion(), LoadFFmpeg(), AudacityApp::OnExit(), LibraryPrefs::OnFFmpegFindButton(), ExportFFmpegCustomOptions::OnOpen(), ExportFFmpeg::~ExportFFmpeg(), ExportFFmpegOptions::~ExportFFmpegOptions(), and FFmpegImportFileHandle::~FFmpegImportFileHandle().

Here is the caller graph for this function:

◆ FFMPEG_FUNCTION_NO_RETURN() [1/12]

FFMPEG_FUNCTION_NO_RETURN ( av_dict_free  ,
(AVDictionary **m)  ,
(m)   
)

◆ FFMPEG_FUNCTION_NO_RETURN() [2/12]

FFMPEG_FUNCTION_NO_RETURN ( av_fifo_free  ,
(AVFifoBuffer *f)  ,
(f)   
)

◆ FFMPEG_FUNCTION_NO_RETURN() [3/12]

FFMPEG_FUNCTION_NO_RETURN ( av_frame_free  ,
(AVFrame **frame)  ,
(frame)   
)

◆ FFMPEG_FUNCTION_NO_RETURN() [4/12]

FFMPEG_FUNCTION_NO_RETURN ( av_free  ,
(void *ptr)  ,
(ptr)   
)

◆ FFMPEG_FUNCTION_NO_RETURN() [5/12]

FFMPEG_FUNCTION_NO_RETURN ( av_free_packet  ,
(AVPacket *pkt)  ,
(pkt)   
)

◆ FFMPEG_FUNCTION_NO_RETURN() [6/12]

FFMPEG_FUNCTION_NO_RETURN ( av_init_packet  ,
(AVPacket *pkt)  ,
(pkt)   
)

◆ FFMPEG_FUNCTION_NO_RETURN() [7/12]

FFMPEG_FUNCTION_NO_RETURN ( av_log_default_callback  ,
(void *ptr, int level, const char *fmt, va_list vl)  ,
(ptr, level, fmt, vl)   
)

◆ FFMPEG_FUNCTION_NO_RETURN() [8/12]

FFMPEG_FUNCTION_NO_RETURN ( av_log_set_callback  ,
(void(*cb)(void *, int, const char *, va_list))  ,
(cb)   
)

◆ FFMPEG_FUNCTION_NO_RETURN() [9/12]

FFMPEG_FUNCTION_NO_RETURN ( av_register_all  ,
(void)  ,
()   
)

◆ FFMPEG_FUNCTION_NO_RETURN() [10/12]

FFMPEG_FUNCTION_NO_RETURN ( avcodec_register_all  ,
(void)  ,
()   
)

◆ FFMPEG_FUNCTION_NO_RETURN() [11/12]

FFMPEG_FUNCTION_NO_RETURN ( avformat_close_input  ,
(AVFormatContext **s)  ,
(s)   
)

◆ FFMPEG_FUNCTION_NO_RETURN() [12/12]

FFMPEG_FUNCTION_NO_RETURN ( avformat_free_context  ,
(AVFormatContext *s)  ,
(s)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [1/42]

FFMPEG_FUNCTION_WITH_RETURN ( AVCodec *  ,
av_codec_next  ,
(const AVCodec *c)  ,
(c)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [2/42]

FFMPEG_FUNCTION_WITH_RETURN ( AVCodec *  ,
avcodec_find_decoder  ,
(enum AVCodecID id ,
(id  
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [3/42]

FFMPEG_FUNCTION_WITH_RETURN ( AVCodec *  ,
avcodec_find_encoder  ,
(enum AVCodecID id ,
(id  
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [4/42]

FFMPEG_FUNCTION_WITH_RETURN ( AVCodec *  ,
avcodec_find_encoder_by_name  ,
(const char *name ,
(name  
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [5/42]

FFMPEG_FUNCTION_WITH_RETURN ( AVDictionaryEntry *  ,
av_dict_get  ,
(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)  ,
(m, key, prev, flags)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [6/42]

FFMPEG_FUNCTION_WITH_RETURN ( AVFifoBuffer *  ,
av_fifo_alloc  ,
(unsigned int size)  ,
(size)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [7/42]

FFMPEG_FUNCTION_WITH_RETURN ( AVFormatContext *  ,
avformat_alloc_context  ,
(void)  ,
()   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [8/42]

FFMPEG_FUNCTION_WITH_RETURN ( AVFrame *  ,
av_frame_alloc  ,
(void)  ,
()   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [9/42]

FFMPEG_FUNCTION_WITH_RETURN ( AVIOContext *  ,
avio_alloc_context  ,
(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_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))  ,
(buffer, buffer_size, write_flag, opaque, read_packet, write_packet, seek)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [10/42]

FFMPEG_FUNCTION_WITH_RETURN ( AVOutputFormat *  ,
av_guess_format  ,
(const char *short_name, const char *filename, const char *mime_type)  ,
(short_name, filename, mime_type)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [11/42]

FFMPEG_FUNCTION_WITH_RETURN ( AVOutputFormat *  ,
av_oformat_next  ,
(const AVOutputFormat *f)  ,
(f)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [12/42]

FFMPEG_FUNCTION_WITH_RETURN ( AVStream *  ,
avformat_new_stream  ,
(AVFormatContext *s, const AVCodec *c)  ,
(s, c)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [13/42]

FFMPEG_FUNCTION_WITH_RETURN ( const char *  ,
avcodec_get_name  ,
(enum AVCodecID id ,
(id  
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [14/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_codec_is_encoder  ,
(const AVCodec *codec)  ,
(codec)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [15/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_dict_set  ,
(AVDictionary **pm, const char *key, const char *value, int flags)  ,
(pm, key, value, flags)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [16/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_fifo_generic_read  ,
(AVFifoBuffer *f, void *buf, int buf_size, void(*func)(void *, void *, int))  ,
(f, buf, buf_size, func)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [17/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_fifo_generic_write  ,
(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))  ,
(f, src, size, func)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [18/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_fifo_realloc2  ,
(AVFifoBuffer *f, unsigned int size)  ,
(f, size)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [19/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_fifo_size  ,
(AVFifoBuffer *f)  ,
(f)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [20/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_get_bytes_per_sample  ,
(enum AVSampleFormat sample_fmt)  ,
(sample_fmt)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [21/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_interleaved_write_frame  ,
(AVFormatContext *s, AVPacket *pkt)  ,
(s, pkt)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [22/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_read_frame  ,
(AVFormatContext *s, AVPacket *pkt)  ,
(s, pkt)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [23/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_samples_get_buffer_size  ,
(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)  ,
(linesize, nb_channels, nb_samples, sample_fmt, align)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [24/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_seek_frame  ,
(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)  ,
(s, stream_index, timestamp, flags)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [25/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_strerror  ,
(int errnum, char *errbuf, size_t errbuf_size)  ,
(errnum, errbuf, errbuf_size)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [26/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
av_write_trailer  ,
(AVFormatContext *s)  ,
(s)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [27/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
avcodec_close  ,
(AVCodecContext *avctx)  ,
(avctx)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [28/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
avcodec_decode_audio4  ,
(AVCodecContext *avctx, AVFrame *frame, int *got_output, const AVPacket *avpkt)  ,
(avctx, frame, got_output, avpkt)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [29/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
avcodec_encode_audio2  ,
(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_output)  ,
(avctx, pkt, frame, got_output)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [30/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
avcodec_fill_audio_frame  ,
(AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align)  ,
(frame, nb_channels, sample_fmt, buf, buf_size, align)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [31/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
avcodec_open2  ,
(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)  ,
(avctx, codec, options);   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [32/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
avformat_find_stream_info  ,
(AVFormatContext *ic, AVDictionary **options)  ,
(ic, options)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [33/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
avformat_open_input  ,
(AVFormatContext **ic_ptr, const char *filename, AVInputFormat *fmt, AVDictionary **options)  ,
(ic_ptr, filename, fmt, options)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [34/42]

FFMPEG_FUNCTION_WITH_RETURN ( int  ,
avformat_write_header  ,
(AVFormatContext *s, AVDictionary **options)  ,
(s, options)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [35/42]

FFMPEG_FUNCTION_WITH_RETURN ( int64_t  ,
av_get_default_channel_layout  ,
(int nb_channels)  ,
(nb_channels)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [36/42]

FFMPEG_FUNCTION_WITH_RETURN ( int64_t  ,
av_rescale_q  ,
(int64_t a, AVRational bq, AVRational cq)  ,
(a, bq, cq)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [37/42]

FFMPEG_FUNCTION_WITH_RETURN ( int64_t  ,
avio_size  ,
(AVIOContext *s)  ,
(s)   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [38/42]

FFMPEG_FUNCTION_WITH_RETURN ( unsigned int  ,
av_codec_get_tag  ,
(const struct AVCodecTag *const *tags, enum AVCodecID id ,
(tags, id  
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [39/42]

FFMPEG_FUNCTION_WITH_RETURN ( unsigned  ,
avcodec_version  ,
(void)  ,
()   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [40/42]

FFMPEG_FUNCTION_WITH_RETURN ( unsigned  ,
avformat_version  ,
(void)  ,
()   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [41/42]

FFMPEG_FUNCTION_WITH_RETURN ( unsigned  ,
avutil_version  ,
(void)  ,
()   
)

◆ FFMPEG_FUNCTION_WITH_RETURN() [42/42]

FFMPEG_FUNCTION_WITH_RETURN ( void *  ,
av_malloc  ,
(size_t size)  ,
(size)   
)

◆ FFmpegLibsInst()

FFmpegLibs* FFmpegLibsInst ( )

◆ FFmpegStartup()

void FFmpegStartup ( )

Called during Audacity start-up to try and load the ffmpeg libraries

Definition at line 95 of file FFmpeg.cpp.

96 {
97  bool enabled = false;
98  gPrefs->Read(wxT("/FFmpeg/Enabled"),&enabled);
99  // 'false' means that no errors should be shown whatsoever
100  if (!LoadFFmpeg(false))
101  {
102  if (enabled)
103  {
105 "FFmpeg was configured in Preferences and successfully loaded before, \
106 \nbut this time Audacity failed to load it at startup. \
107 \n\nYou may want to go back to Preferences > Libraries and re-configure it."),
108  XO("FFmpeg startup failed"));
109  }
110  }
111 }

References AudacityMessageBox(), gPrefs, LoadFFmpeg(), and XO.

Referenced by AudacityApp::InitPart2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFFmpegVersion()

TranslatableString GetFFmpegVersion ( )

Definition at line 113 of file FFmpeg.cpp.

114 {
115  PickFFmpegLibs();
116 
117  auto versionString = XO("FFmpeg library not found");
118 
119  if (FFmpegLibsInst()->ValidLibsLoaded()) {
120  versionString = Verbatim( FFmpegLibsInst()->GetLibraryVersion() );
121  }
122 
123  DropFFmpegLibs();
124 
125  return versionString;
126 }

References DropFFmpegLibs(), FFmpegLibsInst(), PickFFmpegLibs(), Verbatim(), and XO.

Referenced by LibraryPrefs::SetFFmpegVersionText().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ import_ffmpeg_decode_frame()

int import_ffmpeg_decode_frame ( streamContext sc,
bool  flushing 
)

Definition at line 350 of file FFmpeg.cpp.

351 {
352  int nBytesDecoded;
353  wxUint8 *pDecode = sc->m_pktDataPtr;
354  int nDecodeSiz = sc->m_pktRemainingSiz;
355 
356  sc->m_frameValid = 0;
357 
358  if (flushing)
359  {
360  // If we're flushing the decoders we don't actually have any NEW data to decode.
361  pDecode = NULL;
362  nDecodeSiz = 0;
363  }
364  else
365  {
366  if (!sc->m_pkt || (sc->m_pktRemainingSiz <= 0))
367  {
368  //No more data
369  return -1;
370  }
371  }
372 
373  AVPacketEx avpkt;
374  avpkt.data = pDecode;
375  avpkt.size = nDecodeSiz;
376 
377  AVFrameHolder frame{ av_frame_alloc() };
378  int got_output = 0;
379 
380  nBytesDecoded =
381  avcodec_decode_audio4(sc->m_codecCtx,
382  frame.get(), // out
383  &got_output, // out
384  &avpkt); // in
385 
386  if (nBytesDecoded < 0)
387  {
388  // Decoding failed. Don't stop.
389  return -1;
390  }
391 
392  sc->m_samplefmt = sc->m_codecCtx->sample_fmt;
393  sc->m_samplesize = static_cast<size_t>(av_get_bytes_per_sample(sc->m_samplefmt));
394 
395  int channels = sc->m_codecCtx->channels;
396  auto newsize = sc->m_samplesize * frame->nb_samples * channels;
397  sc->m_decodedAudioSamplesValidSiz = newsize;
398  // Reallocate the audio sample buffer if it's smaller than the frame size.
399  if (newsize > sc->m_decodedAudioSamplesSiz )
400  {
401  // Reallocate a bigger buffer. But av_realloc is NOT compatible with the returns of av_malloc!
402  // So do this:
403  sc->m_decodedAudioSamples.reset(static_cast<uint8_t *>(av_malloc(newsize)));
404  sc->m_decodedAudioSamplesSiz = newsize;
405  if (!sc->m_decodedAudioSamples)
406  {
407  //Can't allocate bytes
408  return -1;
409  }
410  }
411  if (frame->data[1]) {
412  for (int i = 0; i<frame->nb_samples; i++) {
413  for (int ch = 0; ch<channels; ch++) {
414  memcpy(sc->m_decodedAudioSamples.get() + sc->m_samplesize * (ch + channels*i),
415  frame->extended_data[ch] + sc->m_samplesize*i,
416  sc->m_samplesize);
417  }
418  }
419  } else {
420  memcpy(sc->m_decodedAudioSamples.get(), frame->data[0], newsize);
421  }
422 
423  // We may not have read all of the data from this packet. If so, the user can call again.
424  // Whether or not they do depends on if m_pktRemainingSiz == 0 (they can check).
425  sc->m_pktDataPtr += nBytesDecoded;
426  sc->m_pktRemainingSiz -= nBytesDecoded;
427 
428  // At this point it's normally safe to assume that we've read some samples. However, the MPEG
429  // audio decoder is broken. If this is the case then we just return with m_frameValid == 0
430  // but m_pktRemainingSiz perhaps != 0, so the user can call again.
431  if (sc->m_decodedAudioSamplesValidSiz > 0)
432  {
433  sc->m_frameValid = 1;
434  }
435  return 0;
436 }

References streamContext::m_codecCtx, streamContext::m_decodedAudioSamples, streamContext::m_decodedAudioSamplesSiz, streamContext::m_decodedAudioSamplesValidSiz, streamContext::m_frameValid, streamContext::m_pkt, streamContext::m_pktDataPtr, streamContext::m_pktRemainingSiz, streamContext::m_samplefmt, and streamContext::m_samplesize.

Referenced by FFmpegImportFileHandle::DecodeFrame().

Here is the caller graph for this function:

◆ import_ffmpeg_read_next_frame()

streamContext* import_ffmpeg_read_next_frame ( AVFormatContext *  formatContext,
streamContext **  streams,
unsigned int  numStreams 
)

Definition at line 315 of file FFmpeg.cpp.

318 {
319  streamContext *sc = NULL;
320  AVPacketEx pkt;
321 
322  if (av_read_frame(formatContext, &pkt) < 0)
323  {
324  return NULL;
325  }
326 
327  // Find a stream to which this frame belongs
328  for (unsigned int i = 0; i < numStreams; i++)
329  {
330  if (streams[i]->m_stream->index == pkt.stream_index)
331  sc = streams[i];
332  }
333 
334  // Off-stream packet. Don't panic, just skip it.
335  // When not all streams are selected for import this will happen very often.
336  if (sc == NULL)
337  {
338  return (streamContext*)1;
339  }
340 
341  // Copy the frame to the stream context
342  sc->m_pkt.emplace(std::move(pkt));
343 
344  sc->m_pktDataPtr = sc->m_pkt->data;
345  sc->m_pktRemainingSiz = sc->m_pkt->size;
346 
347  return sc;
348 }

References Optional< X >::emplace(), streamContext::m_pkt, streamContext::m_pktDataPtr, and streamContext::m_pktRemainingSiz.

Referenced by FFmpegImportFileHandle::ReadNextFrame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadFFmpeg()

bool LoadFFmpeg ( bool  showerror)

Definition at line 71 of file FFmpeg.cpp.

72 {
74  if (FFmpegLibsInst()->ValidLibsLoaded())
75  {
77  return true;
78  }
79  if (!FFmpegLibsInst()->LoadLibs(NULL, showerror))
80  {
82  gPrefs->Write(wxT("/FFmpeg/Enabled"), false);
83  gPrefs->Flush();
84  return false;
85  }
86  else
87  {
88  gPrefs->Write(wxT("/FFmpeg/Enabled"), true);
89  gPrefs->Flush();
90  return true;
91  }
92 }

References DropFFmpegLibs(), FFmpegLibsInst(), FileConfig::Flush(), gPrefs, and PickFFmpegLibs().

Referenced by ExportFFmpeg::CheckFileName(), FFmpegStartup(), LibraryPrefs::OnFFmpegFindButton(), and ExportFFmpegCustomOptions::OnOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PickFFmpegLibs()

FFmpegLibs* PickFFmpegLibs ( )

! Helper function - creates FFmpegLibs object if it does not exists or just increments reference count if it does It is usually called by constructors or initializators

Definition at line 51 of file FFmpeg.cpp.

52 {
53  if (FFmpegLibsPtr)
54  FFmpegLibsPtr->refcount++;
55  else
56  FFmpegLibsPtr = std::make_unique<FFmpegLibs>();
57 
58  return FFmpegLibsPtr.get();
59 }

References FFmpegLibsPtr.

Referenced by CheckFFmpegPresence(), ExportFFmpeg::ExportFFmpeg(), ExportFFmpegOptions::ExportFFmpegOptions(), FFmpegImportFileHandle::FFmpegImportFileHandle(), GetFFmpegVersion(), LoadFFmpeg(), LibraryPrefs::OnFFmpegFindButton(), and ExportFFmpegCustomOptions::OnOpen().

Here is the caller graph for this function:

◆ ufile_close()

int ufile_close ( AVIOContext *  pb)

Definition at line 198 of file FFmpeg.cpp.

199 {
200  std::unique_ptr<wxFile> f{ (wxFile *)pb->opaque };
201 
202  bool success = true;
203  if (f) {
204  if (pb->write_flag) {
205  success = f->Flush();
206  }
207  if (success) {
208  success = f->Close();
209  }
210  pb->opaque = nullptr;
211  }
212 
213  // We're not certain that a close error is for want of space, but we'll
214  // guess that
215  return success ? 0 : -ENOSPC;
216 
217  // Implicitly destroy the wxFile object here
218 }

Referenced by FFmpegContext::~FFmpegContext().

Here is the caller graph for this function:

◆ ufile_fopen()

int ufile_fopen ( AVIOContext **  s,
const FilePath name,
int  flags 
)

Definition at line 221 of file FFmpeg.cpp.

222 {
223  wxFile::OpenMode mode;
224 
225  auto f = std::make_unique<wxFile>();
226  if (!f) {
227  return -ENOMEM;
228  }
229 
230  if (flags == (AVIO_FLAG_READ | AVIO_FLAG_WRITE)) {
231  return -EINVAL;
232  } else if (flags == AVIO_FLAG_WRITE) {
233  mode = wxFile::write;
234  } else {
235  mode = wxFile::read;
236  }
237 
238  if (!f->Open(name, mode)) {
239  return -ENOENT;
240  }
241 
242  *s = avio_alloc_context((unsigned char*)av_malloc(32768), 32768,
243  flags & AVIO_FLAG_WRITE,
244  /*opaque*/f.get(),
245  ufile_read,
246  ufile_write,
247  ufile_seek);
248  if (!*s) {
249  return -ENOMEM;
250  }
251 
252  f.release(); // s owns the file object now
253 
254  return 0;
255 }

References name, ufile_read(), ufile_seek(), and ufile_write().

Referenced by ExportFFmpeg::Init(), and ufile_fopen_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ufile_fopen_input()

int ufile_fopen_input ( std::unique_ptr< FFmpegContext > &  context_ptr,
FilePath name 
)

Definition at line 260 of file FFmpeg.cpp.

261 {
262  context_ptr.reset();
263  auto context = std::make_unique<FFmpegContext>();
264 
265  wxFileName ff{ name };
266  wxCharBuffer fname;
267  const char *filename;
268  int err;
269 
270  fname = ff.GetFullName().mb_str();
271  filename = (const char *) fname;
272 
273  // Open the file to prepare for probing
274  if ((err = ufile_fopen(&context->pb, name, AVIO_FLAG_READ)) < 0) {
275  goto fail;
276  }
277 
278  context->ic_ptr = avformat_alloc_context();
279  context->ic_ptr->pb = context->pb;
280 
281  // And finally, attempt to associate an input stream with the file
282  err = avformat_open_input(&context->ic_ptr, filename, NULL, NULL);
283  if (err) {
284  goto fail;
285  }
286 
287  // success
288  context_ptr = std::move(context);
289  return 0;
290 
291 fail:
292 
293  return err;
294 }

References name, and ufile_fopen().

Referenced by FFmpegImportFileHandle::Init().

Here is the call graph for this function:
Here is the caller graph for this function:
streamContext::m_frameValid
int m_frameValid
Definition: FFmpeg.h:1017
streamContext::m_pktRemainingSiz
int m_pktRemainingSiz
Definition: FFmpeg.h:1012
streamContext::m_pkt
Optional< AVPacketEx > m_pkt
Definition: FFmpeg.h:1010
Optional::emplace
X & emplace(Args &&... args)
Definition: MemoryX.h:192
streamContext
Definition: FFmpeg.h:1005
ufile_fopen
int ufile_fopen(AVIOContext **s, const FilePath &name, int flags)
Definition: FFmpeg.cpp:221
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:68
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: AudacityMessageBox.h:20
AVPacketEx
Definition: FFmpeg.h:884
streamContext::m_samplesize
size_t m_samplesize
Definition: FFmpeg.h:1023
ufile_write
static int ufile_write(void *opaque, uint8_t *buf, int size)
Definition: FFmpeg.cpp:164
XO
#define XO(s)
Definition: Internat.h:31
streamContext::m_pktDataPtr
uint8_t * m_pktDataPtr
Definition: FFmpeg.h:1011
streamContext::m_decodedAudioSamplesSiz
unsigned int m_decodedAudioSamplesSiz
Definition: FFmpeg.h:1019
PickFFmpegLibs
FFmpegLibs * PickFFmpegLibs()
Definition: FFmpeg.cpp:51
ufile_read
static int ufile_read(void *opaque, uint8_t *buf, int size)
Definition: FFmpeg.cpp:158
streamContext::m_samplefmt
AVSampleFormat m_samplefmt
Definition: FFmpeg.h:1024
LoadFFmpeg
bool LoadFFmpeg(bool showerror)
Definition: FFmpeg.cpp:71
ufile_seek
static int64_t ufile_seek(void *opaque, int64_t pos, int whence)
Definition: FFmpeg.cpp:172
streamContext::m_decodedAudioSamplesValidSiz
size_t m_decodedAudioSamplesValidSiz
Definition: FFmpeg.h:1020
name
const TranslatableString name
Definition: Distortion.cpp:98
streamContext::m_decodedAudioSamples
AVMallocHolder< uint8_t > m_decodedAudioSamples
Definition: FFmpeg.h:1018
streamContext::m_codecCtx
AVCodecContext * m_codecCtx
Definition: FFmpeg.h:1008
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:153
FFmpegLibsInst
FFmpegLibs * FFmpegLibsInst()
Definition: FFmpeg.cpp:46
Verbatim
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
Definition: TranslatableString.h:321
DropFFmpegLibs
void DropFFmpegLibs()
Definition: FFmpeg.cpp:61
AVFrameHolder
std::unique_ptr< AVFrame, AV_Deleterp< AVFrame, void, av_frame_free > > AVFrameHolder
Definition: FFmpeg.h:964
FFmpegLibsPtr
std::unique_ptr< FFmpegLibs > FFmpegLibsPtr
Definition: FFmpeg.cpp:45