Ticket #5346: 5346-v1.patch
File 5346-v1.patch, 16.3 KB (added by , 16 years ago) |
---|
-
programs/mythcommflag/ClassicCommDetector.h
31 31 QString toString(uint64_t frame, bool verbose) const; 32 32 }; 33 33 34 typedef QMap<long long, int> comm_map_t; 35 34 36 class ClassicCommDetector : public CommDetectorBase 35 37 { 36 38 Q_OBJECT … … 44 46 const QDateTime& recordingStopsAt_in); 45 47 virtual ~ClassicCommDetector(); 46 48 bool go(); 47 void getCommercialBreakList( QMap<long long, int>&comms);49 void getCommercialBreakList(comm_map_t &comms); 48 50 void recordingFinished(long long totalFileSize); 49 51 void requestCommBreakMapUpdate(void); 50 52 … … 76 78 void SetVideoParams(float aspect); 77 79 void ProcessFrame(VideoFrame *frame, long long frame_number); 78 80 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, 82 84 long long start_frame); 83 void BuildMasterCommList(void);85 comm_map_t Combine2Maps(comm_map_t &a, comm_map_t &b) const; 84 86 void UpdateFrameBlock(FrameBlock *fbp, FrameInfoEntry finfo, 85 87 int format, int aspect); 86 88 void BuildAllMethodsCommList(void); … … 88 90 void BuildSceneChangeCommList(void); 89 91 void BuildLogoCommList(); 90 92 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); 95 97 void CleanupFrameInfo(void); 96 void GetLogoCommBreakMap( QMap<long long, int>&map);98 void GetLogoCommBreakMap(comm_map_t &map); 97 99 98 100 enum SkipTypes commDetectMethod; 99 101 bool showProgress; … … 152 154 unsigned char *framePtr; 153 155 154 156 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; 162 164 163 165 bool frameIsBlank; 164 166 bool sceneHasChanged; -
programs/mythcommflag/ClassicCommDetector.cpp
433 433 ((currentFrameNumber % 500) == 0))) 434 434 { 435 435 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; 438 438 bool mapsAreIdentical = false; 439 439 440 440 getCommercialBreakList(commBreakMap); … … 600 600 frameInfo[framenum].sceneChangePercent = (int) (debugValue*100); 601 601 } 602 602 603 void ClassicCommDetector::getCommercialBreakList( QMap<long long, int>&marks)603 void ClassicCommDetector::getCommercialBreakList(comm_map_t &marks) 604 604 { 605 605 606 606 VERBOSE(VB_COMMFLAG, "CommDetect::GetCommBreakMap()"); … … 609 609 610 610 CleanupFrameInfo(); 611 611 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) 613 620 { 614 case COMM_DETECT_OFF: return; 621 VERBOSE(VB_COMMFLAG, 622 QString("Unexpected commDetectMethod: 0x%1") 623 .arg(commDetectMethod,0,16)); 624 return; 625 } 615 626 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 } 619 634 620 case COMM_DETECT_SCENE: BuildSceneChangeCommList(); 621 marks = sceneCommBreakMap; 622 break; 635 if (blank) 636 { 637 BuildBlankFrameCommList(); 638 marks = blankCommBreakMap; 639 } 623 640 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 } 629 646 630 case COMM_DETECT_LOGO: BuildLogoCommList(); 631 marks = logoCommBreakMap; 632 break; 647 if (logo) 648 { 649 BuildLogoCommList(); 650 marks = logoCommBreakMap; 651 } 633 652 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 } 641 671 } 642 672 643 VERBOSE(VB_COMMFLAG, "Final Commercial Break Map" 673 VERBOSE(VB_COMMFLAG, "Final Commercial Break Map"); 644 674 } 645 675 646 676 void ClassicCommDetector::recordingFinished(long long totalFileSize) … … 953 983 commBreakMap.clear(); 954 984 } 955 985 956 void ClassicCommDetector::GetBlankCommMap( QMap<long long, int>&comms)986 void ClassicCommDetector::GetBlankCommMap(comm_map_t &comms) 957 987 { 958 988 VERBOSE(VB_COMMFLAG, "CommDetect::GetBlankCommMap()"); 959 989 … … 963 993 comms = blankCommMap; 964 994 } 965 995 966 void ClassicCommDetector::GetBlankCommBreakMap( QMap<long long, int>&comms)996 void ClassicCommDetector::GetBlankCommBreakMap(comm_map_t &comms) 967 997 { 968 998 VERBOSE(VB_COMMFLAG, "CommDetect::GetBlankCommBreakMap()"); 969 999 … … 973 1003 comms = blankCommBreakMap; 974 1004 } 975 1005 976 void ClassicCommDetector::GetSceneChangeMap( QMap<long long, int>&scenes,1006 void ClassicCommDetector::GetSceneChangeMap(comm_map_t &scenes, 977 1007 long long start_frame) 978 1008 { 979 1009 VERBOSE(VB_COMMFLAG, "CommDetect::GetSceneChangeMap()"); 980 1010 981 QMap<long long, int>::Iterator it;1011 comm_map_t::Iterator it; 982 1012 983 1013 if (start_frame == -1) 984 1014 scenes.clear(); … … 988 1018 scenes[it.key()] = it.data(); 989 1019 } 990 1020 991 void ClassicCommDetector::BuildMasterCommList(void) 1021 comm_map_t ClassicCommDetector::Combine2Maps(comm_map_t &a, comm_map_t &b) const 992 1022 { 993 1023 VERBOSE(VB_COMMFLAG, "CommDetect::BuildMasterCommList()"); 994 1024 995 if (blankCommBreakMap.size()) 1025 comm_map_t newMap; 1026 1027 if (a.size()) 996 1028 { 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(); 1001 1032 } 1002 1033 1003 if (( blankCommBreakMap.size() > 1) &&1004 ( sceneCommBreakMap.size() > 1))1034 if ((a.size() > 1) && 1035 (b.size() > 1)) 1005 1036 { 1006 1037 // 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; 1009 1040 1010 it_a = blankCommBreakMap.begin();1011 it_b = sceneCommBreakMap.begin();1041 it_a = a.begin(); 1042 it_b = b.begin(); 1012 1043 1013 1044 if ((it_b.key() < 2) && 1014 1045 (it_a.key() > 2)) 1015 1046 { 1016 commBreakMap.erase(it_a.key());1017 commBreakMap[0] = MARK_COMM_START;1047 newMap.erase(it_a.key()); 1048 newMap[0] = MARK_COMM_START; 1018 1049 } 1019 1050 1020 1051 1021 1052 // 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; 1025 1056 1026 it = blankCommBreakMap.begin();1027 for (; it != blankCommBreakMap.end(); ++it)1057 it = a.begin(); 1058 for (; it != a.end(); ++it) 1028 1059 { 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(); 1031 1062 } 1032 1063 1033 it = sceneCommBreakMap.begin();1034 for (; it != sceneCommBreakMap.end(); ++it)1064 it = b.begin(); 1065 for (; it != b.end(); ++it) 1035 1066 { 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(); 1038 1069 } 1039 1070 1040 if ((max_ blank< (framesProcessed - 2)) &&1041 (max_ scene> (framesProcessed - 2)))1071 if ((max_a < (framesProcessed - 2)) && 1072 (max_b > (framesProcessed - 2))) 1042 1073 { 1043 commBreakMap.erase(max_blank);1044 commBreakMap[framesProcessed] = MARK_COMM_END;1074 newMap.erase(max_a); 1075 newMap[framesProcessed] = MARK_COMM_END; 1045 1076 } 1046 1077 } 1047 1078 1048 if (( blankCommBreakMap.size() > 3) &&1049 ( sceneCommBreakMap.size() > 1))1079 if ((a.size() > 3) && 1080 (b.size() > 1)) 1050 1081 { 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; 1053 1084 long long b_start, b_end; 1054 1085 long long s_start, s_end; 1055 1086 1056 1087 b_start = b_end = -1; 1057 1088 s_start = s_end = -1; 1058 1089 1059 it_a = blankCommBreakMap.begin();1090 it_a = a.begin(); 1060 1091 it_a++; 1061 1092 it_b = it_a; 1062 1093 it_b++; 1063 while(it_b != blankCommBreakMap.end())1094 while(it_b != a.end()) 1064 1095 { 1065 1096 long long fdiff = it_b.key() - it_a.key(); 1066 1097 bool allTrue = false; … … 1072 1103 allTrue = true; 1073 1104 1074 1105 while ((f <= framesProcessed) && (f < it_b.key()) && (allTrue)) 1075 allTrue = FrameIsInBreakMap(f++, sceneCommBreakMap);1106 allTrue = FrameIsInBreakMap(f++, b); 1076 1107 } 1077 1108 1078 1109 if (allTrue) 1079 1110 { 1080 commBreakMap.erase(it_a.key());1081 commBreakMap.erase(it_b.key());1111 newMap.erase(it_a.key()); 1112 newMap.erase(it_b.key()); 1082 1113 } 1083 1114 1084 1115 it_a++; it_a++; 1085 1116 it_b++; 1086 if (it_b != blankCommBreakMap.end())1117 if (it_b != a.end()) 1087 1118 it_b++; 1088 1119 } 1089 1120 } 1121 1122 return newMap; 1090 1123 } 1091 1124 1092 1125 void ClassicCommDetector::UpdateFrameBlock(FrameBlock *fbp, … … 1139 1172 int aspect = COMM_ASPECT_NORMAL; 1140 1173 QString msg; 1141 1174 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; 1144 1177 1145 1178 commBreakMap.clear(); 1146 1179 … … 1816 1849 int frames = 0; 1817 1850 int commercials = 0; 1818 1851 int i, x; 1819 QMap<long long, int>::Iterator it;1852 comm_map_t::Iterator it; 1820 1853 1821 1854 blankCommMap.clear(); 1822 1855 … … 2020 2053 if (section_start >= 0) 2021 2054 sceneCommBreakMap[framesProcessed] = MARK_COMM_END; 2022 2055 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; 2026 2059 2027 2060 it = sceneCommBreakMap.begin(); 2028 2061 prev = it; … … 2059 2092 CondenseMarkMap(logoCommBreakMap, (int)(25 * fps), (int)(30 * fps)); 2060 2093 ConvertShowMapToCommMap(logoCommBreakMap); 2061 2094 2062 QMap<long long, int>::Iterator it;2095 comm_map_t::Iterator it; 2063 2096 VERBOSE(VB_COMMFLAG, "Logo Commercial Break Map" ); 2064 2097 for(it = logoCommBreakMap.begin(); it != logoCommBreakMap.end(); ++it) 2065 2098 VERBOSE(VB_COMMFLAG, QString(" %1:%2") … … 2068 2101 2069 2102 void ClassicCommDetector::MergeBlankCommList(void) 2070 2103 { 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; 2073 2106 QMap<long long, long long> tmpMap; 2074 2107 QMap<long long, long long>::Iterator tmpMap_it; 2075 2108 QMap<long long, long long>::Iterator tmpMap_prev; … … 2131 2164 } 2132 2165 } 2133 2166 2134 bool ClassicCommDetector::FrameIsInBreakMap( long long f,2135 QMap<long long, int> &breakMap)2167 bool ClassicCommDetector::FrameIsInBreakMap( 2168 long long f, const comm_map_t &breakMap) const 2136 2169 { 2137 2170 for(long long i = f; i < framesProcessed; i++) 2138 2171 if (breakMap.contains(i)) … … 2157 2190 return false; 2158 2191 } 2159 2192 2160 void ClassicCommDetector::DumpMap( QMap<long long, int>&map)2193 void ClassicCommDetector::DumpMap(comm_map_t &map) 2161 2194 { 2162 QMap<long long, int>::Iterator it;2195 comm_map_t::Iterator it; 2163 2196 QString msg; 2164 2197 2165 2198 VERBOSE(VB_COMMFLAG, "---------------------------------------------------"); … … 2181 2214 VERBOSE(VB_COMMFLAG, "---------------------------------------------------"); 2182 2215 } 2183 2216 2184 void ClassicCommDetector::CondenseMarkMap( QMap<long long, int>&map, int spacing,2217 void ClassicCommDetector::CondenseMarkMap(comm_map_t&map, int spacing, 2185 2218 int length) 2186 2219 { 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; 2190 2223 2191 2224 if (map.size() <= 2) 2192 2225 return; … … 2246 2279 .arg((long int)it.key()).arg(it.data())); 2247 2280 } 2248 2281 2249 void ClassicCommDetector::ConvertShowMapToCommMap( QMap<long long, int>&map)2282 void ClassicCommDetector::ConvertShowMapToCommMap(comm_map_t&map) 2250 2283 { 2251 QMap<long long, int>::Iterator it;2284 comm_map_t::Iterator it; 2252 2285 2253 2286 if (map.size() == 0) 2254 2287 return; … … 2375 2408 } 2376 2409 } 2377 2410 2378 void ClassicCommDetector::GetLogoCommBreakMap( QMap<long long, int>&map)2411 void ClassicCommDetector::GetLogoCommBreakMap(comm_map_t &map) 2379 2412 { 2380 2413 VERBOSE(VB_COMMFLAG, "CommDetect::GetLogoCommBreakMap()"); 2381 2414 … … 2426 2459 out << (*it).toString(i, verbose).ascii() << " "; 2427 2460 if (comm_breaks) 2428 2461 { 2429 QMap<long long, int>::const_iterator mit = comm_breaks->find(i);2462 comm_map_t::const_iterator mit = comm_breaks->find(i); 2430 2463 if (mit != comm_breaks->end()) 2431 2464 { 2432 2465 QString tmp = (verbose) ?