void DVVideoFileServerMediaSubsession::seekStreamSource(FramedSource* inputSource, double seekNPT) {
  // First, get the file source from "inputSource" (a framer):
  DVVideoStreamFramer* framer = (DVVideoStreamFramer*)inputSource;
  ByteStreamFileSource* fileSource = (ByteStreamFileSource*)(framer->inputSource());

  // Then figure out where to seek to within the file:
  if (fFileDuration > 0.0) {
    u_int64_t seekByteNumber = (u_int64_t)(((int64_t)fFileSize*seekNPT)/fFileDuration);
    fileSource->seekToByteAbsolute(seekByteNumber);
  }
}
void DVVideoFileServerMediaSubsession
::setStreamSourceDuration(FramedSource* inputSource, double streamDuration, u_int64_t& numBytes) {
  // First, get the file source from "inputSource" (a framer):
  DVVideoStreamFramer* framer = (DVVideoStreamFramer*)inputSource;
  ByteStreamFileSource* fileSource = (ByteStreamFileSource*)(framer->inputSource());

  // Then figure out how many bytes to limit the streaming to:
  if (fFileDuration > 0.0) {
    numBytes = (u_int64_t)(((int64_t)fFileSize*streamDuration)/fFileDuration);
    fileSource->seekToByteRelative(0, numBytes);
  }
}
FramedSource* DVVideoFileServerMediaSubsession
::createNewStreamSource(unsigned /*clientSessionId*/, unsigned& estBitrate) {
  // Create the video source:
  ByteStreamFileSource* fileSource = ByteStreamFileSource::createNew(envir(), fFileName);
  if (fileSource == NULL) return NULL;
  fFileSize = fileSource->fileSize();

  // Create a framer for the Video Elementary Stream:
  DVVideoStreamFramer* framer = DVVideoStreamFramer::createNew(envir(), fileSource, True/*the file source is seekable*/);
  
  // Use the framer to figure out the file's duration:
  unsigned frameSize;
  double frameDuration;
  if (framer->getFrameParameters(frameSize, frameDuration)) {
    fFileDuration = (float)(((int64_t)fFileSize*frameDuration)/(frameSize*1000000.0));
    estBitrate = (unsigned)((8000.0*frameSize)/frameDuration); // in kbps
  } else {
    estBitrate = 50000; // kbps, estimate
  }

  return framer;
}
void DVVideoStreamFramer::afterGettingFrame(void* clientData, unsigned frameSize,
					    unsigned numTruncatedBytes,
					    struct timeval /*presentationTime*/, unsigned /*durationInMicroseconds*/) {
  DVVideoStreamFramer* source = (DVVideoStreamFramer*)clientData;
  source->afterGettingFrame1(frameSize, numTruncatedBytes);
}