Created by the British Broadcasting Corporation.
00001 /* ***** BEGIN LICENSE BLOCK ***** 00002 * 00003 * $Id: common.h,v 1.52 2007/04/11 08:08:49 tjdwave Exp $ $Name: Dirac_0_7_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 enumeration types used throughout the codec ...// 00068 00070 enum PredMode{ INTRA , REF1_ONLY , REF2_ONLY , REF1AND2, UNDEFINED }; 00071 00073 enum CompSort{ Y_COMP , U_COMP , V_COMP }; 00074 00076 enum AddOrSub{ ADD , SUBTRACT }; 00077 00079 enum Direction { FORWARD , BACKWARD }; 00080 00082 enum CtxAliases 00083 {//used for residual coding 00084 SIGN0_CTX, // -sign, previous symbol is 0 00085 SIGN_POS_CTX, // -sign, previous symbol is +ve 00086 SIGN_NEG_CTX, // -sign, previous symbol is -ve 00087 00088 // Follow bit contexts 00089 Z_FBIN1z_CTX, // -bin 1, parent is zero, neighbours zero 00090 Z_FBIN1nz_CTX, // -bin 1, parent is zero, neighbours non-zero 00091 Z_FBIN2_CTX, // -bin 2, parent is zero 00092 Z_FBIN3_CTX, // -bin 3, parent is zero 00093 Z_FBIN4_CTX, // -bin 4, parent is zero 00094 Z_FBIN5_CTX, // -bin 5, parent is zero 00095 Z_FBIN6plus_CTX, // -bins 6 plus, parent is zero 00096 00097 NZ_FBIN1z_CTX, // -bin 1, parent is non-zero, neighbours zero 00098 NZ_FBIN1nz_CTX, // -bin 1, parent is non-zero, neighbours non-zero 00099 NZ_FBIN2_CTX, // -bin 2, parent is non-zero 00100 NZ_FBIN3_CTX, // -bin 3, parent is non-zero 00101 NZ_FBIN4_CTX, // -bin 4, parent is non-zero 00102 NZ_FBIN5_CTX, // -bin 5, parent is non-zero 00103 NZ_FBIN6plus_CTX, // -bins 6 plus, parent is non-zero 00104 00105 // Information bit contexts 00106 INFO_CTX, 00107 00108 BLOCK_SKIP_CTX, // - blocks are skipped 00109 Q_OFFSET_FOLLOW_CTX, // - code block quantiser offset magnitude 00110 Q_OFFSET_INFO_CTX, // - code block quantiser offset info context 00111 Q_OFFSET_SIGN_CTX, // - code block quantiser offset sign 00112 TOTAL_COEFF_CTXS // The total number of coefficient contexts 00113 }; 00114 00116 enum MvCtxAliases 00117 { 00118 // DC value contexts // 00120 00121 DC_FBIN1_CTX, 00122 DC_FBIN2plus_CTX, 00123 DC_INFO_CTX, 00124 DC_SIGN_CTX, 00125 00126 // Motion vector contexts // 00128 00129 00130 MV_FBIN1_CTX, 00131 MV_FBIN2_CTX, 00132 MV_FBIN3_CTX, 00133 MV_FBIN4_CTX, 00134 MV_FBIN5plus_CTX, 00135 00136 MV_INFO_CTX, 00137 00138 MV_SIGN_CTX, 00139 00140 00141 // Prediction mode contexts 00142 00143 PMODE_BIT0_CTX, // -bit 0, prediction mode value 00144 PMODE_BIT1_CTX, // -bin 1, prediction mode value 00145 00146 00147 // Macroblock contexts 00148 00149 MB_SPLIT_BIN1_CTX, // bin 1, MB split mode vals 00150 MB_SPLIT_BIN2_CTX, // bin 2, MB split mode vals. Bin 3 not required 00151 00152 MB_SPLIT_INFO_CTX, // info context for MB split mode 00153 00154 TOTAL_MV_CTXS // The total number of motion vector contexts 00155 }; 00156 00157 00163 VideoFormat IntToVideoFormat(int video_format); 00164 00170 ChromaFormat IntToChromaFormat(int chroma_format); 00171 00177 FrameRateType IntToFrameRateType(int frame_rate_idx); 00178 00184 AspectRatioType IntToAspectRatioType(int aspect_ratio_idx); 00185 00191 SignalRangeType IntToSignalRangeType(int signal_range_idx); 00192 00198 MVPrecisionType IntToMVPrecisionType(int mv_prec); 00199 00200 //Classes used throughout the codec// 00203 class FrameSort 00204 { 00205 public: 00206 FrameSort() { fs = 0x00; } // default intra non-ref 00207 00208 void SetIntra() { fs &= 0xfe; } 00209 void SetInter() { fs |= 0x01; } 00210 void SetNonRef() { fs &= 0xfd; } 00211 void SetRef() { fs |= 0x02; } 00212 00213 bool IsInter () const { return fs & 0x01; } 00214 bool IsIntra () const { return !IsInter(); } 00215 bool IsRef() const { return fs & 0x02; }; 00216 bool IsNonRef() const { return !IsRef(); } 00217 00218 void SetIntraNonRef() { SetIntra(); SetNonRef(); } 00219 void SetIntraRef() { SetIntra(); SetRef(); } 00220 void SetInterNonRef() { SetInter(); SetNonRef(); } 00221 void SetInterRef() { SetInter(); SetRef(); } 00222 00223 bool IsIntraNonRef() const { return (fs & 0x03) == 0x00; } 00224 bool IsIntraRef() const { return (fs & 0x03) == 0x02; } 00225 bool IsInterNonRef() const { return (fs & 0x03) == 0x01; } 00226 bool IsInterRef() const { return (fs & 0x03) == 0x03; } 00227 00228 void Clear() { fs=0x00; } 00229 00230 static FrameSort IntraRefFrameSort() 00231 { 00232 FrameSort fs; 00233 fs.SetIntraRef(); 00234 return fs; 00235 } 00236 00237 static FrameSort InterRefFrameSort() 00238 { 00239 FrameSort fs; 00240 fs.SetInterRef(); 00241 return fs; 00242 } 00243 00244 static FrameSort IntraNonRefFrameSort() 00245 { 00246 FrameSort fs; 00247 fs.SetIntraNonRef(); 00248 return fs; 00249 } 00250 00251 static FrameSort InterNonRefFrameSort() 00252 { 00253 FrameSort fs; 00254 fs.SetInterNonRef(); 00255 return fs; 00256 } 00257 00258 private: 00259 unsigned char fs; 00260 }; 00261 00263 00269 class PicArray: public TwoDArray<ValueType> 00270 { 00271 public: 00273 00276 PicArray(): TwoDArray<ValueType>(){} 00277 00279 00283 PicArray(int height, int width, CompSort cs=Y_COMP); 00284 00285 //copy constructor and assignment= derived by inheritance 00286 00288 ~PicArray(){} 00289 00291 const CompSort& CSort() const; 00292 00294 void SetCSort(const CompSort cs); 00295 00296 private: 00297 00298 CompSort m_csort; 00299 }; 00300 00301 00303 class CostType 00304 { 00305 public: 00307 double Error; 00308 00310 double ENTROPY; 00311 00313 double TOTAL; 00314 }; 00315 00316 00318 00323 class EntropyCorrector 00324 { 00325 public: 00327 00331 EntropyCorrector(int depth); 00332 00334 //NB: Assume default copy constructor, assignment = and destructor// 00336 00338 00342 float Factor(const int bandnum, const FrameSort fsort,const CompSort c) const; 00343 00345 00353 void Update(int bandnum, FrameSort fsort, CompSort c,int est_bits,int actual_bits); 00354 00355 private: 00357 void Init(); 00358 00359 TwoDArray<float> m_Yfctrs; 00360 TwoDArray<float> m_Ufctrs; 00361 TwoDArray<float> m_Vfctrs; 00362 }; 00363 00365 class OLBParams 00366 { 00367 00368 public: 00369 00371 OLBParams(){} 00372 00374 /* 00375 Constructor rationalises proposed parameters to allow suitable 00376 overlap and fit in with chroma format 00377 \param xblen the horizontal block length 00378 \param yblen the vertical block length 00379 \param xblen the horizontal block separation 00380 \param yblen the vertical block separation 00381 00382 */ 00383 OLBParams(const int xblen, const int yblen, 00384 const int xbsep, const int ybsep); 00385 00386 // Gets ... 00387 00389 int Xblen() const {return m_xblen;} 00390 00392 int Yblen() const {return m_yblen;} 00393 00395 int Xbsep() const {return m_xbsep;} 00396 00398 int Ybsep() const {return m_ybsep;} 00399 00401 int Xoffset() const {return m_xoffset;} 00402 00404 int Yoffset() const {return m_yoffset;} 00405 00406 // ... and sets 00407 00409 void SetXblen( int xblen ){ m_xblen = xblen; m_xoffset = (m_xblen-m_xbsep)/2;} 00410 00412 void SetYblen( int yblen ){ m_yblen = yblen; m_yoffset = (m_yblen-m_ybsep)/2;} 00413 00415 void SetXbsep( int xbsep ){ m_xbsep = xbsep; m_xoffset = (m_xblen-m_xbsep)/2;} 00416 00418 void SetYbsep( int ybsep ){ m_ybsep = ybsep; m_yoffset = (m_yblen-m_ybsep)/2;} 00419 00420 bool operator == (const OLBParams bparams) const; 00421 00422 // overloaded stream operators 00423 friend std::ostream & operator<< (std::ostream &, OLBParams &); 00424 friend std::istream & operator>> (std::istream &, OLBParams &); 00425 00426 00427 private: 00428 00429 int m_xblen; 00430 int m_yblen; 00431 int m_xbsep; 00432 int m_ybsep; 00433 int m_xoffset; 00434 int m_yoffset; 00435 }; 00436 00438 class SeqParams 00439 { 00440 public: 00442 SeqParams(const VideoFormat& video_format=VIDEO_FORMAT_CUSTOM, 00443 bool set_defaults=true); 00444 00446 //NB: Assume default copy constructor, assignment = and destructor// 00448 00449 //gets ... 00451 int Xl() const {return m_xl;} 00452 00454 int Yl() const {return m_yl;} 00455 00457 ChromaFormat CFormat() const {return m_cformat;} 00458 00460 int ChromaWidth() const; 00461 00463 int ChromaHeight() const; 00464 00466 int BitstreamVersion() const {return m_bs_ver;} 00467 00469 VideoFormat GetVideoFormat() const { return m_video_format;} 00470 00472 int GetVideoDepth() const { return m_video_depth; } 00473 00474 // ... Sets 00475 00477 void SetXl(int xlen) {m_xl = xlen;} 00478 00480 void SetYl(int ylen) {m_yl = ylen;} 00481 00483 void SetCFormat(ChromaFormat cf) {m_cformat=cf;} 00484 00486 void SetVideoDepth(int vd){ m_video_depth=vd;} 00487 00489 void SetBitstreamVersion(int bs_ver){m_bs_ver=bs_ver;} 00490 00491 00492 private: 00494 int m_xl; 00495 00497 int m_yl; 00498 00500 ChromaFormat m_cformat; 00501 00503 unsigned char m_bs_ver; 00504 00506 VideoFormat m_video_format; 00507 00509 int m_video_depth; 00510 }; 00511 00513 class Rational 00514 { 00515 public: 00517 unsigned int m_num; 00519 unsigned int m_denom; 00520 }; 00521 00523 class ParseParams 00524 { 00525 public: 00527 ParseParams(unsigned int au_pnum = 0); 00528 00529 // Gets 00530 00532 unsigned int AccessUnitPictureNumber() const { return m_au_pnum; } 00533 00535 unsigned int MajorVersion() const { return m_major_ver; } 00536 00538 unsigned int MinorVersion() const { return m_minor_ver; } 00539 00541 unsigned int Profile() const { return m_profile; } 00542 00544 unsigned int Level() const { return m_level; } 00545 00546 // Sets 00547 00549 void SetAccessUnitPictureNumber(unsigned int au_pnum) { m_au_pnum = au_pnum; } 00550 00552 void SetMajorVersion(unsigned int major_ver) { m_major_ver = major_ver; } 00553 00555 void SetMinorVersion(unsigned int minor_ver) { m_minor_ver = minor_ver; } 00556 00558 void SetProfile(unsigned int level) { m_level = level; } 00559 00561 void SetLevel(unsigned int profile) { m_profile = profile; } 00562 00563 private: 00565 unsigned int m_au_pnum; 00567 unsigned int m_major_ver; 00569 unsigned int m_minor_ver; 00571 unsigned int m_profile; 00573 unsigned int m_level; 00574 }; 00575 00577 class SourceParams 00578 { 00579 public: 00581 SourceParams (const VideoFormat &vf = VIDEO_FORMAT_CUSTOM, 00582 bool set_defaults=true); 00583 00585 //NB: Assume default copy constructor, assignment = and destructor// 00587 00588 // Gets 00590 bool Interlace() const { return m_interlace; } 00591 00593 bool TopFieldFirst() const { return m_topfieldfirst; } 00594 00596 bool SequentialFields() const { return m_seq_fields; } 00597 00599 Rational FrameRate() const { return m_framerate; } 00600 00602 FrameRateType FrameRateIndex() const { return m_fr_idx; } 00603 00605 Rational AspectRatio() const { return m_aspect_ratio; } 00606 00608 AspectRatioType AspectRatioIndex() const { return m_asr_idx; } 00609 00610 // Clean area parameters 00612 unsigned int CleanWidth() const { return m_clean_width; } 00614 unsigned int CleanHeight() const { return m_clean_height; } 00616 unsigned int LeftOffset() const { return m_left_offset; } 00618 unsigned int TopOffset() const { return m_top_offset; } 00619 00620 // Signal Range parameters 00621 00623 SignalRangeType SignalRangeIndex() const { return m_sr_idx; } 00624 00626 unsigned int LumaOffset() const { return m_luma_offset; } 00628 unsigned int LumaExcursion() const { return m_luma_excursion; } 00630 unsigned int ChromaOffset() const { return m_chroma_offset; } 00632 unsigned int ChromaExcursion() const { return m_chroma_excursion; } 00633 00635 unsigned int ColourSpecificationIndex() const { return m_cs_idx; } 00636 00638 ColourPrimaries ColourPrimariesIndex() const { return m_col_primary; } 00640 ColourMatrix ColourMatrixIndex() const { return m_col_matrix; } 00642 TransferFunction TransferFunctionIndex() const { return m_transfer_func; } 00643 00644 // Sets 00646 void SetInterlace(bool interlace) { m_interlace = interlace; } 00647 00649 void SetTopFieldFirst(bool tff) { m_topfieldfirst = tff; } 00650 00652 void SetSequentialFields(bool seq_flds) { m_seq_fields = seq_flds; } 00653 00655 void SetFrameRate(const Rational &frate ) 00656 { 00657 m_fr_idx = FRAMERATE_CUSTOM; m_framerate = frate; 00658 } 00659 00661 void SetFrameRate(unsigned int fr_num, unsigned int fr_denom ) 00662 { 00663 m_fr_idx = FRAMERATE_CUSTOM; 00664 m_framerate.m_num = fr_num; 00665 m_framerate.m_denom = fr_denom; 00666 } 00667 00669 void SetFrameRate(FrameRateType fr); 00670 00672 void SetAspectRatio(const Rational &asr) 00673 { 00674 m_asr_idx = ASPECT_RATIO_CUSTOM; 00675 m_aspect_ratio = asr; 00676 } 00677 00679 void SetAspectRatio(unsigned int as_num, unsigned int as_denom ) 00680 { 00681 m_asr_idx = ASPECT_RATIO_CUSTOM; 00682 m_aspect_ratio.m_num = as_num; 00683 m_aspect_ratio.m_denom = as_denom; 00684 } 00685 00687 void SetAspectRatio(AspectRatioType aspect_ratio); 00688 00689 // Clean area parameters 00691 void SetCleanWidth(unsigned int clean_width) { m_clean_width = clean_width; } 00693 void SetCleanHeight(unsigned int clean_height) { m_clean_height = clean_height; } 00695 void SetLeftOffset(unsigned int left_offset) { m_left_offset = left_offset; } 00697 void SetTopOffset(unsigned int top_offset) { m_top_offset = top_offset; } 00698 00699 // Signal Range parameters 00701 void SetSignalRange(SignalRangeType sr); 00702 00704 void SetLumaOffset(unsigned int luma_offset) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_offset = luma_offset; } 00706 void SetLumaExcursion(unsigned int luma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_excursion = luma_exc; } 00708 void SetChromaOffset(unsigned int chroma_off) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_offset = chroma_off; } 00710 void SetChromaExcursion(unsigned int chroma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_excursion = chroma_exc; } 00711 00713 void SetColourSpecification(unsigned int cs_idx); 00715 void SetColourPrimariesIndex(unsigned int cp); 00717 void SetColourMatrixIndex(unsigned int cm); 00719 void SetTransferFunctionIndex(unsigned int tf); 00720 00721 private: 00723 bool m_interlace; 00724 00726 bool m_topfieldfirst; 00727 00729 bool m_seq_fields; 00730 00732 FrameRateType m_fr_idx; 00733 00735 Rational m_framerate; 00736 00738 AspectRatioType m_asr_idx; 00739 00741 Rational m_aspect_ratio; 00742 00743 // Clean area parameters 00744 00746 unsigned int m_clean_width; 00747 00749 unsigned int m_clean_height; 00750 00752 unsigned int m_left_offset; 00753 00755 unsigned int m_top_offset; 00756 00757 // signal range parameters 00758 00760 SignalRangeType m_sr_idx; 00761 00763 unsigned int m_luma_offset; 00765 unsigned int m_luma_excursion; 00767 unsigned int m_chroma_offset; 00769 unsigned int m_chroma_excursion; 00770 00772 unsigned int m_cs_idx; 00773 00775 ColourPrimaries m_col_primary; 00776 00777 // Colour Matrix index 00778 ColourMatrix m_col_matrix; 00779 00780 // Transfer function index 00781 TransferFunction m_transfer_func; 00782 }; 00783 00785 class FrameParams 00786 { 00787 00788 public: 00790 FrameParams(); 00791 00793 00796 FrameParams(const ChromaFormat& cf, int xlen, int ylen, int c_xlen, int c_ylen, unsigned int video_depth); 00797 00799 00802 FrameParams(const ChromaFormat& cf, const FrameSort& fs); 00803 00805 /* 00806 All data is derived from the sequence parameters 00807 */ 00808 FrameParams(const SeqParams& sparams); 00809 00811 /* 00812 All data is derived from the sequence parameters 00813 */ 00814 FrameParams(const SeqParams& sparams, const FrameSort& fs); 00815 00817 //NB: Assume default copy constructor, assignment = and destructor// 00819 00820 // Gets ... 00821 00823 const ChromaFormat& CFormat() const{return m_cformat;} 00824 00826 int Xl() const{return m_xl;} 00827 00829 int Yl() const{return m_yl;} 00830 00832 int ChromaXl() const{return m_chroma_xl;} 00833 00835 int ChromaYl() const{return m_chroma_yl;} 00836 00838 const FrameSort& FSort() const {return m_fsort;} 00839 00841 int FrameNum() const {return m_fnum;} 00842 00844 bool IsBFrame() const; 00845 00847 int ExpiryTime() const {return m_expiry_time;} 00848 00850 bool Output() const {return m_output;} 00851 00853 const std::vector<int>& Refs() const {return m_refs;} 00854 00856 std::vector<int>& Refs(){return m_refs;} 00857 00859 unsigned int NumRefs()const {return m_refs.size();} 00860 00862 FrameType GetFrameType () const { return m_frame_type; } 00863 00865 ReferenceType GetReferenceType() const { return m_reference_type;} 00866 00868 unsigned int GetVideoDepth() const{return m_video_depth;} 00869 00870 // ... Sets 00871 00873 void SetFSort( const FrameSort& fs ); 00874 00876 void SetFrameType(const FrameType ftype); 00877 00879 void SetReferenceType(const ReferenceType rtype); 00880 00882 void SetFrameNum( const int fn ){ m_fnum=fn; } 00883 00885 void SetExpiryTime( const int expt ){ m_expiry_time=expt; } 00886 00888 void SetAsOutput(){m_output=true;} 00889 00891 void SetCFormat(ChromaFormat cf){ m_cformat = cf; } 00892 00894 void SetXl(int xl){m_xl = xl; } 00895 00897 void SetYl(int yl){m_yl = yl; } 00898 00900 void SetChromaXl(int xl){m_chroma_xl = xl; } 00901 00903 void SetChromaYl(int yl){m_chroma_yl = yl; } 00904 00906 void SetVideoDepth(int vd) { m_video_depth = vd; } 00907 00909 std::vector<int>& RetiredFrames() const {return m_retd_list;} 00910 00912 std::vector<int>& RetiredFrames() {return m_retd_list;} 00913 00914 private: 00915 00917 ChromaFormat m_cformat; 00918 00920 int m_xl; 00921 00923 int m_yl; 00924 00926 FrameSort m_fsort; 00927 00929 std::vector<int> m_refs; 00930 00932 int m_expiry_time; 00933 00935 int m_fnum; 00936 00938 FrameType m_frame_type; 00939 00941 ReferenceType m_reference_type; 00942 00944 bool m_output; 00945 00947 int m_chroma_xl; 00948 00950 int m_chroma_yl; 00951 00953 mutable std::vector<int> m_retd_list; 00954 00956 unsigned int m_video_depth; 00957 00958 }; 00959 00961 class CodeBlocks 00962 { 00963 public: 00965 CodeBlocks () : m_hblocks(0), m_vblocks(0) 00966 {} 00967 00969 CodeBlocks (unsigned int hblocks, unsigned int vblocks) : 00970 m_hblocks(hblocks), 00971 m_vblocks(vblocks) 00972 {} 00973 00974 // Gets 00976 unsigned int HorizontalCodeBlocks() const { return m_hblocks; } 00978 unsigned int VerticalCodeBlocks() const { return m_vblocks; } 00979 // Sets 00981 void SetHorizontalCodeBlocks(unsigned int hblocks) { m_hblocks = hblocks; } 00983 void SetVerticalCodeBlocks(unsigned int vblocks) { m_vblocks = vblocks; } 00984 private: 00986 unsigned int m_hblocks; 00988 unsigned int m_vblocks; 00989 }; 00991 00994 class CodecParams 00995 { 00996 public: 00997 00999 CodecParams(const VideoFormat& vd, FrameType ftype, unsigned int num_refs, bool set_defaults); 01000 01002 //NB: Assume default copy constructor, assignment = and destructor// 01004 01005 // Gets ... 01006 01008 int XNumMB() const {return m_x_num_mb;} 01009 01011 int YNumMB() const {return m_y_num_mb;} 01012 01014 int XNumBlocks() const {return m_x_num_blocks;} 01015 01017 int YNumBlocks() const {return m_y_num_blocks;} 01018 01020 bool Verbose() const {return m_verbose;} 01021 01023 bool Interlace() const {return m_interlace;} 01024 01026 bool TopFieldFirst() const {return m_topfieldfirst;} 01027 01029 const OLBParams& LumaBParams(int n) const {return m_lbparams[n];} 01030 01032 const OLBParams& ChromaBParams(int n) const {return m_cbparams[n];} 01033 01035 int OrigXl() const {return m_orig_xl;} 01036 01038 int OrigYl() const {return m_orig_yl;} 01039 01041 MVPrecisionType MVPrecision() const { return m_mv_precision; } 01042 01044 bool ZeroTransform() const { return m_zero_transform; } 01045 01047 WltFilter TransformFilter() const { return m_wlt_filter; } 01048 01050 unsigned int TransformDepth() const { return m_wlt_depth; } 01051 01053 CodeBlockMode GetCodeBlockMode() const { return m_cb_mode; } 01054 01056 bool SpatialPartition() const { return m_spatial_partition; } 01057 01059 bool DefaultSpatialPartition() const { return m_def_spatial_partition; } 01061 const CodeBlocks &GetCodeBlocks(unsigned int level) const; 01062 01064 VideoFormat GetVideoFormat() const { return m_video_format; } 01065 01067 bool UsingGlobalMotion() const { return m_use_global_motion; } 01068 01070 unsigned int FrameWeightsBits() const { return m_frame_weights_bits; } 01071 01073 unsigned int Ref1Weight() const { return m_ref1_weight; } 01074 01076 unsigned int Ref2Weight() const { return m_ref2_weight; } 01077 01078 // ... and Sets 01080 void SetXNumMB(const int xn){m_x_num_mb=xn;} 01081 01083 void SetYNumMB(const int yn){m_y_num_mb=yn;} 01084 01086 void SetXNumBlocks(const int xn){m_x_num_blocks=xn;} 01087 01089 void SetYNumBlocks(const int yn){m_y_num_blocks=yn;} 01090 01092 void SetVerbose(bool v){m_verbose=v;} 01093 01095 void SetInterlace(bool intlc){m_interlace=intlc;} 01096 01098 void SetTopFieldFirst(bool topf){m_topfieldfirst=topf;} 01099 01101 void SetBlockSizes(const OLBParams& olbparams , const ChromaFormat cformat); 01103 void SetLumaBlockParams(const OLBParams& olbparams) {m_lbparams[2] = olbparams;} 01104 01106 void SetOrigXl(const int x){m_orig_xl=x;} 01107 01109 void SetOrigYl(const int y){m_orig_yl=y;} 01110 01112 void SetMVPrecision(const MVPrecisionType p) 01113 { 01114 // Assert in debug mode. Maybe we should throw an exception??? 01115 TESTM((p >=0 && p <=3), "Motion precision value in range 0..3"); 01116 m_mv_precision = p; 01117 } 01118 01119 void SetMVPrecision(const MVPrecisionType p) const 01120 { 01121 // Assert in debug mode. Maybe we should throw an exception??? 01122 TESTM((p >=0 && p <=3), "Motion precision value in range 0..3"); 01123 m_mv_precision = p; 01124 } 01125 01127 void SetZeroTransform(bool zero_transform) { m_zero_transform = zero_transform; } 01128 01130 void SetTransformFilter(const WltFilter wf) { m_wlt_filter=wf; } 01131 01133 void SetTransformFilter(unsigned int wf_idx); 01134 01136 void SetTransformDepth(unsigned int wd); 01137 01139 void SetCodeBlockMode(unsigned int cb_mode); 01140 01142 void SetSpatialPartition(bool spatial_partition) { m_spatial_partition=spatial_partition; } 01143 01145 void SetDefaultSpatialPartition(bool def_spatial_partition) { m_def_spatial_partition=def_spatial_partition; } 01146 01148 void SetCodeBlocks(unsigned int level, unsigned int hblocks, unsigned int vblocks); 01149 01151 void SetDefaultCodeBlocks(const FrameType& ftype); 01152 01154 void SetVideoFormat(const VideoFormat vd) { m_video_format=vd; } 01155 01157 void SetUsingGlobalMotion(bool gm) { m_use_global_motion=gm; } 01158 01160 void SetFrameWeightsPrecision(unsigned int wt_prec) { m_frame_weights_bits=wt_prec; } 01161 01163 void SetRef1Weight(unsigned int wt) { m_ref1_weight=wt; } 01164 01166 void SetRef2Weight(unsigned int wt) { m_ref2_weight=wt; } 01167 01168 protected: 01170 WltFilter TransformFilter (unsigned int wf_idx); 01171 private: 01172 01174 int m_x_num_mb; 01175 01177 int m_y_num_mb; 01178 01180 int m_x_num_blocks; 01181 01183 int m_y_num_blocks; 01184 01186 bool m_verbose; 01187 01189 bool m_interlace; 01190 01192 bool m_topfieldfirst; 01193 01194 OneDArray<OLBParams> m_lbparams; 01195 OneDArray<OLBParams> m_cbparams; 01196 01198 int m_orig_xl; 01199 01201 int m_orig_yl; 01202 01204 mutable MVPrecisionType m_mv_precision; 01205 01207 VideoFormat m_video_format; 01208 01210 bool m_use_global_motion; 01211 01213 unsigned int m_frame_weights_bits; 01214 01216 unsigned int m_ref1_weight; 01217 01219 unsigned int m_ref2_weight; 01220 01222 bool m_zero_transform; 01223 01225 WltFilter m_wlt_filter; 01226 01228 unsigned int m_wlt_depth; 01229 01231 CodeBlockMode m_cb_mode; 01232 01234 bool m_spatial_partition; 01235 01237 bool m_def_spatial_partition; 01238 01240 OneDArray<CodeBlocks> m_cb; 01241 }; 01242 01244 01247 class EncoderParams: public CodecParams 01248 { 01249 //codec params plus parameters relating solely to the operation of the encoder 01250 01251 public: 01253 EncoderParams(const VideoFormat& video_format, 01254 FrameType ftype = INTER_FRAME, 01255 unsigned int num_refs = 2, 01256 bool set_defaults=true); 01257 01259 //NB: Assume default copy constructor, assignment = and destructor// 01260 //This means pointers are copied, not the objects they point to.//// 01262 01263 // Gets ... 01264 01266 bool LocalDecode() const {return m_loc_decode;} 01267 01269 bool Lossless() const {return m_lossless;} 01270 01272 float Qf() const {return m_qf;} 01273 01275 01280 int NumL1() const {return m_num_L1;} 01281 01283 int L1Sep() const {return m_L1_sep;} 01284 01286 float UFactor() const {return m_ufactor;} 01287 01289 float VFactor() const {return m_vfactor;} 01290 01292 float CPD() const {return m_cpd;} 01293 01295 bool Denoise() const {return m_denoise;} 01296 01298 float ILambda() const {return m_I_lambda;} 01299 01301 float L1Lambda() const {return m_L1_lambda;} 01302 01304 float L2Lambda() const {return m_L2_lambda;} 01305 01307 float L1MELambda() const {return m_L1_me_lambda;} 01308 01310 float L2MELambda() const {return m_L2_me_lambda;} 01311 01313 int GOPLength() const { if (m_num_L1>0) return (m_num_L1+1)*m_L1_sep; 01314 return (m_num_L1==0) ? 10 : 0; } 01315 01317 char * OutputPath() const {return ( char* ) m_output_path.c_str();} 01318 01320 const EntropyCorrector& EntropyFactors() const {return *m_ent_correct;} 01321 01323 EntropyCorrector& EntropyFactors() {return *m_ent_correct;} 01324 01326 WltFilter IntraTransformFilter() { return m_intra_wltfilter; } 01327 01329 WltFilter InterTransformFilter() { return m_inter_wltfilter; } 01330 01332 int TargetRate() {return m_target_rate;} 01333 01334 // ... and Sets 01335 01337 void SetLocalDecode( const bool decode ){m_loc_decode=decode;} 01338 01340 void SetLossless(const bool l){m_lossless = l;} 01341 01343 void SetQf(const float qfac){ m_qf=qfac; CalcLambdas(m_qf); } 01344 01346 void SetNumL1(const int nl){m_num_L1=nl;} 01347 01349 void SetL1Sep(const int lsep){m_L1_sep=lsep;} 01350 01352 void SetUFactor(const float uf){m_ufactor=uf;} 01353 01355 void SetVFactor(const float vf){m_vfactor=vf;} 01356 01358 void SetCPD(const float cpd){m_cpd=cpd;} 01359 01360 01362 void SetDenoise(const bool denoise){m_denoise=denoise;} 01363 01365 void SetOutputPath(const char * op){ m_output_path = op; } 01366 01368 void SetEntropyFactors(EntropyCorrector* entcorrect){m_ent_correct=entcorrect;} 01370 void SetIntraTransformFilter(unsigned int wf_idx); 01371 01373 void SetInterTransformFilter(unsigned int wf_idx); 01374 01376 void SetIntraTransformFilter(WltFilter wf) { m_intra_wltfilter = wf; } 01377 01379 void SetInterTransformFilter(WltFilter wf) { m_inter_wltfilter = wf; } 01380 01382 void SetTargetRate(const int rate){m_target_rate = rate;} 01383 private: 01384 01386 void CalcLambdas(const float qf); 01387 01388 private: 01389 01391 bool m_loc_decode; 01392 01394 bool m_lossless; 01395 01397 float m_qf; 01398 01400 int m_num_L1; 01401 01403 int m_L1_sep; 01404 01406 float m_ufactor; 01407 01409 float m_vfactor; 01410 01412 float m_cpd; 01413 01415 bool m_denoise; 01416 01418 float m_I_lambda; 01419 01421 float m_L1_lambda; 01422 01424 float m_L2_lambda; 01425 01427 float m_L1_me_lambda; 01428 01430 float m_L2_me_lambda; 01431 01433 EntropyCorrector* m_ent_correct; 01434 01436 std::string m_output_path; 01437 01439 WltFilter m_intra_wltfilter; 01440 01442 WltFilter m_inter_wltfilter; 01443 01445 int m_target_rate; 01446 01447 }; 01448 01450 01453 class DecoderParams: public CodecParams 01454 { 01455 public: 01457 DecoderParams(const VideoFormat& video_format = VIDEO_FORMAT_CIF, FrameType ftype=INTRA_FRAME, unsigned int num_refs = 0, bool set_defaults = false); 01458 01460 //NB: Assume default copy constructor, assignment = and destructor// 01461 //This means pointers are copied, not the objects they point to.//// 01463 01464 01465 private: 01466 01467 }; 01468 01470 inline ValueType BChk(const ValueType &num, const ValueType &max) 01471 { 01472 if(num < 0) return 0; 01473 else if(num >= max) return max-1; 01474 else return num; 01475 } 01476 01478 class QuantiserLists 01479 { 01480 public: 01482 QuantiserLists(); 01483 01485 inline int QuantFactor4( const int index ) const {return m_qflist4[index]; } 01486 01488 inline int IntraQuantOffset4( const int index ) const {return m_intra_offset4[index]; } 01490 inline int InterQuantOffset4( const int index ) const {return m_inter_offset4[index]; } 01491 01493 inline int MaxQIndex() const {return m_max_qindex; } 01494 01495 01496 private: 01497 unsigned int m_max_qindex; 01498 OneDArray<int> m_qflist4; 01499 OneDArray<int> m_intra_offset4; 01500 OneDArray<int> m_inter_offset4; 01501 01502 }; 01503 01505 static const QuantiserLists dirac_quantiser_lists; 01506 01507 } // namespace dirac 01508 01509 #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.