diff options
author | Christian Gmeiner <christian.gmeiner@gmail.com> | 2010-06-30 14:19:48 +0200 |
---|---|---|
committer | Christian Gmeiner <christian.gmeiner@gmail.com> | 2010-06-30 14:19:48 +0200 |
commit | 8a470b5328b2e9e4bbf33d4027bae4bfc5e85c90 (patch) | |
tree | 621781d8fccdd4d90793e5fcd72cc718d5c80580 | |
parent | 3ae36c76928283a0ae21d8a78ab556a4d2daaf36 (diff) | |
download | vdr-plugin-dxr3-8a470b5328b2e9e4bbf33d4027bae4bfc5e85c90.tar.gz vdr-plugin-dxr3-8a470b5328b2e9e4bbf33d4027bae4bfc5e85c90.tar.bz2 |
extend decoder to decode mpeg2 frames
Warning: Only compile tested
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | decoder.c | 46 | ||||
-rw-r--r-- | decoder.h | 3 |
3 files changed, 50 insertions, 0 deletions
@@ -34,6 +34,7 @@ FFMPEG_INC = $(shell pkg-config --cflags-only-I libavcodec) # Usually something like -L/path/to/ffmpeg/libavcodec -lavcodec, should work # as is if FFmpeg was installed properly and pkg-config is available. FFMPEG_LIBS = $(shell pkg-config --libs libavcodec) +FFMPEG_LIBS += $(shell pkg-config --libs libswscale) ALSA_INC = $(shell pkg-config --cflags-only-I alsa) ALSA_LIBS = $(shell pkg-config --libs alsa) @@ -74,6 +74,26 @@ cDecoder::cDecoder() : rbuf(50000), ac3dtsDecoder(&rbuf) exit(-1); } + rgbFrame = avcodec_alloc_frame(); + if (!rgbFrame) { + esyslog("[dxr3-decoder] failed to alloc rgbFrame"); + exit(-1); + } + + // reserve place for raw data for our rgbFrame + uint8_t *buffer; + int numBytes; + // determine required buffer size and allocate buffer + numBytes = avpicture_get_size(PIX_FMT_RGB24, contextVideo->width, contextVideo->height); + buffer = (uint8_t *)av_malloc(numBytes * sizeof(uint8_t)); + if (!buffer) { + esyslog("[dxr3-decoder] failed to alloc rgbFrame data"); + exit(-1); + } + + // ssociate the frame with our newly allocated buffer + avpicture_fill((AVPicture *)rgbFrame, buffer, PIX_FMT_RGB24, contextVideo->width, contextVideo->height); + lastBitrate = 0xff; // init with an invalid value - see checkMpegAudioHdr; } @@ -84,6 +104,11 @@ cDecoder::~cDecoder() // close codec, if it is open avcodec_close(contextAudio); avcodec_close(contextVideo); + + if (rgbFrame) { + av_free(rgbFrame->data); + av_free(rgbFrame); + } } // ================================== @@ -102,6 +127,27 @@ void cDecoder::Init() } } +AVFrame *cDecoder::decode(AVPacket *source, uint32_t width, uint32_t height) +{ + AVFrame frame; + int gotPicture; + + avcodec_decode_video2(contextVideo, &frame, &gotPicture, source); + + if (gotPicture) { + + SwsContext *swsContext = sws_getContext(contextVideo->width, contextVideo->height, + contextVideo->pix_fmt, width, height, PIX_FMT_RGB24, SWS_BILINEAR, 0, 0, 0); + + if (swsContext) { + sws_scale(swsContext, frame.data, frame.linesize, 0, contextVideo->height, rgbFrame->data, rgbFrame->linesize); + return rgbFrame; + } + } + + return NULL; +} + void cDecoder::decode(cDxr3PesFrame *frame, iAudio *audio) { int len, out_size; @@ -31,6 +31,7 @@ extern "C" { # include <libavcodec/avcodec.h> # include <libavformat/avformat.h> +# include <libswscale/swscale.h> } #include <vdr/ringbuffer.h> @@ -47,6 +48,7 @@ public: cDecoder(); ~cDecoder(); + AVFrame *decode(AVPacket *source, uint32_t width, uint32_t height); void decode(cDxr3PesFrame *frame, iAudio *audio); void ac3dts(cDxr3PesFrame *frame, iAudio *audio); /* @@ -68,6 +70,7 @@ private: AVCodecContext *contextVideo; AVPacket avpkt; + AVFrame *rgbFrame; cRingBufferFrame rbuf; cMultichannelAudio ac3dtsDecoder; |