Skip to content

Commit

Permalink
Merge pull request #1723 from JeromeMartinez/USAC_LoudnessInfoSet
Browse files Browse the repository at this point in the history
USAC: refactoring of loudnessInfoSet conformance checks
  • Loading branch information
JeromeMartinez authored Mar 28, 2023
2 parents e654288 + ad30591 commit bc56c02
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
20 changes: 4 additions & 16 deletions Source/MediaInfo/Audio/File_Mpegh3da.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,9 @@ void File_Mpegh3da::Streams_Fill()
bool NoLoudnesConch;
if (!Mpegh3da_loudnessInfo_Data[0].empty())
{
C.Reset(false, true);
C.loudnessInfo_Data[0]=Mpegh3da_loudnessInfo_Data[0].begin()->second.Data[0];
C.loudnessInfo_Data[1]=Mpegh3da_loudnessInfo_Data[0].begin()->second.Data[1];
#if MEDIAINFO_CONFORMANCE
C.loudnessInfoSet_Present[0]=0;
C.loudnessInfoSet_Present[1]=1;
#endif
Fill_Loudness(NULL);
C.loudnessInfo_Data[0].clear();
C.loudnessInfo_Data[1].clear();
Expand Down Expand Up @@ -410,11 +407,8 @@ void File_Mpegh3da::Streams_Fill()
std::map<int8u, loudness_info_data>::iterator Loudness=Mpegh3da_loudnessInfo_Data[3].find(P.ID);
if (Loudness!=Mpegh3da_loudnessInfo_Data[3].end())
{
C.Reset(false, true);
C.loudnessInfo_Data[0]=Loudness->second.Data[0];
#if MEDIAINFO_CONFORMANCE
C.loudnessInfoSet_Present[0]=0;
C.loudnessInfoSet_Present[1]=1;
#endif
Fill_Loudness(p.c_str(), NoLoudnesConch);
C.loudnessInfo_Data[0].clear();
}
Expand Down Expand Up @@ -544,11 +538,8 @@ void File_Mpegh3da::Streams_Fill()
std::map<int8u, loudness_info_data>::iterator Loudness=Mpegh3da_loudnessInfo_Data[1].find(G.ID);
if (Loudness!=Mpegh3da_loudnessInfo_Data[1].end())
{
C.Reset(false, true);
C.loudnessInfo_Data[0]=Loudness->second.Data[0];
#if MEDIAINFO_CONFORMANCE
C.loudnessInfoSet_Present[0]=0;
C.loudnessInfoSet_Present[1]=1;
#endif
Fill_Loudness(g.c_str(), NoLoudnesConch);
C.loudnessInfo_Data[0].clear();
}
Expand All @@ -568,11 +559,8 @@ void File_Mpegh3da::Streams_Fill()
std::map<int8u, loudness_info_data>::iterator Loudness=Mpegh3da_loudnessInfo_Data[2].find(G.ID);
if (Loudness!=Mpegh3da_loudnessInfo_Data[2].end())
{
C.Reset(false, true);
C.loudnessInfo_Data[0]=Loudness->second.Data[0];
#if MEDIAINFO_CONFORMANCE
C.loudnessInfoSet_Present[0]=0;
C.loudnessInfoSet_Present[1]=1;
#endif
Fill_Loudness(g.c_str(), NoLoudnesConch);
C.loudnessInfo_Data[0].clear();
}
Expand Down
13 changes: 6 additions & 7 deletions Source/MediaInfo/Audio/File_Usac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,8 +1248,7 @@ void File_Usac::UsacConfig(size_t BitsNotIncluded)
C = usac_config();
#if MEDIAINFO_CONFORMANCE
Warning_Error=MediaInfoLib::Config.WarningError();
C.loudnessInfoSet_Present[0] = 0;
C.loudnessInfoSet_Present[1] = 0;
C.Reset();
#endif

Element_Begin1("UsacConfig");
Expand Down Expand Up @@ -1521,7 +1520,7 @@ void File_Usac::Fill_Loudness(const char* Prefix, bool NoConCh)
if (NoConCh || C.IsNotValid)
return;
auto loudnessInfoSet_Present_Total=C.loudnessInfoSet_Present[0]+C.loudnessInfoSet_Present[1];
if (C.loudnessInfoSet_Present[0] && C.loudnessInfoSet_Present[1])
if (C.loudnessInfoSet_HasContent[0] && C.loudnessInfoSet_HasContent[1])
Fill_Conformance("loudnessInfoSet Coherency", "Mix of v0 and v1");
if (C.loudnessInfoSet_Present[0]>1)
Fill_Conformance("loudnessInfoSet Coherency", "loudnessInfoSet is present " + to_string(C.loudnessInfoSet_Present[0]) + " times but only 1 instance is allowed");
Expand Down Expand Up @@ -2600,18 +2599,18 @@ void File_Usac::loudnessInfoSet(bool V1)
Element_Begin1(V1?"loudnessInfoSetV1":"loudnessInfoSet");

#if MEDIAINFO_CONFORMANCE
if (V1)
C.loudnessInfoSet_Present[V1]++;
C.loudnessInfoSet_Present[V1]++;
#endif

int8u loudnessInfoAlbumCount, loudnessInfoCount;
bool loudnessInfoSetExtPresent;
Get_S1 (6, loudnessInfoAlbumCount, "loudnessInfoAlbumCount");
Get_S1 (6, loudnessInfoCount, "loudnessInfoCount");
#if MEDIAINFO_CONFORMANCE
if (!V1 && (loudnessInfoAlbumCount || loudnessInfoCount))
C.loudnessInfoSet_Present[V1]++;
if (loudnessInfoAlbumCount || loudnessInfoCount)
C.loudnessInfoSet_HasContent[V1]=true;
#endif

for (int8u i=0; i<loudnessInfoAlbumCount; i++)
loudnessInfo(true, V1);
for (int8u i=0; i<loudnessInfoCount; i++)
Expand Down
11 changes: 11 additions & 0 deletions Source/MediaInfo/Audio/File_Usac.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ public :
gain_sets gainSets;
#if MEDIAINFO_CONFORMANCE
size_t loudnessInfoSet_Present[2];
bool loudnessInfoSet_HasContent[2];
vector<size_t> numOutChannels_Lfe;
#endif
int32u numOutChannels;
Expand All @@ -353,6 +354,16 @@ public :
arith_context arithContext[2];
sbr_handler sbrHandler;
usac_dlft_handler dlftHandler;

void Reset(bool V0=false, bool V1=false)
{
#if MEDIAINFO_CONFORMANCE
loudnessInfoSet_HasContent[0]=V0;
loudnessInfoSet_HasContent[1]=V1;
loudnessInfoSet_Present[0]=V0;
loudnessInfoSet_Present[1]=V1;
#endif
}
};
struct usac_frame
{
Expand Down

0 comments on commit bc56c02

Please sign in to comment.