Ticket #6824: 6824-v4.patch

File 6824-v4.patch, 16.3 KB (added by beirdo, 14 years ago)
  • mythtv/libs/libmythtv/avformatdecoder.cpp

    From e69cf044d99e9aff0dccf1a7db12544d976c219a Mon Sep 17 00:00:00 2001
    From: Gavin Hurlbut <gjhurlbu@gmail.com>
    Date: Wed, 28 Jul 2010 18:08:07 -0700
    Subject: [PATCH] 6824-v4.patch from #6824
    
    
    diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
    index c7a526e..264a1b3 100644
    a b static int dts_decode_header(uint8_t *indata_ptr, int *rate, 
    8484                             int *nblks, int *sfreq);
    8585static int encode_frame(bool dts, unsigned char* data, int len,
    8686                        short *samples, int &samples_size);
     87static QSize get_video_dim(const AVCodecContext &ctx)
     88{
     89    return QSize(ctx.width >> ctx.lowres, ctx.height >> ctx.lowres);
     90}
     91static float get_aspect(const AVCodecContext &ctx)
     92{
     93    float aspect_ratio = 0.0f;
     94
     95    if (ctx.sample_aspect_ratio.num && ctx.height)
     96    {
     97        aspect_ratio = av_q2d(ctx.sample_aspect_ratio) * (float) ctx.width;
     98        aspect_ratio /= (float) ctx.height;
     99    }
     100
     101    if (aspect_ratio <= 0.0f || aspect_ratio > 6.0f)
     102    {
     103        if (ctx.height)
     104            aspect_ratio = (float)ctx.width / (float)ctx.height;
     105        else
     106            aspect_ratio = 4.0f / 3.0f;
     107    }
     108
     109    return aspect_ratio;
     110}
    87111
    88112int get_avf_buffer_xvmc(struct AVCodecContext *c, AVFrame *pic);
    89113int get_avf_buffer(struct AVCodecContext *c, AVFrame *pic);
    AvFormatDecoder::AvFormatDecoder(MythPlayer *parent, 
    216240                                 const ProgramInfo &pginfo,
    217241                                 bool use_null_videoout,
    218242                                 bool allow_private_decode,
    219                                  bool no_hardware_decode)
     243                                 bool no_hardware_decode,
     244                                 AVSpecialDecode special_decoding)
    220245    : DecoderBase(parent, pginfo),
    221246      private_dec(NULL),
    222247      is_db_ignored(gCoreContext->IsDatabaseIgnored()),
    AvFormatDecoder::AvFormatDecoder(MythPlayer *parent, 
    236261      video_codec_id(kCodec_NONE),
    237262      no_hardware_decoders(no_hardware_decode),
    238263      allow_private_decoders(allow_private_decode),
     264      special_decode(special_decoding),
    239265      maxkeyframedist(-1),
    240266      // Closed Caption & Teletext decoders
    241267      ccd608(new CC608Decoder(parent->GetCC608Reader())),
    AvFormatDecoder::AvFormatDecoder(MythPlayer *parent, 
    277303        CC708Window::forceWhiteOnBlackText = true;
    278304
    279305    no_dts_hack = false;
     306
     307    int x = gCoreContext->GetNumSetting("CommFlagFast", -1);
     308    if (x != -1)
     309        special_decode = (AVSpecialDecode) x;
     310    VERBOSE(VB_IMPORTANT, "commflagging_speedups: " << special_decode);
    280311}
    281312
    282313AvFormatDecoder::~AvFormatDecoder()
    void AvFormatDecoder::InitVideoCodec(AVStream *stream, AVCodecContext *enc, 
    11291160            <<") type ("<<codec_type_string(enc->codec_type)
    11301161            <<").");
    11311162
    1132     float aspect_ratio = 0.0;
    1133 
    11341163    if (ringBuffer && ringBuffer->isDVD())
    11351164        directrendering = false;
    11361165
    1137     if (selectedStream)
    1138     {
    1139         fps = normalized_fps(stream, enc);
    1140 
    1141         if (enc->sample_aspect_ratio.num)
    1142             aspect_ratio = av_q2d(enc->sample_aspect_ratio);
    1143         else if (stream->sample_aspect_ratio.num)
    1144             aspect_ratio = av_q2d(stream->sample_aspect_ratio);
    1145         else
    1146             aspect_ratio = 1.0f;
    1147 
    1148         if (aspect_ratio <= 0.0f || aspect_ratio > 6.0f)
    1149             aspect_ratio = 1.0f;
    1150 
    1151         aspect_ratio *= (float)enc->width / (float)enc->height;
    1152 
    1153         current_width  = enc->width;
    1154         current_height = enc->height;
    1155         current_aspect = aspect_ratio;
    1156     }
    1157 
    11581166    enc->opaque = (void *)this;
    11591167    enc->get_buffer = get_avf_buffer;
    11601168    enc->release_buffer = release_avf_buffer;
    void AvFormatDecoder::InitVideoCodec(AVStream *stream, AVCodecContext *enc, 
    12161224                .arg(codec_id_string(enc->codec_id)));
    12171225    }
    12181226
     1227    if (special_decode)
     1228    {
     1229        if (special_decode & kAVSpecialDecode_SingleThreaded)
     1230            enc->thread_count = 1;
     1231
     1232        enc->flags |= CODEC_FLAG2_FAST;
     1233
     1234        if ((CODEC_ID_MPEG2VIDEO == codec->id) ||
     1235            (CODEC_ID_MPEG1VIDEO == codec->id))
     1236        {
     1237            if (special_decode & kAVSpecialDecode_FewBlocks)
     1238            {
     1239                uint total_blocks = (enc->height+15) / 16;
     1240                enc->skip_top     = (total_blocks+3) / 4;
     1241                enc->skip_bottom  = (total_blocks+3) / 4;
     1242            }
     1243
     1244            if (special_decode & kAVSpecialDecode_LowRes)
     1245                enc->lowres = 2; // 1 = 1/2 size, 2 = 1/4 size
     1246        }
     1247        else if (CODEC_ID_H264 == codec->id)
     1248        {
     1249            if (special_decode & kAVSpecialDecode_NoLoopFilter)
     1250            {
     1251                enc->flags &= ~CODEC_FLAG_LOOP_FILTER;
     1252                enc->skip_loop_filter = AVDISCARD_ALL;
     1253            }
     1254        }
     1255
     1256        if (special_decode & kAVSpecialDecode_NoDecode)
     1257        {
     1258            enc->skip_idct = AVDISCARD_ALL;
     1259        }
     1260    }
     1261
    12191262    if (selectedStream)
    12201263    {
    1221         uint width  = enc->width;
    1222         uint height = enc->height;
     1264        fps = normalized_fps(stream, enc);
     1265        QSize dim    = get_video_dim(*enc);
     1266        int   width  = current_width  = dim.width();
     1267        int   height = current_height = dim.height();
     1268        float aspect = current_aspect = get_aspect(*enc);
    12231269
    1224         if (width == 0 && height == 0)
     1270        if (!width || !height)
    12251271        {
    12261272            VERBOSE(VB_PLAYBACK, LOC + "InitVideoCodec "
    12271273                    "invalid dimensions, resetting decoder.");
    1228             width = 640;
     1274            width  = 640;
    12291275            height = 480;
    1230             fps = 29.97;
    1231             aspect_ratio = 4.0 / 3;
     1276            fps    = 29.97f;
     1277            aspect = 4.0f / 3.0f;
    12321278        }
    12331279
    12341280        GetPlayer()->SetVideoParams(width, height, fps,
    1235                                  keyframedist, aspect_ratio, kScan_Detect,
     1281                                 keyframedist, aspect, kScan_Detect,
    12361282                                 dvd_video_codec_changed);
    12371283        if (LCD *lcd = LCD::Get())
    12381284        {
    int AvFormatDecoder::ScanStreams(bool novideo) 
    16461692                private_dec = NULL;
    16471693                m_h264_parser->Reset();
    16481694
    1649                 uint width  = max(enc->width, 16);
    1650                 uint height = max(enc->height, 16);
     1695                QSize dim = get_video_dim(*enc);
     1696                uint width  = max(dim.width(),  16);
     1697                uint height = max(dim.height(), 16);
    16511698                QString dec = "ffmpeg";
    16521699                uint thread_count = 1;
    16531700
    void AvFormatDecoder::MpegPreProcessPkt(AVStream *stream, AVPacket *pkt) 
    26312678            SequenceHeader *seq = reinterpret_cast<SequenceHeader*>(
    26322679                const_cast<uint8_t*>(bufptr));
    26332680
    2634             uint  width  = seq->width();
    2635             uint  height = seq->height();
     2681            uint  width  = seq->width()  >> context->lowres;
     2682            uint  height = seq->height() >> context->lowres;
    26362683            float aspect = seq->aspect(context->sub_id == 1);
    26372684            float seqFPS = seq->fps();
    26382685
    2639             bool changed = (seqFPS > fps+0.01) || (seqFPS < fps-0.01);
     2686            bool changed = (seqFPS > fps+0.01f) || (seqFPS < fps-0.01f);
    26402687            changed |= (width  != (uint)current_width );
    26412688            changed |= (height != (uint)current_height);
    26422689            changed |= fabs(aspect - current_aspect) > eps;
    void AvFormatDecoder::MpegPreProcessPkt(AVStream *stream, AVPacket *pkt) 
    26612708
    26622709                // fps debugging info
    26632710                float avFPS = normalized_fps(stream, context);
    2664                 if ((seqFPS > avFPS+0.01) || (seqFPS < avFPS-0.01))
     2711                if ((seqFPS > avFPS+0.01f) || (seqFPS < avFPS-0.01f))
    26652712                {
    26662713                    VERBOSE(VB_PLAYBACK, LOC +
    26672714                            QString("avFPS(%1) != seqFPS(%2)")
    bool AvFormatDecoder::H264PreProcessPkt(AVStream *stream, AVPacket *pkt) 
    27352782            continue;
    27362783        }
    27372784
    2738         float aspect_ratio;
    2739         if (context->sample_aspect_ratio.num == 0)
    2740             aspect_ratio = 0.0f;
    2741         else
    2742             aspect_ratio = av_q2d(context->sample_aspect_ratio) *
    2743                 context->width / context->height;
    2744 
    2745         if (aspect_ratio <= 0.0f || aspect_ratio > 6.0f)
    2746             aspect_ratio = (float)context->width / context->height;
    2747 
    2748         uint  width  = context->width;
    2749         uint  height = context->height;
     2785        float aspect_ratio = get_aspect(*context);
     2786        QSize dim    = get_video_dim(*context);
     2787        uint  width  = dim.width();
     2788        uint  height = dim.height();
    27502789        float seqFPS = normalized_fps(stream, context);
    27512790
    2752         bool changed = (seqFPS > fps+0.01) || (seqFPS < fps-0.01);
     2791        bool changed = (seqFPS > fps+0.01f) || (seqFPS < fps-0.01f);
    27532792        changed |= (width  != (uint)current_width );
    27542793        changed |= (height != (uint)current_height);
    27552794        changed |= fabs(aspect_ratio - current_aspect) > eps;
    bool AvFormatDecoder::H264PreProcessPkt(AVStream *stream, AVPacket *pkt) 
    27712810
    27722811            // fps debugging info
    27732812            float avFPS = normalized_fps(stream, context);
    2774             if ((seqFPS > avFPS+0.01) || (seqFPS < avFPS-0.01))
     2813            if ((seqFPS > avFPS+0.01f) || (seqFPS < avFPS-0.01f))
    27752814            {
    27762815                VERBOSE(VB_PLAYBACK, LOC +
    27772816                        QString("avFPS(%1) != seqFPS(%2)")
    bool AvFormatDecoder::ProcessVideoPacket(AVStream *curstream, AVPacket *pkt) 
    29122951        tmppicture.linesize[1] = picframe->pitches[1];
    29132952        tmppicture.linesize[2] = picframe->pitches[2];
    29142953
     2954        QSize dim = get_video_dim(*context);
    29152955        sws_ctx = sws_getCachedContext(sws_ctx, context->width,
    29162956                                       context->height, context->pix_fmt,
    29172957                                       context->width, context->height,
    bool AvFormatDecoder::ProcessVideoPacket(AVStream *curstream, AVPacket *pkt) 
    29222962            VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to allocate sws context");
    29232963            return false;
    29242964        }
    2925         sws_scale(sws_ctx, mpa_pic.data, mpa_pic.linesize, 0, context->height,
     2965        sws_scale(sws_ctx, mpa_pic.data, mpa_pic.linesize, 0, dim.height(),
    29262966                  tmppicture.data, tmppicture.linesize);
    29272967
    29282968
  • mythtv/libs/libmythtv/avformatdecoder.h

    diff --git a/mythtv/libs/libmythtv/avformatdecoder.h b/mythtv/libs/libmythtv/avformatdecoder.h
    index 23d990b..a82b30b 100644
    a b  
    22#define AVFORMATDECODER_H_
    33
    44#include <QString>
     5#include <QMap>
    56#include <QList>
    67
    78#include "programinfo.h"
    class AvFormatDecoder : public DecoderBase 
    8182    AvFormatDecoder(MythPlayer *parent, const ProgramInfo &pginfo,
    8283                    bool use_null_video_out,
    8384                    bool allow_private_decode = true,
    84                     bool no_hardware_decode = false);
     85                    bool no_hardware_decode = false,
     86                    AVSpecialDecode av_special_decode = kAVSpecialDecode_None);
    8587   ~AvFormatDecoder();
    8688
    8789    void CloseCodecs();
    class AvFormatDecoder : public DecoderBase 
    267269    MythCodecID video_codec_id;
    268270    bool no_hardware_decoders;
    269271    bool allow_private_decoders;
     272    AVSpecialDecode special_decode;
    270273
    271274    int maxkeyframedist;
    272275
  • mythtv/libs/libmythtv/mythplayer.cpp

    diff --git a/mythtv/libs/libmythtv/mythplayer.cpp b/mythtv/libs/libmythtv/mythplayer.cpp
    index 9738516..f93be02 100644
    a b int MythPlayer::OpenFile(uint retries, bool allow_libmpeg2) 
    956956                          (player_ctx->IsPBP() && !player_ctx->IsPrimaryPBP());
    957957            SetDecoder(new AvFormatDecoder(this, *player_ctx->playingInfo,
    958958                                           using_null_videoout,
    959                                            allow_libmpeg2, noaccel));
     959                                           allow_libmpeg2, noaccel,
     960                                           player_ctx->GetSpecialDecode()));
    960961        }
    961962        player_ctx->UnlockPlayingInfo(__FILE__, __LINE__);
    962963        if (GetDecoder())
  • mythtv/libs/libmythtv/playercontext.cpp

    diff --git a/mythtv/libs/libmythtv/playercontext.cpp b/mythtv/libs/libmythtv/playercontext.cpp
    index fcd62ab..b6d3316 100644
    a b void PlayerThread::run(void) 
    3737PlayerContext::PlayerContext(const QString &inUseID) :
    3838    recUsage(inUseID), player(NULL), playerUnsafe(false), recorder(NULL),
    3939    tvchain(NULL), buffer(NULL), playingInfo(NULL),
    40     playingLen(0), nohardwaredecoders(false), last_cardid(-1), last_framerate(30.0f),
     40    playingLen(0), specialDecode(kAVSpecialDecode_None),
     41    nohardwaredecoders(false), last_cardid(-1), last_framerate(30.0f),
    4142    // Fast forward state
    4243    ff_rew_state(0), ff_rew_index(0), ff_rew_speed(0),
    4344    // Other state
  • mythtv/libs/libmythtv/playercontext.h

    diff --git a/mythtv/libs/libmythtv/playercontext.h b/mythtv/libs/libmythtv/playercontext.h
    index 3e0e672..ae769bf 100644
    a b class MPUBLIC PlayerContext 
    119119    void SetPIPState(PIPState change) { pipState = change; }
    120120    void SetPlayerChangingBuffers(bool val) { playerUnsafe = val; }
    121121    void SetNoHardwareDecoders(void) { nohardwaredecoders = true; }
     122    void SetSpecialDecode(AVSpecialDecode sp) { specialDecode = sp; }
    122123
    123124    // Gets
    124125    QRect    GetStandAlonePIPRect(void);
    class MPUBLIC PlayerContext 
    131132    QString  GetPlayMessage(void) const;
    132133    TVState  GetState(void) const;
    133134    bool     GetPlayingInfoMap(InfoMap &infoMap) const;
     135    AVSpecialDecode GetSpecialDecode(void) const { return specialDecode; }
    134136
    135137    // Boolean Gets
    136138    bool IsPIPSupported(void) const;
    class MPUBLIC PlayerContext 
    169171    RingBuffer         *buffer;
    170172    ProgramInfo        *playingInfo; ///< Currently playing info
    171173    long long           playingLen;  ///< Initial CalculateLength()
     174    AVSpecialDecode     specialDecode;
    172175    bool                nohardwaredecoders; // < Disable use of VDPAU decoding
    173176    int                 last_cardid; ///< CardID of current/last recorder
    174177    float               last_framerate; ///< Estimated framerate from recorder
  • mythtv/libs/libmythtv/videoouttypes.h

    diff --git a/mythtv/libs/libmythtv/videoouttypes.h b/mythtv/libs/libmythtv/videoouttypes.h
    index 37b9517..b3401a3 100644
    a b typedef enum VideoErrorState 
    109109    kError_Switch_Renderer = 0x04, // Current renderer is not preferred choice
    110110} VideoErrorState;
    111111
     112typedef enum AVSpecialDecode
     113{
     114    kAVSpecialDecode_None           = 0x00,
     115    kAVSpecialDecode_LowRes         = 0x01,
     116    kAVSpecialDecode_SingleThreaded = 0x02,
     117    kAVSpecialDecode_FewBlocks      = 0x04,
     118    kAVSpecialDecode_NoLoopFilter   = 0x08,
     119    kAVSpecialDecode_NoDecode       = 0x10,
     120} AVSpecialDecode;
     121
    112122inline bool is_interlaced(FrameScanType scan)
    113123{
    114124    return (kScan_Interlaced == scan) || (kScan_Intr2ndField == scan);
  • mythtv/programs/mythcommflag/main.cpp

    diff --git a/mythtv/programs/mythcommflag/main.cpp b/mythtv/programs/mythcommflag/main.cpp
    index 050ffc9..bf2bda7 100644
    a b int BuildVideoMarkup(ProgramInfo *program_info, bool useDB) 
    172172
    173173    MythCommFlagPlayer *cfp = new MythCommFlagPlayer();
    174174    PlayerContext *ctx = new PlayerContext("seektable rebuilder");
     175    ctx->SetSpecialDecode(kAVSpecialDecode_NoDecode);
    175176    ctx->SetPlayingInfo(program_info);
    176177    ctx->SetRingBuffer(tmprbuf);
    177178    ctx->SetPlayer(cfp);
    int FlagCommercials( 
    756757    MythCommFlagPlayer *cfp = new MythCommFlagPlayer();
    757758
    758759    PlayerContext *ctx = new PlayerContext(kFlaggerInUseID);
     760
     761    AVSpecialDecode sp = (AVSpecialDecode)
     762        (kAVSpecialDecode_LowRes         |
     763         kAVSpecialDecode_SingleThreaded |
     764         kAVSpecialDecode_NoLoopFilter);
     765
     766    /* blank detector needs to be only sample center for this optimization. */
     767    if ((COMM_DETECT_BLANKS  == commDetectMethod) ||
     768        (COMM_DETECT_2_BLANK == commDetectMethod))
     769    {
     770        sp = (AVSpecialDecode) (sp | kAVSpecialDecode_FewBlocks);
     771    }
     772
     773    ctx->SetSpecialDecode(sp);
     774
    759775    ctx->SetPlayingInfo(program_info);
    760776    ctx->SetRingBuffer(tmprbuf);
    761777    ctx->SetPlayer(cfp);