Skip to content

Commit

Permalink
MythPlayer: Consolidate AvSpecialDecode into PlayerFlags.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Kendall committed Dec 7, 2011
1 parent 4c1b97a commit c66767d
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 105 deletions.
47 changes: 22 additions & 25 deletions mythtv/libs/libmythtv/avformatdecoder.cpp
Expand Up @@ -258,10 +258,7 @@ void AvFormatDecoder::GetDecoders(render_opts &opts)

AvFormatDecoder::AvFormatDecoder(MythPlayer *parent,
const ProgramInfo &pginfo,
bool use_null_videoout,
bool allow_private_decode,
bool no_hardware_decode,
AVSpecialDecode special_decoding)
PlayerFlags flags)
: DecoderBase(parent, pginfo),
private_dec(NULL),
is_db_ignored(gCoreContext->IsDatabaseIgnored()),
Expand All @@ -286,11 +283,8 @@ AvFormatDecoder::AvFormatDecoder(MythPlayer *parent,
pts_detected(false),
reordered_pts_detected(false),
pts_selected(true),
using_null_videoout(use_null_videoout),
playerFlags(flags),
video_codec_id(kCodec_NONE),
no_hardware_decoders(no_hardware_decode),
allow_private_decoders(allow_private_decode),
special_decode(special_decoding),
maxkeyframedist(-1),
// Closed Caption & Teletext decoders
ignore_scte(false),
Expand Down Expand Up @@ -330,8 +324,8 @@ AvFormatDecoder::AvFormatDecoder(MythPlayer *parent,
if (gCoreContext->GetNumSetting("CCBackground", 0))
CC708Window::forceWhiteOnBlackText = true;

LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("Special Decode Flags: 0x%1")
.arg(special_decode, 0, 16));
LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("PlayerFlags: 0x%1")
.arg(playerFlags, 0, 16));
}

AvFormatDecoder::~AvFormatDecoder()
Expand Down Expand Up @@ -1313,33 +1307,35 @@ void AvFormatDecoder::InitVideoCodec(AVStream *stream, AVCodecContext *enc,
.arg(ff_codec_id_string(enc->codec_id)));
}

if (special_decode)
if (FlagIsSet(kDecodeLowRes) || FlagIsSet(kDecodeSingleThreaded) ||
FlagIsSet(kDecodeFewBlocks) || FlagIsSet(kDecodeNoLoopFilter) ||
FlagIsSet(kDecodeNoDecode))
{
enc->flags2 |= CODEC_FLAG2_FAST;

if ((CODEC_ID_MPEG2VIDEO == codec->id) ||
(CODEC_ID_MPEG1VIDEO == codec->id))
{
if (special_decode & kAVSpecialDecode_FewBlocks)
if (FlagIsSet(kDecodeFewBlocks))
{
uint total_blocks = (enc->height+15) / 16;
enc->skip_top = (total_blocks+3) / 4;
enc->skip_bottom = (total_blocks+3) / 4;
}

if (special_decode & kAVSpecialDecode_LowRes)
if (FlagIsSet(kDecodeLowRes))
enc->lowres = 2; // 1 = 1/2 size, 2 = 1/4 size
}
else if (CODEC_ID_H264 == codec->id)
{
if (special_decode & kAVSpecialDecode_NoLoopFilter)
if (FlagIsSet(kDecodeNoLoopFilter))
{
enc->flags &= ~CODEC_FLAG_LOOP_FILTER;
enc->skip_loop_filter = AVDISCARD_ALL;
}
}

if (special_decode & kAVSpecialDecode_NoDecode)
if (FlagIsSet(kDecodeNoDecode))
{
enc->skip_idct = AVDISCARD_ALL;
}
Expand Down Expand Up @@ -1814,7 +1810,7 @@ int AvFormatDecoder::ScanStreams(bool novideo)
if (version)
video_codec_id = (MythCodecID)(kCodec_MPEG1 + version - 1);

if (!using_null_videoout && version)
if (!FlagIsSet(kVideoIsNull) && version)
{
#if defined(USING_VDPAU)
// HACK -- begin
Expand All @@ -1830,7 +1826,8 @@ int AvFormatDecoder::ScanStreams(bool novideo)
MythCodecID vdpau_mcid;
vdpau_mcid = VideoOutputVDPAU::GetBestSupportedCodec(
width, height,
mpeg_version(enc->codec_id), no_hardware_decoders);
mpeg_version(enc->codec_id),
!FlagIsSet(kDecodeAllowGPU));

if (vdpau_mcid >= video_codec_id)
{
Expand All @@ -1843,13 +1840,13 @@ int AvFormatDecoder::ScanStreams(bool novideo)
PixelFormat pix_fmt = PIX_FMT_YUV420P;
vaapi_mcid = VideoOutputOpenGLVAAPI::GetBestSupportedCodec(
width, height, mpeg_version(enc->codec_id),
no_hardware_decoders, pix_fmt);
!FlagIsSet(kDecodeAllowGPU), pix_fmt);

if (vaapi_mcid >= video_codec_id)
{
enc->codec_id = (CodecID)myth2av_codecid(vaapi_mcid);
video_codec_id = vaapi_mcid;
if (!no_hardware_decoders &&
if (FlagIsSet(kDecodeAllowGPU) &&
codec_is_vaapi(video_codec_id))
{
enc->pix_fmt = pix_fmt;
Expand All @@ -1861,13 +1858,13 @@ int AvFormatDecoder::ScanStreams(bool novideo)
PixelFormat pix_fmt = PIX_FMT_YUV420P;
dxva2_mcid = VideoOutputD3D::GetBestSupportedCodec(
width, height, mpeg_version(enc->codec_id),
no_hardware_decoders, pix_fmt);
!FlagIsSet(kDecodeAllowGPU), pix_fmt);

if (dxva2_mcid >= video_codec_id)
{
enc->codec_id = (CodecID)myth2av_codecid(dxva2_mcid);
video_codec_id = dxva2_mcid;
if (!no_hardware_decoders &&
if (FlagIsSet(kDecodeAllowGPU) &&
codec_is_dxva2(video_codec_id))
{
enc->pix_fmt = pix_fmt;
Expand Down Expand Up @@ -1899,19 +1896,19 @@ int AvFormatDecoder::ScanStreams(bool novideo)
if (selectedTrack[kTrackTypeVideo].av_stream_index < 0)
selectedTrack[kTrackTypeVideo] = si;

if (!using_null_videoout && allow_private_decoders &&
if (!FlagIsSet(kVideoIsNull) && FlagIsSet(kDecodeAllowEXT) &&
(selectedTrack[kTrackTypeVideo].av_stream_index == (int) i))
{
private_dec = PrivateDecoder::Create(
dec, no_hardware_decoders, enc);
dec, !FlagIsSet(kDecodeAllowGPU), enc);
if (private_dec)
thread_count = 1;
}

if (!codec_is_std(video_codec_id))
thread_count = 1;

if (special_decode & kAVSpecialDecode_SingleThreaded)
if (FlagIsSet(kDecodeSingleThreaded))
thread_count = 1;

LOG(VB_PLAYBACK, LOG_INFO, LOC +
Expand Down Expand Up @@ -3140,7 +3137,7 @@ bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic)

VideoFrame *picframe = (VideoFrame *)(mpa_pic->opaque);

if (special_decode & kAVSpecialDecode_NoDecode)
if (FlagIsSet(kDecodeNoDecode))
{
// Do nothing, we just want the pts, captions, subtites, etc.
// So we can release the unconverted blank video frame to the
Expand Down
11 changes: 3 additions & 8 deletions mythtv/libs/libmythtv/avformatdecoder.h
Expand Up @@ -17,6 +17,7 @@
#include "vbilut.h"
#include "H264Parser.h"
#include "videodisplayprofile.h"
#include "mythplayer.h"

extern "C" {
#include "frame.h"
Expand Down Expand Up @@ -93,10 +94,7 @@ class AvFormatDecoder : public DecoderBase
public:
static void GetDecoders(render_opts &opts);
AvFormatDecoder(MythPlayer *parent, const ProgramInfo &pginfo,
bool use_null_video_out,
bool allow_private_decode = true,
bool no_hardware_decode = false,
AVSpecialDecode av_special_decode = kAVSpecialDecode_None);
PlayerFlags flags);
~AvFormatDecoder();

virtual void SetEof(bool eof);
Expand Down Expand Up @@ -309,11 +307,8 @@ class AvFormatDecoder : public DecoderBase
bool reordered_pts_detected;
bool pts_selected;

bool using_null_videoout;
PlayerFlags playerFlags;
MythCodecID video_codec_id;
bool no_hardware_decoders;
bool allow_private_decoders;
AVSpecialDecode special_decode;

int maxkeyframedist;

Expand Down
7 changes: 2 additions & 5 deletions mythtv/libs/libmythtv/avformatdecoderbd.cpp
Expand Up @@ -5,11 +5,8 @@
#define LOC QString("AFD_BD: ")

AvFormatDecoderBD::AvFormatDecoderBD(
MythPlayer *parent, const ProgramInfo &pginfo,
bool use_null_video_out, bool allow_private_decode,
bool no_hardware_decode, AVSpecialDecode av_special_decode)
: AvFormatDecoder(parent, pginfo, use_null_video_out, allow_private_decode,
no_hardware_decode, av_special_decode)
MythPlayer *parent, const ProgramInfo &pginfo, PlayerFlags flags)
: AvFormatDecoder(parent, pginfo, flags)
{
}

Expand Down
5 changes: 1 addition & 4 deletions mythtv/libs/libmythtv/avformatdecoderbd.h
Expand Up @@ -7,10 +7,7 @@ class AvFormatDecoderBD : public AvFormatDecoder
{
public:
AvFormatDecoderBD(MythPlayer *parent, const ProgramInfo &pginfo,
bool use_null_video_out,
bool allow_private_decode = true,
bool no_hardware_decode = false,
AVSpecialDecode av_special_decode = kAVSpecialDecode_None);
PlayerFlags flags);
virtual void Reset(bool reset_video_data, bool seek_reset, bool reset_file);
virtual void UpdateFramesPlayed(void);

Expand Down
7 changes: 2 additions & 5 deletions mythtv/libs/libmythtv/avformatdecoderdvd.cpp
Expand Up @@ -5,11 +5,8 @@
#define LOC QString("AFD_DVD: ")

AvFormatDecoderDVD::AvFormatDecoderDVD(
MythPlayer *parent, const ProgramInfo &pginfo,
bool use_null_video_out, bool allow_private_decode,
bool no_hardware_decode, AVSpecialDecode av_special_decode)
: AvFormatDecoder(parent, pginfo, use_null_video_out, allow_private_decode,
no_hardware_decode, av_special_decode)
MythPlayer *parent, const ProgramInfo &pginfo, PlayerFlags flags)
: AvFormatDecoder(parent, pginfo, flags)
{
}

Expand Down
5 changes: 1 addition & 4 deletions mythtv/libs/libmythtv/avformatdecoderdvd.h
Expand Up @@ -7,10 +7,7 @@ class AvFormatDecoderDVD : public AvFormatDecoder
{
public:
AvFormatDecoderDVD(MythPlayer *parent, const ProgramInfo &pginfo,
bool use_null_video_out,
bool allow_private_decode = true,
bool no_hardware_decode = false,
AVSpecialDecode av_special_decode = kAVSpecialDecode_None);
PlayerFlags flags);
virtual void Reset(bool reset_video_data, bool seek_reset, bool reset_file);
virtual void UpdateFramesPlayed(void);

Expand Down
5 changes: 1 addition & 4 deletions mythtv/libs/libmythtv/mythbdplayer.cpp
Expand Up @@ -347,9 +347,6 @@ void MythBDPlayer::CreateDecoder(char *testbuf, int testreadsize)
testreadsize))
{
SetDecoder(new AvFormatDecoderBD(this, *player_ctx->playingInfo,
FlagIsSet(kVideoIsNull),
FlagIsSet(kDecodeAllowEXT),
!FlagIsSet(kDecodeAllowGPU),
player_ctx->GetSpecialDecode()));
playerFlags));
}
}
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/mythccextractorplayer.cpp
Expand Up @@ -47,8 +47,8 @@ TeletextStuff::~TeletextStuff() { delete reader; }
DVBSubStuff::~DVBSubStuff() { delete reader; }

MythCCExtractorPlayer::MythCCExtractorPlayer(
bool showProgress, const QString &fileName) :
MythPlayer((PlayerFlags)(kAudioMuted | kVideoIsNull)),
PlayerFlags flags, bool showProgress, const QString &fileName) :
MythPlayer(flags),
m_curTime(0),
m_curTimeShift(-1),
m_myFramesPlayed(0),
Expand Down
3 changes: 2 additions & 1 deletion mythtv/libs/libmythtv/mythccextractorplayer.h
Expand Up @@ -117,7 +117,8 @@ typedef QHash<uint, SubtitleReader*> SubtitleReaders;
class MTV_PUBLIC MythCCExtractorPlayer : public MythPlayer
{
public:
MythCCExtractorPlayer(bool showProgress, const QString &fileName);
MythCCExtractorPlayer(PlayerFlags flags, bool showProgress,
const QString &fileName);
~MythCCExtractorPlayer() {}

bool run(void);
Expand Down
5 changes: 1 addition & 4 deletions mythtv/libs/libmythtv/mythdvdplayer.cpp
Expand Up @@ -686,9 +686,6 @@ void MythDVDPlayer::CreateDecoder(char *testbuf, int testreadsize)
testreadsize))
{
SetDecoder(new AvFormatDecoderDVD(this, *player_ctx->playingInfo,
FlagIsSet(kVideoIsNull),
FlagIsSet(kDecodeAllowEXT),
!FlagIsSet(kDecodeAllowGPU),
player_ctx->GetSpecialDecode()));
playerFlags));
}
}
5 changes: 1 addition & 4 deletions mythtv/libs/libmythtv/mythplayer.cpp
Expand Up @@ -901,10 +901,7 @@ void MythPlayer::CreateDecoder(char *testbuf, int testreadsize)
testreadsize))
{
SetDecoder(new AvFormatDecoder(this, *player_ctx->playingInfo,
FlagIsSet(kVideoIsNull),
FlagIsSet(kDecodeAllowEXT),
!FlagIsSet(kDecodeAllowGPU),
player_ctx->GetSpecialDecode()));
playerFlags));
}
}

Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythtv/playercontext.cpp
Expand Up @@ -26,8 +26,7 @@ const uint PlayerContext::kMaxChannelHistory = 30;

