The project's sample rate is its own to name (.edith v17)
Browse files at this commit- feat
- the project's sample rate is its own to name (.edith v17)
5 changed files +261 -33
- crates/engine/src/audio.rs +39 -4
- crates/engine/src/edith.rs +133 -20
- crates/engine/src/export.rs +16 -8
- crates/engine/src/playback.rs +70 -1
- crates/engine/src/proxy.rs +3 -0
crates/engine/src/audio.rsmodified+39 -4
| @@ -376,6 +376,22 @@ impl AudioSession { | |||
| 376 | segs: &[(Option<usize>, f64, f64)], | 376 | segs: &[(Option<usize>, f64, f64)], |
| 377 | eqs: &[Option<EqParams>], | 377 | eqs: &[Option<EqParams>], |
| 378 | speeds: &[Option<crate::project::Stretch>], | 378 | speeds: &[Option<crate::project::Stretch>], |
| 379 | + ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> { | ||
| 380 | + Self::open_multi_streams_speed_at(sources, segs, eqs, speeds, None) | ||
| 381 | + } | ||
| 382 | + | ||
| 383 | + /// [`open_multi_streams_speed`] with the project's own rate, when one was | ||
| 384 | + /// picked ([`crate::edith::Document::sample_rate`]), overriding the source's | ||
| 385 | + /// derived one. The per-segment [`Rate`] chain below already conforms any | ||
| 386 | + /// segment whose own rate differs from `meta.sample_rate`, so naming a rate | ||
| 387 | + /// here costs nothing new -- it only changes which rate that chain conforms | ||
| 388 | + /// *to*. | ||
| 389 | + pub fn open_multi_streams_speed_at( | ||
| 390 | + sources: &[(PathBuf, usize)], | ||
| 391 | + segs: &[(Option<usize>, f64, f64)], | ||
| 392 | + eqs: &[Option<EqParams>], | ||
| 393 | + speeds: &[Option<crate::project::Stretch>], | ||
| 394 | + sample_rate: Option<u32>, | ||
| 379 | ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> { | 395 | ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> { |
| 380 | // The first source that could have a track, which is not always index 0: | 396 | // The first source that could have a track, which is not always index 0: |
| 381 | // a still image has none, and one at the front of the list (a save | 397 | // a still image has none, and one at the front of the list (a save |
| @@ -395,7 +411,7 @@ impl AudioSession { | |||
| 395 | // The timeline's meta is that source's: policy makes every other source | 411 | // The timeline's meta is that source's: policy makes every other source |
| 396 | // match it, and the checks below hold them to that. | 412 | // match it, and the checks below hold them to that. |
| 397 | let meta = AudioMeta { | 413 | let meta = AudioMeta { |
| 398 | - sample_rate: first.sample_rate(), | 414 | + sample_rate: sample_rate.unwrap_or_else(|| first.sample_rate()), |
| 399 | channels: first.channels(), | 415 | channels: first.channels(), |
| 400 | total_samples: first.total_samples(), | 416 | total_samples: first.total_samples(), |
| 401 | }; | 417 | }; |
| @@ -658,7 +674,23 @@ impl AudioSession { | |||
| 658 | gains: &[f32], | 674 | gains: &[f32], |
| 659 | limiter: Limiter, | 675 | limiter: Limiter, |
| 660 | ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> { | 676 | ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> { |
| 661 | - Self::open_mixed_streams_live(sources, lanes, eqs, speeds, gains, limiter, None) | 677 | + Self::open_mixed_streams_master_at(sources, lanes, eqs, speeds, gains, limiter, None) |
| 678 | + } | ||
| 679 | + | ||
| 680 | + /// [`open_mixed_streams_master`] with the project's own rate | ||
| 681 | + /// ([`crate::edith::Document::sample_rate`]) overriding the derived one, the | ||
| 682 | + /// same rate every lane's meta agrees on ([`open_mixed_streams_live`]'s | ||
| 683 | + /// invariant). | ||
| 684 | + pub fn open_mixed_streams_master_at( | ||
| 685 | + sources: &[(PathBuf, usize)], | ||
| 686 | + lanes: &[Vec<(Option<usize>, f64, f64)>], | ||
| 687 | + eqs: &[Vec<Option<EqParams>>], | ||
| 688 | + speeds: &[Vec<Option<crate::project::Stretch>>], | ||
| 689 | + gains: &[f32], | ||
| 690 | + limiter: Limiter, | ||
| 691 | + sample_rate: Option<u32>, | ||
| 692 | + ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> { | ||
| 693 | + Self::open_mixed_streams_live(sources, lanes, eqs, speeds, gains, limiter, None, sample_rate) | ||
| 662 | } | 694 | } |
| 663 | 695 | ||
| 664 | /// [`open_mixed_streams_master`](Self::open_mixed_streams_master) with the | 696 | /// [`open_mixed_streams_master`](Self::open_mixed_streams_master) with the |
| @@ -677,6 +709,7 @@ impl AudioSession { | |||
| 677 | gains: &[f32], | 709 | gains: &[f32], |
| 678 | limiter: Limiter, | 710 | limiter: Limiter, |
| 679 | live: Option<&Arc<MixControls>>, | 711 | live: Option<&Arc<MixControls>>, |
| 712 | + sample_rate: Option<u32>, | ||
| 680 | ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> { | 713 | ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> { |
| 681 | let [first, ..] = lanes else { | 714 | let [first, ..] = lanes else { |
| 682 | return Ok(None); | 715 | return Ok(None); |
| @@ -684,11 +717,12 @@ impl AudioSession { | |||
| 684 | if !Self::is_mixed(lanes.len(), gains, limiter) { | 717 | if !Self::is_mixed(lanes.len(), gains, limiter) { |
| 685 | let flat = Vec::new(); | 718 | let flat = Vec::new(); |
| 686 | let plain = Vec::new(); | 719 | let plain = Vec::new(); |
| 687 | - return Self::open_multi_streams_speed( | 720 | + return Self::open_multi_streams_speed_at( |
| 688 | sources, | 721 | sources, |
| 689 | first, | 722 | first, |
| 690 | eqs.first().unwrap_or(&flat), | 723 | eqs.first().unwrap_or(&flat), |
| 691 | speeds.first().unwrap_or(&plain), | 724 | speeds.first().unwrap_or(&plain), |
| 725 | + sample_rate, | ||
| 692 | ); | 726 | ); |
| 693 | } | 727 | } |
| 694 | let mut meta = None; | 728 | let mut meta = None; |
| @@ -699,11 +733,12 @@ impl AudioSession { | |||
| 699 | // timeline. | 733 | // timeline. |
| 700 | let flat = Vec::new(); | 734 | let flat = Vec::new(); |
| 701 | let plain = Vec::new(); | 735 | let plain = Vec::new(); |
| 702 | - let Some((lane_meta, rx)) = Self::open_multi_streams_speed( | 736 | + let Some((lane_meta, rx)) = Self::open_multi_streams_speed_at( |
| 703 | sources, | 737 | sources, |
| 704 | segs, | 738 | segs, |
| 705 | eqs.get(i).unwrap_or(&flat), | 739 | eqs.get(i).unwrap_or(&flat), |
| 706 | speeds.get(i).unwrap_or(&plain), | 740 | speeds.get(i).unwrap_or(&plain), |
| 741 | + sample_rate, | ||
| 707 | )? | 742 | )? |
| 708 | else { | 743 | else { |
| 709 | return Ok(None); | 744 | return Ok(None); |
crates/engine/src/edith.rsmodified+133 -20
| @@ -216,7 +216,8 @@ use crate::subtitle::SubtitleTrack; | |||
| 216 | 216 | ||
| 217 | /// What [`save`] writes. Read support goes back to `edith 1`; see the module | 217 | /// What [`save`] writes. Read support goes back to `edith 1`; see the module |
| 218 | /// docs for what those dialects looked like. | 218 | /// docs for what those dialects looked like. |
| 219 | -const MAGIC: &[u8] = b"edith 16"; | 219 | +const MAGIC: &[u8] = b"edith 17"; |
| 220 | +const MAGIC_V16: &[u8] = b"edith 16"; | ||
| 220 | const MAGIC_V15: &[u8] = b"edith 15"; | 221 | const MAGIC_V15: &[u8] = b"edith 15"; |
| 221 | const MAGIC_V14: &[u8] = b"edith 14"; | 222 | const MAGIC_V14: &[u8] = b"edith 14"; |
| 222 | const MAGIC_V13: &[u8] = b"edith 13"; | 223 | const MAGIC_V13: &[u8] = b"edith 13"; |
| @@ -296,6 +297,15 @@ pub struct Document { | |||
| 296 | /// for a v14 file that leaves the line out, which both mean the seat this | 297 | /// for a v14 file that leaves the line out, which both mean the seat this |
| 297 | /// machine has -- the only choice those projects offered. | 298 | /// machine has -- the only choice those projects offered. |
| 298 | pub encoder: crate::export::EncoderSeat, | 299 | pub encoder: crate::export::EncoderSeat, |
| 300 | + /// The rate the project's *sound* is mixed and exported at, chosen rather | ||
| 301 | + /// than probed. `None` for every dialect before v17 and for a v17 file that | ||
| 302 | + /// leaves the line out, which both mean what they always did: the rate of | ||
| 303 | + /// the first source that has any ([`crate::PlaybackSession::open_project`]'s | ||
| 304 | + /// `first_audio_of`). Playback and export both resample every other source | ||
| 305 | + /// to whichever rate this resolves to, exactly as they already resample a | ||
| 306 | + /// source shot at another rate than the timeline's -- an explicit choice | ||
| 307 | + /// here only changes what that timeline's own rate *is*. | ||
| 308 | + pub sample_rate: Option<u32>, | ||
| 299 | pub playhead: u32, | 309 | pub playhead: u32, |
| 300 | } | 310 | } |
| 301 | 311 | ||
| @@ -321,6 +331,7 @@ pub fn save( | |||
| 321 | auto_proxy: bool, | 331 | auto_proxy: bool, |
| 322 | encoder: crate::export::EncoderSeat, | 332 | encoder: crate::export::EncoderSeat, |
| 323 | limiter: Limiter, | 333 | limiter: Limiter, |
| 334 | + sample_rate: Option<u32>, | ||
| 324 | playhead: u32, | 335 | playhead: u32, |
| 325 | ) -> crate::Result<()> { | 336 | ) -> crate::Result<()> { |
| 326 | let dir = project_dir(path); | 337 | let dir = project_dir(path); |
| @@ -335,7 +346,7 @@ pub fn save( | |||
| 335 | .and_then(|mut f| { | 346 | .and_then(|mut f| { |
| 336 | f.write_all(&emit( | 347 | f.write_all(&emit( |
| 337 | &dir, sources, lanes, gains, subs, subtitles, eq, color, resolution, fps, tone, | 348 | &dir, sources, lanes, gains, subs, subtitles, eq, color, resolution, fps, tone, |
| 338 | - proxy, auto_proxy, encoder, limiter, playhead, | 349 | + proxy, auto_proxy, encoder, limiter, sample_rate, playhead, |
| 339 | ))?; | 350 | ))?; |
| 340 | f.sync_all() | 351 | f.sync_all() |
| 341 | }) | 352 | }) |
| @@ -383,6 +394,7 @@ fn emit( | |||
| 383 | auto_proxy: bool, | 394 | auto_proxy: bool, |
| 384 | encoder: crate::export::EncoderSeat, | 395 | encoder: crate::export::EncoderSeat, |
| 385 | limiter: Limiter, | 396 | limiter: Limiter, |
| 397 | + sample_rate: Option<u32>, | ||
| 386 | playhead: u32, | 398 | playhead: u32, |
| 387 | ) -> Vec<u8> { | 399 | ) -> Vec<u8> { |
| 388 | let mut out = Vec::new(); | 400 | let mut out = Vec::new(); |
| @@ -395,6 +407,12 @@ fn emit( | |||
| 395 | if let Some(fps) = fps.filter(|f| f.is_finite() && *f > 0.0) { | 407 | if let Some(fps) = fps.filter(|f| f.is_finite() && *f > 0.0) { |
| 396 | out.extend_from_slice(format!("fps {fps:?}\n").as_bytes()); | 408 | out.extend_from_slice(format!("fps {fps:?}\n").as_bytes()); |
| 397 | } | 409 | } |
| 410 | + // Beside it, and by the same rule: a project nobody chose a sound rate for | ||
| 411 | + // is the mix the source's own probe always gave it, which is what leaving | ||
| 412 | + // this line out still means. | ||
| 413 | + if let Some(rate) = sample_rate.filter(|&r| (1_000..=384_000).contains(&r)) { | ||
| 414 | + out.extend_from_slice(format!("samplerate {rate}\n").as_bytes()); | ||
| 415 | + } | ||
| 398 | // Beside the rate, and written only when it is not the default: a project | 416 | // Beside the rate, and written only when it is not the default: a project |
| 399 | // holding no HDR media has nothing to say here, and saying nothing is what | 417 | // holding no HDR media has nothing to say here, and saying nothing is what |
| 400 | // a v10 file already said. | 418 | // a v10 file already said. |
| @@ -580,8 +598,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | |||
| 580 | // The dialects that wrote a source line without its stream field. Reading | 598 | // The dialects that wrote a source line without its stream field. Reading |
| 581 | // one is the whole of what "an old project still opens" means here. | 599 | // one is the whole of what "an old project still opens" means here. |
| 582 | let streamless = v1 || first == MAGIC_V2; | 600 | let streamless = v1 || first == MAGIC_V2; |
| 583 | - // The one whose captions may carry a group id... | 601 | + // The one that carries an explicit sound rate... |
| 584 | - let v16 = first == MAGIC; | 602 | + let v17 = first == MAGIC; |
| 603 | + // ...the one whose captions may carry a group id... | ||
| 604 | + let v16 = v17 || first == MAGIC_V16; | ||
| 585 | // ...the one that places the words it names... | 605 | // ...the one that places the words it names... |
| 586 | let v15 = v16 || first == MAGIC_V15; | 606 | let v15 = v16 || first == MAGIC_V15; |
| 587 | // ...the ones that say which encoder an export takes... | 607 | // ...the ones that say which encoder an export takes... |
| @@ -653,6 +673,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | |||
| 653 | // still means. | 673 | // still means. |
| 654 | encoder: crate::export::EncoderSeat::default(), | 674 | encoder: crate::export::EncoderSeat::default(), |
| 655 | fps: None, | 675 | fps: None, |
| 676 | + // Nothing before v17 chose a sound rate: the source's own probe is | ||
| 677 | + // still what the mix is cut at, which is what `None` means everywhere | ||
| 678 | + // else it reaches (`PlaybackSession::open_project`). | ||
| 679 | + sample_rate: None, | ||
| 656 | playhead: 0, | 680 | playhead: 0, |
| 657 | }; | 681 | }; |
| 658 | let mut playhead_seen = false; | 682 | let mut playhead_seen = false; |
| @@ -708,6 +732,20 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | |||
| 708 | })?; | 732 | })?; |
| 709 | doc.fps = Some(fps); | 733 | doc.fps = Some(fps); |
| 710 | } | 734 | } |
| 735 | + b"samplerate" if v17 => { | ||
| 736 | + if doc.sample_rate.is_some() || !doc.sources.is_empty() { | ||
| 737 | + return Err(format!( | ||
| 738 | + "line {n}: samplerate belongs once, before the sources" | ||
| 739 | + ) | ||
| 740 | + .into()); | ||
| 741 | + } | ||
| 742 | + let f = fields(rest, 1, "samplerate", n)?; | ||
| 743 | + let rate = number(f[0], n)?; | ||
| 744 | + if !(1_000..=384_000).contains(&rate) { | ||
| 745 | + return Err(format!("line {n}: {rate} Hz is not a sound rate").into()); | ||
| 746 | + } | ||
| 747 | + doc.sample_rate = Some(rate); | ||
| 748 | + } | ||
| 711 | b"tonemap" if v11 => { | 749 | b"tonemap" if v11 => { |
| 712 | if !doc.sources.is_empty() { | 750 | if !doc.sources.is_empty() { |
| 713 | return Err( | 751 | return Err( |
| @@ -1395,6 +1433,7 @@ mod tests { | |||
| 1395 | true, | 1433 | true, |
| 1396 | crate::export::EncoderSeat::default(), | 1434 | crate::export::EncoderSeat::default(), |
| 1397 | Limiter::default(), | 1435 | Limiter::default(), |
| 1436 | + None, | ||
| 1398 | playhead, | 1437 | playhead, |
| 1399 | ) | 1438 | ) |
| 1400 | } | 1439 | } |
| @@ -1442,6 +1481,7 @@ mod tests { | |||
| 1442 | true, | 1481 | true, |
| 1443 | crate::export::EncoderSeat::default(), | 1482 | crate::export::EncoderSeat::default(), |
| 1444 | Limiter::default(), | 1483 | Limiter::default(), |
| 1484 | + None, | ||
| 1445 | 0, | 1485 | 0, |
| 1446 | ); | 1486 | ); |
| 1447 | let text = String::from_utf8_lossy(&bytes); | 1487 | let text = String::from_utf8_lossy(&bytes); |
| @@ -1469,7 +1509,7 @@ mod tests { | |||
| 1469 | video 1 0 0 30 0 - - - fit 1000\n"; | 1509 | video 1 0 0 30 0 - - - fit 1000\n"; |
| 1470 | let old = parse(v9, &dir).expect("v9 still loads"); | 1510 | let old = parse(v9, &dir).expect("v9 still loads"); |
| 1471 | assert_eq!(old.subtitles, Vec::new()); | 1511 | assert_eq!(old.subtitles, Vec::new()); |
| 1472 | - assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 16\n")); | 1512 | + assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 17\n")); |
| 1473 | // ...and the line itself is not a v9 line: a dialect may not be mixed. | 1513 | // ...and the line itself is not a v9 line: a dialect may not be mixed. |
| 1474 | let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir) | 1514 | let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir) |
| 1475 | .unwrap_err() | 1515 | .unwrap_err() |
| @@ -1522,6 +1562,7 @@ mod tests { | |||
| 1522 | true, | 1562 | true, |
| 1523 | crate::export::EncoderSeat::default(), | 1563 | crate::export::EncoderSeat::default(), |
| 1524 | Limiter::default(), | 1564 | Limiter::default(), |
| 1565 | + None, | ||
| 1525 | 0, | 1566 | 0, |
| 1526 | ); | 1567 | ); |
| 1527 | let text = String::from_utf8_lossy(&bytes); | 1568 | let text = String::from_utf8_lossy(&bytes); |
| @@ -1573,6 +1614,7 @@ mod tests { | |||
| 1573 | true, | 1614 | true, |
| 1574 | crate::export::EncoderSeat::default(), | 1615 | crate::export::EncoderSeat::default(), |
| 1575 | Limiter::default(), | 1616 | Limiter::default(), |
| 1617 | + None, | ||
| 1576 | 0, | 1618 | 0, |
| 1577 | ) | 1619 | ) |
| 1578 | }; | 1620 | }; |
| @@ -1636,6 +1678,7 @@ mod tests { | |||
| 1636 | auto, | 1678 | auto, |
| 1637 | crate::export::EncoderSeat::default(), | 1679 | crate::export::EncoderSeat::default(), |
| 1638 | Limiter::default(), | 1680 | Limiter::default(), |
| 1681 | + None, | ||
| 1639 | 0, | 1682 | 0, |
| 1640 | ) | 1683 | ) |
| 1641 | }; | 1684 | }; |
| @@ -1701,6 +1744,7 @@ mod tests { | |||
| 1701 | true, | 1744 | true, |
| 1702 | seat, | 1745 | seat, |
| 1703 | Limiter::default(), | 1746 | Limiter::default(), |
| 1747 | + None, | ||
| 1704 | 0, | 1748 | 0, |
| 1705 | ) | 1749 | ) |
| 1706 | }; | 1750 | }; |
| @@ -1749,6 +1793,72 @@ mod tests { | |||
| 1749 | } | 1793 | } |
| 1750 | } | 1794 | } |
| 1751 | 1795 | ||
| 1796 | + /// The v17 line: an explicit sound rate, written only when picked and read | ||
| 1797 | + /// back as the very number -- and a v16 file, which had no way to say one | ||
| 1798 | + /// and meant the source's own probe, still opens with `None`. | ||
| 1799 | + #[test] | ||
| 1800 | + fn the_sample_rate_round_trips_and_a_v16_file_leaves_it_derived() { | ||
| 1801 | + let dir = PathBuf::from("/proj"); | ||
| 1802 | + let (_, sources, lanes) = doc(); | ||
| 1803 | + let bytes = |rate| { | ||
| 1804 | + super::emit( | ||
| 1805 | + &dir, | ||
| 1806 | + &sources, | ||
| 1807 | + &lanes, | ||
| 1808 | + &[], | ||
| 1809 | + &[], | ||
| 1810 | + &[], | ||
| 1811 | + &[], | ||
| 1812 | + &[], | ||
| 1813 | + (1280, 720), | ||
| 1814 | + None, | ||
| 1815 | + crate::tonemap::Preset::default(), | ||
| 1816 | + false, | ||
| 1817 | + true, | ||
| 1818 | + crate::export::EncoderSeat::default(), | ||
| 1819 | + Limiter::default(), | ||
| 1820 | + rate, | ||
| 1821 | + 0, | ||
| 1822 | + ) | ||
| 1823 | + }; | ||
| 1824 | + // Unset is the line left out, so a project nobody has chosen a rate for | ||
| 1825 | + // is the bytes a v16 file was bar the version line. | ||
| 1826 | + let unset = bytes(None); | ||
| 1827 | + assert!( | ||
| 1828 | + !String::from_utf8_lossy(&unset).contains("samplerate"), | ||
| 1829 | + "no pick is the line left out: {}", | ||
| 1830 | + String::from_utf8_lossy(&unset) | ||
| 1831 | + ); | ||
| 1832 | + assert_eq!(parse(&unset, &dir).expect("v17 parses").sample_rate, None); | ||
| 1833 | + for rate in [44_100, 48_000, 96_000] { | ||
| 1834 | + let written = bytes(Some(rate)); | ||
| 1835 | + let text = String::from_utf8_lossy(&written).to_string(); | ||
| 1836 | + assert!(text.contains(&format!("samplerate {rate}\n")), "{text}"); | ||
| 1837 | + assert_eq!( | ||
| 1838 | + parse(&written, &dir).expect("v17 parses").sample_rate, | ||
| 1839 | + Some(rate) | ||
| 1840 | + ); | ||
| 1841 | + } | ||
| 1842 | + // A v16 project had no rate of its own to say: the field comes back | ||
| 1843 | + // `None`, which is what "derive it from the source" already meant. | ||
| 1844 | + let v16 = b"edith 16\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ | ||
| 1845 | + video 1 0 0 30 0 - - - fit 1000\n"; | ||
| 1846 | + assert_eq!(parse(v16, &dir).expect("v16 still loads").sample_rate, None); | ||
| 1847 | + // ...and the line is not a v16 line: a dialect may not be mixed. | ||
| 1848 | + let mixed = parse(b"edith 16\nsource 0 a.mp4\nsamplerate 48000\n", &dir) | ||
| 1849 | + .unwrap_err() | ||
| 1850 | + .to_string(); | ||
| 1851 | + assert_eq!(mixed, "line 3: unknown keyword \"samplerate\""); | ||
| 1852 | + // A number out of a sound rate's range is a corrupt line, by name. | ||
| 1853 | + for line in ["samplerate 0\n", "samplerate 500000\n", "samplerate nope\n"] { | ||
| 1854 | + let file = format!("edith 17\nsource 0 a.mp4\n{line}"); | ||
| 1855 | + assert!( | ||
| 1856 | + parse(file.as_bytes(), &dir).is_err(), | ||
| 1857 | + "{line:?} is not a sound rate line" | ||
| 1858 | + ); | ||
| 1859 | + } | ||
| 1860 | + } | ||
| 1861 | + | ||
| 1752 | /// The v11 line: the HDR rendition, written by name, read back as the very | 1862 | /// The v11 line: the HDR rendition, written by name, read back as the very |
| 1753 | /// preset -- and the dialect before it, which had no way to say one and | 1863 | /// preset -- and the dialect before it, which had no way to say one and |
| 1754 | /// meant the published conversion. | 1864 | /// meant the published conversion. |
| @@ -1773,6 +1883,7 @@ mod tests { | |||
| 1773 | true, | 1883 | true, |
| 1774 | crate::export::EncoderSeat::default(), | 1884 | crate::export::EncoderSeat::default(), |
| 1775 | Limiter::default(), | 1885 | Limiter::default(), |
| 1886 | + None, | ||
| 1776 | 0, | 1887 | 0, |
| 1777 | ); | 1888 | ); |
| 1778 | let text = String::from_utf8_lossy(&bytes).to_string(); | 1889 | let text = String::from_utf8_lossy(&bytes).to_string(); |
| @@ -1866,7 +1977,7 @@ mod tests { | |||
| 1866 | let bytes = flat(&dir, &sources, &lanes, 12); | 1977 | let bytes = flat(&dir, &sources, &lanes, 12); |
| 1867 | assert_eq!( | 1978 | assert_eq!( |
| 1868 | String::from_utf8_lossy(&bytes), | 1979 | String::from_utf8_lossy(&bytes), |
| 1869 | - "edith 16\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ | 1980 | + "edith 17\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ |
| 1870 | source 2 /elsewhere/b.mp4\n\ | 1981 | source 2 /elsewhere/b.mp4\n\ |
| 1871 | video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\ | 1982 | video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\ |
| 1872 | audio 1 0 0 30 0 0 - - fit 1000\n", | 1983 | audio 1 0 0 30 0 0 - - fit 1000\n", |
| @@ -1903,7 +2014,7 @@ mod tests { | |||
| 1903 | let bytes = flat(&dir, &sources, &lanes, 7); | 2014 | let bytes = flat(&dir, &sources, &lanes, 7); |
| 1904 | assert_eq!( | 2015 | assert_eq!( |
| 1905 | String::from_utf8_lossy(&bytes), | 2016 | String::from_utf8_lossy(&bytes), |
| 1906 | - "edith 16\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\ | 2017 | + "edith 17\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\ |
| 1907 | video 1 0 0 30 0 4 - - fit 1000\naudio 1\n\ | 2018 | video 1 0 0 30 0 4 - - fit 1000\naudio 1\n\ |
| 1908 | video 2 40 0 10 0 - - - fit 1000\naudio 2 0 0 30 0 4 - - fit 1000\n", | 2019 | video 2 40 0 10 0 - - - fit 1000\naudio 2 0 0 30 0 4 - - fit 1000\n", |
| 1909 | "an empty lane is a line of its own; everything else is its clips" | 2020 | "an empty lane is a line of its own; everything else is its clips" |
| @@ -2011,7 +2122,7 @@ mod tests { | |||
| 2011 | let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0); | 2122 | let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0); |
| 2012 | assert_eq!( | 2123 | assert_eq!( |
| 2013 | String::from_utf8_lossy(&bytes), | 2124 | String::from_utf8_lossy(&bytes), |
| 2014 | - "edith 16\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ | 2125 | + "edith 17\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ |
| 2015 | eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ | 2126 | eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ |
| 2016 | eq 16777215.0:-0.1:3.918315e-39:hs\n\ | 2127 | eq 16777215.0:-0.1:3.918315e-39:hs\n\ |
| 2017 | eq\n\ | 2128 | eq\n\ |
| @@ -2115,7 +2226,7 @@ mod tests { | |||
| 2115 | let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0); | 2226 | let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0); |
| 2116 | assert_eq!( | 2227 | assert_eq!( |
| 2117 | String::from_utf8_lossy(&bytes), | 2228 | String::from_utf8_lossy(&bytes), |
| 2118 | - "edith 16\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ | 2229 | + "edith 17\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ |
| 2119 | color 0.1:1.2:0.9:-0.3\n\ | 2230 | color 0.1:1.2:0.9:-0.3\n\ |
| 2120 | color -1e-7:16777215.0:3.918315e-39:-0.0\n\ | 2231 | color -1e-7:16777215.0:3.918315e-39:-0.0\n\ |
| 2121 | color 0.0:1.0:1.0:0.0\n\ | 2232 | color 0.0:1.0:1.0:0.0\n\ |
| @@ -2180,7 +2291,7 @@ mod tests { | |||
| 2180 | (1280, 720), | 2291 | (1280, 720), |
| 2181 | old.playhead | 2292 | old.playhead |
| 2182 | )), | 2293 | )), |
| 2183 | - "edith 16\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ | 2294 | + "edith 17\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ |
| 2184 | eq 80.0:-3.0:0.707:ls\n\ | 2295 | eq 80.0:-3.0:0.707:ls\n\ |
| 2185 | video 1 0 0 30 0 0 0 - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n" | 2296 | video 1 0 0 30 0 0 0 - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n" |
| 2186 | ); | 2297 | ); |
| @@ -2218,7 +2329,7 @@ mod tests { | |||
| 2218 | let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0); | 2329 | let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0); |
| 2219 | assert_eq!( | 2330 | assert_eq!( |
| 2220 | String::from_utf8_lossy(&bytes), | 2331 | String::from_utf8_lossy(&bytes), |
| 2221 | - "edith 16\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ | 2332 | + "edith 17\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ |
| 2222 | video 1 0 0 30 0 - - - fit 2000\nvideo 1 15 30 40 0 - - - fit 250\n\ | 2333 | video 1 0 0 30 0 - - - fit 2000\nvideo 1 15 30 40 0 - - - fit 250\n\ |
| 2223 | audio 1 0 0 30 0 - - - fit 2000\n", | 2334 | audio 1 0 0 30 0 - - - fit 2000\n", |
| 2224 | "the rate is the clip line's last field, in thousandths" | 2335 | "the rate is the clip line's last field, in thousandths" |
| @@ -2247,7 +2358,7 @@ mod tests { | |||
| 2247 | (1280, 720), | 2358 | (1280, 720), |
| 2248 | old.playhead | 2359 | old.playhead |
| 2249 | )), | 2360 | )), |
| 2250 | - "edith 16\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ | 2361 | + "edith 17\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ |
| 2251 | video 1 0 0 30 0 0 - - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n" | 2362 | video 1 0 0 30 0 0 - - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n" |
| 2252 | ); | 2363 | ); |
| 2253 | // A rate outside what the editor can set is a corrupt line, by name. | 2364 | // A rate outside what the editor can set is a corrupt line, by name. |
| @@ -2293,11 +2404,12 @@ mod tests { | |||
| 2293 | true, | 2404 | true, |
| 2294 | crate::export::EncoderSeat::default(), | 2405 | crate::export::EncoderSeat::default(), |
| 2295 | limiter, | 2406 | limiter, |
| 2407 | + None, | ||
| 2296 | 0, | 2408 | 0, |
| 2297 | ); | 2409 | ); |
| 2298 | assert_eq!( | 2410 | assert_eq!( |
| 2299 | String::from_utf8_lossy(&bytes), | 2411 | String::from_utf8_lossy(&bytes), |
| 2300 | - "edith 16\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\ | 2412 | + "edith 17\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\ |
| 2301 | limiter -1.5 on\nsource 0 a.mp4\n\ | 2413 | limiter -1.5 on\nsource 0 a.mp4\n\ |
| 2302 | video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n\ | 2414 | video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n\ |
| 2303 | audio 2 0 0 30 0 - - - fit 1000\n\ | 2415 | audio 2 0 0 30 0 - - - fit 1000\n\ |
| @@ -2329,7 +2441,7 @@ mod tests { | |||
| 2329 | (1280, 720), | 2441 | (1280, 720), |
| 2330 | old.playhead | 2442 | old.playhead |
| 2331 | )), | 2443 | )), |
| 2332 | - "edith 16\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ | 2444 | + "edith 17\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ |
| 2333 | video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n" | 2445 | video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n" |
| 2334 | ); | 2446 | ); |
| 2335 | 2447 | ||
| @@ -2493,7 +2605,7 @@ mod tests { | |||
| 2493 | assert!(old.eq.is_empty(), "nothing before v5 equalizes anything"); | 2605 | assert!(old.eq.is_empty(), "nothing before v5 equalizes anything"); |
| 2494 | assert_eq!( | 2606 | assert_eq!( |
| 2495 | String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)), | 2607 | String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)), |
| 2496 | - "edith 16\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ | 2608 | + "edith 17\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ |
| 2497 | source 2 /elsewhere/b.mp4\n\ | 2609 | source 2 /elsewhere/b.mp4\n\ |
| 2498 | video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\ | 2610 | video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\ |
| 2499 | audio 1 0 0 30 0 0 - - fit 1000\n" | 2611 | audio 1 0 0 30 0 0 - - fit 1000\n" |
| @@ -2546,7 +2658,7 @@ mod tests { | |||
| 2546 | let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); | 2658 | let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); |
| 2547 | assert_eq!( | 2659 | assert_eq!( |
| 2548 | String::from_utf8_lossy(&v5), | 2660 | String::from_utf8_lossy(&v5), |
| 2549 | - "edith 16\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ | 2661 | + "edith 17\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ |
| 2550 | source 0 /elsewhere/b.mp4\n\ | 2662 | source 0 /elsewhere/b.mp4\n\ |
| 2551 | video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\ | 2663 | video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\ |
| 2552 | audio 1 0 0 30 0 0 - - fit 1000\n", | 2664 | audio 1 0 0 30 0 0 - - fit 1000\n", |
| @@ -2578,7 +2690,7 @@ mod tests { | |||
| 2578 | // Saved again it is the current version, which round-trips to the | 2690 | // Saved again it is the current version, which round-trips to the |
| 2579 | // same document. | 2691 | // same document. |
| 2580 | let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); | 2692 | let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); |
| 2581 | - assert!(v5.starts_with(b"edith 16\n")); | 2693 | + assert!(v5.starts_with(b"edith 17\n")); |
| 2582 | let again = parse(&v5, &dir).expect("v5 parses"); | 2694 | let again = parse(&v5, &dir).expect("v5 parses"); |
| 2583 | assert_eq!(again.lanes, back.lanes); | 2695 | assert_eq!(again.lanes, back.lanes); |
| 2584 | // A dialect may not be mixed: lane lines under v1, `clip` under v2. | 2696 | // A dialect may not be mixed: lane lines under v1, `clip` under v2. |
| @@ -2681,13 +2793,14 @@ mod tests { | |||
| 2681 | true, | 2793 | true, |
| 2682 | crate::export::EncoderSeat::default(), | 2794 | crate::export::EncoderSeat::default(), |
| 2683 | Limiter::default(), | 2795 | Limiter::default(), |
| 2796 | + None, | ||
| 2684 | 0, | 2797 | 0, |
| 2685 | ) | 2798 | ) |
| 2686 | .expect("save"); | 2799 | .expect("save"); |
| 2687 | let bytes = std::fs::read(&path).expect("read back"); | 2800 | let bytes = std::fs::read(&path).expect("read back"); |
| 2688 | assert_eq!( | 2801 | assert_eq!( |
| 2689 | String::from_utf8_lossy(&bytes), | 2802 | String::from_utf8_lossy(&bytes), |
| 2690 | - "edith 16\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\ | 2803 | + "edith 17\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\ |
| 2691 | video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n" | 2804 | video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n" |
| 2692 | ); | 2805 | ); |
| 2693 | // Loading rejoins the *given* directory, so the file is reached by the | 2806 | // Loading rejoins the *given* directory, so the file is reached by the |
| @@ -2732,10 +2845,10 @@ mod tests { | |||
| 2732 | #[test] | 2845 | #[test] |
| 2733 | fn a_wrong_first_line_is_refused_by_name() { | 2846 | fn a_wrong_first_line_is_refused_by_name() { |
| 2734 | let dir = PathBuf::from("/proj"); | 2847 | let dir = PathBuf::from("/proj"); |
| 2735 | - let err = parse(b"edith 17\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir) | 2848 | + let err = parse(b"edith 18\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir) |
| 2736 | .unwrap_err() | 2849 | .unwrap_err() |
| 2737 | .to_string(); | 2850 | .to_string(); |
| 2738 | - assert_eq!(err, "line 1: unsupported version 17"); | 2851 | + assert_eq!(err, "line 1: unsupported version 18"); |
| 2739 | for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] { | 2852 | for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] { |
| 2740 | assert_eq!( | 2853 | assert_eq!( |
| 2741 | parse(junk, &dir).unwrap_err().to_string(), | 2854 | parse(junk, &dir).unwrap_err().to_string(), |
crates/engine/src/export.rsmodified+16 -8
| @@ -443,6 +443,7 @@ pub fn start( | |||
| 443 | meta: VideoMeta, | 443 | meta: VideoMeta, |
| 444 | out: &Path, | 444 | out: &Path, |
| 445 | settings: &ExportSettings, | 445 | settings: &ExportSettings, |
| 446 | + sample_rate: Option<u32>, | ||
| 446 | ) -> ExportHandle { | 447 | ) -> ExportHandle { |
| 447 | let settings = settings.clone(); | 448 | let settings = settings.clone(); |
| 448 | let shared = Arc::new(Shared { | 449 | let shared = Arc::new(Shared { |
| @@ -498,7 +499,7 @@ pub fn start( | |||
| 498 | ) | 499 | ) |
| 499 | .into()), | 500 | .into()), |
| 500 | format if format.has_video() => { | 501 | format if format.has_video() => { |
| 501 | - let first = run(&project, &meta, &part, &worker, &settings); | 502 | + let first = run(&project, &meta, &part, &worker, &settings, sample_rate); |
| 502 | match first { | 503 | match first { |
| 503 | // The hardware encoder's *process* died under the driver | 504 | // The hardware encoder's *process* died under the driver |
| 504 | // ([`crate::hwproc`]) -- the editor is still here, and the | 505 | // ([`crate::hwproc`]) -- the editor is still here, and the |
| @@ -525,12 +526,12 @@ pub fn start( | |||
| 525 | // run backwards. | 526 | // run backwards. |
| 526 | let mut software = settings.clone(); | 527 | let mut software = settings.clone(); |
| 527 | software.seat = EncoderSeat::Software; | 528 | software.seat = EncoderSeat::Software; |
| 528 | - run(&project, &meta, &part, &worker, &software) | 529 | + run(&project, &meta, &part, &worker, &software, sample_rate) |
| 529 | } | 530 | } |
| 530 | other => other, | 531 | other => other, |
| 531 | } | 532 | } |
| 532 | } | 533 | } |
| 533 | - _ => run_audio(&project, &meta, &part, &worker, &settings), | 534 | + _ => run_audio(&project, &meta, &part, &worker, &settings, sample_rate), |
| 534 | }; | 535 | }; |
| 535 | let result = written.and_then(|()| std::fs::rename(&part, &out).map_err(Into::into)); | 536 | let result = written.and_then(|()| std::fs::rename(&part, &out).map_err(Into::into)); |
| 536 | if result.is_err() { | 537 | if result.is_err() { |
| @@ -1309,6 +1310,7 @@ fn copy_audio( | |||
| 1309 | kbps: u32, | 1310 | kbps: u32, |
| 1310 | mkv: bool, | 1311 | mkv: bool, |
| 1311 | shared: &Shared, | 1312 | shared: &Shared, |
| 1313 | + sample_rate: Option<u32>, | ||
| 1312 | ) -> crate::Result<Option<ExportAudio>> { | 1314 | ) -> crate::Result<Option<ExportAudio>> { |
| 1313 | // The segments name their source, and the copy carries its packet-rounding | 1315 | // The segments name their source, and the copy carries its packet-rounding |
| 1314 | // debt across a source join exactly as across a cut, so a timeline spanning | 1316 | // debt across a source join exactly as across a cut, so a timeline spanning |
| @@ -1350,7 +1352,7 @@ fn copy_audio( | |||
| 1350 | } | 1352 | } |
| 1351 | } | 1353 | } |
| 1352 | let [segments] = &lanes[..] else { | 1354 | let [segments] = &lanes[..] else { |
| 1353 | - return encode_audio(project, meta, kbps, mkv, shared); | 1355 | + return encode_audio(project, meta, kbps, mkv, shared, sample_rate); |
| 1354 | }; | 1356 | }; |
| 1355 | // ...and the same list names *which* lane those clips sit on, which is the | 1357 | // ...and the same list names *which* lane those clips sit on, which is the |
| 1356 | // only way to ask what has been done to them. | 1358 | // only way to ask what has been done to them. |
| @@ -1388,7 +1390,7 @@ fn copy_audio( | |||
| 1388 | // such a lane would write it at unity and unlimited, silently. | 1390 | // such a lane would write it at unity and unlimited, silently. |
| 1389 | let speeded = project.lane(lane).iter().any(|c| !c.speed.is_normal()); | 1391 | let speeded = project.lane(lane).iter().any(|c| !c.speed.is_normal()); |
| 1390 | if speeded || equalized(project) || mastered(project) { | 1392 | if speeded || equalized(project) || mastered(project) { |
| 1391 | - return encode_audio(project, meta, kbps, mkv, shared); | 1393 | + return encode_audio(project, meta, kbps, mkv, shared, sample_rate); |
| 1392 | } | 1394 | } |
| 1393 | // What is left is a copy the *sources* may still not be able to give: AAC | 1395 | // What is left is a copy the *sources* may still not be able to give: AAC |
| 1394 | // inside a Matroska file (readable, but not out of a sample table this walks | 1396 | // inside a Matroska file (readable, but not out of a sample table this walks |
| @@ -1408,7 +1410,7 @@ fn copy_audio( | |||
| 1408 | // (they are not in a sample table) and every one of them re-encodes. | 1410 | // (they are not in a sample table) and every one of them re-encodes. |
| 1409 | opus_pre_skip: None, | 1411 | opus_pre_skip: None, |
| 1410 | })), | 1412 | })), |
| 1411 | - Err(_) => encode_audio(project, meta, kbps, mkv, shared), | 1413 | + Err(_) => encode_audio(project, meta, kbps, mkv, shared, sample_rate), |
| 1412 | } | 1414 | } |
| 1413 | } | 1415 | } |
| 1414 | 1416 | ||
| @@ -1663,6 +1665,7 @@ fn encode_audio( | |||
| 1663 | kbps: u32, | 1665 | kbps: u32, |
| 1664 | mkv: bool, | 1666 | mkv: bool, |
| 1665 | shared: &Shared, | 1667 | shared: &Shared, |
| 1668 | + sample_rate: Option<u32>, | ||
| 1666 | ) -> crate::Result<Option<ExportAudio>> { | 1669 | ) -> crate::Result<Option<ExportAudio>> { |
| 1667 | let sources = project.audio_sources(); | 1670 | let sources = project.audio_sources(); |
| 1668 | let segs = project.audio_segments_from(0, meta.frame_rate); | 1671 | let segs = project.audio_segments_from(0, meta.frame_rate); |
| @@ -1673,13 +1676,14 @@ fn encode_audio( | |||
| 1673 | // is written, and which minutes went where is the first question asked of a | 1676 | // is written, and which minutes went where is the first question asked of a |
| 1674 | // slow export. Three lines an export, so they stay on. | 1677 | // slow export. Three lines an export, so they stay on. |
| 1675 | let mixed = std::time::Instant::now(); | 1678 | let mixed = std::time::Instant::now(); |
| 1676 | - let Some((audio, chunks)) = AudioSession::open_mixed_streams_master( | 1679 | + let Some((audio, chunks)) = AudioSession::open_mixed_streams_master_at( |
| 1677 | &sources, | 1680 | &sources, |
| 1678 | &segs, | 1681 | &segs, |
| 1679 | &eqs, | 1682 | &eqs, |
| 1680 | &speeds, | 1683 | &speeds, |
| 1681 | &project.audio_gains(), | 1684 | &project.audio_gains(), |
| 1682 | project.limiter(), | 1685 | project.limiter(), |
| 1686 | + sample_rate, | ||
| 1683 | )? | 1687 | )? |
| 1684 | else { | 1688 | else { |
| 1685 | return Ok(None); // no audio to write, exactly as a copy of nothing is | 1689 | return Ok(None); // no audio to write, exactly as a copy of nothing is |
| @@ -2138,6 +2142,7 @@ fn run( | |||
| 2138 | out: &Path, | 2142 | out: &Path, |
| 2139 | shared: &Arc<Shared>, | 2143 | shared: &Arc<Shared>, |
| 2140 | settings: &ExportSettings, | 2144 | settings: &ExportSettings, |
| 2145 | + sample_rate: Option<u32>, | ||
| 2141 | ) -> crate::Result<()> { | 2146 | ) -> crate::Result<()> { |
| 2142 | // The media's length and not the timeline's: a caption placed past the last | 2147 | // The media's length and not the timeline's: a caption placed past the last |
| 2143 | // picture holds the *timeline* open ([`Project::timeline_frames`]) and there | 2148 | // picture holds the *timeline* open ([`Project::timeline_frames`]) and there |
| @@ -2205,6 +2210,7 @@ fn run( | |||
| 2205 | audio_kbps_of(&settings), | 2210 | audio_kbps_of(&settings), |
| 2206 | settings.format.is_mkv(), | 2211 | settings.format.is_mkv(), |
| 2207 | &shared, | 2212 | &shared, |
| 2213 | + sample_rate, | ||
| 2208 | ) | 2214 | ) |
| 2209 | })? | 2215 | })? |
| 2210 | }; | 2216 | }; |
| @@ -2743,6 +2749,7 @@ fn run_audio( | |||
| 2743 | out: &Path, | 2749 | out: &Path, |
| 2744 | shared: &Shared, | 2750 | shared: &Shared, |
| 2745 | settings: &ExportSettings, | 2751 | settings: &ExportSettings, |
| 2752 | + sample_rate: Option<u32>, | ||
| 2746 | ) -> crate::Result<()> { | 2753 | ) -> crate::Result<()> { |
| 2747 | let format = settings.format; | 2754 | let format = settings.format; |
| 2748 | let sources = project.audio_sources(); | 2755 | let sources = project.audio_sources(); |
| @@ -2762,13 +2769,14 @@ fn run_audio( | |||
| 2762 | // limiter out of it. The same opener playback's feeder reads from, so a | 2769 | // limiter out of it. The same opener playback's feeder reads from, so a |
| 2763 | // file is written at the levels it was heard at -- there is no second | 2770 | // file is written at the levels it was heard at -- there is no second |
| 2764 | // place here that could mix it differently. | 2771 | // place here that could mix it differently. |
| 2765 | - let Some((audio, chunks)) = AudioSession::open_mixed_streams_master( | 2772 | + let Some((audio, chunks)) = AudioSession::open_mixed_streams_master_at( |
| 2766 | &sources, | 2773 | &sources, |
| 2767 | &segs, | 2774 | &segs, |
| 2768 | &eqs, | 2775 | &eqs, |
| 2769 | &speeds, | 2776 | &speeds, |
| 2770 | &project.audio_gains(), | 2777 | &project.audio_gains(), |
| 2771 | project.limiter(), | 2778 | project.limiter(), |
| 2779 | + sample_rate, | ||
| 2772 | )? | 2780 | )? |
| 2773 | else { | 2781 | else { |
| 2774 | return Err("this timeline has no audio to export".into()); | 2782 | return Err("this timeline has no audio to export".into()); |
crates/engine/src/playback.rsmodified+70 -1
| @@ -407,6 +407,16 @@ pub struct PlaybackSession { | |||
| 407 | /// two switches above, and read by the front end: the engine starts no | 407 | /// two switches above, and read by the front end: the engine starts no |
| 408 | /// export of its own. | 408 | /// export of its own. |
| 409 | encoder_seat: crate::export::EncoderSeat, | 409 | encoder_seat: crate::export::EncoderSeat, |
| 410 | + /// The rate this project's mix was picked to run at | ||
| 411 | + /// ([`crate::edith::Document::sample_rate`]), overriding the one the first | ||
| 412 | + /// audio source would otherwise hand the mixer. `None` -- every project | ||
| 413 | + /// before the field existed, and any project nobody has picked one for -- | ||
| 414 | + /// leaves the derived rate alone. Saved with the project like the switches | ||
| 415 | + /// above it, and read by the front end: the engine picks no rate of its own. | ||
| 416 | + /// | ||
| 417 | + /// Setting it takes effect at the next audio rebuild (a seek, an edit, a | ||
| 418 | + /// reopen); there is no live resample of an audio device already playing. | ||
| 419 | + sample_rate: Option<u32>, | ||
| 410 | } | 420 | } |
| 411 | 421 | ||
| 412 | /// What an edit dirtied -- which half of the pipeline has to be rebuilt for the | 422 | /// What an edit dirtied -- which half of the pipeline has to be rebuilt for the |
| @@ -545,6 +555,7 @@ impl PlaybackSession { | |||
| 545 | proxies: false, | 555 | proxies: false, |
| 546 | auto_proxies: true, | 556 | auto_proxies: true, |
| 547 | encoder_seat: crate::export::EncoderSeat::default(), | 557 | encoder_seat: crate::export::EncoderSeat::default(), |
| 558 | + sample_rate: None, | ||
| 548 | }) | 559 | }) |
| 549 | } | 560 | } |
| 550 | 561 | ||
| @@ -663,6 +674,7 @@ impl PlaybackSession { | |||
| 663 | proxies: false, | 674 | proxies: false, |
| 664 | auto_proxies: true, | 675 | auto_proxies: true, |
| 665 | encoder_seat: crate::export::EncoderSeat::default(), | 676 | encoder_seat: crate::export::EncoderSeat::default(), |
| 677 | + sample_rate: None, | ||
| 666 | }) | 678 | }) |
| 667 | } | 679 | } |
| 668 | 680 | ||
| @@ -745,6 +757,7 @@ impl PlaybackSession { | |||
| 745 | proxies: false, | 757 | proxies: false, |
| 746 | auto_proxies: true, | 758 | auto_proxies: true, |
| 747 | encoder_seat: crate::export::EncoderSeat::default(), | 759 | encoder_seat: crate::export::EncoderSeat::default(), |
| 760 | + sample_rate: None, | ||
| 748 | }) | 761 | }) |
| 749 | } | 762 | } |
| 750 | 763 | ||
| @@ -1053,6 +1066,7 @@ impl PlaybackSession { | |||
| 1053 | // ...and which encoder it exports with, which is the seat this | 1066 | // ...and which encoder it exports with, which is the seat this |
| 1054 | // machine has for every dialect before v14. | 1067 | // machine has for every dialect before v14. |
| 1055 | encoder_seat: doc.encoder, | 1068 | encoder_seat: doc.encoder, |
| 1069 | + sample_rate: doc.sample_rate, | ||
| 1056 | }; | 1070 | }; |
| 1057 | // The scaffolding above opened source 0 from its first frame and the | 1071 | // The scaffolding above opened source 0 from its first frame and the |
| 1058 | // whole of its audio; this puts both onto the clip the playhead is | 1072 | // whole of its audio; this puts both onto the clip the playhead is |
| @@ -1324,6 +1338,10 @@ impl PlaybackSession { | |||
| 1324 | // again after a reload. | 1338 | // again after a reload. |
| 1325 | self.encoder_seat, | 1339 | self.encoder_seat, |
| 1326 | self.project.limiter(), | 1340 | self.project.limiter(), |
| 1341 | + // ...and the rate the mix was picked to run at, for the same | ||
| 1342 | + // reason: a project delivered at a chosen rate is delivered at it | ||
| 1343 | + // again after a reload. | ||
| 1344 | + self.sample_rate, | ||
| 1327 | playhead, | 1345 | playhead, |
| 1328 | ) | 1346 | ) |
| 1329 | } | 1347 | } |
| @@ -2293,6 +2311,20 @@ impl PlaybackSession { | |||
| 2293 | self.encoder_seat = seat; | 2311 | self.encoder_seat = seat; |
| 2294 | } | 2312 | } |
| 2295 | 2313 | ||
| 2314 | + /// The rate this project's mix was picked to run at | ||
| 2315 | + /// ([`Self::set_sample_rate`]), or `None` for the rate the first audio | ||
| 2316 | + /// source derives it to. | ||
| 2317 | + pub fn sample_rate(&self) -> Option<u32> { | ||
| 2318 | + self.sample_rate | ||
| 2319 | + } | ||
| 2320 | + | ||
| 2321 | + /// Pick the mix's own rate, overriding the derived one. Nothing to reseek | ||
| 2322 | + /// here: it takes effect at the next audio rebuild (a seek, an edit, a | ||
| 2323 | + /// reopen), not on the device already playing. | ||
| 2324 | + pub fn set_sample_rate(&mut self, rate: Option<u32>) { | ||
| 2325 | + self.sample_rate = rate; | ||
| 2326 | + } | ||
| 2327 | + | ||
| 2296 | /// Whether an imported film that wants a stand-in gets one made for it | 2328 | /// Whether an imported film that wants a stand-in gets one made for it |
| 2297 | /// there and then ([`Self::set_auto_proxies`]). | 2329 | /// there and then ([`Self::set_auto_proxies`]). |
| 2298 | pub fn auto_proxies(&self) -> bool { | 2330 | pub fn auto_proxies(&self) -> bool { |
| @@ -3236,6 +3268,10 @@ impl PlaybackSession { | |||
| 3236 | // more -- the open runs on the feeder. | 3268 | // more -- the open runs on the feeder. |
| 3237 | let mixed = crate::audio::AudioSession::is_mixed(segs.len(), &gains, limiter); | 3269 | let mixed = crate::audio::AudioSession::is_mixed(segs.len(), &gains, limiter); |
| 3238 | let worker_controls = Arc::clone(&controls); | 3270 | let worker_controls = Arc::clone(&controls); |
| 3271 | + // ...and the rate the mix runs at, if the project picked one: the | ||
| 3272 | + // same override [`crate::edith::save`] writes and [`Self::open_project`] | ||
| 3273 | + // reads back. | ||
| 3274 | + let sample_rate = self.sample_rate; | ||
| 3239 | // ...and the open itself -- every track a segment names, its packet | 3275 | // ...and the open itself -- every track a segment names, its packet |
| 3240 | // table, its priming -- happens there too. That is the whole point: | 3276 | // table, its priming -- happens there too. That is the whole point: |
| 3241 | // one `pread` on a cold 25 GB film is seconds, and this is called | 3277 | // one `pread` on a cold 25 GB film is seconds, and this is called |
| @@ -3249,6 +3285,7 @@ impl PlaybackSession { | |||
| 3249 | &gains, | 3285 | &gains, |
| 3250 | limiter, | 3286 | limiter, |
| 3251 | Some(&worker_controls), | 3287 | Some(&worker_controls), |
| 3288 | + sample_rate, | ||
| 3252 | ) { | 3289 | ) { |
| 3253 | Ok(Some((_, rx))) => Some(rx), | 3290 | Ok(Some((_, rx))) => Some(rx), |
| 3254 | // A silent timeline, and a source that will not open: both | 3291 | // A silent timeline, and a source that will not open: both |
| @@ -3327,7 +3364,13 @@ impl PlaybackSession { | |||
| 3327 | out: &Path, | 3364 | out: &Path, |
| 3328 | settings: &crate::export::ExportSettings, | 3365 | settings: &crate::export::ExportSettings, |
| 3329 | ) -> crate::ExportHandle { | 3366 | ) -> crate::ExportHandle { |
| 3330 | - crate::export::start(self.project.export_snapshot(), self.meta, out, settings) | 3367 | + crate::export::start( |
| 3368 | + self.project.export_snapshot(), | ||
| 3369 | + self.meta, | ||
| 3370 | + out, | ||
| 3371 | + settings, | ||
| 3372 | + self.sample_rate, | ||
| 3373 | + ) | ||
| 3331 | } | 3374 | } |
| 3332 | 3375 | ||
| 3333 | /// Moves the clock forward; the caller runs this once per rendered frame. | 3376 | /// Moves the clock forward; the caller runs this once per rendered frame. |
| @@ -3775,6 +3818,32 @@ mod tests { | |||
| 3775 | .join(name) | 3818 | .join(name) |
| 3776 | } | 3819 | } |
| 3777 | 3820 | ||
| 3821 | + /// A picked project rate overrides the derived one, and its absence leaves | ||
| 3822 | + /// the source's own -- the seam every explicit-sample-rate caller | ||
| 3823 | + /// (playback rebuild, both export encoders) goes through | ||
| 3824 | + /// ([`crate::AudioSession::open_multi_streams_speed_at`]). The per-segment | ||
| 3825 | + /// conform chain resamples to whatever `meta` names, so the meta *is* the | ||
| 3826 | + /// behaviour. | ||
| 3827 | + #[test] | ||
| 3828 | + fn a_picked_sample_rate_overrides_the_derived_one() { | ||
| 3829 | + let file = asset("test_av.mp4"); | ||
| 3830 | + let sources = [(file, 0)]; | ||
| 3831 | + let segs = [(Some(0), 0., 1.)]; | ||
| 3832 | + let derived = crate::AudioSession::open_multi_streams_speed_at(&sources, &segs, &[], &[], None) | ||
| 3833 | + .expect("open the fixture") | ||
| 3834 | + .expect("the fixture has sound") | ||
| 3835 | + .0 | ||
| 3836 | + .sample_rate; | ||
| 3837 | + let picked = | ||
| 3838 | + crate::AudioSession::open_multi_streams_speed_at(&sources, &segs, &[], &[], Some(32000)) | ||
| 3839 | + .expect("open the fixture") | ||
| 3840 | + .expect("the fixture has sound") | ||
| 3841 | + .0 | ||
| 3842 | + .sample_rate; | ||
| 3843 | + assert_ne!(derived, 32000, "a fixture at the picked rate proves nothing"); | ||
| 3844 | + assert_eq!(picked, 32000); | ||
| 3845 | + } | ||
| 3846 | + | ||
| 3778 | /// Which source the timeline's sound is opened on -- the one rule | 3847 | /// Which source the timeline's sound is opened on -- the one rule |
| 3779 | /// [`open_project`](PlaybackSession::open_project), the probe every import | 3848 | /// [`open_project`](PlaybackSession::open_project), the probe every import |
| 3780 | /// is held to and the audio worker all read through. A still at index 0 is | 3849 | /// is held to and the audio worker all read through. A still at index 0 is |
crates/engine/src/proxy.rsmodified+3 -0
| @@ -524,6 +524,9 @@ fn started(source: &Path, only_if: fn(&VideoMeta) -> bool) -> crate::Result<Opti | |||
| 524 | bitrate: Some(bitrate), | 524 | bitrate: Some(bitrate), |
| 525 | ..Default::default() | 525 | ..Default::default() |
| 526 | }, | 526 | }, |
| 527 | + // A stand-in keeps its film's own rate: the override is the | ||
| 528 | + // timeline's affair, not the proxy's. | ||
| 529 | + None, | ||
| 527 | ); | 530 | ); |
| 528 | Ok(Some(Job { | 531 | Ok(Some(Job { |
| 529 | out, | 532 | out, |