Skip to content

feat: Embeddable APIs as "embeddable pipeline"#200

Draft
tmathern wants to merge 27 commits intomainfrom
mathern/embeddable-state
Draft

feat: Embeddable APIs as "embeddable pipeline"#200
tmathern wants to merge 27 commits intomainfrom
mathern/embeddable-state

Conversation

@tmathern
Copy link
Copy Markdown
Collaborator

@tmathern tmathern commented Apr 6, 2026

This PR introduces wrappers for the embeddable APIs which rely somewhat on state machine to attempt simplifying the use of the embeddable APIs.

The state of the pipeline advances based on the functions called, so it is easy to "remember" (or find out) where in the embedding process we are.

Usage example for a BMFF file:

// Create the "right" pipeline type, based on the existing builder and hash type that will be used
// (Relies on the new Builder API that tells which hash type will be used
// pipeline type here is generics, as the different pipelines inherit from a base class
auto pipeline = c2pa::EmbeddablePipeline::create(make_builder(), "video/mp4");
auto source_asset = c2pa_test::get_fixture_path("video1.mp4");

// EXPECT_EQ(pipeline->hash_type(), c2pa::HashType::Bmff);
// EXPECT_EQ(pipeline->current_state(), PipelineState::init);

pipeline->create_placeholder();
// EXPECT_EQ(pipeline->current_state(), PipelineState::placeholder_created);

// hash
std::ifstream asset_stream(source_asset, std::ios::binary);
pipeline->hash_from_stream(asset_stream);
 asset_stream.close();
// EXPECT_EQ(pipeline->current_state(), PipelineState::hashed);

// Return signed bytes
auto& manifest = pipeline->sign();

Or a JPEG with data hash:

auto pipeline = c2pa::EmbeddablePipeline::create(make_builder(), "image/jpeg");
auto source_asset = c2pa_test::get_fixture_path("A.jpg");

// EXPECT_EQ(pipeline->hash_type(), c2pa::HashType::Data);
// EXPECT_EQ(pipeline->current_state(), PipelineState::init);

auto& placeholder = pipeline->create_placeholder();
// EXPECT_EQ(pipeline->current_state(), PipelineState::placeholder_created);
size_t placeholder_size = placeholder.size();

uint64_t embed_offset = 20;
pipeline->set_exclusions({{embed_offset, placeholder_size}});
// EXPECT_EQ(pipeline->current_state(), PipelineState::exclusions_configured);

std::ifstream asset_stream(source_asset, std::ios::binary);
pipeline->hash_from_stream(asset_stream);
asset_stream.close();
// EXPECT_EQ(pipeline->current_state(), PipelineState::hashed);

auto& manifest = pipeline->sign();
// EXPECT_EQ(pipeline->current_state(), PipelineState::pipeline_signed);

@tmathern tmathern marked this pull request as draft April 6, 2026 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant