Skip to content

Commit

Permalink
Add Opus audio content block type
Browse files Browse the repository at this point in the history
Summary: We're adding audio/opus as a content block type, just like we have image/jpg, image/png, etc.

Differential Revision: D53259226

fbshipit-source-id: 51b563d175d881618f715556d60c57db57df5a9d
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Feb 1, 2024
1 parent 154df37 commit 3c7e7cc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vrs/RecordFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static_assert(
static_assert(
static_cast<int>(PixelFormat::YUV_420_NV12) == 22,
"PixelFormat enum values CHANGED!");
const char* sAudioFormatNames[] = {"undefined", "pcm"};
const char* sAudioFormatNames[] = {"undefined", "pcm", "opus"};
struct AudioFormatConverter : public EnumStringConverter<
AudioFormat,
sAudioFormatNames,
Expand All @@ -147,6 +147,7 @@ struct AudioFormatConverter : public EnumStringConverter<

// Enum values may NEVER BE CHANGED, as they are used in data layout definitions!!
static_assert(static_cast<int>(AudioFormat::PCM) == 1, "AudioFormat enum values CHANGED!");
static_assert(static_cast<int>(AudioFormat::OPUS) == 2, "AudioFormat enum values CHANGED!");

// These text names may NEVER BE CHANGED, as they are used in data layout definitions!!
const char* sAudioSampleFormatNames[] = {
Expand Down
1 change: 1 addition & 0 deletions vrs/RecordFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ string toString(PixelFormat pixelFormat);
enum class AudioFormat : uint8_t {
UNDEFINED = 0, ///< Unknown/unspecified.
PCM = 1, ///< Raw PCM audio data.
OPUS = 2, ///< Audio data compressed using Opus. https://opus-codec.org/
COUNT ///< Count of values in this enum type. @internal
};

Expand Down
16 changes: 16 additions & 0 deletions vrs/test/RecordFormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,22 @@ TEST_F(RecordFormatTest, testBlockFormat) {
"audio/pcm/float64be/channels=2/rate=32000/samples=100");
FORMAT_EQUAL(ContentBlock(ContentType::CUSTOM), "custom");
FORMAT_EQUAL(ContentBlock(ContentType::CUSTOM, 20), "custom/size=20");

ContentBlock opus("audio/opus");
EXPECT_EQ(opus.getContentType(), ContentType::AUDIO);
EXPECT_EQ(opus.audio().getAudioFormat(), AudioFormat::OPUS);

ContentBlock opusFull("audio/opus/float64be/channels=2/rate=32000/samples=100/stride=16");
EXPECT_EQ(opusFull.getContentType(), ContentType::AUDIO);
EXPECT_EQ(opusFull.getBlockSize(), 100 * 8 * 2);
EXPECT_EQ(opusFull.audio().getAudioFormat(), AudioFormat::OPUS);
EXPECT_EQ(opusFull.audio().getSampleFormat(), AudioSampleFormat::F64_BE);
EXPECT_EQ(opusFull.audio().getSampleRate(), 32000);
EXPECT_EQ(opusFull.audio().getChannelCount(), 2);
EXPECT_EQ(opusFull.audio().getBitsPerSample(), 64);
EXPECT_EQ(opusFull.audio().isLittleEndian(), false);
EXPECT_EQ(opusFull.audio().getSampleBlockStride(), 16);
EXPECT_EQ(opusFull.audio().getSampleCount(), 100);
}

TEST_F(RecordFormatTest, testBadStride) {
Expand Down

0 comments on commit 3c7e7cc

Please sign in to comment.