Created by the British Broadcasting Corporation.
00001 /* ***** BEGIN LICENSE BLOCK ***** 00002 * 00003 * $Id: common.h,v 1.46 2006/11/22 11:00:24 tjdwave Exp $ $Name: $ 00004 * 00005 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 00006 * 00007 * The contents of this file are subject to the Mozilla Public License 00008 * Version 1.1 (the "License"); you may not use this file except in compliance 00009 * with the License. You may obtain a copy of the License at 00010 * http://www.mozilla.org/MPL/ 00011 * 00012 * Software distributed under the License is distributed on an "AS IS" basis, 00013 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for 00014 * the specific language governing rights and limitations under the License. 00015 * 00016 * The Original Code is BBC Research and Development code. 00017 * 00018 * The Initial Developer of the Original Code is the British Broadcasting 00019 * Corporation. 00020 * Portions created by the Initial Developer are Copyright (C) 2004. 00021 * All Rights Reserved. 00022 * 00023 * Contributor(s): Thomas Davies (Original Author), 00024 * Scott R Ladd, 00025 * Tim Borer, 00026 * Anuradha Suraparaju, 00027 * Andrew Kennedy 00028 * 00029 * Alternatively, the contents of this file may be used under the terms of 00030 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser 00031 * Public License Version 2.1 (the "LGPL"), in which case the provisions of 00032 * the GPL or the LGPL are applicable instead of those above. If you wish to 00033 * allow use of your version of this file only under the terms of the either 00034 * the GPL or LGPL and not to allow others to use your version of this file 00035 * under the MPL, indicate your decision by deleting the provisions above 00036 * and replace them with the notice and other provisions required by the GPL 00037 * or LGPL. If you do not delete the provisions above, a recipient may use 00038 * your version of this file under the terms of any one of the MPL, the GPL 00039 * or the LGPL. 00040 * ***** END LICENSE BLOCK ***** */ 00041 00042 #ifndef _COMMON_H_ 00043 #define _COMMON_H_ 00044 00045 #include <libdirac_common/arrays.h> 00046 #include <libdirac_common/common_types.h> 00047 #include <libdirac_common/dirac_assertions.h> 00048 #include <vector> 00049 #include <cmath> 00050 namespace dirac 00051 { 00061 //Some basic enumeration types used throughout the codec ...// 00063 00065 enum PredMode{ INTRA , REF1_ONLY , REF2_ONLY , REF1AND2, UNDEFINED }; 00066 00068 enum CompSort{ Y_COMP , U_COMP , V_COMP }; 00069 00071 enum AddOrSub{ ADD , SUBTRACT }; 00072 00074 enum Direction { FORWARD , BACKWARD }; 00075 00077 enum CtxAliases 00078 {//used for residual coding 00079 SIGN0_CTX, // -sign, previous symbol is 0 00080 SIGN_POS_CTX, // -sign, previous symbol is +ve 00081 SIGN_NEG_CTX, // -sign, previous symbol is -ve 00082 00083 // Follow bit contexts 00084 Z_FBIN1z_CTX, // -bin 1, parent is zero, neighbours zero 00085 Z_FBIN1nz_CTX, // -bin 1, parent is zero, neighbours non-zero 00086 Z_FBIN2_CTX, // -bin 2, parent is zero 00087 Z_FBIN3_CTX, // -bin 3, parent is zero 00088 Z_FBIN4_CTX, // -bin 4, parent is zero 00089 Z_FBIN5_CTX, // -bin 5, parent is zero 00090 Z_FBIN6plus_CTX, // -bins 6 plus, parent is zero 00091 00092 NZ_FBIN1z_CTX, // -bin 1, parent is non-zero, neighbours zero 00093 NZ_FBIN1nz_CTX, // -bin 1, parent is non-zero, neighbours non-zero 00094 NZ_FBIN2_CTX, // -bin 2, parent is non-zero 00095 NZ_FBIN3_CTX, // -bin 3, parent is non-zero 00096 NZ_FBIN4_CTX, // -bin 4, parent is non-zero 00097 NZ_FBIN5_CTX, // -bin 5, parent is non-zero 00098 NZ_FBIN6plus_CTX, // -bins 6 plus, parent is non-zero 00099 00100 // Information bit contexts 00101 INFO_CTX, 00102 00103 BLOCK_SKIP_CTX, // - blocks are skipped 00104 Q_OFFSET_FOLLOW_CTX, // - code block quantiser offset magnitude 00105 Q_OFFSET_INFO_CTX, // - code block quantiser offset info context 00106 Q_OFFSET_SIGN_CTX, // - code block quantiser offset sign 00107 TOTAL_COEFF_CTXS // The total number of coefficient contexts 00108 }; 00109 00111 enum MvCtxAliases 00112 { 00113 // DC value contexts // 00115 00116 // Luma 00117 YDC_FBIN1_CTX, // -bin 1 of follow bits 00118 YDC_FBIN2plus_CTX, // -remaining follow bins 00119 YDC_INFO_CTX, // -info bit context 00120 YDC_SIGN_CTX, // -sign context 00121 00122 UDC_FBIN1_CTX, 00123 UDC_FBIN2plus_CTX, 00124 UDC_INFO_CTX, 00125 UDC_SIGN_CTX, 00126 00127 VDC_FBIN1_CTX, 00128 VDC_FBIN2plus_CTX, 00129 VDC_INFO_CTX, 00130 VDC_SIGN_CTX, 00131 00132 00133 // Motion vector contexts // 00135 00136 REF1x_FBIN1_CTX, // -bin 1 of follow bits 00137 REF1x_FBIN2_CTX, // -bin 2 of follow bits 00138 REF1x_FBIN3_CTX, // -bin 3 of follows bits 00139 REF1x_FBIN4_CTX, // -bin 4 of follow bits 00140 REF1x_FBIN5plus_CTX, // -bins 5 plus of follow bits 00141 00142 REF1x_INFO_CTX, // context for information bits 00143 00144 REF1x_SIGN_CTX, // -sign 00145 00146 00147 REF1y_FBIN1_CTX, 00148 REF1y_FBIN2_CTX, 00149 REF1y_FBIN3_CTX, 00150 REF1y_FBIN4_CTX, 00151 REF1y_FBIN5plus_CTX, 00152 00153 REF1y_INFO_CTX, 00154 00155 REF1y_SIGN_CTX, 00156 00157 REF2x_FBIN1_CTX, 00158 REF2x_FBIN2_CTX, 00159 REF2x_FBIN3_CTX, 00160 REF2x_FBIN4_CTX, 00161 REF2x_FBIN5plus_CTX, 00162 00163 REF2x_INFO_CTX, 00164 00165 REF2x_SIGN_CTX, 00166 00167 REF2y_FBIN1_CTX, 00168 REF2y_FBIN2_CTX, 00169 REF2y_FBIN3_CTX, 00170 REF2y_FBIN4_CTX, 00171 REF2y_FBIN5plus_CTX, 00172 00173 REF2y_INFO_CTX, 00174 00175 REF2y_SIGN_CTX, 00176 00177 00178 // Prediction mode contexts 00179 00180 PMODE_BIT0_CTX, // -bit 0, prediction mode value 00181 PMODE_BIT1_CTX, // -bin 1, prediction mode value 00182 00183 00184 // Macroblock contexts 00185 00186 MB_SPLIT_BIN1_CTX, // bin 1, MB split mode vals 00187 MB_SPLIT_BIN2_CTX, // bin 2, MB split mode vals. Bin 3 not required 00188 00189 MB_SPLIT_INFO_CTX, // info context for MB split mode 00190 00191 TOTAL_MV_CTXS // The total number of motion vector contexts 00192 }; 00193 00194 00200 VideoFormat IntToVideoFormat(int video_format); 00201 00207 ChromaFormat IntToChromaFormat(int chroma_format); 00208 00214 FrameRateType IntToFrameRateType(int frame_rate_idx); 00215 00221 AspectRatioType IntToAspectRatioType(int aspect_ratio_idx); 00222 00228 SignalRangeType IntToSignalRangeType(int signal_range_idx); 00229 00235 MVPrecisionType IntToMVPrecisionType(int mv_prec); 00236 00237 //Classes used throughout the codec// 00240 class FrameSort 00241 { 00242 public: 00243 FrameSort() { fs = 0x00; } // default intra non-ref 00244 00245 void SetIntra() { fs &= 0xfe; } 00246 void SetInter() { fs |= 0x01; } 00247 void SetNonRef() { fs &= 0xfd; } 00248 void SetRef() { fs |= 0x02; } 00249 00250 bool IsInter () const { return fs & 0x01; } 00251 bool IsIntra () const { return !IsInter(); } 00252 bool IsRef() const { return fs & 0x02; }; 00253 bool IsNonRef() const { return !IsRef(); } 00254 00255 void SetIntraNonRef() { SetIntra(); SetNonRef(); } 00256 void SetIntraRef() { SetIntra(); SetRef(); } 00257 void SetInterNonRef() { SetInter(); SetNonRef(); } 00258 void SetInterRef() { SetInter(); SetRef(); } 00259 00260 bool IsIntraNonRef() const { return (fs & 0x03) == 0x00; } 00261 bool IsIntraRef() const { return (fs & 0x03) == 0x02; } 00262 bool IsInterNonRef() const { return (fs & 0x03) == 0x01; } 00263 bool IsInterRef() const { return (fs & 0x03) == 0x03; } 00264 00265 void Clear() { fs=0x00; } 00266 00267 static FrameSort IntraRefFrameSort() 00268 { 00269 FrameSort fs; 00270 fs.SetIntraRef(); 00271 return fs; 00272 } 00273 00274 static FrameSort InterRefFrameSort() 00275 { 00276 FrameSort fs; 00277 fs.SetInterRef(); 00278 return fs; 00279 } 00280 00281 static FrameSort IntraNonRefFrameSort() 00282 { 00283 FrameSort fs; 00284 fs.SetIntraNonRef(); 00285 return fs; 00286 } 00287 00288 static FrameSort InterNonRefFrameSort() 00289 { 00290 FrameSort fs; 00291 fs.SetInterNonRef(); 00292 return fs; 00293 } 00294 00295 private: 00296 unsigned char fs; 00297 }; 00298 00300 00306 class PicArray: public TwoDArray<ValueType> 00307 { 00308 public: 00310 00313 PicArray(): TwoDArray<ValueType>(){} 00314 00316 00320 PicArray(int height, int width, CompSort cs=Y_COMP); 00321 00322 //copy constructor and assignment= derived by inheritance 00323 00325 ~PicArray(){} 00326 00328 const CompSort& CSort() const; 00329 00331 void SetCSort(const CompSort cs); 00332 00333 private: 00334 00335 CompSort m_csort; 00336 }; 00337 00338 00340 class CostType 00341 { 00342 public: 00344 double Error; 00345 00347 double ENTROPY; 00348 00350 double TOTAL; 00351 }; 00352 00353 00355 00360 class EntropyCorrector 00361 { 00362 public: 00364 00368 EntropyCorrector(int depth); 00369 00371 //NB: Assume default copy constructor, assignment = and destructor// 00373 00375 00379 float Factor(const int bandnum, const FrameSort fsort,const CompSort c) const; 00380 00382 00390 void Update(int bandnum, FrameSort fsort, CompSort c,int est_bits,int actual_bits); 00391 00392 private: 00394 void Init(); 00395 00396 TwoDArray<float> m_Yfctrs; 00397 TwoDArray<float> m_Ufctrs; 00398 TwoDArray<float> m_Vfctrs; 00399 }; 00400 00402 class OLBParams 00403 { 00404 00405 public: 00406 00408 OLBParams(){} 00409 00411 /* 00412 Constructor rationalises proposed parameters to allow suitable 00413 overlap and fit in with chroma format 00414 \param xblen the horizontal block length 00415 \param yblen the vertical block length 00416 \param xblen the horizontal block separation 00417 \param yblen the vertical block separation 00418 00419 */ 00420 OLBParams(const int xblen, const int yblen, 00421 const int xbsep, const int ybsep); 00422 00423 // Gets ... 00424 00426 int Xblen() const {return m_xblen;} 00427 00429 int Yblen() const {return m_yblen;} 00430 00432 int Xbsep() const {return m_xbsep;} 00433 00435 int Ybsep() const {return m_ybsep;} 00436 00438 int Xoffset() const {return m_xoffset;} 00439 00441 int Yoffset() const {return m_yoffset;} 00442 00443 // ... and sets 00444 00446 void SetXblen( int xblen ){ m_xblen = xblen; m_xoffset = (m_xblen-m_xbsep)/2;} 00447 00449 void SetYblen( int yblen ){ m_yblen = yblen; m_yoffset = (m_yblen-m_ybsep)/2;} 00450 00452 void SetXbsep( int xbsep ){ m_xbsep = xbsep; m_xoffset = (m_xblen-m_xbsep)/2;} 00453 00455 void SetYbsep( int ybsep ){ m_ybsep = ybsep; m_yoffset = (m_yblen-m_ybsep)/2;} 00456 00457 bool operator == (const OLBParams bparams) const; 00458 00459 // overloaded stream operators 00460 friend std::ostream & operator<< (std::ostream &, OLBParams &); 00461 friend std::istream & operator>> (std::istream &, OLBParams &); 00462 00463 00464 private: 00465 00466 int m_xblen; 00467 int m_yblen; 00468 int m_xbsep; 00469 int m_ybsep; 00470 int m_xoffset; 00471 int m_yoffset; 00472 }; 00473 00475 class SeqParams 00476 { 00477 public: 00479 SeqParams(const VideoFormat& video_format=VIDEO_FORMAT_CUSTOM, 00480 bool set_defaults=true); 00481 00483 //NB: Assume default copy constructor, assignment = and destructor// 00485 00486 //gets ... 00488 int Xl() const {return m_xl;} 00489 00491 int Yl() const {return m_yl;} 00492 00494 ChromaFormat CFormat() const {return m_cformat;} 00495 00497 int ChromaWidth() const; 00498 00500 int ChromaHeight() const; 00501 00503 int BitstreamVersion() const {return m_bs_ver;} 00504 00506 VideoFormat GetVideoFormat() const { return m_video_format;} 00507 00509 int GetVideoDepth() const { return m_video_depth; } 00510 00511 // ... Sets 00512 00514 void SetXl(int xlen) {m_xl = xlen;} 00515 00517 void SetYl(int ylen) {m_yl = ylen;} 00518 00520 void SetCFormat(ChromaFormat cf) {m_cformat=cf;} 00521 00523 void SetVideoDepth(int vd){ m_video_depth=vd;} 00524 00526 void SetBitstreamVersion(int bs_ver){m_bs_ver=bs_ver;} 00527 00528 00529 private: 00531 int m_xl; 00532 00534 int m_yl; 00535 00537 ChromaFormat m_cformat; 00538 00540 unsigned char m_bs_ver; 00541 00543 VideoFormat m_video_format; 00544 00546 int m_video_depth; 00547 }; 00548 00550 class Rational 00551 { 00552 public: 00554 unsigned int m_num; 00556 unsigned int m_denom; 00557 }; 00558 00560 class ParseParams 00561 { 00562 public: 00564 ParseParams(unsigned int au_pnum = 0); 00565 00566 // Gets 00567 00569 unsigned int AccessUnitPictureNumber() const { return m_au_pnum; } 00570 00572 unsigned int MajorVersion() const { return m_major_ver; } 00573 00575 unsigned int MinorVersion() const { return m_minor_ver; } 00576 00578 unsigned int Profile() const { return m_profile; } 00579 00581 unsigned int Level() const { return m_level; } 00582 00583 // Sets 00584 00586 void SetAccessUnitPictureNumber(unsigned int au_pnum) { m_au_pnum = au_pnum; } 00587 00589 void SetMajorVersion(unsigned int major_ver) { m_major_ver = major_ver; } 00590 00592 void SetMinorVersion(unsigned int minor_ver) { m_minor_ver = minor_ver; } 00593 00595 void SetProfile(unsigned int level) { m_level = level; } 00596 00598 void SetLevel(unsigned int profile) { m_profile = profile; } 00599 00600 private: 00602 unsigned int m_au_pnum; 00604 unsigned int m_major_ver; 00606 unsigned int m_minor_ver; 00608 unsigned int m_profile; 00610 unsigned int m_level; 00611 }; 00612 00614 class SourceParams 00615 { 00616 public: 00618 SourceParams (const VideoFormat &vf = VIDEO_FORMAT_CUSTOM, 00619 bool set_defaults=true); 00620 00622 //NB: Assume default copy constructor, assignment = and destructor// 00624 00625 // Gets 00627 bool Interlace() const { return m_interlace; } 00628 00630 bool TopFieldFirst() const { return m_topfieldfirst; } 00631 00633 bool SequentialFields() const { return m_seq_fields; } 00634 00636 Rational FrameRate() const { return m_framerate; } 00637 00639 FrameRateType FrameRateIndex() const { return m_fr_idx; } 00640 00642 Rational AspectRatio() const { return m_aspect_ratio; } 00643 00645 AspectRatioType AspectRatioIndex() const { return m_asr_idx; } 00646 00647 // Clean area parameters 00649 unsigned int CleanWidth() const { return m_clean_width; } 00651 unsigned int CleanHeight() const { return m_clean_height; } 00653 unsigned int LeftOffset() const { return m_left_offset; } 00655 unsigned int TopOffset() const { return m_top_offset; } 00656 00657 // Signal Range parameters 00658 00660 SignalRangeType SignalRangeIndex() const { return m_sr_idx; } 00661 00663 unsigned int LumaOffset() const { return m_luma_offset; } 00665 unsigned int LumaExcursion() const { return m_luma_excursion; } 00667 unsigned int ChromaOffset() const { return m_chroma_offset; } 00669 unsigned int ChromaExcursion() const { return m_chroma_excursion; } 00670 00672 unsigned int ColourSpecificationIndex() const { return m_cs_idx; } 00673 00675 ColourPrimaries ColourPrimariesIndex() const { return m_col_primary; } 00677 ColourMatrix ColourMatrixIndex() const { return m_col_matrix; } 00679 TransferFunction TransferFunctionIndex() const { return m_transfer_func; } 00680 00681 // Sets 00683 void SetInterlace(bool interlace) { m_interlace = interlace; } 00684 00686 void SetTopFieldFirst(bool tff) { m_topfieldfirst = tff; } 00687 00689 void SetSequentialFields(bool seq_flds) { m_seq_fields = seq_flds; } 00690 00692 void SetFrameRate(const Rational &frate ) 00693 { 00694 m_fr_idx = FRAMERATE_CUSTOM; m_framerate = frate; 00695 } 00696 00698 void SetFrameRate(unsigned int fr_num, unsigned int fr_denom ) 00699 { 00700 m_fr_idx = FRAMERATE_CUSTOM; 00701 m_framerate.m_num = fr_num; 00702 m_framerate.m_denom = fr_denom; 00703 } 00704 00706 void SetFrameRate(FrameRateType fr); 00707 00709 void SetAspectRatio(const Rational &asr) 00710 { 00711 m_asr_idx = ASPECT_RATIO_CUSTOM; 00712 m_aspect_ratio = asr; 00713 } 00714 00716 void SetAspectRatio(unsigned int as_num, unsigned int as_denom ) 00717 { 00718 m_asr_idx = ASPECT_RATIO_CUSTOM; 00719 m_aspect_ratio.m_num = as_num; 00720 m_aspect_ratio.m_denom = as_denom; 00721 } 00722 00724 void SetAspectRatio(AspectRatioType aspect_ratio); 00725 00726 // Clean area parameters 00728 void SetCleanWidth(unsigned int clean_width) { m_clean_width = clean_width; } 00730 void SetCleanHeight(unsigned int clean_height) { m_clean_height = clean_height; } 00732 void SetLeftOffset(unsigned int left_offset) { m_left_offset = left_offset; } 00734 void SetTopOffset(unsigned int top_offset) { m_top_offset = top_offset; } 00735 00736 // Signal Range parameters 00738 void SetSignalRange(SignalRangeType sr); 00739 00741 void SetLumaOffset(unsigned int luma_offset) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_offset = luma_offset; } 00743 void SetLumaExcursion(unsigned int luma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_excursion = luma_exc; } 00745 void SetChromaOffset(unsigned int chroma_off) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_offset = chroma_off; } 00747 void SetChromaExcursion(unsigned int chroma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_excursion = chroma_exc; } 00748 00750 void SetColourSpecification(unsigned int cs_idx); 00752 void SetColourPrimariesIndex(unsigned int cp); 00754 void SetColourMatrixIndex(unsigned int cm); 00756 void SetTransferFunctionIndex(unsigned int tf); 00757 00758 private: 00760 bool m_interlace; 00761 00763 bool m_topfieldfirst; 00764 00766 bool m_seq_fields; 00767 00769 FrameRateType m_fr_idx; 00770 00772 Rational m_framerate; 00773 00775 AspectRatioType m_asr_idx; 00776 00778 Rational m_aspect_ratio; 00779 00780 // Clean area parameters 00781 00783 unsigned int m_clean_width; 00784 00786 unsigned int m_clean_height; 00787 00789 unsigned int m_left_offset; 00790 00792 unsigned int m_top_offset; 00793 00794 // signal range parameters 00795 00797 SignalRangeType m_sr_idx; 00798 00800 unsigned int m_luma_offset; 00802 unsigned int m_luma_excursion; 00804 unsigned int m_chroma_offset; 00806 unsigned int m_chroma_excursion; 00807 00809 unsigned int m_cs_idx; 00810 00812 ColourPrimaries m_col_primary; 00813 00814 // Colour Matrix index 00815 ColourMatrix m_col_matrix; 00816 00817 // Transfer function index 00818 TransferFunction m_transfer_func; 00819 }; 00820 00822 class FrameParams 00823 { 00824 00825 public: 00827 FrameParams(); 00828 00830 00833 FrameParams(const ChromaFormat& cf, int xlen, int ylen, int c_xlen, int c_ylen, unsigned int video_depth); 00834 00836 00839 FrameParams(const ChromaFormat& cf, const FrameSort& fs); 00840 00842 /* 00843 All data is derived from the sequence parameters 00844 */ 00845 FrameParams(const SeqParams& sparams); 00846 00848 /* 00849 All data is derived from the sequence parameters 00850 */ 00851 FrameParams(const SeqParams& sparams, const FrameSort& fs); 00852 00854 //NB: Assume default copy constructor, assignment = and destructor// 00856 00857 // Gets ... 00858 00860 const ChromaFormat& CFormat() const{return m_cformat;} 00861 00863 int Xl() const{return m_xl;} 00864 00866 int Yl() const{return m_yl;} 00867 00869 int ChromaXl() const{return m_chroma_xl;} 00870 00872 int ChromaYl() const{return m_chroma_yl;} 00873 00875 const FrameSort& FSort() const {return m_fsort;} 00876 00878 int FrameNum() const {return m_fnum;} 00879 00881 bool IsBFrame() const; 00882 00884 int ExpiryTime() const {return m_expiry_time;} 00885 00887 bool Output() const {return m_output;} 00888 00890 const std::vector<int>& Refs() const {return m_refs;} 00891 00893 std::vector<int>& Refs(){return m_refs;} 00894 00896 unsigned int NumRefs()const {return m_refs.size();} 00897 00899 FrameType GetFrameType () const { return m_frame_type; } 00900 00902 ReferenceType GetReferenceType() const { return m_reference_type;} 00903 00905 unsigned int GetVideoDepth() const{return m_video_depth;} 00906 00907 // ... Sets 00908 00910 void SetFSort( const FrameSort& fs ); 00911 00913 void SetFrameType(const FrameType ftype); 00914 00916 void SetReferenceType(const ReferenceType rtype); 00917 00919 void SetFrameNum( const int fn ){ m_fnum=fn; } 00920 00922 void SetExpiryTime( const int expt ){ m_expiry_time=expt; } 00923 00925 void SetAsOutput(){m_output=true;} 00926 00928 void SetCFormat(ChromaFormat cf){ m_cformat = cf; } 00929 00931 void SetXl(int xl){m_xl = xl; } 00932 00934 void SetYl(int yl){m_yl = yl; } 00935 00937 void SetChromaXl(int xl){m_chroma_xl = xl; } 00938 00940 void SetChromaYl(int yl){m_chroma_yl = yl; } 00941 00943 void SetVideoDepth(int vd) { m_video_depth = vd; } 00944 00946 std::vector<int>& RetiredFrames() const {return m_retd_list;} 00947 00949 std::vector<int>& RetiredFrames() {return m_retd_list;} 00950 00951 private: 00952 00954 ChromaFormat m_cformat; 00955 00957 int m_xl; 00958 00960 int m_yl; 00961 00963 FrameSort m_fsort; 00964 00966 std::vector<int> m_refs; 00967 00969 int m_expiry_time; 00970 00972 int m_fnum; 00973 00975 FrameType m_frame_type; 00976 00978 ReferenceType m_reference_type; 00979 00981 bool m_output; 00982 00984 int m_chroma_xl; 00985 00987 int m_chroma_yl; 00988 00990 mutable std::vector<int> m_retd_list; 00991 00993 unsigned int m_video_depth; 00994 00995 }; 00996 00998 class CodeBlocks 00999 { 01000 public: 01002 CodeBlocks () : m_hblocks(0), m_vblocks(0) 01003 {} 01004 01006 CodeBlocks (unsigned int hblocks, unsigned int vblocks) : 01007 m_hblocks(hblocks), 01008 m_vblocks(vblocks) 01009 {} 01010 01011 // Gets 01013 unsigned int HorizontalCodeBlocks() const { return m_hblocks; } 01015 unsigned int VerticalCodeBlocks() const { return m_vblocks; } 01016 // Sets 01018 void SetHorizontalCodeBlocks(unsigned int hblocks) { m_hblocks = hblocks; } 01020 void SetVerticalCodeBlocks(unsigned int vblocks) { m_vblocks = vblocks; } 01021 private: 01023 unsigned int m_hblocks; 01025 unsigned int m_vblocks; 01026 }; 01028 01031 class CodecParams 01032 { 01033 public: 01034 01036 CodecParams(const VideoFormat& vd, FrameType ftype, unsigned int num_refs, bool set_defaults); 01037 01039 //NB: Assume default copy constructor, assignment = and destructor// 01041 01042 // Gets ... 01043 01045 int XNumMB() const {return m_x_num_mb;} 01046 01048 int YNumMB() const {return m_y_num_mb;} 01049 01051 int XNumBlocks() const {return m_x_num_blocks;} 01052 01054 int YNumBlocks() const {return m_y_num_blocks;} 01055 01057 bool Verbose() const {return m_verbose;} 01058 01060 bool Interlace() const {return m_interlace;} 01061 01063 bool TopFieldFirst() const {return m_topfieldfirst;} 01064 01066 const OLBParams& LumaBParams(int n) const {return m_lbparams[n];} 01067 01069 const OLBParams& ChromaBParams(int n) const {return m_cbparams[n];} 01070 01072 int OrigXl() const {return m_orig_xl;} 01073 01075 int OrigYl() const {return m_orig_yl;} 01076 01078 MVPrecisionType MVPrecision() const { return m_mv_precision; } 01079 01081 bool ZeroTransform() const { return m_zero_transform; } 01082 01084 WltFilter TransformFilter() const { return m_wlt_filter; } 01085 01087 unsigned int TransformDepth() const { return m_wlt_depth; } 01088 01090 CodeBlockMode GetCodeBlockMode() const { return m_cb_mode; } 01091 01093 bool SpatialPartition() const { return m_spatial_partition; } 01094 01096 bool DefaultSpatialPartition() const { return m_def_spatial_partition; } 01098 const CodeBlocks &GetCodeBlocks(unsigned int level) const; 01099 01101 VideoFormat GetVideoFormat() const { return m_video_format; } 01102 01104 bool UsingGlobalMotion() const { return m_use_global_motion; } 01105 01107 unsigned int FrameWeightsBits() const { return m_frame_weights_bits; } 01108 01110 unsigned int Ref1Weight() const { return m_ref1_weight; } 01111 01113 unsigned int Ref2Weight() const { return m_ref2_weight; } 01114 01115 // ... and Sets 01117 void SetXNumMB(const int xn){m_x_num_mb=xn;} 01118 01120 void SetYNumMB(const int yn){m_y_num_mb=yn;} 01121 01123 void SetXNumBlocks(const int xn){m_x_num_blocks=xn;} 01124 01126 void SetYNumBlocks(const int yn){m_y_num_blocks=yn;} 01127 01129 void SetVerbose(bool v){m_verbose=v;} 01130 01132 void SetInterlace(bool intlc){m_interlace=intlc;} 01133 01135 void SetTopFieldFirst(bool topf){m_topfieldfirst=topf;} 01136 01138 void SetBlockSizes(const OLBParams& olbparams , const ChromaFormat cformat); 01140 void SetLumaBlockParams(const OLBParams& olbparams) {m_lbparams[2] = olbparams;} 01141 01143 void SetOrigXl(const int x){m_orig_xl=x;} 01144 01146 void SetOrigYl(const int y){m_orig_yl=y;} 01147 01149 void SetMVPrecision(const MVPrecisionType p) 01150 { 01151 // Assert in debug mode. Maybe we should throw an exception??? 01152 TESTM((p >=0 && p <=3), "Motion precision value in range 0..3"); 01153 m_mv_precision = p; 01154 } 01155 01157 void SetZeroTransform(bool zero_transform) { m_zero_transform = zero_transform; } 01158 01160 void SetTransformFilter(const WltFilter wf) { m_wlt_filter=wf; } 01161 01163 void SetTransformFilter(unsigned int wf_idx); 01164 01166 void SetTransformDepth(unsigned int wd); 01167 01169 void SetCodeBlockMode(unsigned int cb_mode); 01170 01172 void SetSpatialPartition(bool spatial_partition) { m_spatial_partition=spatial_partition; } 01173 01175 void SetDefaultSpatialPartition(bool def_spatial_partition) { m_def_spatial_partition=def_spatial_partition; } 01176 01178 void SetCodeBlocks(unsigned int level, unsigned int hblocks, unsigned int vblocks); 01179 01181 void SetDefaultCodeBlocks(const FrameType& ftype); 01182 01184 void SetVideoFormat(const VideoFormat vd) { m_video_format=vd; } 01185 01187 void SetUsingGlobalMotion(bool gm) { m_use_global_motion=gm; } 01188 01190 void SetFrameWeightsPrecision(unsigned int wt_prec) { m_frame_weights_bits=wt_prec; } 01191 01193 void SetRef1Weight(unsigned int wt) { m_ref1_weight=wt; } 01194 01196 void SetRef2Weight(unsigned int wt) { m_ref2_weight=wt; } 01197 01198 protected: 01200 WltFilter TransformFilter (unsigned int wf_idx); 01201 private: 01202 01204 int m_x_num_mb; 01205 01207 int m_y_num_mb; 01208 01210 int m_x_num_blocks; 01211 01213 int m_y_num_blocks; 01214 01216 bool m_verbose; 01217 01219 bool m_interlace; 01220 01222 bool m_topfieldfirst; 01223 01224 OneDArray<OLBParams> m_lbparams; 01225 OneDArray<OLBParams> m_cbparams; 01226 01228 int m_orig_xl; 01229 01231 int m_orig_yl; 01232 01234 MVPrecisionType m_mv_precision; 01235 01237 VideoFormat m_video_format; 01238 01240 bool m_use_global_motion; 01241 01243 unsigned int m_frame_weights_bits; 01244 01246 unsigned int m_ref1_weight; 01247 01249 unsigned int m_ref2_weight; 01250 01252 bool m_zero_transform; 01253 01255 WltFilter m_wlt_filter; 01256 01258 unsigned int m_wlt_depth; 01259 01261 CodeBlockMode m_cb_mode; 01262 01264 bool m_spatial_partition; 01265 01267 bool m_def_spatial_partition; 01268 01270 OneDArray<CodeBlocks> m_cb; 01271 }; 01272 01274 01277 class EncoderParams: public CodecParams 01278 { 01279 //codec params plus parameters relating solely to the operation of the encoder 01280 01281 public: 01283 EncoderParams(const VideoFormat& video_format, 01284 FrameType ftype = INTER_FRAME, 01285 unsigned int num_refs = 2, 01286 bool set_defaults=true); 01287 01289 //NB: Assume default copy constructor, assignment = and destructor// 01290 //This means pointers are copied, not the objects they point to.//// 01292 01293 // Gets ... 01294 01296 bool LocalDecode() const {return m_loc_decode;} 01297 01299 bool Lossless() const {return m_lossless;} 01300 01302 float Qf() const {return m_qf;} 01303 01305 01310 int NumL1() const {return m_num_L1;} 01311 01313 int L1Sep() const {return m_L1_sep;} 01314 01316 float UFactor() const {return m_ufactor;} 01317 01319 float VFactor() const {return m_vfactor;} 01320 01322 float CPD() const {return m_cpd;} 01323 01325 bool Denoise() const {return m_denoise;} 01326 01328 float ILambda() const {return m_I_lambda;} 01329 01331 float L1Lambda() const {return m_L1_lambda;} 01332 01334 float L2Lambda() const {return m_L2_lambda;} 01335 01337 float L1MELambda() const {return m_L1_me_lambda;} 01338 01340 float L2MELambda() const {return m_L2_me_lambda;} 01341 01343 int GOPLength() const { if (m_num_L1>0) return (m_num_L1+1)*m_L1_sep; 01344 return (m_num_L1==0) ? 10 : 0; } 01345 01347 char * OutputPath() const {return ( char* ) m_output_path.c_str();} 01348 01350 const EntropyCorrector& EntropyFactors() const {return *m_ent_correct;} 01351 01353 EntropyCorrector& EntropyFactors() {return *m_ent_correct;} 01354 01356 WltFilter IntraTransformFilter() { return m_intra_wltfilter; } 01357 01359 WltFilter InterTransformFilter() { return m_inter_wltfilter; } 01360 01361 // ... and Sets 01362 01364 void SetLocalDecode( const bool decode ){m_loc_decode=decode;} 01365 01367 void SetLossless(const bool l){m_lossless = l;} 01368 01370 void SetQf(const float qfac){m_qf=qfac;} 01371 01373 void SetNumL1(const int nl){m_num_L1=nl;} 01374 01376 void SetL1Sep(const int lsep){m_L1_sep=lsep;} 01377 01379 void SetUFactor(const float uf){m_ufactor=uf;} 01380 01382 void SetVFactor(const float vf){m_vfactor=vf;} 01383 01385 void SetCPD(const float cpd){m_cpd=cpd;} 01386 01387 01389 void SetDenoise(const bool denoise){m_denoise=denoise;} 01390 01392 void SetILambda(const float l){m_I_lambda=l;} 01393 01395 void SetL1Lambda(const float l){m_L1_lambda=l;} 01396 01398 void SetL2Lambda(const float l){m_L2_lambda=l;} 01399 01401 void SetLambda(const FrameSort& fsort, const float l); 01402 01404 void SetL1MELambda(const float l){m_L1_me_lambda=l;} 01405 01407 void SetL2MELambda(const float l){m_L2_me_lambda=l;} 01408 01410 void SetOutputPath(const char * op){ m_output_path = op; } 01411 01413 void SetEntropyFactors(EntropyCorrector* entcorrect){m_ent_correct=entcorrect;} 01415 void SetIntraTransformFilter(unsigned int wf_idx); 01416 01418 void SetInterTransformFilter(unsigned int wf_idx); 01419 01421 void SetIntraTransformFilter(WltFilter wf) { m_intra_wltfilter = wf; } 01422 01424 void SetInterTransformFilter(WltFilter wf) { m_inter_wltfilter = wf; } 01425 private: 01426 01428 bool m_loc_decode; 01429 01431 bool m_lossless; 01432 01434 float m_qf; 01435 01437 int m_num_L1; 01438 01440 int m_L1_sep; 01441 01443 float m_ufactor; 01444 01446 float m_vfactor; 01447 01449 float m_cpd; 01450 01452 bool m_denoise; 01453 01455 float m_I_lambda; 01456 01458 float m_L1_lambda; 01459 01461 float m_L2_lambda; 01462 01464 float m_L1_me_lambda; 01465 01467 float m_L2_me_lambda; 01468 01470 EntropyCorrector* m_ent_correct; 01471 01473 std::string m_output_path; 01474 01476 WltFilter m_intra_wltfilter; 01477 01479 WltFilter m_inter_wltfilter; 01480 01481 }; 01482 01484 01487 class DecoderParams: public CodecParams 01488 { 01489 public: 01491 DecoderParams(const VideoFormat& video_format = VIDEO_FORMAT_CIF, FrameType ftype=INTRA_FRAME, unsigned int num_refs = 0, bool set_defaults = false); 01492 01494 //NB: Assume default copy constructor, assignment = and destructor// 01495 //This means pointers are copied, not the objects they point to.//// 01497 01498 01499 private: 01500 01501 }; 01502 01504 inline ValueType BChk(const ValueType &num, const ValueType &max) 01505 { 01506 if(num < 0) return 0; 01507 else if(num >= max) return max-1; 01508 else return num; 01509 } 01510 01512 class QuantiserLists 01513 { 01514 public: 01516 QuantiserLists(); 01517 01519 inline int QuantFactor4( const int index ) const {return m_qflist4[index]; } 01520 01522 inline int IntraQuantOffset4( const int index ) const {return m_intra_offset4[index]; } 01524 inline int InterQuantOffset4( const int index ) const {return m_inter_offset4[index]; } 01525 01527 inline int MaxQIndex() const {return m_max_qindex; } 01528 01529 01530 private: 01531 unsigned int m_max_qindex; 01532 OneDArray<int> m_qflist4; 01533 OneDArray<int> m_intra_offset4; 01534 OneDArray<int> m_inter_offset4; 01535 01536 }; 01537 01539 static const QuantiserLists dirac_quantiser_lists; 01540 01541 } // namespace dirac 01542 01543 #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.