www.pudn.com > MPEG2systemsrc.rar > Producer.C


/* Copyright (C) 1995, Tektronix Inc. All Rights Reserved.
 *
 *   Usage Restrictions
 *
 * License is granted to copy, to use, and to make and to use derivative
 * works for research and evaluation purposes only.
 *
 *   Disclaimer of Warranty
 *
 * These software programs are available to the user without any license
 * fee or royalty on an "as is" basis.  Tektronix Inc. disclaims any and
 * all warranties, whether express, implied, or statuary, including any
 * implied warranties or merchantability or of fitness for a particular
 * purpose.  In no event shall the copyright-holder be liable for any 
 * incidental, punitive, or consequential damages of any kind whatsoever
 * arising from the use of these programs.
 *
 * This disclaimer of warranty extends to the user of these programs and
 * user's customers, employees, agents, transferees, successors, and
 * assigns.
 *
 * The Tektronix Inc. does not represent or warrant that the programs
 * furnished hereunder are free of infringement of any third-party
 * patents.
*/

/* Producer class implementation */

#include "Utilities.H"
#include "Producer.H"
#include "OutputPort.H"

extern "C"
{
//#include 
}

Producer::Producer (Encoder* e)
{
  encoder = e;
  length_stored = 0;
  buf_index = 1;
}

void Producer::connect (OutputPort* p)
{
  oport = p;
}

int Producer::fill_buffer ()
{
  // do nothing in the base class
  return 0;
}

int Producer::get_nready ()
{
  if (length_stored < buf_index) return 0;
  return length_stored - buf_index; 
}

int Producer::send_partial (int n)
{
  if (buf_index >= length_stored)
    {
      // fill buffer
      length_stored = fill_buffer();
    }
  // now send bytes
  for (int i = 0; i < n; i++)
    {
      if (buf_index < length_stored)
	{
          oport->write_byte(buf[buf_index]);
          buf_index++;
	}
      else
	{
	  oport->write_byte(0xff);
	  sys_message("0xff padding inserted by Producer::send_partial");
	}
    }
  if (buf_index < length_stored)
    return 0;
  else
    return 1;
}