OpenMW
apps/openmw/mwsound/ffmpeg_decoder.hpp
Go to the documentation of this file.
00001 #ifndef GAME_SOUND_FFMPEG_DECODER_H
00002 #define GAME_SOUND_FFMPEG_DECODER_H
00003 
00004 // FIXME: This can't be right? The headers refuse to build without UINT64_C,
00005 // which only gets defined in stdint.h in either C99 mode or with this macro
00006 // defined...
00007 #define __STDC_CONSTANT_MACROS
00008 #include <stdint.h>
00009 extern "C"
00010 {
00011 #include <libavcodec/avcodec.h>
00012 #include <libavformat/avformat.h>
00013 
00014 // From libavutil version 52.2.0 and onward the declaration of
00015 // AV_CH_LAYOUT_* is removed from libavcodec/avcodec.h and moved to
00016 // libavutil/channel_layout.h
00017 #if AV_VERSION_INT(52, 2, 0) <= AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
00018     LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO)
00019     #include <libavutil/channel_layout.h>
00020 #endif
00021 }
00022 
00023 #include <string>
00024 
00025 #include "sound_decoder.hpp"
00026 
00027 
00028 namespace MWSound
00029 {
00030     class FFmpeg_Decoder : public Sound_Decoder
00031     {
00032         AVFormatContext *mFormatCtx;
00033         AVStream **mStream;
00034 
00035         AVPacket mPacket;
00036         AVFrame *mFrame;
00037 
00038         int mFrameSize;
00039         int mFramePos;
00040 
00041         double mNextPts;
00042 
00043         bool getNextPacket();
00044 
00045         Ogre::DataStreamPtr mDataStream;
00046         static int readPacket(void *user_data, uint8_t *buf, int buf_size);
00047         static int writePacket(void *user_data, uint8_t *buf, int buf_size);
00048         static int64_t seek(void *user_data, int64_t offset, int whence);
00049 
00050         bool getAVAudioData();
00051         size_t readAVAudioData(void *data, size_t length);
00052 
00053         virtual void open(const std::string &fname);
00054         virtual void close();
00055 
00056         virtual std::string getName();
00057         virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type);
00058 
00059         virtual size_t read(char *buffer, size_t bytes);
00060         virtual void readAll(std::vector<char> &output);
00061         virtual void rewind();
00062         virtual size_t getSampleOffset();
00063 
00064         FFmpeg_Decoder& operator=(const FFmpeg_Decoder &rhs);
00065         FFmpeg_Decoder(const FFmpeg_Decoder &rhs);
00066 
00067         FFmpeg_Decoder();
00068     public:
00069         virtual ~FFmpeg_Decoder();
00070 
00071         friend class SoundManager;
00072     };
00073 #ifndef DEFAULT_DECODER
00074 #define DEFAULT_DECODER (::MWSound::FFmpeg_Decoder)
00075 #endif
00076 }
00077 
00078 #endif