diff options
author | methodus <methodus@web.de> | 2012-10-13 22:58:00 +0200 |
---|---|---|
committer | methodus <methodus@web.de> | 2012-10-13 22:58:00 +0200 |
commit | 5ddef2b47d987323419a5411169dbb8a855f2e70 (patch) | |
tree | 6f07f31f337d6ab9693176c036c8898ef8ebc210 /common | |
parent | b450015b9a6c0d35c264e93fbc9bcdf92538f47a (diff) | |
download | vdr-plugin-upnp-5ddef2b47d987323419a5411169dbb8a855f2e70.tar.gz vdr-plugin-upnp-5ddef2b47d987323419a5411169dbb8a855f2e70.tar.bz2 |
Added codec toolkit for getting detailed media information
Diffstat (limited to 'common')
-rw-r--r-- | common/codec.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/common/codec.cpp b/common/codec.cpp new file mode 100644 index 0000000..d38a8e5 --- /dev/null +++ b/common/codec.cpp @@ -0,0 +1,65 @@ +/* + * codec.cpp + * + * Created on: 13.10.2012 + * Author: savop + */ + +#include "../include/tools/codec.h" + +namespace upnp { + +namespace codec { + +cFormatContext::cFormatContext() +: formatCtx(NULL) +{ + av_register_all(); +} + +cFormatContext::~cFormatContext(){ + av_free(formatCtx); +} + +bool cFormatContext::Open(const string& file){ + if(avformat_open_input(&formatCtx, file.c_str(), NULL, NULL) == 0){ + if(avformat_find_stream_info(formatCtx, NULL) == 0){ + return true; + } + } + + return false; +} + +const AVCodec* cFormatContext::GetCodec(AVMediaType Type) const { + return avcodec_find_decoder(GetCodecContext(Type)->codec_id); +} + +const AVCodecContext* cFormatContext::GetCodecContext(AVMediaType Type) const { + const AVStream* strm = GetStream(Type); + return strm?strm->codec:NULL; +} + +const AVStream* cFormatContext::GetStream(AVMediaType Type) const { + if(!formatCtx) return NULL; + int Stream = -1; unsigned int i; + for(i = 0; i < formatCtx->nb_streams; i++){ + if(formatCtx->streams[i]->codec->codec_type == Type){ + Stream = i; + break; + } + } + if(Stream == -1){ + return NULL; + } + + return formatCtx->streams[Stream]; +} + +AVFormatContext* cFormatContext::operator*() const { + return formatCtx; +} + +} // namespace codec + +} // namespace upnp |