-static const uint8_t default_scaling4[2][16]={
-{ 6,13,20,28,
- 13,20,28,32,
- 20,28,32,37,
- 28,32,37,42
-},{
- 10,14,20,24,
- 14,20,24,27,
- 20,24,27,30,
- 24,27,30,34
-}};
-
-static const uint8_t default_scaling8[2][64]={
-{ 6,10,13,16,18,23,25,27,
- 10,11,16,18,23,25,27,29,
- 13,16,18,23,25,27,29,31,
- 16,18,23,25,27,29,31,33,
- 18,23,25,27,29,31,33,36,
- 23,25,27,29,31,33,36,38,
- 25,27,29,31,33,36,38,40,
- 27,29,31,33,36,38,40,42
-},{
- 9,13,15,17,19,21,22,24,
- 13,13,17,19,21,22,24,25,
- 15,17,19,21,22,24,25,27,
- 17,19,21,22,24,25,27,28,
- 19,21,22,24,25,27,28,30,
- 21,22,24,25,27,28,30,32,
- 22,24,25,27,28,30,32,33,
- 24,25,27,28,30,32,33,35
-}};
-
-static inline int decode_hrd_parameters(H264Context *h, SPS *sps){
- MpegEncContext * const s = &h->s;
+/* maximum number of MBs in the DPB for a given level */
+static const int level_max_dpb_mbs[][2] = {
+ { 10, 396 },
+ { 11, 900 },
+ { 12, 2376 },
+ { 13, 2376 },
+ { 20, 2376 },
+ { 21, 4752 },
+ { 22, 8100 },
+ { 30, 8100 },
+ { 31, 18000 },
+ { 32, 20480 },
+ { 40, 32768 },
+ { 41, 32768 },
+ { 42, 34816 },
+ { 50, 110400 },
+ { 51, 184320 },
+ { 52, 184320 },
+};
+
+static void remove_pps(H264ParamSets *s, int id)
+{
+ if (s->pps_list[id] && s->pps == (const PPS*)s->pps_list[id]->data)
+ s->pps = NULL;
+ av_buffer_unref(&s->pps_list[id]);
+}
+
+static void remove_sps(H264ParamSets *s, int id)
+{
+ int i;
+ if (s->sps_list[id]) {
+ if (s->sps == (SPS*)s->sps_list[id]->data)
+ s->sps = NULL;
+
+ /* drop all PPS that depend on this SPS */
+ for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++)
+ if (s->pps_list[i] && ((PPS*)s->pps_list[i]->data)->sps_id == id)
+ remove_pps(s, i);
+ }
+ av_buffer_unref(&s->sps_list[id]);
+}
+
+static inline int decode_hrd_parameters(GetBitContext *gb, AVCodecContext *avctx,
+ SPS *sps)
+{