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.75 2008/05/27 01:29:53 asuraparaju Exp $ $Name: Dirac_0_10_0 $
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 #ifdef  _MSC_VER
00047 #define  _CRT_SECURE_NO_DEPRECATE
00048 #endif // _MSC_VER
00049 
00050 #include <libdirac_common/arrays.h>
00051 #include <libdirac_common/common_types.h>
00052 #include <libdirac_common/dirac_assertions.h>
00053 #include <vector>
00054 #include <cmath>
00055 namespace dirac
00056 {
00066     //Some basic types used throughout the codec ...//
00068 
00070     typedef short ValueType;
00071 
00072 #if !defined(HAVE_MMX)
00073 
00074     typedef int CoeffType;
00075 #else
00076 
00077     typedef short CoeffType;
00078 #endif
00079 
00081     typedef int CalcValueType;
00082 
00084     enum PredMode{ INTRA , REF1_ONLY , REF2_ONLY , REF1AND2, UNDEFINED };
00085 
00087     enum CompSort{ Y_COMP , U_COMP , V_COMP };
00088 
00090     enum AddOrSub{ ADD , SUBTRACT };
00091 
00093     enum Direction { FORWARD , BACKWARD };
00094 
00096     enum CtxAliases
00097     {//used for residual coding
00098         SIGN0_CTX,          // -sign, previous symbol is 0
00099         SIGN_POS_CTX,       // -sign, previous symbol is +ve
00100         SIGN_NEG_CTX,       // -sign, previous symbol is -ve
00101 
00102         // Follow bit contexts
00103         Z_FBIN1z_CTX,       // -bin 1, parent is zero, neighbours zero
00104         Z_FBIN1nz_CTX,      // -bin 1, parent is zero, neighbours non-zero
00105         Z_FBIN2_CTX,        // -bin 2, parent is zero
00106         Z_FBIN3_CTX,        // -bin 3, parent is zero
00107         Z_FBIN4_CTX,        // -bin 4, parent is zero
00108         Z_FBIN5_CTX,        // -bin 5, parent is zero
00109         Z_FBIN6plus_CTX,    // -bins 6 plus, parent is zero
00110 
00111         NZ_FBIN1z_CTX,      // -bin 1, parent is non-zero, neighbours zero
00112         NZ_FBIN1nz_CTX,     // -bin 1, parent is non-zero, neighbours non-zero
00113         NZ_FBIN2_CTX,       // -bin 2, parent is non-zero
00114         NZ_FBIN3_CTX,       // -bin 3, parent is non-zero
00115         NZ_FBIN4_CTX,       // -bin 4, parent is non-zero
00116         NZ_FBIN5_CTX,       // -bin 5, parent is non-zero
00117         NZ_FBIN6plus_CTX,   // -bins 6 plus, parent is non-zero
00118 
00119         // Information bit contexts
00120         INFO_CTX,
00121 
00122         BLOCK_SKIP_CTX,     // - blocks are skipped
00123         Q_OFFSET_FOLLOW_CTX,   // - code block quantiser offset magnitude
00124         Q_OFFSET_INFO_CTX,  // - code block quantiser offset info context
00125         Q_OFFSET_SIGN_CTX,   // - code block quantiser offset sign
00126         TOTAL_COEFF_CTXS   // The total number of coefficient contexts
00127     };
00128 
00130     enum MvCtxAliases
00131     {
00132         // DC value contexts //
00134 
00135         DC_FBIN1_CTX,
00136         DC_FBIN2plus_CTX,
00137         DC_INFO_CTX,
00138         DC_SIGN_CTX,
00139 
00140         // Motion vector contexts //
00142 
00143 
00144         MV_FBIN1_CTX,
00145         MV_FBIN2_CTX,
00146         MV_FBIN3_CTX,
00147         MV_FBIN4_CTX,
00148         MV_FBIN5plus_CTX,
00149 
00150         MV_INFO_CTX,
00151 
00152         MV_SIGN_CTX,
00153 
00154 
00155         // Prediction mode contexts
00156 
00157         PMODE_BIT0_CTX,     // -bit 0, prediction mode value
00158         PMODE_BIT1_CTX,     // -bin 1, prediction mode value
00159 
00160 
00161         // Macroblock contexts
00162 
00163         MB_SPLIT_BIN1_CTX,  // bin 1, MB split mode vals
00164         MB_SPLIT_BIN2_CTX,  // bin 2, MB split mode vals. Bin 3 not required
00165 
00166         MB_SPLIT_INFO_CTX,  // info context for MB split mode
00167 
00168         TOTAL_MV_CTXS       // The total number of motion vector contexts
00169     };
00170 
00171 
00177     VideoFormat IntToVideoFormat(int video_format);
00178 
00184     ChromaFormat IntToChromaFormat(int chroma_format);
00185 
00191     FrameRateType IntToFrameRateType(int frame_rate_idx);
00192 
00198     PixelAspectRatioType IntToPixelAspectRatioType(int pix_asr_idx);
00199 
00205     SignalRangeType IntToSignalRangeType(int signal_range_idx);
00206 
00212     MVPrecisionType IntToMVPrecisionType(int mv_prec);
00213 
00214     //Classes used throughout the codec//
00216  
00218     class Rational
00219     {
00220     public:
00222         unsigned int m_num;
00224         unsigned int m_denom;
00225     };
00226 
00228     class PictureSort
00229     {
00230     public:
00231         PictureSort() { fs = 0x00; } // default intra non-ref
00232 
00233         void SetIntra() { fs &= 0xfe; }
00234         void SetInter() { fs |= 0x01; }
00235         void SetNonRef() { fs &= 0xfd; }
00236         void SetRef() { fs |= 0x02; }
00237 
00238         bool IsInter () const { return fs & 0x01; }
00239         bool IsIntra () const { return !IsInter(); }
00240         bool IsRef() const { return fs & 0x02; };
00241         bool IsNonRef() const { return !IsRef(); }
00242 
00243         void SetIntraNonRef() { SetIntra(); SetNonRef(); }
00244         void SetIntraRef() { SetIntra(); SetRef(); }
00245         void SetInterNonRef() { SetInter(); SetNonRef(); }
00246         void SetInterRef() { SetInter(); SetRef(); }
00247 
00248         bool IsIntraNonRef() const { return (fs & 0x03) == 0x00; }
00249         bool IsIntraRef() const { return (fs & 0x03) == 0x02; }
00250         bool IsInterNonRef() const { return (fs & 0x03) == 0x01; }
00251         bool IsInterRef() const { return (fs & 0x03) == 0x03; }
00252 
00253         void Clear() { fs=0x00; }
00254 
00255         static PictureSort IntraRefPictureSort()
00256         {
00257             PictureSort fs;
00258             fs.SetIntraRef();
00259             return fs;
00260         }
00261 
00262         static PictureSort InterRefPictureSort()
00263         {
00264             PictureSort fs;
00265             fs.SetInterRef();
00266             return fs;
00267         }
00268 
00269         static PictureSort IntraNonRefPictureSort()
00270         {
00271             PictureSort fs;
00272             fs.SetIntraNonRef();
00273             return fs;
00274         }
00275 
00276         static PictureSort InterNonRefPictureSort()
00277         {
00278             PictureSort fs;
00279             fs.SetInterNonRef();
00280             return fs;
00281         }
00282 
00283     private:
00284         unsigned char fs;
00285     };
00286 
00288     class SourceParams
00289     {
00290     public:
00292         SourceParams (const VideoFormat &vf = VIDEO_FORMAT_CUSTOM,
00293                       bool set_defaults=true);
00294 
00296         //NB: Assume default copy constructor, assignment = and destructor//
00298 
00299         // Gets
00301         VideoFormat GetVideoFormat() const { return m_video_format;}
00302 
00304         unsigned int Xl() const {return m_xl;}
00305 
00307         unsigned int Yl() const {return m_yl;}
00308 
00310         ChromaFormat CFormat() const {return m_cformat;}
00311 
00313         int ChromaWidth() const;
00314 
00316         int ChromaHeight() const;
00317 
00319         unsigned int SourceSampling() const { return m_source_sampling; }
00320 
00322         bool TopFieldFirst() const { return m_topfieldfirst; }
00323 
00325         Rational FrameRate() const { return m_framerate; }
00326 
00328         FrameRateType FrameRateIndex() const { return m_fr_idx; }
00329 
00331         Rational PixelAspectRatio() const { return m_pixel_aspect_ratio; }
00332 
00334         PixelAspectRatioType PixelAspectRatioIndex() const { return m_pix_asr_idx; }
00335 
00336         // Clean area parameters
00338         unsigned int CleanWidth() const { return m_clean_width; }
00340         unsigned int CleanHeight() const { return m_clean_height; }
00342         unsigned int LeftOffset() const { return m_left_offset; }
00344         unsigned int TopOffset() const { return m_top_offset; }
00345 
00346         // Signal Range parameters
00347 
00349         SignalRangeType SignalRangeIndex() const { return m_sr_idx; }
00350 
00352         unsigned int LumaOffset() const { return m_luma_offset; }
00354         unsigned int LumaExcursion() const { return m_luma_excursion; }
00356         unsigned int ChromaOffset() const { return m_chroma_offset; }
00358         unsigned int ChromaExcursion() const { return m_chroma_excursion; }
00359 
00361         unsigned int ColourSpecificationIndex() const { return m_cs_idx; }
00362 
00364         ColourPrimaries ColourPrimariesIndex() const { return m_col_primary; }
00366         ColourMatrix ColourMatrixIndex() const { return m_col_matrix; }
00368         TransferFunction TransferFunctionIndex() const { return m_transfer_func; }
00369 
00370         // Sets
00371 
00373         void SetXl(unsigned int xlen) {m_xl = xlen;}
00374 
00376         void SetYl(unsigned int ylen) {m_yl = ylen;}
00377 
00379         void SetCFormat(ChromaFormat cf) {m_cformat=cf;}
00380 
00382         void SetSourceSampling(unsigned int source_sampling) 
00383         { m_source_sampling = source_sampling; }
00384 
00386         void SetTopFieldFirst(bool tff) { m_topfieldfirst = tff; }
00387 
00389         void SetVideoFormat(VideoFormat vf){ m_video_format=vf;}
00390 
00392         void SetFrameRate(const Rational &frate )
00393         {
00394             m_fr_idx = FRAMERATE_CUSTOM; m_framerate = frate;
00395         }
00396 
00398         void SetFrameRate(unsigned int fr_num, unsigned int fr_denom )
00399         {
00400             m_fr_idx = FRAMERATE_CUSTOM;
00401             m_framerate.m_num = fr_num;
00402             m_framerate.m_denom = fr_denom;
00403         }
00404 
00406         void SetFrameRate(FrameRateType fr);
00407 
00409         void SetPixelAspectRatio(const Rational &pix_asr)
00410         {
00411             m_pix_asr_idx = PIXEL_ASPECT_RATIO_CUSTOM;
00412             m_pixel_aspect_ratio = pix_asr;
00413         }
00414 
00416         void SetPixelAspectRatio(unsigned int pix_as_num, unsigned int pix_as_denom )
00417         {
00418             m_pix_asr_idx = PIXEL_ASPECT_RATIO_CUSTOM;
00419             m_pixel_aspect_ratio.m_num = pix_as_num;
00420             m_pixel_aspect_ratio.m_denom = pix_as_denom;
00421         }
00422 
00424         void SetPixelAspectRatio(PixelAspectRatioType pixel_aspect_ratio);
00425 
00426         // Clean area parameters
00428         void SetCleanWidth(unsigned int clean_width) { m_clean_width = clean_width; }
00430         void SetCleanHeight(unsigned int clean_height) { m_clean_height = clean_height; }
00432         void SetLeftOffset(unsigned int left_offset) { m_left_offset = left_offset; }
00434         void SetTopOffset(unsigned int top_offset) { m_top_offset = top_offset; }
00435 
00436         // Signal Range parameters
00438         void SetSignalRange(SignalRangeType sr);
00439 
00441         void SetLumaOffset(unsigned int luma_offset) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_offset = luma_offset; }
00443         void SetLumaExcursion(unsigned int luma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_excursion = luma_exc; }
00445         void SetChromaOffset(unsigned int chroma_off) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_offset = chroma_off; }
00447         void SetChromaExcursion(unsigned int chroma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_excursion = chroma_exc; }
00448 
00450         void SetColourSpecification(unsigned int cs_idx);
00452         void SetColourPrimariesIndex(unsigned int cp);
00454         void SetColourMatrixIndex(unsigned int cm);
00456         void SetTransferFunctionIndex(unsigned int tf);
00457 
00458     private:
00460         VideoFormat m_video_format;
00461 
00463         unsigned int m_xl;
00464 
00466         unsigned int m_yl;
00467 
00469         ChromaFormat m_cformat;
00470 
00472         unsigned int m_source_sampling;
00473 
00475         bool m_topfieldfirst;
00476 
00478         FrameRateType m_fr_idx;
00479 
00481         Rational m_framerate;
00482 
00484         PixelAspectRatioType m_pix_asr_idx;
00485 
00487         Rational m_pixel_aspect_ratio;
00488 
00489         // Clean area parameters
00490 
00492         unsigned int m_clean_width;
00493 
00495         unsigned int m_clean_height;
00496 
00498         unsigned int m_left_offset;
00499 
00501         unsigned int m_top_offset;
00502 
00503         // signal range parameters
00504 
00506         SignalRangeType m_sr_idx;
00507 
00509         unsigned int m_luma_offset;
00511         unsigned int m_luma_excursion;
00513         unsigned int m_chroma_offset;
00515         unsigned int m_chroma_excursion;
00516 
00518         unsigned int m_cs_idx;
00519 
00521         ColourPrimaries m_col_primary;
00522 
00523         // Colour Matrix index
00524         ColourMatrix m_col_matrix;
00525 
00526         // Transfer function index
00527         TransferFunction m_transfer_func;
00528     };
00529 
00530 
00532     class PictureParams
00533     {
00534 
00535     public:
00537         PictureParams();
00538 
00540 
00543         PictureParams(const ChromaFormat& cf, int xlen, int ylen,
00544                     unsigned int luma_depth, unsigned int chroma_depth);
00545 
00547 
00550         PictureParams(const ChromaFormat& cf, const PictureSort& fs);
00551 
00553         /*
00554             All data is derived from the sequence parameters
00555         */
00556         PictureParams(const SourceParams& sparams);
00557 
00559         /*
00560            All data is derived from the sequence parameters
00561         */
00562         PictureParams(const SourceParams& sparams, const PictureSort& fs);
00563 
00565         //NB: Assume default copy constructor, assignment = and destructor//
00567 
00568         // Gets ...
00569 
00571         const ChromaFormat& CFormat() const{return m_cformat;}
00572 
00574         int Xl() const {return m_xl;}
00575 
00577         int Yl() const {return m_yl;}
00578 
00580         int ChromaXl() const{return m_cxl;}
00581 
00583         int ChromaYl() const{return m_cyl;}
00584 
00586         unsigned int LumaDepth() const { return m_luma_depth; }
00587 
00589         unsigned int ChromaDepth() const { return m_chroma_depth; }
00590 
00592         const PictureSort& PicSort() const {return m_psort;}
00593 
00595         int PictureNum() const {return m_fnum;}
00596 
00598         int RetiredPictureNum() const {return m_retd_fnum;}
00599 
00601         bool IsBPicture() const;
00602 
00604         int ExpiryTime() const {return m_expiry_time;}
00605 
00607         bool Output() const {return m_output;}
00608 
00610         const std::vector<int>& Refs() const {return m_refs;}
00611 
00613         std::vector<int>& Refs(){return m_refs;}
00614 
00616         unsigned int NumRefs()const {return m_refs.size();}
00617 
00619         PictureType GetPictureType () const { return m_picture_type; }
00620 
00622         ReferenceType GetReferenceType() const { return m_reference_type;}
00623 
00625         bool UsingAC() const { return m_using_ac; }
00626 
00627         // ... Sets
00628 
00630         void SetPicSort( const PictureSort& ps );
00631 
00633         void SetPictureType(const PictureType ftype);
00634 
00636         void SetReferenceType(const ReferenceType rtype);
00637 
00639         void SetPictureNum( const int fn ){ m_fnum=fn; }
00640 
00642         void SetExpiryTime( const int expt ){ m_expiry_time=expt; }
00643 
00645         void SetAsOutput(){m_output=true;}
00646 
00648         void SetCFormat(ChromaFormat cf){ m_cformat = cf; }
00649 
00651         void SetXl(int xlen);
00652 
00654         void SetYl(int ylen);
00655 
00657         void SetLumaDepth(unsigned int luma_depth) { m_luma_depth = luma_depth; }
00658 
00660         void SetChromaDepth(unsigned int chroma_depth) { m_chroma_depth = chroma_depth; }
00661 
00663         void SetRetiredPictureNum(int retd_fnum) {m_retd_fnum = retd_fnum;}
00664 
00666         void SetUsingAC(bool using_ac) { m_using_ac = using_ac; }
00667 
00668     private:
00669 
00671         ChromaFormat m_cformat;
00672 
00674         PictureSort m_psort;
00675 
00677         std::vector<int> m_refs;
00678 
00680         int m_expiry_time;
00681 
00683         int m_fnum;
00684 
00686         PictureType m_picture_type;
00687 
00689         ReferenceType m_reference_type;
00690 
00692         bool m_output;
00693 
00695         mutable  int m_retd_fnum;
00696 
00698         int m_xl;
00699 
00701         int m_yl;
00702 
00704         int m_cxl;
00705 
00707         int m_cyl;
00708 
00710         unsigned int m_luma_depth;
00711 
00713         unsigned int m_chroma_depth;
00714 
00716         bool m_using_ac;
00717     };
00718 
00719 
00721 
00724     class PicArray: public TwoDArray<ValueType>
00725     {
00726     public:
00728 
00731         PicArray(): TwoDArray<ValueType>(){}
00732 
00734 
00738         PicArray(int height, int width, CompSort cs=Y_COMP): 
00739             TwoDArray<ValueType>(height, width), m_csort(cs){}
00740 
00741         //copy constructor and assignment= derived by inheritance
00742 
00744         ~PicArray(){}
00745 
00747         const CompSort& CSort() const {return m_csort;}
00748         
00750         void SetCSort(const CompSort cs){ m_csort = cs; }
00751 
00752     private:
00753 
00754         CompSort m_csort;
00755     };
00756 
00758 
00761     class CoeffArray: public TwoDArray<CoeffType>
00762     {
00763     public:
00765 
00768         CoeffArray(): TwoDArray<CoeffType>(){}
00769 
00771 
00775         CoeffArray(int height, int width, CompSort cs=Y_COMP): 
00776             TwoDArray<CoeffType>(height, width), m_csort(cs){}
00777 
00778         //copy constructor and assignment= derived by inheritance
00779 
00781         ~CoeffArray(){}
00782         
00784         const CompSort& CSort() const {return m_csort;}
00785         
00787         void SetCSort(const CompSort cs){ m_csort = cs; }
00788         
00789         private:
00790 
00791         CompSort m_csort;
00792 
00793     };
00794 
00795 
00797     class CostType
00798     {
00799     public:
00801         double Error;
00802 
00804         double ENTROPY;
00805 
00807         double TOTAL;
00808     };
00809 
00810 
00812 
00817     class EntropyCorrector
00818     {
00819     public:
00821 
00825         EntropyCorrector(int depth);
00826 
00828         //NB: Assume default copy constructor, assignment = and destructor//
00830 
00832 
00836         float Factor(const int bandnum, const PictureParams& pp,
00837                      const CompSort c) const;
00838 
00840 
00848         void Update(int bandnum, const PictureParams& pp, 
00849                     CompSort c,int est_bits,int actual_bits);
00850 
00851     private:
00853         void Init();
00854 
00855         TwoDArray<float> m_Yfctrs;
00856         TwoDArray<float> m_Ufctrs;
00857         TwoDArray<float> m_Vfctrs;
00858     };
00859 
00861     class OLBParams
00862     {
00863 
00864     public:
00865 
00867         OLBParams(){}
00868 
00870         /*
00871             Constructor rationalises proposed parameters to allow suitable
00872             overlap and fit in with chroma format
00873             \param    xblen    the horizontal block length
00874             \param    yblen    the vertical block length
00875             \param    xblen    the horizontal block separation
00876             \param    yblen    the vertical block separation
00877 
00878         */
00879         OLBParams(const int xblen, const int yblen,
00880                   const int xbsep, const int ybsep);
00881 
00882         // Gets ...
00883 
00885         int Xblen() const {return m_xblen;}
00886 
00888         int Yblen() const {return m_yblen;}
00889 
00891         int Xbsep() const {return m_xbsep;}
00892 
00894         int Ybsep() const {return m_ybsep;}
00895 
00897         int Xoffset() const {return m_xoffset;}
00898 
00900         int Yoffset() const {return m_yoffset;}
00901 
00902         // ... and sets
00903 
00905         void SetXblen( int xblen ){ m_xblen = xblen; m_xoffset = (m_xblen-m_xbsep)/2;}
00906 
00908         void SetYblen( int yblen ){ m_yblen = yblen; m_yoffset = (m_yblen-m_ybsep)/2;}
00909 
00911         void SetXbsep( int xbsep ){ m_xbsep = xbsep; m_xoffset = (m_xblen-m_xbsep)/2;}
00912 
00914         void SetYbsep( int ybsep ){ m_ybsep = ybsep; m_yoffset = (m_yblen-m_ybsep)/2;}
00915 
00916         bool operator == (const OLBParams bparams) const;
00917 
00918         // overloaded stream operators
00919         friend std::ostream & operator<< (std::ostream &, OLBParams &);
00920         friend std::istream & operator>> (std::istream &, OLBParams &);
00921 
00922 
00923     private:
00924 
00925         int m_xblen;
00926         int m_yblen;
00927         int m_xbsep;
00928         int m_ybsep;
00929         int m_xoffset;
00930         int m_yoffset;
00931     };
00932 
00934     class ParseParams
00935     {
00936     public:
00938         ParseParams();
00939 
00940         // Gets
00941 
00943         unsigned int MajorVersion() const { return m_major_ver; }
00944 
00946         unsigned int MinorVersion() const { return m_minor_ver; }
00947 
00949         unsigned int Profile() const { return m_profile; }
00950 
00952         unsigned int Level() const { return m_level; }
00953 
00954         // Sets
00955 
00957         void SetMajorVersion(unsigned int major_ver) {m_major_ver = major_ver; }
00958 
00960         void SetMinorVersion(unsigned int minor_ver) { m_minor_ver = minor_ver; }
00961 
00963         void SetProfile(unsigned int profile) { m_profile = profile; }
00964 
00966         void SetLevel(unsigned int level) { m_level = level; }
00967 
00968     private:
00970         unsigned int m_major_ver;
00972         unsigned int m_minor_ver;
00974         unsigned int m_profile;
00976         unsigned int m_level;
00977     };
00978 
00980     class CodeBlocks
00981     {
00982     public:
00984         CodeBlocks () : m_hblocks(1), m_vblocks(1)
00985         {}
00986 
00988         CodeBlocks (unsigned int  hblocks, unsigned int vblocks) :
00989             m_hblocks(hblocks),
00990             m_vblocks(vblocks)
00991             {}
00992 
00993         // Gets
00995         unsigned int HorizontalCodeBlocks() const { return m_hblocks; }
00997         unsigned int VerticalCodeBlocks() const { return m_vblocks; }
00998         // Sets
01000         void SetHorizontalCodeBlocks(unsigned int hblocks) { m_hblocks = hblocks; }
01002         void SetVerticalCodeBlocks(unsigned int vblocks) { m_vblocks = vblocks; }
01003     private:
01005         unsigned int m_hblocks;
01007         unsigned int m_vblocks;
01008     };
01010 
01013     class CodecParams
01014     {
01015     public:
01016 
01018         CodecParams (const VideoFormat& video_format = VIDEO_FORMAT_CUSTOM,
01019                       PictureType ftype = INTRA_PICTURE,
01020                       unsigned int num_refs = 0,
01021                       bool set_defaults=true);
01022 
01024         //NB: Assume default copy constructor, assignment = and destructor//
01026 
01027         // Gets ...
01028 
01030         int XNumMB() const {return m_x_num_mb;}
01031 
01033         int YNumMB() const {return m_y_num_mb;}
01034 
01036         int XNumBlocks() const {return m_x_num_blocks;}
01037 
01039         int YNumBlocks() const {return m_y_num_blocks;}
01040 
01042 
01046         int PictureCodingMode() const {return m_pic_coding_mode;}
01047 
01049         bool FieldCoding() const { return  (m_pic_coding_mode==1); } 
01050 
01052         bool TopFieldFirst() const {return m_topfieldfirst;}
01053 
01055         int Xl() const {return m_xl;}
01056 
01058         int Yl() const {return m_yl;}
01059 
01061         int ChromaXl() const {return m_cxl;}
01062 
01064         int ChromaYl() const {return m_cyl;}
01065 
01067         unsigned int LumaDepth() const { return m_luma_depth; }
01068 
01070         unsigned int ChromaDepth() const { return m_chroma_depth; }
01071 
01073         const OLBParams& LumaBParams(int n) const {return m_lbparams[n];}
01074 
01076         const OLBParams& ChromaBParams(int n) const {return m_cbparams[n];}
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         const CodeBlocks &GetCodeBlocks(unsigned int level) const;
01098 
01100         VideoFormat GetVideoFormat() const { return m_video_format; }
01101 
01103         bool UsingGlobalMotion() const { return m_use_global_motion; }
01104 
01106         unsigned int PictureWeightsBits() const { return m_picture_weights_bits; }
01107 
01109         int Ref1Weight() const { return m_ref1_weight; }
01110 
01112         int Ref2Weight() const { return m_ref2_weight; }
01113 
01114         bool CustomRefWeights()
01115         {
01116             return (m_picture_weights_bits != 1 ||
01117                     m_ref1_weight != 1 ||
01118                     m_ref2_weight != 1);
01119         }
01120         // ... and Sets
01122         void SetXNumMB(const int xn){m_x_num_mb=xn;}
01123 
01125         void SetYNumMB(const int yn){m_y_num_mb=yn;}
01126 
01128         void SetXNumBlocks(const int xn){m_x_num_blocks=xn;}
01129 
01131         void SetYNumBlocks(const int yn){m_y_num_blocks=yn;}
01132 
01134         void SetPictureCodingMode(int pic_coding){m_pic_coding_mode=pic_coding;}
01135 
01137         void SetTopFieldFirst(bool topf){m_topfieldfirst=topf;}
01138 
01140         void SetXl(const int x){m_xl=x;}
01141 
01143         void SetYl(const int y){m_yl=y;}
01144 
01146         void SetChromaXl(const int x){m_cxl=x;}
01147 
01149         void SetChromaYl(const int y){m_cyl=y;}
01150 
01152         void SetLumaDepth(unsigned int luma_depth) { m_luma_depth = luma_depth; }
01153 
01155         void SetChromaDepth(unsigned int chroma_depth) { m_chroma_depth = chroma_depth; }
01156 
01158         void SetBlockSizes(const OLBParams& olbparams , const ChromaFormat cformat);
01160         void SetLumaBlockParams(const OLBParams& olbparams) {m_lbparams[2] = olbparams;}
01161 
01163         void SetMVPrecision(const MVPrecisionType p)
01164         {
01165             // Assert in debug mode. Maybe we should throw an exception???
01166             TESTM((p >=0 && p <=3), "Motion precision value in range 0..3");
01167             m_mv_precision = p;
01168         }
01169 
01170         void SetMVPrecision(const MVPrecisionType p) const
01171         {
01172             // Assert in debug mode. Maybe we should throw an exception???
01173             TESTM((p >=0 && p <=3), "Motion precision value in range 0..3");
01174             m_mv_precision = p;
01175         }
01176 
01178         void SetZeroTransform(bool zero_transform)  { m_zero_transform = zero_transform; }
01179 
01181         void SetTransformFilter(const WltFilter wf) { m_wlt_filter=wf; }
01182 
01184         void SetTransformFilter(unsigned int wf_idx);
01185 
01187         void SetTransformDepth(unsigned int wd);
01188 
01190         void SetCodeBlockMode(unsigned int cb_mode);
01191 
01193         void SetSpatialPartition(bool spatial_partition) { m_spatial_partition=spatial_partition; }
01194 
01196         void  SetCodeBlocks(unsigned int level, unsigned int hblocks, unsigned int vblocks);
01197 
01199         void SetVideoFormat(const VideoFormat vd) { m_video_format=vd; }
01200 
01202         void SetUsingGlobalMotion(bool gm) { m_use_global_motion=gm; }
01203 
01205         void SetPictureWeightsPrecision(unsigned int wt_prec) { m_picture_weights_bits=wt_prec; }
01206 
01208         void SetRef1Weight(int wt) { m_ref1_weight=wt; }
01209 
01211         void SetRef2Weight(int wt) { m_ref2_weight=wt; }
01212 
01213     protected:
01215         WltFilter TransformFilter (unsigned int wf_idx);
01216     private:
01217 
01219         int m_pic_coding_mode;
01220 
01222         bool m_topfieldfirst;
01223 
01225         int m_xl;
01226 
01228         int m_yl;
01229 
01231         int m_cxl;
01232 
01234         int m_cyl;
01235 
01237         unsigned int m_luma_depth;
01238 
01240         unsigned int m_chroma_depth;
01241 
01243         int m_x_num_mb;
01244 
01246         int m_y_num_mb;
01247 
01249         int m_x_num_blocks;
01250 
01252         int m_y_num_blocks;
01253 
01254         OneDArray<OLBParams> m_lbparams;
01255 
01256         OneDArray<OLBParams> m_cbparams;
01257 
01259         mutable MVPrecisionType m_mv_precision;
01260 
01262         VideoFormat m_video_format;
01263 
01265         bool m_use_global_motion;
01266 
01268         unsigned int m_picture_weights_bits;
01269 
01271         int m_ref1_weight;
01272 
01274         int m_ref2_weight;
01275 
01277         bool m_zero_transform;
01278 
01280         WltFilter m_wlt_filter;
01281 
01283         unsigned int m_wlt_depth;
01284 
01286         CodeBlockMode m_cb_mode;
01287 
01289         bool m_spatial_partition;
01290 
01292         OneDArray<CodeBlocks> m_cb;
01293     };
01294 
01296 
01299     class EncoderParams: public CodecParams
01300     {
01301         //codec params plus parameters relating solely to the operation of the encoder
01302 
01303     public:
01305         EncoderParams(const VideoFormat& video_format,
01306                       PictureType ftype = INTER_PICTURE,
01307                       unsigned int num_refs = 2,
01308                       bool set_defaults=true);
01309 
01311             //NB: Assume default copy constructor, assignment = and destructor//
01312             //This means pointers are copied, not the objects they point to.////
01314 
01315          // Gets ...
01316 
01317 
01319         bool Verbose() const {return m_verbose;}
01320 
01322         bool LocalDecode() const {return m_loc_decode;}
01323 
01325         bool Lossless() const {return m_lossless;}
01326 
01328         bool FullSearch() const {return m_full_search; }
01329 
01331         int XRangeME() const {return m_x_range_me;}
01332 
01334         int YRangeME() const {return m_y_range_me;}
01335 
01337         float Qf() const {return m_qf;}
01338 
01340 
01345         int NumL1() const {return m_num_L1;}
01346 
01348         int L1Sep() const {return m_L1_sep;}
01349 
01351         float UFactor() const {return m_ufactor;}
01352 
01354         float VFactor() const {return m_vfactor;}
01355 
01357         float CPD() const {return m_cpd;}
01358 
01360         PrefilterType Prefilter() const {return m_prefilter;}
01361 
01363         int PrefilterStrength() const {return m_prefilter_strength;}
01364 
01366         float ILambda() const {return m_I_lambda;}
01367 
01369         float L1Lambda() const {return m_L1_lambda;}
01370 
01372         float L2Lambda() const {return m_L2_lambda;}
01373 
01375         float L1MELambda() const {return m_L1_me_lambda;}
01376 
01378         float L2MELambda() const {return m_L2_me_lambda;}
01379 
01381         int GOPLength() const;
01382 
01384         char * OutputPath() const {return ( char* ) m_output_path.c_str();}
01385 
01387         const EntropyCorrector& EntropyFactors() const {return *m_ent_correct;}
01388 
01390         EntropyCorrector& EntropyFactors() {return *m_ent_correct;}
01391 
01393         WltFilter IntraTransformFilter() { return m_intra_wltfilter; }
01394 
01396         WltFilter InterTransformFilter() { return m_inter_wltfilter; }
01397 
01399         int TargetRate() {return m_target_rate;}
01400 
01402         bool UsingAC()  const {return m_using_ac;}
01403 
01404         // ... and Sets
01405 
01407         void SetVerbose(bool v){m_verbose=v;}
01408 
01410         void SetLocalDecode( const bool decode ){m_loc_decode=decode;}
01411 
01413         void SetLossless(const bool l){m_lossless = l;}
01414 
01416         void SetFullSearch(const bool fs){m_full_search = fs;}
01417 
01419         void SetXRangeME(const int xr){m_x_range_me = xr;}
01420 
01422         void SetYRangeME(const int yr){m_y_range_me = yr;}
01423 
01425         void SetQf(const float qfac){ m_qf=qfac; CalcLambdas(m_qf); }
01426 
01428         void SetNumL1(const int nl){m_num_L1=nl;}
01429 
01431         void SetL1Sep(const int lsep){m_L1_sep=lsep;}
01432 
01434         void SetUFactor(const float uf){m_ufactor=uf;}
01435 
01437         void SetVFactor(const float vf){m_vfactor=vf;}
01438 
01440         void SetCPD(const float cpd){m_cpd=cpd;}
01441 
01443         void SetPrefilter(const PrefilterType pf, const int str){m_prefilter=pf;
01444                                                    m_prefilter_strength=str;}
01445 
01447         void SetOutputPath(const char * op){ m_output_path = op; }
01448 
01450         void SetEntropyFactors(EntropyCorrector* entcorrect){m_ent_correct=entcorrect;}
01452         void SetIntraTransformFilter(unsigned int wf_idx);
01453 
01455         void SetInterTransformFilter(unsigned int wf_idx);
01456 
01458         void SetIntraTransformFilter(WltFilter wf) { m_intra_wltfilter = wf; }
01459         
01461         void  SetUsualCodeBlocks(const PictureType& ftype);
01462 
01464         void SetInterTransformFilter(WltFilter wf) { m_inter_wltfilter = wf; }
01465 
01467         void SetTargetRate(const int rate){m_target_rate = rate;}
01468 
01470         void SetUsingAC(bool using_ac) {m_using_ac = using_ac;}
01471     private:
01472 
01474         void CalcLambdas(const float qf);
01475 
01476     private:
01477 
01479         bool m_verbose;
01480 
01482         bool m_loc_decode;
01483 
01485         bool m_lossless;
01486 
01488         bool m_full_search;
01489 
01491         int m_x_range_me;
01492 
01494         int m_y_range_me;
01495 
01497         float m_qf;
01498 
01500         int m_num_L1;
01501 
01503         int m_L1_sep;
01504 
01506         float m_ufactor;
01507 
01509         float m_vfactor;
01510 
01512         float m_cpd;
01513 
01515         PrefilterType m_prefilter;
01516 
01518         int m_prefilter_strength;
01519 
01521         float m_I_lambda;
01522 
01524         float m_L1_lambda;
01525 
01527         float m_L2_lambda;
01528 
01530         float m_L1_me_lambda;
01531 
01533         float m_L2_me_lambda;
01534 
01536         EntropyCorrector* m_ent_correct;
01537 
01539         std::string m_output_path;
01540 
01542         WltFilter m_intra_wltfilter;
01543 
01545         WltFilter m_inter_wltfilter;
01546 
01548         int m_target_rate;
01549 
01551         bool m_using_ac;
01552 
01553     };
01554 
01556 
01559     class DecoderParams: public CodecParams
01560     {
01561     public:
01563         DecoderParams(const VideoFormat& video_format = VIDEO_FORMAT_CIF, PictureType ftype=INTRA_PICTURE, unsigned int num_refs = 0, bool set_defaults = false);
01564 
01566         bool Verbose() const {return m_verbose;}
01567 
01569         void SetVerbose(bool v){m_verbose=v;}
01570 
01572             //NB: Assume default copy constructor, assignment = and destructor//
01573             //This means pointers are copied, not the objects they point to.////
01575 
01576 
01577     private:
01578 
01580         bool m_verbose;
01581 
01582     };
01583 
01585     inline ValueType BChk(const ValueType &num, const ValueType &max)
01586     {
01587         if(num < 0) return 0;
01588         else if(num >= max) return max-1;
01589         else return num;
01590     }
01591 
01593     class QuantiserLists
01594     {
01595     public:
01597         QuantiserLists();
01598 
01600         inline int QuantFactor4( const int index ) const {return m_qflist4[index]; }
01601 
01603         inline int IntraQuantOffset4( const int index ) const {return m_intra_offset4[index]; }
01605         inline int InterQuantOffset4( const int index ) const {return m_inter_offset4[index]; }
01606 
01608         inline int MaxQuantIndex() const {return m_max_qindex; }
01609 
01610 
01611     private:
01612         unsigned int m_max_qindex;
01613         OneDArray<int> m_qflist4;
01614         OneDArray<int> m_intra_offset4;
01615         OneDArray<int> m_inter_offset4;
01616 
01617     };
01618 
01620     static const QuantiserLists dirac_quantiser_lists;
01621 
01622 } // namespace dirac
01623 
01624 #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.