1 /* ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.1 (the "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14 * the specific language governing rights and limitations under the License.
16 * The Original Code is BBC Research and Development code.
18 * The Initial Developer of the Original Code is the British Broadcasting
20 * Portions created by the Initial Developer are Copyright (C) 2004.
21 * All Rights Reserved.
23 * Contributor(s): Thomas Davies (Original Author),
26 * Anuradha Suraparaju,
28 * Myo Tun (Brunel University, myo.tun@brunel.ac.uk)
30 * Alternatively, the contents of this file may be used under the terms of
31 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
32 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
33 * the GPL or the LGPL are applicable instead of those above. If you wish to
34 * allow use of your version of this file only under the terms of the either
35 * the GPL or LGPL and not to allow others to use your version of this file
36 * under the MPL, indicate your decision by deleting the provisions above
37 * and replace them with the notice and other provisions required by the GPL
38 * or LGPL. If you do not delete the provisions above, a recipient may use
39 * your version of this file under the terms of any one of the MPL, the GPL
41 * ***** END LICENSE BLOCK ***** */
48 #include <libdirac_common/common.h>
49 #include <libdirac_common/video_format_defaults.h>
50 #include <libdirac_common/dirac_exception.h>
51 using namespace dirac
;
54 //const dirac::QuantiserLists dirac::dirac_quantiser_lists;
57 //EntropyCorrector functions
59 EntropyCorrector::EntropyCorrector(int depth
):
60 m_Yfctrs( 3 , 3*depth
+1 ),
61 m_Ufctrs( 3 , 3*depth
+1 ),
62 m_Vfctrs( 3 , 3*depth
+1 )
67 float EntropyCorrector::Factor(const int bandnum
, const PictureParams
& pp
,
68 const CompSort c
) const
70 int idx
= pp
.PicSort().IsIntra() ? 0 : (pp
.IsBPicture() ? 1 : 2);
72 return m_Ufctrs
[idx
][bandnum
-1];
74 return m_Vfctrs
[idx
][bandnum
-1];
76 return m_Yfctrs
[idx
][bandnum
-1];
79 void EntropyCorrector::Init()
83 for (int i
=0 ; i
<m_Yfctrs
.LengthX() ; ++i
)
85 if ( i
== m_Yfctrs
.LastX() )
87 // Set factor for Intra pictures
88 m_Yfctrs
[0][i
] = 1.0f
;
89 m_Ufctrs
[0][i
] = 1.0f
;
90 m_Vfctrs
[0][i
] = 1.0f
;
91 // Set factor for Inter Ref pictures
92 m_Yfctrs
[1][i
] = 0.85f
;
93 m_Ufctrs
[1][i
] = 0.85f
;
94 m_Vfctrs
[1][i
] = 0.85f
;
95 // Set factor for Inter Non-Ref pictures
96 m_Yfctrs
[2][i
] = 0.85f
;
97 m_Ufctrs
[2][i
] = 0.85f
;
98 m_Vfctrs
[2][i
] = 0.85f
;
100 else if ( i
>= m_Yfctrs
.LastX()-3 )
102 // Set factor for Intra pictures
103 m_Yfctrs
[0][i
] = 0.85f
;
104 m_Ufctrs
[0][i
] = 0.85f
;
105 m_Vfctrs
[0][i
] = 0.85f
;
106 // Set factor for Inter Ref pictures
107 m_Yfctrs
[1][i
] = 0.75f
;
108 m_Ufctrs
[1][i
] = 0.75f
;
109 m_Vfctrs
[1][i
] = 0.75f
;
110 // Set factor for Inter Non-Ref pictures
111 m_Yfctrs
[2][i
] = 0.75f
;
112 m_Ufctrs
[2][i
] = 0.75f
;
113 m_Vfctrs
[2][i
] = 0.75f
;
117 // Set factor for Intra pictures
118 m_Yfctrs
[0][i
] = 0.75f
;
119 m_Ufctrs
[0][i
] = 0.75f
;
120 m_Vfctrs
[0][i
] = 0.75f
;
121 // Set factor for Inter Ref pictures
122 m_Yfctrs
[1][i
] = 0.75f
;
123 m_Ufctrs
[1][i
] = 0.75f
;
124 m_Vfctrs
[1][i
] = 0.75f
;
125 // Set factor for Inter Non-Ref pictures
126 m_Yfctrs
[2][i
] = 0.75f
;
127 m_Ufctrs
[2][i
] = 0.75f
;
128 m_Vfctrs
[2][i
] = 0.75f
;
134 void EntropyCorrector::Update(int bandnum
, const PictureParams
& pp
,
135 CompSort c
,int est_bits
, int actual_bits
){
136 //updates the factors - note that the estimated bits are assumed to already include the correction factor
139 if (actual_bits
!= 0 && est_bits
!= 0)
140 multiplier
= float(actual_bits
)/float(est_bits
);
144 int idx
= pp
.PicSort().IsIntra() ? 0 : (pp
.IsBPicture() ? 1 : 2);
146 m_Ufctrs
[idx
][bandnum
-1] *= multiplier
;
147 else if (c
== V_COMP
)
148 m_Vfctrs
[idx
][bandnum
-1] *= multiplier
;
150 m_Yfctrs
[idx
][bandnum
-1] *= multiplier
;
153 // Overlapped block parameter functions
155 OLBParams::OLBParams(const int xblen
, int const yblen
, int const xbsep
, int const ybsep
):
160 m_xoffset( (xblen
-xbsep
)/2 ),
161 m_yoffset( (yblen
-ybsep
)/2 )
164 bool OLBParams::operator ==(const OLBParams bparams
) const
166 if (bparams
.Xblen() != m_xblen
||
167 bparams
.Yblen() != m_yblen
||
168 bparams
.Xbsep() != m_xbsep
||
169 bparams
.Ybsep() != m_ybsep
)
178 std::ostream
& operator<< (std::ostream
& stream
, OLBParams
& params
)
180 stream
<< params
.Ybsep() << " " << params
.Xbsep();
181 // stream << " " <<params.Yblen() << " " << params.Xblen();
186 std::istream
& operator>> (std::istream
& stream
, OLBParams
& params
)
191 params
.SetYbsep(temp
);
194 params
.SetXbsep(temp
);
197 // params.SetYblen(temp);
200 // params.SetXblen(temp);
207 void PicturePredParams::SetBlockSizes(const OLBParams
& olbparams
, const ChromaFormat cformat
)
209 //given the raw overlapped block parameters, set the modified internal parameters to
210 //take account of the chroma sampling format and overlapping requirements, as well
211 //as the equivalent parameters for sub-SBs and SBs.
212 //Does NOT set the number of blocks or superblocks, as padding may be required.
214 OLBParams tmp_olbparams
= olbparams
;
215 // Factors for scaling chroma blocks
216 int xcfactor
,ycfactor
;
218 if (cformat
== format420
)
223 else if (cformat
== format422
)
235 m_lbparams
[2] = tmp_olbparams
;
237 // Check separations are all divisible by 4
238 int remainder
= m_lbparams
[2].Xbsep()%4;
239 if ( remainder
!=0 || m_lbparams
[2].Xbsep()==0 )
241 m_lbparams
[2].SetXbsep( m_lbparams
[2].Xbsep()+(4-remainder
));
242 m_lbparams
[2].SetXblen( m_lbparams
[2].Xbsep()+4 );
244 remainder
= m_lbparams
[2].Ybsep()%4;
245 if ( remainder
!=0 || m_lbparams
[2].Ybsep()==0 )
247 m_lbparams
[2].SetYbsep( m_lbparams
[2].Ybsep()+(4-remainder
));
248 m_lbparams
[2].SetYblen( m_lbparams
[2].Ybsep()+4 );
252 // Now check lengths are divisible by 4
253 remainder
= m_lbparams
[2].Xblen()%4;
256 m_lbparams
[2].SetXblen( m_lbparams
[2].Xbsep()+4);
258 remainder
= m_lbparams
[2].Yblen()%4;
261 m_lbparams
[2].SetYblen( m_lbparams
[2].Ybsep()+4);
264 // Check there's non-negative overlap,
265 // XBLEN >= XBSEP, YBLEN >= YBSEP
266 if (m_lbparams
[2].Xbsep()>m_lbparams
[2].Xblen())
268 m_lbparams
[2].SetXblen( m_lbparams
[2].Xbsep()+4);
270 if (m_lbparams
[2].Ybsep()>m_lbparams
[2].Yblen())
272 m_lbparams
[2].SetYblen( m_lbparams
[2].Ybsep()+4);
275 // Check the lengths aren't too big (100% is max roll-off)
276 // XBLEN <= 2*XBSEP, YBLEN <= 2*YBSEP
277 if (2*m_lbparams
[2].Xbsep()<m_lbparams
[2].Xblen())
279 m_lbparams
[2].SetXblen( m_lbparams
[2].Xbsep()+4);
281 if (2*m_lbparams
[2].Ybsep()<m_lbparams
[2].Yblen())
283 m_lbparams
[2].SetYblen( m_lbparams
[2].Ybsep()+4);
286 // Set the chroma values
287 m_cbparams
[2].SetXbsep( m_lbparams
[2].Xbsep()/xcfactor
);
288 m_cbparams
[2].SetXblen( m_lbparams
[2].Xblen()/xcfactor
);
289 m_cbparams
[2].SetYbsep( m_lbparams
[2].Ybsep()/ycfactor
);
290 m_cbparams
[2].SetYblen( m_lbparams
[2].Yblen()/ycfactor
);
293 //Now work out the overlaps for splitting levels 1 and 0
294 m_lbparams
[1].SetXbsep( m_lbparams
[2].Xbsep()*2 );
295 m_lbparams
[1].SetXblen( m_lbparams
[2].Xblen() + m_lbparams
[2].Xbsep() );
296 m_lbparams
[1].SetYbsep( m_lbparams
[2].Ybsep()*2 );
297 m_lbparams
[1].SetYblen( m_lbparams
[2].Yblen() + m_lbparams
[2].Xbsep() );
299 m_lbparams
[0].SetXbsep( m_lbparams
[1].Xbsep()*2 );
300 m_lbparams
[0].SetXblen( m_lbparams
[1].Xblen() + m_lbparams
[1].Xbsep() );
301 m_lbparams
[0].SetYbsep( m_lbparams
[1].Ybsep()*2 );
302 m_lbparams
[0].SetYblen( m_lbparams
[1].Yblen() + m_lbparams
[1].Xbsep() );
304 m_cbparams
[1].SetXbsep( m_cbparams
[2].Xbsep()*2 );
305 m_cbparams
[1].SetXblen( m_cbparams
[2].Xblen() + m_cbparams
[2].Xbsep() );
306 m_cbparams
[1].SetYbsep( m_cbparams
[2].Ybsep()*2 );
307 m_cbparams
[1].SetYblen( m_cbparams
[2].Yblen() + m_cbparams
[2].Xbsep() );
309 m_cbparams
[0].SetXbsep( m_cbparams
[1].Xbsep()*2 );
310 m_cbparams
[0].SetXblen( m_cbparams
[1].Xblen() + m_cbparams
[1].Xbsep() );
311 m_cbparams
[0].SetYbsep( m_cbparams
[1].Ybsep()*2 );
312 m_cbparams
[0].SetYblen( m_cbparams
[1].Yblen() + m_cbparams
[1].Xbsep() );
314 if ( m_lbparams
[2].Xbsep()!=olbparams
.Xbsep() ||
315 m_lbparams
[2].Ybsep()!=olbparams
.Ybsep() ||
316 m_lbparams
[2].Xblen()!=olbparams
.Xblen() ||
317 m_lbparams
[2].Yblen()!=olbparams
.Yblen() )
319 std::cout
<<std::endl
<<"WARNING: block parameters are inconsistent with ";
320 std::cout
<<"specification requirements, which are:";
321 std::cout
<<std::endl
<<"\t 1. Lengths and separations must be positive multiples of 4";
322 std::cout
<<std::endl
<<"\t 2. Length can't be more than twice separations";
323 std::cout
<<std::endl
<<"\t 3. Lengths must be greater than or equal to separations";
324 std::cout
<<std::endl
<<std::endl
<<"Instead, using:";
325 std::cout
<<" xblen="<<m_lbparams
[2].Xblen();
326 std::cout
<<" yblen="<<m_lbparams
[2].Yblen();
327 std::cout
<<" xbsep="<<m_lbparams
[2].Xbsep();
328 std::cout
<<" ybsep="<<m_lbparams
[2].Ybsep() << std::endl
;
333 // Codec params functions
335 CodecParams::CodecParams(const VideoFormat
&vd
, PictureType ftype
, unsigned int num_refs
, bool set_defaults
):
339 SetDefaultCodecParameters(*this, ftype
, num_refs
);
342 WltFilter
CodecParams::TransformFilter (unsigned int wf_idx
)
344 if (wf_idx
>= filterNK
)
345 DIRAC_THROW_EXCEPTION(
346 ERR_UNSUPPORTED_STREAM_DATA
,
347 "Wavelet filter idx out of range [0-7]",
348 SEVERITY_PICTURE_ERROR
);
350 if (wf_idx
==FIDELITY
)
352 std::ostringstream errstr
;
353 errstr
<< "Wavelet Filter " << wf_idx
<< " currently not supported";
354 DIRAC_THROW_EXCEPTION(
355 ERR_UNSUPPORTED_STREAM_DATA
,
357 SEVERITY_PICTURE_ERROR
);
359 return static_cast<WltFilter
>(wf_idx
);
362 void CodecParams::SetTransformFilter(unsigned int wf_idx
)
364 SetTransformFilter(TransformFilter(wf_idx
));
367 void CodecParams::SetTransformDepth (unsigned int wd
)
370 // Resize the code block size array.
374 void CodecParams::SetCodeBlocks (unsigned int level
,
375 unsigned int hblocks
,
376 unsigned int vblocks
)
378 if (level
> m_wlt_depth
)
380 std::ostringstream errstr
;
381 errstr
<< "level " << level
<< " out of range [0-" << m_wlt_depth
<< "]";
382 DIRAC_THROW_EXCEPTION(
383 ERR_UNSUPPORTED_STREAM_DATA
,
385 SEVERITY_PICTURE_ERROR
);
388 m_cb
[level
].SetHorizontalCodeBlocks(hblocks
);
389 m_cb
[level
].SetVerticalCodeBlocks(vblocks
);
392 const CodeBlocks
&CodecParams::GetCodeBlocks (unsigned int level
) const
394 if (level
> m_wlt_depth
)
396 std::ostringstream errstr
;
397 errstr
<< "level " << level
<< " out of range [0-" << m_wlt_depth
<< "]";
398 DIRAC_THROW_EXCEPTION(
399 ERR_UNSUPPORTED_STREAM_DATA
,
401 SEVERITY_PICTURE_ERROR
);
407 void CodecParams::SetCodeBlockMode (unsigned int cb_mode
)
409 if (cb_mode
>= QUANT_UNDEF
)
411 std::ostringstream errstr
;
412 errstr
<< "Code Block mode " << cb_mode
<< " out of supported range [0-" << QUANT_MULTIPLE
<< "]";
413 DIRAC_THROW_EXCEPTION(
414 ERR_UNSUPPORTED_STREAM_DATA
,
416 SEVERITY_PICTURE_ERROR
);
419 m_cb_mode
= static_cast<CodeBlockMode
>(cb_mode
);
422 //EncoderParams functions
424 //Default constructor
425 EncoderParams::EncoderParams(const VideoFormat
& video_format
,
427 unsigned int num_refs
,
429 CodecParams(video_format
, ftype
, num_refs
, set_defaults
),
432 m_full_search(false),
438 m_prefilter_strength(0),
442 m_L1_me_lambda(0.0f
),
443 m_L2_me_lambda(0.0f
),
448 SetDefaultEncoderParameters(*this);
451 void EncoderParams::CalcLambdas(const float qf
)
455 m_I_lambda
= std::pow( 10.0 , (12.0-qf
)/2.5 )/16.0;
457 m_L1_lambda
= m_I_lambda
*4.0;
458 m_L2_lambda
= m_I_lambda
*32.0;
460 // Set the lambdas for motion estimation
461 const double me_ratio
= 2.0;
463 // Use the same ME lambda for L1 and L2 pictures
464 m_L1_me_lambda
= std::sqrt(m_L1_lambda
)*me_ratio
;
465 m_L2_me_lambda
= m_L1_me_lambda
;
473 m_L1_me_lambda
= 0.0;
474 m_L2_me_lambda
= 0.0;
478 void EncoderParams::SetIntraTransformFilter(unsigned int wf_idx
)
480 SetIntraTransformFilter(TransformFilter(wf_idx
));
483 void EncoderParams::SetInterTransformFilter(unsigned int wf_idx
)
485 SetInterTransformFilter(TransformFilter(wf_idx
));
488 void EncoderParams::SetUsualCodeBlocks ( const PictureType
&ftype
)
490 // No subband splitting if spatial partitioning if false
491 // Since this function is common to encoder and decoder we allow the
492 // setting of code blocks without checking if DefaultSpatialPartition is
494 if (SpatialPartition() == false)
497 SetCodeBlocks(0, 1, 1);
498 if (TransformDepth() == 0)
501 switch (GetVideoFormat())
503 case VIDEO_FORMAT_QSIF525
:
504 case VIDEO_FORMAT_QCIF
:
505 case VIDEO_FORMAT_CUSTOM
:
506 case VIDEO_FORMAT_SIF525
:
507 case VIDEO_FORMAT_CIF
:
508 case VIDEO_FORMAT_4CIF
:
509 case VIDEO_FORMAT_4SIF525
:
510 case VIDEO_FORMAT_SD_480I60
:
511 case VIDEO_FORMAT_SD_576I50
:
512 case VIDEO_FORMAT_HD_720P60
:
513 case VIDEO_FORMAT_HD_720P50
:
514 case VIDEO_FORMAT_HD_1080I60
:
515 case VIDEO_FORMAT_HD_1080I50
:
516 case VIDEO_FORMAT_HD_1080P60
:
517 case VIDEO_FORMAT_HD_1080P50
:
518 case VIDEO_FORMAT_UHDTV_4K60
:
519 case VIDEO_FORMAT_UHDTV_4K50
:
520 case VIDEO_FORMAT_UHDTV_8K60
:
521 case VIDEO_FORMAT_UHDTV_8K50
:
522 case VIDEO_FORMAT_DIGI_CINEMA_2K24
:
523 case VIDEO_FORMAT_DIGI_CINEMA_4K24
:
524 if (ftype
== INTRA_PICTURE
){
525 int depth
= TransformDepth();
526 for (int i
=depth
; i
>=std::max(1,depth
-3); --i
)
527 SetCodeBlocks(i
, Xl()/(24*2^(depth
-i
)), Yl()/(24*2^(depth
-i
)));
528 for (int i
= 0; i
<std::max(1,depth
-3); ++i
)
529 SetCodeBlocks(i
, 1, 1);
532 int depth
= TransformDepth();
533 for (int i
=depth
; i
>=std::max(1,depth
-3); --i
)
534 SetCodeBlocks(i
, Xl()/(24*2^(depth
-i
)), Yl()/(24*2^(depth
-i
)));
535 for (int i
= 0; i
<std::max(1,depth
-3); ++i
)
536 SetCodeBlocks(i
, 1, 1);
541 DIRAC_THROW_EXCEPTION(
542 ERR_INVALID_VIDEO_FORMAT
,
543 "Unsupported video format",
544 SEVERITY_PICTURE_ERROR
);
551 int EncoderParams::GOPLength() const
554 return (m_num_L1
+1)*m_L1_sep
;
556 return ((m_num_L1
==0) ? 10 : 0);
559 DecoderParams::DecoderParams(const VideoFormat
& video_format
,
561 unsigned int num_refs
,
563 CodecParams(video_format
, ftype
, num_refs
, set_defaults
),
568 // ParseParams functions
570 ParseParams::ParseParams():
580 SourceParams::SourceParams(const VideoFormat
& video_format
,
583 // set default parameters
585 SetDefaultSourceParameters(video_format
, *this);
588 int SourceParams::ChromaWidth() const
602 int SourceParams::ChromaHeight() const
617 void SourceParams::SetFrameRate (FrameRateType fr
)
622 case FRAMERATE_23p97_FPS
:
623 m_framerate
.m_num
= 24000;
624 m_framerate
.m_denom
= 1001;
626 case FRAMERATE_24_FPS
:
627 m_framerate
.m_num
= 24;
628 m_framerate
.m_denom
= 1;
630 case FRAMERATE_25_FPS
:
631 m_framerate
.m_num
= 25;
632 m_framerate
.m_denom
= 1;
634 case FRAMERATE_29p97_FPS
:
635 m_framerate
.m_num
= 30000;
636 m_framerate
.m_denom
= 1001;
638 case FRAMERATE_30_FPS
:
639 m_framerate
.m_num
= 30;
640 m_framerate
.m_denom
= 1;
642 case FRAMERATE_50_FPS
:
643 m_framerate
.m_num
= 50;
644 m_framerate
.m_denom
= 1;
646 case FRAMERATE_59p94_FPS
:
647 m_framerate
.m_num
= 60000;
648 m_framerate
.m_denom
= 1001;
650 case FRAMERATE_60_FPS
:
651 m_framerate
.m_num
= 60;
652 m_framerate
.m_denom
= 1;
654 case FRAMERATE_14p98_FPS
:
655 m_framerate
.m_num
= 15000;
656 m_framerate
.m_denom
= 1001;
658 case FRAMERATE_12p5_FPS
:
659 m_framerate
.m_num
= 25;
660 m_framerate
.m_denom
= 2;
663 m_fr_idx
= FRAMERATE_CUSTOM
;
664 m_framerate
.m_num
= m_framerate
.m_denom
= 0;
669 void SourceParams::SetPixelAspectRatio (PixelAspectRatioType pix_asr_idx
)
671 m_pix_asr_idx
= pix_asr_idx
;
675 case PIXEL_ASPECT_RATIO_1_1
:
676 m_pixel_aspect_ratio
.m_num
= m_pixel_aspect_ratio
.m_denom
= 1;
678 case PIXEL_ASPECT_RATIO_10_11
:
679 m_pixel_aspect_ratio
.m_num
= 10;
680 m_pixel_aspect_ratio
.m_denom
= 11;
682 case PIXEL_ASPECT_RATIO_12_11
:
683 m_pixel_aspect_ratio
.m_num
= 12;
684 m_pixel_aspect_ratio
.m_denom
= 11;
686 case PIXEL_ASPECT_RATIO_40_33
:
687 m_pixel_aspect_ratio
.m_num
= 40;
688 m_pixel_aspect_ratio
.m_denom
= 33;
690 case PIXEL_ASPECT_RATIO_16_11
:
691 m_pixel_aspect_ratio
.m_num
= 16;
692 m_pixel_aspect_ratio
.m_denom
= 11;
694 case PIXEL_ASPECT_RATIO_4_3
:
695 m_pixel_aspect_ratio
.m_num
= 4;
696 m_pixel_aspect_ratio
.m_denom
= 3;
699 m_pix_asr_idx
= PIXEL_ASPECT_RATIO_CUSTOM
;
700 m_pixel_aspect_ratio
.m_num
= m_pixel_aspect_ratio
.m_denom
= 0;
705 void SourceParams::SetSignalRange (SignalRangeType sr
)
710 case SIGNAL_RANGE_8BIT_FULL
:
712 m_luma_excursion
= 255;
713 m_chroma_offset
= 128;
714 m_chroma_excursion
= 255;
716 case SIGNAL_RANGE_8BIT_VIDEO
:
718 m_luma_excursion
= 219;
719 m_chroma_offset
= 128;
720 m_chroma_excursion
= 224;
722 case SIGNAL_RANGE_10BIT_VIDEO
:
724 m_luma_excursion
= 876;
725 m_chroma_offset
= 512;
726 m_chroma_excursion
= 896;
728 case SIGNAL_RANGE_12BIT_VIDEO
:
730 m_luma_excursion
= 3504;
731 m_chroma_offset
= 2048;
732 m_chroma_excursion
= 3584;
735 m_sr_idx
= SIGNAL_RANGE_CUSTOM
;
737 m_luma_excursion
= 0;
739 m_chroma_excursion
= 0;
744 void SourceParams::SetColourSpecification (unsigned int cs_idx
)
750 m_col_primary
= CP_SDTV_525
;
751 m_col_matrix
= CM_SDTV
;
752 m_transfer_func
= TF_TV
;
755 m_col_primary
= CP_SDTV_625
;
756 m_col_matrix
= CM_SDTV
;
757 m_transfer_func
= TF_TV
;
760 m_col_primary
= CP_HDTV_COMP_INTERNET
;
761 m_col_matrix
= CM_HDTV_COMP_INTERNET
;
762 m_transfer_func
= TF_TV
;
765 m_col_primary
= CP_DCINEMA
;
766 m_col_matrix
= CM_HDTV_COMP_INTERNET
;
767 m_transfer_func
= TF_DCINEMA
;
771 m_col_primary
= CP_HDTV_COMP_INTERNET
;
772 m_col_matrix
= CM_HDTV_COMP_INTERNET
;
773 m_transfer_func
= TF_TV
;
778 void SourceParams::SetColourPrimariesIndex (unsigned int cp
)
783 //TODO: flag a warning
785 m_col_primary
= static_cast<ColourPrimaries
>(cp
);
788 void SourceParams::SetColourMatrixIndex (unsigned int cm
)
793 //TODO: flag a warning
795 m_col_matrix
= static_cast<ColourMatrix
>(cm
);
798 void SourceParams::SetTransferFunctionIndex (unsigned int tf
)
803 //TODO: flag a warning
805 m_transfer_func
= static_cast<TransferFunction
>(tf
);
809 //PictureParams functions
810 // Default constructor
811 PictureParams::PictureParams():
812 m_psort(PictureSort::IntraRefPictureSort()),
813 m_picture_type( INTRA_PICTURE
),
814 m_reference_type( REFERENCE_PICTURE
),
820 PictureParams::PictureParams(const ChromaFormat
& cf
,
822 unsigned int luma_depth
,
823 unsigned int chroma_depth
) :
825 m_psort(PictureSort::IntraRefPictureSort()),
826 m_picture_type( INTRA_PICTURE
),
827 m_reference_type( REFERENCE_PICTURE
),
831 m_luma_depth(luma_depth
),
832 m_chroma_depth(chroma_depth
),
841 else if (cf
== format422
)
846 else if (cf
== format444
)
854 PictureParams::PictureParams(const ChromaFormat
& cf
, const PictureSort
& ps
):
862 PictureParams::PictureParams(const SourceParams
& sparams
):
863 m_cformat(sparams
.CFormat()),
864 m_psort(PictureSort::IntraRefPictureSort()),
865 m_picture_type( INTRA_PICTURE
),
866 m_reference_type( REFERENCE_PICTURE
),
870 m_cxl(sparams
.ChromaWidth()),
871 m_cyl(sparams
.ChromaHeight()),
874 if (sparams
.SourceSampling() == 1)
879 m_luma_depth
= static_cast<unsigned int>
881 std::log((double)sparams
.LumaExcursion())/std::log(2.0) + 1
884 m_chroma_depth
= static_cast<unsigned int>
886 std::log((double)sparams
.ChromaExcursion())/std::log(2.0) + 1
892 void PictureParams::SetXl(int xlen
)
896 if (m_cformat
== format420
|| m_cformat
== format422
)
900 else if (m_cformat
== format444
)
906 void PictureParams::SetYl(int ylen
)
910 if (m_cformat
== format420
)
914 else if (m_cformat
== format422
|| m_cformat
== format444
)
920 bool PictureParams::IsBPicture() const
922 bool is_B_picture( false );
924 if ( m_refs
.size() == 2 )
926 if ( m_refs
[0] < m_fnum
&& m_refs
[1] > m_fnum
)
929 if ( m_refs
[0] > m_fnum
&& m_refs
[1] < m_fnum
)
936 void PictureParams::SetPicSort( const PictureSort
& ps
)
940 m_picture_type
= INTRA_PICTURE
;
942 m_picture_type
= INTER_PICTURE
;
945 m_reference_type
= REFERENCE_PICTURE
;
947 m_reference_type
= NON_REFERENCE_PICTURE
;
951 void PictureParams::SetPictureType(const PictureType ftype
)
953 m_picture_type
= ftype
;
954 if (ftype
== INTRA_PICTURE
)
960 void PictureParams::SetReferenceType(const ReferenceType rtype
)
962 m_reference_type
= rtype
;
963 if (rtype
== REFERENCE_PICTURE
)
970 QuantiserLists::QuantiserLists()
972 // FIXME: hardcode m_max_qindex to 119. In future this will depend on level
973 // As per spec max qf_idx is 127. But for values of qf_idx > 120 we
974 // will need more than 32 bits. Hence qf_idx is limited to 119.
976 m_qflist4( m_max_qindex
+1 ),
977 m_intra_offset4( m_max_qindex
+1 ),
978 m_inter_offset4( m_max_qindex
+1 )
982 m_intra_offset4
[0] = 1;
983 m_inter_offset4
[0] = 1;
984 m_intra_offset4
[1] = 2;
985 m_inter_offset4
[1] = 2;
988 unsigned __int64 base
, qfactor
;
990 uint64_t base
, qfactor
;
993 for (unsigned int q
=2; q
<=m_max_qindex
; ++q
)
1003 qfactor
= (503829*base
+52958)/105917;
1006 qfactor
= (665857*base
+58854)/117708;
1009 qfactor
= (440253*base
+32722)/65444;
1011 default: //Default case never used
1015 m_qflist4
[q
] = int( qfactor
);
1017 m_intra_offset4
[q
] = (m_qflist4
[q
]+1)>>1;
1018 m_inter_offset4
[q
] = (3*m_qflist4
[q
]+4)>>3;
1024 VideoFormat
IntToVideoFormat(int video_format
)
1026 switch(video_format
)
1028 case VIDEO_FORMAT_CUSTOM
:
1029 return VIDEO_FORMAT_CUSTOM
;
1030 case VIDEO_FORMAT_QSIF525
:
1031 return VIDEO_FORMAT_QSIF525
;
1032 case VIDEO_FORMAT_QCIF
:
1033 return VIDEO_FORMAT_QCIF
;
1034 case VIDEO_FORMAT_SIF525
:
1035 return VIDEO_FORMAT_SIF525
;
1036 case VIDEO_FORMAT_CIF
:
1037 return VIDEO_FORMAT_CIF
;
1038 case VIDEO_FORMAT_4CIF
:
1039 return VIDEO_FORMAT_4CIF
;
1040 case VIDEO_FORMAT_4SIF525
:
1041 return VIDEO_FORMAT_4SIF525
;
1042 case VIDEO_FORMAT_SD_480I60
:
1043 return VIDEO_FORMAT_SD_480I60
;
1044 case VIDEO_FORMAT_SD_576I50
:
1045 return VIDEO_FORMAT_SD_576I50
;
1046 case VIDEO_FORMAT_HD_720P60
:
1047 return VIDEO_FORMAT_HD_720P60
;
1048 case VIDEO_FORMAT_HD_720P50
:
1049 return VIDEO_FORMAT_HD_720P50
;
1050 case VIDEO_FORMAT_HD_1080I60
:
1051 return VIDEO_FORMAT_HD_1080I60
;
1052 case VIDEO_FORMAT_HD_1080I50
:
1053 return VIDEO_FORMAT_HD_1080I50
;
1054 case VIDEO_FORMAT_HD_1080P60
:
1055 return VIDEO_FORMAT_HD_1080P60
;
1056 case VIDEO_FORMAT_HD_1080P50
:
1057 return VIDEO_FORMAT_HD_1080P50
;
1058 case VIDEO_FORMAT_DIGI_CINEMA_2K24
:
1059 return VIDEO_FORMAT_DIGI_CINEMA_2K24
;
1060 case VIDEO_FORMAT_DIGI_CINEMA_4K24
:
1061 return VIDEO_FORMAT_DIGI_CINEMA_4K24
;
1062 case VIDEO_FORMAT_UHDTV_4K60
:
1063 return VIDEO_FORMAT_UHDTV_4K60
;
1064 case VIDEO_FORMAT_UHDTV_4K50
:
1065 return VIDEO_FORMAT_UHDTV_4K50
;
1066 case VIDEO_FORMAT_UHDTV_8K60
:
1067 return VIDEO_FORMAT_UHDTV_8K60
;
1068 case VIDEO_FORMAT_UHDTV_8K50
:
1069 return VIDEO_FORMAT_UHDTV_8K50
;
1071 return VIDEO_FORMAT_UNDEFINED
;
1075 ChromaFormat
IntToChromaFormat(int chroma_format
)
1077 switch(chroma_format
)
1090 FrameRateType
IntToFrameRateType(int frame_rate_idx
)
1092 switch(frame_rate_idx
)
1094 case FRAMERATE_CUSTOM
:
1095 return FRAMERATE_CUSTOM
;
1096 case FRAMERATE_23p97_FPS
:
1097 return FRAMERATE_23p97_FPS
;
1098 case FRAMERATE_24_FPS
:
1099 return FRAMERATE_24_FPS
;
1100 case FRAMERATE_25_FPS
:
1101 return FRAMERATE_25_FPS
;
1102 case FRAMERATE_29p97_FPS
:
1103 return FRAMERATE_29p97_FPS
;
1104 case FRAMERATE_30_FPS
:
1105 return FRAMERATE_30_FPS
;
1106 case FRAMERATE_50_FPS
:
1107 return FRAMERATE_30_FPS
;
1108 case FRAMERATE_59p94_FPS
:
1109 return FRAMERATE_59p94_FPS
;
1110 case FRAMERATE_60_FPS
:
1111 return FRAMERATE_60_FPS
;
1112 case FRAMERATE_14p98_FPS
:
1113 return FRAMERATE_14p98_FPS
;
1114 case FRAMERATE_12p5_FPS
:
1115 return FRAMERATE_12p5_FPS
;
1117 return FRAMERATE_UNDEFINED
;
1121 PixelAspectRatioType
IntToPixelAspectRatioType(int pix_asr_idx
)
1125 case PIXEL_ASPECT_RATIO_CUSTOM
:
1126 return PIXEL_ASPECT_RATIO_CUSTOM
;
1127 case PIXEL_ASPECT_RATIO_1_1
:
1128 return PIXEL_ASPECT_RATIO_1_1
;
1129 case PIXEL_ASPECT_RATIO_10_11
:
1130 return PIXEL_ASPECT_RATIO_10_11
;
1131 case PIXEL_ASPECT_RATIO_12_11
:
1132 return PIXEL_ASPECT_RATIO_12_11
;
1133 case PIXEL_ASPECT_RATIO_40_33
:
1134 return PIXEL_ASPECT_RATIO_40_33
;
1135 case PIXEL_ASPECT_RATIO_16_11
:
1136 return PIXEL_ASPECT_RATIO_16_11
;
1137 case PIXEL_ASPECT_RATIO_4_3
:
1138 return PIXEL_ASPECT_RATIO_4_3
;
1140 return PIXEL_ASPECT_RATIO_UNDEFINED
;
1145 SignalRangeType
IntToSignalRangeType(int signal_range_idx
)
1147 switch(signal_range_idx
)
1149 case SIGNAL_RANGE_CUSTOM
:
1150 return SIGNAL_RANGE_CUSTOM
;
1151 case SIGNAL_RANGE_8BIT_FULL
:
1152 return SIGNAL_RANGE_8BIT_FULL
;
1153 case SIGNAL_RANGE_8BIT_VIDEO
:
1154 return SIGNAL_RANGE_8BIT_VIDEO
;
1155 case SIGNAL_RANGE_10BIT_VIDEO
:
1156 return SIGNAL_RANGE_10BIT_VIDEO
;
1157 case SIGNAL_RANGE_12BIT_VIDEO
:
1158 return SIGNAL_RANGE_12BIT_VIDEO
;
1160 return SIGNAL_RANGE_UNDEFINED
;
1164 MVPrecisionType
IntToMVPrecisionType(int mv_prec
)
1168 case MV_PRECISION_PIXEL
:
1169 return MV_PRECISION_PIXEL
;
1170 case MV_PRECISION_HALF_PIXEL
:
1171 return MV_PRECISION_HALF_PIXEL
;
1172 case MV_PRECISION_QUARTER_PIXEL
:
1173 return MV_PRECISION_QUARTER_PIXEL
;
1174 case MV_PRECISION_EIGHTH_PIXEL
:
1175 return MV_PRECISION_EIGHTH_PIXEL
;
1177 return MV_PRECISION_UNDEFINED
;