@@ -137,11 +137,12 @@ ADTSFrame::ADTSFrameInfo ADTSFrame::GetFrameInfo(AP4_ByteStream* stream)
137137 case AdtsType::AC3:
138138 ParseAc3Header (stream, frameInfo);
139139 break ;
140+ case AdtsType::AC4:
141+ ParseAc4Header (stream, frameInfo);
142+ break ;
140143 case AdtsType::EAC3:
141144 ParseEc3Header (stream, frameInfo);
142145 break ;
143- case AdtsType::AC4:
144- break ;
145146 default :
146147 break ;
147148 }
@@ -157,10 +158,10 @@ bool ADTSFrame::parse(AP4_ByteStream* stream)
157158 return ParseAac (stream);
158159 case AdtsType::AC3:
159160 return ParseAc3 (stream);
161+ case AdtsType::AC4:
162+ return ParseAc4 (stream);
160163 case AdtsType::EAC3:
161164 return ParseEc3 (stream);
162- case AdtsType::AC4:
163- return false ;
164165 default :
165166 return false ;
166167 }
@@ -255,6 +256,50 @@ bool ADTSFrame::ParseAc3Header(AP4_ByteStream* stream, ADTSFrameInfo& frameInfo)
255256 return true ;
256257}
257258
259+ bool ADTSFrame::ParseAc4 (AP4_ByteStream* stream)
260+ {
261+ if (!ParseAc4Header (stream, m_frameInfo))
262+ return false ;
263+
264+ m_summedFrameCount += m_frameInfo.m_frameCount ;
265+
266+ // rewind stream to beginning of syncframe
267+ AP4_Position currentPos;
268+ stream->Tell (currentPos);
269+ stream->Seek (currentPos - (AP4_AC4_HEADER_SIZE));
270+
271+ m_dataBuffer.SetDataSize (m_frameInfo.m_frameSize );
272+ if (!AP4_SUCCEEDED (stream->Read (m_dataBuffer.UseData (), m_dataBuffer.GetDataSize ())))
273+ return false ;
274+
275+ AdjustStreamForPadding (stream);
276+ return true ;
277+ }
278+
279+ bool ADTSFrame::ParseAc4Header (AP4_ByteStream* stream, ADTSFrameInfo& frameInfo)
280+ {
281+ AP4_DataBuffer buffer;
282+ buffer.SetDataSize (AP4_AC3_HEADER_SIZE);
283+
284+ if (!AP4_SUCCEEDED (stream->Read (buffer.UseData (), AP4_AC3_HEADER_SIZE)))
285+ return false ;
286+
287+ CAdaptiveAc3Parser parser;
288+ AP4_Size sz = buffer.GetDataSize ();
289+ parser.Feed (buffer.GetData (), &sz);
290+
291+ AP4_Ac3Frame frame;
292+ AP4_Result result = parser.FindFrameHeader (frame);
293+ if (!AP4_SUCCEEDED (result))
294+ return false ;
295+
296+ frameInfo.m_frameSize = frame.m_Info .m_FrameSize ;
297+ frameInfo.m_frameCount = 256u * frame.m_Info .m_ChannelCount ;
298+ frameInfo.m_sampleRate = frame.m_Info .m_SampleRate ;
299+ frameInfo.m_channels = frame.m_Info .m_ChannelCount ;
300+ return true ;
301+ }
302+
258303bool ADTSFrame::ParseEc3 (AP4_ByteStream* stream)
259304{
260305 if (!ParseEc3Header (stream, m_frameInfo))
@@ -379,6 +424,10 @@ bool ADTSReader::GetInformation(kodi::addon::InputstreamInfo& info)
379424 {
380425 codecName = CODEC::NAME_AC3;
381426 }
427+ else if (frameInfo.m_codecType == AdtsType::AC4)
428+ {
429+ codecName = CODEC::NAME_AC4;
430+ }
382431 else if (frameInfo.m_codecType == AdtsType::EAC3)
383432 {
384433 codecName = CODEC::NAME_EAC3;
0 commit comments