Ticket #692: Changeset7902-revert.diff
File Changeset7902-revert.diff, 25.2 KB (added by , 18 years ago) |
---|
-
libs/libmythtv/dbox2recorder.cpp
old new 527 527 // Inject PAT every 2000 TS packets. 528 528 if (pkts_until_pat == 0) 529 529 { 530 BufferedWrite(*(reinterpret_cast<const TSPacket*>(m_patPacket)));530 ringBuffer->Write(m_patPacket, 188); 531 531 pkts_until_pat = 2000; 532 532 } 533 533 else 534 534 pkts_until_pat--; 535 535 536 const void *data = stream->buffer + readIndex + tsPos; 537 const TSPacket *tspacket = reinterpret_cast<const TSPacket*>(data); 538 539 _buffer_packets = !FindKeyframes(tspacket); 540 541 BufferedWrite(*tspacket); 536 tpkt.InitHeader(stream->buffer+readIndex+tsPos); 537 tpkt.InitPayload(stream->buffer+readIndex+tsPos+4); 538 FindKeyframes(&tpkt); 542 539 540 ringBuffer->Write(stream->buffer+readIndex+tsPos, 188); 543 541 lastpacket = time(NULL); 544 readIndex += tsPos + TSPacket::SIZE;542 readIndex += tsPos + 188; 545 543 } 546 544 547 545 memcpy(stream->buffer, stream->buffer + readIndex, bufferSize - readIndex); -
libs/libmythtv/dbox2recorder.h
old new 101 101 time_t lastpacket; 102 102 int bufferSize; 103 103 stream_meta transportStream; 104 TSPacket tpkt; 104 105 int m_videoWidth; 105 106 int m_videoHeight; 106 107 QString m_videoFormat; -
libs/libmythtv/dtvrecorder.cpp
old new 45 45 _wait_for_keyframe(true), 46 46 // state 47 47 _recording(false), 48 _streamid_not_in_first_ts_packet(false), 48 49 _error(false), 49 50 // TS packet buffer 50 51 _buffer(0), _buffer_size(0), 51 // keyframe TS buffer52 _buffer_packets(false),53 52 // statistics 54 53 _frames_seen_count(0), _frames_written_count(0) 55 54 { … … 57 56 58 57 DTVRecorder::~DTVRecorder() 59 58 { 59 if (_streamid_not_in_first_ts_packet) 60 { 61 VERBOSE(VB_IMPORTANT, LOC + 62 "Saw keyframe stream_id which was not in first TS Packet."); 63 } 60 64 } 61 65 62 66 /** \fn DTVRecorder::SetOption(const QString&,int) … … 132 136 _last_gop_seen = 0; 133 137 _last_seq_seen = 0; 134 138 //_recording 139 //_streamid_not_in_first_ts_packet 135 140 _error = false; 136 141 //_buffer 137 142 //_buffer_size … … 141 146 _position_map_delta.clear(); 142 147 } 143 148 144 void DTVRecorder::BufferedWrite(const TSPacket &tspacket)145 {146 // delay until first GOP to avoid decoder crash on res change147 if (_wait_for_keyframe && !_keyframe_seen)148 return;149 150 // Do we have to buffer the packet for exact keyframe detection?151 if (_buffer_packets)152 {153 int idx = _payload_buffer.size();154 _payload_buffer.resize(idx + TSPacket::SIZE);155 memcpy(&_payload_buffer[idx], tspacket.data(), TSPacket::SIZE);156 return;157 }158 159 // We are free to write the packet, but if we have buffered packet[s]160 // we have to write them first...161 if (!_payload_buffer.empty())162 {163 ringBuffer->Write(&_payload_buffer[0], _payload_buffer.size());164 _payload_buffer.clear();165 }166 167 ringBuffer->Write(tspacket.data(), TSPacket::SIZE);168 }169 170 149 /** \fn DTVRecorder::FindKeyframes(const TSPacket* tspacket) 171 150 * \brief Locates the keyframes and saves them to the position map. 172 151 * … … 178 157 * streams, and if all else fails we just look for the picture 179 158 * start codes and call every 16th frame a keyframe. 180 159 * 181 * 160 * \startcode 182 161 * PES header format 183 162 * byte 0 byte 1 byte 2 byte 3 [byte 4 byte 5] 184 163 * 0x00 0x00 0x01 PESStreamID PES packet length 185 * 164 * \endcode 186 165 * 187 * \return Returns true if packet[s] should be output.188 166 */ 189 boolDTVRecorder::FindKeyframes(const TSPacket* tspacket)167 void DTVRecorder::FindKeyframes(const TSPacket* tspacket) 190 168 { 191 bool haveBufferedData = !_payload_buffer.empty(); 192 if (!tspacket->HasPayload()) // no payload to scan 193 return !haveBufferedData; 169 if (!tspacket->HasPayload()) 170 return; // no payload to scan 194 171 195 172 // if packet contains start of PES packet, start 196 173 // looking for first byte of MPEG start code (3 bytes 0 0 1) … … 199 176 _position_within_gop_header = (payloadStart) ? 200 177 0 : _position_within_gop_header; 201 178 202 // if this is not a payload start packet, and aren't waiting203 // for anything then just output this packet..204 if (!payloadStart && !haveBufferedData)205 return true;206 207 179 // Just make these local for efficiency reasons (gcc not so smart..) 208 180 const uint maxKFD = kMaxKeyFrameDistance; 209 181 const long long frameSeenNum = _frames_seen_count; … … 270 242 { 271 243 _last_keyframe_seen = frameSeenNum; 272 244 HandleKeyframe(); 273 return true; 274 } 275 else 276 { 277 uint idx = _payload_buffer.size(); 278 return (idx >= 10*TSPacket::SIZE); 245 246 if (!payloadStart && !_streamid_not_in_first_ts_packet) 247 { 248 VERBOSE(VB_IMPORTANT, LOC + 249 "Keyframe stream_id not in first TS Packet.\n" 250 "This is not an error, but MythTV may not always handle\n" 251 "this gracefully. If you would like it to, please inform\n" 252 "the mythtv developer mailing list of this message.\n"); 253 // If this happens in practice, it means we need to buffer 254 // all TS packets after the first payload start until 255 // we determine the PES stream ID; and then only write 256 // data to the ringbuffer after we determine the PES stream ID 257 // and call HandleKeyframe() if needed. 258 _streamid_not_in_first_ts_packet = true; 259 } 279 260 } 280 261 } 281 262 -
libs/libmythtv/dtvrecorder.h
old new 9 9 #ifndef DTVRECORDER_H 10 10 #define DTVRECORDER_H 11 11 12 #include <vector>13 using namespace std;14 15 12 #include "recorderbase.h" 16 13 17 14 class TSPacket; … … 47 44 void FinishRecording(void); 48 45 void ResetForNewFile(void); 49 46 50 boolFindKeyframes(const TSPacket* tspacket);47 void FindKeyframes(const TSPacket* tspacket); 51 48 void HandleKeyframe(); 52 49 void SavePositionMap(bool force); 53 50 54 void BufferedWrite(const TSPacket &tspacket);55 56 51 // file handle for stream 57 52 int _stream_fd; 58 53 … … 73 68 // state tracking variables 74 69 /// True iff recording is actually being performed 75 70 bool _recording; 71 /// True iff a frame PESStreamID seen outside first TS Packet 72 /// containing a PES Packet 73 bool _streamid_not_in_first_ts_packet; 76 74 /// True iff irrecoverable recording error detected 77 75 bool _error; 78 76 … … 80 78 unsigned char* _buffer; 81 79 int _buffer_size; 82 80 83 // keyframe finding buffer84 bool _buffer_packets;85 vector<unsigned char> _payload_buffer;86 87 81 // statistics 88 82 long long _frames_seen_count; 89 83 long long _frames_written_count; -
libs/libmythtv/dvbrecorder.cpp
old new 362 362 _payload_start_seen.clear(); 363 363 data_found = false; 364 364 _wait_for_keyframe = _wait_for_keyframe_option; 365 keyframe_found = false; 365 366 366 367 _ps_rec_audio_id = 0xC0; 367 368 _ps_rec_video_id = 0xE0; … … 769 770 } 770 771 771 772 if (_record_transport_stream_option) 772 ProcessTSPacket(*(reinterpret_cast<const TSPacket*>(pktbuf))); 773 { // handle TS recording 774 MythTimer t; 775 t.start(); 776 if (_videoPID[pid]) 777 { 778 // Check for keyframe 779 const TSPacket *pkt = 780 reinterpret_cast<const TSPacket*>(pktbuf); 781 FindKeyframes(pkt); 782 } 783 if (t.elapsed() > 10) 784 { 785 VERBOSE(VB_RECORD, LOC_WARN + 786 QString("Find keyframes took %1 ms!") 787 .arg(t.elapsed())); 788 } 789 790 // Sync recording start to first keyframe 791 if (_wait_for_keyframe && !_keyframe_seen) 792 continue; 793 if (!keyframe_found) 794 { 795 keyframe_found = true; 796 VERBOSE(VB_RECORD, QString("Found first keyframe")); 797 } 798 799 // Sync streams to the first Payload Unit Start Indicator 800 // _after_ first keyframe iff _wait_for_keyframe is true 801 if (!_payload_start_seen[pid]) 802 { 803 if ((pktbuf[1] & 0x40) == 0) 804 continue; // not payload start - drop packet 805 806 VERBOSE(VB_RECORD, QString("Found Payload Start for PID %1").arg(pid)); 807 _payload_start_seen[pid] = true; 808 } 809 810 t.start(); 811 LocalProcessDataTS(pktbuf, MPEG_TS_PKT_SIZE); 812 if (t.elapsed() > 10) 813 { 814 VERBOSE(VB_RECORD, LOC_WARN + 815 QString("TS packet write took %1 ms!") 816 .arg(t.elapsed())); 817 } 818 } 773 819 else 774 820 { // handle PS recording 775 821 ipack *ip = _ps_rec_pid_ipack[pid]; … … 800 846 } 801 847 } 802 848 803 // handle TS recording804 bool DVBRecorder::ProcessTSPacket(const TSPacket& tspacket)805 {806 // Check video pids for keyframes807 if (_videoPID[tspacket.PID()])808 _buffer_packets = !FindKeyframes(&tspacket);809 810 // If haven't seen a keyframe yet and we are supposed to wait for the811 // first keyframe before starting a recording, then return early...812 if (_wait_for_keyframe && !_keyframe_seen)813 return true;814 815 // Sync each stream to the first Payload Start816 // _after_ first keyframe iff _wait_for_keyframe is true817 if (!_payload_start_seen[tspacket.PID()])818 {819 if (!tspacket.PayloadStart())820 return true; // not payload start - drop packet821 VERBOSE(VB_RECORD, LOC + "Found first payload start for " +822 QString("PID 0x%1").arg(tspacket.PID(),0,16));823 _payload_start_seen[tspacket.PID()] = true;824 }825 826 // Write out PAT & PMT on occasion...827 int pktCnt = _payload_buffer.size() / TSPacket::SIZE;828 _ts_packets_until_psip_sync -= (pktCnt + 1);829 {830 QMutexLocker read_lock(&_pid_lock);831 if (_ts_packets_until_psip_sync <= 0 && _pat && _pmt)832 {833 BufferedWrite(*(reinterpret_cast<TSPacket*>(_pat->tsheader())));834 BufferedWrite(*(reinterpret_cast<TSPacket*>(_pmt->tsheader())));835 _ts_packets_until_psip_sync = TSPACKETS_BETWEEN_PSIP_SYNC;836 }837 }838 839 BufferedWrite(tspacket);840 841 return true;842 }843 844 849 #define SEQ_START 0x000001B3 845 850 #define GOP_START 0x000001B8 846 851 #define PICTURE_START 0x00000100 … … 921 926 ringBuffer->Write(buffer, len); 922 927 } 923 928 924 void DVBRecorder::LocalProcessDataTS( const unsigned char *buffer, uint len)929 void DVBRecorder::LocalProcessDataTS(unsigned char *buffer, int len) 925 930 { 931 QMutexLocker read_lock(&_pid_lock); 932 if (_ts_packets_until_psip_sync == 0) 933 { 934 if (_pat && _pmt) 935 { 936 ringBuffer->Write(_pat->tsheader()->data(), TSPacket::SIZE); 937 ringBuffer->Write(_pmt->tsheader()->data(), TSPacket::SIZE); 938 _ts_packets_until_psip_sync = TSPACKETS_BETWEEN_PSIP_SYNC; 939 } 940 } 941 else 942 _ts_packets_until_psip_sync--; 943 926 944 ringBuffer->Write(buffer,len); 927 945 } 928 946 -
libs/libmythtv/dvbrecorder.h
old new 24 24 25 25 class ProgramAssociationTable; 26 26 class ProgramMapTable; 27 class TSPacket;28 27 29 28 /** \class DVBRecorder 30 29 * \brief This is a specialization of DTVRecorder used to … … 67 66 void ReadFromDMX(void); 68 67 static void ProcessDataPS(unsigned char *buffer, int len, void *priv); 69 68 void LocalProcessDataPS(unsigned char *buffer, int len); 70 bool ProcessTSPacket(const TSPacket &tspacket); 71 void LocalProcessDataTS(const unsigned char *buffer, uint len); 69 void LocalProcessDataTS(unsigned char *buffer, int len); 72 70 73 71 void CloseFilters(void); 74 72 void OpenFilter(uint pid, ES_Type type, dmx_pes_type_t pes_type, … … 102 100 ProgramAssociationTable *_pat; 103 101 ProgramMapTable *_pmt; 104 102 uint _next_pmt_version; 105 int_ts_packets_until_psip_sync;103 uint _ts_packets_until_psip_sync; 106 104 QMap<uint,bool> _payload_start_seen; 107 105 QMap<uint,bool> _videoPID; 108 106 … … 129 127 130 128 // For debugging 131 129 bool data_found; ///< debugging variable used by transform.c 130 bool keyframe_found; 132 131 133 132 // Constants 134 133 static const int PMT_PID; -
libs/libmythtv/firewirerecorder.cpp
old new 15 15 // MythTV includes 16 16 #include "firewirerecorder.h" 17 17 #include "mythcontext.h" 18 #include "RingBuffer.h" 18 19 #include "tspacket.h" 19 20 #include "tv_rec.h" 20 21 21 22 // callback function for libiec61883 22 int read_tspacket (unsigned char *tspacket, int /*len*/, 23 uint dropped, void *callback_data) 24 { 25 FirewireRecorder *fw = (FirewireRecorder*) callback_data; 23 int read_tspacket (unsigned char *tspacket, int len, unsigned int dropped, void *callback_data) { 26 24 27 if (!fw)28 25 FirewireRecorder *fw = (FirewireRecorder*)callback_data; 26 if (!fw) return 0; 29 27 30 if (dropped) 31 { 32 VERBOSE(VB_RECORD, 33 QString("Firewire: %1 packet(s) dropped.").arg(dropped)); 34 } 35 36 if (SYNC_BYTE != tspacket[0]) 37 { 38 VERBOSE(VB_IMPORTANT, "Firewire: Got out of sync TS Packet"); 39 return 1; 40 } 28 if (dropped) { 29 VERBOSE(VB_GENERAL,QString("Firewire: %1 packet(s) dropped.").arg(dropped)); 30 } 41 31 42 fw->ProcessTSPacket(*(reinterpret_cast<TSPacket*>(tspacket))); 32 if (tspacket[0] == SYNC_BYTE) { 33 fw->ProcessTSPacket(tspacket,len); 34 } else { 35 VERBOSE(VB_GENERAL,QString("Firewire: out of sync mpeg2ts packet")); 36 } 43 37 44 return 1;38 return 1; 45 39 } 46 40 47 41 void FirewireRecorder::deleteLater(void) … … 189 183 _recording = false; 190 184 } 191 185 192 void FirewireRecorder::ProcessTSPacket(const TSPacket &tspacket) 193 { 186 void FirewireRecorder::ProcessTSPacket(unsigned char *tspacket, int len) { 187 tpkt.InitHeader(tspacket); 188 tpkt.InitPayload(tspacket+4); 189 FindKeyframes(&tpkt); 194 190 lastpacket = time(NULL); 195 _buffer_packets = !FindKeyframes(&tspacket); 196 BufferedWrite(tspacket); 191 ringBuffer->Write(tspacket,len); 197 192 } 198 193 199 194 void FirewireRecorder::SetOptionsFromProfile(RecordingProfile *profile, -
libs/libmythtv/firewirerecorder.h
old new 41 41 42 42 void StartRecording(void); 43 43 bool Open(void); 44 void ProcessTSPacket( const TSPacket &tspacket);44 void ProcessTSPacket(unsigned char *tspacket, int len); 45 45 void FirewireRecorder::SetOptionsFromProfile(RecordingProfile *profile, 46 46 const QString &videodev, 47 47 const QString &audiodev, … … 66 66 iec61883_mpeg2_t fwmpeg; 67 67 bool isopen; 68 68 time_t lastpacket; 69 TSPacket tpkt; 69 70 }; 70 71 71 72 #endif -
libs/libmythtv/hdtvrecorder.cpp
old new 110 110 #endif 111 111 112 112 HDTVRecorder::HDTVRecorder(TVRec *rec) 113 : DTVRecorder(rec, "HDTVRecorder"), 114 _atsc_stream_data(NULL), 115 _resync_count(0) 113 : DTVRecorder(rec, "HDTVRecorder"), _atsc_stream_data(0), _resync_count(0) 116 114 { 117 115 _atsc_stream_data = new ATSCStreamData(-1, DEFAULT_SUBCHANNEL); 118 116 connect(_atsc_stream_data, SIGNAL(UpdatePATSingleProgram( … … 689 687 return paused; 690 688 } 691 689 692 int HDTVRecorder::ResyncStream(const unsigned char *buffer, 693 uint curr_pos, uint len) 690 int HDTVRecorder::ResyncStream(unsigned char *buffer, int curr_pos, int len) 694 691 { 695 692 // Search for two sync bytes 188 bytes apart, 696 uint pos = curr_pos;697 uint nextpos = pos + TSPacket::SIZE;693 int pos = curr_pos; 694 int nextpos = pos + TSPacket::SIZE; 698 695 if (nextpos >= len) 699 696 return -1; // not enough bytes; caller should try again 700 697 701 while (buffer[pos] != SYNC_BYTE || buffer[nextpos] != SYNC_BYTE) 702 { 698 while (buffer[pos] != SYNC_BYTE || buffer[nextpos] != SYNC_BYTE) { 703 699 pos++; 704 700 nextpos++; 705 701 if (nextpos == len) … … 711 707 712 708 void HDTVRecorder::WritePAT(ProgramAssociationTable *pat) 713 709 { 714 if (!pat)715 return;716 717 710 int next = (pat->tsheader()->ContinuityCounter()+1)&0xf; 718 711 pat->tsheader()->SetContinuityCounter(next); 719 BufferedWrite(*(reinterpret_cast<TSPacket*>(pat->tsheader())));712 ringBuffer->Write(pat->tsheader()->data(), TSPacket::SIZE); 720 713 } 721 714 715 #if WHACK_A_BUG_VIDEO 716 static int WABV_base_pid = 0x100; 717 #define WABV_WAIT 60 718 static int WABV_wait_a_while = WABV_WAIT; 719 bool WABV_started = false; 720 #endif 721 722 #if WHACK_A_BUG_AUDIO 723 static int WABA_base_pid = 0x200; 724 #define WABA_WAIT 60 725 static int WABA_wait_a_while = WABA_WAIT; 726 bool WABA_started = false; 727 #endif 728 722 729 void HDTVRecorder::WritePMT(ProgramMapTable* pmt) 723 730 { 724 if (!pmt) 725 return; 731 if (pmt) { 732 int next = (pmt->tsheader()->ContinuityCounter()+1)&0xf; 733 pmt->tsheader()->SetContinuityCounter(next); 734 735 #if WHACK_A_BUG_VIDEO 736 WABV_wait_a_while--; 737 if (WABV_wait_a_while<=0) { 738 WABV_started = true; 739 WABV_wait_a_while = WABV_WAIT; 740 WABV_base_pid = (((WABV_base_pid-0x100)+1)%32)+0x100; 741 if (StreamID::MPEG2Video != StreamData()->PMT()->StreamType(0)) 742 { 743 VERBOSE(VB_IMPORTANT, "HDTVRecorder::WritePMT(): Error," 744 "Whack a Bug can not rewrite PMT, wrong stream type"); 745 } 746 else 747 { 748 VERBOSE(VB_IMPORTANT, QString("Whack a Bug: new video pid %1"). 749 arg(WABV_base_pid)); 750 // rewrite video pid 751 const uint old_video_pid=StreamData()->PMT()->StreamPID(0); 752 StreamData()->PMT()->SetStreamPID(0, WABV_base_pid); 753 if (StreamData()->PMT()->PCRPID() == old_video_pid) 754 StreamData()->PMT()->SetPCRPID(WABV_base_pid); 755 StreamData()->PMT()->SetCRC(StreamData()->PMT()->CalcCRC()); 756 VERBOSE(VB_IMPORTANT, StreamData()->PMT()->toString()); 757 } 758 } 759 #endif 760 #if WHACK_A_BUG_AUDIO 761 WABA_wait_a_while--; 762 if (WABA_wait_a_while<=0) { 763 WABA_started = true; 764 WABA_wait_a_while = WABA_WAIT; 765 WABA_base_pid = (((WABA_base_pid-0x200)+1)%32)+0x200; 766 VERBOSE(VB_IMPORTANT, QString("Whack a Bug: new audio BASE pid %1").arg(WABA_base_pid)); 767 // rewrite audio pids 768 for (uint i=0; i<StreamData()->PMT()->StreamCount(); i++) { 769 if (StreamID::MPEG2Audio == StreamData()->PMT()->StreamType(i) || 770 StreamID::MPEG2Audio == StreamData()->PMT()->StreamType(i)) { 771 const uint old_audio_pid = StreamData()->PMT()->StreamPID(i); 772 const uint new_audio_pid = WABA_base_pid + old_audio_pid; 773 StreamData()->PMT()->SetStreamPID(i, new_audio_pid); 774 if (StreamData()->PMT()->PCRPID() == old_audio_pid) 775 StreamData()->PMT()->SetPCRPID(new_audio_pid); 776 StreamData()->PMT()->SetCRC(StreamData()->PMT()->CalcCRC()); 777 VERBOSE(VB_IMPORTANT, StreamData()->PMT()->toString()); 778 } 779 } 780 } 781 #endif 726 782 727 int next = (pmt->tsheader()->ContinuityCounter()+1)&0xf; 728 pmt->tsheader()->SetContinuityCounter(next); 729 BufferedWrite(*(reinterpret_cast<TSPacket*>(pmt->tsheader()))); 783 ringBuffer->Write(pmt->tsheader()->data(), TSPacket::SIZE); 784 } 730 785 } 731 786 732 787 /** \fn HDTVRecorder::ProcessMGT(const MasterGuideTable*) … … 791 846 } 792 847 } 793 848 794 bool HDTVRecorder::ProcessTSPacket(const TSPacket &tspacket) 849 void HDTVRecorder::HandleVideo(const TSPacket* tspacket) 850 { 851 FindKeyframes(tspacket); 852 // decoder needs video, of course (just this PID) 853 // delay until first GOP to avoid decoder crash on res change 854 if (_wait_for_keyframe && !_keyframe_seen) 855 return; 856 857 #if WHACK_A_BUG_VIDEO 858 if (WABV_started) 859 ((TSPacket*)(tspacket))->SetPID(WABV_base_pid); 860 #endif 861 862 ringBuffer->Write(tspacket->data(), TSPacket::SIZE); 863 } 864 865 void HDTVRecorder::HandleAudio(const TSPacket* tspacket) 866 { 867 // decoder needs audio, of course (just this PID) 868 if (_wait_for_keyframe && !_keyframe_seen) 869 return; 870 871 #if WHACK_A_BUG_AUDIO 872 if (WABA_started) 873 ((TSPacket*)(tspacket))->SetPID(WABA_base_pid+tspacket->PID()); 874 #endif 875 876 ringBuffer->Write(tspacket->data(), TSPacket::SIZE); 877 } 878 879 bool HDTVRecorder::ProcessTSPacket(const TSPacket& tspacket) 795 880 { 796 881 bool ok = !tspacket.TransportError(); 797 882 if (ok && !tspacket.ScramplingControl()) … … 803 888 const unsigned int lpid = tspacket.PID(); 804 889 // Pass or reject frames based on PID, and parse info from them 805 890 if (lpid == StreamData()->VideoPIDSingleProgram()) 806 { 807 _buffer_packets = !FindKeyframes(&tspacket); 808 BufferedWrite(tspacket); 809 } 891 HandleVideo(&tspacket); 810 892 else if (StreamData()->IsAudioPID(lpid)) 811 BufferedWrite(tspacket);893 HandleAudio(&tspacket); 812 894 else if (StreamData()->IsListeningPID(lpid)) 813 895 StreamData()->HandleTSTables(&tspacket); 814 896 else if (StreamData()->IsWritingPID(lpid)) 815 BufferedWrite(tspacket);897 ringBuffer->Write(tspacket.data(), TSPacket::SIZE); 816 898 else if (StreamData()->VersionMGT()>=0) 817 899 _ts_stats.IncrPIDCount(lpid); 818 900 } … … 820 902 return ok; 821 903 } 822 904 823 int HDTVRecorder::ProcessData( const unsigned char *buffer, uint len)905 int HDTVRecorder::ProcessData(unsigned char *buffer, int len) 824 906 { 825 uint pos = 0;907 int pos = 0; 826 908 827 909 while (pos + 187 < len) // while we have a whole packet left 828 910 { … … 843 925 } 844 926 845 927 const TSPacket *pkt = reinterpret_cast<const TSPacket*>(&buffer[pos]); 846 if (ProcessTSPacket(*pkt)) 847 { 928 if (ProcessTSPacket(*pkt)) { 848 929 pos += TSPacket::SIZE; // Advance to next TS packet 849 930 _ts_stats.IncrTSPacketCount(); 850 931 if (0 == _ts_stats.TSPacketCount()%1000000) 851 932 VERBOSE(VB_RECORD, _ts_stats.toString()); 852 } 853 else 854 { // Let it resync in case of dropped bytes 855 pos++; 856 } 933 } else // Let it resync in case of dropped bytes 934 buffer[pos] = SYNC_BYTE+1; 857 935 } 858 936 859 937 return len - pos; -
libs/libmythtv/hdtvrecorder.h
old new 62 62 63 63 private: 64 64 void TeardownAll(void); 65 int ProcessData(unsigned char *buffer, int len); 66 bool ProcessTSPacket(const TSPacket& tspacket); 67 void HandleVideo(const TSPacket* tspacket); 68 void HandleAudio(const TSPacket* tspacket); 65 69 66 int ProcessData (const unsigned char *buffer, uint len); 67 int ResyncStream (const unsigned char *buffer, uint pos, uint len); 68 bool ProcessTSPacket(const TSPacket &tspacket); 70 int ResyncStream(unsigned char *buffer, int curr_pos, int len); 69 71 70 72 static void *boot_ringbuffer(void *); 71 73 void fill_ringbuffer(void);