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.70 2008/01/15 04:36:23 asuraparaju Exp $ $Name: Dirac_0_9_1 $
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//
00217     class FrameSort
00218     {
00219     public:
00220         FrameSort() { fs = 0x00; } // default intra non-ref
00221 
00222         void SetIntra() { fs &= 0xfe; }
00223         void SetInter() { fs |= 0x01; }
00224         void SetNonRef() { fs &= 0xfd; }
00225         void SetRef() { fs |= 0x02; }
00226 
00227         bool IsInter () const { return fs & 0x01; }
00228         bool IsIntra () const { return !IsInter(); }
00229         bool IsRef() const { return fs & 0x02; };
00230         bool IsNonRef() const { return !IsRef(); }
00231 
00232         void SetIntraNonRef() { SetIntra(); SetNonRef(); }
00233         void SetIntraRef() { SetIntra(); SetRef(); }
00234         void SetInterNonRef() { SetInter(); SetNonRef(); }
00235         void SetInterRef() { SetInter(); SetRef(); }
00236 
00237         bool IsIntraNonRef() const { return (fs & 0x03) == 0x00; }
00238         bool IsIntraRef() const { return (fs & 0x03) == 0x02; }
00239         bool IsInterNonRef() const { return (fs & 0x03) == 0x01; }
00240         bool IsInterRef() const { return (fs & 0x03) == 0x03; }
00241 
00242         void Clear() { fs=0x00; }
00243 
00244         static FrameSort IntraRefFrameSort()
00245         {
00246             FrameSort fs;
00247             fs.SetIntraRef();
00248             return fs;
00249         }
00250 
00251         static FrameSort InterRefFrameSort()
00252         {
00253             FrameSort fs;
00254             fs.SetInterRef();
00255             return fs;
00256         }
00257 
00258         static FrameSort IntraNonRefFrameSort()
00259         {
00260             FrameSort fs;
00261             fs.SetIntraNonRef();
00262             return fs;
00263         }
00264 
00265         static FrameSort InterNonRefFrameSort()
00266         {
00267             FrameSort fs;
00268             fs.SetInterNonRef();
00269             return fs;
00270         }
00271 
00272     private:
00273         unsigned char fs;
00274     };
00275 
00277 
00280     class PicArray: public TwoDArray<ValueType>
00281     {
00282     public:
00284 
00287         PicArray(): TwoDArray<ValueType>(){}
00288 
00290 
00294         PicArray(int height, int width, CompSort cs=Y_COMP): 
00295             TwoDArray<ValueType>(height, width), m_csort(cs){}
00296 
00297         //copy constructor and assignment= derived by inheritance
00298 
00300         ~PicArray(){}
00301 
00303         const CompSort& CSort() const {return m_csort;}
00304         
00306         void SetCSort(const CompSort cs){ m_csort = cs; }
00307 
00308     private:
00309 
00310         CompSort m_csort;
00311     };
00312 
00314 
00317     class CoeffArray: public TwoDArray<CoeffType>
00318     {
00319     public:
00321 
00324         CoeffArray(): TwoDArray<CoeffType>(){}
00325 
00327 
00331         CoeffArray(int height, int width, CompSort cs=Y_COMP): 
00332             TwoDArray<CoeffType>(height, width), m_csort(cs){}
00333 
00334         //copy constructor and assignment= derived by inheritance
00335 
00337         ~CoeffArray(){}
00338         
00340         const CompSort& CSort() const {return m_csort;}
00341         
00343         void SetCSort(const CompSort cs){ m_csort = cs; }
00344         
00345         private:
00346 
00347         CompSort m_csort;
00348 
00349     };
00350 
00351 
00353     class CostType
00354     {
00355     public:
00357         double Error;
00358 
00360         double ENTROPY;
00361 
00363         double TOTAL;
00364     };
00365 
00366 
00368 
00373     class EntropyCorrector
00374     {
00375     public:
00377 
00381         EntropyCorrector(int depth);
00382 
00384         //NB: Assume default copy constructor, assignment = and destructor//
00386 
00388 
00392         float Factor(const int bandnum, const FrameSort fsort,const CompSort c) const;
00393 
00395 
00403         void Update(int bandnum, FrameSort fsort, CompSort c,int est_bits,int actual_bits);
00404 
00405     private:
00407         void Init();
00408 
00409         TwoDArray<float> m_Yfctrs;
00410         TwoDArray<float> m_Ufctrs;
00411         TwoDArray<float> m_Vfctrs;
00412     };
00413 
00415     class OLBParams
00416     {
00417 
00418     public:
00419 
00421         OLBParams(){}
00422 
00424         /*
00425             Constructor rationalises proposed parameters to allow suitable
00426             overlap and fit in with chroma format
00427             \param    xblen    the horizontal block length
00428             \param    yblen    the vertical block length
00429             \param    xblen    the horizontal block separation
00430             \param    yblen    the vertical block separation
00431 
00432         */
00433         OLBParams(const int xblen, const int yblen,
00434                   const int xbsep, const int ybsep);
00435 
00436         // Gets ...
00437 
00439         int Xblen() const {return m_xblen;}
00440 
00442         int Yblen() const {return m_yblen;}
00443 
00445         int Xbsep() const {return m_xbsep;}
00446 
00448         int Ybsep() const {return m_ybsep;}
00449 
00451         int Xoffset() const {return m_xoffset;}
00452 
00454         int Yoffset() const {return m_yoffset;}
00455 
00456         // ... and sets
00457 
00459         void SetXblen( int xblen ){ m_xblen = xblen; m_xoffset = (m_xblen-m_xbsep)/2;}
00460 
00462         void SetYblen( int yblen ){ m_yblen = yblen; m_yoffset = (m_yblen-m_ybsep)/2;}
00463 
00465         void SetXbsep( int xbsep ){ m_xbsep = xbsep; m_xoffset = (m_xblen-m_xbsep)/2;}
00466 
00468         void SetYbsep( int ybsep ){ m_ybsep = ybsep; m_yoffset = (m_yblen-m_ybsep)/2;}
00469 
00470         bool operator == (const OLBParams bparams) const;
00471 
00472         // overloaded stream operators
00473         friend std::ostream & operator<< (std::ostream &, OLBParams &);
00474         friend std::istream & operator>> (std::istream &, OLBParams &);
00475 
00476 
00477     private:
00478 
00479         int m_xblen;
00480         int m_yblen;
00481         int m_xbsep;
00482         int m_ybsep;
00483         int m_xoffset;
00484         int m_yoffset;
00485     };
00486 
00488     class Rational
00489     {
00490     public:
00492         unsigned int m_num;
00494         unsigned int m_denom;
00495     };
00496 
00498     class ParseParams
00499     {
00500     public:
00502         ParseParams();
00503 
00504         // Gets
00505 
00507         unsigned int MajorVersion() const { return m_major_ver; }
00508 
00510         unsigned int MinorVersion() const { return m_minor_ver; }
00511 
00513         unsigned int Profile() const { return m_profile; }
00514 
00516         unsigned int Level() const { return m_level; }
00517 
00518         // Sets
00519 
00521         void SetMajorVersion(unsigned int major_ver) {m_major_ver = major_ver; }
00522 
00524         void SetMinorVersion(unsigned int minor_ver) { m_minor_ver = minor_ver; }
00525 
00527         void SetProfile(unsigned int level) { m_level = level; }
00528 
00530         void SetLevel(unsigned int profile) { m_profile = profile; }
00531 
00532     private:
00534         unsigned int m_major_ver;
00536         unsigned int m_minor_ver;
00538         unsigned int m_profile;
00540         unsigned int m_level;
00541     };
00542 
00544     class SourceParams
00545     {
00546     public:
00548         SourceParams (const VideoFormat &vf = VIDEO_FORMAT_CUSTOM,
00549                       bool set_defaults=true);
00550 
00552         //NB: Assume default copy constructor, assignment = and destructor//
00554 
00555         // Gets
00557         VideoFormat GetVideoFormat() const { return m_video_format;}
00558 
00560         unsigned int Xl() const {return m_xl;}
00561 
00563         unsigned int Yl() const {return m_yl;}
00564 
00566         ChromaFormat CFormat() const {return m_cformat;}
00567 
00569         int ChromaWidth() const;
00570 
00572         int ChromaHeight() const;
00573 
00575         unsigned int SourceSampling() const { return m_source_sampling; }
00576 
00578         bool TopFieldFirst() const { return m_topfieldfirst; }
00579 
00581         Rational FrameRate() const { return m_framerate; }
00582 
00584         FrameRateType FrameRateIndex() const { return m_fr_idx; }
00585 
00587         Rational PixelAspectRatio() const { return m_pixel_aspect_ratio; }
00588 
00590         PixelAspectRatioType PixelAspectRatioIndex() const { return m_pix_asr_idx; }
00591 
00592         // Clean area parameters
00594         unsigned int CleanWidth() const { return m_clean_width; }
00596         unsigned int CleanHeight() const { return m_clean_height; }
00598         unsigned int LeftOffset() const { return m_left_offset; }
00600         unsigned int TopOffset() const { return m_top_offset; }
00601 
00602         // Signal Range parameters
00603 
00605         SignalRangeType SignalRangeIndex() const { return m_sr_idx; }
00606 
00608         unsigned int LumaOffset() const { return m_luma_offset; }
00610         unsigned int LumaExcursion() const { return m_luma_excursion; }
00612         unsigned int ChromaOffset() const { return m_chroma_offset; }
00614         unsigned int ChromaExcursion() const { return m_chroma_excursion; }
00615 
00617         unsigned int ColourSpecificationIndex() const { return m_cs_idx; }
00618 
00620         ColourPrimaries ColourPrimariesIndex() const { return m_col_primary; }
00622         ColourMatrix ColourMatrixIndex() const { return m_col_matrix; }
00624         TransferFunction TransferFunctionIndex() const { return m_transfer_func; }
00625 
00626         // Sets
00627 
00629         void SetXl(unsigned int xlen) {m_xl = xlen;}
00630 
00632         void SetYl(unsigned int ylen) {m_yl = ylen;}
00633 
00635         void SetCFormat(ChromaFormat cf) {m_cformat=cf;}
00636 
00638         void SetSourceSampling(unsigned int source_sampling) 
00639         { m_source_sampling = source_sampling; }
00640 
00642         void SetTopFieldFirst(bool tff) { m_topfieldfirst = tff; }
00643 
00645         void SetVideoFormat(VideoFormat vf){ m_video_format=vf;}
00646 
00648         void SetFrameRate(const Rational &frate )
00649         {
00650             m_fr_idx = FRAMERATE_CUSTOM; m_framerate = frate;
00651         }
00652 
00654         void SetFrameRate(unsigned int fr_num, unsigned int fr_denom )
00655         {
00656             m_fr_idx = FRAMERATE_CUSTOM;
00657             m_framerate.m_num = fr_num;
00658             m_framerate.m_denom = fr_denom;
00659         }
00660 
00662         void SetFrameRate(FrameRateType fr);
00663 
00665         void SetPixelAspectRatio(const Rational &pix_asr)
00666         {
00667             m_pix_asr_idx = PIXEL_ASPECT_RATIO_CUSTOM;
00668             m_pixel_aspect_ratio = pix_asr;
00669         }
00670 
00672         void SetPixelAspectRatio(unsigned int pix_as_num, unsigned int pix_as_denom )
00673         {
00674             m_pix_asr_idx = PIXEL_ASPECT_RATIO_CUSTOM;
00675             m_pixel_aspect_ratio.m_num = pix_as_num;
00676             m_pixel_aspect_ratio.m_denom = pix_as_denom;
00677         }
00678 
00680         void SetPixelAspectRatio(PixelAspectRatioType pixel_aspect_ratio);
00681 
00682         // Clean area parameters
00684         void SetCleanWidth(unsigned int clean_width) { m_clean_width = clean_width; }
00686         void SetCleanHeight(unsigned int clean_height) { m_clean_height = clean_height; }
00688         void SetLeftOffset(unsigned int left_offset) { m_left_offset = left_offset; }
00690         void SetTopOffset(unsigned int top_offset) { m_top_offset = top_offset; }
00691 
00692         // Signal Range parameters
00694         void SetSignalRange(SignalRangeType sr);
00695 
00697         void SetLumaOffset(unsigned int luma_offset) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_offset = luma_offset; }
00699         void SetLumaExcursion(unsigned int luma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_excursion = luma_exc; }
00701         void SetChromaOffset(unsigned int chroma_off) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_offset = chroma_off; }
00703         void SetChromaExcursion(unsigned int chroma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_excursion = chroma_exc; }
00704 
00706         void SetColourSpecification(unsigned int cs_idx);
00708         void SetColourPrimariesIndex(unsigned int cp);
00710         void SetColourMatrixIndex(unsigned int cm);
00712         void SetTransferFunctionIndex(unsigned int tf);
00713 
00714     private:
00716         VideoFormat m_video_format;
00717 
00719         unsigned int m_xl;
00720 
00722         unsigned int m_yl;
00723 
00725         ChromaFormat m_cformat;
00726 
00728         unsigned int m_source_sampling;
00729 
00731         bool m_topfieldfirst;
00732 
00734         FrameRateType m_fr_idx;
00735 
00737         Rational m_framerate;
00738 
00740         PixelAspectRatioType m_pix_asr_idx;
00741 
00743         Rational m_pixel_aspect_ratio;
00744 
00745         // Clean area parameters
00746 
00748         unsigned int m_clean_width;
00749 
00751         unsigned int m_clean_height;
00752 
00754         unsigned int m_left_offset;
00755 
00757         unsigned int m_top_offset;
00758 
00759         // signal range parameters
00760 
00762         SignalRangeType m_sr_idx;
00763 
00765         unsigned int m_luma_offset;
00767         unsigned int m_luma_excursion;
00769         unsigned int m_chroma_offset;
00771         unsigned int m_chroma_excursion;
00772 
00774         unsigned int m_cs_idx;
00775 
00777         ColourPrimaries m_col_primary;
00778 
00779         // Colour Matrix index
00780         ColourMatrix m_col_matrix;
00781 
00782         // Transfer function index
00783         TransferFunction m_transfer_func;
00784     };
00785 
00787     class FrameParams
00788     {
00789 
00790     public:
00792         FrameParams();
00793 
00795 
00798         FrameParams(const ChromaFormat& cf, int orig_xlen, int orig_ylen,
00799                     int dwt_xlen, int dwt_ylen,
00800                     int c_dwt_xlen, int c_dwt_ylen,
00801                     unsigned int luma_depth, unsigned int chroma_depth);
00802 
00804 
00807         FrameParams(const ChromaFormat& cf, const FrameSort& fs);
00808 
00810         /*
00811             All data is derived from the sequence parameters
00812         */
00813         FrameParams(const SourceParams& sparams);
00814 
00816         /*
00817            All data is derived from the sequence parameters
00818         */
00819         FrameParams(const SourceParams& sparams, const FrameSort& fs);
00820 
00822         //NB: Assume default copy constructor, assignment = and destructor//
00824 
00825         // Gets ...
00826 
00828         const ChromaFormat& CFormat() const{return m_cformat;}
00829 
00831         int DwtXl() const{return m_dwt_xl;}
00832 
00834         int DwtYl() const{return m_dwt_yl;}
00835 
00837         int DwtChromaXl() const{return m_dwt_chroma_xl;}
00838 
00840         int DwtChromaYl() const{return m_dwt_chroma_yl;}
00841 
00843         int OrigXl() const {return m_orig_xl;}
00844 
00846         int OrigYl() const {return m_orig_yl;}
00847 
00849         int OrigChromaXl() const{return m_orig_cxl;}
00850 
00852         int OrigChromaYl() const{return m_orig_cyl;}
00853 
00855         unsigned int LumaDepth() const { return m_luma_depth; }
00856 
00858         unsigned int ChromaDepth() const { return m_chroma_depth; }
00859 
00861         const FrameSort& FSort() const {return m_fsort;}
00862 
00864         int FrameNum() const {return m_fnum;}
00865 
00867         int RetiredFrameNum() const {return m_retd_fnum;}
00868 
00870         bool IsBFrame() const;
00871 
00873         int ExpiryTime() const {return m_expiry_time;}
00874 
00876         bool Output() const {return m_output;}
00877 
00879         const std::vector<int>& Refs() const {return m_refs;}
00880 
00882         std::vector<int>& Refs(){return m_refs;}
00883 
00885         unsigned int NumRefs()const {return m_refs.size();}
00886 
00888         FrameType GetFrameType () const { return m_frame_type; }
00889 
00891         ReferenceType GetReferenceType() const { return m_reference_type;}
00892 
00894         bool UsingAC() const { return m_using_ac; }
00895 
00896         // ... Sets
00897 
00899         void SetFSort( const FrameSort& fs );
00900 
00902         void SetFrameType(const FrameType ftype);
00903 
00905         void SetReferenceType(const ReferenceType rtype);
00906 
00908         void SetFrameNum( const int fn ){ m_fnum=fn; }
00909 
00911         void SetExpiryTime( const int expt ){ m_expiry_time=expt; }
00912 
00914         void SetAsOutput(){m_output=true;}
00915 
00917         void SetCFormat(ChromaFormat cf){ m_cformat = cf; }
00918 
00920         void SetDwtXl(int xl){m_dwt_xl = xl; }
00921 
00923         void SetDwtYl(int yl){m_dwt_yl = yl; }
00924 
00926         void SetOrigXl(int orig_xlen);
00927 
00929         void SetOrigYl(int orig_ylen);
00930 
00932         void SetDwtChromaXl(int xl){m_dwt_chroma_xl = xl; }
00933 
00935         void SetDwtChromaYl(int yl){m_dwt_chroma_yl = yl; }
00936 
00938         void SetLumaDepth(unsigned int luma_depth) { m_luma_depth = luma_depth; }
00939 
00941         void SetChromaDepth(unsigned int chroma_depth) { m_chroma_depth = chroma_depth; }
00942 
00944         void SetRetiredFrameNum(int retd_fnum) {m_retd_fnum = retd_fnum;}
00945 
00947         void SetUsingAC(bool using_ac) { m_using_ac = using_ac; }
00948 
00949     private:
00950 
00952         ChromaFormat m_cformat;
00953 
00955         int m_dwt_xl;
00956 
00958         int m_dwt_yl;
00959 
00961         FrameSort m_fsort;
00962 
00964         std::vector<int> m_refs;
00965 
00967         int m_expiry_time;
00968 
00970         int m_fnum;
00971 
00973         FrameType m_frame_type;
00974 
00976         ReferenceType m_reference_type;
00977 
00979         bool m_output;
00980 
00982         int m_dwt_chroma_xl;
00983 
00985         int m_dwt_chroma_yl;
00986 
00988         mutable  int m_retd_fnum;
00989 
00991         int m_orig_xl;
00992 
00994         int m_orig_yl;
00995 
00997         int m_orig_cxl;
00998 
01000         int m_orig_cyl;
01001 
01003         unsigned int m_luma_depth;
01004 
01006         unsigned int m_chroma_depth;
01007 
01009         bool m_using_ac;
01010     };
01011 
01013     class CodeBlocks
01014     {
01015     public:
01017         CodeBlocks () : m_hblocks(1), m_vblocks(1)
01018         {}
01019 
01021         CodeBlocks (unsigned int  hblocks, unsigned int vblocks) :
01022             m_hblocks(hblocks),
01023             m_vblocks(vblocks)
01024             {}
01025 
01026         // Gets
01028         unsigned int HorizontalCodeBlocks() const { return m_hblocks; }
01030         unsigned int VerticalCodeBlocks() const { return m_vblocks; }
01031         // Sets
01033         void SetHorizontalCodeBlocks(unsigned int hblocks) { m_hblocks = hblocks; }
01035         void SetVerticalCodeBlocks(unsigned int vblocks) { m_vblocks = vblocks; }
01036     private:
01038         unsigned int m_hblocks;
01040         unsigned int m_vblocks;
01041     };
01043 
01046     class CodecParams
01047     {
01048     public:
01049 
01051         CodecParams (const VideoFormat& video_format = VIDEO_FORMAT_CUSTOM,
01052                       FrameType ftype = INTRA_FRAME,
01053                       unsigned int num_refs = 0,
01054                       bool set_defaults=true);
01055 
01057         //NB: Assume default copy constructor, assignment = and destructor//
01059 
01060         // Gets ...
01061 
01063         int XNumMB() const {return m_x_num_mb;}
01064 
01066         int YNumMB() const {return m_y_num_mb;}
01067 
01069         int XNumBlocks() const {return m_x_num_blocks;}
01070 
01072         int YNumBlocks() const {return m_y_num_blocks;}
01073 
01075         bool FieldCoding() const {return m_field_coding;}
01076 
01078         bool TopFieldFirst() const {return m_topfieldfirst;}
01079 
01081         int OrigXl() const {return m_orig_xl;}
01082 
01084         int OrigYl() const {return m_orig_yl;}
01085 
01087         int OrigChromaXl() const {return m_orig_cxl;}
01088 
01090         int OrigChromaYl() const {return m_orig_cyl;}
01091 
01093         unsigned int LumaDepth() const { return m_luma_depth; }
01094 
01096         unsigned int ChromaDepth() const { return m_chroma_depth; }
01097 
01098 
01100         const OLBParams& LumaBParams(int n) const {return m_lbparams[n];}
01101 
01103         const OLBParams& ChromaBParams(int n) const {return m_cbparams[n];}
01104 
01106         MVPrecisionType MVPrecision() const { return m_mv_precision; }
01107 
01109         bool ZeroTransform() const { return m_zero_transform; }
01110 
01112         WltFilter TransformFilter() const { return m_wlt_filter; }
01113 
01115         unsigned int TransformDepth() const { return m_wlt_depth; }
01116 
01118         CodeBlockMode GetCodeBlockMode() const { return m_cb_mode; }
01119 
01121         bool SpatialPartition() const { return m_spatial_partition; }
01122 
01124         const CodeBlocks &GetCodeBlocks(unsigned int level) const;
01125 
01127         VideoFormat GetVideoFormat() const { return m_video_format; }
01128 
01130         bool UsingGlobalMotion() const { return m_use_global_motion; }
01131 
01133         unsigned int FrameWeightsBits() const { return m_frame_weights_bits; }
01134 
01136         int Ref1Weight() const { return m_ref1_weight; }
01137 
01139         int Ref2Weight() const { return m_ref2_weight; }
01140 
01141         bool CustomRefWeights()
01142         {
01143             return (m_frame_weights_bits != 1 ||
01144                     m_ref1_weight != 1 ||
01145                     m_ref2_weight != 1);
01146         }
01147         // ... and Sets
01149         void SetXNumMB(const int xn){m_x_num_mb=xn;}
01150 
01152         void SetYNumMB(const int yn){m_y_num_mb=yn;}
01153 
01155         void SetXNumBlocks(const int xn){m_x_num_blocks=xn;}
01156 
01158         void SetYNumBlocks(const int yn){m_y_num_blocks=yn;}
01159 
01161         void SetFieldCoding(bool field_coding){m_field_coding=field_coding;}
01162 
01164         void SetTopFieldFirst(bool topf){m_topfieldfirst=topf;}
01165 
01167         void SetOrigXl(const int x){m_orig_xl=x;}
01168 
01170         void SetOrigYl(const int y){m_orig_yl=y;}
01171 
01172 
01174         void SetOrigChromaXl(const int x){m_orig_cxl=x;}
01175 
01177         void SetOrigChromaYl(const int y){m_orig_cyl=y;}
01178 
01180         void SetLumaDepth(unsigned int luma_depth) { m_luma_depth = luma_depth; }
01181 
01183         void SetChromaDepth(unsigned int chroma_depth) { m_chroma_depth = chroma_depth; }
01184 
01186         void SetBlockSizes(const OLBParams& olbparams , const ChromaFormat cformat);
01188         void SetLumaBlockParams(const OLBParams& olbparams) {m_lbparams[2] = olbparams;}
01189 
01191         void SetMVPrecision(const MVPrecisionType p)
01192         {
01193             // Assert in debug mode. Maybe we should throw an exception???
01194             TESTM((p >=0 && p <=3), "Motion precision value in range 0..3");
01195             m_mv_precision = p;
01196         }
01197 
01198         void SetMVPrecision(const MVPrecisionType p) const
01199         {
01200             // Assert in debug mode. Maybe we should throw an exception???
01201             TESTM((p >=0 && p <=3), "Motion precision value in range 0..3");
01202             m_mv_precision = p;
01203         }
01204 
01206         void SetZeroTransform(bool zero_transform)  { m_zero_transform = zero_transform; }
01207 
01209         void SetTransformFilter(const WltFilter wf) { m_wlt_filter=wf; }
01210 
01212         void SetTransformFilter(unsigned int wf_idx);
01213 
01215         void SetTransformDepth(unsigned int wd);
01216 
01218         void SetCodeBlockMode(unsigned int cb_mode);
01219 
01221         void SetSpatialPartition(bool spatial_partition) { m_spatial_partition=spatial_partition; }
01222 
01224         void  SetCodeBlocks(unsigned int level, unsigned int hblocks, unsigned int vblocks);
01225 
01227         void SetVideoFormat(const VideoFormat vd) { m_video_format=vd; }
01228 
01230         void SetUsingGlobalMotion(bool gm) { m_use_global_motion=gm; }
01231 
01233         void SetFrameWeightsPrecision(unsigned int wt_prec) { m_frame_weights_bits=wt_prec; }
01234 
01236         void SetRef1Weight(int wt) { m_ref1_weight=wt; }
01237 
01239         void SetRef2Weight(int wt) { m_ref2_weight=wt; }
01240 
01241     protected:
01243         WltFilter TransformFilter (unsigned int wf_idx);
01244     private:
01245 
01247         bool m_field_coding;
01248 
01250         bool m_topfieldfirst;
01251 
01253         int m_orig_xl;
01254 
01256         int m_orig_yl;
01257 
01259         int m_orig_cxl;
01260 
01262         int m_orig_cyl;
01263 
01265         unsigned int m_luma_depth;
01266 
01268         unsigned int m_chroma_depth;
01269 
01271         int m_x_num_mb;
01272 
01274         int m_y_num_mb;
01275 
01277         int m_x_num_blocks;
01278 
01280         int m_y_num_blocks;
01281 
01282         OneDArray<OLBParams> m_lbparams;
01283 
01284         OneDArray<OLBParams> m_cbparams;
01285 
01287         mutable MVPrecisionType m_mv_precision;
01288 
01290         VideoFormat m_video_format;
01291 
01293         bool m_use_global_motion;
01294 
01296         unsigned int m_frame_weights_bits;
01297 
01299         int m_ref1_weight;
01300 
01302         int m_ref2_weight;
01303 
01305         bool m_zero_transform;
01306 
01308         WltFilter m_wlt_filter;
01309 
01311         unsigned int m_wlt_depth;
01312 
01314         CodeBlockMode m_cb_mode;
01315 
01317         bool m_spatial_partition;
01318 
01320         OneDArray<CodeBlocks> m_cb;
01321     };
01322 
01324 
01327     class EncoderParams: public CodecParams
01328     {
01329         //codec params plus parameters relating solely to the operation of the encoder
01330 
01331     public:
01333         EncoderParams(const VideoFormat& video_format,
01334                       FrameType ftype = INTER_FRAME,
01335                       unsigned int num_refs = 2,
01336                       bool set_defaults=true);
01337 
01339             //NB: Assume default copy constructor, assignment = and destructor//
01340             //This means pointers are copied, not the objects they point to.////
01342 
01343          // Gets ...
01344 
01345 
01347         bool Verbose() const {return m_verbose;}
01348 
01350         bool LocalDecode() const {return m_loc_decode;}
01351 
01353         bool Lossless() const {return m_lossless;}
01354 
01356         bool FullSearch() const {return m_full_search; }
01357 
01359         int XRangeME() const {return m_x_range_me;}
01360 
01362         int YRangeME() const {return m_y_range_me;}
01363 
01365         float Qf() const {return m_qf;}
01366 
01368 
01373         int NumL1() const {return m_num_L1;}
01374 
01376         int L1Sep() const {return m_L1_sep;}
01377 
01379         float UFactor() const {return m_ufactor;}
01380 
01382         float VFactor() const {return m_vfactor;}
01383 
01385         float CPD() const {return m_cpd;}
01386 
01388         bool Denoise() const {return m_denoise;}
01389 
01391         float ILambda() const {return m_I_lambda;}
01392 
01394         float L1Lambda() const {return m_L1_lambda;}
01395 
01397         float L2Lambda() const {return m_L2_lambda;}
01398 
01400         float L1MELambda() const {return m_L1_me_lambda;}
01401 
01403         float L2MELambda() const {return m_L2_me_lambda;}
01404 
01406         int GOPLength() const;
01407 
01409         char * OutputPath() const {return ( char* ) m_output_path.c_str();}
01410 
01412         const EntropyCorrector& EntropyFactors() const {return *m_ent_correct;}
01413 
01415         EntropyCorrector& EntropyFactors() {return *m_ent_correct;}
01416 
01418         WltFilter IntraTransformFilter() { return m_intra_wltfilter; }
01419 
01421         WltFilter InterTransformFilter() { return m_inter_wltfilter; }
01422 
01424         int TargetRate() {return m_target_rate;}
01425 
01427         bool UsingAC()  const {return m_using_ac;}
01428 
01429         // ... and Sets
01430 
01432         void SetVerbose(bool v){m_verbose=v;}
01433 
01435         void SetLocalDecode( const bool decode ){m_loc_decode=decode;}
01436 
01438         void SetLossless(const bool l){m_lossless = l;}
01439 
01441         void SetFullSearch(const bool fs){m_full_search = fs;}
01442 
01444         void SetXRangeME(const int xr){m_x_range_me = xr;}
01445 
01447         void SetYRangeME(const int yr){m_y_range_me = yr;}
01448 
01450         void SetQf(const float qfac){ m_qf=qfac; CalcLambdas(m_qf); }
01451 
01453         void SetNumL1(const int nl){m_num_L1=nl;}
01454 
01456         void SetL1Sep(const int lsep){m_L1_sep=lsep;}
01457 
01459         void SetUFactor(const float uf){m_ufactor=uf;}
01460 
01462         void SetVFactor(const float vf){m_vfactor=vf;}
01463 
01465         void SetCPD(const float cpd){m_cpd=cpd;}
01466 
01467 
01469         void SetDenoise(const bool denoise){m_denoise=denoise;}
01470 
01472         void SetOutputPath(const char * op){ m_output_path = op; }
01473 
01475         void SetEntropyFactors(EntropyCorrector* entcorrect){m_ent_correct=entcorrect;}
01477         void SetIntraTransformFilter(unsigned int wf_idx);
01478 
01480         void SetInterTransformFilter(unsigned int wf_idx);
01481 
01483         void SetIntraTransformFilter(WltFilter wf) { m_intra_wltfilter = wf; }
01484         
01486         void  SetUsualCodeBlocks(const FrameType& ftype);
01487 
01489         void SetInterTransformFilter(WltFilter wf) { m_inter_wltfilter = wf; }
01490 
01492         void SetTargetRate(const int rate){m_target_rate = rate;}
01493 
01495         void SetUsingAC(bool using_ac) {m_using_ac = using_ac;}
01496     private:
01497 
01499         void CalcLambdas(const float qf);
01500 
01501     private:
01502 
01504         bool m_verbose;
01505 
01507         bool m_loc_decode;
01508 
01510         bool m_lossless;
01511 
01513         bool m_full_search;
01514 
01516         int m_x_range_me;
01517 
01519         int m_y_range_me;
01520 
01522         float m_qf;
01523 
01525         int m_num_L1;
01526 
01528         int m_L1_sep;
01529 
01531         float m_ufactor;
01532 
01534         float m_vfactor;
01535 
01537         float m_cpd;
01538 
01540         bool m_denoise;
01541 
01543         float m_I_lambda;
01544 
01546         float m_L1_lambda;
01547 
01549         float m_L2_lambda;
01550 
01552         float m_L1_me_lambda;
01553 
01555         float m_L2_me_lambda;
01556 
01558         EntropyCorrector* m_ent_correct;
01559 
01561         std::string m_output_path;
01562 
01564         WltFilter m_intra_wltfilter;
01565 
01567         WltFilter m_inter_wltfilter;
01568 
01570         int m_target_rate;
01571 
01573         bool m_using_ac;
01574 
01575     };
01576 
01578 
01581     class DecoderParams: public CodecParams
01582     {
01583     public:
01585         DecoderParams(const VideoFormat& video_format = VIDEO_FORMAT_CIF, FrameType ftype=INTRA_FRAME, unsigned int num_refs = 0, bool set_defaults = false);
01586 
01588         bool Verbose() const {return m_verbose;}
01589 
01591         void SetVerbose(bool v){m_verbose=v;}
01592 
01594             //NB: Assume default copy constructor, assignment = and destructor//
01595             //This means pointers are copied, not the objects they point to.////
01597 
01598 
01599     private:
01600 
01602         bool m_verbose;
01603 
01604     };
01605 
01607     inline ValueType BChk(const ValueType &num, const ValueType &max)
01608     {
01609         if(num < 0) return 0;
01610         else if(num >= max) return max-1;
01611         else return num;
01612     }
01613 
01615     class QuantiserLists
01616     {
01617     public:
01619         QuantiserLists();
01620 
01622         inline int QuantFactor4( const int index ) const {return m_qflist4[index]; }
01623 
01625         inline int IntraQuantOffset4( const int index ) const {return m_intra_offset4[index]; }
01627         inline int InterQuantOffset4( const int index ) const {return m_inter_offset4[index]; }
01628 
01630         inline int MaxQIndex() const {return m_max_qindex; }
01631 
01632 
01633     private:
01634         unsigned int m_max_qindex;
01635         OneDArray<int> m_qflist4;
01636         OneDArray<int> m_intra_offset4;
01637         OneDArray<int> m_inter_offset4;
01638 
01639     };
01640 
01642     static const QuantiserLists dirac_quantiser_lists;
01643 
01644 } // namespace dirac
01645 
01646 #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.