From 822ae13835c2f6443d5b4fface6f3f547bcfcb11 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Thu, 6 Jan 2011 06:13:12 +0100 Subject: Implemented rudimentary ffmpeg-based decoder. --- decoders/ffmpeg_decoder.cpp | 36 ++++++++++++++++++++++++++++++++++++ decoders/ffmpeg_decoder.h | 24 ++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 decoders/ffmpeg_decoder.cpp create mode 100644 decoders/ffmpeg_decoder.h (limited to 'decoders') diff --git a/decoders/ffmpeg_decoder.cpp b/decoders/ffmpeg_decoder.cpp new file mode 100644 index 0000000..d66c72b --- /dev/null +++ b/decoders/ffmpeg_decoder.cpp @@ -0,0 +1,36 @@ +#include "ffmpeg_decoder.h" + +#include + +DecoderFFmpeg::DecoderFFmpeg(const std::string& filename) { + av_register_all(); + + std::cerr << "Opening file: " << av_open_input_file(&lavf_ctx, filename.c_str(), 0, 0, 0) << std::endl; + + av_find_stream_info(lavf_ctx); + + dump_format(lavf_ctx, 0, filename.c_str(), 0); + + lavc_ctx = lavf_ctx->streams[0]->codec; + codec = avcodec_find_decoder(lavc_ctx->codec_id); + + std::cerr << "Opening decoder: " << avcodec_open(lavc_ctx, codec) << std::endl; +} + +DecoderFFmpeg::~DecoderFFmpeg() { + +} + +std::size_t DecoderFFmpeg::read(char* buf, std::size_t buf_size) { + AVPacket packet; + + av_read_packet(lavf_ctx, &packet); + + int len = avcodec_decode_audio3(lavc_ctx, (int16_t*)buf, (int*)&buf_size, &packet); + + std::cerr << "Decoded " << len << " bytes of data to " << buf_size << " bytes of raw data." << std::endl; + + av_free_packet(&packet); + + return buf_size; +} diff --git a/decoders/ffmpeg_decoder.h b/decoders/ffmpeg_decoder.h new file mode 100644 index 0000000..a77e303 --- /dev/null +++ b/decoders/ffmpeg_decoder.h @@ -0,0 +1,24 @@ +#ifndef FFMPEG_DECODER_H +#define FFMPEG_DECODER_H + +#include "decoder.h" + +extern "C" { + #include + #include +} + +class DecoderFFmpeg : public Decoder { + private: + AVFormatContext* lavf_ctx; + AVCodecContext* lavc_ctx; + AVCodec* codec; + + public: + DecoderFFmpeg(const std::string& filename); + ~DecoderFFmpeg(); + + virtual std::size_t read(char* buf, std::size_t buf_size); +}; + +#endif -- cgit v1.2.3