Ticket #4515: write_dsmcc_packets_where_no_AV_packets.diff

File write_dsmcc_packets_where_no_AV_packets.diff, 5.7 KB (added by bradley.kite@…, 16 years ago)

write non-A/V data to recorded file

  • libs/libmythtv/dtvrecorder.cpp

     
    3838    // used for scanning pes headers for keyframes
    3939    _start_code(0xffffffff),        _first_keyframe(-1),
    4040    _last_gop_seen(0),              _last_seq_seen(0),
    41     _last_keyframe_seen(0),
     41    _last_keyframe_seen(0),         _hasWrittenOtherKeyFrame(false),
    4242    // H.264 support
    4343    _pes_synced(false),
    4444    _seen_sps(false),
     
    146146
    147147    //_start_code
    148148    _first_keyframe             =-1;
     149    _hasWrittenOtherKeyFrame    = false;
    149150    _last_keyframe_seen         = 0;
    150151    _last_gop_seen              = 0;
    151152    _last_seq_seen              = 0;
     
    344345    return hasKeyFrame;
    345346}
    346347
     348// Non-Audio/Video data. For streams which contain no audio/video, write just 1 key-frame
     349// at the start.
     350bool DTVRecorder::FindOtherKeyframes(const TSPacket *tspacket)
     351{
     352    if (_hasWrittenOtherKeyFrame)
     353        return true;
     354
     355    VERBOSE(VB_RECORD, LOC + "DSMCC - FindOtherKeyframes() - generating initial key-frame");
     356    _frames_seen_count++;
     357    _frames_written_count++;
     358    _last_keyframe_seen = _frames_seen_count;
     359    HandleKeyframe();
     360    _hasWrittenOtherKeyFrame = true;
     361    return true;
     362}
     363
    347364// documented in recorderbase.h
    348365void DTVRecorder::SetNextRecording(const ProgramInfo *progInf, RingBuffer *rb)
    349366{
  • libs/libmythtv/dvbrecorder.cpp

     
    477477
    478478bool DVBRecorder::ProcessVideoTSPacket(const TSPacket &tspacket)
    479479{
     480    VERBOSE(VB_RECORD, LOC + "DSMCC - ProcessVideoTSPacket()");
    480481    uint streamType = _stream_id[tspacket.PID()];
    481482
    482483    // Check for keyframes and count frames
     
    491492        _buffer_packets = !FindMPEG2Keyframes(&tspacket);
    492493    }
    493494
    494     return ProcessTSPacket(tspacket);
     495    return ProcessAVTSPacket(tspacket);
    495496}
    496497
    497498bool DVBRecorder::ProcessAudioTSPacket(const TSPacket &tspacket)
    498499{
     500    VERBOSE(VB_RECORD, LOC + "DSMCC - ProcessAudioTSPacket()");
    499501    _buffer_packets = !FindAudioKeyframes(&tspacket);
    500     return ProcessTSPacket(tspacket);
     502    return ProcessAVTSPacket(tspacket);
    501503}
    502504
    503 bool DVBRecorder::ProcessTSPacket(const TSPacket &tspacket)
     505// Common code for processing either audio or video packets
     506bool DVBRecorder::ProcessAVTSPacket(const TSPacket &tspacket)
    504507{
    505     const uint pid = tspacket.PID();
    506508
    507     // Check continuity counter
    508     if ((pid != 0x1fff) && !CheckCC(pid, tspacket.ContinuityCounter()))
    509     {
    510         VERBOSE(VB_RECORD, LOC +
    511                 QString("PID 0x%1 discontinuity detected").arg(pid,0,16));
    512         _continuity_error_count++;
    513     }
    514 
    515509    // Sync recording start to first keyframe
     510    // (Delay's until first GOP to avoid decoder crash on res change)
    516511    if (_wait_for_keyframe_option && _first_keyframe < 0)
     512    {
     513        VERBOSE(VB_RECORD, LOC + QString("DSMCC - ProcessAVTSPacket() - Ignoring packet"));
    517514        return true;
     515    }
    518516
     517    const uint pid = tspacket.PID();
    519518    // Sync streams to the first Payload Unit Start Indicator
    520519    // _after_ first keyframe iff _wait_for_keyframe_option is true
    521520    if (!(_pid_status[pid] & kPayloadStartSeen) && tspacket.HasPayload())
    522521    {
    523522        if (!tspacket.PayloadStart())
     523        {
     524            VERBOSE(VB_RECORD, LOC + "DSMCC - ProcessAVTSPacket() - Not PayloadStart - dropping packet");
    524525            return true; // not payload start - drop packet
     526        }
    525527
    526528        VERBOSE(VB_RECORD,
    527529                QString("PID 0x%1 Found Payload Start").arg(pid,0,16));
     
    529531        _pid_status[pid] |= kPayloadStartSeen;
    530532    }
    531533
     534    return ProcessTSPacketCommon(tspacket);
     535}
     536
     537bool DVBRecorder::ProcessTSPacket(const TSPacket &tspacket)
     538{
     539    VERBOSE(VB_RECORD, LOC + "DSMCC - ProcessTSPacket()");
     540    _buffer_packets = !FindOtherKeyframes(&tspacket);
     541    return ProcessTSPacketCommon(tspacket);
     542}
     543
     544bool DVBRecorder::ProcessTSPacketCommon(const TSPacket &tspacket)
     545{
     546    // Care must be taken to make sure that the packet actually gets written
     547    // as the decision to actually write it has already been made
     548    const uint pid = tspacket.PID();
     549    VERBOSE(VB_RECORD, LOC + QString("DSMCC - ProcessTSPacketCommon() Started (PID: 0x%1)").arg(pid,0,16));
     550
     551    // Check continuity counter
     552    if ((pid != 0x1fff) && !CheckCC(pid, tspacket.ContinuityCounter()))
     553    {
     554        VERBOSE(VB_RECORD, LOC +
     555                QString("PID 0x%1 discontinuity detected").arg(pid,0,16));
     556        _continuity_error_count++;
     557    }
     558
    532559    BufferedWrite(tspacket);
    533560
    534561    return true;
    535562}
     563
     564void DVBRecorder::BufferedWrite(const TSPacket &tspacket)
     565{
     566    VERBOSE(VB_RECORD, LOC + QString("DSMCC - BufferedWrite() - buffer: %1").arg(_buffer_packets));
     567    // Care must be taken to make sure that the packet actually gets written
     568    // as the decision to actually write it has already been made
     569
     570    // Do we have to buffer the packet for exact keyframe detection?
     571    if (_buffer_packets)
     572    {
     573        int idx = _payload_buffer.size();
     574        _payload_buffer.resize(idx + TSPacket::SIZE);
     575        memcpy(&_payload_buffer[idx], tspacket.data(), TSPacket::SIZE);
     576        return;
     577    }
     578
     579    // We are free to write the packet, but if we have buffered packet[s]
     580    // we have to write them first...
     581    if (!_payload_buffer.empty())
     582    {
     583        if (ringBuffer)
     584            ringBuffer->Write(&_payload_buffer[0], _payload_buffer.size());
     585        _payload_buffer.clear();
     586    }
     587
     588    if (ringBuffer)
     589        ringBuffer->Write(tspacket.data(), TSPacket::SIZE);
     590}
     591