Skip to content

Commit

Permalink
add announce_ok
Browse files Browse the repository at this point in the history
  • Loading branch information
suhasHere committed May 31, 2024
1 parent 02a86c7 commit 791acef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
9 changes: 5 additions & 4 deletions include/quicr/moq_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,18 @@ struct MoqAnnounce {
TrackNamespace track_namespace;
std::vector<MoqParameter> params;
friend bool operator>>(qtransport::StreamBuffer<uint8_t> &buffer, MoqAnnounce &msg);
friend qtransport::StreamBuffer<uint8_t>& operator<<(qtransport::StreamBuffer<uint8_t>& buffer,
const MoqAnnounce& msg);
private:
uint64_t num_params {0};
MoqParameter current_param{};
};

struct MoqAnnounceOk {
TrackNamespace track_namespace;
friend bool operator>>(qtransport::StreamBuffer<uint8_t> &buffer, MoqAnnounceOk &msg);
friend qtransport::StreamBuffer<uint8_t>& operator<<(qtransport::StreamBuffer<uint8_t>& buffer,
const MoqAnnounceOk& msg);
};

struct MoqAnnounceError {
Expand All @@ -197,10 +202,6 @@ struct MoqAnnounceCancel {
};


MessageBuffer& operator<<(MessageBuffer& buffer, const MoqAnnounce& msg);
MessageBuffer& operator>>(MessageBuffer &buffer, MoqAnnounce &msg);
qtransport::StreamBuffer<uint8_t>& operator<<(qtransport::StreamBuffer<uint8_t>& buffer, const MoqAnnounce& msg);
bool operator>>(qtransport::StreamBuffer<uint8_t> &buffer, MoqAnnounce &msg);
MessageBuffer& operator<<(MessageBuffer& buffer, const MoqAnnounceOk& msg);
MessageBuffer& operator>>(MessageBuffer &buffer, MoqAnnounceOk &msg);
MessageBuffer& operator<<(MessageBuffer& buffer, const MoqAnnounceError& msg);
Expand Down
47 changes: 16 additions & 31 deletions src/moq_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,44 +285,29 @@ bool operator>>(qtransport::StreamBuffer<uint8_t> &buffer,
return true;
}

MessageBuffer&operator<<(MessageBuffer &buffer, const MoqAnnounce &msg) {
buffer << static_cast<uint8_t>(MESSAGE_TYPE_ANNOUNCE);
buffer << msg.track_namespace;
// TODO(Suhas): Fix this once we have params
buffer << uintVar_t{0};
return buffer;
}


MessageBuffer& operator>>(MessageBuffer &buffer, MoqAnnounce &msg) {
buffer >> msg.track_namespace;
uintVar_t num_params {0};
buffer >> num_params;
auto track_params = std::vector<MoqParameter>{};
while(static_cast<uint64_t>(num_params) > 0) {
auto param = MoqParameter{};
buffer >> param.param_type;
buffer >> param.param_length;
buffer >> param.param_value;
track_params.push_back(std::move(param));
num_params = num_params - 1;
}
qtransport::StreamBuffer<uint8_t>& operator<<(qtransport::StreamBuffer<uint8_t>& buffer,
const MoqAnnounceOk& msg){
buffer.push(qtransport::to_uintV(static_cast<uint64_t>(MESSAGE_TYPE_ANNOUNCE_OK)));
buffer.push_lv(msg.track_namespace);
return buffer;
}

bool operator>>(qtransport::StreamBuffer<uint8_t> &buffer,
MoqAnnounceOk &msg) {

MessageBuffer &
operator<<(MessageBuffer &buffer, const MoqAnnounceOk &msg) {
buffer << static_cast<uint8_t>(MESSAGE_TYPE_ANNOUNCE_OK);
buffer << msg.track_namespace;
return buffer;
// read namespace
if (msg.track_namespace.empty())
{
const auto val = buffer.decode_bytes();
if (!val) {
return false;
}
msg.track_namespace = *val;
}
return true;
}

MessageBuffer &
operator>>(MessageBuffer &buffer, MoqAnnounceOk &msg) {
buffer >> msg.track_namespace;
return buffer;
}

MessageBuffer &
operator<<(MessageBuffer &buffer, const MoqAnnounceError &msg) {
Expand Down
17 changes: 17 additions & 0 deletions test/moq_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ const quicr::bytes TRACK_NAMESPACE_CONF = from_ascii("moqt://conf.example.com/co
const quicr::bytes TRACK_NAME_ALICE_VIDEO = from_ascii("alice/video");
const uintVar_t TRACK_ALIAS_ALICE_VIDEO = 0xA11CE;

TEST_CASE("AnnounceOk Message encode/decode")
{
qtransport::StreamBuffer<uint8_t> buffer;

auto announce_ok = MoqAnnounceOk {};
announce_ok.track_namespace = TRACK_NAMESPACE_CONF;

buffer << announce_ok;

auto message_type = buffer.decode_uintV();
CHECK_EQ(*message_type, static_cast<uint64_t>(MESSAGE_TYPE_ANNOUNCE_OK));

MoqAnnounceOk announce_ok_out;
buffer >> announce_ok_out;
CHECK_EQ(TRACK_NAMESPACE_CONF, announce_ok_out.track_namespace);
}

TEST_CASE("Announce Message encode/decode")
{
qtransport::StreamBuffer<uint8_t> buffer;
Expand Down

0 comments on commit 791acef

Please sign in to comment.