Ticket #4273: mythtv-4273.patch
File mythtv-4273.patch, 13.5 KB (added by , 16 years ago) |
---|
-
programs/mythtranscode/mpeg2fix.cpp
15 15 #include <getopt.h> 16 16 #include <stdint.h> 17 17 18 #include "../libmythtv/mpeg/mpegtables.h" 19 #include "../libs/libmythtv/mpeg/dvbdescriptors.h" 20 #include "../libs/libmythtv/vbilut.h" 21 18 22 #ifndef O_LARGEFILE 19 23 #define O_LARGEFILE 0 20 24 #endif … … 196 200 return (delta); 197 201 } 198 202 199 MPEG2fixup::MPEG2fixup(const char *inf, const char *outf, 203 MPEG2fixup::MPEG2fixup(const char *inf, const char *outf, const char *subtitlef, 200 204 QMap<long long, int> *deleteMap, 201 205 const char *fmt, int norp, int fixPTS, int maxf, 202 206 bool showprog, int otype, void (*update_func)(float), … … 204 208 { 205 209 displayFrame = new QPtrListIterator<MPEG2frame> (vFrame); 206 210 211 subtitle_id = -1; 212 ttd = NULL; 213 subtitlefile = subtitlef; 214 if (subtitlefile.length() > 0) 215 { 216 ttd = new TeletextDecoder(); 217 ttd_viewer = new SRTTypeTeletext(); 218 ttd->SetViewer(ttd_viewer); 219 } 220 207 221 infile = inf; 208 222 rx.outfile = outf; 209 223 rx.done = 0; … … 307 321 delete tmpFrame; 308 322 } 309 323 } 324 max_frames += sFrame.count(); 325 while (sFrame.count()) 326 { 327 tmpFrame = sFrame.first(); 328 sFrame.remove(); 329 delete tmpFrame; 330 } 310 331 max_frames += framePool.count(); 311 332 while (framePool.count()) 312 333 delete framePool.dequeue(); … … 766 787 .arg(inputFC->streams[i]->codec->codec_id)); 767 788 break; 768 789 790 case CODEC_TYPE_DATA: 791 if (subtitle_id == -1 && // see if subtitle not yet found 792 ttd != NULL) // and we want to decode the subtitles 793 { 794 if (inputFC->cur_pmt_sect) 795 { 796 const PESPacket pes = PESPacket::ViewData(inputFC->cur_pmt_sect); 797 const PSIPTable psip(pes); 798 const ProgramMapTable pmt(psip); 799 800 for (uint i = 0; i < pmt.StreamCount() && subtitle_id == -1; i++) 801 { 802 if (pmt.StreamType(i) != 6) 803 continue; 804 805 const desc_list_t desc_list = MPEGDescriptor::ParseOnlyInclude( 806 pmt.StreamInfo(i), pmt.StreamInfoLength(i), 807 DescriptorID::teletext); 808 809 for (uint j = 0; j < desc_list.size() && subtitle_id == -1; j++) 810 { 811 const TeletextDescriptor td(desc_list[j]); 812 for (uint k = 0; k < td.StreamCount() && subtitle_id == -1; k++) 813 { 814 int type = td.TeletextType(k); 815 if (type != 2) 816 continue; 817 818 subtitle_language = td.CanonicalLanguageKey(k); 819 subtitle_magazine = td.TeletextMagazineNum(k)?:8; 820 subtitle_pagenum = td.TeletextPageNum(k); 821 aubtitle_lang_idx = (subtitle_magazine << 8) | subtitle_pagenum; 822 823 VERBOSE(MPF_GENERAL, QString("Teletext caption #%1 is in the %2 language " 824 "on page %3 %4.") 825 .arg(k).arg(iso639_key_toName(subtitle_language)) 826 .arg(subtitle_magazine).arg(subtitle_pagenum)); 827 subtitle_id = i; 828 ttd_viewer->SetPage((subtitle_magazine << 8) | subtitle_pagenum, -1); 829 ttd_viewer->SetDisplaying(true); 830 } 831 } 832 } 833 } 834 } 835 break; 836 769 837 default: 770 838 VERBOSE(MPF_GENERAL, QString( 771 839 "Skipping unsupported codec %1 on stream %2") … … 1181 1249 } 1182 1250 1183 1251 if (pkt->stream_index == vid_id || 1252 pkt->stream_index == subtitle_id || 1184 1253 aFrame.contains(pkt->stream_index)) 1185 1254 done = 1; 1186 1255 else … … 1232 1301 av_free_packet(pkt); 1233 1302 return 0; 1234 1303 1304 case CODEC_TYPE_DATA: 1305 if (inputFC->streams[pkt->stream_index]->codec->codec_id == CODEC_ID_DVB_VBI) 1306 { 1307 sFrame.append(tmpFrame); 1308 } 1309 else if (inputFC->streams[pkt->stream_index]->codec->codec_id == CODEC_ID_MPEG2VBI) 1310 { 1311 //todo.... 1312 framePool.enqueue(tmpFrame); 1313 } 1314 else 1315 { 1316 framePool.enqueue(tmpFrame); 1317 } 1318 av_free_packet(pkt); 1319 return 0; 1320 1235 1321 default: 1236 1322 framePool.enqueue(tmpFrame); 1237 1323 av_free_packet(pkt); … … 1283 1369 if (vFrame.isEmpty()) 1284 1370 continue; 1285 1371 1372 while (!sFrame.isEmpty()) 1373 { 1374 framePool.enqueue(sFrame.first()); 1375 sFrame.removeFirst(); 1376 } 1377 1286 1378 for (QMap<int, QPtrList<MPEG2frame> >::iterator it = aFrame.begin(); 1287 1379 it != aFrame.end(); it++) 1288 1380 { … … 1761 1853 GetNbFields(curFrame))); 1762 1854 } 1763 1855 1856 void MPEG2fixup::ProcessDVBDataPacket() 1857 { 1858 const uint8_t *buf = sFrame.first()->pkt.data; 1859 const uint8_t *buf_end = sFrame.first()->pkt.data + sFrame.first()->pkt.size; 1860 1861 while (buf < buf_end) 1862 { 1863 if (*buf == 0x10) 1864 buf++; // skip 1865 1866 if (*buf == 0x02) 1867 { 1868 buf += 3; 1869 ttd->Decode(buf+1, VBI_DVB); 1870 } 1871 else if (*buf == 0x03) 1872 { 1873 buf += 3; 1874 ttd->Decode(buf+1, VBI_DVB_SUBTITLE); 1875 } 1876 else if (*buf == 0xff) 1877 { 1878 buf += 3; 1879 } 1880 else 1881 { 1882 VERBOSE(VB_VBI, QString("VBI: Unknown descriptor: %1").arg(*buf)); 1883 } 1884 1885 buf += 43; 1886 } 1887 } 1888 1764 1889 int MPEG2fixup::Start() 1765 1890 { 1766 1891 //NOTE: expectedvPTS/DTS are in units of SCR (300*PTS) to allow for better … … 1774 1899 int ret; 1775 1900 QMap<int, int> af_dlta_cnt, cutState; 1776 1901 // int i; 1777 1778 1902 AVPacket pkt, lastRealvPkt; 1779 1903 SRTOutputFile subtitleOutput(subtitlefile); 1904 1780 1905 if (! InitAV(infile.ascii(), format, 0)) 1781 1906 { 1782 1907 return (TRANSCODE_EXIT_UNKNOWN_ERROR); … … 1785 1910 if (! FindStart()) 1786 1911 return (TRANSCODE_EXIT_UNKNOWN_ERROR); 1787 1912 1913 if (ttd != NULL) 1914 { 1915 if (subtitleOutput.Open() == false) 1916 { 1917 return (TRANSCODE_EXIT_UNKNOWN_ERROR); 1918 } 1919 ttd_viewer->Set_Output_Device(&subtitleOutput); 1920 } 1921 1788 1922 av_init_packet(&pkt); 1789 1923 1790 1924 ptsIncrement = vFrame.first()->mpeg2_seq.frame_period / 300; … … 2187 2321 StoreSecondary(); 2188 2322 } 2189 2323 2324 if (ttd != NULL) 2325 { 2326 subtitleOutput.Set_DTS(expectedDTS / 300); // need to update the DTS value 2327 subtitleOutput.Set_Enable(discard == 0); // need to handle cut points 2328 while (sFrame.count() > 1) 2329 { 2330 ProcessDVBDataPacket(); // process the frames 2331 //here... to do. Need to get the data from the subtitle and save to a file. 2332 //or do it in the above procedure? 2333 framePool.enqueue(sFrame.first()); 2334 sFrame.remove(); 2335 } 2336 } 2337 2190 2338 for (QMap<int, QPtrList<MPEG2frame> >::iterator it = aFrame.begin(); 2191 2339 it != aFrame.end(); it++) 2192 2340 { … … 2194 2342 AVCodecContext *CC = getCodecContext(it.key()); 2195 2343 bool backwardsPTS = false; 2196 2344 2345 VERBOSE(MPF_PROCESS, QString("AFrame.key %1").arg(it.key())); 2346 2197 2347 while (af->count()) 2198 2348 { 2199 2349 // What to do if the CC is corrupt? -
programs/mythtranscode/mythtranscode.pro
10 10 QMAKE_CLEAN += $(TARGET) 11 11 12 12 # Input 13 SOURCES += main.cpp transcode.cpp mpeg2fix.cpp helper.c 13 SOURCES += main.cpp transcode.cpp mpeg2fix.cpp helper.c srttypeteletext.cpp 14 14 SOURCES += replex/element.c replex/mpg_common.c replex/multiplex.c \ 15 15 replex/pes.c replex/ringbuffer.c replex/ts.c 16 HEADERS += mpeg2fix.h transcodedefs.h 16 HEADERS += mpeg2fix.h transcodedefs.h srttypeteletext.h 17 17 HEADERS += replex/element.h replex/mpg_common.h replex/multiplex.h \ 18 18 replex/pes.h replex/ringbuffer.h replex/ts.h 19 19 -
programs/mythtranscode/main.cpp
57 57 cerr << "\t--video : Specifies that this is not a mythtv recording\n"; 58 58 cerr << "\t (must be used with --infile)\n"; 59 59 cerr << "\t--showprogress : Display status info to the stdout\n"; 60 cerr << "\t--subtitle or -t: Subtitle output file\n"; 60 61 cerr << "\t--verbose level or -v: Use '-v help' for level info\n"; 61 62 cerr << "\t--help or -h: Prints this help statement.\n"; 62 63 } 63 64 64 65 int main(int argc, char *argv[]) 65 66 { 66 QString chanid, starttime, infile, outfile ;67 QString chanid, starttime, infile, outfile, subtitlefile; 67 68 QString profilename = QString("autodetect"); 68 69 QString fifodir = NULL; 69 70 int jobID = -1; … … 161 162 return TRANSCODE_EXIT_INVALID_CMDLINE; 162 163 } 163 164 } 165 else if (!strcmp(a.argv()[argpos],"-t") || 166 !strcmp(a.argv()[argpos],"--subtitle")) 167 { 168 if(a.argc() > argpos) 169 { 170 subtitlefile = a.argv()[argpos + 1]; 171 ++argpos; 172 } 173 else 174 { 175 cerr << "Missing argument to -t/--subtitle option\n"; 176 usage(a.argv()[0]); 177 return TRANSCODE_EXIT_INVALID_CMDLINE; 178 } 179 } 164 180 else if (!strcmp(a.argv()[argpos],"-V")) 165 181 { 166 182 if (a.argc() > argpos) … … 509 525 check_func = &CheckJobQueue; 510 526 } 511 527 MPEG2fixup *m2f = new MPEG2fixup(infile.ascii(), outfile.ascii(), 528 subtitlefile.ascii(), 512 529 &deleteMap, NULL, false, false, 20, 513 530 showprogress, otype, update_func, 514 531 check_func); -
programs/mythtranscode/mpeg2fix.h
7 7 #include <qvaluelist.h> 8 8 #include <qstringlist.h> 9 9 #include <qdatetime.h> 10 #include <qfile.h> 10 11 11 12 #include "transcodedefs.h" 12 13 … … 24 25 #include "../libmythmpeg2/mpeg2.h" 25 26 } 26 27 28 #include "../libmythtv/teletextdecoder.h" 29 #include "srttypeteletext.h" 30 27 31 enum MPFDisplayMask { 28 32 MPF_IMPORTANT = 0x0001, 29 33 MPF_GENERAL = 0x0002, … … 131 135 class MPEG2fixup 132 136 { 133 137 public: 134 MPEG2fixup(const char *inf, const char *outf, 138 MPEG2fixup(const char *inf, const char *outf, const char *subtitlef, 135 139 QMap<long long, int> *deleteMap, const char *fmt, int norp, 136 140 int fixPTS, int maxf, bool showprog, int otype, 137 141 void (*update_func)(float) = NULL, int (*check_func)() = NULL); … … 154 158 MPEG2replex rx; 155 159 156 160 private: 161 void ProcessDVBDataPacket(); 157 162 int FindMPEG2Header(uint8_t *buf, int size, uint8_t code); 158 163 void InitReplex(); 159 164 void FrameInfo(MPEG2frame *f); … … 220 225 bool use_secondary; 221 226 222 227 QPtrList<MPEG2frame> vFrame; 228 QPtrList<MPEG2frame> sFrame; 223 229 QMap<int, QPtrList<MPEG2frame> > aFrame; 224 230 QPtrQueue<MPEG2frame> framePool; 225 231 QPtrQueue<MPEG2frame> unreadFrames; … … 239 245 int aud_stream_count; 240 246 int64_t ptsIncrement; 241 247 int64_t ptsOffset; //was initPTS 248 249 int subtitle_language; 250 int subtitle_magazine; 251 int subtitle_pagenum; 252 int aubtitle_lang_idx; 253 int subtitle_id; 242 254 243 255 int discard; 244 256 //control options 245 int no_repeat, fix_PTS, maxframes; 257 int no_repeat, fix_PTS, maxframes; 246 258 QString infile; 259 QString subtitlefile; 247 260 const char *format; 248 261 249 262 //complete? … … 257 270 int framenum; 258 271 int status_update_time; 259 272 uint64_t last_written_pos; 273 274 TeletextDecoder *ttd; 275 SRTTypeTeletext *ttd_viewer; 260 276 }; 261 277 262 278 #ifdef NO_MYTH