summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2011-01-06 06:13:12 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2011-01-06 06:13:12 +0100
commit822ae13835c2f6443d5b4fface6f3f547bcfcb11 (patch)
tree2a9c2ec01f90b8dcb26b2d873fd23443ed8d4a14 /decoders
parent6f2fefdd9ff5f8561b3538efb5eb0765a9b4a141 (diff)
Implemented rudimentary ffmpeg-based decoder.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/ffmpeg_decoder.cpp36
-rw-r--r--decoders/ffmpeg_decoder.h24
2 files changed, 60 insertions, 0 deletions
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 <iostream>
+
+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 <libavformat/avformat.h>
+ #include <libavcodec/avcodec.h>
+}
+
+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