Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members

mxcpcMJPEGServerpushWriter.cpp

00001 //           ///          //
00002 //          /////        ////
00003 //         /// XXX     XXX ///
00004 //        ///    XXX XXX    ///     $RCSfile: mxcpcMJPEGServerpushWriter.cpp,v $  
00005 //       ///       XXX       ///     $Revision: 1.1 $
00006 //      ///      XXX XXX      ///     $Date: 2005/08/09 13:57:26 $
00007 //     ////    XXX     XXX    ////     $Author: cvs-steve $
00008 //    ////                     ////
00009 //   ////  M  O  B  O  T  I  X  ////////////////////////////////////////////////
00010 //  //// Security Vision Systems ///////////////////////////////////////////////
00011 
00012 // Copyright (c) 2005, MOBOTIX AG.
00013 // This software is made available under the BSD licence. Please refer 
00014 // to the file LICENCE.TXT contained in this distribution for details.
00015 
00016 
00017 #include <mxcpcMJPEGServerpushWriter.h>
00018 
00019 #ifdef WIN32
00020 #include <fcntl.h>
00021 #include <io.h>
00022 #else
00023 #include <cstdio>
00024 #endif
00025 #include <cstring>
00026 #include <memory>
00027 
00028 
00029 
00030 mxcpcMJPEGServerpushWriter::mxcpcMJPEGServerpushWriter(FILE* output_dest, const char* separator_string) {
00031 
00032   if (output_dest != NULL)
00033     OutputDest = output_dest;
00034   else 
00035     OutputDest = stdout;
00036 
00037   SeparatorString = separator_string;
00038 
00039 #ifdef O_BINARY // for Win32 (both mxvc and cygwin)
00040   setmode( fileno(OutputDest), O_BINARY );
00041 #endif
00042 
00043   if (strlen(SeparatorString) > 0)
00044       fprintf (OutputDest, "Content-type: multipart/x-mixed-replace;boundary=\"%s\"\r\n", SeparatorString);
00045 
00046   FrameNum = 0;
00047   
00048   ErrorEncountered = false;
00049 
00050 }
00051 
00052 mxcpcMJPEGServerpushWriter::~mxcpcMJPEGServerpushWriter() {
00053   if (strlen(SeparatorString) > 0)
00054       fprintf (OutputDest, "\r\n--%s--\r\n", SeparatorString);
00055   fprintf (stderr, "Frames written: %d\n", FrameNum);
00056 }
00057 
00058 
00059 void mxcpcMJPEGServerpushWriter::beginFrame(void) {
00060   if (strlen(SeparatorString) > 0)
00061       fprintf (OutputDest, "\r\n--%s\r\nContent-type: image/jpeg\r\n\r\n", SeparatorString);
00062 }
00063 
00064 
00065 void mxcpcMJPEGServerpushWriter::endFrame(void) {
00066   FrameNum++;
00067 }
00068   
00069 
00070 void mxcpcMJPEGServerpushWriter::receiveJPEGBytes(mxcpc::u8 *buffer, int num) {
00071 
00072   if (OutputDest == NULL) {
00073     ErrorEncountered = true;
00074     return;
00075   }
00076   
00077   if (num < 1) {
00078     ErrorEncountered = true;  
00079     return;
00080   }
00081   
00082   if (fwrite(buffer, num, 1, OutputDest) != 1) {
00083     OutputDest = 0;
00084     ErrorEncountered = true;
00085   }
00086 }
00087 

Generated on Mon Aug 15 03:39:30 2005 for mxcpc by  doxygen 1.4.2-20050421