MxPEGScanToJPEGConverterSoftwareOnly.h

00001 //           ///          //                                  C++ Cross Platform
00002 //          /////        ////
00003 //         /// XXX     XXX ///            ///////////   /////////     ///   ///
00004 //        ///    XXX XXX    ///         ///             ///    ///   ///  ///
00005 //       ///       XXX       ///         /////////     ///      //  //////
00006 //      ///      XXX XXX      ///               ///   ///    ///   ///  ///
00007 //     ////    XXX     XXX    ////    ////////////  //////////    ///   ///
00008 //    ////                     ////
00009 //   ////  M  O  B  O  T  I  X  ////////////////////////////////////////////////
00010 //  //// Security Vision Systems //////////////////////////////////////////////
00011 //
00012 //  $Author: khe_admin $
00013 //  $LastChangedBy: khe_admin $
00014 //  $LastChangedDate: 2007-06-28 11:26:00 +0200 (Thu, 28 Jun 2007) $
00015 //  $HeadURL: http://svn.mobotix.net/svn/mxsdk/src/MxPEGCoreComponent/trunk/include/MxPEGScanToJPEGConverterSoftwareOnly.h $
00016 //
00018      //
00019      //  MOBOTIX MxPEG SDK
00020      //
00021      //  This file belongs to the C++ library released as part of the MxPEG SDK.
00022      //
00023      //  This software is licenced under the BSD licence,
00024      //  http://www.opensource.org/licenses/bsd-license.php
00025      //
00026      //  Copyright (c) 2005 - 2007, MOBOTIX AG
00027      //  All rights reserved.
00028      //
00029      //  Redistribution and use in source and binary forms, with or without
00030      //  modification, are permitted provided that the following conditions are
00031      //  met:
00032      //
00033      //  - Redistributions of source code must retain the above copyright
00034      //    notice, this list of conditions and the following disclaimer.
00035      //
00036      //  - Redistributions in binary form must reproduce the above copyright
00037      //    notice, this list of conditions and the following disclaimer in the
00038      //    documentation and/or other materials provided with the distribution.
00039      //
00040      //  - Neither the name of MOBOTIX AG nor the names of its contributors may
00041      //    be used to endorse or promote products derived from this software
00042      //    without specific prior written permission.
00043      //
00044      //  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00045      //  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00046      //  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00047      //  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00048      //  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00049      //  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00050      //  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00051      //  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00052      //  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00053      //  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00054      //  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00055      //
00057 
00058 
00059 
00060 #ifndef __MX_MXPEGSCANTOJPEGCONVERTERSOFTWAREONLY_H__
00061 #define __MX_MXPEGSCANTOJPEGCONVERTERSOFTWAREONLY_H__
00062 
00063 
00064 
00065 #define MX_MXPEGSCANTOJPEGCONVERTERSOFTWAREONLY_ID \
00066          "MxPEGScanToJPEGConverterSoftwareOnly"
00067 
00068 
00069 
00070 #include "MxPEGScanDecoderSoftwareOnlyCore.h"
00071 #include "mxcpcHuffmanTree.h"
00072 
00073 #include <interfaces/IComponent.h>
00074 #include <interfaces/IComponentInvoker.h>
00075 #include <interfaces/IMxPEGScanToJPEGConverter.h>
00076 
00077 #include <Framework/Framework.h>
00078 
00079 #include <mxm/core/mxm_jpeg.h>
00080 
00081 
00082 
00083 class mxmUndecoderMxPEGFrameDescriptor;
00084 
00085 
00086 
00087 namespace mx {
00088   
00089   class ISegmentedStreamReceiver;
00090   
00093 
00103   class MxPEGScanToJPEGConverterSoftwareOnly
00104          : public MxPEGScanDecoderSoftwareOnlyCore,
00105            public virtual IComponent,
00106            public virtual IMxPEGScanToJPEGConverter {
00107     
00111    private:
00112     static mxm::smart<mxmStringList> _enumerateInterfaces() {
00113       return(new mxmStringList(
00114                    (mxmString(MX_MXPEGSCANTOJPEGCONVERTERSOFTWAREONLY_ID),
00115                     MX_ICOMPONENT_ID,
00116                     MX_IMXPEGSCANTOJPEGCONVERTER_ID,
00117                     MX_IUNDECODEDMXPEGFRAMERECEIVER_ID,
00118                     MX_ISENDSSEGMENTEDSTREAM_ID,
00119                     MX_IERRORSTATE_ID)));
00120     }
00121     static mxm::smart<mxmStringList> _enumerateCapabilities(
00122                                         const mxmString &interface_id) {
00123       if(interface_id == mx::Framework::IdHintKey)
00124        return(new mxmStringList(MX_MXPEGSCANTOJPEGCONVERTERSOFTWAREONLY_ID));
00125       else
00126       return(new mxmStringList());
00127     }
00128    private:
00129     class Invoker : public mxmObject, public virtual IComponentInvoker {
00130      public:
00131       mxm::smart<mxmStringList> enumerateInterfaces() {
00132         return(_enumerateInterfaces());
00133       }
00134       mxm::smart<mxmStringList> enumerateCapabilities(
00135                                   const mxmString &interface_id) {
00136         return(_enumerateCapabilities(interface_id));
00137       }
00138       IComponent *newComponent() {
00139         return(new MxPEGScanToJPEGConverterSoftwareOnly());
00140       }
00141     };
00142    public:
00144     static IComponentInvoker *newInvoker() {
00145       return(new Invoker());
00146     }
00147     
00148    private:
00149     static const int BitstreamBufferSize = 0x100000;
00150     static const unsigned char ZigZag_StoreMap[64];
00151     
00153     typedef struct {
00156       mxm::u8 bits_dc[16];
00159       mxm::u8 val_dc[12];
00160     } HuffCompDC;
00161     
00163     typedef struct {
00169       mxm::u8 bits_ac[16];
00170       mxm::u8 val_ac[162];
00171     } HuffCompAC;
00172     
00173     static const HuffCompDC HuffTbl_Y_UV_DC[2];
00174     static const HuffCompAC HuffTbl_Y_UV_AC[2];
00175     
00177     typedef struct {
00180       unsigned int code_msk:  26;
00182       unsigned int fill_0bit:  1;
00184       unsigned int bit_len:    5;
00185     } HuffCodeTblEntry;
00186     
00188     typedef union {
00189       HuffCodeTblEntry table_entry;
00190       mxm::u32         u32_word;
00191     } u32t;
00192     
00194     typedef struct {
00196       HuffCodeTblEntry ac_tbl[1];
00198       HuffCodeTblEntry dc_tbl[12];
00200       int free_13;
00202       int free_14;
00204       HuffCodeTblEntry dc_tbl_0FtoAF[161];
00205     } FoldedHuffTbl_DC_AC;
00206     
00208     FoldedHuffTbl_DC_AC Huff_Y_UV[2];
00209     
00211     typedef struct {
00212       mxm::u8* buf_start;         // Addr of buf in memory, word-aligned
00213       mxm::u8* buf_end1;          // End of buffer + 1, word-aligned */
00214       mxm::u8* buf_current_w_pos; // Current buffer pointer, word-aligned if
00215                                   //  huf_accu is valid,
00216                                   //  may be odd after jd_close_huf_buf_stateb
00217                                   //  was called */
00218       mxm::u32 huf_accu;          // Left justified bits not yet emitted
00219       unsigned int huf_bits_used; // Number of valid bits in huf_accu not yet
00220                                   //  emitted
00221     } HuffmanBufferStateStructure;
00222     
00223    private:
00224     ISegmentedStreamReceiver *JPEGReceiver;
00225     HuffmanBufferStateStructure HuffmanBufferState;
00226     mxm::u8 *HuffmanTableWriteBuffer;
00227     mxm::u8 *HuffmanEncoderBuffer;
00228     mxm::s16 *CoeffBuffer;        // Ptr. to decoded frame!
00229     int TileNumX, TileNumY;       // Nb. of tiles to handle per frame!
00230     mxm::JPEG::MarkerLayoutAPP0 APP0_Block;
00231     mxm::JPEG::MarkerLayoutSOF0 SOF0_Block;
00232     mxm::JPEG::MarkerLayoutSOS  SOS_Block;
00233     int FramesProcessed;
00234     bool ErrorEncountered;
00235     
00236    public:
00238     MxPEGScanToJPEGConverterSoftwareOnly();
00239     ~MxPEGScanToJPEGConverterSoftwareOnly();
00240     
00241    public:
00243     mxm::smart<mxmStringList> enumerateInterfaces();
00245     mxm::smart<mxmStringList> enumerateCapabilities(
00246                                 const mxmString &interface);
00247     
00249     void receiveUndecodedMxPEGFrame(mxmUndecodedMxPEGFrameDescriptor
00250                                      *frame_descriptor);
00252     void receiveMxPEGAudioFrame(const mxmAudioBlockInfo &audio_info,
00253                                 const mxm::u8 *sample_data);
00254     
00256     void setSegmentedStreamReceiver(ISegmentedStreamReceiver *receiver);
00257     
00259     bool errorState();
00261     void setErrorState();
00262          
00263    private:
00265     void calcFoldedHuffTables(void);
00267 
00276     void generateHuffTables1(const mxm::u8 * bits_tbl_off1,
00277                              const mxm::u8 * val_tbl,
00278                              int swap_symbol,
00279                              HuffCodeTblEntry * folded_tbl_p);
00281     void initHuffmanEncoderBufferState();
00282     void resetHuffmanEncoderBufferState();
00283     
00285     void encodeSubMCUTiles(mxm::s16* coef_matrix,
00286                            mxm::s16* last_dc_coeff,
00287                            FoldedHuffTbl_DC_AC* huff_code_tbl_entry,
00288                            HuffmanBufferStateStructure* hbuf_state_ptr);
00289     
00291     void copyAccuToGlobalHuffBuffer(mxm::u32 huff_accu_32,
00292                                     HuffmanBufferStateStructure
00293                                     *huff_buf_state_ptr);
00294     
00296     int shutDownHuffAccu(void);
00297     
00299     int returnBitsInCoef(mxm::s16 c);
00300   };
00301 };
00302 
00303 
00304 #endif   // __MX_MXPEGSCANTOJPEGCONVERTERSOFTWAREONLY_H__

Generated on Fri Jun 29 17:21:04 2007 for MxPEG SDK by  doxygen 1.4.6