Commit 2dbb2282 authored by Kehuang Li's avatar Kehuang Li Committed by Chromium LUCI CQ

[Chromecast] Add padding bytes to the end of handshake packet

Audio packet can be sent after handshake packet, and thus handshake
packet must also has a multiple of 4 bytes to ensure alignment of audio
data.

Merge-With: eureka-internal/509721
Bug: internal: 176167293
Test: Add alignment check on receiver side and audio works fine.
Change-Id: I57343bf0238df64de47ec69ed5b64ed4eecd0a43
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2607812
Commit-Queue: Kehuang Li <kehuangli@chromium.org>
Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840446}
parent 18676a0b
......@@ -28,24 +28,26 @@ namespace capture_service {
namespace {
constexpr StreamInfo kStreamInfo =
StreamInfo{StreamType::kSoftwareEchoCancelled,
AudioCodec::kPcm,
1,
SampleFormat::PLANAR_FLOAT,
16000,
160};
constexpr HandshakePacket kHandshakePacket =
HandshakePacket{0,
static_cast<uint8_t>(MessageType::kHandshake),
static_cast<uint8_t>(kStreamInfo.stream_type),
static_cast<uint8_t>(kStreamInfo.audio_codec),
static_cast<uint8_t>(kStreamInfo.sample_format),
kStreamInfo.num_channels,
kStreamInfo.frames_per_buffer,
kStreamInfo.sample_rate};
constexpr PcmPacketHeader kPcmAudioPacketHeader =
PcmPacketHeader{0, static_cast<uint8_t>(MessageType::kPcmAudio),
static_cast<uint8_t>(kStreamInfo.stream_type), 0};
StreamInfo{.stream_type = StreamType::kSoftwareEchoCancelled,
.audio_codec = AudioCodec::kPcm,
.num_channels = 1,
.sample_format = SampleFormat::PLANAR_FLOAT,
.sample_rate = 16000,
.frames_per_buffer = 160};
constexpr HandshakePacket kHandshakePacket = HandshakePacket{
.size = 0, // dummy
.message_type = static_cast<uint8_t>(MessageType::kHandshake),
.stream_type = static_cast<uint8_t>(kStreamInfo.stream_type),
.audio_codec = static_cast<uint8_t>(kStreamInfo.audio_codec),
.sample_format = static_cast<uint8_t>(kStreamInfo.sample_format),
.num_channels = kStreamInfo.num_channels,
.num_frames = kStreamInfo.frames_per_buffer,
.sample_rate = kStreamInfo.sample_rate};
constexpr PcmPacketHeader kPcmAudioPacketHeader = PcmPacketHeader{
.size = 0, // dummy
.message_type = static_cast<uint8_t>(MessageType::kPcmAudio),
.stream_type = static_cast<uint8_t>(kStreamInfo.stream_type),
.timestamp_us = 0};
class MockStreamSocket : public chromecast::MockStreamSocket {
public:
......
......@@ -27,6 +27,10 @@ namespace {
constexpr size_t kHandshakeHeaderBytes =
sizeof(HandshakePacket) - sizeof(uint16_t);
static_assert(sizeof(PcmPacketHeader) % 4 == 0,
"Size of PCM audio packet header must be a multiple of 4 bytes.");
static_assert(sizeof(HandshakePacket) % 4 == 0,
"Size of handshake packet must be a multiple of 4 bytes.");
static_assert(kPcmAudioHeaderBytes ==
sizeof(PcmPacketHeader) - sizeof(uint16_t),
"Invalid message header size.");
......
......@@ -23,8 +23,9 @@ struct __attribute__((__packed__)) PcmPacketHeader {
int64_t timestamp_us;
};
// Memory block of a handshake packet. There is no size restriction for this
// structure.
// Memory block of a handshake packet. Audio packet may be sent after handshake
// packet, and thus handshake packet must also have a multiple of 4 bytes, since
// audio data must be aligned.
struct __attribute__((__packed__)) HandshakePacket {
uint16_t size;
uint8_t message_type;
......@@ -32,7 +33,9 @@ struct __attribute__((__packed__)) HandshakePacket {
uint8_t audio_codec;
uint8_t sample_format;
uint8_t num_channels;
uint8_t padding_uint8;
uint16_t num_frames;
uint16_t padding_uint16;
uint32_t sample_rate;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment