Ticket #5346: 5346-v1.patch

File 5346-v1.patch, 16.3 KB (added by danielk, 16 years ago)

Patch to allow blank & logo and logo & scene to be combined in the classic commercial flagger.

  • programs/mythcommflag/ClassicCommDetector.h

     
    3131    QString toString(uint64_t frame, bool verbose) const;
    3232};
    3333
     34typedef QMap<long long, int> comm_map_t;
     35
    3436class ClassicCommDetector : public CommDetectorBase
    3537{
    3638    Q_OBJECT
     
    4446                            const QDateTime& recordingStopsAt_in);
    4547        virtual ~ClassicCommDetector();
    4648        bool go();
    47         void getCommercialBreakList(QMap<long long, int> &comms);
     49        void getCommercialBreakList(comm_map_t &comms);
    4850        void recordingFinished(long long totalFileSize);
    4951        void requestCommBreakMapUpdate(void);
    5052
     
    7678        void SetVideoParams(float aspect);
    7779        void ProcessFrame(VideoFrame *frame, long long frame_number);
    7880        void ClearAllMaps(void);
    79         void GetBlankCommMap(QMap<long long, int> &comms);
    80         void GetBlankCommBreakMap(QMap<long long, int> &comms);
    81         void GetSceneChangeMap(QMap<long long, int> &scenes,
     81        void GetBlankCommMap(comm_map_t &comms);
     82        void GetBlankCommBreakMap(comm_map_t &comms);
     83        void GetSceneChangeMap(comm_map_t &scenes,
    8284                               long long start_frame);
    83         void BuildMasterCommList(void);
     85        comm_map_t Combine2Maps(comm_map_t &a, comm_map_t &b) const;
    8486        void UpdateFrameBlock(FrameBlock *fbp, FrameInfoEntry finfo,
    8587                              int format, int aspect);
    8688        void BuildAllMethodsCommList(void);
     
    8890        void BuildSceneChangeCommList(void);
    8991        void BuildLogoCommList();
    9092        void MergeBlankCommList(void);
    91         bool FrameIsInBreakMap(long long f, QMap<long long, int> &breakMap);
    92         void DumpMap(QMap<long long, int> &map);
    93         void CondenseMarkMap(QMap<long long, int>&map, int spacing, int length);
    94         void ConvertShowMapToCommMap(QMap<long long, int>&map);
     93        bool FrameIsInBreakMap(long long f, const comm_map_t &breakMap) const;
     94        void DumpMap(comm_map_t &map);
     95        void CondenseMarkMap(comm_map_t&map, int spacing, int length);
     96        void ConvertShowMapToCommMap(comm_map_t&map);
    9597        void CleanupFrameInfo(void);
    96         void GetLogoCommBreakMap(QMap<long long, int> &map);
     98        void GetLogoCommBreakMap(comm_map_t &map);
    9799
    98100        enum SkipTypes commDetectMethod;
    99101        bool showProgress;
     
    152154        unsigned char *framePtr;
    153155
    154156        QMap<long long, FrameInfoEntry> frameInfo;
    155         QMap<long long, int> blankFrameMap;
    156         QMap<long long, int> blankCommMap;
    157         QMap<long long, int> blankCommBreakMap;
    158         QMap<long long, int> sceneMap;
    159         QMap<long long, int> sceneCommBreakMap;
    160         QMap<long long, int> commBreakMap;
    161         QMap<long long, int> logoCommBreakMap;
     157        comm_map_t blankFrameMap;
     158        comm_map_t blankCommMap;
     159        comm_map_t blankCommBreakMap;
     160        comm_map_t sceneMap;
     161        comm_map_t sceneCommBreakMap;
     162        comm_map_t commBreakMap;
     163        comm_map_t logoCommBreakMap;
    162164
    163165        bool frameIsBlank;
    164166        bool sceneHasChanged;
  • programs/mythcommflag/ClassicCommDetector.cpp

     
    433433             ((currentFrameNumber % 500) == 0)))
    434434        {
    435435            QMap<long long,int> commBreakMap;
    436             QMap<long long, int>::Iterator it;
    437             QMap<long long, int>::Iterator lastIt;
     436            comm_map_t::Iterator it;
     437            comm_map_t::Iterator lastIt;
    438438            bool mapsAreIdentical = false;
    439439
    440440            getCommercialBreakList(commBreakMap);
     
    600600    frameInfo[framenum].sceneChangePercent = (int) (debugValue*100);
    601601}
    602602
    603 void ClassicCommDetector::getCommercialBreakList(QMap<long long, int> &marks)
     603void ClassicCommDetector::getCommercialBreakList(comm_map_t &marks)
    604604{
    605605
    606606    VERBOSE(VB_COMMFLAG, "CommDetect::GetCommBreakMap()");
     
    609609
    610610    CleanupFrameInfo();
    611611
    612     switch (commDetectMethod)
     612    bool blank = COMM_DETECT_BLANK & commDetectMethod;
     613    bool scene = COMM_DETECT_SCENE & commDetectMethod;
     614    bool logo  = COMM_DETECT_LOGO  & commDetectMethod;
     615
     616    if (COMM_DETECT_OFF == commDetectMethod)
     617        return;
     618
     619    if (!blank && !scene && !logo)
    613620    {
    614             case COMM_DETECT_OFF:         return;
     621        VERBOSE(VB_COMMFLAG,
     622                QString("Unexpected commDetectMethod: 0x%1")
     623                .arg(commDetectMethod,0,16));
     624        return;
     625    }
    615626
    616             case COMM_DETECT_BLANKS:      BuildBlankFrameCommList();
    617                                           marks = blankCommBreakMap;
    618                                           break;
     627    if (blank && scene && logo)
     628    {
     629        BuildAllMethodsCommList();
     630        marks = commBreakMap;
     631        VERBOSE(VB_COMMFLAG, "Final Commercial Break Map");
     632        return;
     633    }
    619634
    620             case COMM_DETECT_SCENE:       BuildSceneChangeCommList();
    621                                           marks = sceneCommBreakMap;
    622                                           break;
     635    if (blank)
     636    {
     637        BuildBlankFrameCommList();
     638        marks = blankCommBreakMap;
     639    }
    623640
    624             case COMM_DETECT_BLANK_SCENE: BuildBlankFrameCommList();
    625                                           BuildSceneChangeCommList();
    626                                           BuildMasterCommList();
    627                                           marks = commBreakMap;
    628                                           break;
     641    if (scene)
     642    {
     643        BuildSceneChangeCommList();
     644        marks = sceneCommBreakMap;
     645    }
    629646
    630             case COMM_DETECT_LOGO:        BuildLogoCommList();
    631                                           marks = logoCommBreakMap;
    632                                           break;
     647    if (logo)
     648    {
     649        BuildLogoCommList();
     650        marks = logoCommBreakMap;
     651    }
    633652
    634             case COMM_DETECT_ALL:         BuildAllMethodsCommList();
    635                                           marks = commBreakMap;
    636                                           break;
    637             default: VERBOSE(VB_COMMFLAG,
    638                              QString("Unexpected commDetectMethod: %1")
    639                              .arg(commDetectMethod));
    640                      break;
     653    int cnt = ((blank) ? 1 : 0) + ((scene) ? 1 : 0) + ((logo) ? 1 : 0);
     654    if (cnt == 2)
     655    {
     656        if (blank && scene)
     657        {
     658            marks = commBreakMap = Combine2Maps(
     659                blankCommBreakMap, sceneCommBreakMap);
     660        }
     661        else if (blank && logo)
     662        {
     663            marks = commBreakMap = Combine2Maps(
     664                blankCommBreakMap, logoCommBreakMap);
     665        }
     666        else if (scene && logo)
     667        {
     668            marks = commBreakMap = Combine2Maps(
     669                sceneCommBreakMap, logoCommBreakMap);
     670        }
    641671    }
    642672
    643     VERBOSE(VB_COMMFLAG, "Final Commercial Break Map" );
     673    VERBOSE(VB_COMMFLAG, "Final Commercial Break Map");
    644674}
    645675
    646676void ClassicCommDetector::recordingFinished(long long totalFileSize)
     
    953983    commBreakMap.clear();
    954984}
    955985
    956 void ClassicCommDetector::GetBlankCommMap(QMap<long long, int> &comms)
     986void ClassicCommDetector::GetBlankCommMap(comm_map_t &comms)
    957987{
    958988    VERBOSE(VB_COMMFLAG, "CommDetect::GetBlankCommMap()");
    959989
     
    963993    comms = blankCommMap;
    964994}
    965995
    966 void ClassicCommDetector::GetBlankCommBreakMap(QMap<long long, int> &comms)
     996void ClassicCommDetector::GetBlankCommBreakMap(comm_map_t &comms)
    967997{
    968998    VERBOSE(VB_COMMFLAG, "CommDetect::GetBlankCommBreakMap()");
    969999
     
    9731003    comms = blankCommBreakMap;
    9741004}
    9751005
    976 void ClassicCommDetector::GetSceneChangeMap(QMap<long long, int> &scenes,
     1006void ClassicCommDetector::GetSceneChangeMap(comm_map_t &scenes,
    9771007        long long start_frame)
    9781008{
    9791009    VERBOSE(VB_COMMFLAG, "CommDetect::GetSceneChangeMap()");
    9801010
    981     QMap<long long, int>::Iterator it;
     1011    comm_map_t::Iterator it;
    9821012
    9831013    if (start_frame == -1)
    9841014        scenes.clear();
     
    9881018            scenes[it.key()] = it.data();
    9891019}
    9901020
    991 void ClassicCommDetector::BuildMasterCommList(void)
     1021comm_map_t ClassicCommDetector::Combine2Maps(comm_map_t &a, comm_map_t &b) const
    9921022{
    9931023    VERBOSE(VB_COMMFLAG, "CommDetect::BuildMasterCommList()");
    9941024
    995     if (blankCommBreakMap.size())
     1025    comm_map_t newMap;
     1026
     1027    if (a.size())
    9961028    {
    997         QMap<long long, int>::Iterator it;
    998 
    999         for(it = blankCommBreakMap.begin(); it != blankCommBreakMap.end(); ++it)
    1000             commBreakMap[it.key()] = it.data();
     1029        comm_map_t::const_iterator it = a.begin();
     1030        for (; it != a.end(); ++it)
     1031            newMap[it.key()] = it.data();
    10011032    }
    10021033
    1003     if ((blankCommBreakMap.size() > 1) &&
    1004         (sceneCommBreakMap.size() > 1))
     1034    if ((a.size() > 1) &&
     1035        (b.size() > 1))
    10051036    {
    10061037        // see if beginning of the recording looks like a commercial
    1007         QMap<long long, int>::Iterator it_a;
    1008         QMap<long long, int>::Iterator it_b;
     1038        comm_map_t::const_iterator it_a;
     1039        comm_map_t::const_iterator it_b;
    10091040
    1010         it_a = blankCommBreakMap.begin();
    1011         it_b = sceneCommBreakMap.begin();
     1041        it_a = a.begin();
     1042        it_b = b.begin();
    10121043
    10131044        if ((it_b.key() < 2) &&
    10141045            (it_a.key() > 2))
    10151046        {
    1016             commBreakMap.erase(it_a.key());
    1017             commBreakMap[0] = MARK_COMM_START;
     1047            newMap.erase(it_a.key());
     1048            newMap[0] = MARK_COMM_START;
    10181049        }
    10191050
    10201051
    10211052        // see if ending of recording looks like a commercial
    1022         QMap<long long, int>::const_iterator it;
    1023         long long max_blank = 0;
    1024         long long max_scene = 0;
     1053        comm_map_t::const_iterator it;
     1054        long long max_a = 0;
     1055        long long max_b = 0;
    10251056
    1026         it = blankCommBreakMap.begin();
    1027         for (; it != blankCommBreakMap.end(); ++it)
     1057        it = a.begin();
     1058        for (; it != a.end(); ++it)
    10281059        {
    1029             if ((it.data() == MARK_COMM_END) && (it.key() > max_blank))
    1030                 max_blank = it.key();
     1060            if ((it.data() == MARK_COMM_END) && (it.key() > max_a))
     1061                max_a = it.key();
    10311062        }
    10321063
    1033         it = sceneCommBreakMap.begin();
    1034         for (; it != sceneCommBreakMap.end(); ++it)
     1064        it = b.begin();
     1065        for (; it != b.end(); ++it)
    10351066        {
    1036             if ((it.data() == MARK_COMM_END) && (it.key() > max_scene))
    1037                 max_scene = it.key();
     1067            if ((it.data() == MARK_COMM_END) && (it.key() > max_b))
     1068                max_b = it.key();
    10381069        }
    10391070
    1040         if ((max_blank < (framesProcessed - 2)) &&
    1041             (max_scene > (framesProcessed - 2)))
     1071        if ((max_a < (framesProcessed - 2)) &&
     1072            (max_b > (framesProcessed - 2)))
    10421073        {
    1043             commBreakMap.erase(max_blank);
    1044             commBreakMap[framesProcessed] = MARK_COMM_END;
     1074            newMap.erase(max_a);
     1075            newMap[framesProcessed] = MARK_COMM_END;
    10451076        }
    10461077    }
    10471078
    1048     if ((blankCommBreakMap.size() > 3) &&
    1049         (sceneCommBreakMap.size() > 1))
     1079    if ((a.size() > 3) &&
     1080        (b.size() > 1))
    10501081    {
    1051         QMap<long long, int>::Iterator it_a;
    1052         QMap<long long, int>::Iterator it_b;
     1082        comm_map_t::const_iterator it_a;
     1083        comm_map_t::const_iterator it_b;
    10531084        long long b_start, b_end;
    10541085        long long s_start, s_end;
    10551086
    10561087        b_start = b_end = -1;
    10571088        s_start = s_end = -1;
    10581089
    1059         it_a = blankCommBreakMap.begin();
     1090        it_a = a.begin();
    10601091        it_a++;
    10611092        it_b = it_a;
    10621093        it_b++;
    1063         while(it_b != blankCommBreakMap.end())
     1094        while(it_b != a.end())
    10641095        {
    10651096            long long fdiff = it_b.key() - it_a.key();
    10661097            bool allTrue = false;
     
    10721103                allTrue = true;
    10731104
    10741105                while ((f <= framesProcessed) && (f < it_b.key()) && (allTrue))
    1075                     allTrue = FrameIsInBreakMap(f++, sceneCommBreakMap);
     1106                    allTrue = FrameIsInBreakMap(f++, b);
    10761107            }
    10771108
    10781109            if (allTrue)
    10791110            {
    1080                 commBreakMap.erase(it_a.key());
    1081                 commBreakMap.erase(it_b.key());
     1111                newMap.erase(it_a.key());
     1112                newMap.erase(it_b.key());
    10821113            }
    10831114
    10841115            it_a++; it_a++;
    10851116            it_b++;
    1086             if (it_b != blankCommBreakMap.end())
     1117            if (it_b != a.end())
    10871118                it_b++;
    10881119        }
    10891120    }
     1121
     1122    return newMap;
    10901123}
    10911124
    10921125void ClassicCommDetector::UpdateFrameBlock(FrameBlock *fbp,
     
    11391172    int aspect = COMM_ASPECT_NORMAL;
    11401173    QString msg;
    11411174    long long formatCounts[COMM_FORMAT_MAX];
    1142     QMap<long long, int> tmpCommMap;
    1143     QMap<long long, int>::Iterator it;
     1175    comm_map_t tmpCommMap;
     1176    comm_map_t::Iterator it;
    11441177
    11451178    commBreakMap.clear();
    11461179
     
    18161849    int frames = 0;
    18171850    int commercials = 0;
    18181851    int i, x;
    1819     QMap<long long, int>::Iterator it;
     1852    comm_map_t::Iterator it;
    18201853
    18211854    blankCommMap.clear();
    18221855
     
    20202053    if (section_start >= 0)
    20212054        sceneCommBreakMap[framesProcessed] = MARK_COMM_END;
    20222055
    2023     QMap<long long, int>::Iterator it;
    2024     QMap<long long, int>::Iterator prev;
    2025     QMap<long long, int> deleteMap;
     2056    comm_map_t::Iterator it;
     2057    comm_map_t::Iterator prev;
     2058    comm_map_t deleteMap;
    20262059
    20272060    it = sceneCommBreakMap.begin();
    20282061    prev = it;
     
    20592092    CondenseMarkMap(logoCommBreakMap, (int)(25 * fps), (int)(30 * fps));
    20602093    ConvertShowMapToCommMap(logoCommBreakMap);
    20612094
    2062     QMap<long long, int>::Iterator it;
     2095    comm_map_t::Iterator it;
    20632096    VERBOSE(VB_COMMFLAG, "Logo Commercial Break Map" );
    20642097    for(it = logoCommBreakMap.begin(); it != logoCommBreakMap.end(); ++it)
    20652098        VERBOSE(VB_COMMFLAG, QString("    %1:%2")
     
    20682101
    20692102void ClassicCommDetector::MergeBlankCommList(void)
    20702103{
    2071     QMap<long long, int>::Iterator it;
    2072     QMap<long long, int>::Iterator prev;
     2104    comm_map_t::Iterator it;
     2105    comm_map_t::Iterator prev;
    20732106    QMap<long long, long long> tmpMap;
    20742107    QMap<long long, long long>::Iterator tmpMap_it;
    20752108    QMap<long long, long long>::Iterator tmpMap_prev;
     
    21312164    }
    21322165}
    21332166
    2134 bool ClassicCommDetector::FrameIsInBreakMap(long long f,
    2135                                             QMap<long long, int> &breakMap)
     2167bool ClassicCommDetector::FrameIsInBreakMap(
     2168    long long f, const comm_map_t &breakMap) const
    21362169{
    21372170    for(long long i = f; i < framesProcessed; i++)
    21382171        if (breakMap.contains(i))
     
    21572190    return false;
    21582191}
    21592192
    2160 void ClassicCommDetector::DumpMap(QMap<long long, int> &map)
     2193void ClassicCommDetector::DumpMap(comm_map_t &map)
    21612194{
    2162     QMap<long long, int>::Iterator it;
     2195    comm_map_t::Iterator it;
    21632196    QString msg;
    21642197
    21652198    VERBOSE(VB_COMMFLAG, "---------------------------------------------------");
     
    21812214    VERBOSE(VB_COMMFLAG, "---------------------------------------------------");
    21822215}
    21832216
    2184 void ClassicCommDetector::CondenseMarkMap(QMap<long long, int>&map, int spacing,
     2217void ClassicCommDetector::CondenseMarkMap(comm_map_t&map, int spacing,
    21852218                                          int length)
    21862219{
    2187     QMap<long long, int>::Iterator it;
    2188     QMap<long long, int>::Iterator prev;
    2189     QMap<long long, int>tmpMap;
     2220    comm_map_t::Iterator it;
     2221    comm_map_t::Iterator prev;
     2222    comm_map_t tmpMap;
    21902223
    21912224    if (map.size() <= 2)
    21922225        return;
     
    22462279                .arg((long int)it.key()).arg(it.data()));
    22472280}
    22482281
    2249 void ClassicCommDetector::ConvertShowMapToCommMap(QMap<long long, int>&map)
     2282void ClassicCommDetector::ConvertShowMapToCommMap(comm_map_t&map)
    22502283{
    2251     QMap<long long, int>::Iterator it;
     2284    comm_map_t::Iterator it;
    22522285
    22532286    if (map.size() == 0)
    22542287        return;
     
    23752408    }
    23762409}
    23772410
    2378 void ClassicCommDetector::GetLogoCommBreakMap(QMap<long long, int> &map)
     2411void ClassicCommDetector::GetLogoCommBreakMap(comm_map_t &map)
    23792412{
    23802413    VERBOSE(VB_COMMFLAG, "CommDetect::GetLogoCommBreakMap()");
    23812414
     
    24262459        out << (*it).toString(i, verbose).ascii() << " ";
    24272460        if (comm_breaks)
    24282461        {
    2429             QMap<long long, int>::const_iterator mit = comm_breaks->find(i);
     2462            comm_map_t::const_iterator mit = comm_breaks->find(i);
    24302463            if (mit != comm_breaks->end())
    24312464            {
    24322465                QString tmp = (verbose) ?