/**
 * XXX merge into DVBCard?
 */

package org.bucksch.zeipis.recorder;
import org.bucksch.zeipis.all.*;
//import org.bucksch.zeipis.store.StreamCopy;
import java.io.*;
import java.sql.SQLException;

public class DVBRecorder extends TVRecorder
{
  public DVBRecorder(DVBCard device)
    throws Misconfiguration, SQLException
  {
    myDevice = device;
  }
  public void startRecording(TVChannel tvchannel)
    throws Misconfiguration, CantUseTVCard
  {
    if (!(tvchannel instanceof DVBChannel))
  		throw new Misconfiguration("Using a non-DVB TV channel on a DVB card");
    myChannel = (DVBChannel) tvchannel;

    myTuner = myDevice.tuner();
    myTuner.tuneTo(myChannel);

    myStream = myDevice.recordDevice();
  }
  public void stopRecording()
    throws CantUseTVCard
  {
    //Util.debug("recorder.stopRecording");
    //if (myStreamCopy != null)
    //  myStreamCopy.stop();
    myTuner.done();
  }

  public InputStream inStream()
  {
    return myStream;
  }
  
//  // Convenience
//  public void startRecordingTo(TVChannel tvchannel, Target target)
//    throws Exception
//  {
//    startRecording(tvchannel);
//    myStreamCopy = new StreamCopy();
//    myStreamCopy.copy(this, target, true, "Recording " + myChannel.toString());
//  }

  // Getter
  //public TVChannel channel() { return myChannel; }
  public String toString()
  {
    if (myChannel == null)
      return myDevice + " recording not started yet";
    else
      return myDevice + " channel " + myChannel.stationLongName();
  }

  // Data
  protected DVBChannel myChannel;
  protected DVBCard myDevice;
  protected DVBTuner myTuner = null;
  protected InputStream myStream = null;
//  protected StreamCopy myStreamCopy = null;
}
