Skip to content

Commit

Permalink
Hooked up VDPAU->OpenGL->OpenCL, new VideoDecoder structure
Browse files Browse the repository at this point in the history
Requires libglew1.6

As it is not possible to bind an OpenGL texture to both VDPAU and OpenCL
simultaneously, bit-blit from VDPAU->OpenGL textures to OpenGL->OpenCL textures
  • Loading branch information
Beirdo committed Dec 24, 2011
1 parent 47c8a4e commit 21b2b1a
Show file tree
Hide file tree
Showing 26 changed files with 1,850 additions and 30 deletions.
5 changes: 3 additions & 2 deletions mythtv/libs/libmythtv/mythcodecid.h
Expand Up @@ -6,6 +6,7 @@ extern "C"
{
#include "libavcodec/avcodec.h"
}
#include "mythtvexp.h"

typedef enum
{
Expand Down Expand Up @@ -84,15 +85,15 @@ typedef enum
QString get_encoding_type(MythCodecID codecid);
QString get_decoder_name(MythCodecID codec_id);
QString toString(MythCodecID codecid);
int myth2av_codecid(MythCodecID codec_id, bool &vdpau);
int MTV_PUBLIC myth2av_codecid(MythCodecID codec_id, bool &vdpau);
inline int myth2av_codecid(MythCodecID codec_id)
{
bool vdpau;
return myth2av_codecid(codec_id, vdpau);
}

// AV codec id convenience functions
int mpeg_version(int codec_id);
int MTV_PUBLIC mpeg_version(int codec_id);
#define CODEC_IS_H264(id) (mpeg_version(id) == 5)
#define CODEC_IS_MPEG(id) (mpeg_version(id) && mpeg_version(id) <= 2)
#define CODEC_IS_FFMPEG_MPEG(id) (CODEC_IS_MPEG(id))
Expand Down
4 changes: 2 additions & 2 deletions mythtv/programs/mythgpucommflag/audioconsumer.cpp
Expand Up @@ -24,7 +24,6 @@ AudioConsumer::AudioConsumer(PacketQueue *inQ, ResultsList *outL,
m_proclist = softwareAudioProcessorList;

m_context = avcodec_alloc_context();
m_opened = false;
}

void AudioConsumer::ProcessPacket(Packet *packet)
Expand All @@ -44,6 +43,7 @@ void AudioConsumer::ProcessPacket(Packet *packet)
return;
m_opened = true;
}

