Created by the British Broadcasting Corporation.
00001 /* ***** BEGIN LICENSE BLOCK ***** 00002 * 00003 * $Id: common.h,v 1.39 2006/06/12 12:11:52 asuraparaju Exp $ $Name: Dirac_0_6_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 * 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_CMODE_CTX, // -context for MB common block mode 00187 00188 MB_SPLIT_BIN1_CTX, // bin 1, MB split mode vals 00189 MB_SPLIT_BIN2_CTX, // bin 2, MB split mode vals. Bin 3 not required 00190 00191 MB_SPLIT_INFO_CTX, // info context for MB split mode 00192 00193 TOTAL_MV_CTXS // The total number of motion vector contexts 00194 }; 00195 00196 00202 VideoFormat IntToVideoFormat(int video_format); 00203 00209 ChromaFormat IntToChromaFormat(int chroma_format); 00210 00216 FrameRateType IntToFrameRateType(int frame_rate_idx); 00217 00223 AspectRatioType IntToAspectRatioType(int aspect_ratio_idx); 00224 00230 SignalRangeType IntToSignalRangeType(int signal_range_idx); 00231 00237 MVPrecisionType IntToMVPrecisionType(int mv_prec); 00238 00239 //Classes used throughout the codec// 00242 class FrameSort 00243 { 00244 public: 00245 FrameSort() { fs = 0x00; } // default intra non-ref 00246 00247 void SetIntra() { fs &= 0xfe; } 00248 void SetInter() { fs |= 0x01; } 00249 void SetNonRef() { fs &= 0xfd; } 00250 void SetRef() { fs |= 0x02; } 00251 00252 bool IsInter () const { return fs & 0x01; } 00253 bool IsIntra () const { return !IsInter(); } 00254 bool IsRef() const { return fs & 0x02; }; 00255 bool IsNonRef() const { return !IsRef(); } 00256 00257 void SetIntraNonRef() { SetIntra(); SetNonRef(); } 00258 void SetIntraRef() { SetIntra(); SetRef(); } 00259 void SetInterNonRef() { SetInter(); SetNonRef(); } 00260 void SetInterRef() { SetInter(); SetRef(); } 00261 00262 bool IsIntraNonRef() const { return (fs & 0x03) == 0x00; } 00263 bool IsIntraRef() const { return (fs & 0x03) == 0x02; } 00264 bool IsInterNonRef() const { return (fs & 0x03) == 0x01; } 00265 bool IsInterRef() const { return (fs & 0x03) == 0x03; } 00266 00267 void Clear() { fs=0x00; } 00268 00269 static FrameSort IntraRefFrameSort() 00270 { 00271 FrameSort fs; 00272 fs.SetIntraRef(); 00273 return fs; 00274 } 00275 00276 static FrameSort InterRefFrameSort() 00277 { 00278 FrameSort fs; 00279 fs.SetInterRef(); 00280 return fs; 00281 } 00282 00283 static FrameSort IntraNonRefFrameSort() 00284 { 00285 FrameSort fs; 00286 fs.SetIntraNonRef(); 00287 return fs; 00288 } 00289 00290 static FrameSort InterNonRefFrameSort() 00291 { 00292 FrameSort fs; 00293 fs.SetInterNonRef(); 00294 return fs; 00295 } 00296 00297 private: 00298 unsigned char fs; 00299 }; 00300 00302 00308 class PicArray: public TwoDArray<ValueType> 00309 { 00310 public: 00312 00315 PicArray(): TwoDArray<ValueType>(){} 00316 00318 00322 PicArray(int height, int width, CompSort cs=Y_COMP); 00323 00324 //copy constructor and assignment= derived by inheritance 00325 00327 ~PicArray(){} 00328 00330 const CompSort& CSort() const; 00331 00333 void SetCSort(const CompSort cs); 00334 00335 private: 00336 00337 CompSort m_csort; 00338 }; 00339 00340 00342 class CostType 00343 { 00344 public: 00346 double MSE; 00347 00349 double ENTROPY; 00350 00352 double TOTAL; 00353 }; 00354 00355 00357 00362 class EntropyCorrector 00363 { 00364 public: 00366 00370 EntropyCorrector(int depth); 00371 00373 //NB: Assume default copy constructor, assignment = and destructor// 00375 00377 00381 float Factor(const int bandnum, const FrameSort fsort,const CompSort c) const; 00382 00384 00392 void Update(int bandnum, FrameSort fsort, CompSort c,int est_bits,int actual_bits); 00393 00394 private: 00396 void Init(); 00397 00398 TwoDArray<float> m_Yfctrs; 00399 TwoDArray<float> m_Ufctrs; 00400 TwoDArray<float> m_Vfctrs; 00401 }; 00402 00404 class OLBParams 00405 { 00406 00407 public: 00408 00410 OLBParams(){} 00411 00413 /* 00414 Constructor rationalises proposed parameters to allow suitable 00415 overlap and fit in with chroma format 00416 \param xblen the horizontal block length 00417 \param yblen the vertical block length 00418 \param xblen the horizontal block separation 00419 \param yblen the vertical block separation 00420 00421 */ 00422 OLBParams(const int xblen, const int yblen, 00423 const int xbsep, const int ybsep); 00424 00425 // Gets ... 00426 00428 int Xblen() const {return m_xblen;} 00429 00431 int Yblen() const {return m_yblen;} 00432 00434 int Xbsep() const {return m_xbsep;} 00435 00437 int Ybsep() const {return m_ybsep;} 00438 00440 int Xoffset() const {return m_xoffset;} 00441 00443 int Yoffset() const {return m_yoffset;} 00444 00445 // ... and sets 00446 00448 void SetXblen( int xblen ){ m_xblen = xblen; m_xoffset = (m_xblen-m_xbsep)/2;} 00449 00451 void SetYblen( int yblen ){ m_yblen = yblen; m_yoffset = (m_yblen-m_ybsep)/2;} 00452 00454 void SetXbsep( int xbsep ){ m_xbsep = xbsep; m_xoffset = (m_xblen-m_xbsep)/2;} 00455 00457 void SetYbsep( int ybsep ){ m_ybsep = ybsep; m_yoffset = (m_yblen-m_ybsep)/2;} 00458 00459 bool operator == (const OLBParams bparams) const; 00460 00461 // overloaded stream operators 00462 friend std::ostream & operator<< (std::ostream &, OLBParams &); 00463 friend std::istream & operator>> (std::istream &, OLBParams &); 00464 00465 00466 private: 00467 00468 int m_xblen; 00469 int m_yblen; 00470 int m_xbsep; 00471 int m_ybsep; 00472 int m_xoffset; 00473 int m_yoffset; 00474 }; 00475 00477 class SeqParams 00478 { 00479 public: 00481 SeqParams(const VideoFormat& video_format=VIDEO_FORMAT_CUSTOM, 00482 bool set_defaults=true); 00483 00485 //NB: Assume default copy constructor, assignment = and destructor// 00487 00488 //gets ... 00490 int Xl() const {return m_xl;} 00491 00493 int Yl() const {return m_yl;} 00494 00496 ChromaFormat CFormat() const {return m_cformat;} 00497 00499 int ChromaWidth() const; 00500 00502 int ChromaHeight() const; 00503 00505 int BitstreamVersion() const {return m_bs_ver;} 00506 00508 VideoFormat GetVideoFormat() const { return m_video_format;} 00509 00511 int GetVideoDepth() const { return m_video_depth; } 00512 00513 // ... Sets 00514 00516 void SetXl(int xlen) {m_xl = xlen;} 00517 00519 void SetYl(int ylen) {m_yl = ylen;} 00520 00522 void SetCFormat(ChromaFormat cf) {m_cformat=cf;} 00523 00525 void SetVideoDepth(int vd){ m_video_depth=vd;} 00526 00528 void SetBitstreamVersion(int bs_ver){m_bs_ver=bs_ver;} 00529 00530 00531 private: 00533 int m_xl; 00534 00536 int m_yl; 00537 00539 ChromaFormat m_cformat; 00540 00542 unsigned char m_bs_ver; 00543 00545 VideoFormat m_video_format; 00546 00548 int m_video_depth; 00549 }; 00550 00552 class Rational 00553 { 00554 public: 00556 unsigned int m_num; 00558 unsigned int m_denom; 00559 }; 00560 00562 class ParseParams 00563 { 00564 public: 00566 ParseParams(unsigned int au_pnum = 0); 00567 00568 // Gets 00569 00571 unsigned int AccessUnitPictureNumber() const { return m_au_pnum; } 00572 00574 unsigned int MajorVersion() const { return m_major_ver; } 00575 00577 unsigned int MinorVersion() const { return m_minor_ver; } 00578 00580 unsigned int Profile() const { return m_profile; } 00581 00583 unsigned int Level() const { return m_level; } 00584 00585 // Sets 00586 00588 void SetAccessUnitPictureNumber(unsigned int au_pnum) { m_au_pnum = au_pnum; } 00589 00591 void SetMajorVersion(unsigned int major_ver) { m_major_ver = major_ver; } 00592 00594 void SetMinorVersion(unsigned int minor_ver) { m_minor_ver = minor_ver; } 00595 00597 void SetProfile(unsigned int level) { m_level = level; } 00598 00600 void SetLevel(unsigned int profile) { m_profile = profile; } 00601 00602 private: 00604 unsigned int m_au_pnum; 00606 unsigned int m_major_ver; 00608 unsigned int m_minor_ver; 00610 unsigned int m_profile; 00612 unsigned int m_level; 00613 }; 00614 00616 class SourceParams 00617 { 00618 public: 00620 SourceParams (const VideoFormat &vf = VIDEO_FORMAT_CUSTOM, 00621 bool set_defaults=true); 00622 00624 //NB: Assume default copy constructor, assignment = and destructor// 00626 00627 // Gets 00629 bool Interlace() const { return m_interlace; } 00630 00632 bool TopFieldFirst() const { return m_topfieldfirst; } 00633 00635 bool SequentialFields() const { return m_seq_fields; } 00636 00638 Rational FrameRate() const { return m_framerate; } 00639 00641 FrameRateType FrameRateIndex() const { return m_fr_idx; } 00642 00644 Rational AspectRatio() const { return m_aspect_ratio; } 00645 00647 AspectRatioType AspectRatioIndex() const { return m_asr_idx; } 00648 00649 // Clean area parameters 00651 unsigned int CleanWidth() const { return m_clean_width; } 00653 unsigned int CleanHeight() const { return m_clean_height; } 00655 unsigned int LeftOffset() const { return m_left_offset; } 00657 unsigned int TopOffset() const { return m_top_offset; } 00658 00659 // Signal Range parameters 00660 00662 SignalRangeType SignalRangeIndex() const { return m_sr_idx; } 00663 00665 unsigned int LumaOffset() const { return m_luma_offset; } 00667 unsigned int LumaExcursion() const { return m_luma_excursion; } 00669 unsigned int ChromaOffset() const { return m_chroma_offset; } 00671 unsigned int ChromaExcursion() const { return m_chroma_excursion; } 00672 00674 unsigned int ColourSpecificationIndex() const { return m_cs_idx; } 00675 00677 ColourPrimaries ColourPrimariesIndex() const { return m_col_primary; } 00679 ColourMatrix ColourMatrixIndex() const { return m_col_matrix; } 00681 TransferFunction TransferFunctionIndex() const { return m_transfer_func; } 00682 00683 // Sets 00685 void SetInterlace(bool interlace) { m_interlace = interlace; } 00686 00688 void SetTopFieldFirst(bool tff) { m_topfieldfirst = tff; } 00689 00691 void SetSequentialFields(bool seq_flds) { m_seq_fields = seq_flds; } 00692 00694 void SetFrameRate(const Rational &frate ) 00695 { 00696 m_fr_idx = FRAMERATE_CUSTOM; m_framerate = frate; 00697 } 00698 00700 void SetFrameRate(unsigned int fr_num, unsigned int fr_denom ) 00701 { 00702 m_fr_idx = FRAMERATE_CUSTOM; 00703 m_framerate.m_num = fr_num; 00704 m_framerate.m_denom = fr_denom; 00705 } 00706 00708 void SetFrameRate(FrameRateType fr); 00709 00711 void SetAspectRatio(const Rational &asr) 00712 { 00713 m_asr_idx = ASPECT_RATIO_CUSTOM; 00714 m_aspect_ratio = asr; 00715 } 00716 00718 void SetAspectRatio(unsigned int as_num, unsigned int as_denom ) 00719 { 00720 m_asr_idx = ASPECT_RATIO_CUSTOM; 00721 m_aspect_ratio.m_num = as_num; 00722 m_aspect_ratio.m_denom = as_denom; 00723 } 00724 00726 void SetAspectRatio(AspectRatioType aspect_ratio); 00727 00728 // Clean area parameters 00730 void SetCleanWidth(unsigned int clean_width) { m_clean_width = clean_width; } 00732 void SetCleanHeight(unsigned int clean_height) { m_clean_height = clean_height; } 00734 void SetLeftOffset(unsigned int left_offset) { m_left_offset = left_offset; } 00736 void SetTopOffset(unsigned int top_offset) { m_top_offset = top_offset; } 00737 00738 // Signal Range parameters 00740 void SetSignalRange(SignalRangeType sr); 00741 00743 void SetLumaOffset(unsigned int luma_offset) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_offset = luma_offset; } 00745 void SetLumaExcursion(unsigned int luma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_excursion = luma_exc; } 00747 void SetChromaOffset(unsigned int chroma_off) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_offset = chroma_off; } 00749 void SetChromaExcursion(unsigned int chroma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_excursion = chroma_exc; } 00750 00752 void SetColourSpecification(unsigned int cs_idx); 00754 void SetColourPrimariesIndex(unsigned int cp); 00756 void SetColourMatrixIndex(unsigned int cm); 00758 void SetTransferFunctionIndex(unsigned int tf); 00759 00760 private: 00762 bool m_interlace; 00763 00765 bool m_topfieldfirst; 00766 00768 bool m_seq_fields; 00769 00771 FrameRateType m_fr_idx; 00772 00774 Rational m_framerate; 00775 00777 AspectRatioType m_asr_idx; 00778 00780 Rational m_aspect_ratio; 00781 00782 // Clean area parameters 00783 00785 unsigned int m_clean_width; 00786 00788 unsigned int m_clean_height; 00789 00791 unsigned int m_left_offset; 00792 00794 unsigned int m_top_offset; 00795 00796 // signal range parameters 00797 00799 SignalRangeType m_sr_idx; 00800 00802 unsigned int m_luma_offset; 00804 unsigned int m_luma_excursion; 00806 unsigned int m_chroma_offset; 00808 unsigned int m_chroma_excursion; 00809 00811 unsigned int m_cs_idx; 00812 00814 ColourPrimaries m_col_primary; 00815 00816 // Colour Matrix index 00817 ColourMatrix m_col_matrix; 00818 00819 // Transfer function index 00820 TransferFunction m_transfer_func; 00821 }; 00822 00824 class FrameParams 00825 { 00826 00827 public: 00829 FrameParams(); 00830 00832 00835 FrameParams(const ChromaFormat& cf, int xlen, int ylen, int c_xlen, int c_ylen, unsigned int video_depth); 00836 00838 00841 FrameParams(const ChromaFormat& cf, const FrameSort& fs); 00842 00844 /* 00845 All data is derived from the sequence parameters 00846 */ 00847 FrameParams(const SeqParams& sparams); 00848 00850 /* 00851 All data is derived from the sequence parameters 00852 */ 00853 FrameParams(const SeqParams& sparams, const FrameSort& fs); 00854 00856 //NB: Assume default copy constructor, assignment = and destructor// 00858 00859 // Gets ... 00860 00862 const ChromaFormat& CFormat() const{return m_cformat;} 00863 00865 int Xl() const{return m_xl;} 00866 00868 int Yl() const{return m_yl;} 00869 00871 int ChromaXl() const{return m_chroma_xl;} 00872 00874 int ChromaYl() const{return m_chroma_yl;} 00875 00877 const FrameSort& FSort() const {return m_fsort;} 00878 00880 int FrameNum() const {return m_fnum;} 00881 00883 int ExpiryTime() const {return m_expiry_time;} 00884 00886 bool Output() const {return m_output;} 00887 00889 const std::vector<int>& Refs() const {return m_refs;} 00890 00892 std::vector<int>& Refs(){return m_refs;} 00893 00895 unsigned int NumRefs()const {return m_refs.size();} 00896 00898 FrameType GetFrameType () const { return m_frame_type; } 00899 00901 ReferenceType GetReferenceType() const { return m_reference_type;} 00902 00904 unsigned int GetVideoDepth() const{return m_video_depth;} 00905 00906 // ... Sets 00907 00909 void SetFSort( const FrameSort& fs ){ m_fsort=fs; } 00910 00912 void SetFrameType(const FrameType& frame_type) { m_frame_type=frame_type; } 00913 00915 void SetReferenceType(const ReferenceType& ref_type) { m_reference_type=ref_type; } 00916 00918 void SetFrameNum( const int fn ){ m_fnum=fn; } 00919 00921 void SetExpiryTime( const int expt ){ m_expiry_time=expt; } 00922 00924 void SetAsOutput(){m_output=true;} 00925 00927 void SetCFormat(ChromaFormat cf){ m_cformat = cf; } 00928 00930 void SetXl(int xl){m_xl = xl; } 00931 00933 void SetYl(int yl){m_yl = yl; } 00934 00936 void SetChromaXl(int xl){m_chroma_xl = xl; } 00937 00939 void SetChromaYl(int yl){m_chroma_yl = yl; } 00940 00942 void SetVideoDepth(int vd) { m_video_depth = vd; } 00943 00945 std::vector<int>& RetiredFrames() const {return m_retd_list;} 00946 00948 std::vector<int>& RetiredFrames() {return m_retd_list;} 00949 00950 private: 00951 00953 ChromaFormat m_cformat; 00954 00956 int m_xl; 00957 00959 int m_yl; 00960 00962 FrameSort m_fsort; 00963 00965 std::vector<int> m_refs; 00966 00968 int m_expiry_time; 00969 00971 bool m_output; 00972 00974 int m_fnum; 00975 00977 FrameType m_frame_type; 00978 00980 ReferenceType m_reference_type; 00981 00983 int m_chroma_xl; 00984 00986 int m_chroma_yl; 00987 00989 mutable std::vector<int> m_retd_list; 00990 00992 unsigned int m_video_depth; 00993 00994 }; 00995 00997 class CodeBlocks 00998 { 00999 public: 01001 CodeBlocks () : m_hblocks(0), m_vblocks(0) 01002 {} 01003 01005 CodeBlocks (unsigned int hblocks, unsigned int vblocks) : 01006 m_hblocks(hblocks), 01007 m_vblocks(vblocks) 01008 {} 01009 01010 // Gets 01012 unsigned int HorizontalCodeBlocks() const { return m_hblocks; } 01014 unsigned int VerticalCodeBlocks() const { return m_vblocks; } 01015 // Sets 01017 void SetHorizontalCodeBlocks(unsigned int hblocks) { m_hblocks = hblocks; } 01019 void SetVerticalCodeBlocks(unsigned int vblocks) { m_vblocks = vblocks; } 01020 private: 01022 unsigned int m_hblocks; 01024 unsigned int m_vblocks; 01025 }; 01027 01030 class CodecParams 01031 { 01032 public: 01033 01035 CodecParams(const VideoFormat& vd, FrameType ftype, bool set_defaults); 01036 01038 //NB: Assume default copy constructor, assignment = and destructor// 01040 01041 // Gets ... 01042 01044 int XNumMB() const {return m_x_num_mb;} 01045 01047 int YNumMB() const {return m_y_num_mb;} 01048 01050 int XNumBlocks() const {return m_x_num_blocks;} 01051 01053 int YNumBlocks() const {return m_y_num_blocks;} 01054 01056 bool Verbose() const {return m_verbose;} 01057 01059 bool Interlace() const {return m_interlace;} 01060 01062 bool TopFieldFirst() const {return m_topfieldfirst;} 01063 01065 const OLBParams& LumaBParams(int n) const {return m_lbparams[n];} 01066 01068 const OLBParams& ChromaBParams(int n) const {return m_cbparams[n];} 01069 01071 int OrigXl() const {return m_orig_xl;} 01072 01074 int OrigYl() const {return m_orig_yl;} 01075 01077 MVPrecisionType MVPrecision() const { return m_mv_precision; } 01078 01080 bool ZeroTransform() const { return m_zero_transform; } 01081 01083 WltFilter TransformFilter() const { return m_wlt_filter; } 01084 01086 unsigned int TransformDepth() const { return m_wlt_depth; } 01087 01089 CodeBlockMode GetCodeBlockMode() const { return m_cb_mode; } 01090 01092 bool SpatialPartition() const { return m_spatial_partition; } 01093 01095 bool DefaultSpatialPartition() const { return m_def_spatial_partition; } 01097 const CodeBlocks &GetCodeBlocks(unsigned int level) const; 01098 01100 VideoFormat GetVideoFormat() const { return m_video_format; } 01101 01103 bool UsingGlobalMotion() const { return m_use_global_motion; } 01104 01106 unsigned int FrameWeightsBits() const { return m_frame_weights_bits; } 01107 01109 unsigned int Ref1Weight() const { return m_ref1_weight; } 01110 01112 unsigned int Ref2Weight() const { return m_ref2_weight; } 01113 01114 // ... and Sets 01116 void SetXNumMB(const int xn){m_x_num_mb=xn;} 01117 01119 void SetYNumMB(const int yn){m_y_num_mb=yn;} 01120 01122 void SetXNumBlocks(const int xn){m_x_num_blocks=xn;} 01123 01125 void SetYNumBlocks(const int yn){m_y_num_blocks=yn;} 01126 01128 void SetVerbose(bool v){m_verbose=v;} 01129 01131 void SetInterlace(bool intlc){m_interlace=intlc;} 01132 01134 void SetTopFieldFirst(bool topf){m_topfieldfirst=topf;} 01135 01137 void SetBlockSizes(const OLBParams& olbparams , const ChromaFormat cformat); 01139 void SetLumaBlockParams(const OLBParams& olbparams) {m_lbparams[2] = olbparams;} 01140 01142 void SetOrigXl(const int x){m_orig_xl=x;} 01143 01145 void SetOrigYl(const int y){m_orig_yl=y;} 01146 01148 void SetMVPrecision(const MVPrecisionType p) 01149 { 01150 // Assert in debug mode. Maybe we should throw an exception??? 01151 TESTM((p >=0 && p <=3), "Motion precision value in range 0..3"); 01152 m_mv_precision = p; 01153 } 01154 01156 void SetZeroTransform(bool zero_transform) { m_zero_transform = zero_transform; } 01157 01159 void SetTransformFilter(const WltFilter wf) { m_wlt_filter=wf; } 01160 01162 void SetTransformFilter(unsigned int wf_idx); 01163 01165 void SetTransformDepth(unsigned int wd); 01166 01168 void SetCodeBlockMode(unsigned int cb_mode); 01169 01171 void SetSpatialPartition(bool spatial_partition) { m_spatial_partition=spatial_partition; } 01172 01174 void SetDefaultSpatialPartition(bool def_spatial_partition) { m_def_spatial_partition=def_spatial_partition; } 01175 01177 void SetCodeBlocks(unsigned int level, unsigned int hblocks, unsigned int vblocks); 01178 01180 void SetDefaultCodeBlocks(const FrameType& ftype); 01181 01183 void SetVideoFormat(const VideoFormat vd) { m_video_format=vd; } 01184 01186 void SetUsingGlobalMotion(bool gm) { m_use_global_motion=gm; } 01187 01189 void SetFrameWeightsPrecision(unsigned int wt_prec) { m_frame_weights_bits=wt_prec; } 01190 01192 void SetRef1Weight(unsigned int wt) { m_ref1_weight=wt; } 01193 01195 void SetRef2Weight(unsigned int wt) { m_ref2_weight=wt; } 01196 01197 private: 01198 01200 int m_x_num_mb; 01201 01203 int m_y_num_mb; 01204 01206 int m_x_num_blocks; 01207 01209 int m_y_num_blocks; 01210 01212 bool m_verbose; 01213 01215 bool m_interlace; 01216 01218 bool m_topfieldfirst; 01219 01220 OneDArray<OLBParams> m_lbparams; 01221 OneDArray<OLBParams> m_cbparams; 01222 01224 int m_orig_xl; 01225 01227 int m_orig_yl; 01228 01230 MVPrecisionType m_mv_precision; 01231 01233 VideoFormat m_video_format; 01234 01236 bool m_use_global_motion; 01237 01239 unsigned int m_frame_weights_bits; 01240 01242 unsigned int m_ref1_weight; 01243 01245 unsigned int m_ref2_weight; 01246 01248 bool m_zero_transform; 01249 01251 WltFilter m_wlt_filter; 01252 01254 unsigned int m_wlt_depth; 01255 01257 CodeBlockMode m_cb_mode; 01258 01260 bool m_spatial_partition; 01261 01263 bool m_def_spatial_partition; 01264 01266 OneDArray<CodeBlocks> m_cb; 01267 }; 01268 01270 01273 class EncoderParams: public CodecParams 01274 { 01275 //codec params plus parameters relating solely to the operation of the encoder 01276 01277 public: 01279 EncoderParams(const VideoFormat& video_format, 01280 FrameType ftype = INTER_FRAME, 01281 bool set_defaults=true); 01282 01284 //NB: Assume default copy constructor, assignment = and destructor// 01285 //This means pointers are copied, not the objects they point to.//// 01287 01288 // Gets ... 01289 01291 bool LocalDecode() const {return m_loc_decode;} 01292 01294 bool Lossless() const {return m_lossless;} 01295 01297 float Qf() const {return m_qf;} 01298 01300 01305 int NumL1() const {return m_num_L1;} 01306 01308 int L1Sep() const {return m_L1_sep;} 01309 01311 float UFactor() const {return m_ufactor;} 01312 01314 float VFactor() const {return m_vfactor;} 01315 01317 float CPD() const {return m_cpd;} 01318 01320 float ILambda() const {return m_I_lambda;} 01321 01323 float L1Lambda() const {return m_L1_lambda;} 01324 01326 float L2Lambda() const {return m_L2_lambda;} 01327 01329 float Lambda(const FrameSort& fsort) const; 01330 01332 float L1MELambda() const {return m_L1_me_lambda;} 01333 01335 float L2MELambda() const {return m_L2_me_lambda;} 01336 01338 int GOPLength() const { if (m_num_L1>0) return (m_num_L1+1)*m_L1_sep; 01339 return (m_num_L1==0) ? 10 : 0; } 01340 01342 char * OutputPath() const {return ( char* ) m_output_path.c_str();} 01343 01345 const EntropyCorrector& EntropyFactors() const {return *m_ent_correct;} 01346 01348 EntropyCorrector& EntropyFactors() {return *m_ent_correct;} 01349 01350 // ... and Sets 01351 01353 void SetLocalDecode( const bool decode ){m_loc_decode=decode;} 01354 01356 void SetLossless(const bool l){m_lossless = l;} 01357 01359 void SetQf(const float qfac){m_qf=qfac;} 01360 01362 void SetNumL1(const int nl){m_num_L1=nl;} 01363 01365 void SetL1Sep(const int lsep){m_L1_sep=lsep;} 01366 01368 void SetUFactor(const float uf){m_ufactor=uf;} 01369 01371 void SetVFactor(const float vf){m_vfactor=vf;} 01372 01374 void SetCPD(const float cpd){m_cpd=cpd;} 01375 01377 void SetILambda(const float l){m_I_lambda=l;} 01378 01380 void SetL1Lambda(const float l){m_L1_lambda=l;} 01381 01383 void SetL2Lambda(const float l){m_L2_lambda=l;} 01384 01386 void SetLambda(const FrameSort& fsort, const float l); 01387 01389 void SetL1MELambda(const float l){m_L1_me_lambda=l;} 01390 01392 void SetL2MELambda(const float l){m_L2_me_lambda=l;} 01393 01395 void SetOutputPath(const char * op){ m_output_path = op; } 01396 01398 void SetEntropyFactors(EntropyCorrector* entcorrect){m_ent_correct=entcorrect;} 01399 01400 private: 01401 01403 bool m_loc_decode; 01404 01406 bool m_lossless; 01407 01409 float m_qf; 01410 01412 int m_num_L1; 01413 01415 int m_L1_sep; 01416 01418 float m_ufactor; 01419 01421 float m_vfactor; 01422 01424 float m_cpd; 01425 01427 float m_I_lambda; 01428 01430 float m_L1_lambda; 01431 01433 float m_L2_lambda; 01434 01436 float m_L1_me_lambda; 01437 01439 float m_L2_me_lambda; 01440 01442 EntropyCorrector* m_ent_correct; 01443 01445 std::string m_output_path; 01446 01447 01448 }; 01449 01451 01454 class DecoderParams: public CodecParams 01455 { 01456 public: 01458 DecoderParams(const VideoFormat& video_format = VIDEO_FORMAT_CIF, FrameType ftype=INTRA_FRAME, bool set_defaults = false); 01459 01461 //NB: Assume default copy constructor, assignment = and destructor// 01462 //This means pointers are copied, not the objects they point to.//// 01464 01465 01466 private: 01467 01468 }; 01469 01471 inline ValueType BChk(const ValueType &num, const ValueType &max) 01472 { 01473 if(num < 0) return 0; 01474 else if(num >= max) return max-1; 01475 else return num; 01476 } 01477 01479 class QuantiserLists 01480 { 01481 public: 01483 QuantiserLists(); 01484 01486 inline int QuantFactor4( const int index ) const {return m_qflist4[index]; } 01487 01489 inline int QuantOffset4( const int index ) const {return m_offset4[index]; } 01490 01492 inline int MaxQIndex() const {return m_max_qindex; } 01493 01494 01495 private: 01496 unsigned int m_max_qindex; 01497 OneDArray<int> m_qflist4; 01498 OneDArray<int> m_offset4; 01499 01500 }; 01501 01503 static const QuantiserLists dirac_quantiser_lists; 01504 01505 } // namespace dirac 01506 01507 #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.