/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/

pub mod matroska;
pub mod mpeg4;

use crate::{
    ContainerFormat,
    muxers::{
        matroska::{MatroskaFragmentMuxer, WebmFragmentMuxer},
        mpeg4::Mpeg4FragmentMuxer,
    },
};
use anyhow::Result;
use std::io::Write;
use winter_matroska::Segment;

pub trait FragmentMuxer {
    fn write_fragment(out: &mut dyn Write, segment: Segment) -> Result<()>;
}

pub fn write_fragment(
    container: ContainerFormat,
    out: &mut dyn Write,
    segment: Segment,
) -> Result<()> {
    match container {
        ContainerFormat::Matroska => MatroskaFragmentMuxer::write_fragment(out, segment),
        ContainerFormat::Webm => WebmFragmentMuxer::write_fragment(out, segment),
        ContainerFormat::Mpeg4 => Mpeg4FragmentMuxer::write_fragment(out, segment),
        _ => unimplemented!(),
    }
}
