Ticket #6240: 6240-v1.patch
File 6240-v1.patch, 7.8 KB (added by , 16 years ago) |
---|
-
libs/libmythtv/xine_demux_sputext.cpp
32 32 #include "config.h" 33 33 #endif 34 34 35 #include <ctype.h> 35 36 #include <stdlib.h> 36 37 #include <stdio.h> 37 38 #include <unistd.h> … … 97 98 off_t nread = 0; 98 99 char *s; 99 100 int linelen; 100 101 if ((len - demuxstr->buflen) > 512) { 102 if((nread = fread( 103 &demuxstr->buf[demuxstr->buflen], 1, 104 len - demuxstr->buflen, demuxstr->file_ptr)) < 0) { 101 102 // Since our RemoteFile code sleeps 200ms whenever we get back less data 103 // than requested, but this code just keeps trying to read until it gets 104 // an error back, we check for empty reads so that we can stop reading 105 // when there is no more data to read 106 if (demuxstr->emptyReads == 0 && (len - demuxstr->buflen) > 512) { 107 nread = demuxstr->rbuffer->Read( 108 &demuxstr->buf[demuxstr->buflen], len - demuxstr->buflen); 109 if (nread < 0) { 105 110 printf("read failed.\n"); 106 111 return NULL; 107 112 } 108 113 } 109 114 115 if (!nread) 116 demuxstr->emptyReads++; 117 110 118 demuxstr->buflen += nread; 111 119 demuxstr->buf[demuxstr->buflen] = '\0'; 112 120 … … 1099 1107 }; 1100 1108 1101 1109 /* Rewind (sub_autodetect() needs to read input from the beginning) */ 1102 if( fseek(demuxstr->file_ptr,0, SEEK_SET) == -1) {1110 if(demuxstr->rbuffer->Seek(0, SEEK_SET) == -1) { 1103 1111 printf("seek failed.\n"); 1104 1112 return NULL; 1105 1113 } 1106 1114 demuxstr->buflen = 0; 1115 demuxstr->emptyReads = 0; 1107 1116 1108 1117 demuxstr->format=sub_autodetect (demuxstr); 1109 1118 if (demuxstr->format==FORMAT_UNKNOWN) { … … 1113 1122 /*printf("Detected subtitle file format: %d\n", demuxstr->format);*/ 1114 1123 1115 1124 /* Rewind */ 1116 if( fseek(demuxstr->file_ptr,0, SEEK_SET) == -1) {1125 if(demuxstr->rbuffer->Seek(0, SEEK_SET) == -1) { 1117 1126 printf("seek failed.\n"); 1118 1127 return NULL; 1119 1128 } 1120 1129 demuxstr->buflen = 0; 1130 demuxstr->emptyReads = 0; 1121 1131 1122 1132 demuxstr->num=0;n_max=32; 1123 1133 first = (subtitle_t *) malloc(n_max*sizeof(subtitle_t)); -
libs/libmythtv/playercontext.cpp
477 477 _nvp->SetNoAudio(); 478 478 else 479 479 { 480 // FIXME: This causes startup to take *forever* 481 // _nvp->LoadExternalSubtitles(buffer->GetFilename()); 480 QString subfn = ComputeExternalSubtitleFileName(buffer->GetFilename()); 481 if (!subfn.isEmpty()) 482 _nvp->LoadExternalSubtitles(subfn); 482 483 } 483 484 484 485 if ((embedwinid > 0) && embedbounds) … … 550 551 return StartDecoderThread(maxWait); 551 552 } 552 553 554 #include <QDir> 555 #include "storagegroup.h" 556 QString PlayerContext::ComputeExternalSubtitleFileName( 557 const QString &videoFile) const 558 { 559 if (videoFile.isEmpty()) 560 return QString::null; 561 562 QString fileName = videoFile; 563 QString dirName = "."; 564 565 int dirPos = videoFile.lastIndexOf(QChar('/')); 566 if (dirPos > 0) 567 { 568 fileName = videoFile.mid(dirPos + 1); 569 dirName = videoFile.left(dirPos); 570 } 571 572 QString baseName = fileName; 573 int suffixPos = fileName.lastIndexOf(QChar('.')); 574 if (suffixPos > 0) 575 baseName = fileName.left(suffixPos); 576 577 // Try to find files with the same base name, but ending with 578 // '.srt', '.sub', or '.txt' 579 QStringList ext; 580 ext += ".srt"; 581 ext += ".sub"; 582 ext += ".txt"; 583 584 if (dirName.startsWith("myth://")) 585 { 586 QString sgroup = ""; 587 if (dirName.indexOf('@') > -1) 588 sgroup = dirName.mid(7, dirName.indexOf('@', 7) - 7); 589 590 StorageGroup sg(sgroup); 591 QStringList::const_iterator it = ext.begin(); 592 for (; it != ext.end(); ++it) 593 { 594 if (sg.FileExists(baseName + *it)) 595 return dirName + "/" + baseName + *it; 596 } 597 598 return QString::null; 599 } 600 601 QStringList el; 602 { 603 // The dir listing does not work if the filename has the 604 // following chars "[]()" so we convert them to the wildcard '?' 605 const QString findBaseName = baseName 606 .replace("[", "?") 607 .replace("]", "?") 608 .replace("(", "?") 609 .replace(")", "?"); 610 611 QStringList::const_iterator eit = ext.begin(); 612 for (; eit != ext.end(); eit++) 613 el += findBaseName + *eit; 614 } 615 616 // Some Qt versions do not accept paths in the search string of 617 // entryList() so we have to set the dir first 618 QDir dir; 619 dir.setPath(dirName); 620 621 const QStringList candidates = dir.entryList(el); 622 623 QStringList::const_iterator cit = candidates.begin(); 624 QStringList::const_iterator eit = ext.begin(); 625 for (; (cit != candidates.end()) && (eit != ext.end()); ++cit, ++eit) 626 { 627 QFileInfo fi(dirName + "/" + *cit); 628 if (fi.exists() && (fi.size() > 0)) 629 return dirName + "/" + baseName + *eit; 630 } 631 632 return QString::null; 633 } 634 553 635 /** \fn PlayerContext::StartDecoderThread(int) 554 636 * \brief Starts player, must be called after StartRecorder(). 555 637 * \param maxWait How long to wait for NuppelVideoPlayer to start playing. -
libs/libmythtv/xine_demux_sputext.h
1 1 #ifndef XINE_DEMUX_SPUTEXT_H 2 2 #define XINE_DEMUX_SPUTEXT_H 3 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 4 #include "RingBuffer.h" 7 5 8 #include <ctype.h>9 #include <stdio.h>10 11 6 #define SUB_BUFSIZE 1024 12 7 #define SUB_MAX_TEXT 5 13 8 #define MAX_TIMEOUT 4 … … 26 21 27 22 typedef struct { 28 23 29 FILE* file_ptr;24 RingBuffer* rbuffer; 30 25 31 26 int status; 32 27 33 28 char buf[SUB_BUFSIZE]; 34 29 off_t buflen; 30 off_t emptyReads; 35 31 36 32 float mpsub_position; 37 33 … … 48 44 49 45 subtitle_t *sub_read_file (demux_sputext_t*); 50 46 51 #ifdef __cplusplus52 }53 47 #endif 54 55 #endif -
libs/libmythtv/playercontext.h
134 134 bool IsValidLiveTV(void) const 135 135 { return nvp && tvchain && recorder && buffer; } 136 136 137 private: 138 QString ComputeExternalSubtitleFileName(const QString &videoFile) const; 139 137 140 public: 138 141 QString recUsage; 139 142 NuppelVideoPlayer *nvp; -
libs/libmythtv/textsubtitleparser.cpp
11 11 #include <qtextcodec.h> 12 12 13 13 #include "mythcontext.h" 14 #include "RingBuffer.h" 14 15 15 16 using std::lower_bound; 16 17 … … 110 111 bool TextSubtitleParser::LoadSubtitles(QString fileName, TextSubtitles &target) 111 112 { 112 113 demux_sputext_t sub_data; 113 sub_data. file_ptr = fopen(fileName.toLocal8Bit().constData(), "r");114 sub_data.rbuffer = new RingBuffer(fileName, 0, false); 114 115 115 if (!sub_data. file_ptr)116 if (!sub_data.rbuffer) 116 117 return false; 117 118 118 119 subtitle_t *loaded_subs = sub_read_file(&sub_data); 119 120 if (!loaded_subs) 120 121 { 121 fclose(sub_data.file_ptr);122 delete sub_data.rbuffer; 122 123 return false; 123 124 } 124 125 … … 131 132 if (!textCodec) 132 133 textCodec = QTextCodec::codecForName("utf-8"); 133 134 if (!textCodec) 135 { 136 delete sub_data.rbuffer; 134 137 return false; 138 } 135 139 136 140 QTextDecoder *dec = textCodec->makeDecoder(); 137 141 … … 162 166 // textCodec object is managed by Qt, do not delete... 163 167 164 168 free(loaded_subs); 165 fclose(sub_data.file_ptr);166 169 170 delete sub_data.rbuffer; 167 171 return true; 168 172 }