diff --git a/cpp/obs/src/moq-output.cpp b/cpp/obs/src/moq-output.cpp index 266b9f8a595..fd941e876c0 100644 --- a/cpp/obs/src/moq-output.cpp +++ b/cpp/obs/src/moq-output.cpp @@ -894,9 +894,9 @@ void MoQOutput::VideoInit(obs_encoder_t *encoder) // with inline parameter sets, which is what OBS hands us. moq::VideoInit config{}; if (strcmp(codec, "h264") == 0) { - config.format = moq::VideoFormat::kAvc3; + config.format = moq::VideoFormat::kH264; } else if (strcmp(codec, "hevc") == 0) { - config.format = moq::VideoFormat::kHev1; + config.format = moq::VideoFormat::kH265; } else if (strcmp(codec, "av1") == 0) { config.format = moq::VideoFormat::kAv01; } else { diff --git a/cpp/obs/test/moq-source-test.cpp b/cpp/obs/test/moq-source-test.cpp index ce170a70c4b..0a7b48773e6 100644 --- a/cpp/obs/test/moq-source-test.cpp +++ b/cpp/obs/test/moq-source-test.cpp @@ -591,7 +591,7 @@ class Publisher { broadcast = route->broadcast(); if (video) { moq::VideoInit init{}; - init.format = moq::VideoFormat::kAvc3; + init.format = moq::VideoFormat::kH264; init.data = TestH264Init(); this->video = TestOk(moq::MediaTrackProducer::video(broadcast, moq::MediaTarget::kNamed{}, init), @@ -953,7 +953,7 @@ int main() CHECK(publisher.WriteUntil([] { return g_output_frames > 0; })); FreezeCatalog(ctx, publisher); moq::VideoInit init{}; - init.format = moq::VideoFormat::kAvc3; + init.format = moq::VideoFormat::kH264; init.data = TestH264Init(); auto replacement = TestOk( moq::MediaTrackProducer::video(publisher.broadcast, @@ -1378,7 +1378,7 @@ int main() CHECK(publisher.WriteUntil([] { return g_output_frames > 0; })); FreezeCatalog(ctx, publisher); moq::VideoInit init{}; - init.format = moq::VideoFormat::kAvc3; + init.format = moq::VideoFormat::kH264; init.data = TestH264Init(); auto replacement = TestOk( moq::MediaTrackProducer::video(publisher.broadcast, @@ -1407,7 +1407,7 @@ int main() FreezeCatalog(ctx, publisher); g_candidate_decode = failure; moq::VideoInit init{}; - init.format = moq::VideoFormat::kAvc3; + init.format = moq::VideoFormat::kH264; init.data = TestH264Init(); auto replacement = TestOk( moq::MediaTrackProducer::video(publisher.broadcast, @@ -1643,7 +1643,7 @@ int main() CHECK(publisher.WriteUntil([] { return g_output_frames > 0; })); g_find_decoder_ok = false; moq::VideoInit init{}; - init.format = moq::VideoFormat::kAvc3; + init.format = moq::VideoFormat::kH264; init.data = TestH264Init(); auto replacement = TestOk( moq::MediaTrackProducer::video(publisher.broadcast, diff --git a/demo/carla/sim/moq_carla_sim/bridge.py b/demo/carla/sim/moq_carla_sim/bridge.py index b49411c490d..463e7f44f6f 100644 --- a/demo/carla/sim/moq_carla_sim/bridge.py +++ b/demo/carla/sim/moq_carla_sim/bridge.py @@ -349,7 +349,7 @@ def configure(self, config: Config) -> None: self._tracks[config.rendition] = moq.media.TrackProducer.video( self._broadcast, moq.media.VideoInit( - format=moq.media.VideoFormat.AVC3, + format=moq.media.VideoFormat.H264, data=config.init, hint=moq.media.VideoHint( coded=moq.media.Dimensions(width=rendition.width, height=rendition.height), diff --git a/demo/carla/sim/tests/conftest.py b/demo/carla/sim/tests/conftest.py index 4bc450ba493..6d6427cfc10 100644 --- a/demo/carla/sim/tests/conftest.py +++ b/demo/carla/sim/tests/conftest.py @@ -75,7 +75,7 @@ def now(self) -> SimpleNamespace: moq_media.CatalogProducer = CatalogProducer -moq_media.VideoFormat = SimpleNamespace(AVC3="avc3") +moq_media.VideoFormat = SimpleNamespace(H264="h264") moq_media.VideoInit = lambda **kwargs: SimpleNamespace(**kwargs) moq_media.VideoHint = lambda **kwargs: SimpleNamespace(**kwargs) moq_media.Dimensions = lambda **kwargs: SimpleNamespace(**kwargs) diff --git a/demo/carla/sim/tests/test_bridge.py b/demo/carla/sim/tests/test_bridge.py index 1a60d4dd17c..84b611b51a2 100644 --- a/demo/carla/sim/tests/test_bridge.py +++ b/demo/carla/sim/tests/test_bridge.py @@ -141,7 +141,7 @@ def __init__(self) -> None: self.tracks: dict[str, FakeTrack] = {} def video(self, init, target) -> FakeTrack: - assert init.format == "avc3" + assert init.format == "h264" self.tracks[target.name] = FakeTrack(init.data, target.name, init.hint) return self.tracks[target.name] diff --git a/demo/pub/justfile b/demo/pub/justfile index 94a7fcd312d..251a5716792 100644 --- a/demo/pub/justfile +++ b/demo/pub/justfile @@ -94,7 +94,7 @@ h264 name url="http://localhost:4443" *args: -c:v copy -an \ -bsf:v h264_mp4toannexb \ -f h264 \ - - | cargo run --bin moq -- "${@:3}" --connect "{{ url }}" --broadcast "{{ name }}.hang" import avc3 + - | cargo run --bin moq -- "${@:3}" --connect "{{ url }}" --broadcast "{{ name }}.hang" import h264 # Publish a video using ffmpeg directly from moq to the localhost. [positional-arguments] diff --git a/doc/bin/cli.md b/doc/bin/cli.md index a84872d3197..cf499c095ff 100644 --- a/doc/bin/cli.md +++ b/doc/bin/cli.md @@ -23,7 +23,7 @@ install. It needs an ARMv7 CPU, so not a Pi 1, Zero, or Zero W. | Verb | Endpoint | | | --- | --- | --- | -| `import` | `ts`, `fmp4`, `flv`, `avc3` | Read a container from stdin (usually FFmpeg). | +| `import` | `ts`, `fmp4`, `flv`, `h264` | Read a container from stdin (usually FFmpeg). | | `import` | `capture` | Capture a camera, display, window, or app plus a microphone, and encode natively. | | `import` | `hls ` | Follow a remote live HLS playlist. | | `import` | `rtmp`, `srt`, `webrtc` | Accept pushes (`--listen`) or pull from a remote (`--connect`). | diff --git a/go/wrapper/example_test.go b/go/wrapper/example_test.go index 4a910e854e3..0d50b00d1df 100644 --- a/go/wrapper/example_test.go +++ b/go/wrapper/example_test.go @@ -140,7 +140,7 @@ func Example_mediaVideoHint() { } defer broadcast.Close() - media, err := moqmedia.NewVideoTrackProducer(broadcast, moqmedia.Named{}, moqmedia.VideoInit{Format: moqmedia.VideoFormatAvc3, Data: nil, Hint: &moqmedia.VideoHint{}}) + media, err := moqmedia.NewVideoTrackProducer(broadcast, moqmedia.Named{}, moqmedia.VideoInit{Format: moqmedia.VideoFormatH264, Data: nil, Hint: &moqmedia.VideoHint{}}) if err != nil { log.Fatal(err) } diff --git a/go/wrapper/media/media.go b/go/wrapper/media/media.go index 234be1c54d6..4d7205db6e6 100644 --- a/go/wrapper/media/media.go +++ b/go/wrapper/media/media.go @@ -362,16 +362,16 @@ const ( // VideoFormat values: a single video codec an importer can parse. The two H.26x pairs // differ by framing, not codec: Avc1/Hvc1 are length-prefixed with an out-of-band config -// record, Avc3/Hev1 are Annex-B with the parameter sets inline. +// record, H264/H265 are a raw Annex B elementary stream with the parameter sets inline. const ( // VideoFormatAvc1 is H.264 with length-prefixed NALUs and an out-of-band avcC. VideoFormatAvc1 = ffi.MoqVideoFormatAvc1 - // VideoFormatAvc3 is H.264 in Annex-B with inline SPS/PPS. - VideoFormatAvc3 = ffi.MoqVideoFormatAvc3 + // VideoFormatH264 is H.264 as a raw Annex B elementary stream with inline SPS/PPS. + VideoFormatH264 = ffi.MoqVideoFormatH264 // VideoFormatHvc1 is H.265 with length-prefixed NALUs and an out-of-band hvcC. VideoFormatHvc1 = ffi.MoqVideoFormatHvc1 - // VideoFormatHev1 is H.265 in Annex-B with inline parameter sets. - VideoFormatHev1 = ffi.MoqVideoFormatHev1 + // VideoFormatH265 is H.265 as a raw Annex B elementary stream with inline parameter sets. + VideoFormatH265 = ffi.MoqVideoFormatH265 // VideoFormatAv01 is AV1. VideoFormatAv01 = ffi.MoqVideoFormatAv01 // VideoFormatVp8 is VP8. diff --git a/py/moq-rs/tests/test_local.py b/py/moq-rs/tests/test_local.py index 44a31b845c2..f51e5663818 100644 --- a/py/moq-rs/tests/test_local.py +++ b/py/moq-rs/tests/test_local.py @@ -282,7 +282,7 @@ async def test_video_publish_consume(): route = origin.route("video-test") broadcast = route.broadcast media = moq.media.TrackProducer.video( - broadcast, moq.media.VideoInit(format=moq.media.VideoFormat.AVC3, data=h264_init()) + broadcast, moq.media.VideoInit(format=moq.media.VideoFormat.H264, data=h264_init()) ) consumer = origin.consume() @@ -321,7 +321,7 @@ async def test_video_publish_named_track(): broadcast = route.broadcast media = moq.media.TrackProducer.video( broadcast, - moq.media.VideoInit(format=moq.media.VideoFormat.AVC3, data=h264_init()), + moq.media.VideoInit(format=moq.media.VideoFormat.H264, data=h264_init()), target=moq.media.Named("hd"), ) assert media.demand().name == "hd" diff --git a/quest/m2/video-format-names.md b/quest/m2/video-format-names.md deleted file mode 100644 index 21f4e17431c..00000000000 --- a/quest/m2/video-format-names.md +++ /dev/null @@ -1,32 +0,0 @@ -# [S] The Annex B import formats are named h264 and h265 - -## Goal - -The import format for a raw Annex B elementary stream is `h264` / `h265` -(`hevc` accepted) everywhere it is named: `moq_mux::import::VideoFormat`, -the CLI's `--format`, moq-ffi, moq-c, and the Go wrapper. `avc1` / `hvc1` -stay as the length-prefixed formats with a config record, and `avc3` / -`hev1` are no longer import format names. - -## Plan - -Decided 2026-11-17 (maintainer, `/quest-import` of -[moq-dev/moq#9011](https://github.com/moq-dev/moq/issues/9011)): -✅ rename (rejected: keep the names and fix only the doc comments). -`avc3`/`hev1` say where parameter sets live, not how NAL units are framed: -inside a frame, NAL units are still split by start codes or length -prefixes. Naming the Annex B input after them taught the conflation that -became the native decoder bug fixed in -[moq-dev/moq#9066](https://github.com/moq-dev/moq/pull/9066). The names follow ffmpeg's raw -`h264` / `hevc` formats; `h264` already aliases `avc3`. - -Where the names live: `rs/moq-mux/src/import/format.rs` (the enum, its doc -comment, and `FromStr`), `rs/moq-ffi/src/media.rs`, `rs/moq-c/src/api.rs`, -`go/wrapper/media/media.go`, `rs/moq-cli/src/args.rs`, and -`doc/bin/cli.md`. Mirror the same names in every binding, and put the -migration (`avc3` → `h264`, `hev1` → `h265`) in the PR's Impact section. -No alias for the old names. - -The catalog's codec strings are not import formats and keep `avc3`/`hev1`. - -Public API: breaking, as above. Wire: none. diff --git a/quest/m5/carla-bridge.md b/quest/m5/carla-bridge.md index 367791e8058..e5b3e3028da 100644 --- a/quest/m5/carla-bridge.md +++ b/quest/m5/carla-bridge.md @@ -46,8 +46,8 @@ probe opens the camera's own backend with a CPU picture. `VERSION`, so a mismatched bridge and worker fail at hello naming both versions; test the refusal both ways. Open, if mixed versions must run: negotiate at hello and keep the v1 layout for H.264. - - `sim/moq_carla_sim/bridge.py` publishes `AVC3` or `HEV1` instead of - hardcoding `AVC3`. + - `sim/moq_carla_sim/bridge.py` publishes `H264` or `H265` instead of + hardcoding `H264`. - Scaling: one render still feeds the 426x240 and 1280x720 renditions, scaled on the GPU. GPU-side copies are allowed; a CPU round trip is not. - Test: the stand-in (`tests/standin/mod.rs`) stops requiring vendor diff --git a/rs/libmoq/src/api.rs b/rs/libmoq/src/api.rs index d9c6b9b1908..5139f6dc02e 100644 --- a/rs/libmoq/src/api.rs +++ b/rs/libmoq/src/api.rs @@ -118,21 +118,21 @@ pub enum moq_audio_format { /// A single video codec [moq_publish_video] can parse. /// -/// H.264 and H.265 appear twice each because the framing differs, not just the -/// codec: AVC1/HVC1 are length-prefixed with an out-of-band config record, -/// while AVC3/HEV1 are Annex-B with the parameter sets inline. +/// H.264 and H.265 appear twice each because the input framing differs: +/// AVC1/HVC1 are length-prefixed with an out-of-band config record, while +/// H264/H265 are a raw Annex B elementary stream with the parameter sets inline. #[repr(C)] #[expect(non_camel_case_types, reason = "C ABI type names match moq.h")] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum moq_video_format { /// H.264, length-prefixed NALUs with an out-of-band avcC. MOQ_VIDEO_FORMAT_AVC1 = 0, - /// H.264, Annex-B with inline SPS/PPS. - MOQ_VIDEO_FORMAT_AVC3 = 1, + /// H.264, a raw Annex B elementary stream with inline SPS/PPS. + MOQ_VIDEO_FORMAT_H264 = 1, /// H.265, length-prefixed NALUs with an out-of-band hvcC. MOQ_VIDEO_FORMAT_HVC1 = 2, - /// H.265, Annex-B with inline parameter sets. - MOQ_VIDEO_FORMAT_HEV1 = 3, + /// H.265, a raw Annex B elementary stream with inline parameter sets. + MOQ_VIDEO_FORMAT_H265 = 3, /// AV1. MOQ_VIDEO_FORMAT_AV01 = 4, /// VP8. @@ -377,9 +377,9 @@ fn video_format_from_u32(value: u32) -> Result VideoFormat::Avc1, - v if v == moq_video_format::MOQ_VIDEO_FORMAT_AVC3 as u32 => VideoFormat::Avc3, + v if v == moq_video_format::MOQ_VIDEO_FORMAT_H264 as u32 => VideoFormat::H264, v if v == moq_video_format::MOQ_VIDEO_FORMAT_HVC1 as u32 => VideoFormat::Hvc1, - v if v == moq_video_format::MOQ_VIDEO_FORMAT_HEV1 as u32 => VideoFormat::Hev1, + v if v == moq_video_format::MOQ_VIDEO_FORMAT_H265 as u32 => VideoFormat::H265, v if v == moq_video_format::MOQ_VIDEO_FORMAT_AV01 as u32 => VideoFormat::Av01, v if v == moq_video_format::MOQ_VIDEO_FORMAT_VP8 as u32 => VideoFormat::Vp8, v if v == moq_video_format::MOQ_VIDEO_FORMAT_VP9 as u32 => VideoFormat::Vp9, diff --git a/rs/libmoq/src/publish.rs b/rs/libmoq/src/publish.rs index 694cfc4018f..a941e8eae0e 100644 --- a/rs/libmoq/src/publish.rs +++ b/rs/libmoq/src/publish.rs @@ -516,7 +516,7 @@ impl Publish { .. } = self.broadcast(broadcast)?; let broadcast = broadcast.clone(); - let name = broadcast.unique_name(&format!(".{}", init.format)); + let name = broadcast.unique_name(init.format.track_suffix()); let request = broadcast.reserve_track(name)?; let track = import::Track::audio(request, catalog.reserve().with_interval(interval), init)?; @@ -538,7 +538,7 @@ impl Publish { .. } = self.broadcast(broadcast)?; let broadcast = broadcast.clone(); - let name = broadcast.unique_name(&format!(".{}", init.format)); + let name = broadcast.unique_name(init.format.track_suffix()); let request = broadcast.reserve_track(name)?; let priority = init.priority; diff --git a/rs/libmoq/src/test.rs b/rs/libmoq/src/test.rs index b5e386f3a35..afa84795bf8 100644 --- a/rs/libmoq/src/test.rs +++ b/rs/libmoq/src/test.rs @@ -889,7 +889,7 @@ fn publish_media_owns_its_rendition_before_the_first_keyframe() { // nothing until a keyframe lands. let media = id(publish_video( broadcast, - moq_video_format::MOQ_VIDEO_FORMAT_AVC3, + moq_video_format::MOQ_VIDEO_FORMAT_H264, &[], None, )); @@ -6312,7 +6312,7 @@ fn video_publish_consume() { let broadcast = publish_broadcast(origin, path); let init = h264_init(); - let format = moq_video_format::MOQ_VIDEO_FORMAT_AVC3; + let format = moq_video_format::MOQ_VIDEO_FORMAT_H264; let media = id(publish_video(broadcast, format, &init, None)); let consume = request_broadcast(origin, path); @@ -7337,7 +7337,7 @@ fn video_raw_decode() { // The init's SPS/PPS only seed catalog metadata; avc3 frames carry their own // inline parameter sets, so the decoder reads the true 320x240 from the wire. let init = h264_init(); - let format = moq_video_format::MOQ_VIDEO_FORMAT_AVC3; + let format = moq_video_format::MOQ_VIDEO_FORMAT_H264; let media = id(publish_video(broadcast, format, &init, None)); let consume = request_broadcast(origin, path); @@ -9273,7 +9273,7 @@ fn track_request_media_carries_hints() { let h264 = h264_init(); let video_config = moq_video_init { lower: 0, - format: moq_video_format::MOQ_VIDEO_FORMAT_AVC3 as u32, + format: moq_video_format::MOQ_VIDEO_FORMAT_H264 as u32, init: h264.as_ptr(), init_len: h264.len(), label: std::ptr::null(), @@ -9328,7 +9328,7 @@ fn invalid_hints_are_refused() { let video = |hint: moq_video_hint| { let config = moq_video_init { lower: 0, - format: moq_video_format::MOQ_VIDEO_FORMAT_AVC3 as u32, + format: moq_video_format::MOQ_VIDEO_FORMAT_H264 as u32, init: h264.as_ptr(), init_len: h264.len(), label: std::ptr::null(), @@ -9444,7 +9444,7 @@ fn preencoded_rungs_and_rate_control() { let broadcast = publish_broadcast(origin, b"preencoded-rungs"); let init = h264_init(); let config = |lower| moq_video_init { - format: moq_video_format::MOQ_VIDEO_FORMAT_AVC3 as u32, + format: moq_video_format::MOQ_VIDEO_FORMAT_H264 as u32, init: init.as_ptr(), init_len: init.len(), label: std::ptr::null(), diff --git a/rs/moq-cli/README.md b/rs/moq-cli/README.md index 86386b2466d..7b613552ef5 100644 --- a/rs/moq-cli/README.md +++ b/rs/moq-cli/README.md @@ -73,5 +73,5 @@ moq --listen '[::]:4443' --listen-tls-generate localhost --auth-public '**' --br ### Import formats -- `avc3` raw H.264 Annex-B from stdin +- `h264` raw H.264 Annex B elementary stream from stdin - `fmp4` fragmented MP4 from stdin diff --git a/rs/moq-cli/src/args.rs b/rs/moq-cli/src/args.rs index 5233f7f0da3..89e4f963558 100644 --- a/rs/moq-cli/src/args.rs +++ b/rs/moq-cli/src/args.rs @@ -843,8 +843,8 @@ impl Import { /// from stdin; the gateways bridge another protocol. #[derive(usage_rs::Subcommands, Clone)] pub enum ImportSource { - /// Raw H.264 Annex-B from stdin. - Avc3, + /// Raw H.264 Annex B elementary stream from stdin. + H264, /// Fragmented MP4 / CMAF from stdin. Fmp4(Fmp4Import), /// MPEG-TS from stdin. @@ -876,7 +876,7 @@ impl ImportSource { /// The stdin container format, when this source is one of the container formats. pub fn stdin_format(&self) -> Option { Some(match self { - Self::Avc3 => PublishFormat::Avc3, + Self::H264 => PublishFormat::H264, Self::Fmp4(args) => PublishFormat::Fmp4 { cmaf: args.cmaf }, Self::Ts(args) if args.passthrough => PublishFormat::TsPassthrough { pcr_pid: args.pcr_pid.map(|pid| pid.0), @@ -906,7 +906,7 @@ impl ImportSource { | Self::Archive(_) => Some("the gateway and archive imports build their own catalogs"), #[cfg(feature = "capture")] Self::Capture(_) => None, - Self::Avc3 | Self::Fmp4(_) | Self::Ts(_) | Self::Flv => None, + Self::H264 | Self::Fmp4(_) | Self::Ts(_) | Self::Flv => None, } } @@ -923,7 +923,7 @@ impl ImportSource { Self::Archive(_) => Some("`import archive` serves its recording until stopped"), #[cfg(feature = "capture")] Self::Capture(_) => Some("`import capture` has no clean end"), - Self::Avc3 + Self::H264 | Self::Fmp4(_) | Self::Ts(_) | Self::Flv @@ -1837,7 +1837,7 @@ mod tests { ["ts"].as_slice(), &["fmp4"], &["flv"], - &["avc3"], + &["h264"], &["ts", "--program", "1"], ] { import(flags, source).validate().unwrap(); diff --git a/rs/moq-cli/src/publish.rs b/rs/moq-cli/src/publish.rs index 88d42cb24c0..66489abec52 100644 --- a/rs/moq-cli/src/publish.rs +++ b/rs/moq-cli/src/publish.rs @@ -4,8 +4,8 @@ use moq_mux::container::{flv, fmp4, ts}; /// Container format read from stdin on the import (source) side. #[derive(Clone, Copy)] pub enum PublishFormat { - /// Raw AVC (H.264) Annex B elementary stream. - Avc3, + /// Raw H.264 Annex B elementary stream. + H264, /// Fragmented MP4 (CMAF), republished whole as CMAF when `cmaf`. Fmp4 { cmaf: bool }, /// MPEG-TS (transport stream), limited to one `program` of a multiplex when given. @@ -172,7 +172,7 @@ pub struct CaptureArgs { } enum PublishDecoder { - Avc3 { + H264 { split: Box, import: Box, }, @@ -196,7 +196,7 @@ impl PublishDecoder { /// [`ts::Republish::decode`]. fn decode_chunk(&mut self, chunk: &[u8]) -> anyhow::Result> { match self { - Self::Avc3 { split, import } => { + Self::H264 { split, import } => { let frames = split.decode(chunk, None)?; import.decode(frames)?; } @@ -215,19 +215,19 @@ impl PublishDecoder { match self { Self::Ts(d) => Some(d.stats()), Self::TsPrograms(d) => Some(d.stats()), - Self::Avc3 { .. } | Self::Fmp4(_) | Self::TsPassthrough(_) | Self::Flv(_) => None, + Self::H264 { .. } | Self::Fmp4(_) | Self::TsPassthrough(_) | Self::Flv(_) => None, } } /// Flush any buffered trailing frame and close the tracks at end of input. - /// The avc3 split holds the final access unit until the next start code, so + /// The H.264 split holds the final access unit until the next start code, so /// stdin EOF must flush it explicitly. fn finish(self) -> anyhow::Result { Ok(match self { - Self::Avc3 { mut split, mut import } => { + Self::H264 { mut split, mut import } => { let tail = split.flush(None)?; import.decode(tail)?; - FinishedDecoder::Avc3(Box::new(import.finish()?)) + FinishedDecoder::H264(Box::new(import.finish()?)) } Self::Fmp4(d) => FinishedDecoder::Fmp4(Box::new(d.finish()?)), Self::Ts(d) => FinishedDecoder::Ts(Box::new(d.finish()?)), @@ -241,7 +241,7 @@ impl PublishDecoder { /// real cause rather than `Error::Dropped`. Consumes the decoder. fn abort(self, err: moq_net::Error) { match self { - Self::Avc3 { import, .. } => import.abort(err), + Self::H264 { import, .. } => import.abort(err), Self::Fmp4(d) => d.abort(err), Self::Ts(d) => d.abort(err), Self::TsPrograms(d) => d.abort(err), @@ -253,7 +253,7 @@ impl PublishDecoder { /// A [`PublishDecoder`] whose tracks finished, holding them so they stay servable. enum FinishedDecoder { - Avc3(Box>), + H264(Box>), Fmp4(Box), Ts(Box), TsPrograms(Box), @@ -276,13 +276,13 @@ impl FinishedDecoder { match self { Self::Ts(d) => Some(d.stats()), Self::TsPrograms(d) => Some(d.stats()), - Self::Avc3(_) | Self::Fmp4(_) | Self::TsPassthrough(_) | Self::Flv(_) => None, + Self::H264(_) | Self::Fmp4(_) | Self::TsPassthrough(_) | Self::Flv(_) => None, } } fn abort(self, err: moq_net::Error) { match self { - Self::Avc3(import) => import.abort(err), + Self::H264(import) => import.abort(err), Self::Fmp4(d) => d.abort(err), Self::Ts(d) => d.abort(err), Self::TsPrograms(d) => d.abort(err), @@ -444,11 +444,11 @@ impl Publish { } let catalog = moq_mux::catalog::Producer::new(&mut broadcast, config)?; let decoder = match format { - PublishFormat::Avc3 => { + PublishFormat::H264 => { let track = broadcast.unique_track(".avc3", catalog.track_info(hang::catalog::PRIORITY.video))?; let import = moq_mux::codec::h264::Import::new(track, catalog.reserve(), Default::default())?; let split = Box::new(moq_mux::codec::h264::Split::new()); - PublishDecoder::Avc3 { + PublishDecoder::H264 { split, import: Box::new(import), } @@ -2735,7 +2735,7 @@ pub(crate) mod tests { (PublishFormat::Ts { program: None }, Vec::new()), (PublishFormat::Ts { program: Some(1) }, tables), (PublishFormat::Flv, flv_header), - (PublishFormat::Avc3, aud), + (PublishFormat::H264, aud), ] { let origin = moq_tokio::origin::spawn(); let mut announced = origin.consume().announced(); diff --git a/rs/moq-ffi/src/media.rs b/rs/moq-ffi/src/media.rs index 084c4d840e6..342b5aab51d 100644 --- a/rs/moq-ffi/src/media.rs +++ b/rs/moq-ffi/src/media.rs @@ -328,19 +328,19 @@ pub enum MoqAudioFormat { /// A single video codec an importer can parse. /// -/// H.264 and H.265 appear twice each because the framing differs, not just the codec: `Avc1`/`Hvc1` -/// are length-prefixed with an out-of-band config record, while `Avc3`/`Hev1` are Annex-B with the -/// parameter sets inline. +/// H.264 and H.265 appear twice each because the input framing differs: `Avc1`/`Hvc1` are +/// length-prefixed with an out-of-band config record, while `H264`/`H265` are a raw Annex B +/// elementary stream with the parameter sets inline. #[derive(Clone, Copy, Debug, PartialEq, Eq, uniffi::Enum)] pub enum MoqVideoFormat { /// H.264, length-prefixed NALUs with an out-of-band avcC. Avc1, - /// H.264, Annex-B with inline SPS/PPS. - Avc3, + /// H.264, a raw Annex B elementary stream with inline SPS/PPS. + H264, /// H.265, length-prefixed NALUs with an out-of-band hvcC. Hvc1, - /// H.265, Annex-B with inline parameter sets. - Hev1, + /// H.265, a raw Annex B elementary stream with inline parameter sets. + H265, /// AV1. Av01, /// VP8. @@ -570,9 +570,9 @@ impl From for moq_mux::import::VideoFormat { fn from(format: MoqVideoFormat) -> Self { match format { MoqVideoFormat::Avc1 => Self::Avc1, - MoqVideoFormat::Avc3 => Self::Avc3, + MoqVideoFormat::H264 => Self::H264, MoqVideoFormat::Hvc1 => Self::Hvc1, - MoqVideoFormat::Hev1 => Self::Hev1, + MoqVideoFormat::H265 => Self::H265, MoqVideoFormat::Av01 => Self::Av01, MoqVideoFormat::Vp8 => Self::Vp8, MoqVideoFormat::Vp9 => Self::Vp9, @@ -803,11 +803,11 @@ impl MoqMediaTarget { fn import( self, broadcast: &moq_net::broadcast::Producer, - format: impl std::fmt::Display, + suffix: &str, import: impl FnOnce(moq_net::track::Request) -> Result, ) -> Result { match self { - Self::Named { name } => import(reserve_track(broadcast, name, &format)?), + Self::Named { name } => import(reserve_track(broadcast, name, suffix)?), Self::Requested { request } => request.answer(import), } } @@ -1030,7 +1030,7 @@ impl MoqMediaTrackProducer { let _guard = crate::ffi::enter(); broadcast.with_state(|state| { let init: moq_mux::import::AudioInit = init.into(); - target.import(&state.broadcast, init.format, |request| { + target.import(&state.broadcast, init.format.track_suffix(), |request| { let import = moq_mux::import::Track::audio(request, state.catalog.reserve(), init).map_err(|err| { MoqError::Codec { reason: format!("init failed: {err}"), @@ -1058,7 +1058,7 @@ impl MoqMediaTrackProducer { let init = init.resolve()?; broadcast.with_state(|state| { let priority = init.priority; - target.import(&state.broadcast, init.format, |request| { + target.import(&state.broadcast, init.format.track_suffix(), |request| { let import = moq_mux::import::Track::video(request, state.catalog.reserve(), init).map_err(|err| { MoqError::Codec { reason: format!("init failed: {err}"), @@ -1099,7 +1099,7 @@ impl MoqMediaContainerProducer { impl MoqMediaTrackStreamProducer { /// Import a video byte stream, inferring frame boundaries. /// - /// Only the self-delimiting formats work here (`Avc3`, `Hev1`, `Av01`); the rest need length + /// Only the self-delimiting formats work here (`H264`, `H265`, `Av01`); the rest need length /// prefixes or an out-of-band config record. There is no audio counterpart for the same reason. #[uniffi::constructor] pub fn video( @@ -1111,7 +1111,7 @@ impl MoqMediaTrackStreamProducer { let init = init.resolve()?; broadcast.with_state(|state| { let priority = init.priority; - target.import(&state.broadcast, init.format, |request| { + target.import(&state.broadcast, init.format.track_suffix(), |request| { let import = moq_mux::import::TrackStream::video(request, state.catalog.reserve(), init).map_err(|err| { MoqError::Codec { @@ -1450,13 +1450,13 @@ impl MoqMediaTrackStreamProducer { } } -/// Reserve the named track, or a unique one named after the format. +/// Reserve the named track, or a unique one ending in the format's `suffix`. fn reserve_track( broadcast: &moq_net::broadcast::Producer, track: Option, - format: &impl std::fmt::Display, + suffix: &str, ) -> Result { - let name = track.unwrap_or_else(|| broadcast.unique_name(&format!(".{format}"))); + let name = track.unwrap_or_else(|| broadcast.unique_name(suffix)); broadcast.reserve_track(name).map_err(|err| MoqError::Codec { reason: format!("init failed: {err}"), }) diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index 5f104a28eea..47c4442a634 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -2254,7 +2254,7 @@ async fn typed_abort_unwanted_keeps_a_late_reader() { let stream = MoqMediaTrackStreamProducer::video( &broadcast, named("stream"), - video_init(MoqVideoFormat::Avc3, Vec::new()), + video_init(MoqVideoFormat::H264, Vec::new()), ) .unwrap(); typed_abort_unwanted( @@ -3294,7 +3294,7 @@ async fn video_publish_named_track() { .await .unwrap(); - let init = || video_init(MoqVideoFormat::Avc3, h264_init()); + let init = || video_init(MoqVideoFormat::H264, h264_init()); let hd = MoqMediaTrackProducer::video( &broadcast, MoqMediaTarget::Named { @@ -3351,13 +3351,13 @@ async fn video_rung_sits_below_its_lower_and_disables() { name: Some(name.into()), }; let low = - MoqMediaTrackProducer::video(&broadcast, named("low"), video_init(MoqVideoFormat::Avc3, h264_init())).unwrap(); + MoqMediaTrackProducer::video(&broadcast, named("low"), video_init(MoqVideoFormat::H264, h264_init())).unwrap(); let high = MoqMediaTrackProducer::video( &broadcast, named("high"), MoqVideoInit { lower: Some(MoqMediaProducer::Track { producer: low.clone() }), - ..video_init(MoqVideoFormat::Avc3, h264_init()) + ..video_init(MoqVideoFormat::H264, h264_init()) }, ) .unwrap(); @@ -3401,14 +3401,14 @@ async fn stream_rung_is_funded_after_its_lower_and_resumes_at_a_keyframe() { name: Some(name.into()), }; let low = - MoqMediaTrackStreamProducer::video(&broadcast, named("low"), video_init(MoqVideoFormat::Avc3, h264_init())) + MoqMediaTrackStreamProducer::video(&broadcast, named("low"), video_init(MoqVideoFormat::H264, h264_init())) .unwrap(); let high = MoqMediaTrackStreamProducer::video( &broadcast, named("high"), MoqVideoInit { lower: Some(MoqMediaProducer::Stream { producer: low.clone() }), - ..video_init(MoqVideoFormat::Avc3, h264_init()) + ..video_init(MoqVideoFormat::H264, h264_init()) }, ) .unwrap(); @@ -3489,7 +3489,7 @@ async fn video_track_demand_follows_a_new_level() { MoqMediaTarget::Named { name: Some("hd".into()), }, - video_init(MoqVideoFormat::Avc3, h264_init()), + video_init(MoqVideoFormat::H264, h264_init()), ) .unwrap(); let keyframe = |level: u8| { @@ -3525,7 +3525,7 @@ async fn track_stream_producer_publishes_its_last_access_unit() { MoqMediaTarget::Named { name: Some("video".into()), }, - video_init(MoqVideoFormat::Avc3, Vec::new()), + video_init(MoqVideoFormat::H264, Vec::new()), ) .unwrap(); let track = consumer.subscribe_track("video".into(), None).await.unwrap(); @@ -3573,7 +3573,7 @@ async fn requested_track_keeps_its_name() { MoqMediaTarget::Requested { request: request.clone(), }, - video_init(MoqVideoFormat::Avc3, h264_init()), + video_init(MoqVideoFormat::H264, h264_init()), ) .unwrap(); assert_eq!(media.demand().unwrap().name(), "requested"); @@ -4448,7 +4448,7 @@ async fn video_publish_consume() { let media = MoqMediaTrackProducer::video( &broadcast, MoqMediaTarget::Named { name: None }, - video_init(MoqVideoFormat::Avc3, init), + video_init(MoqVideoFormat::H264, init), ) .unwrap(); @@ -5475,7 +5475,7 @@ async fn a_failed_finish_ends_the_track_with_its_cause() { MoqMediaTarget::Named { name: Some("video".into()), }, - video_init(MoqVideoFormat::Avc3, h264_init()), + video_init(MoqVideoFormat::H264, h264_init()), ) .unwrap(); let reader = consumer.subscribe_track("video".into(), None).await.unwrap(); diff --git a/rs/moq-ffi/src/test/rung.rs b/rs/moq-ffi/src/test/rung.rs index c021c70a45f..cf9ae1ed7e6 100644 --- a/rs/moq-ffi/src/test/rung.rs +++ b/rs/moq-ffi/src/test/rung.rs @@ -81,7 +81,7 @@ async fn shaped_uplink_disables_and_resumes() { .first() .cloned() .map(|producer| MoqMediaProducer::Track { producer }), - ..video_init(MoqVideoFormat::Avc3, h264_init()) + ..video_init(MoqVideoFormat::H264, h264_init()) }, ) .unwrap(); diff --git a/rs/moq-gst/src/sink/pad.rs b/rs/moq-gst/src/sink/pad.rs index 45229505863..d8c08f43c58 100644 --- a/rs/moq-gst/src/sink/pad.rs +++ b/rs/moq-gst/src/sink/pad.rs @@ -549,7 +549,7 @@ impl Pad { &mut broadcast, reserved, requested, - import::VideoFormat::Avc3, + import::VideoFormat::H264, &[], container, )?; @@ -560,7 +560,7 @@ impl Pad { &mut broadcast, reserved, requested, - import::VideoFormat::Hev1, + import::VideoFormat::H265, &[], container, )?; @@ -722,7 +722,7 @@ impl Pad { init: &[u8], container: hang::catalog::Container, ) -> Result<(import::Track, String)> { - let name = Self::track_name(broadcast, requested, &format!(".{format}")); + let name = Self::track_name(broadcast, requested, format.track_suffix()); let request = broadcast .reserve_track(name.clone()) .with_context(|| format!("cannot reserve track {name}"))?; @@ -741,7 +741,7 @@ impl Pad { init: &[u8], container: hang::catalog::Container, ) -> Result<(import::Track, String)> { - let name = Self::track_name(broadcast, requested, &format!(".{format}")); + let name = Self::track_name(broadcast, requested, format.track_suffix()); let request = broadcast .reserve_track(name.clone()) .with_context(|| format!("cannot reserve track {name}"))?; diff --git a/rs/moq-mux/README.md b/rs/moq-mux/README.md index 2069b7bf545..fa646da537e 100644 --- a/rs/moq-mux/README.md +++ b/rs/moq-mux/README.md @@ -22,8 +22,8 @@ The crate splits along two axes: - `codec::*` parses each codec's configuration record and provides an importer that publishes a raw bitstream into a broadcast. -For format-string dispatch (e.g. `--format avc3`), use `import::Framed` or -`import::Stream`. For lower-level control, instantiate a codec/container +For format-string dispatch (e.g. `--format h264`), parse an `import::Format` and use +`import::Track`, `import::TrackStream`, or `import::Container`. For lower-level control, instantiate a codec/container importer directly. See the [API docs](https://docs.rs/moq-mux/) for the full module map. diff --git a/rs/moq-mux/src/fuzz.rs b/rs/moq-mux/src/fuzz.rs index 8afa67c07ec..721931a9799 100644 --- a/rs/moq-mux/src/fuzz.rs +++ b/rs/moq-mux/src/fuzz.rs @@ -149,7 +149,7 @@ pub fn cmaf(data: &[u8]) -> bool { } /// The codecs [`annexb`] splits, selected by the leading byte modulo their count. -const STREAMS: &[VideoFormat] = &[VideoFormat::Avc3, VideoFormat::Hev1, VideoFormat::Av01]; +const STREAMS: &[VideoFormat] = &[VideoFormat::H264, VideoFormat::H265, VideoFormat::Av01]; /// A raw byte stream of unknown frame boundaries: H.264 or H.265 Annex-B, or AV1 OBUs. /// diff --git a/rs/moq-mux/src/import/format.rs b/rs/moq-mux/src/import/format.rs index a0a0cedbc5a..4ac26501d07 100644 --- a/rs/moq-mux/src/import/format.rs +++ b/rs/moq-mux/src/import/format.rs @@ -25,20 +25,22 @@ pub enum AudioFormat { /// A single video codec an importer can parse. /// -/// H.264 and H.265 each appear twice because the framing differs, not just the codec: `avc1`/`hvc1` -/// are length-prefixed with an out-of-band config record, while `avc3`/`hev1` are Annex-B with the -/// parameter sets inline. +/// H.264 and H.265 each appear twice because the input framing differs: `avc1`/`hvc1` are +/// length-prefixed NAL units with an out-of-band config record, while `h264`/`h265` are a raw Annex B +/// elementary stream split on start codes, carrying its parameter sets inline. The raw names follow +/// ffmpeg's `h264`/`hevc` formats rather than `avc3`/`hev1`, which say where parameter sets live, not +/// how NAL units are framed. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum VideoFormat { /// H.264, length-prefixed NALUs with an out-of-band avcC. Avc1, - /// H.264, Annex-B with inline SPS/PPS. - Avc3, + /// H.264, a raw Annex B elementary stream with inline SPS/PPS. + H264, /// H.265, length-prefixed NALUs with an out-of-band hvcC. Hvc1, - /// H.265, Annex-B with inline parameter sets. - Hev1, + /// H.265, a raw Annex B elementary stream with inline parameter sets. + H265, /// AV1. Av01, /// VP8. @@ -127,9 +129,9 @@ impl FromStr for Format { "mp3" => Format::Audio(AudioFormat::Mp3), "avc1" | "avcc" => Format::Video(VideoFormat::Avc1), - "avc3" | "h264" => Format::Video(VideoFormat::Avc3), + "h264" => Format::Video(VideoFormat::H264), "hvc1" | "hvcc" => Format::Video(VideoFormat::Hvc1), - "hev1" => Format::Video(VideoFormat::Hev1), + "h265" | "hevc" => Format::Video(VideoFormat::H265), "av01" | "av1" | "av1c" | "av1C" => Format::Video(VideoFormat::Av01), "vp8" | "vp08" => Format::Video(VideoFormat::Vp8), "vp9" | "vp09" => Format::Video(VideoFormat::Vp9), @@ -201,12 +203,42 @@ kind_format!(AudioFormat, Audio, Aac => "aac", Opus => "opus", Flac => "flac", Mp3 => "mp3"); kind_format!(VideoFormat, Video, - Avc1 => "avc1", Avc3 => "avc3", Hvc1 => "hvc1", Hev1 => "hev1", + Avc1 => "avc1", H264 => "h264", Hvc1 => "hvc1", H265 => "h265", Av01 => "av01", Vp8 => "vp8", Vp9 => "vp9"); kind_format!(ContainerFormat, Container, Fmp4 => "fmp4", Mkv => "mkv", Ts => "ts", Flv => "flv"); +impl AudioFormat { + /// The suffix of a track named after this format, such as `.opus` in `0.opus`. + pub fn track_suffix(self) -> &'static str { + match self { + AudioFormat::Aac => ".aac", + AudioFormat::Opus => ".opus", + AudioFormat::Flac => ".flac", + AudioFormat::Mp3 => ".mp3", + } + } +} + +impl VideoFormat { + /// The suffix of a track named after this format, such as `.avc3` in `0.avc3`. + /// + /// Names the codec family the track publishes rather than the input, so a raw Annex B stream + /// is `.avc3` or `.hev1` like every other in-band H.26x track. + pub fn track_suffix(self) -> &'static str { + match self { + VideoFormat::Avc1 => ".avc1", + VideoFormat::H264 => ".avc3", + VideoFormat::Hvc1 => ".hvc1", + VideoFormat::H265 => ".hev1", + VideoFormat::Av01 => ".av01", + VideoFormat::Vp8 => ".vp8", + VideoFormat::Vp9 => ".vp9", + } + } +} + #[cfg(test)] mod tests { use super::*; @@ -216,7 +248,8 @@ mod tests { #[test] fn aliases_resolve_to_one_canonical_name() { for (aliases, canonical) in [ - (vec!["avc3", "h264"], "avc3"), + (vec!["h264"], "h264"), + (vec!["h265", "hevc"], "h265"), (vec!["avc1", "avcc"], "avc1"), (vec!["hvc1", "hvcc"], "hvc1"), (vec!["av01", "av1", "av1c", "av1C"], "av01"), @@ -238,7 +271,7 @@ mod tests { /// boundary, and says which entry point does take it. #[test] fn a_format_of_another_kind_names_the_kind_that_takes_it() { - let err = "avc3".parse::().unwrap_err(); + let err = "h264".parse::().unwrap_err(); assert!( matches!( &err, diff --git a/rs/moq-mux/src/import/init.rs b/rs/moq-mux/src/import/init.rs index dcec2396b89..06f75fd57fa 100644 --- a/rs/moq-mux/src/import/init.rs +++ b/rs/moq-mux/src/import/init.rs @@ -42,13 +42,13 @@ impl AudioInit { /// What a video importer needs to start: a format, optional init bytes, a label, and hints. /// -/// `format` selects the codec parser (`"avc3"`, `"hev1"`, `"vp8"`, ...). `data` may be empty for a +/// `format` selects the codec parser (`"h264"`, `"h265"`, `"vp8"`, ...). `data` may be empty for a /// format that resolves in band; a [`hint`](Self::hint) can pin fields the stream never reveals /// (bitrate) or publish the catalog before the first keyframe. See [`VideoHint`]. #[derive(Clone, Debug, PartialEq)] #[non_exhaustive] pub struct VideoInit { - /// The video format, e.g. `"avc3"` or `"vp8"`. + /// The video format, e.g. `"h264"` or `"vp8"`. pub format: VideoFormat, /// Codec init bytes (an avcC, an hvcC, ...). May be empty for a format that resolves in band. pub data: Bytes, diff --git a/rs/moq-mux/src/import/mod.rs b/rs/moq-mux/src/import/mod.rs index 313b9e5ee6d..5c4dc55e9a8 100644 --- a/rs/moq-mux/src/import/mod.rs +++ b/rs/moq-mux/src/import/mod.rs @@ -8,7 +8,7 @@ //! byte stream (piped Annex-B H.264, ...). A container recovers its own //! framing, so [`Container`] takes chunks split anywhere. //! -//! Each importer takes a typed format (parsed from e.g. `"avc3"` or `"fmp4"`) +//! Each importer takes a typed format (parsed from e.g. `"h264"` or `"fmp4"`) //! and errors on a format it doesn't handle; `TrackStream` accepts only the //! self-delimiting formats. The concrete importers live with their format //! under [`crate::container`] or [`crate::codec`] and own their @@ -113,7 +113,7 @@ mod tests { async fn finished_track_releases_its_splitter() { let keyframe = h264_keyframe(); assert_released("avc3 track", &|broadcast, catalog| { - let init = VideoInit::new(VideoFormat::Avc3, Bytes::new()); + let init = VideoInit::new(VideoFormat::H264, Bytes::new()); let mut track = Track::video(avc3(broadcast), catalog.reserve(), init).unwrap(); for pts in [0, 33_333] { let pts = moq_net::Timestamp::from_micros(pts).unwrap(); @@ -128,7 +128,7 @@ mod tests { // Two access units in one write, so the splitter holds the whole write. let stream = [h264_keyframe(), h264_keyframe()].concat(); assert_released("avc3 stream", &|broadcast, catalog| { - let init = VideoInit::new(VideoFormat::Avc3, Bytes::new()); + let init = VideoInit::new(VideoFormat::H264, Bytes::new()); let mut track = TrackStream::video(avc3(broadcast), catalog.reserve(), init).unwrap(); track.decode(&stream).unwrap(); Box::new(track.finish().unwrap()) diff --git a/rs/moq-mux/src/import/track.rs b/rs/moq-mux/src/import/track.rs index 3b5650ae7ac..ebcb6565db1 100644 --- a/rs/moq-mux/src/import/track.rs +++ b/rs/moq-mux/src/import/track.rs @@ -148,9 +148,9 @@ fn not_video(format: AudioFormat) -> crate::Error { } enum TrackKind { - /// H.264 Annex-B with inline SPS/PPS, published as avc3. The split owns byte + /// H.264 Annex B with inline SPS/PPS, published as avc3. The split owns byte /// parsing; the import publishes. - Avc3 { + H264 { split: crate::codec::h264::Split, import: crate::codec::h264::Import, }, @@ -161,7 +161,7 @@ enum TrackKind { length_size: usize, import: crate::codec::h264::Import, }, - Hev1 { + H265 { split: crate::codec::h265::Split, import: crate::codec::h265::Import, }, @@ -188,8 +188,8 @@ enum TrackKind { macro_rules! import { ($kind:expr, $import:ident => $body:expr) => { match $kind { - TrackKind::Avc3 { $import, .. } | TrackKind::Avc1 { $import, .. } => $body, - TrackKind::Hev1 { $import, .. } | TrackKind::Hvc1 { $import, .. } => $body, + TrackKind::H264 { $import, .. } | TrackKind::Avc1 { $import, .. } => $body, + TrackKind::H265 { $import, .. } | TrackKind::Hvc1 { $import, .. } => $body, TrackKind::Av01 { $import, .. } => $body, TrackKind::Vp8($import) => $body, TrackKind::Vp9($import) => $body, @@ -288,17 +288,17 @@ impl Track { let (length_size, import) = build_h264_avc1(track, reserved, data, video_hint(&init, None))?; TrackKind::Avc1 { length_size, import } } - VideoFormat::Avc3 => { + VideoFormat::H264 => { let (split, import) = build_h264_avc3(track, reserved, data, video_hint(&init, None))?; - TrackKind::Avc3 { split, import } + TrackKind::H264 { split, import } } VideoFormat::Hvc1 => { let (length_size, import) = build_h265_hvc1(track, reserved, data, video_hint(&init, None))?; TrackKind::Hvc1 { length_size, import } } - VideoFormat::Hev1 => { + VideoFormat::H265 => { let (split, import) = build_h265(track, reserved, data, video_hint(&init, None))?; - TrackKind::Hev1 { split, import } + TrackKind::H265 { split, import } } VideoFormat::Av01 => { let (split, import) = build_av1(track, reserved, data, video_hint(&init, None))?; @@ -361,7 +361,7 @@ impl Track { /// Decode one whole frame. pub fn decode(&mut self, frame: B, pts: Option) -> Result<()> { match self.kind { - TrackKind::Avc3 { + TrackKind::H264 { ref mut split, ref mut import, } => { @@ -379,7 +379,7 @@ impl Track { let frame = crate::codec::h264::avc1_frame(frame, length_size, pts)?; import.decode([frame])?; } - TrackKind::Hev1 { + TrackKind::H265 { ref mut split, ref mut import, } => { @@ -438,8 +438,8 @@ impl Track { // Each decode flushed its whole frame, so a splitter holds at most a picture its init // carried. let flushed = (|| match &mut self.kind { - TrackKind::Avc3 { split, import } => import.decode(split.flush(None)?), - TrackKind::Hev1 { split, import } => import.decode(split.flush(None)?), + TrackKind::H264 { split, import } => import.decode(split.flush(None)?), + TrackKind::H265 { split, import } => import.decode(split.flush(None)?), TrackKind::Av01 { split, import } => import.decode(split.flush(None)?), _ => Ok(()), })(); @@ -448,8 +448,8 @@ impl Track { return Err(err); } let inner = match self.kind { - TrackKind::Avc3 { import, .. } | TrackKind::Avc1 { import, .. } => FinishedKind::Video(import.finish()?), - TrackKind::Hev1 { import, .. } | TrackKind::Hvc1 { import, .. } => FinishedKind::Video(import.finish()?), + TrackKind::H264 { import, .. } | TrackKind::Avc1 { import, .. } => FinishedKind::Video(import.finish()?), + TrackKind::H265 { import, .. } | TrackKind::Hvc1 { import, .. } => FinishedKind::Video(import.finish()?), TrackKind::Av01 { import, .. } => FinishedKind::Video(import.finish()?), TrackKind::Vp8(import) => FinishedKind::Video(import.finish()?), TrackKind::Vp9(import) => FinishedKind::Video(import.finish()?), @@ -484,15 +484,15 @@ impl Track { warned, } = self; let kind = match kind { - TrackKind::Avc3 { split, import } => import + TrackKind::H264 { split, import } => import .abort_unwanted(err) - .map_err(|import| TrackKind::Avc3 { split, import }), + .map_err(|import| TrackKind::H264 { split, import }), TrackKind::Avc1 { length_size, import } => import .abort_unwanted(err) .map_err(|import| TrackKind::Avc1 { length_size, import }), - TrackKind::Hev1 { split, import } => import + TrackKind::H265 { split, import } => import .abort_unwanted(err) - .map_err(|import| TrackKind::Hev1 { split, import }), + .map_err(|import| TrackKind::H265 { split, import }), TrackKind::Hvc1 { length_size, import } => import .abort_unwanted(err) .map_err(|import| TrackKind::Hvc1 { length_size, import }), @@ -542,8 +542,8 @@ impl Track { /// [`Error::WrongKind`](crate::Error::WrongKind). pub fn set_enabled(&mut self, enabled: bool) -> Result<()> { match &mut self.kind { - TrackKind::Avc3 { import, .. } | TrackKind::Avc1 { import, .. } => import.set_enabled(enabled)?, - TrackKind::Hev1 { import, .. } | TrackKind::Hvc1 { import, .. } => import.set_enabled(enabled)?, + TrackKind::H264 { import, .. } | TrackKind::Avc1 { import, .. } => import.set_enabled(enabled)?, + TrackKind::H265 { import, .. } | TrackKind::Hvc1 { import, .. } => import.set_enabled(enabled)?, TrackKind::Av01 { import, .. } => import.set_enabled(enabled)?, TrackKind::Vp8(import) => import.set_enabled(enabled)?, TrackKind::Vp9(import) => import.set_enabled(enabled)?, @@ -565,8 +565,8 @@ impl Track { /// Drop the partial access unit of a format split from a byte stream. fn reset_split(&mut self) { match &mut self.kind { - TrackKind::Avc3 { split, .. } => split.reset(), - TrackKind::Hev1 { split, .. } => split.reset(), + TrackKind::H264 { split, .. } => split.reset(), + TrackKind::H265 { split, .. } => split.reset(), TrackKind::Av01 { split, .. } => split.reset(), TrackKind::Avc1 { .. } | TrackKind::Hvc1 { .. } @@ -614,13 +614,13 @@ impl From for Track { } enum TrackStreamKind { - /// H.264 Annex-B with inline SPS/PPS, published as avc3. The split owns + /// H.264 Annex B with inline SPS/PPS, published as avc3. The split owns /// byte parsing; the import publishes. - Avc3 { + H264 { split: crate::codec::h264::Split, import: crate::codec::h264::Import, }, - Hev1 { + H265 { split: crate::codec::h265::Split, import: crate::codec::h265::Import, }, @@ -634,11 +634,11 @@ enum TrackStreamKind { macro_rules! stream { ($kind:expr, $split:pat, $import:pat => $body:expr) => { match $kind { - TrackStreamKind::Avc3 { + TrackStreamKind::H264 { split: $split, import: $import, } => $body, - TrackStreamKind::Hev1 { + TrackStreamKind::H265 { split: $split, import: $import, } => $body, @@ -734,11 +734,11 @@ impl TrackStream { let hint = video_hint(&init, None); // Only the self-delimiting codecs can be recovered from a raw byte stream. let kind = match init.format { - VideoFormat::Avc3 => TrackStreamKind::Avc3 { + VideoFormat::H264 => TrackStreamKind::H264 { split: crate::codec::h264::Split::new(), import: crate::codec::h264::Import::new(track, reserved, hint)?, }, - VideoFormat::Hev1 => TrackStreamKind::Hev1 { + VideoFormat::H265 => TrackStreamKind::H265 { split: crate::codec::h265::Split::new(), import: crate::codec::h265::Import::new(track, reserved, hint)?, }, @@ -763,17 +763,17 @@ impl TrackStream { /// Initialize the importer with the given buffer and populate the broadcast. /// - /// This is not required for self-describing formats like AVC3. + /// This is not required for self-describing formats like H264. pub fn initialize(&mut self, data: &[u8]) -> Result<()> { match self.kind { - TrackStreamKind::Avc3 { + TrackStreamKind::H264 { ref mut split, ref mut import, } => { import.initialize(data)?; publish!(self.gate, import, split.initialize(data)?)?; } - TrackStreamKind::Hev1 { + TrackStreamKind::H265 { ref mut split, ref mut import, } => { @@ -867,12 +867,12 @@ impl TrackStream { pub fn abort_unwanted(self, err: moq_net::Error) -> std::result::Result<(), Self> { let Self { kind, gate } = self; let kind = match kind { - TrackStreamKind::Avc3 { split, import } => import + TrackStreamKind::H264 { split, import } => import .abort_unwanted(err) - .map_err(|import| TrackStreamKind::Avc3 { split, import }), - TrackStreamKind::Hev1 { split, import } => import + .map_err(|import| TrackStreamKind::H264 { split, import }), + TrackStreamKind::H265 { split, import } => import .abort_unwanted(err) - .map_err(|import| TrackStreamKind::Hev1 { split, import }), + .map_err(|import| TrackStreamKind::H265 { split, import }), TrackStreamKind::Av01 { split, import } => import .abort_unwanted(err) .map_err(|import| TrackStreamKind::Av01 { split, import }), @@ -1365,7 +1365,7 @@ mod tests { let import = Track::video( request, catalog.reserve(), - VideoInit::new(VideoFormat::Avc3, h264_init()), + VideoInit::new(VideoFormat::H264, h264_init()), ) .unwrap(); @@ -1721,7 +1721,7 @@ mod tests { let mut stream = TrackStream::video( broadcast.reserve_track("video").unwrap(), catalog.reserve(), - VideoInit::new(VideoFormat::Avc3, h264_init()), + VideoInit::new(VideoFormat::H264, h264_init()), ) .unwrap(); let mut track = consumer.track("video").unwrap().subscribe(None).await.unwrap(); @@ -1744,24 +1744,24 @@ mod tests { async fn avc3_init_picture_published_at_finish() { let mut init = h264_init(); init.extend_from_slice(&annexb(&[H264_IDR])); - init_picture_published_at_finish(VideoFormat::Avc3, init).await; + init_picture_published_at_finish(VideoFormat::H264, init).await; } #[tokio::test(start_paused = true)] async fn hev1_init_picture_published_at_finish() { use crate::codec::h265::fixtures::{PPS, SPS, VPS}; - init_picture_published_at_finish(VideoFormat::Hev1, annexb(&[VPS, SPS, PPS, H265_IDR])).await; + init_picture_published_at_finish(VideoFormat::H265, annexb(&[VPS, SPS, PPS, H265_IDR])).await; } #[tokio::test(start_paused = true)] async fn avc3_init_headers_survive_reset() { - headers_survive_reset(VideoFormat::Avc3, h264_init(), annexb(&[H264_IDR])).await; + headers_survive_reset(VideoFormat::H264, h264_init(), annexb(&[H264_IDR])).await; } #[tokio::test(start_paused = true)] async fn hev1_init_headers_survive_reset() { use crate::codec::h265::fixtures::{PPS, SPS, VPS}; - headers_survive_reset(VideoFormat::Hev1, annexb(&[VPS, SPS, PPS]), annexb(&[H265_IDR])).await; + headers_survive_reset(VideoFormat::H265, annexb(&[VPS, SPS, PPS]), annexb(&[H265_IDR])).await; } #[tokio::test(start_paused = true)] @@ -1826,7 +1826,7 @@ mod tests { let cases = [ (VideoFormat::Avc1, avcc, length_prefixed(H264_IDR)), ( - VideoFormat::Hev1, + VideoFormat::H265, Vec::new(), annexb(&[h265::fixtures::VPS, h265::fixtures::SPS, h265::fixtures::PPS, H265_IDR]), ), @@ -1912,9 +1912,9 @@ mod tests { let (_, av1_keyframe) = av1_init_and_keyframe(); let cases = [ - (VideoFormat::Avc3, [h264_init(), annexb(&[H264_IDR])].concat(), H264_IDR), + (VideoFormat::H264, [h264_init(), annexb(&[H264_IDR])].concat(), H264_IDR), ( - VideoFormat::Hev1, + VideoFormat::H265, annexb(&[h265::fixtures::VPS, h265::fixtures::SPS, h265::fixtures::PPS, H265_IDR]), H265_IDR, ), @@ -1958,7 +1958,7 @@ mod tests { let mut import = TrackStream::video( request, catalog.reserve(), - VideoInit::new(VideoFormat::Avc3, Vec::new()), + VideoInit::new(VideoFormat::H264, Vec::new()), ) .unwrap(); // Every group is written before anything reads, which the default diff --git a/swift/Tests/MoqTests/SmokeTests.swift b/swift/Tests/MoqTests/SmokeTests.swift index cf1aed13138..17ed8b9c189 100644 --- a/swift/Tests/MoqTests/SmokeTests.swift +++ b/swift/Tests/MoqTests/SmokeTests.swift @@ -619,7 +619,7 @@ final class SmokeTests: XCTestCase { optimizeForLatency: true ) let media = try Media.TrackProducer.video( - broadcast: broadcast, initData: Media.VideoInit(format: .avc3, data: Data(), hint: hint)) + broadcast: broadcast, initData: Media.VideoInit(format: .h264, data: Data(), hint: hint)) try media.finish() try broadcast.close() } diff --git a/test/interop/clients/cpp/main.cpp b/test/interop/clients/cpp/main.cpp index 5bd2655e6a1..c6f4643442d 100644 --- a/test/interop/clients/cpp/main.cpp +++ b/test/interop/clients/cpp/main.cpp @@ -216,7 +216,7 @@ int publish( auto broadcast = route->broadcast(); auto catalog = ok(moq::MediaCatalogProducer::init(broadcast), "catalog producer"); auto media = ok( - moq::MediaTrackStreamProducer::video(broadcast, moq::MediaTarget::kNamed{}, {moq::VideoFormat::kAvc3, {}}), + moq::MediaTrackStreamProducer::video(broadcast, moq::MediaTarget::kNamed{}, {moq::VideoFormat::kH264, {}}), "video stream producer" ); moq::AudioEncoderOutput output{moq::AudioCodec::opus()}; diff --git a/test/interop/clients/go/main.go b/test/interop/clients/go/main.go index 2f22e344845..2aa299db53c 100644 --- a/test/interop/clients/go/main.go +++ b/test/interop/clients/go/main.go @@ -164,7 +164,7 @@ func publish(ctx context.Context, url, broadcast string, opts dialOptions, timeo if err != nil { return err } - media, err := moqmedia.NewVideoTrackStreamProducer(producer, moqmedia.Named{}, moqmedia.VideoInit{Format: moqmedia.VideoFormatAvc3, Data: nil}) + media, err := moqmedia.NewVideoTrackStreamProducer(producer, moqmedia.Named{}, moqmedia.VideoInit{Format: moqmedia.VideoFormatH264, Data: nil}) if err != nil { return err } diff --git a/test/interop/clients/python/interop.py b/test/interop/clients/python/interop.py index e759872bfb3..ff8d9f5d200 100644 --- a/test/interop/clients/python/interop.py +++ b/test/interop/clients/python/interop.py @@ -121,7 +121,7 @@ async def publish( producer = route.broadcast catalog = moq.media.CatalogProducer(producer) media = moq.media.TrackStreamProducer.video( - producer, moq.media.VideoInit(format=moq.media.VideoFormat.AVC3, data=b"") + producer, moq.media.VideoInit(format=moq.media.VideoFormat.H264, data=b"") ) audio = moq.audio.Producer( catalog, diff --git a/test/interop/clients/rust/finish.rs b/test/interop/clients/rust/finish.rs index 57aa0f0f6f1..26a860f4fc0 100644 --- a/test/interop/clients/rust/finish.rs +++ b/test/interop/clients/rust/finish.rs @@ -81,7 +81,7 @@ async fn main() -> anyhow::Result<()> { let mut stream = moq_mux::import::TrackStream::video( route.broadcast().reserve_track("video")?, catalog.reserve(), - moq_mux::import::VideoInit::new(moq_mux::import::VideoFormat::Avc3, Vec::new()), + moq_mux::import::VideoInit::new(moq_mux::import::VideoFormat::H264, Vec::new()), )?; let mut data = Vec::new(); stdin.read_to_end(&mut data).await?; diff --git a/test/interop/compat.sh b/test/interop/compat.sh index c8aebcbed37..92ea2f03bc0 100755 --- a/test/interop/compat.sh +++ b/test/interop/compat.sh @@ -193,10 +193,17 @@ cell() { fetch() { local relay="$1" pub="$2" sub="$3" js="$4" version="$5" RELAY_BIN="$relay" CLI_BIN="$pub" INTEROP_SUB_MOQ="$sub" INTEROP_VERSION="$version" \ - INTEROP_COMPAT_CLIENT="$js" INTEROP_FETCH_TRACK=1 \ + INTEROP_COMPAT_CLIENT="$js" INTEROP_FETCH_TRACK=1 INTEROP_PUB_ANNEXB="$(annexb_import "$pub")" \ bash "$DIR/interop.sh" --publishers rust --subscribers rust } +# TEMPORARY migration, delete once the released CLI names it `h264`: releases before +# it name the Annex-B import `avc3`. Probed once, so a release with the rename needs no edit. +if "$RELEASED" import h264 --help >/dev/null 2>&1; then released_annexb=h264; else released_annexb=avc3; fi +annexb_import() { + [[ "$1" == "$RELEASED" ]] && echo "$released_annexb" || echo h264 +} + # The released CLI's fMP4 import restamps media on its arrival clock, so its tone # does not start at timestamp zero and its decodes cannot be held to the tone's # phase (see phase_checked in interop.sh). Its readers' phase is still checked. diff --git a/test/interop/interop.sh b/test/interop/interop.sh index eb2b2e68e62..cb7a37b5bd4 100755 --- a/test/interop/interop.sh +++ b/test/interop/interop.sh @@ -50,7 +50,7 @@ source "$INTEROP_DIR/../lib/harness.sh" # Captured before the parse below consumes it, so the rerun command carries every # flag and every environment override this run was actually given. -RERUN="$(harness_env INTEROP_TIMEOUT INTEROP_FPS INTEROP_SIZE INTEROP_PORT INTEROP_PROFILE RELAY_BIN CLI_BIN INTEROP_SUB_MOQ INTEROP_VERSION INTEROP_COMPAT_CLIENT INTEROP_DECODE INTEROP_PUB_LIVE INTEROP_FETCH_DATA INTEROP_FETCH_TRACK)just test interop$(harness_argv "$@")" +RERUN="$(harness_env INTEROP_TIMEOUT INTEROP_FPS INTEROP_SIZE INTEROP_PORT INTEROP_PROFILE RELAY_BIN CLI_BIN INTEROP_SUB_MOQ INTEROP_VERSION INTEROP_COMPAT_CLIENT INTEROP_DECODE INTEROP_PUB_LIVE INTEROP_PUB_ANNEXB INTEROP_FETCH_DATA INTEROP_FETCH_TRACK)just test interop$(harness_argv "$@")" PUBLISHERS="rust" SUBSCRIBERS="rust" @@ -1131,8 +1131,9 @@ run_publisher() { ffmpeg_fmp4 "$(tone_source "$tone")" "$(publisher_codecs rust)" | RUST_LOG="$CLI_LOG" "$MOQ" "${connect[@]}" --connect-version "$(cell_version rust)" \ --broadcast "$broadcast" import --max-age 5s fmp4 else + # INTEROP_PUB_ANNEXB names the Annex-B source for a released CLI, which calls it `avc3`. ffmpeg_h264 | RUST_LOG="$CLI_LOG" "$MOQ" "${connect[@]}" --connect-version "$(cell_version rust)" \ - --broadcast "$broadcast" import --max-age 1s avc3 + --broadcast "$broadcast" import --max-age 1s "${INTEROP_PUB_ANNEXB:-h264}" fi ;; python) diff --git a/test/portrait/run.sh b/test/portrait/run.sh index c14fe333fca..cb5db02e9e0 100755 --- a/test/portrait/run.sh +++ b/test/portrait/run.sh @@ -23,7 +23,7 @@ harness_ready "$URL/certificate.sha256" 30 "$HARNESS_PID" publish_portrait() { ffmpeg -hide_banner -loglevel error -re -f lavfi -i testsrc2=size=720x1280:rate=10 \ -c:v libx264 -preset ultrafast -tune zerolatency -profile:v baseline -pix_fmt yuv420p -g 10 -f h264 - | - "$WORKSPACE/target/debug/moq" --connect "$URL" --connect-version moq-lite-07-wip --broadcast portrait.hang import avc3 + "$WORKSPACE/target/debug/moq" --connect "$URL" --connect-version moq-lite-07-wip --broadcast portrait.hang import h264 } harness_spawn publisher "$HARNESS_RUN/publisher.log" publish_portrait harness_spawn transcode "$HARNESS_RUN/transcode.log" "$WORKSPACE/target/debug/moq" \ diff --git a/test/smoke/smoke.sh b/test/smoke/smoke.sh index 85299283bd2..58377fe6342 100755 --- a/test/smoke/smoke.sh +++ b/test/smoke/smoke.sh @@ -217,6 +217,13 @@ require_tools() { echo "error: missing required tools: ${missing[*]}" >&2 exit 1 fi + # TEMPORARY migration, delete once every smoked channel ships a CLI with `import h264`: + # releases before it name the Annex-B import `avc3`. + if "$MOQ" import h264 --help >/dev/null 2>&1; then + ANNEXB_IMPORT=h264 + else + ANNEXB_IMPORT=avc3 + fi } # Run swift with the Xcode toolchain. A loaded nix devShell exports SDKROOT / @@ -705,7 +712,7 @@ start_publisher() { local lang="$1" broadcast="$2" log="$TMP/pub-$1.log" case "$lang" in rust) - (ffmpeg_h264 | rust_moq "$URL" --broadcast "$broadcast" import avc3) >"$log" 2>&1 & + (ffmpeg_h264 | rust_moq "$URL" --broadcast "$broadcast" import "$ANNEXB_IMPORT") >"$log" 2>&1 & ;; python) (ffmpeg_h264 | run_client "$PY" "$CLIENTS/python/smoke.py" \