www.pudn.com > MPEG2systemsrc.rar > pesin.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.
*/
/* pes stream reader */
#include "Decoder.H"
#include "IPortFromFile.H"
#include "Events.H"
#include "Utilities.H"
#include "PESConsumer.H"
extern "C"
{
void exit (int);
#include
}
// Callbacks
void cleanup (EventType, void*, void*);
void print_pes (EventType, void*, void*);
main (int argc, char* argv[])
{
if ((argc < 2) || (argc > 3))
{
printf("syntax is decode \n");
exit (0);
}
if (argc == 3) PRINTFLAG = FALSE;
// create an EventManager
EventManager* manager = new EventManager();
EM = manager;
// create a Decoder
Decoder* decoder = new Decoder(manager);
// build consumer, port and connect
PESConsumer* pcons = new PESConsumer(decoder, new PES());
IPortFromFile* iport = new IPortFromFile(argv[1], NOCYCLE);
pcons->connect(iport);
pcons->pes_out_flag = NULL;
// register callbacks
manager->Register(PESHeaderParsed, print_pes, NULL);
manager->Register(Termination, cleanup, pcons);
// read some pes packets
for (;;)
{
pcons->read_partial(100);
// we assume here that the PES header has been read and parsed
// and that therefore pcons->pes has a length field.
int length = pcons->pes->get_length();
if (length < 100)
{
sys_halt("can't continue with this stream");
}
pcons->read_partial(length - 100);
pcons->set_cstate(CSTART);
}
printf("\ndone\n");
}
void print_pes (EventType t, void* client_data, void* call_data)
{
PES* pes = (PES*) call_data;
printf(" **** PES Packet Header Start ****\n");
pes->print();
printf(" **** PES Packet Header End ****\n\n");
}
void cleanup (EventType t, void* client_data, void* call_data)
{
PESConsumer* pcons = (PESConsumer*) client_data;
pcons->flush();
}