Ticket #4622: zero_copy_mpeg_streams.diff
File zero_copy_mpeg_streams.diff, 19.9 KB (added by , 16 years ago) |
---|
-
libs/libmythtv/dvbrecorder.cpp
181 181 { 182 182 uint next_cc = (pat->tsheader()->ContinuityCounter()+1)&0xf; 183 183 pat->tsheader()->SetContinuityCounter(next_cc); 184 BufferedWrite( *(reinterpret_cast<TSPacket*>(pat->tsheader())));184 BufferedWrite(reinterpret_cast<TSPacket*>(pat->tsheader())); 185 185 } 186 186 187 187 uint posB[2] = { ringBuffer->GetWritePosition(), _payload_buffer.size() }; … … 221 221 uint posA[2] = { ringBuffer->GetWritePosition(), _payload_buffer.size() }; 222 222 223 223 for (uint i = 0; i < size ; i += TSPacket::SIZE) 224 BufferedWrite( *(reinterpret_cast<TSPacket*>(&buf[i])));224 BufferedWrite(reinterpret_cast<TSPacket*>(&buf[i])); 225 225 226 226 uint posB[2] = { ringBuffer->GetWritePosition(), _payload_buffer.size() }; 227 227 … … 475 475 return paused; 476 476 } 477 477 478 bool DVBRecorder::ProcessVideoTSPacket(const TSPacket &tspacket)478 bool DVBRecorder::ProcessVideoTSPacket(const TSPacket *tspacket) 479 479 { 480 uint streamType = _stream_id[tspacket .PID()];480 uint streamType = _stream_id[tspacket->PID()]; 481 481 482 482 // Check for keyframes and count frames 483 483 if (streamType == StreamID::H264Video) 484 484 { 485 _buffer_packets = !FindH264Keyframes( &tspacket);485 _buffer_packets = !FindH264Keyframes(tspacket); 486 486 if (!_seen_sps) 487 487 return true; 488 488 } 489 489 else 490 490 { 491 _buffer_packets = !FindMPEG2Keyframes( &tspacket);491 _buffer_packets = !FindMPEG2Keyframes(tspacket); 492 492 } 493 493 494 494 return ProcessTSPacket(tspacket); 495 495 } 496 496 497 bool DVBRecorder::ProcessAudioTSPacket(const TSPacket &tspacket)497 bool DVBRecorder::ProcessAudioTSPacket(const TSPacket *tspacket) 498 498 { 499 _buffer_packets = !FindAudioKeyframes( &tspacket);499 _buffer_packets = !FindAudioKeyframes(tspacket); 500 500 return ProcessTSPacket(tspacket); 501 501 } 502 502 503 bool DVBRecorder::ProcessTSPacket(const TSPacket &tspacket)503 bool DVBRecorder::ProcessTSPacket(const TSPacket *tspacket) 504 504 { 505 const uint pid = tspacket .PID();505 const uint pid = tspacket->PID(); 506 506 507 507 // Check continuity counter 508 if ((pid != 0x1fff) && !CheckCC(pid, tspacket .ContinuityCounter()))508 if ((pid != 0x1fff) && !CheckCC(pid, tspacket->ContinuityCounter())) 509 509 { 510 510 VERBOSE(VB_RECORD, LOC + 511 511 QString("PID 0x%1 discontinuity detected").arg(pid,0,16)); … … 518 518 519 519 // Sync streams to the first Payload Unit Start Indicator 520 520 // _after_ first keyframe iff _wait_for_keyframe_option is true 521 if (!(_pid_status[pid] & kPayloadStartSeen) && tspacket .HasPayload())521 if (!(_pid_status[pid] & kPayloadStartSeen) && tspacket->HasPayload()) 522 522 { 523 if (!tspacket .PayloadStart())523 if (!tspacket->PayloadStart()) 524 524 return true; // not payload start - drop packet 525 525 526 526 VERBOSE(VB_RECORD, -
libs/libmythtv/dvbrecorder.h
84 84 void HandleSDT(uint /*tsid*/, const ServiceDescriptionTable*) {} 85 85 86 86 // TSPacketListener 87 bool ProcessTSPacket(const TSPacket &tspacket);87 bool ProcessTSPacket(const TSPacket* tspacket); 88 88 89 89 // TSPacketListenerAV 90 bool ProcessVideoTSPacket(const TSPacket &tspacket);91 bool ProcessAudioTSPacket(const TSPacket &tspacket);90 bool ProcessVideoTSPacket(const TSPacket* tspacket); 91 bool ProcessAudioTSPacket(const TSPacket* tspacket); 92 92 93 93 void SetStreamData(MPEGStreamData*); 94 94 MPEGStreamData* GetStreamData(void) { return _stream_data; } -
libs/libmythtv/hdhrrecorder.h
64 64 bool AdjustEITPIDs(void); 65 65 66 66 void ProcessTSData(const unsigned char *buffer, int len); 67 bool ProcessTSPacket(const TSPacket &tspacket);67 bool ProcessTSPacket(const TSPacket* tspacket); 68 68 void TeardownAll(void); 69 69 70 70 private: -
libs/libmythtv/hdhrrecorder.cpp
153 153 return; 154 154 } 155 155 156 const TSPacket *tspacket = reinterpret_cast<const TSPacket*>(data); 157 ProcessTSPacket(*tspacket); 156 ProcessTSPacket(reinterpret_cast<const TSPacket*>(data)); 158 157 159 158 data += 188; 160 159 } … … 242 241 243 242 int next = (pat->tsheader()->ContinuityCounter()+1)&0xf; 244 243 pat->tsheader()->SetContinuityCounter(next); 245 BufferedWrite( *(reinterpret_cast<TSPacket*>(pat->tsheader())));244 BufferedWrite(reinterpret_cast<TSPacket*>(pat->tsheader())); 246 245 } 247 246 248 247 void HDHRRecorder::HandleSingleProgramPMT(ProgramMapTable *pmt) … … 252 251 253 252 int next = (pmt->tsheader()->ContinuityCounter()+1)&0xf; 254 253 pmt->tsheader()->SetContinuityCounter(next); 255 BufferedWrite( *(reinterpret_cast<TSPacket*>(pmt->tsheader())));254 BufferedWrite(reinterpret_cast<TSPacket*>(pmt->tsheader())); 256 255 } 257 256 258 257 /** \fn HDHRRecorder::HandleMGT(const MasterGuideTable*) … … 272 271 } 273 272 */ 274 273 275 bool HDHRRecorder::ProcessTSPacket(const TSPacket &tspacket)274 bool HDHRRecorder::ProcessTSPacket(const TSPacket* tspacket) 276 275 { 277 bool ok = !tspacket .TransportError();278 if (ok && !tspacket .ScramplingControl())276 bool ok = !tspacket->TransportError(); 277 if (ok && !tspacket->ScramplingControl()) 279 278 { 280 if (tspacket .HasAdaptationField())281 GetStreamData()->HandleAdaptationFieldControl( &tspacket);282 if (tspacket .HasPayload())279 if (tspacket->HasAdaptationField()) 280 GetStreamData()->HandleAdaptationFieldControl(tspacket); 281 if (tspacket->HasPayload()) 283 282 { 284 const unsigned int lpid = tspacket .PID();283 const unsigned int lpid = tspacket->PID(); 285 284 286 285 if ((GetStreamData()->VideoPIDSingleProgram() > 0x1fff) && 287 286 _wait_for_keyframe_option) … … 293 292 if (lpid == GetStreamData()->VideoPIDSingleProgram()) 294 293 { 295 294 //cerr<<"v"; 296 _buffer_packets = !FindMPEG2Keyframes( &tspacket);295 _buffer_packets = !FindMPEG2Keyframes(tspacket); 297 296 BufferedWrite(tspacket); 298 297 } 299 298 else if (GetStreamData()->IsAudioPID(lpid)) 300 299 { 301 300 //cerr<<"a"; 302 _buffer_packets = !FindAudioKeyframes( &tspacket);301 _buffer_packets = !FindAudioKeyframes(tspacket); 303 302 BufferedWrite(tspacket); 304 303 } 305 304 else if (GetStreamData()->IsListeningPID(lpid)) 306 305 { 307 306 //cerr<<"t"; 308 GetStreamData()->HandleTSTables( &tspacket);307 GetStreamData()->HandleTSTables(tspacket); 309 308 } 310 309 else if (GetStreamData()->IsWritingPID(lpid)) 311 310 BufferedWrite(tspacket); -
libs/libmythtv/dtvrecorder.h
53 53 54 54 void HandleKeyframe(); 55 55 56 void BufferedWrite(const TSPacket &tspacket);56 void BufferedWrite(const TSPacket *tspacket); 57 57 58 58 // MPEG "audio only" support 59 59 bool FindAudioKeyframes(const TSPacket *tspacket); -
libs/libmythtv/firewirerecorder.cpp
90 90 if (bufsz) 91 91 buffer.clear(); 92 92 93 ProcessTSPacket( *(reinterpret_cast<const TSPacket*>(data)));93 ProcessTSPacket(reinterpret_cast<const TSPacket*>(data)); 94 94 return; 95 95 } 96 96 … … 112 112 113 113 while (sync_at + TSPacket::SIZE < bufsz) 114 114 { 115 ProcessTSPacket( *(reinterpret_cast<const TSPacket*>(116 &buffer[0] + sync_at)) );115 ProcessTSPacket(reinterpret_cast<const TSPacket*>( 116 &buffer[0] + sync_at)); 117 117 118 118 sync_at += TSPacket::SIZE; 119 119 } … … 123 123 return; 124 124 } 125 125 126 void FirewireRecorder::ProcessTSPacket(const TSPacket &tspacket)126 void FirewireRecorder::ProcessTSPacket(const TSPacket *tspacket) 127 127 { 128 if (tspacket .TransportError())128 if (tspacket->TransportError()) 129 129 return; 130 130 131 if (tspacket .ScramplingControl())131 if (tspacket->ScramplingControl()) 132 132 return; 133 133 134 if (tspacket .HasAdaptationField())135 GetStreamData()->HandleAdaptationFieldControl( &tspacket);134 if (tspacket->HasAdaptationField()) 135 GetStreamData()->HandleAdaptationFieldControl(tspacket); 136 136 137 if (tspacket .HasPayload())137 if (tspacket->HasPayload()) 138 138 { 139 const unsigned int lpid = tspacket .PID();139 const unsigned int lpid = tspacket->PID(); 140 140 141 141 // Pass or reject packets based on PID, and parse info from them 142 142 if (lpid == GetStreamData()->VideoPIDSingleProgram()) 143 143 { 144 _buffer_packets = !FindMPEG2Keyframes( &tspacket);144 _buffer_packets = !FindMPEG2Keyframes(tspacket); 145 145 BufferedWrite(tspacket); 146 146 } 147 147 else if (GetStreamData()->IsAudioPID(lpid)) 148 148 { 149 _buffer_packets = !FindAudioKeyframes( &tspacket);149 _buffer_packets = !FindAudioKeyframes(tspacket); 150 150 BufferedWrite(tspacket); 151 151 } 152 152 else if (GetStreamData()->IsListeningPID(lpid)) 153 GetStreamData()->HandleTSTables( &tspacket);153 GetStreamData()->HandleTSTables(tspacket); 154 154 else if (GetStreamData()->IsWritingPID(lpid)) 155 155 BufferedWrite(tspacket); 156 156 } … … 218 218 219 219 int next = (pat->tsheader()->ContinuityCounter()+1)&0xf; 220 220 pat->tsheader()->SetContinuityCounter(next); 221 BufferedWrite( *(reinterpret_cast<const TSPacket*>(pat->tsheader())));221 BufferedWrite(reinterpret_cast<const TSPacket*>(pat->tsheader())); 222 222 } 223 223 224 224 void FirewireRecorder::HandleSingleProgramPMT(ProgramMapTable *pmt) … … 228 228 229 229 int next = (pmt->tsheader()->ContinuityCounter()+1)&0xf; 230 230 pmt->tsheader()->SetContinuityCounter(next); 231 BufferedWrite( *(reinterpret_cast<const TSPacket*>(pmt->tsheader())));231 BufferedWrite(reinterpret_cast<const TSPacket*>(pmt->tsheader())); 232 232 } -
libs/libmythtv/dtvrecorder.cpp
175 175 curRecording->ClearPositionMap(MARK_GOP_BYFRAME); 176 176 } 177 177 178 void DTVRecorder::BufferedWrite(const TSPacket &tspacket)178 void DTVRecorder::BufferedWrite(const TSPacket *tspacket) 179 179 { 180 180 // delay until first GOP to avoid decoder crash on res change 181 181 if (_wait_for_keyframe_option && _first_keyframe<0) … … 186 186 { 187 187 int idx = _payload_buffer.size(); 188 188 _payload_buffer.resize(idx + TSPacket::SIZE); 189 memcpy(&_payload_buffer[idx], tspacket .data(), TSPacket::SIZE);189 memcpy(&_payload_buffer[idx], tspacket->data(), TSPacket::SIZE); 190 190 return; 191 191 } 192 192 … … 200 200 } 201 201 202 202 if (ringBuffer) 203 ringBuffer->Write(tspacket .data(), TSPacket::SIZE);203 ringBuffer->Write(tspacket->data(), TSPacket::SIZE); 204 204 } 205 205 206 206 /** \fn DTVRecorder::FindMPEG2Keyframes(const TSPacket* tspacket) -
libs/libmythtv/firewirerecorder.h
43 43 bool PauseAndWait(int timeout = 100); 44 44 45 45 void AddData(const unsigned char *data, uint dataSize); 46 void ProcessTSPacket(const TSPacket &tspacket);46 void ProcessTSPacket(const TSPacket *tspacket); 47 47 48 48 // Sets 49 49 void SetOptionsFromProfile(RecordingProfile *profile, -
libs/libmythtv/mpeg/mpegstreamdata.cpp
935 935 } 936 936 937 937 const TSPacket *pkt = reinterpret_cast<const TSPacket*>(&buffer[pos]); 938 if (ProcessTSPacket( *pkt))938 if (ProcessTSPacket(pkt)) 939 939 pos += TSPacket::SIZE; // Advance to next TS packet 940 940 else // Let it resync in case of dropped bytes 941 941 buffer[pos] = SYNC_BYTE + 1; … … 944 944 return len - pos; 945 945 } 946 946 947 bool MPEGStreamData::ProcessTSPacket(const TSPacket &tspacket)947 bool MPEGStreamData::ProcessTSPacket(const TSPacket* tspacket) 948 948 { 949 bool ok = !tspacket .TransportError();949 bool ok = !tspacket->TransportError(); 950 950 951 if (IsEncryptionTestPID(tspacket .PID()))951 if (IsEncryptionTestPID(tspacket->PID())) 952 952 { 953 953 ProcessEncryptedPacket(tspacket); 954 954 } … … 956 956 if (!ok) 957 957 return false; 958 958 959 if (!tspacket .ScramplingControl() && tspacket.HasPayload())959 if (!tspacket->ScramplingControl() && tspacket->HasPayload()) 960 960 { 961 if (IsVideoPID(tspacket .PID()))961 if (IsVideoPID(tspacket->PID())) 962 962 { 963 963 for (uint j = 0; j < _ts_av_listeners.size(); j++) 964 964 _ts_av_listeners[j]->ProcessVideoTSPacket(tspacket); … … 966 966 return true; 967 967 } 968 968 969 if (IsAudioPID(tspacket .PID()))969 if (IsAudioPID(tspacket->PID())) 970 970 { 971 971 for (uint j = 0; j < _ts_av_listeners.size(); j++) 972 972 _ts_av_listeners[j]->ProcessAudioTSPacket(tspacket); … … 974 974 return true; 975 975 } 976 976 977 if (IsWritingPID(tspacket .PID()) && _ts_writing_listeners.size())977 if (IsWritingPID(tspacket->PID()) && _ts_writing_listeners.size()) 978 978 { 979 979 for (uint j = 0; j < _ts_writing_listeners.size(); j++) 980 980 _ts_writing_listeners[j]->ProcessTSPacket(tspacket); 981 981 } 982 982 983 if (IsListeningPID(tspacket .PID()))983 if (IsListeningPID(tspacket->PID())) 984 984 { 985 HandleTSTables( &tspacket);985 HandleTSTables(tspacket); 986 986 } 987 987 } 988 988 … … 1666 1666 /** \fn MPEGStreamData::ProcessEncryptedPacket(const TSPacket& tspacket) 1667 1667 * \brief counts en/decrypted packets to decide if a stream is en/decrypted 1668 1668 */ 1669 void MPEGStreamData::ProcessEncryptedPacket(const TSPacket &tspacket)1669 void MPEGStreamData::ProcessEncryptedPacket(const TSPacket* tspacket) 1670 1670 { 1671 1671 QMutexLocker locker(&_encryption_lock); 1672 1672 1673 const uint pid = tspacket .PID();1673 const uint pid = tspacket->PID(); 1674 1674 CryptInfo &info = _encryption_pid_to_info[pid]; 1675 1675 1676 1676 CryptStatus status = kEncUnknown; 1677 1677 1678 if (tspacket .ScramplingControl())1678 if (tspacket->ScramplingControl()) 1679 1679 { 1680 1680 info.decrypted_packets = 0; 1681 1681 -
libs/libmythtv/mpeg/streamlisteners.h
49 49 class TSPacketListener 50 50 { 51 51 public: 52 virtual bool ProcessTSPacket(const TSPacket &tspacket) = 0;52 virtual bool ProcessTSPacket(const TSPacket* tspacket) = 0; 53 53 54 54 protected: 55 55 virtual ~TSPacketListener() { } … … 58 58 class TSPacketListenerAV 59 59 { 60 60 public: 61 virtual bool ProcessVideoTSPacket(const TSPacket &tspacket) = 0;62 virtual bool ProcessAudioTSPacket(const TSPacket &tspacket) = 0;61 virtual bool ProcessVideoTSPacket(const TSPacket* tspacket) = 0; 62 virtual bool ProcessAudioTSPacket(const TSPacket* tspacket) = 0; 63 63 64 64 protected: 65 65 virtual ~TSPacketListenerAV() { } -
libs/libmythtv/mpeg/mpegstreamdata.h
106 106 virtual bool IsRedundant(uint pid, const PSIPTable&) const; 107 107 virtual bool HandleTables(uint pid, const PSIPTable &psip); 108 108 virtual void HandleTSTables(const TSPacket* tspacket); 109 virtual bool ProcessTSPacket(const TSPacket &tspacket);109 virtual bool ProcessTSPacket(const TSPacket* tspacket); 110 110 virtual int ProcessData(unsigned char *buffer, int len); 111 111 inline void HandleAdaptationFieldControl(const TSPacket* tspacket); 112 112 … … 291 291 void DeletePartialPES(uint pid); 292 292 void ProcessPAT(const ProgramAssociationTable *pat); 293 293 void ProcessPMT(const ProgramMapTable *pmt); 294 void ProcessEncryptedPacket(const TSPacket &);294 void ProcessEncryptedPacket(const TSPacket*); 295 295 296 296 static int ResyncStream(unsigned char *buffer, int curr_pos, int len); 297 297 -
libs/libmythtv/iptvrecorder.cpp
193 193 194 194 // Cast current found TS Packet to TSPacket structure 195 195 const void *newData = data + tsPos + readIndex; 196 ProcessTSPacket( *reinterpret_cast<const TSPacket*>(newData));196 ProcessTSPacket(reinterpret_cast<const TSPacket*>(newData)); 197 197 198 198 // follow to next packet 199 199 readIndex += tsPos + TSPacket::SIZE; 200 200 } 201 201 } 202 202 203 void IPTVRecorder::ProcessTSPacket(const TSPacket &tspacket)203 void IPTVRecorder::ProcessTSPacket(const TSPacket* tspacket) 204 204 { 205 205 if (!_stream_data) 206 206 return; 207 207 208 if (tspacket .TransportError() || tspacket.ScramplingControl())208 if (tspacket->TransportError() || tspacket->ScramplingControl()) 209 209 return; 210 210 211 if (tspacket .HasAdaptationField())212 _stream_data->HandleAdaptationFieldControl( &tspacket);211 if (tspacket->HasAdaptationField()) 212 _stream_data->HandleAdaptationFieldControl(tspacket); 213 213 214 if (tspacket .HasPayload())214 if (tspacket->HasPayload()) 215 215 { 216 const unsigned int lpid = tspacket .PID();216 const unsigned int lpid = tspacket->PID(); 217 217 218 218 // Pass or reject packets based on PID, and parse info from them 219 219 if (lpid == _stream_data->VideoPIDSingleProgram()) … … 222 222 uint video_stream_type = pmt->StreamType(pmt->FindPID(lpid)); 223 223 224 224 if (video_stream_type == StreamID::H264Video) 225 _buffer_packets = !FindH264Keyframes( &tspacket);225 _buffer_packets = !FindH264Keyframes(tspacket); 226 226 else if (StreamID::IsVideo(video_stream_type)) 227 _buffer_packets = !FindMPEG2Keyframes( &tspacket);227 _buffer_packets = !FindMPEG2Keyframes(tspacket); 228 228 229 229 if ((video_stream_type != StreamID::H264Video) || _seen_sps) 230 230 BufferedWrite(tspacket); 231 231 } 232 232 else if (_stream_data->IsAudioPID(lpid)) 233 233 { 234 _buffer_packets = !FindAudioKeyframes( &tspacket);234 _buffer_packets = !FindAudioKeyframes(tspacket); 235 235 BufferedWrite(tspacket); 236 236 } 237 237 else if (_stream_data->IsListeningPID(lpid)) 238 _stream_data->HandleTSTables( &tspacket);238 _stream_data->HandleTSTables(tspacket); 239 239 else if (_stream_data->IsWritingPID(lpid)) 240 240 BufferedWrite(tspacket); 241 241 } … … 270 270 271 271 int next = (pat->tsheader()->ContinuityCounter()+1)&0xf; 272 272 pat->tsheader()->SetContinuityCounter(next); 273 BufferedWrite( *(reinterpret_cast<const TSPacket*>(pat->tsheader())));273 BufferedWrite(reinterpret_cast<const TSPacket*>(pat->tsheader())); 274 274 } 275 275 276 276 void IPTVRecorder::HandleSingleProgramPMT(ProgramMapTable *pmt) … … 280 280 281 281 int next = (pmt->tsheader()->ContinuityCounter()+1)&0xf; 282 282 pmt->tsheader()->SetContinuityCounter(next); 283 BufferedWrite( *(reinterpret_cast<const TSPacket*>(pmt->tsheader())));283 BufferedWrite(reinterpret_cast<const TSPacket*>(pmt->tsheader())); 284 284 } 285 285 286 286 /* vim: set expandtab tabstop=4 shiftwidth=4: */