00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
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;
00213 mxm::u8* buf_end1;
00214 mxm::u8* buf_current_w_pos;
00215
00216
00217
00218 mxm::u32 huf_accu;
00219 unsigned int huf_bits_used;
00220
00221 } HuffmanBufferStateStructure;
00222
00223 private:
00224 ISegmentedStreamReceiver *JPEGReceiver;
00225 HuffmanBufferStateStructure HuffmanBufferState;
00226 mxm::u8 *HuffmanTableWriteBuffer;
00227 mxm::u8 *HuffmanEncoderBuffer;
00228 mxm::s16 *CoeffBuffer;
00229 int TileNumX, TileNumY;
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__