Ticket #1164: firewire.diff

File firewire.diff, 6.1 KB (added by jwestfall@…, 14 years ago)
  • libs/libmythtv/firewirerecorder.cpp

     
    1515// MythTV includes
    1616#include "firewirerecorder.h"
    1717#include "mythcontext.h"
    18 #include "tspacket.h"
     18#include "mpegtables.h"
     19#include "mpegstreamdata.h"
    1920#include "tv_rec.h"
    2021
    2122// callback function for libiec61883
     
    4445    return 1;
    4546}
    4647
     48FirewireRecorder::FirewireRecorder(TVRec *rec)
     49    : DTVRecorder(rec, "FirewireRecorder"),
     50      fwport(-1),     fwchannel(-1), fwspeed(-1),   fwbandwidth(-1),
     51      fwfd(-1),       fwconnection(FIREWIRE_CONNECTION_P2P),
     52      fwoplug(-1),    fwiplug(-1),   fwmodel(""),   fwnode(0),
     53      fwhandle(NULL), fwmpeg(NULL),  isopen(false), lastpacket(0),
     54      _mpeg_stream_data(NULL)
     55{
     56
     57    _mpeg_stream_data = new MPEGStreamData(1, true);
     58    connect(_mpeg_stream_data, SIGNAL(UpdatePATSingleProgram(
     59                                          ProgramAssociationTable*)),
     60            this, SLOT(WritePAT(ProgramAssociationTable*)));
     61    connect(_mpeg_stream_data, SIGNAL(UpdatePMTSingleProgram(ProgramMapTable*)),
     62            this, SLOT(WritePMT(ProgramMapTable*)));
     63
     64}
     65
     66FirewireRecorder::~FirewireRecorder()
     67{
     68   Close();
     69   if (_mpeg_stream_data)
     70       delete(_mpeg_stream_data);
     71}
     72     
    4773void FirewireRecorder::deleteLater(void)
    4874{
    4975    Close();
     
    5581     if (isopen)
    5682         return true;
    5783   
     84     if(!_mpeg_stream_data)
     85         return false;
     86
    5887     VERBOSE(VB_GENERAL,QString("Firewire: Initializing Port: %1, Node: %2, Speed: %3")
    5988                               .arg(fwport)
    6089                               .arg(fwnode)
     
    113142     return true;
    114143}
    115144
     145void FirewireRecorder::SetStreamData(MPEGStreamData *stream_data)
     146{
     147    if (stream_data == _mpeg_stream_data)
     148        return;
     149
     150    MPEGStreamData *old_data = _mpeg_stream_data;
     151    _mpeg_stream_data = stream_data;
     152    if (old_data)
     153        delete old_data;
     154}
     155
    116156void FirewireRecorder::Close(void)
    117157{
    118158    if (!isopen)
     
    189229    _recording = false;
    190230
    191231
     232void FirewireRecorder::WritePAT(ProgramAssociationTable *pat)
     233{
     234    if (!pat)
     235        return;
     236
     237    int next = (pat->tsheader()->ContinuityCounter()+1)&0xf;
     238    pat->tsheader()->SetContinuityCounter(next);
     239    BufferedWrite(*(reinterpret_cast<TSPacket*>(pat->tsheader())));
     240}
     241
     242void FirewireRecorder::WritePMT(ProgramMapTable* pmt)
     243{
     244    if (!pmt)
     245        return;
     246
     247    int next = (pmt->tsheader()->ContinuityCounter()+1)&0xf;
     248    pmt->tsheader()->SetContinuityCounter(next);
     249    BufferedWrite(*(reinterpret_cast<TSPacket*>(pmt->tsheader())));
     250}
     251
    192252void FirewireRecorder::ProcessTSPacket(const TSPacket &tspacket)
    193253{
    194     lastpacket = time(NULL);
    195     _buffer_packets = !FindKeyframes(&tspacket);
    196     BufferedWrite(tspacket);
     254
     255    bool ok = !tspacket.TransportError();
     256    if (ok && !tspacket.ScramplingControl())
     257    {
     258        if (tspacket.HasAdaptationField())
     259            StreamData()->HandleAdaptationFieldControl(&tspacket);
     260        if (tspacket.HasPayload())
     261        {
     262            const unsigned int lpid = tspacket.PID();
     263            // Pass or reject frames based on PID, and parse info from them
     264            if (lpid == StreamData()->VideoPIDSingleProgram())
     265            {
     266                _buffer_packets = !FindKeyframes(&tspacket);
     267                BufferedWrite(tspacket);
     268            }
     269            else if (StreamData()->IsAudioPID(lpid))
     270                BufferedWrite(tspacket);
     271            else if (StreamData()->IsListeningPID(lpid))
     272                StreamData()->HandleTSTables(&tspacket);
     273            else if (StreamData()->IsWritingPID(lpid))
     274                BufferedWrite(tspacket);
     275        }
     276    }
     277
     278    if (ok)
     279    {
     280       lastpacket = time(NULL);
     281       _ts_stats.IncrTSPacketCount();
     282       if (0 == _ts_stats.TSPacketCount()%1000000)
     283           VERBOSE(VB_RECORD, _ts_stats.toString());
     284    }
    197285}
    198286
    199287void FirewireRecorder::SetOptionsFromProfile(RecordingProfile *profile,
  • libs/libmythtv/firewirerecorder.h

     
    88#define FIREWIRERECORDER_H_
    99
    1010#include "dtvrecorder.h"
    11 #include "mpeg/tspacket.h"
     11#include "tsstats.h"
    1212#include <libraw1394/raw1394.h>
    1313#include <libiec61883/iec61883.h>
    14 
    1514#include <time.h>
    1615
     16class MPEGStreamData;
     17class ProgramAssociationTable;
     18class ProgramMapTable;
     19
    1720#define FIREWIRE_TIMEOUT 15
    1821
    1922#define FIREWIRE_CONNECTION_P2P         0
     
    2932 */
    3033class FirewireRecorder : public DTVRecorder
    3134{
     35  Q_OBJECT
     36  friend class MPEGStreamData;
     37  friend class TSPacketProcessor;
     38
    3239  public:
    33     FirewireRecorder(TVRec *rec) :
    34         DTVRecorder(rec, "FirewireRecorder"),
    35         fwport(-1),     fwchannel(-1), fwspeed(-1),   fwbandwidth(-1),
    36         fwfd(-1),       fwconnection(FIREWIRE_CONNECTION_P2P),
    37         fwoplug(-1),    fwiplug(-1),   fwmodel(""),   fwnode(0),
    38         fwhandle(NULL), fwmpeg(NULL),  isopen(false), lastpacket(0) {;}
    39        
    40     ~FirewireRecorder() { Close(); }
     40    FirewireRecorder(TVRec *rec);
     41    ~FirewireRecorder();
    4142
    4243    void StartRecording(void);
    4344    bool Open(void);
     
    5051    void SetOption(const QString &name, const QString &value);
    5152    void SetOption(const QString &name, int value);
    5253    QString FirewireSpeedString(int speed);
     54    void SetStreamData(MPEGStreamData*);
     55    MPEGStreamData* StreamData(void) { return _mpeg_stream_data; }
    5356
    5457    bool PauseAndWait(int timeout = 100);
    5558
     
    5861       
    5962  private:
    6063    void Close(void);
     64
     65  private slots:
     66    void WritePAT(ProgramAssociationTable*);
     67    void WritePMT(ProgramMapTable*);
     68
     69  private:
    6170    int fwport, fwchannel, fwspeed, fwbandwidth, fwfd, fwconnection;
    6271    int fwoplug, fwiplug;
    6372    QString fwmodel;
     
    6675    iec61883_mpeg2_t fwmpeg;
    6776    bool isopen;
    6877    time_t lastpacket;
     78    MPEGStreamData* _mpeg_stream_data;
     79    TSStats _ts_stats;
     80   
    6981};
    7082
    7183#endif