int ret = 0;
int dataSize = 0;
int frames = -1;
Expand Down Expand Up @@ -132,7 +132,7 @@ void AudioConsumer::ProcessFrame(int16_t *samples, int size, int frames,
// Toss the results onto the results list
if (result)
{
LOG(VB_GENERAL, LOG_INFO, "Finding found");
LOG(VB_GENERAL, LOG_INFO, "Audio Finding found");
result->m_pts = pts;
result->m_duration = duration;
m_outL->append(result);
Expand Down
4 changes: 1 addition & 3 deletions mythtv/programs/mythgpucommflag/audioconsumer.h
Expand Up @@ -13,15 +13,13 @@ class AudioConsumer : public QueueConsumer
public:
AudioConsumer(PacketQueue *inQ, ResultsList *outL, OpenCLDevice *dev);
~AudioConsumer() { av_free(m_audioSamples); };
bool Initialize(void) { return true; };
void ProcessPacket(Packet *packet);
void ProcessFrame(int16_t *samples, int size, int frames, int64_t pts,
int rate, uint64_t pos);

int16_t *m_audioSamples;
AudioProcessorList *m_proclist;
AVCodecContext *m_context;
AVCodec *m_codec;
bool m_opened;
};

#endif
Expand Down
4 changes: 4 additions & 0 deletions mythtv/programs/mythgpucommflag/commandlineparser.cpp
Expand Up @@ -18,6 +18,7 @@ void MythGPUCommFlagCommandLineParser::LoadArguments(void)
addJob();
addRecording();
addLogging();
addDisplay();

CommandLineArg::AllowOneOf( QList<CommandLineArg*>()
<< new CommandLineArg("chanid")
Expand Down Expand Up @@ -92,6 +93,9 @@ void MythGPUCommFlagCommandLineParser::LoadArguments(void)
add("--force-sw-video", "swvideo", false,
"Force video processing to be done in software.", "")
->SetGroup("Advanced");
add("--force-disable-x", "noX", false,
"Force disabling X Windows use. Forces software video decoding.", "")
->SetGroup("Advanced");
}


Expand Down
98 changes: 98 additions & 0 deletions mythtv/programs/mythgpucommflag/ffmpegvideodecoder.cpp
@@ -0,0 +1,98 @@
#include "ffmpegvideodecoder.h"
#include "videoconsumer.h"
#include "frame.h"
#include "videosurface.h"

extern "C" {
#include "libavcodec/avcodec.h"
}


bool FFMpegVideoDecoder::Initialize(void)
{
return true;
}

VideoSurface *FFMpegVideoDecoder::DecodeFrame(AVFrame *frame)
{
return NULL;
}

void FFMpegVideoDecoder::DiscardFrame(VideoSurface *frame)
{
}

void FFMpegVideoDecoder::Shutdown(void)
{
}

static bool IS_DR1_PIX_FMT(const enum PixelFormat fmt)
{
switch (fmt)
{
case PIX_FMT_YUV420P:
case PIX_FMT_YUVJ420P:
return true;
default:
return false;
}
}


int get_avf_buffer(struct AVCodecContext *c, AVFrame *pic)
{
VideoConsumer *nd = (VideoConsumer *)(c->opaque);
(void)nd;

if (!IS_DR1_PIX_FMT(c->pix_fmt))
{
return avcodec_default_get_buffer(c, pic);
}

VideoFrame *frame = NULL; //= nd->GetNextVideoFrame();

if (!frame)
return -1;

for (int i = 0; i < 3; i++)
{
pic->data[i] = frame->buf + frame->offsets[i];
pic->linesize[i] = frame->pitches[i];
}

pic->opaque = frame;
pic->type = FF_BUFFER_TYPE_USER;

pic->age = 256 * 256 * 256 * 64;

pic->reordered_opaque = c->reordered_opaque;

return 0;
}

void release_avf_buffer(struct AVCodecContext *c, AVFrame *pic)
{
(void)c;

if (pic->type == FF_BUFFER_TYPE_INTERNAL)
{
avcodec_default_release_buffer(c, pic);
return;
}

VideoConsumer *nd = (VideoConsumer *)(c->opaque);
(void)nd;
// if (nd)
// nd->DeLimboFrame((VideoFrame*)pic->opaque);

assert(pic->type == FF_BUFFER_TYPE_USER);

for (uint i = 0; i < 4; i++)
pic->data[i] = NULL;
}



/*
* vim:ts=4:sw=4:ai:et:si:sts=4
*/
32 changes: 32 additions & 0 deletions mythtv/programs/mythgpucommflag/ffmpegvideodecoder.h
@@ -0,0 +1,32 @@
#ifndef _FFMPEGVIDEODECODER_H
#define _FFMPEGVIDEODECODER_H

#include "videodecoder.h"
#include "openclinterface.h"
#include "videosurface.h"

extern "C" {
#include "libavcodec/avcodec.h"
}

class FFMpegVideoDecoder : public VideoDecoder
{
public:
FFMpegVideoDecoder(OpenCLDevice *dev) : VideoDecoder(dev, true) {};
~FFMpegVideoDecoder() { Shutdown(); };
const char *Name(void) { return "FFMpeg"; };
bool Initialize(void);
VideoSurface *DecodeFrame(AVFrame *frame);
void DiscardFrame(VideoSurface *frame);
void Shutdown(void);
void SetCodec(AVCodec *codec) { m_codecId = codec->id; };
};

int get_avf_buffer(struct AVCodecContext *c, AVFrame *pic);
void release_avf_buffer(struct AVCodecContext *c, AVFrame *pic);

#endif

/*
* vim:ts=4:sw=4:ai:et:si:sts=4
*/
36 changes: 32 additions & 4 deletions mythtv/programs/mythgpucommflag/main.cpp
Expand Up @@ -13,6 +13,7 @@ using namespace std;
#include "playercontext.h"
#include "remotefile.h"
#include "jobqueue.h"
#include "mythuihelper.h"

#include "openclinterface.h"
#include "packetqueue.h"
Expand Down Expand Up @@ -50,6 +51,7 @@ namespace
}

MythGPUCommFlagCommandLineParser cmdline;
OpenCLDeviceMap *devMap = NULL;

static QString get_filename(ProgramInfo *program_info)
{
Expand Down Expand Up @@ -124,27 +126,50 @@ int main(int argc, char **argv)
return GENERIC_EXIT_OK;
}

QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName("mythgpucommflag");
#ifdef Q_WS_X11
bool useX = (getenv("DISPLAY") != 0) ||
!cmdline.toString("display").isEmpty();

if (cmdline.toBool("noX"))
useX = false;
#else
bool useX = true;
#endif

QApplication app(argc, argv, useX);
QApplication::setApplicationName("mythgpucommflag");
int retval = cmdline.ConfigureLogging("general", false);
// !cmdline.toBool("noprogress"));
if (retval != GENERIC_EXIT_OK)
return retval;

if (useX && !cmdline.toString("display").isEmpty())
{
MythUIHelper::SetX11Display(cmdline.toString("display"));
}

if (!useX)
{
LOG(VB_GENERAL, LOG_NOTICE,
"Use of X disabled, reverting to software video decoding");
}

CleanupGuard callCleanup(cleanup);
gContext = new MythContext(MYTH_BINARY_VERSION);

if (!gContext->Init( false, /* use gui */
false, /* prompt for backend */
false, /* bypass auto discovery */
false)) /* ignoreDB */
false) ) /* ignoreDB */
{
LOG(VB_GENERAL, LOG_EMERG, "Failed to init MythContext, exiting.");
return GENERIC_EXIT_NO_MYTHCONTEXT;
}

cmdline.ApplySettingsOverride();

// Determine capabilities
OpenCLDeviceMap *devMap = new OpenCLDeviceMap();
devMap = new OpenCLDeviceMap();

OpenCLDevice *devices[2]; // 0 = video, 1 = audio;
bool found;
Expand Down Expand Up @@ -272,6 +297,9 @@ int main(int argc, char **argv)
VideoConsumer *videoThread = new VideoConsumer(&videoQ, &videoMarks,
devices[0]);

if (useX)
videoThread->EnableX();

audioThread->start();
videoThread->start();

Expand Down
24 changes: 18 additions & 6 deletions mythtv/programs/mythgpucommflag/mythgpucommflag.pro
Expand Up @@ -11,30 +11,42 @@ QMAKE_CLEAN += $(TARGET)

SDK = /opt/NVIDIA_GPU_Computing_SDK
INCLUDEPATH += $$SDK/shared/inc $$SDK/OpenCL/common/inc
#INCLUDEPATH += $$SDK/OpenCL/common/inc
LIBPATH += $$SDK/shared/lib $$SDK/shared/lib/linux
LIBPATH += $$SDK/OpenCL/common/lib

LIBS += -lOpenCL -loclUtil_x86_64 -lshrutil_x86_64
LIBS += -lOpenCL -loclUtil_x86_64 -lshrutil_x86_64 -lglut -lGLEW

# Input
HEADERS += commandlineparser.h
HEADERS += openclinterface.h
HEADERS += openclinterface.h openglsupport.h
HEADERS += packetqueue.h
HEADERS += resultslist.h
HEADERS += gpuplayer.h
HEADERS += queueconsumer.h audioconsumer.h videoconsumer.h
HEADERS += audioprocessor.h
HEADERS += audiopacket.h
HEADERS += audioprocessor.h videoprocessor.h
HEADERS += audiopacket.h videopacket.h videosurface.h
HEADERS += videodecoder.h vdpauvideodecoder.h ffmpegvideodecoder.h

SOURCES += main.cpp commandlineparser.cpp
SOURCES += openclinterface.cpp
SOURCES += packetqueue.cpp
SOURCES += gpuplayer.cpp
SOURCES += queueconsumer.cpp audioconsumer.cpp videoconsumer.cpp
SOURCES += audioprocessor.cpp
SOURCES += audioprocessor.cpp videoprocessor.cpp
SOURCES += openclaudioprocessor.cpp softwareaudioprocessor.cpp
SOURCES += audiopacket.cpp
SOURCES += openclvideoprocessor.cpp softwarevideoprocessor.cpp
SOURCES += audiopacket.cpp videopacket.cpp videosurface.cpp
SOURCES += vdpauvideodecoder.cpp ffmpegvideodecoder.cpp

#The following line was inserted by qt3to4
QT += xml sql network

using_x11:DEFINES += USING_X11
using_xv:DEFINES += USING_XV
using_xrandr:DEFINES += USING_XRANDR
using_opengl:QT += opengl
using_opengl:DEFINES += USING_OPENGL
using_opengl_video:DEFINES += USING_OPENGL_VIDEO
using_vdpau:DEFINES += USING_VDPAU

0 comments on commit 21b2b1a

Please sign in to comment.