Dirac - A Video Codec

Created by the British Broadcasting Corporation.


common.h

Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002 *
00003 * $Id: common.h,v 1.48 2007/03/22 14:48:09 davidf_ Exp $ $Name:  $
00004 *
00005 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006 *
00007 * The contents of this file are subject to the Mozilla Public License
00008 * Version 1.1 (the "License"); you may not use this file except in compliance
00009 * with the License. You may obtain a copy of the License at
00010 * http://www.mozilla.org/MPL/
00011 *
00012 * Software distributed under the License is distributed on an "AS IS" basis,
00013 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
00014 * the specific language governing rights and limitations under the License.
00015 *
00016 * The Original Code is BBC Research and Development code.
00017 *
00018 * The Initial Developer of the Original Code is the British Broadcasting
00019 * Corporation.
00020 * Portions created by the Initial Developer are Copyright (C) 2004.
00021 * All Rights Reserved.
00022 *
00023 * Contributor(s): Thomas Davies (Original Author),
00024 *                 Scott R Ladd,
00025 *                 Tim Borer,
00026 *                 Anuradha Suraparaju,
00027 *                 Andrew Kennedy
00028 *                 Myo Tun (Brunel University, myo.tun@brunel.ac.uk)
00029 *
00030 * Alternatively, the contents of this file may be used under the terms of
00031 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
00032 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
00033 * the GPL or the LGPL are applicable instead of those above. If you wish to
00034 * allow use of your version of this file only under the terms of the either
00035 * the GPL or LGPL and not to allow others to use your version of this file
00036 * under the MPL, indicate your decision by deleting the provisions above
00037 * and replace them with the notice and other provisions required by the GPL
00038 * or LGPL. If you do not delete the provisions above, a recipient may use
00039 * your version of this file under the terms of any one of the MPL, the GPL
00040 * or the LGPL.
00041 * ***** END LICENSE BLOCK ***** */
00042 
00043 #ifndef _COMMON_H_
00044 #define _COMMON_H_
00045 
00046 #include <libdirac_common/arrays.h>
00047 #include <libdirac_common/common_types.h>
00048 #include <libdirac_common/dirac_assertions.h>
00049 #include <vector>
00050 #include <cmath>
00051 namespace dirac
00052 {
00062     //Some basic enumeration types used throughout the codec ...//
00064 
00066     enum PredMode{ INTRA , REF1_ONLY , REF2_ONLY , REF1AND2, UNDEFINED };
00067 
00069     enum CompSort{ Y_COMP , U_COMP , V_COMP };
00070 
00072     enum AddOrSub{ ADD , SUBTRACT };
00073 
00075     enum Direction { FORWARD , BACKWARD };
00076 
00078     enum CtxAliases
00079     {//used for residual coding
00080         SIGN0_CTX,          // -sign, previous symbol is 0
00081         SIGN_POS_CTX,       // -sign, previous symbol is +ve
00082         SIGN_NEG_CTX,       // -sign, previous symbol is -ve
00083 
00084         // Follow bit contexts
00085         Z_FBIN1z_CTX,       // -bin 1, parent is zero, neighbours zero
00086         Z_FBIN1nz_CTX,      // -bin 1, parent is zero, neighbours non-zero
00087         Z_FBIN2_CTX,        // -bin 2, parent is zero
00088         Z_FBIN3_CTX,        // -bin 3, parent is zero
00089         Z_FBIN4_CTX,        // -bin 4, parent is zero
00090         Z_FBIN5_CTX,        // -bin 5, parent is zero
00091         Z_FBIN6plus_CTX,    // -bins 6 plus, parent is zero
00092 
00093         NZ_FBIN1z_CTX,      // -bin 1, parent is non-zero, neighbours zero
00094         NZ_FBIN1nz_CTX,     // -bin 1, parent is non-zero, neighbours non-zero
00095         NZ_FBIN2_CTX,       // -bin 2, parent is non-zero
00096         NZ_FBIN3_CTX,       // -bin 3, parent is non-zero
00097         NZ_FBIN4_CTX,       // -bin 4, parent is non-zero
00098         NZ_FBIN5_CTX,       // -bin 5, parent is non-zero
00099         NZ_FBIN6plus_CTX,   // -bins 6 plus, parent is non-zero
00100 
00101         // Information bit contexts
00102         INFO_CTX,
00103 
00104         BLOCK_SKIP_CTX,     // - blocks are skipped
00105         Q_OFFSET_FOLLOW_CTX,   // - code block quantiser offset magnitude
00106         Q_OFFSET_INFO_CTX,  // - code block quantiser offset info context
00107         Q_OFFSET_SIGN_CTX,   // - code block quantiser offset sign
00108         TOTAL_COEFF_CTXS   // The total number of coefficient contexts
00109     };
00110 
00112     enum MvCtxAliases
00113     {
00114         // DC value contexts //
00116 
00117         // Luma        
00118         YDC_FBIN1_CTX,       // -bin 1 of follow bits
00119         YDC_FBIN2plus_CTX,   // -remaining follow bins
00120         YDC_INFO_CTX,        // -info bit context
00121         YDC_SIGN_CTX,        // -sign context
00122 
00123         UDC_FBIN1_CTX,       
00124         UDC_FBIN2plus_CTX,   
00125         UDC_INFO_CTX,
00126         UDC_SIGN_CTX,      
00127 
00128         VDC_FBIN1_CTX,       
00129         VDC_FBIN2plus_CTX,   
00130         VDC_INFO_CTX,
00131         VDC_SIGN_CTX,      
00132         
00133 
00134         // Motion vector contexts //
00136 
00137         REF1x_FBIN1_CTX,     // -bin 1 of follow bits
00138         REF1x_FBIN2_CTX,     // -bin 2 of follow bits
00139         REF1x_FBIN3_CTX,     // -bin 3 of follows bits
00140         REF1x_FBIN4_CTX,     // -bin 4 of follow bits
00141         REF1x_FBIN5plus_CTX, // -bins 5 plus of follow bits
00142 
00143         REF1x_INFO_CTX,      // context for information bits 
00144 
00145         REF1x_SIGN_CTX,      // -sign
00146         
00147 
00148         REF1y_FBIN1_CTX,     
00149         REF1y_FBIN2_CTX,     
00150         REF1y_FBIN3_CTX,     
00151         REF1y_FBIN4_CTX,     
00152         REF1y_FBIN5plus_CTX, 
00153 
00154         REF1y_INFO_CTX,
00155 
00156         REF1y_SIGN_CTX,            
00157 
00158         REF2x_FBIN1_CTX,     
00159         REF2x_FBIN2_CTX,     
00160         REF2x_FBIN3_CTX,     
00161         REF2x_FBIN4_CTX,     
00162         REF2x_FBIN5plus_CTX, 
00163 
00164         REF2x_INFO_CTX,
00165 
00166         REF2x_SIGN_CTX,    
00167         
00168         REF2y_FBIN1_CTX,     
00169         REF2y_FBIN2_CTX,     
00170         REF2y_FBIN3_CTX,     
00171         REF2y_FBIN4_CTX,     
00172         REF2y_FBIN5plus_CTX, 
00173 
00174         REF2y_INFO_CTX,
00175 
00176         REF2y_SIGN_CTX,    
00177         
00178 
00179         // Prediction mode contexts
00180 
00181         PMODE_BIT0_CTX,     // -bit 0, prediction mode value
00182         PMODE_BIT1_CTX,     // -bin 1, prediction mode value
00183         
00184         
00185         // Macroblock contexts
00186        
00187         MB_SPLIT_BIN1_CTX,  // bin 1, MB split mode vals
00188         MB_SPLIT_BIN2_CTX,  // bin 2, MB split mode vals. Bin 3 not required
00189         
00190         MB_SPLIT_INFO_CTX,  // info context for MB split mode
00191         
00192         TOTAL_MV_CTXS       // The total number of motion vector contexts
00193     };
00194 
00195 
00201     VideoFormat IntToVideoFormat(int video_format);
00202 
00208     ChromaFormat IntToChromaFormat(int chroma_format);
00209 
00215     FrameRateType IntToFrameRateType(int frame_rate_idx);
00216 
00222     AspectRatioType IntToAspectRatioType(int aspect_ratio_idx);
00223 
00229     SignalRangeType IntToSignalRangeType(int signal_range_idx);
00230 
00236     MVPrecisionType IntToMVPrecisionType(int mv_prec);
00237 
00238     //Classes used throughout the codec//
00241     class FrameSort
00242     {
00243     public:
00244         FrameSort() { fs = 0x00; } // default intra non-ref
00245     
00246         void SetIntra() { fs &= 0xfe; }
00247         void SetInter() { fs |= 0x01; }
00248         void SetNonRef() { fs &= 0xfd; }
00249         void SetRef() { fs |= 0x02; }
00250     
00251         bool IsInter () const { return fs & 0x01; }
00252         bool IsIntra () const { return !IsInter(); }
00253         bool IsRef() const { return fs & 0x02; };
00254         bool IsNonRef() const { return !IsRef(); }
00255         
00256         void SetIntraNonRef() { SetIntra(); SetNonRef(); }
00257         void SetIntraRef() { SetIntra(); SetRef(); }
00258         void SetInterNonRef() { SetInter(); SetNonRef(); }
00259         void SetInterRef() { SetInter(); SetRef(); }
00260     
00261         bool IsIntraNonRef() const { return (fs & 0x03) == 0x00; }
00262         bool IsIntraRef() const { return (fs & 0x03) == 0x02; }
00263         bool IsInterNonRef() const { return (fs & 0x03) == 0x01; }
00264         bool IsInterRef() const { return (fs & 0x03) == 0x03; }
00265     
00266         void Clear() { fs=0x00; }
00267 
00268         static FrameSort IntraRefFrameSort()
00269         {
00270             FrameSort fs;
00271             fs.SetIntraRef();
00272             return fs;
00273         }
00274 
00275         static FrameSort InterRefFrameSort()
00276         {
00277             FrameSort fs;
00278             fs.SetInterRef();
00279             return fs;
00280         }
00281         
00282         static FrameSort IntraNonRefFrameSort()
00283         {
00284             FrameSort fs;
00285             fs.SetIntraNonRef();
00286             return fs;
00287         }
00288 
00289         static FrameSort InterNonRefFrameSort()
00290         {
00291             FrameSort fs;
00292             fs.SetInterNonRef();
00293             return fs;
00294         }
00295 
00296     private:
00297         unsigned char fs;
00298     };
00299 
00301 
00307     class PicArray: public TwoDArray<ValueType>
00308     {
00309     public:
00311 
00314         PicArray(): TwoDArray<ValueType>(){}
00315         
00317 
00321         PicArray(int height, int width, CompSort cs=Y_COMP);
00322         
00323         //copy constructor and assignment= derived by inheritance
00324         
00326         ~PicArray(){}
00327         
00329         const CompSort& CSort() const;
00330         
00332         void SetCSort(const CompSort cs);
00333         
00334     private:
00335         
00336         CompSort m_csort;
00337     };
00338 
00339 
00341     class CostType
00342     {
00343     public:
00345         double Error;
00346         
00348         double ENTROPY;
00349         
00351         double TOTAL;
00352     };
00353 
00354 
00356 
00361     class EntropyCorrector
00362     {
00363     public:
00365 
00369         EntropyCorrector(int depth);
00370         
00372         //NB: Assume default copy constructor, assignment = and destructor//
00374 
00376 
00380         float Factor(const int bandnum, const FrameSort fsort,const CompSort c) const;
00381 
00383 
00391         void Update(int bandnum, FrameSort fsort, CompSort c,int est_bits,int actual_bits);
00392         
00393     private:
00395         void Init();
00396 
00397         TwoDArray<float> m_Yfctrs;
00398         TwoDArray<float> m_Ufctrs;
00399         TwoDArray<float> m_Vfctrs;
00400     };
00401 
00403     class OLBParams
00404     {
00405         
00406     public:
00407         
00409         OLBParams(){}
00410         
00412         /*
00413             Constructor rationalises proposed parameters to allow suitable 
00414             overlap and fit in with chroma format
00415             \param    xblen    the horizontal block length    
00416             \param    yblen    the vertical block length
00417             \param    xblen    the horizontal block separation
00418             \param    yblen    the vertical block separation
00419 
00420         */
00421         OLBParams(const int xblen, const int yblen, 
00422                   const int xbsep, const int ybsep);
00423         
00424         // Gets ...
00425         
00427         int Xblen() const {return m_xblen;}
00428         
00430         int Yblen() const {return m_yblen;}
00431         
00433         int Xbsep() const {return m_xbsep;}
00434         
00436         int Ybsep() const {return m_ybsep;}
00437         
00439         int Xoffset() const {return m_xoffset;}
00440         
00442         int Yoffset() const {return m_yoffset;}
00443         
00444         // ... and sets
00445         
00447         void SetXblen( int xblen ){ m_xblen = xblen; m_xoffset = (m_xblen-m_xbsep)/2;}
00448         
00450         void SetYblen( int yblen ){ m_yblen = yblen; m_yoffset = (m_yblen-m_ybsep)/2;}
00451         
00453         void SetXbsep( int xbsep ){ m_xbsep = xbsep; m_xoffset = (m_xblen-m_xbsep)/2;}
00454         
00456         void SetYbsep( int ybsep ){ m_ybsep = ybsep; m_yoffset = (m_yblen-m_ybsep)/2;}
00457        
00458         bool operator == (const OLBParams bparams) const;
00459 
00460         // overloaded stream operators
00461         friend std::ostream & operator<< (std::ostream &, OLBParams &);
00462         friend std::istream & operator>> (std::istream &, OLBParams &);
00463         
00464         
00465     private:
00466         
00467         int m_xblen;
00468         int m_yblen;
00469         int m_xbsep;
00470         int m_ybsep;
00471         int m_xoffset;
00472         int m_yoffset;
00473     };
00474 
00476     class SeqParams
00477     {
00478     public:        
00480         SeqParams(const VideoFormat& video_format=VIDEO_FORMAT_CUSTOM,
00481                   bool set_defaults=true);
00482         
00484         //NB: Assume default copy constructor, assignment = and destructor//
00486         
00487         //gets ...
00489         int Xl() const {return m_xl;}
00490         
00492         int Yl() const {return m_yl;}
00493         
00495         ChromaFormat CFormat() const {return m_cformat;}
00496         
00498         int ChromaWidth() const;
00499         
00501         int ChromaHeight() const;
00502         
00504         int BitstreamVersion() const {return m_bs_ver;}
00505         
00507         VideoFormat GetVideoFormat() const { return m_video_format;}
00508 
00510         int GetVideoDepth() const { return m_video_depth; }
00511 
00512         // ... Sets
00513         
00515         void SetXl(int xlen) {m_xl = xlen;}
00516         
00518         void SetYl(int ylen) {m_yl = ylen;}
00519         
00521         void SetCFormat(ChromaFormat cf) {m_cformat=cf;}
00522         
00524         void SetVideoDepth(int vd){ m_video_depth=vd;}
00525 
00527         void SetBitstreamVersion(int bs_ver){m_bs_ver=bs_ver;}
00528        
00529 
00530     private:
00532         int m_xl;
00533         
00535         int m_yl;
00536         
00538         ChromaFormat m_cformat;
00539         
00541         unsigned char  m_bs_ver;
00542 
00544         VideoFormat m_video_format;
00545 
00547         int m_video_depth;
00548     };
00549 
00551     class Rational
00552     {
00553     public:
00555         unsigned int m_num;
00557         unsigned int m_denom;
00558     };
00559 
00561     class ParseParams
00562     {
00563     public:
00565         ParseParams(unsigned int au_pnum = 0);
00566 
00567         // Gets
00568 
00570         unsigned int AccessUnitPictureNumber() const { return m_au_pnum; }
00571 
00573         unsigned int MajorVersion() const { return m_major_ver; }
00574 
00576         unsigned int MinorVersion() const { return m_minor_ver; }
00577 
00579         unsigned int Profile() const { return m_profile; }
00580 
00582         unsigned int Level() const { return m_level; }
00583 
00584         // Sets
00585         
00587         void SetAccessUnitPictureNumber(unsigned int au_pnum) { m_au_pnum = au_pnum; }
00588 
00590         void SetMajorVersion(unsigned int major_ver) { m_major_ver = major_ver; }
00591 
00593         void SetMinorVersion(unsigned int minor_ver) { m_minor_ver = minor_ver; }
00594 
00596         void SetProfile(unsigned int level) { m_level = level; }
00597 
00599         void SetLevel(unsigned int profile) { m_profile = profile; }
00600 
00601     private:
00603         unsigned int m_au_pnum;
00605         unsigned int m_major_ver;
00607         unsigned int m_minor_ver;
00609         unsigned int m_profile;
00611         unsigned int m_level;
00612     };
00613 
00615     class SourceParams
00616     {
00617     public:
00619         SourceParams (const VideoFormat &vf = VIDEO_FORMAT_CUSTOM, 
00620                       bool set_defaults=true);
00621         
00623         //NB: Assume default copy constructor, assignment = and destructor//
00625 
00626         // Gets
00628         bool Interlace() const { return m_interlace; }
00629         
00631         bool TopFieldFirst() const { return m_topfieldfirst; }
00632         
00634         bool SequentialFields() const { return m_seq_fields; }
00635        
00637         Rational FrameRate() const { return m_framerate; }
00638        
00640         FrameRateType FrameRateIndex() const { return m_fr_idx; }
00641        
00643         Rational AspectRatio() const { return m_aspect_ratio; }
00644 
00646         AspectRatioType AspectRatioIndex() const { return m_asr_idx; }
00647 
00648         // Clean area parameters
00650         unsigned int CleanWidth() const { return m_clean_width; }
00652         unsigned int CleanHeight() const { return m_clean_height; }
00654         unsigned int LeftOffset() const { return m_left_offset; }
00656         unsigned int TopOffset() const { return m_top_offset; }
00657 
00658         // Signal Range parameters
00659 
00661         SignalRangeType SignalRangeIndex() const { return m_sr_idx; }
00662 
00664         unsigned int LumaOffset() const { return m_luma_offset; }
00666         unsigned int LumaExcursion() const { return m_luma_excursion; }
00668         unsigned int ChromaOffset() const { return m_chroma_offset; }
00670         unsigned int ChromaExcursion() const { return m_chroma_excursion; }
00671 
00673         unsigned int ColourSpecificationIndex() const { return m_cs_idx; }
00674 
00676         ColourPrimaries ColourPrimariesIndex() const { return m_col_primary; }
00678         ColourMatrix ColourMatrixIndex() const { return m_col_matrix; }
00680         TransferFunction TransferFunctionIndex() const { return m_transfer_func; }
00681     
00682         // Sets
00684         void SetInterlace(bool interlace) { m_interlace = interlace; }
00685         
00687         void SetTopFieldFirst(bool tff) { m_topfieldfirst = tff; }
00688         
00690         void SetSequentialFields(bool seq_flds) { m_seq_fields = seq_flds; }
00691        
00693         void SetFrameRate(const Rational &frate ) 
00694         {
00695             m_fr_idx = FRAMERATE_CUSTOM; m_framerate = frate;
00696         }
00697            
00699         void SetFrameRate(unsigned int fr_num, unsigned int fr_denom )
00700         {
00701             m_fr_idx = FRAMERATE_CUSTOM;
00702             m_framerate.m_num = fr_num;
00703             m_framerate.m_denom = fr_denom;
00704         }
00705        
00707         void SetFrameRate(FrameRateType fr); 
00708 
00710         void SetAspectRatio(const Rational &asr) 
00711         {
00712             m_asr_idx = ASPECT_RATIO_CUSTOM;
00713             m_aspect_ratio = asr;
00714         }
00715         
00717         void SetAspectRatio(unsigned int as_num, unsigned int as_denom )
00718         { 
00719             m_asr_idx = ASPECT_RATIO_CUSTOM;
00720             m_aspect_ratio.m_num = as_num;
00721             m_aspect_ratio.m_denom = as_denom;
00722         }
00723        
00725         void SetAspectRatio(AspectRatioType aspect_ratio); 
00726 
00727         // Clean area parameters
00729         void SetCleanWidth(unsigned int clean_width) { m_clean_width = clean_width; }
00731         void SetCleanHeight(unsigned int clean_height) { m_clean_height = clean_height; }
00733         void SetLeftOffset(unsigned int left_offset) { m_left_offset = left_offset; }
00735         void SetTopOffset(unsigned int top_offset) { m_top_offset = top_offset; }
00736 
00737         // Signal Range parameters
00739         void SetSignalRange(SignalRangeType sr);
00740 
00742         void SetLumaOffset(unsigned int luma_offset) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_offset = luma_offset; }
00744         void SetLumaExcursion(unsigned int luma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_excursion = luma_exc; }
00746         void SetChromaOffset(unsigned int chroma_off) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_offset = chroma_off; }
00748         void SetChromaExcursion(unsigned int chroma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_excursion = chroma_exc; }
00749 
00751         void SetColourSpecification(unsigned int cs_idx);
00753         void SetColourPrimariesIndex(unsigned int cp);
00755         void SetColourMatrixIndex(unsigned int cm);
00757         void SetTransferFunctionIndex(unsigned int tf);
00758 
00759     private:
00761         bool m_interlace;
00762         
00764         bool m_topfieldfirst;
00765         
00767         bool m_seq_fields;
00768 
00770         FrameRateType m_fr_idx;
00771 
00773         Rational m_framerate;
00774 
00776         AspectRatioType m_asr_idx;
00777 
00779         Rational m_aspect_ratio;
00780 
00781         // Clean area parameters
00782 
00784         unsigned int m_clean_width;
00785         
00787         unsigned int m_clean_height;
00788         
00790         unsigned int m_left_offset;
00791         
00793         unsigned int m_top_offset;
00794 
00795         // signal range parameters
00796 
00798         SignalRangeType m_sr_idx;
00799 
00801         unsigned int m_luma_offset;
00803         unsigned int m_luma_excursion;
00805         unsigned int m_chroma_offset;
00807         unsigned int m_chroma_excursion;
00808 
00810         unsigned int m_cs_idx;
00811 
00813         ColourPrimaries m_col_primary;
00814 
00815         // Colour Matrix index
00816         ColourMatrix m_col_matrix;
00817 
00818         // Transfer function index
00819         TransferFunction m_transfer_func;
00820     };
00821 
00823     class FrameParams 
00824     {
00825         
00826     public:
00828         FrameParams();
00829         
00831 
00834         FrameParams(const ChromaFormat& cf, int xlen, int ylen, int c_xlen, int c_ylen, unsigned int video_depth);
00835         
00837 
00840         FrameParams(const ChromaFormat& cf, const FrameSort& fs);
00841         
00843         /*
00844             All data is derived from the sequence parameters
00845         */
00846         FrameParams(const SeqParams& sparams);
00847         
00849         /*
00850            All data is derived from the sequence parameters
00851         */
00852         FrameParams(const SeqParams& sparams, const FrameSort& fs);
00853         
00855         //NB: Assume default copy constructor, assignment = and destructor//
00857         
00858         // Gets ...
00859         
00861         const ChromaFormat& CFormat() const{return m_cformat;}
00862         
00864         int Xl() const{return m_xl;}
00865         
00867         int Yl() const{return m_yl;}
00868         
00870         int ChromaXl() const{return m_chroma_xl;}
00871         
00873         int ChromaYl() const{return m_chroma_yl;}
00874         
00876         const FrameSort& FSort() const {return m_fsort;}
00877         
00879         int FrameNum() const {return m_fnum;}
00880         
00882         bool IsBFrame() const;
00883         
00885         int ExpiryTime() const {return m_expiry_time;}
00886         
00888         bool Output() const {return m_output;}
00889         
00891         const std::vector<int>& Refs() const {return m_refs;}
00892         
00894         std::vector<int>& Refs(){return m_refs;}
00895         
00897         unsigned int NumRefs()const {return m_refs.size();}
00898         
00900         FrameType GetFrameType () const { return m_frame_type; }
00901 
00903         ReferenceType GetReferenceType() const { return m_reference_type;}
00904         
00906         unsigned int GetVideoDepth() const{return m_video_depth;}
00907 
00908         // ... Sets
00909         
00911         void SetFSort( const FrameSort& fs );
00912         
00914         void SetFrameType(const FrameType ftype);
00915         
00917         void SetReferenceType(const ReferenceType rtype);
00918         
00920         void SetFrameNum( const int fn ){ m_fnum=fn; }
00921         
00923         void SetExpiryTime( const int expt ){ m_expiry_time=expt; }
00924         
00926         void SetAsOutput(){m_output=true;}
00927         
00929         void SetCFormat(ChromaFormat cf){ m_cformat = cf; }
00930         
00932         void SetXl(int xl){m_xl = xl; }
00933         
00935         void SetYl(int yl){m_yl = yl; }
00936         
00938         void SetChromaXl(int xl){m_chroma_xl = xl; }
00939         
00941         void SetChromaYl(int yl){m_chroma_yl = yl; }
00942         
00944         void SetVideoDepth(int vd) { m_video_depth = vd; }
00945         
00947         std::vector<int>& RetiredFrames() const {return m_retd_list;}
00948         
00950         std::vector<int>& RetiredFrames() {return m_retd_list;}
00951         
00952     private:
00953         
00955         ChromaFormat m_cformat;
00956         
00958         int m_xl;
00959         
00961         int m_yl;
00962         
00964         FrameSort m_fsort;
00965         
00967         std::vector<int> m_refs;
00968         
00970         int m_expiry_time;
00971         
00973         int m_fnum;        
00974 
00976         FrameType m_frame_type;
00977 
00979         ReferenceType m_reference_type;
00980         
00982         bool m_output;
00983 
00985         int m_chroma_xl;        
00986         
00988         int m_chroma_yl;        
00989         
00991         mutable std::vector<int> m_retd_list;
00992 
00994         unsigned int m_video_depth;
00995         
00996     };
00997 
00999     class CodeBlocks
01000     {
01001     public:
01003         CodeBlocks () : m_hblocks(0), m_vblocks(0)
01004         {}
01005 
01007         CodeBlocks (unsigned int  hblocks, unsigned int vblocks) : 
01008             m_hblocks(hblocks),
01009             m_vblocks(vblocks)
01010             {}
01011 
01012         // Gets
01014         unsigned int HorizontalCodeBlocks() const { return m_hblocks; }
01016         unsigned int VerticalCodeBlocks() const { return m_vblocks; }
01017         // Sets 
01019         void SetHorizontalCodeBlocks(unsigned int hblocks) { m_hblocks = hblocks; }
01021         void SetVerticalCodeBlocks(unsigned int vblocks) { m_vblocks = vblocks; }
01022     private:
01024         unsigned int m_hblocks;
01026         unsigned int m_vblocks;
01027     };
01029 
01032     class CodecParams
01033     {
01034     public:
01035         
01037         CodecParams(const VideoFormat& vd, FrameType ftype, unsigned int num_refs, bool set_defaults);
01038         
01040             //NB: Assume default copy constructor, assignment = and destructor//
01042         
01043         // Gets ...    
01044         
01046         int XNumMB() const {return m_x_num_mb;}
01047         
01049         int YNumMB() const {return m_y_num_mb;}
01050         
01052         int XNumBlocks() const {return m_x_num_blocks;}
01053         
01055         int YNumBlocks() const {return m_y_num_blocks;}
01056         
01058         bool Verbose() const {return m_verbose;}
01059         
01061         bool Interlace() const {return m_interlace;}
01062         
01064         bool TopFieldFirst() const {return m_topfieldfirst;}    
01065         
01067         const OLBParams& LumaBParams(int n) const {return m_lbparams[n];}
01068         
01070         const OLBParams& ChromaBParams(int n) const {return m_cbparams[n];}    
01071 
01073         int OrigXl() const {return m_orig_xl;}
01074 
01076         int OrigYl() const {return m_orig_yl;}
01077 
01079         MVPrecisionType MVPrecision() const { return m_mv_precision; }
01080 
01082         bool ZeroTransform() const { return m_zero_transform; } 
01083 
01085         WltFilter TransformFilter() const { return m_wlt_filter; } 
01086 
01088         unsigned int TransformDepth() const { return m_wlt_depth; } 
01089 
01091         CodeBlockMode GetCodeBlockMode() const { return m_cb_mode; } 
01092 
01094         bool SpatialPartition() const { return m_spatial_partition; } 
01095         
01097         bool DefaultSpatialPartition() const { return m_def_spatial_partition; } 
01099         const CodeBlocks &GetCodeBlocks(unsigned int level) const;
01100 
01102         VideoFormat GetVideoFormat() const { return m_video_format; } 
01103              
01105         bool UsingGlobalMotion() const { return m_use_global_motion; } 
01106 
01108         unsigned int FrameWeightsBits() const { return m_frame_weights_bits; } 
01109 
01111         unsigned int Ref1Weight() const { return m_ref1_weight; } 
01112 
01114         unsigned int Ref2Weight() const { return m_ref2_weight; } 
01115              
01116         // ... and Sets
01118         void SetXNumMB(const int xn){m_x_num_mb=xn;}    
01119         
01121         void SetYNumMB(const int yn){m_y_num_mb=yn;}
01122         
01124         void SetXNumBlocks(const int xn){m_x_num_blocks=xn;}
01125         
01127         void SetYNumBlocks(const int yn){m_y_num_blocks=yn;}
01128         
01130         void SetVerbose(bool v){m_verbose=v;}
01131         
01133         void SetInterlace(bool intlc){m_interlace=intlc;}
01134         
01136         void SetTopFieldFirst(bool topf){m_topfieldfirst=topf;}
01137         
01139         void SetBlockSizes(const OLBParams& olbparams , const ChromaFormat cformat);
01141         void SetLumaBlockParams(const OLBParams& olbparams) {m_lbparams[2] = olbparams;}
01142 
01144         void SetOrigXl(const int x){m_orig_xl=x;}
01145 
01147         void SetOrigYl(const int y){m_orig_yl=y;}
01148 
01150         void SetMVPrecision(const MVPrecisionType p)
01151         {
01152             // Assert in debug mode. Maybe we should throw an exception???
01153             TESTM((p >=0 && p <=3), "Motion precision value in range 0..3");
01154             m_mv_precision = p;
01155         }
01156 
01158         void SetZeroTransform(bool zero_transform)  { m_zero_transform = zero_transform; } 
01159 
01161         void SetTransformFilter(const WltFilter wf) { m_wlt_filter=wf; } 
01162 
01164         void SetTransformFilter(unsigned int wf_idx);
01165 
01167         void SetTransformDepth(unsigned int wd);
01168 
01170         void SetCodeBlockMode(unsigned int cb_mode);
01171 
01173         void SetSpatialPartition(bool spatial_partition) { m_spatial_partition=spatial_partition; } 
01174 
01176         void SetDefaultSpatialPartition(bool def_spatial_partition) { m_def_spatial_partition=def_spatial_partition; } 
01177         
01179         void  SetCodeBlocks(unsigned int level, unsigned int hblocks, unsigned int vblocks);
01180         
01182         void  SetDefaultCodeBlocks(const FrameType& ftype);
01183 
01185         void SetVideoFormat(const VideoFormat vd) { m_video_format=vd; } 
01186 
01188         void SetUsingGlobalMotion(bool gm) { m_use_global_motion=gm; } 
01189 
01191         void SetFrameWeightsPrecision(unsigned int wt_prec) { m_frame_weights_bits=wt_prec; } 
01192 
01194         void SetRef1Weight(unsigned int wt) { m_ref1_weight=wt; } 
01195 
01197         void SetRef2Weight(unsigned int wt) { m_ref2_weight=wt; } 
01198 
01199     protected:
01201         WltFilter TransformFilter (unsigned int wf_idx);
01202     private:
01203         
01205         int m_x_num_mb;
01206         
01208         int m_y_num_mb;
01209         
01211         int m_x_num_blocks;    
01212         
01214         int m_y_num_blocks;
01215         
01217         bool m_verbose;
01218         
01220         bool m_interlace;
01221         
01223         bool m_topfieldfirst;
01224         
01225         OneDArray<OLBParams> m_lbparams;
01226         OneDArray<OLBParams> m_cbparams;
01227 
01229         int m_orig_xl;
01230 
01232         int m_orig_yl;
01233 
01235         MVPrecisionType m_mv_precision;
01236 
01238         VideoFormat m_video_format;
01239 
01241         bool m_use_global_motion;
01242 
01244         unsigned int m_frame_weights_bits;
01245 
01247         unsigned int m_ref1_weight;
01248         
01250         unsigned int m_ref2_weight;
01251 
01253         bool m_zero_transform;
01254 
01256         WltFilter m_wlt_filter;
01257 
01259         unsigned int m_wlt_depth;
01260 
01262         CodeBlockMode m_cb_mode;
01263 
01265         bool m_spatial_partition;
01266 
01268         bool m_def_spatial_partition;
01269 
01271         OneDArray<CodeBlocks> m_cb;
01272     };
01273 
01275 
01278     class EncoderParams: public CodecParams
01279     {
01280         //codec params plus parameters relating solely to the operation of the encoder
01281         
01282     public:
01284         EncoderParams(const VideoFormat& video_format,
01285                       FrameType ftype = INTER_FRAME,
01286                       unsigned int num_refs = 2, 
01287                       bool set_defaults=true);
01288         
01290             //NB: Assume default copy constructor, assignment = and destructor//
01291             //This means pointers are copied, not the objects they point to.////       
01293         
01294          // Gets ...
01295 
01297         bool LocalDecode() const {return m_loc_decode;}
01298 
01300         bool Lossless() const {return m_lossless;}
01301 
01303         float Qf() const {return m_qf;}
01304 
01306 
01311         int NumL1() const {return m_num_L1;}
01312 
01314         int L1Sep() const {return m_L1_sep;}
01315 
01317         float UFactor() const {return m_ufactor;}
01318 
01320         float VFactor() const {return m_vfactor;}
01321 
01323         float CPD() const {return m_cpd;}
01324 
01326         bool Denoise() const {return m_denoise;}
01327 
01329         float ILambda() const {return m_I_lambda;}
01330 
01332         float L1Lambda() const {return m_L1_lambda;}
01333 
01335         float L2Lambda() const {return m_L2_lambda;}
01336 
01338         float L1MELambda() const {return m_L1_me_lambda;}
01339 
01341         float L2MELambda() const {return m_L2_me_lambda;}
01342 
01344         int GOPLength() const { if (m_num_L1>0) return (m_num_L1+1)*m_L1_sep;
01345                                 return (m_num_L1==0) ? 10 : 0; }
01346 
01348         char * OutputPath() const {return ( char* ) m_output_path.c_str();}
01349         
01351         const EntropyCorrector& EntropyFactors() const {return *m_ent_correct;}
01352         
01354         EntropyCorrector& EntropyFactors() {return *m_ent_correct;}
01355         
01357         WltFilter IntraTransformFilter() { return m_intra_wltfilter; }
01358         
01360         WltFilter InterTransformFilter() { return m_inter_wltfilter; }
01361         
01363         int TargetRate() {return m_target_rate;}
01364 
01365         // ... and Sets
01366 
01368         void SetLocalDecode( const bool decode ){m_loc_decode=decode;}
01369 
01371         void SetLossless(const bool l){m_lossless = l;}
01372 
01374         void SetQf(const float qfac){ m_qf=std::min(qfac,12.5f); CalcLambdas(m_qf); }
01375 
01377         void SetNumL1(const int nl){m_num_L1=nl;}
01378 
01380         void SetL1Sep(const int lsep){m_L1_sep=lsep;}
01381 
01383         void SetUFactor(const float uf){m_ufactor=uf;}
01384 
01386         void SetVFactor(const float vf){m_vfactor=vf;}
01387 
01389         void SetCPD(const float cpd){m_cpd=cpd;}
01390 
01391 
01393         void SetDenoise(const bool denoise){m_denoise=denoise;}
01394 
01396         void SetOutputPath(const char * op){ m_output_path = op; }
01397         
01399         void SetEntropyFactors(EntropyCorrector* entcorrect){m_ent_correct=entcorrect;}
01401         void SetIntraTransformFilter(unsigned int wf_idx);
01402        
01404         void SetInterTransformFilter(unsigned int wf_idx);
01405         
01407         void SetIntraTransformFilter(WltFilter wf) { m_intra_wltfilter = wf; }
01408        
01410         void SetInterTransformFilter(WltFilter wf) { m_inter_wltfilter = wf; }
01411         
01413         void SetTargetRate(const int rate){m_target_rate = rate;}
01414     private:
01415             
01417         void CalcLambdas(const float qf);
01418 
01419     private:
01420 
01422         bool m_loc_decode;
01423       
01425         bool m_lossless;
01426 
01428         float m_qf; 
01429         
01431         int m_num_L1;
01432         
01434         int m_L1_sep;   
01435         
01437         float m_ufactor;
01438         
01440         float m_vfactor;
01441         
01443         float m_cpd;
01444         
01446         bool m_denoise;
01447         
01449         float m_I_lambda;
01450 
01452         float m_L1_lambda;
01453 
01455         float m_L2_lambda;
01456         
01458         float m_L1_me_lambda;
01459 
01461         float m_L2_me_lambda; 
01462         
01464         EntropyCorrector* m_ent_correct;
01465         
01467         std::string m_output_path;
01468         
01470         WltFilter m_intra_wltfilter;
01471 
01473         WltFilter m_inter_wltfilter;
01474         
01476         int m_target_rate;
01477      
01478     };
01479 
01481 
01484     class DecoderParams: public CodecParams
01485     {
01486     public:
01488         DecoderParams(const VideoFormat& video_format = VIDEO_FORMAT_CIF, FrameType ftype=INTRA_FRAME, unsigned int num_refs = 0, bool set_defaults = false);
01489         
01491             //NB: Assume default copy constructor, assignment = and destructor//
01492             //This means pointers are copied, not the objects they point to.////       
01494         
01495        
01496     private:        
01497        
01498     };
01499 
01501     inline ValueType BChk(const ValueType &num, const ValueType &max)
01502     {
01503         if(num < 0) return 0;
01504         else if(num >= max) return max-1;
01505         else return num;
01506     }
01507 
01509     class QuantiserLists
01510     {
01511     public:
01513         QuantiserLists();
01514 
01516         inline int QuantFactor4( const int index ) const {return m_qflist4[index]; }
01517 
01519         inline int IntraQuantOffset4( const int index ) const {return m_intra_offset4[index]; }
01521         inline int InterQuantOffset4( const int index ) const {return m_inter_offset4[index]; }
01522 
01524         inline int MaxQIndex() const {return m_max_qindex; }
01525     
01526 
01527     private:
01528         unsigned int m_max_qindex;
01529         OneDArray<int> m_qflist4;
01530         OneDArray<int> m_intra_offset4;
01531         OneDArray<int> m_inter_offset4;
01532 
01533     };
01534 
01536     static const QuantiserLists dirac_quantiser_lists;
01537 
01538 } // namespace dirac
01539 
01540 #endif

© 2004 British Broadcasting Corporation. Dirac code licensed under the Mozilla Public License (MPL) Version 1.1.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.