PlayerContext::PlayerContext(const QString &inUseID) :
recUsage(inUseID), player(NULL), playerUnsafe(false), recorder(NULL),
tvchain(NULL), buffer(NULL), playingInfo(NULL),
playingLen(0), specialDecode(kAVSpecialDecode_None),
tvchain(NULL), buffer(NULL), playingInfo(NULL), playingLen(0),
nohardwaredecoders(false), last_cardid(-1),
// Fast forward state
ff_rew_state(0), ff_rew_index(0), ff_rew_speed(0),
Expand Down
3 changes: 0 additions & 3 deletions mythtv/libs/libmythtv/playercontext.h
Expand Up @@ -103,7 +103,6 @@ class MTV_PUBLIC PlayerContext
void SetPIPState(PIPState change) { pipState = change; }
void SetPlayerChangingBuffers(bool val) { playerUnsafe = val; }
void SetNoHardwareDecoders(void) { nohardwaredecoders = true; }
void SetSpecialDecode(AVSpecialDecode sp) { specialDecode = sp; }

// Gets
QRect GetStandAlonePIPRect(void);
Expand All @@ -116,7 +115,6 @@ class MTV_PUBLIC PlayerContext
QString GetPlayMessage(void) const;
TVState GetState(void) const;
bool GetPlayingInfoMap(InfoMap &infoMap) const;
AVSpecialDecode GetSpecialDecode(void) const { return specialDecode; }

// Boolean Gets
bool IsPIPSupported(void) const;
Expand Down Expand Up @@ -154,7 +152,6 @@ class MTV_PUBLIC PlayerContext
RingBuffer *buffer;
ProgramInfo *playingInfo; ///< Currently playing info
long long playingLen; ///< Initial CalculateLength()
AVSpecialDecode specialDecode;
bool nohardwaredecoders; // < Disable use of VDPAU decoding
int last_cardid; ///< CardID of current/last recorder
/// 0 == normal, +1 == fast forward, -1 == rewind
Expand Down
10 changes: 0 additions & 10 deletions mythtv/libs/libmythtv/videoouttypes.h
Expand Up @@ -113,16 +113,6 @@ typedef enum VideoErrorState
kError_Switch_Renderer = 0x04, // Current renderer is not preferred choice
} VideoErrorState;

typedef enum AVSpecialDecode
{
kAVSpecialDecode_None = 0x00,
kAVSpecialDecode_LowRes = 0x01,
kAVSpecialDecode_SingleThreaded = 0x02,
kAVSpecialDecode_FewBlocks = 0x04,
kAVSpecialDecode_NoLoopFilter = 0x08,
kAVSpecialDecode_NoDecode = 0x10,
} AVSpecialDecode;

inline bool is_interlaced(FrameScanType scan)
{
return (kScan_Interlaced == scan) || (kScan_Intr2ndField == scan);
Expand Down
15 changes: 6 additions & 9 deletions mythtv/programs/mythccextractor/main.cpp
Expand Up @@ -72,16 +72,13 @@ static int RunCCExtract(const ProgramInfo &program_info)
return GENERIC_EXIT_PERMISSIONS_ERROR;
}

bool showProgress = true;
MythCCExtractorPlayer *ccp = new MythCCExtractorPlayer(
showProgress, filename);

PlayerFlags flags = (PlayerFlags)(kVideoIsNull | kAudioMuted |
kDecodeNoLoopFilter | kDecodeFewBlocks |
kDecodeLowRes | kDecodeSingleThreaded |
kDecodeNoDecode);
MythCCExtractorPlayer *ccp = new MythCCExtractorPlayer(flags, true, filename);
PlayerContext *ctx = new PlayerContext(kCCExtractorInUseID);
ctx->SetSpecialDecode((AVSpecialDecode)
(kAVSpecialDecode_NoDecode |
kAVSpecialDecode_NoLoopFilter |
kAVSpecialDecode_FewBlocks |
kAVSpecialDecode_LowRes |
kAVSpecialDecode_SingleThreaded));
ctx->SetPlayingInfo(&program_info);
ctx->SetRingBuffer(tmprbuf);
ctx->SetPlayer(ccp);
Expand Down

0 comments on commit c66767d

Please sign in to comment.