carlos / platform Public

media: HDR video up to 1080p converts up to 75 minutes

The spike converted 1080p HDR at 2.71 times real time on the long class
against 5.85 for SDR, so the plan's rule gives 86.6 minutes for HDR,
rounded down to 75, while SDR keeps its 2 hours. Above 1080p stays 30
minutes whatever the transfer.

CARLOS_MEDIA_LIMITS gains video_max_hdr (default 75m, held to video_max).
The payload carries it as MaxHDRMS, omitted for audio, and 0 from an
older console means MaxMS. The result's source facts now say HDR, so the
console's source_too_long message names the HDR maximum with a new deck
row, media.job.source_too_long_hdr. The media page's limits and error
tables follow. New copy is pending Luna pass 6.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev f25494cad57fe2681d3984575053cc04bdec0f30 parent ca22555
14 files changed, +194 −47
  • docs/site/media-conversion.md +5 −2
  • docs/superpowers/notes/media-conversion-copy-deck.md +8 −4
  • internal/console/apimedia_test.go +19 −0
  • internal/console/media_copy.go +8 −3
  • internal/console/mediawire.go +1 −1
  • internal/media/limits.go +32 −14
  • internal/media/media_test.go +32 −12
  • internal/media/payload.go +6 −1
  • internal/media/result.go +3 −1
  • internal/mediahandler/probe.go +7 −3
  • internal/mediahandler/probe_test.go +62 −0
  • internal/mediahandler/run.go +3 −3
  • internal/mediajobs/dispatch.go +3 −2
  • internal/mediajobs/jobs_test.go +5 −1
diff --git a/docs/site/media-conversion.md b/docs/site/media-conversion.md
index 9090c54bb..efbd57ae2 100644
--- a/docs/site/media-conversion.md
+++ b/docs/site/media-conversion.md
@@ -132,7 +132,9 @@ A job is `queued` while it waits for a place, `running` while the engine works o
| `source_dimensions` | `the video is larger than %s` |
| `source_frame_rate` | `the video has more than %d frames a second` |
| `source_too_long` | `the file is longer than %s, the maximum for this preset` |
+| `source_too_long` | `the HDR video is longer than %s, the maximum for HDR video up to 1080p` |
| `needs_long_class` | `the file is longer than %s, the most the short class converts. submit it again in the long class` |
+| `needs_long_class` | `the video is larger than 1080p, which only the long class converts. submit it again in the long class` |
| `allowance_exceeded` | `this account's media allowance for the month does not cover this file. buy a media pack or move to a larger plan to convert it` |
| `unreadable` | `the file could not be read. it may be damaged or cut short` |
| `output_too_large` | `a converted file would be over 5 GB, the maximum for one output` |
@@ -194,14 +196,15 @@ Each job runs in a class. By default the source's size picks it, and you can ask
| Preset | Short class is used for | Short class converts up to | Stops a short job after | Stops a long job after |
| --- | --- | --- | --- | --- |
-| `video-720p` | sources up to 1 GiB | 10 minutes | 15 minutes | 50 minutes |
+| `video-720p` | sources up to 1 GiB | 10 minutes, up to 1080p | 15 minutes | 50 minutes |
| `audio-aac` | sources up to 256 MiB | 2 hours | 10 minutes | 50 minutes |
-A long job converts up to the preset's maximum. These maximums are provisional and may change:
+A video above 1080p converts only in the long class. The short class refuses it with `needs_long_class`, however short it is. A long job converts up to the preset's maximum:
| | `video-720p` | `audio-aac` |
| --- | --- | --- |
| Length, sources up to 1080p | 2 hours | 8 hours |
+| Length, HDR sources up to 1080p | 75 minutes | |
| Length, sources above 1080p | 30 minutes | |
| Source size | 40 GiB | 10 GiB |
| Largest picture, frame rate | 3840x2160, 60 | |
diff --git a/docs/superpowers/notes/media-conversion-copy-deck.md b/docs/superpowers/notes/media-conversion-copy-deck.md
index bd8fe7377..7556dfb41 100644
--- a/docs/superpowers/notes/media-conversion-copy-deck.md
+++ b/docs/superpowers/notes/media-conversion-copy-deck.md
@@ -81,7 +81,9 @@ object. Placeholders: `source_too_long` and `needs_long_class` take the
limit as `mediaDuration` writes it (`2 hours`, `30 minutes`, `10 minutes`);
`source_dimensions` takes the maximum as `3840x2160`; `source_frame_rate` takes the maximum frames a second. Codes
marked "door copy" reuse the door's message for the same code.
-`needs_long_class_hi` has no placeholder: it is `needs_long_class`'s
+`source_too_long_hdr` is `source_too_long`'s message when the result's
+source facts say HDR and not above 1080p; its placeholder is that
+maximum (`75 minutes` by default). `needs_long_class_hi` has no placeholder: it is `needs_long_class`'s
message when the result's source facts are above 1080p, which the short
video class refuses whatever the length (spec §11 A7).
@@ -95,6 +97,7 @@ video class refuses whatever the length (spec §11 A7).
| `media.job.source_dimensions` | `the video is larger than %s` |
| `media.job.source_frame_rate` | `the video has more than %d frames a second` |
| `media.job.source_too_long` | `the file is longer than %s, the maximum for this preset` |
+| `media.job.source_too_long_hdr` | `the HDR video is longer than %s, the maximum for HDR video up to 1080p` (pending Luna pass 6) |
| `media.job.needs_long_class` | `the file is longer than %s, the most the short class converts. submit it again in the long class` |
| `media.job.needs_long_class_hi` | `the video is larger than 1080p, which only the long class converts. submit it again in the long class` (pending Luna pass 6) |
| `media.job.allowance_exceeded` | `this account's media allowance for the month does not cover this file. buy a media pack or move to a larger plan to convert it` |
@@ -465,7 +468,7 @@ row is applied to the page verbatim.
| `docs.media.door.9` | (table, columns Status / Code / Message: one row per code; every message is its approved deck row verbatim, door copy for job codes as that table says) |
| `docs.media.jobs.1` | ## Job states and errors |
| `docs.media.jobs.2` | A job is `queued` while it waits for a place, `running` while the engine works on it, then `done` or `failed`. A failed job's answer has an `error` with a `code` and a `message`: |
-| `docs.media.jobs.3` | (table, columns Code / Message: one row per code; every message is its approved deck row verbatim, door copy for job codes as that table says) |
+| `docs.media.jobs.3` | (table, columns Code / Message: one row per message; every message is its approved deck row verbatim, door copy for job codes as that table says. `source_too_long` and `needs_long_class` each have two rows, the second for `media.job.source_too_long_hdr` and `media.job.needs_long_class_hi`) |
| `docs.media.jobs.4` | Encrypted files fail as `unsupported_container`. For `needs_long_class`, send the same `POST` again with `"class": "long"`. That is a new job. |
| `docs.media.serving.1` | ## Serving |
| `docs.media.serving.2` | The playlist names the video by the relative URL `video.mp4`, and a player looks for it beside wherever the playlist came from. So serve the playlist from your app's own origin, next to a route for the MP4, for example `/media/<id>/video.m3u8` and `/media/<id>/video.mp4`. Never redirect the playlist. |
@@ -489,11 +492,12 @@ row is applied to the page verbatim.
| `docs.media.limits.1` | ## Limits |
| `docs.media.limits.2` | Each job runs in a class. By default the source's size picks it, and you can ask for `"class": "long"`: |
| `docs.media.limits.3` | \| Preset \| Short class is used for \| Short class converts up to \| Stops a short job after \| Stops a long job after \| |
-| `docs.media.limits.4` | \| `video-720p` \| sources up to 1 GiB \| 10 minutes \| 15 minutes \| 50 minutes \| |
+| `docs.media.limits.4` | \| `video-720p` \| sources up to 1 GiB \| 10 minutes, up to 1080p \| 15 minutes \| 50 minutes \| | (pending Luna pass 6)
| `docs.media.limits.5` | \| `audio-aac` \| sources up to 256 MiB \| 2 hours \| 10 minutes \| 50 minutes \| |
-| `docs.media.limits.6` | A long job converts up to the preset's maximum. These maximums are provisional and may change: |
+| `docs.media.limits.6` | A video above 1080p converts only in the long class. The short class refuses it with `needs_long_class`, however short it is. A long job converts up to the preset's maximum: | (pending Luna pass 6)
| `docs.media.limits.7` | \| \| `video-720p` \| `audio-aac` \| |
| `docs.media.limits.8` | \| Length, sources up to 1080p \| 2 hours \| 8 hours \| |
+| `docs.media.limits.8a` | \| Length, HDR sources up to 1080p \| 75 minutes \| \| | (pending Luna pass 6)
| `docs.media.limits.9` | \| Length, sources above 1080p \| 30 minutes \| \| |
| `docs.media.limits.10` | \| Source size \| 40 GiB \| 10 GiB \| |
| `docs.media.limits.11` | \| Largest picture, frame rate \| 3840x2160, 60 \| \| |
diff --git a/internal/console/apimedia_test.go b/internal/console/apimedia_test.go
index 9a1c04b5b..be5ea48a4 100644
--- a/internal/console/apimedia_test.go
+++ b/internal/console/apimedia_test.go
@@ -3,6 +3,7 @@ package console
import (
"context"
"encoding/json"
+ "fmt"
"net/http"
"strings"
"sync"
@@ -644,6 +645,24 @@ func TestGetFailedMessageComesFromTheDeck(t *testing.T) {
r.job.Error.Message != "the file is longer than 10 minutes, the most the short class converts. submit it again in the long class" {
t.Fatalf("needs_long_class: %s", r.raw)
}
+ // An HDR source up to 1080p over its own maximum (spec §11 A7): the
+ // handler's failure result for an 80-minute HLG 1080p source, named
+ // with the HDR maximum, not the SDR one.
+ hdrProbe := []byte(`{"streams":[{"index":0,"codec_type":"video","codec_name":"hevc","width":1920,"height":1080,` +
+ `"avg_frame_rate":"30/1","r_frame_rate":"30/1","color_transfer":"arib-std-b67"}],"format":{"duration":"4800.000000"}}`)
+ hdrLong, refused := mediahandler.ProbeFailure("0123456789abcdef0123456789abcdef", media.PresetVideo720p, media.JobLimits{
+ SourceBytes: l.VideoBytes, GrantedMS: l.VideoMax.Milliseconds(), GrantedBy: "class",
+ MaxMS: l.VideoMax.Milliseconds(), MaxHDRMS: l.MaxHDR().Milliseconds(), MaxHiMS: l.VideoMaxHi.Milliseconds(), OutputBytes: media.MaxPutBytes,
+ }, hdrProbe)
+ if !refused || hdrLong.Error != media.CodeSourceTooLong {
+ t.Fatalf("the handler's probe check answered %+v, refused %v", hdrLong, refused)
+ }
+ fail("source_too_long", hdrLong)
+ if tmpl := mediaCopy["media.job.source_too_long_hdr"]; tmpl == "" {
+ t.Fatal("the deck has no media.job.source_too_long_hdr row")
+ } else if r := f.get(sub.job.ID); r.job.Error == nil || r.job.Error.Message != fmt.Sprintf(tmpl, "75 minutes") {
+ t.Fatalf("source_too_long for HDR: %s", r.raw)
+ }
// A short-class job whose source is above 1080p (spec §11 A7): the
// handler's own failure result for a 30-second 2160p source, and the
// deck's row that names the picture size, not a length.
diff --git a/internal/console/media_copy.go b/internal/console/media_copy.go
index 1ecbb92f6..4bcf81f00 100644
--- a/internal/console/media_copy.go
+++ b/internal/console/media_copy.go
@@ -66,6 +66,7 @@ var mediaCopy = map[string]string{
"media.job.source_dimensions": "the video is larger than %s",
"media.job.source_frame_rate": "the video has more than %d frames a second",
"media.job.source_too_long": "the file is longer than %s, the maximum for this preset",
+ "media.job.source_too_long_hdr": "the HDR video is longer than %s, the maximum for HDR video up to 1080p",
"media.job.needs_long_class": "the file is longer than %s, the most the short class converts. submit it again in the long class",
"media.job.needs_long_class_hi": "the video is larger than 1080p, which only the long class converts. submit it again in the long class",
"media.job.allowance_exceeded": "this account's media allowance for the month does not cover this file. buy a media pack or move to a larger plan to convert it",
@@ -148,11 +149,15 @@ func mediaJobMessage(j mediajobs.Job, l media.Limits) string {
case media.CodeSourceFrameRate:
return mediaText(key, media.MaxFPS)
case media.CodeSourceTooLong:
- w, h := 0, 0
+ w, h, hdr := 0, 0, false
if s := jobSource(j); s != nil {
- w, h = s.Width, s.Height
+ w, h, hdr = s.Width, s.Height, s.HDR
}
- return mediaText(key, mediaDuration(l.MaxDuration(j.Preset, w, h)))
+ if j.Preset == media.PresetVideo720p && hdr && !media.Above1080p(w, h) {
+ // HDR up to 1080p has its own maximum (spec §11 A7).
+ key = "media.job.source_too_long_hdr"
+ }
+ return mediaText(key, mediaDuration(l.MaxDuration(j.Preset, w, h, hdr)))
case media.CodeNeedsLongClass:
// The short video class refuses a source above 1080p whatever
// its length (spec §11 A7); the result's facts say which.
diff --git a/internal/console/mediawire.go b/internal/console/mediawire.go
index 175870053..1d7ad7ae7 100644
--- a/internal/console/mediawire.go
+++ b/internal/console/mediawire.go
@@ -212,7 +212,7 @@ func (s *Server) mediaAccountGone(ctx context.Context, account string) (bool, er
// limit). media.ParseLimits gives only such limits; this holds for a
// Config built any other way.
func validMediaLimits(l media.Limits) error {
- ok := l.VideoMax > 0 && l.VideoMaxHi > 0 && l.AudioMax > 0 && l.VideoBytes > 0 && l.AudioBytes > 0 &&
+ ok := l.VideoMax > 0 && l.VideoMaxHDR > 0 && l.VideoMaxHi > 0 && l.AudioMax > 0 && l.VideoBytes > 0 && l.AudioBytes > 0 &&
l.AccountMinutes >= 0 && l.Short > 0 && l.Long > 0 && l.AccountShort > 0 && l.AccountLong > 0 &&
l.AccountActive > 0 && l.PerMinute > 0 && l.Burst > 0 && l.Queue > 0
if !ok {
diff --git a/internal/media/limits.go b/internal/media/limits.go
index 0e8891dce..57bcaa377 100644
--- a/internal/media/limits.go
+++ b/internal/media/limits.go
@@ -10,21 +10,27 @@ import (
// Limits are a deployment's media settings (CARLOS_MEDIA_LIMITS): the
// per-file maximums (spec §7.1), the per-account allowance used when there
// is no plan catalog (§7.3), and the fair-use figures (§7.2).
+//
+// VideoMaxHDR is the maximum for an HDR video source up to 1080p, held to
+// VideoMax (MaxHDR): the spike converted 1080p HDR at 2.71 times real
+// time on the long class, against 5.85 for SDR, so two hours of it do not
+// fit the class's 40-minute budget (spec §11 A7).
type Limits struct {
- VideoMax, VideoMaxHi, AudioMax time.Duration
- VideoBytes, AudioBytes int64
- AccountMinutes int64
- Short, Long int
- AccountShort, AccountLong int
- AccountActive int
- PerMinute, Burst int
- Queue int
+ VideoMax, VideoMaxHDR, VideoMaxHi, AudioMax time.Duration
+ VideoBytes, AudioBytes int64
+ AccountMinutes int64
+ Short, Long int
+ AccountShort, AccountLong int
+ AccountActive int
+ PerMinute, Burst int
+ Queue int
}
// DefaultLimits is what ParseLimits("") gives.
func DefaultLimits() Limits {
return Limits{
VideoMax: 2 * time.Hour,
+ VideoMaxHDR: 75 * time.Minute,
VideoMaxHi: 30 * time.Minute,
VideoBytes: 40 << 30,
AudioMax: 8 * time.Hour,
@@ -52,9 +58,10 @@ func ParseLimits(v string) (Limits, error) {
return l, nil
}
durations := map[string]*time.Duration{
- "video_max": &l.VideoMax,
- "video_max_hi": &l.VideoMaxHi,
- "audio_max": &l.AudioMax,
+ "video_max": &l.VideoMax,
+ "video_max_hdr": &l.VideoMaxHDR,
+ "video_max_hi": &l.VideoMaxHi,
+ "audio_max": &l.AudioMax,
}
sizes := map[string]*int64{
"video_bytes": &l.VideoBytes,
@@ -144,15 +151,26 @@ func (l Limits) MaxBytes(preset string) int64 {
return 0
}
+// MaxHDR is the maximum for an HDR video source up to 1080p: VideoMaxHDR,
+// held to VideoMax.
+func (l Limits) MaxHDR() time.Duration {
+ return min(l.VideoMaxHDR, l.VideoMax)
+}
+
// MaxDuration is the longest source the preset converts: for video,
-// VideoMaxHi when the source is above 1080p (Above1080p), else VideoMax;
-// for audio, AudioMax. It fills the deck's media.job.source_too_long.
-func (l Limits) MaxDuration(preset string, width, height int) time.Duration {
+// VideoMaxHi when the source is above 1080p (Above1080p), whatever its
+// transfer; else MaxHDR for an HDR source; else VideoMax. For audio,
+// AudioMax. It fills the deck's media.job.source_too_long and
+// source_too_long_hdr.
+func (l Limits) MaxDuration(preset string, width, height int, hdr bool) time.Duration {
switch preset {
case PresetVideo720p:
if Above1080p(width, height) {
return l.VideoMaxHi
}
+ if hdr {
+ return l.MaxHDR()
+ }
return l.VideoMax
case PresetAudioAAC:
return l.AudioMax
diff --git a/internal/media/media_test.go b/internal/media/media_test.go
index c5999afce..2d3ebcf6f 100644
--- a/internal/media/media_test.go
+++ b/internal/media/media_test.go
@@ -170,7 +170,7 @@ func TestParseLimits(t *testing.T) {
t.Fatal(err)
}
want := Limits{
- VideoMax: 2 * time.Hour, VideoMaxHi: 30 * time.Minute, VideoBytes: 40 << 30,
+ VideoMax: 2 * time.Hour, VideoMaxHDR: 75 * time.Minute, VideoMaxHi: 30 * time.Minute, VideoBytes: 40 << 30,
AudioMax: 8 * time.Hour, AudioBytes: 10 << 30, AccountMinutes: 0,
Short: 6, Long: 2, AccountShort: 2, AccountLong: 1, AccountActive: 20,
PerMinute: 30, Burst: 10, Queue: 200,
@@ -187,15 +187,15 @@ func TestParseLimits(t *testing.T) {
if two != w2 {
t.Fatalf("overrides = %+v, want %+v", two, w2)
}
- all, err := ParseLimits("video_max=90m, video_max_hi=20m,video_bytes=512MiB,audio_max=4h,audio_bytes=1048576,account_minutes=600,short=4,long=1,account_short=3,account_long=2,account_active=5,per_minute=6,burst=2,queue=50")
+ all, err := ParseLimits("video_max=90m, video_max_hdr=45m, video_max_hi=20m,video_bytes=512MiB,audio_max=4h,audio_bytes=1048576,account_minutes=600,short=4,long=1,account_short=3,account_long=2,account_active=5,per_minute=6,burst=2,queue=50")
if err != nil {
t.Fatal(err)
}
- wAll := Limits{VideoMax: 90 * time.Minute, VideoMaxHi: 20 * time.Minute, VideoBytes: 512 << 20, AudioMax: 4 * time.Hour, AudioBytes: 1 << 20, AccountMinutes: 600, Short: 4, Long: 1, AccountShort: 3, AccountLong: 2, AccountActive: 5, PerMinute: 6, Burst: 2, Queue: 50}
+ wAll := Limits{VideoMax: 90 * time.Minute, VideoMaxHDR: 45 * time.Minute, VideoMaxHi: 20 * time.Minute, VideoBytes: 512 << 20, AudioMax: 4 * time.Hour, AudioBytes: 1 << 20, AccountMinutes: 600, Short: 4, Long: 1, AccountShort: 3, AccountLong: 2, AccountActive: 5, PerMinute: 6, Burst: 2, Queue: 50}
if all != wAll {
t.Fatalf("every key = %+v, want %+v", all, wAll)
}
- for _, bad := range []string{"bogus=1", "short=0", "video_max=1h,video_max=2h", "video_bytes=-1", "account_minutes=-1", "video_max=0s", "video_max", "queue=x", "audio_bytes=3TiB"} {
+ for _, bad := range []string{"bogus=1", "short=0", "video_max=1h,video_max=2h", "video_max_hdr=0s", "video_bytes=-1", "account_minutes=-1", "video_max=0s", "video_max", "queue=x", "audio_bytes=3TiB"} {
if _, err := ParseLimits(bad); err == nil {
t.Errorf("ParseLimits(%q) = nil error", bad)
}
@@ -208,24 +208,44 @@ func TestParseLimits(t *testing.T) {
}
}
+// TestMaxDuration: 2 hours for SDR up to 1080p, 75 minutes for HDR up to
+// 1080p (the spike's 1080p HDR ran at 2.71 times real time on the long
+// class, spec §11 A7), 30 minutes above 1080p whatever the transfer.
func TestMaxDuration(t *testing.T) {
l := DefaultLimits()
for _, c := range []struct {
preset string
w, h int
+ hdr bool
want time.Duration
}{
- {PresetVideo720p, 1920, 1080, 2 * time.Hour},
- {PresetVideo720p, 1080, 1920, 2 * time.Hour},
- {PresetVideo720p, 2560, 1440, 30 * time.Minute},
- {PresetVideo720p, 1440, 2560, 30 * time.Minute},
- {PresetVideo720p, 1921, 800, 30 * time.Minute},
- {PresetAudioAAC, 0, 0, 8 * time.Hour},
+ {PresetVideo720p, 1920, 1080, false, 2 * time.Hour},
+ {PresetVideo720p, 1080, 1920, false, 2 * time.Hour},
+ {PresetVideo720p, 1920, 1080, true, 75 * time.Minute},
+ {PresetVideo720p, 1080, 1920, true, 75 * time.Minute},
+ {PresetVideo720p, 2560, 1440, false, 30 * time.Minute},
+ {PresetVideo720p, 1440, 2560, false, 30 * time.Minute},
+ {PresetVideo720p, 3840, 2160, true, 30 * time.Minute},
+ {PresetVideo720p, 1921, 800, false, 30 * time.Minute},
+ {PresetAudioAAC, 0, 0, false, 8 * time.Hour},
+ {PresetAudioAAC, 0, 0, true, 8 * time.Hour},
} {
- if got := l.MaxDuration(c.preset, c.w, c.h); got != c.want {
- t.Errorf("MaxDuration(%s, %dx%d) = %s, want %s", c.preset, c.w, c.h, got, c.want)
+ if got := l.MaxDuration(c.preset, c.w, c.h, c.hdr); got != c.want {
+ t.Errorf("MaxDuration(%s, %dx%d, hdr %v) = %s, want %s", c.preset, c.w, c.h, c.hdr, got, c.want)
}
}
+ // An HDR maximum over the SDR one is held to it.
+ short := l
+ short.VideoMax = time.Hour
+ if got := short.MaxDuration(PresetVideo720p, 1920, 1080, true); got != time.Hour {
+ t.Errorf("HDR maximum with video_max=1h: %s, want 1h", got)
+ }
+ if got := short.MaxHDR(); got != time.Hour {
+ t.Errorf("MaxHDR with video_max=1h: %s, want 1h", got)
+ }
+ if got := l.MaxHDR(); got != 75*time.Minute {
+ t.Errorf("MaxHDR: %s, want 75m", got)
+ }
}
func TestEphemeralGiB(t *testing.T) {
diff --git a/internal/media/payload.go b/internal/media/payload.go
index 443803c24..ee1bbf3b8 100644
--- a/internal/media/payload.go
+++ b/internal/media/payload.go
@@ -99,6 +99,10 @@ func SplitPresigned(raw string) (base, shared, rest string, err error) {
// JobLimits are the limits the codec enforces on one execution.
//
+// MaxHDRMS is the maximum for an HDR video source up to 1080p
+// (Limits.MaxHDR); 0, as an older console sends it, means MaxMS. The codec
+// holds it to MaxMS either way.
+//
// Above1080pNeedsLong is set on a video class that does not take a source
// above 1080p (ClassSpec.TakesAbove1080p false: the short video class).
// The codec then answers needs_long_class for such a source, after the
@@ -109,7 +113,8 @@ type JobLimits struct {
GrantedMS int64 `json:"g"`
GrantedBy string `json:"gb"` // "class" | "allowance"
MaxMS int64 `json:"d"`
- MaxHiMS int64 `json:"dh"` // video sources above 1080p; 0 for audio
+ MaxHDRMS int64 `json:"dr,omitempty"` // HDR video sources up to 1080p; 0 for audio
+ MaxHiMS int64 `json:"dh"` // video sources above 1080p; 0 for audio
OutputBytes int64 `json:"o"`
Above1080pNeedsLong bool `json:"hl,omitempty"`
}
diff --git a/internal/media/result.go b/internal/media/result.go
index ddf1db0d0..9bc7742bc 100644
--- a/internal/media/result.go
+++ b/internal/media/result.go
@@ -12,13 +12,15 @@ import (
// ResultVersion is the result object's schema version.
const ResultVersion = 1
-// SourceFacts are what the codec's probe found.
+// SourceFacts are what the codec's probe found. HDR is set for an HDR
+// video source (spec §11 A7: the console names its maximum from it).
type SourceFacts struct {
DurationMS int64 `json:"duration_ms"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
VideoCodec string `json:"video_codec,omitempty"`
AudioCodec string `json:"audio_codec,omitempty"`
+ HDR bool `json:"hdr,omitempty"`
}
// OutputFact is one uploaded output.
diff --git a/internal/mediahandler/probe.go b/internal/mediahandler/probe.go
index 0481b654c..967e1af21 100644
--- a/internal/mediahandler/probe.go
+++ b/internal/mediahandler/probe.go
@@ -537,8 +537,9 @@ func allDigits(s string) bool {
// media.MaxDimensions: source_dimensions (no positive size:
// unreadable);
// 5. (video-720p) over media.MaxFPS: source_frame_rate;
-// 6. longer than MaxHiMS (video above 1080p, media.Above1080p) or
-// MaxMS: source_too_long (no positive duration: unreadable);
+// 6. longer than MaxHiMS (video above 1080p, media.Above1080p), else
+// MaxHDRMS (an HDR video; 0 is MaxMS, and it is held to MaxMS),
+// else MaxMS: source_too_long (no positive duration: unreadable);
// 7. (video-720p) above 1080p when Above1080pNeedsLong (the short
// class, spec §11 A7): needs_long_class;
// 8. longer than GrantedMS: needs_long_class when the class granted
@@ -578,8 +579,11 @@ func check(f probeFacts, preset string, l media.JobLimits) error {
}
hi := video && media.Above1080p(f.Width, f.Height)
maxMS := l.MaxMS
- if hi {
+ switch {
+ case hi:
maxMS = l.MaxHiMS
+ case video && f.HDR && l.MaxHDRMS > 0:
+ maxMS = min(l.MaxHDRMS, l.MaxMS)
}
if f.DurationMS > maxMS {
return jobError{media.CodeSourceTooLong}
diff --git a/internal/mediahandler/probe_test.go b/internal/mediahandler/probe_test.go
index 8cad4fb55..7f95bd7bf 100644
--- a/internal/mediahandler/probe_test.go
+++ b/internal/mediahandler/probe_test.go
@@ -313,6 +313,38 @@ func TestCheckTable(t *testing.T) {
l.Above1080pNeedsLong = true
f.Width, f.Height = 3840, 2160
}, ""},
+ // HDR up to 1080p has its own maximum (spec §11 A7).
+ {"hdr 1080p over the hdr maximum", video, func(f *probeFacts, l *media.JobLimits) {
+ l.MaxHDRMS = 4500000
+ f.HDR, f.DurationMS = true, 4500001
+ }, media.CodeSourceTooLong},
+ {"hdr 1080p at the hdr maximum", video, func(f *probeFacts, l *media.JobLimits) {
+ l.MaxHDRMS = 4500000
+ f.HDR, f.DurationMS = true, 4500000
+ }, ""},
+ {"sdr 1080p past the hdr maximum", video, func(f *probeFacts, l *media.JobLimits) {
+ l.MaxHDRMS = 4500000
+ f.DurationMS = 4500001
+ }, ""},
+ {"hdr above 1080p uses the hi maximum", video, func(f *probeFacts, l *media.JobLimits) {
+ l.MaxHDRMS = 4500000
+ f.HDR, f.Width, f.Height, f.DurationMS = true, 3840, 2160, l.MaxHiMS+1
+ }, media.CodeSourceTooLong},
+ {"hdr above 1080p at the hi maximum", video, func(f *probeFacts, l *media.JobLimits) {
+ l.MaxHDRMS = 4500000
+ f.HDR, f.Width, f.Height, f.DurationMS = true, 3840, 2160, l.MaxHiMS
+ }, ""},
+ {"no hdr maximum in the payload is the maximum", video, func(f *probeFacts, l *media.JobLimits) {
+ f.HDR, f.DurationMS = true, l.MaxMS
+ }, ""},
+ {"hdr maximum over the maximum is held to it", video, func(f *probeFacts, l *media.JobLimits) {
+ l.MaxHDRMS = l.MaxMS + 60000
+ f.HDR, f.DurationMS = true, l.MaxMS+1
+ }, media.CodeSourceTooLong},
+ {"audio has no hdr maximum", audio, func(f *probeFacts, l *media.JobLimits) {
+ l.MaxHDRMS = 60000
+ f.HDR, f.DurationMS = true, 60001
+ }, ""},
{"over the class grant", video, func(f *probeFacts, l *media.JobLimits) { l.GrantedMS = 600000; f.DurationMS = 600001 }, media.CodeNeedsLongClass},
{"at the class grant", video, func(f *probeFacts, l *media.JobLimits) { l.GrantedMS = 600000; f.DurationMS = 600000 }, ""},
{"over the allowance", audio, func(f *probeFacts, l *media.JobLimits) {
@@ -843,3 +875,33 @@ func TestCodecWhitelistMatchesTheChecks(t *testing.T) {
t.Errorf("the fixtures' provenance is not recorded: %v", err)
}
}
+
+// TestSourceFactsNameHDR (spec §11 A7): the result's source facts say
+// whether the video is HDR, on a refusal and on a success, so the console
+// can name the HDR maximum; an SDR video and an audio job say nothing.
+func TestSourceFactsNameHDR(t *testing.T) {
+ hdr := goodVideo()
+ hdr.HDR, hdr.VideoCodec = true, "hevc"
+ if s := errorFacts(hdr, media.PresetVideo720p); s == nil || !s.HDR {
+ t.Errorf("errorFacts of an HDR video: %+v", s)
+ }
+ if s := sourceFacts(hdr, media.PresetVideo720p, 1000); !s.HDR {
+ t.Errorf("sourceFacts of an HDR video: %+v", s)
+ }
+ if s := sourceFacts(goodVideo(), media.PresetVideo720p, 1000); s.HDR {
+ t.Errorf("sourceFacts of an SDR video: %+v", s)
+ }
+ if s := sourceFacts(hdr, media.PresetAudioAAC, 1000); s.HDR {
+ t.Errorf("sourceFacts of an audio job: %+v", s)
+ }
+ // The probe JSON of an HLG 1080p source over the HDR maximum, through
+ // the handler's own failure construction.
+ probe := []byte(`{"streams":[{"index":0,"codec_type":"video","codec_name":"hevc","width":1920,"height":1080,` +
+ `"avg_frame_rate":"30/1","r_frame_rate":"30/1","color_transfer":"arib-std-b67"}],"format":{"duration":"4800.000000"}}`)
+ l := limitsFor(media.PresetVideo720p)
+ l.MaxHDRMS = 4500000
+ r, refused := ProbeFailure(testExec, media.PresetVideo720p, l, probe)
+ if !refused || r.Error != media.CodeSourceTooLong || r.Source == nil || !r.Source.HDR {
+ t.Fatalf("ProbeFailure = %+v, %v", r, refused)
+ }
+}
diff --git a/internal/mediahandler/run.go b/internal/mediahandler/run.go
index ed81b496a..b6e605e15 100644
--- a/internal/mediahandler/run.go
+++ b/internal/mediahandler/run.go
@@ -233,12 +233,12 @@ func failureResult(execution, code string, facts *media.SourceFacts) media.Resul
// sourceFacts are the result's source facts: the converted duration
// (spec A2: what the job is charged for, at most the grant), the
-// source's stored dimensions and video codec (video-720p), and its
-// audio codec when it has audio.
+// source's stored dimensions, video codec and whether it is HDR
+// (video-720p), and its audio codec when it has audio.
func sourceFacts(f probeFacts, preset string, durationMS int64) *media.SourceFacts {
s := &media.SourceFacts{DurationMS: durationMS}
if preset == media.PresetVideo720p && f.VideoIndex >= 0 {
- s.Width, s.Height, s.VideoCodec = f.Width, f.Height, f.VideoCodec
+ s.Width, s.Height, s.VideoCodec, s.HDR = f.Width, f.Height, f.VideoCodec, f.HDR
}
if f.AudioIndex >= 0 {
s.AudioCodec = f.AudioCodec
diff --git a/internal/mediajobs/dispatch.go b/internal/mediajobs/dispatch.go
index 614fdc31c..648badc2f 100644
--- a/internal/mediajobs/dispatch.go
+++ b/internal/mediajobs/dispatch.go
@@ -361,9 +361,9 @@ func (j *Jobs) launch(ctx context.Context, l *Launch, now time.Time) (started bo
}
return false, ErrLaunchStale
}
- maxMS, maxHiMS, hiNeedsLong := j.d.Limits.AudioMax.Milliseconds(), int64(0), false
+ maxMS, maxHDRMS, maxHiMS, hiNeedsLong := j.d.Limits.AudioMax.Milliseconds(), int64(0), int64(0), false
if job.Preset == media.PresetVideo720p {
- maxMS, maxHiMS = j.d.Limits.VideoMax.Milliseconds(), j.d.Limits.VideoMaxHi.Milliseconds()
+ maxMS, maxHDRMS, maxHiMS = j.d.Limits.VideoMax.Milliseconds(), j.d.Limits.MaxHDR().Milliseconds(), j.d.Limits.VideoMaxHi.Milliseconds()
spec, _ := media.Class(media.ClassKey{Preset: job.Preset, Class: job.Class})
hiNeedsLong = !spec.TakesAbove1080p
}
@@ -374,6 +374,7 @@ func (j *Jobs) launch(ctx context.Context, l *Launch, now time.Time) (started bo
GrantedMS: job.GrantedS * 1000,
GrantedBy: l.grantedBy,
MaxMS: maxMS,
+ MaxHDRMS: maxHDRMS,
MaxHiMS: maxHiMS,
OutputBytes: media.MaxPutBytes,
// The short video class takes nothing above 1080p (A7).
diff --git a/internal/mediajobs/jobs_test.go b/internal/mediajobs/jobs_test.go
index 8af8b808f..7a55dbee1 100644
--- a/internal/mediajobs/jobs_test.go
+++ b/internal/mediajobs/jobs_test.go
@@ -615,7 +615,8 @@ func TestDispatchFitsTheReservation(t *testing.T) {
if len(req) != 1 || json.Unmarshal(req[0].Payload, &p) != nil || p.Limits.GrantedMS != 3300000 || p.Limits.GrantedBy != grantedByAllowance || req[0].DeadlineS != 3000 {
t.Fatalf("payload limits %+v", p.Limits)
}
- if p.Limits.MaxMS != h.limits.VideoMax.Milliseconds() || p.Limits.MaxHiMS != h.limits.VideoMaxHi.Milliseconds() || p.Limits.SourceBytes != h.limits.VideoBytes || p.Limits.OutputBytes != media.MaxPutBytes {
+ if p.Limits.MaxMS != h.limits.VideoMax.Milliseconds() || p.Limits.MaxHiMS != h.limits.VideoMaxHi.Milliseconds() || p.Limits.SourceBytes != h.limits.VideoBytes || p.Limits.OutputBytes != media.MaxPutBytes ||
+ p.Limits.MaxHDRMS != (75*time.Minute).Milliseconds() {
t.Fatalf("payload limits %+v", p.Limits)
}
if err := p.Validate(); err != nil {
@@ -1824,6 +1825,9 @@ func TestShortVideoRefusesAbove1080p(t *testing.T) {
if len(req) != 1 || json.Unmarshal(req[0].Payload, &p) != nil {
t.Fatalf("%s: no payload", c.key)
}
+ if c.preset == audio && p.Limits.MaxHDRMS != 0 {
+ t.Errorf("%s: an audio payload carries an HDR maximum %d", c.key, p.Limits.MaxHDRMS)
+ }
if p.Limits.Above1080pNeedsLong != c.want {
t.Errorf("%s (%s): Above1080pNeedsLong %v, want %v", c.key, r.Class, p.Limits.Above1080pNeedsLong, c.want)
}