From 89961817f408e921de2c1be6197e2b1ee0f5df98 Mon Sep 17 00:00:00 2001 From: Comment Date: Wed, 29 Jan 2014 23:58:55 +0000 Subject: NT audio framework --- NT/src/libavwrapper.h | 239 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 NT/src/libavwrapper.h (limited to 'NT/src/libavwrapper.h') diff --git a/NT/src/libavwrapper.h b/NT/src/libavwrapper.h new file mode 100644 index 0000000..162a77e --- /dev/null +++ b/NT/src/libavwrapper.h @@ -0,0 +1,239 @@ +#ifndef libavwrapper_H +#define libavwrapper_H + +#ifndef UINT64_C +#define UINT64_C(c) (c ## ULL) +#endif + +#include "Poco/Mutex.h" +#include "Poco/ScopedLock.h" +#include "Poco/StringTokenizer.h" +#include "Poco/File.h" + +extern Poco::Mutex mutex; //application wide mutex + +extern "C" { +#include +#include +#include +#include +#include +} + +#include +#include +#include +#include +#include +#include + +#include + + +namespace libav { + // Some libavcodec calls are not reentrant + void maybeInitFFMpegLib(); + + class video_decoder + { + public: + video_decoder(){ + maybeInitFFMpegLib(); + pixfmts[0] = FFMS_GetPixFmt("rgb24"); + pixfmts[1] = -1; + h=0; + w=0; + source=NULL; + loaded=false; + err.Buffer = errmsg; + err.BufferSize = sizeof(errmsg); + err.ErrorType = FFMS_ERROR_SUCCESS; + err.SubType = FFMS_ERROR_SUCCESS; + } + ~video_decoder(){ + cleanup(); + } + void cleanup(); + bool open(const std::string& filename); + double get_framerate(){ + if (loaded) return (((double)props->FPSNumerator)/((double)props->FPSDenominator)); + else return -1.0; + } + int get_number_frames(){ + if (loaded) return props->NumFrames; + else return -1; + } + int get_number_channels(){ + return 3; //this is what we convert to + } + int get_width(){ + return w; + } + int get_height(){ + return h; + } + bool fetch_frame(int width,int height,int wanted){ + if (FFMS_SetOutputFormatV2(source, pixfmts, width, height, FFMS_RESIZER_BICUBIC, &err)) { + std::cerr<<"ffmpegsource: "<NumFrames, &err); + if (frame == NULL) { + std::cerr<<"ffmpegsource: "<SampleFormat; + else return 0; + } + int get_sample_rate(){ + if (props) return props->SampleRate; + else return 0; + } + int get_bit_depth(){ + if (props) return props->BitsPerSample; + else return 0; + } + int get_number_channels(){ + if (props) return props->Channels; + else return 0; + } + int get_number_samples(){ + if (props) return props->NumSamples; + else return 0; + } + int64_t get_channel_layout(){ + if (props) return props->ChannelLayout; + else return 0; + } + double get_duration(){ + if (props) return ((double)props->NumSamples)/props->SampleRate; + else return 0; + } + bool get_samples(void *buf,int64_t start, int64_t count){ + if (source) { + if (FFMS_GetAudio(source, buf, start, count, &err)) { + std::cerr<<"ffmpegsource: "<