Decodificatore H.264 per gli strumenti di Baseline ed Extended: FMO, ASO, slice ridondanti, partizionamento dei dati, slice SP e SI (#58)
Il decodificatore rifiutava i flussi con gruppi di slice e con slice SP o SI, e non leggeva le partizioni A, B e C: ora li gestisce tutti, perché sono parte di Baseline ed Extended e un file della libreria può usarli. - Gruppi di slice dal PPS, tipi da 0 a 6, con il cambio per immagine di slice_group_change_cycle; il macroblocco successivo segue il gruppo (§8.2.2). - Slice in ordine qualunque: la disponibilità dei vicini era già per slice, il deblocking a fine immagine. - Slice SP e SI con QS (§8.6): predizione trasformata e riquantizzata in QS, anche per P_Skip; sp_for_switch_flag e macroblocchi SI; nel deblocking contano come intra. - Partizionamento: A con intestazione e dati di categoria 2, B con il residuo intra (e gli I_PCM), C con quello inter; la regola del nN a zero con la predizione intra vincolata (§9.2.1). Una partizione che manca lascia a zero il suo residuo e, da lì in poi, quello della partizione che ne dipende. I cinque flussi FMO, ASO e SP della serie ITU-T (FM2_SVA_C, FM1_FT_E, FM1_BT_B, sp1_bt_a, sp2_bt_b) passano fra i verificati e coincidono fotogramma per fotogramma. Partizionamento, slice ridondanti e ASO si provano riscrivendo flussi verificati senza toccare i bit dei macroblocchi (StreamRewriter) e chiedendo di nuovo il riferimento ufficiale; le SI con un flusso sintetico calcolato a mano. Anche i flussi nuovi e quelli partizionati sono provati rovinati. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9c626f67ec
commit
8d03ca23de
19 files changed
+1738
-169
No files matched your search
@@ -181,6 +181,31 @@ internal sealed class Pps
|
||||
internal bool WeightedPred;
|
||||
internal int WeightedBipredIdc;
|
||||
internal int PicInitQp;
|
||||
|
||||
/// <summary>26 + pic_init_qs_minus26: the starting QS of SP and SI slices.</summary>
|
||||
internal int PicInitQs;
|
||||
|
||||
/// <summary>num_slice_groups_minus1 + 1: more than one is FMO (§8.2.2).</summary>
|
||||
internal int NumSliceGroups = 1;
|
||||
|
||||
internal int SliceGroupMapType;
|
||||
|
||||
/// <summary>run_length_minus1 + 1 of each slice group (map type 0).</summary>
|
||||
internal int[] RunLength = [];
|
||||
|
||||
/// <summary>top_left and bottom_right of the rectangles of the slice groups but the last (map type 2).</summary>
|
||||
internal int[] TopLeft = [];
|
||||
|
||||
internal int[] BottomRight = [];
|
||||
|
||||
internal bool SliceGroupChangeDirection;
|
||||
|
||||
/// <summary>slice_group_change_rate_minus1 + 1 (map types 3–5).</summary>
|
||||
internal int SliceGroupChangeRate;
|
||||
|
||||
/// <summary>slice_group_id of each map unit (map type 6).</summary>
|
||||
internal byte[] SliceGroupIds = [];
|
||||
|
||||
internal int ChromaQpIndexOffset;
|
||||
internal int SecondChromaQpIndexOffset;
|
||||
internal bool DeblockingFilterControlPresent;
|
||||
@@ -196,9 +221,10 @@ internal sealed class Pps
|
||||
var p = new Pps { Id = r.ReadUe(255), SpsId = r.ReadUe(31) };
|
||||
p.Cabac = r.ReadFlag();
|
||||
p.BottomFieldPicOrderInFramePresent = r.ReadFlag();
|
||||
if (r.ReadUe(7) > 0)
|
||||
p.NumSliceGroups = r.ReadUe(7) + 1;
|
||||
if (p.NumSliceGroups > 1)
|
||||
{
|
||||
throw new H264Exception("I gruppi di slice (FMO) non sono gestiti.");
|
||||
ParseSliceGroups(r, p);
|
||||
}
|
||||
|
||||
p.NumRefIdxL0DefaultActive = r.ReadUe(31) + 1;
|
||||
@@ -206,7 +232,12 @@ internal sealed class Pps
|
||||
p.WeightedPred = r.ReadFlag();
|
||||
p.WeightedBipredIdc = (int)r.Read(2);
|
||||
p.PicInitQp = 26 + r.ReadSe();
|
||||
r.ReadSe(); // pic_init_qs_minus26
|
||||
p.PicInitQs = 26 + r.ReadSe();
|
||||
if (p.PicInitQs is < 0 or > 51)
|
||||
{
|
||||
throw new H264Exception("QS iniziale del PPS non valido.");
|
||||
}
|
||||
|
||||
p.ChromaQpIndexOffset = r.ReadSe();
|
||||
p.DeblockingFilterControlPresent = r.ReadFlag();
|
||||
p.ConstrainedIntraPred = r.ReadFlag();
|
||||
@@ -227,6 +258,58 @@ internal sealed class Pps
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/// <summary>The slice group map of §7.3.2.2 (num_slice_groups_minus1 above 0), checked against the picture later.</summary>
|
||||
private static void ParseSliceGroups(RbspReader r, Pps p)
|
||||
{
|
||||
p.SliceGroupMapType = r.ReadUe(6);
|
||||
var groups = p.NumSliceGroups;
|
||||
switch (p.SliceGroupMapType)
|
||||
{
|
||||
case 0:
|
||||
p.RunLength = new int[groups];
|
||||
for (var i = 0; i < groups; i++)
|
||||
{
|
||||
p.RunLength[i] = r.ReadUe(Sps.MaxFrameMbs - 1) + 1;
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
p.TopLeft = new int[groups - 1];
|
||||
p.BottomRight = new int[groups - 1];
|
||||
for (var i = 0; i < groups - 1; i++)
|
||||
{
|
||||
p.TopLeft[i] = r.ReadUe(Sps.MaxFrameMbs - 1);
|
||||
p.BottomRight[i] = r.ReadUe(Sps.MaxFrameMbs - 1);
|
||||
}
|
||||
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
p.SliceGroupChangeDirection = r.ReadFlag();
|
||||
p.SliceGroupChangeRate = r.ReadUe(Sps.MaxFrameMbs - 1) + 1;
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
var size = r.ReadUe(Sps.MaxFrameMbs - 1) + 1;
|
||||
var bits = 32 - System.Numerics.BitOperations.LeadingZeroCount((uint)(groups - 1));
|
||||
p.SliceGroupIds = new byte[size];
|
||||
for (var i = 0; i < size; i++)
|
||||
{
|
||||
var id = (int)r.Read(bits);
|
||||
if (id >= groups || r.BitsLeft < 0)
|
||||
{
|
||||
throw new H264Exception("slice_group_id non valido.");
|
||||
}
|
||||
|
||||
p.SliceGroupIds[i] = (byte)id;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Scaling lists (§7.3.2.1.1.1, tables 7-2 to 7-4) and the scale factors derived from them (§8.5.9).</summary>
|
||||
|
||||
Reference in new issue
Block a user