OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ffmpeg_decoder.hpp
Go to the documentation of this file.
1 #ifndef GAME_SOUND_FFMPEG_DECODER_H
2 #define GAME_SOUND_FFMPEG_DECODER_H
3 
4 #include <stdint.h>
5 extern "C"
6 {
7 #include <libavcodec/avcodec.h>
8 #include <libavformat/avformat.h>
9 
10 // From libavutil version 52.2.0 and onward the declaration of
11 // AV_CH_LAYOUT_* is removed from libavcodec/avcodec.h and moved to
12 // libavutil/channel_layout.h
13 #if AV_VERSION_INT(52, 2, 0) <= AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
14  LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO)
15  #include <libavutil/channel_layout.h>
16 #endif
17 
18 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
19 #define av_frame_alloc avcodec_alloc_frame
20 #endif
21 
22 // From version 54.56 binkaudio encoding format changed from S16 to FLTP. See:
23 // https://gitorious.org/ffmpeg/ffmpeg/commit/7bfd1766d1c18f07b0a2dd042418a874d49ea60d
24 // http://ffmpeg.zeranoe.com/forum/viewtopic.php?f=15&t=872
25 #include <libswresample/swresample.h>
26 }
27 
29 
30 #include <string>
31 #include <istream>
32 
33 #include "sound_decoder.hpp"
34 
35 
36 namespace MWSound
37 {
39  {
40  AVFormatContext *mFormatCtx;
41  AVStream **mStream;
42 
43  AVPacket mPacket;
44  AVFrame *mFrame;
45 
47  int mFramePos;
48 
49  double mNextPts;
50 
51  SwrContext *mSwr;
52  enum AVSampleFormat mOutputSampleFormat;
54  uint8_t *mDataBuf;
55  uint8_t **mFrameData;
57 
58  bool getNextPacket();
59 
61 
62  static int readPacket(void *user_data, uint8_t *buf, int buf_size);
63  static int writePacket(void *user_data, uint8_t *buf, int buf_size);
64  static int64_t seek(void *user_data, int64_t offset, int whence);
65 
66  bool getAVAudioData();
67  size_t readAVAudioData(void *data, size_t length);
68 
69  virtual void open(const std::string &fname);
70  virtual void close();
71 
72  virtual std::string getName();
73  virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type);
74 
75  virtual size_t read(char *buffer, size_t bytes);
76  virtual void readAll(std::vector<char> &output);
77  virtual size_t getSampleOffset();
78 
79  void fail(const std::string &msg);
80 
82  FFmpeg_Decoder(const FFmpeg_Decoder &rhs);
83 
84  FFmpeg_Decoder(const VFS::Manager* vfs);
85  public:
86  virtual ~FFmpeg_Decoder();
87 
88  friend class SoundManager;
89  };
90 #ifndef DEFAULT_DECODER
91 #define DEFAULT_DECODER (::MWSound::FFmpeg_Decoder)
92 #endif
93 }
94 
95 #endif
virtual void readAll(std::vector< char > &output)
Definition: ffmpeg_decoder.cpp:378
int mFrameSize
Definition: ffmpeg_decoder.hpp:46
Files::IStreamPtr mDataStream
Definition: ffmpeg_decoder.hpp:60
bool getAVAudioData()
Definition: ffmpeg_decoder.cpp:95
SampleType
Definition: sound_decoder.hpp:14
void fail(const std::string &msg)
Definition: ffmpeg_decoder.cpp:14
virtual void open(const std::string &fname)
Definition: ffmpeg_decoder.cpp:183
SwrContext * mSwr
Definition: ffmpeg_decoder.hpp:51
virtual size_t getSampleOffset()
Definition: ffmpeg_decoder.cpp:392
uint8_t * mDataBuf
Definition: ffmpeg_decoder.hpp:54
int64_t mOutputChannelLayout
Definition: ffmpeg_decoder.hpp:53
FFmpeg_Decoder & operator=(const FFmpeg_Decoder &rhs)
FFmpeg_Decoder(const FFmpeg_Decoder &rhs)
Definition: ffmpeg_decoder.hpp:38
virtual std::string getName()
Definition: ffmpeg_decoder.cpp:292
int mFramePos
Definition: ffmpeg_decoder.hpp:47
double mNextPts
Definition: ffmpeg_decoder.hpp:49
AVPacket mPacket
Definition: ffmpeg_decoder.hpp:43
uint8_t ** mFrameData
Definition: ffmpeg_decoder.hpp:55
virtual ~FFmpeg_Decoder()
Definition: ffmpeg_decoder.cpp:427
AVFrame * mFrame
Definition: ffmpeg_decoder.hpp:44
AVFormatContext * mFormatCtx
Definition: ffmpeg_decoder.hpp:40
boost::shared_ptr< std::istream > IStreamPtr
Definition: constrainedfilestream.hpp:20
static int64_t seek(void *user_data, int64_t offset, int whence)
Definition: ffmpeg_decoder.cpp:39
virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type)
Definition: ffmpeg_decoder.cpp:297
static int writePacket(void *user_data, uint8_t *buf, int buf_size)
Definition: ffmpeg_decoder.cpp:34
AVStream ** mStream
Definition: ffmpeg_decoder.hpp:41
static int readPacket(void *user_data, uint8_t *buf, int buf_size)
Definition: ffmpeg_decoder.cpp:19
virtual void close()
Definition: ffmpeg_decoder.cpp:258
virtual size_t read(char *buffer, size_t bytes)
Definition: ffmpeg_decoder.cpp:371
bool getNextPacket()
Definition: ffmpeg_decoder.cpp:72
char buf[1024]
Definition: crashcatcher.cpp:54
Definition: soundmanagerimp.hpp:45
int mDataBufLen
Definition: ffmpeg_decoder.hpp:56
enum AVSampleFormat mOutputSampleFormat
Definition: ffmpeg_decoder.hpp:52
The main class responsible for loading files from a virtual file system.
Definition: manager.hpp:20
Definition: sound_decoder.hpp:33
ChannelConfig
Definition: sound_decoder.hpp:21
size_t readAVAudioData(void *data, size_t length)
Definition: ffmpeg_decoder.cpp:152