Skip to content

Commit 77b9397

Browse files
committed
Bug 1891082 - Add a function for making AAC specific config r=media-playback-reviewers,padenot
Depends on D219146 Differential Revision: https://phabricator.services.mozilla.com/D219147 UltraBlame original commit: 8e10bbcacceafdb4f862a3007bf7bf540185d480
1 parent 3dea7f9 commit 77b9397

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

dom/media/platforms/agnostic/bytestreams/Adts.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
#include "Adts.h"
6+
#include "BitWriter.h"
67
#include "MediaData.h"
78
#include "PlatformDecoderModule.h"
89
#include "mozilla/Array.h"
@@ -286,6 +287,52 @@ void InitAudioSpecificConfig(const ADTS::Frame& frame,
286287
aBuffer->AppendElements(asc, 2);
287288
}
288289

290+
291+
Result<already_AddRefed<MediaByteBuffer>, nsresult> MakeSpecificConfig(
292+
uint8_t aObjectType, uint32_t aFrequency, uint32_t aChannelCount) {
293+
if (aObjectType > 45 || aObjectType == 0x1F ) {
294+
return Err(NS_ERROR_INVALID_ARG);
295+
}
296+
297+
if (aFrequency > 0x00FFFFFF ) {
298+
return Err(NS_ERROR_INVALID_ARG);
299+
}
300+
301+
if (aChannelCount > 8 || aChannelCount == 7) {
302+
return Err(NS_ERROR_INVALID_ARG);
303+
}
304+
305+
uint8_t index = GetFrequencyIndex(aFrequency)
306+
.unwrapOr(0x0F );
307+
MOZ_ASSERT(index <= 0x0F );
308+
309+
uint8_t channelConfig =
310+
aChannelCount == 8 ? aChannelCount - 1 : aChannelCount;
311+
312+
RefPtr<MediaByteBuffer> buffer = new MediaByteBuffer();
313+
BitWriter bw(buffer);
314+
315+
if (aObjectType < 0x1F ) {
316+
bw.WriteBits(aObjectType, 5);
317+
} else {
318+
MOZ_ASSERT(aObjectType >= 32);
319+
bw.WriteBits(0x1F, 5);
320+
321+
bw.WriteBits(aObjectType - 32, 6);
322+
}
323+
324+
bw.WriteBits(index, 4);
325+
if (index == 0x0F ) {
326+
bw.WriteBits(aFrequency, 24);
327+
}
328+
329+
bw.WriteBits(channelConfig, 4);
330+
331+
332+
333+
return buffer.forget();
334+
}
335+
289336
};
290337
};
291338

dom/media/platforms/agnostic/bytestreams/Adts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Result<uint8_t, bool> GetFrequencyIndex(uint32_t aSamplesPerSecond);
123123
bool ConvertSample(uint16_t aChannelCount, uint8_t aFrequencyIndex,
124124
uint8_t aProfile, mozilla::MediaRawData* aSample);
125125
bool RevertSample(MediaRawData* aSample);
126+
Result<already_AddRefed<MediaByteBuffer>, nsresult> MakeSpecificConfig(
127+
uint8_t aObjectType, uint32_t aFrequency, uint32_t aChannelCount);
126128
}
127129
}
128130

0 commit comments

Comments
 (0)