Add args field to mjResource for decoder and encoder arguments.

Add an optional `const char* args` field to `mjResource` to allow passing
resource arguments/hints (such as requested channel count or encoding options)
to resource decoders and encoders.

PiperOrigin-RevId: 959774058
Change-Id: Icc41a2bb3895fef24f98c5fa9a77cdad092a6bc7
This commit is contained in:
Sam Haves
2026-08-05 11:30:42 -07:00
committed by Copybara-Service
parent 83e621d771
commit 596b6f433d
5 changed files with 74 additions and 0 deletions
+24
View File
@@ -130,5 +130,29 @@ TEST_F(EncoderPluginTest, EncodeModel) {
mj_deleteSpec(spec);
}
TEST_F(EncoderPluginTest, EncodeWithResourceArgs) {
mjSpec* spec = mj_makeSpec();
mjModel* model = mj_compile(spec, nullptr);
ASSERT_THAT(model, testing::NotNull());
const mjpEncoder* found = mjp_findEncoder("output.fakeformat", nullptr);
ASSERT_THAT(found, testing::NotNull());
mjResource resource = {};
resource.name = const_cast<char*>("output.fakeformat");
resource.args = "format=binary&compression=9";
int result = found->encode(spec, model, nullptr, &resource);
EXPECT_GT(result, 0);
auto* output = static_cast<FakeEncoderOutput*>(resource.data);
ASSERT_THAT(output, testing::NotNull());
EXPECT_STREQ(resource.args, "format=binary&compression=9");
found->close_resource(&resource);
mj_deleteModel(model);
mj_deleteSpec(spec);
}
} // namespace
} // namespace mujoco