News for hackers. Stuff that matters.
Re:The Case of the Extra 40ms by nemothekid on Monday December 14, 2020 @11:25PM (#25426990)
>If you're doing real time audio, your processing loop needs to be directly driven by audio hardware buffer events/interrupts

Is this realistic? I don't know much about providing software for a wide range of hardware, but I would imagine this would require either Netflix or the integrator to write drivers for Netflix to communicate to the hardware dsp right (or standardize)? It seems more feasible to piggyback on a platform that has done that already and is already widely deployed.

Re:The Case of the Extra 40ms by asdfasgasdgasdg on Monday December 14, 2020 @11:32PM (#25427026)
If I'm reading correctly, they're saying that Netflix is not doing realtime audio, so they need not have this level of precision. They should buffer more than 40ms of audio data.
Re:The Case of the Extra 40ms by scoutt on Tuesday December 15, 2020 @11:33AM (#25431835)
I think they are doing so ("The Netflix application is complex, but at its simplest it streams data from a Netflix server, buffers several seconds worth of video and audio data on the device").

The system was built to fill the (hardware) buffers for 15ms worth of audio. The problem is that the 15ms window was not invoked in time (sometimes it took 40ms). Some suggested Netflix that in that case they could fill audio data for 40ms into the HW, but they didn't wanted to because it required low-level modifications.

Re:The Case of the Extra 40ms by tomnipotent on Monday December 14, 2020 @11:58PM (#25427170)
Except buffering wasn't the problem, an OS-managed thread was.
Re:The Case of the Extra 40ms by wolrah on Tuesday December 15, 2020 @12:17AM (#25427273)
The reason it caused a problem is because Netflix wasn't loading more than a frame worth of data at a time. That's a strategy that makes sense for a game streaming app like Stadia or Steam Link where every frame of latency matters, but for a movie/TV streaming app it really doesn't.

The point is that there was never any good reason to make the Netflix app so timing-dependent. Had Netflix not done this they wouldn't have even noticed.

---

That said, if a company was releasing an Android 5.0 powered device in late 2017 when Android 8.0 had already been released I can't help but say they brought this on themselves by being idiotically out of date. There's no excuse for launching a device with an OS three years and three versions out of date.

Everybody in this story is doing really dumb things.

Re:The Case of the Extra 40ms by tomnipotent on Tuesday December 15, 2020 @12:32AM (#25427348)
> wasn't loading more than a frame worth of data at a time

So the real question should be, does Netflix have a valid reason for only delivering a single frame of video and audio at a time? Is it bad software design, or good software design for an unknown problem (to us)?

I've seen plenty of things that looked stupid out of context, then made sense later on after understanding why the "stupid" things was done in the first place.

Re:The Case of the Extra 40ms by csharptwdec19 on Tuesday December 15, 2020 @10:20AM (#25431059)
Stupid thought, especially thinking about Netflix's history as one of the earliest services that streamed licensed content, it would not surprise me if this was at some point a way to minimize how much unencrypted data was in memory or similar.

Other thought would be, whether the architecture was somehow related to how one had to do things in Silverlight (any silverlight devs still remember how one would do this sort of thing? Any Silverlight devs still around?)

Re:The Case of the Extra 40ms by jfim on Tuesday December 15, 2020 @01:20AM (#25427561)
It's probably easier to keep the audio and video in sync with a simple implementation. They can't really drift out of sync if all that's being one is handling one frame at a time.
Re:The Case of the Extra 40ms by ghusbands on Tuesday December 15, 2020 @02:16AM (#25427831)
Though it sounds like they aren't even getting that advantage, because the audio thread is separate, and the described problem is starvation of the audio buffer alone.
Re:The Case of the Extra 40ms by Closi on Tuesday December 15, 2020 @02:56AM (#25428042)
It probably makes it easier to implement things like variable frame rates.
Re:The Case of the Extra 40ms by andi999 on Tuesday December 15, 2020 @06:55AM (#25429429)
"There's no excuse for launching a device with an OS three years and three versions out of date." Really? Why not? I mean if you only launch for the newest OS version, you cut out a lot of devices which were not or cannot be upgraded. Maybe in the US this is not a problem, but in Europe I wouldnt be surprised if this were actually a larger than 50% market share you cut out.
Re:The Case of the Extra 40ms by wolrah on Tuesday December 15, 2020 @03:19PM (#25434669)
You have misunderstood. The hardware device that was misbehaving had not yet been released to the public, yet it was running an ancient and out-of-date OS build. That's what I'm saying is idiotic.

Netflix can and should support their software on as old of OS releases as makes sense for them, but a hardware vendor introducing a new device to market on an outdated OS is inexcusable. Android 5.x received its final update in early 2015, over two full years before this mystery TV box was to be released. There is no good reason it couldn't have been on Android 7 or 8.

Re:The Case of the Extra 40ms by PaulDavisThe1st on Tuesday December 15, 2020 @12:15AM (#25427266)
It was the interaction between the expected amount of required buffering and the thread scheduling behavior that caused the problem. As typically happens when there's a video programmer around, the audio timing is considered less important, and there's a belief that "we can always get the audio we need for the video". Ergo, not much need for buffering. In this case, the odd/incorrect behavior of the thread scheduler exposed the optimistic assumption that you can rely on waking up every 15ms and handling the audio.
Re:The Case of the Extra 40ms by marcan_42 on Tuesday December 15, 2020 @01:03AM (#25427479)
And further, video latency is much less noticeable than audio latency. ~nobody will notice one dropped frame, but ~everyone will notice 16ms of audio missing, because you get a blatant click. Therefore, it is always important to prioritize audio buffering over video buffering.
Re:The Case of the Extra 40ms by gpderetta on Tuesday December 15, 2020 @05:12AM (#25428788)
oh, yes, I had to use some videoconferencing software recently that appears to drop audio before video. It was basically unusable.
Re:The Case of the Extra 40ms by amluto on Monday December 14, 2020 @11:44PM (#25427096)
I see no reason that interrupts are need at all. On a properly working system, the system clock will track the audio clock quite well. If the audio hardware tells you that it will need more data in x ms, it will be very close to x ms as seen by the CPU. If you use a deadline scheduler, you don’t want to wait for an interrupt — you tell the scheduler that you need to run before a specific deadline, and that that. A hardware interrupt is pure overhead, especially on platforms like x86 with silly interrupt latency.

(A good kernel can account for the time it takes to wake from idle and compensate when programming a timer (as could a good CPU, but I’ve never heard of hardware that does this) and can wake a user program a bit early if the CPU is otherwise idle and would take a short nap. A sound hardware interrupt can’t do these tricks.)

Re:The Case of the Extra 40ms by PaulDavisThe1st on Tuesday December 15, 2020 @12:12AM (#25427244)
This is both true and false at the same time.

(1) It is absolutely not true that the system clock will track the audio clock "quite well". Real world numbers would typically involve drift measurable in seconds within a low integer number of hours.

(2) It absolutely is true that on most sensible audio interface designs, you don't need interrupts except early after device open. At that point, you use them to set up a DLL (Delay Locked Loop) that will enable you to use the system clock to know where the audio hardware is reading/writing to in the buffer used to move data to/from the hardware. Once the DLL is correctly configured, you can just be woken by the system timer, determine the current audio hardware state and read/write data appropriately.

Re:The Case of the Extra 40ms by marcan_42 on Tuesday December 15, 2020 @01:05AM (#25427494)
But on (2): unless you're a low level app directly driving the hardware, you shouldn't do this. And you especially shouldn't do this without good guarantees that system timers are indeed well behaved. Effectively, using a DLL and system timers instead of straight IRQs is a low level implementation detail, but that belongs either in the driver or in a very low level piece of code anyway (like JACK or some other audio daemon), not user applications. I was sort of throwing all of this together when I said hardware "events"; locking a DLL with a different time base to the playback hardware buffer pointer stats is still effectively that, and should be done, but only at a level low enough where you know it'll work. Which definitely isn't Android's high level thread scheduling framework.
Re:The Case of the Extra 40ms by amluto on Tuesday December 15, 2020 @02:10PM (#25433797)
For (1), by “quite well” I mean well enough to avoid buffer underruns. So I think we agree.
Re:The Case of the Extra 40ms by PaulDavisThe1st on Tuesday December 15, 2020 @04:04PM (#25435249)
No, we don't agree. The drift will exceed the buffer size is less than an hour, or certainly could with many hardware configurations.
Re:The Case of the Extra 40ms by FpUser on Tuesday December 15, 2020 @01:45AM (#25427699)
>"A hardware interrupt is pure overhead, especially on platforms like x86 with silly interrupt latency."

Relatively speaking maybe. But I have a device I've designed that communicates to PC using interrupt transfer at the rate of 250 requests/s. I've watched it then over oscilloscope and it is stable like a rock. Sure if you overload PC it might get into trouble but it is a game like application so when the app is ran PC is not doing much else. I recently ported the same thing to Raspberry Pi 4.

Re:The Case of the Extra 40ms by amluto on Tuesday December 15, 2020 @02:10PM (#25433784)
Hah, you must never have tried this on an otherwise idle stock Sandy Bridge before Linux added mitigations :)

x86 interrupts are slow but at least reasonably consistent on a non-idle system. If your system is deeply enough into its various idle states, this is not at all true any more. I’ve seen latencies over 10ms on Sandy Bridge with C1E enabled.

Re:The Case of the Extra 40ms by FpUser on Tuesday December 15, 2020 @04:58PM (#25435754)
Linux was on Pi 4. On PC it was actually Windows. The first version went out some 7 years ago I think and was rock solid since the beginning. They must've done something right ;)
Re:The Case of the Extra 40ms by marcan_42 on Tuesday December 15, 2020 @01:06AM (#25427501)
It isn't on Android, but as I said, Netflix isn't a real-time app, so Android's deficiencies in the low latency audio department should not concern them. They should just buffer more audio per wakeup.
Re:The Case of the Extra 40ms by saghm on Tuesday December 15, 2020 @01:24AM (#25427588)
> as I said, Netflix isn't a real-time app

I honestly had a tough time parsing the sentence when you said that due to the triple negative, so it's possible that others might have misunderstood it.

Re:The Case of the Extra 40ms by sitkack on Tuesday December 15, 2020 @02:00AM (#25427765)
Multiple negatives are common in some languages and absolutely do connote a distinct meaning from the simplified language.

https://linguistics.stackexchange.com/questions/15334/what-i...

Re:The Case of the Extra 40ms by saghm on Tuesday December 15, 2020 @01:00PM (#25432903)
Yep, I don't disagree! I think they can still be tough to parse in English though, even as a native speaker
Re:The Case of the Extra 40ms by marcan_42 on Tuesday December 15, 2020 @02:06AM (#25427787)
That sentence was indeed a bit awkward, but I hope the meaning gets across since it wouldn't really make much sense the other way around, I think :-)
Re:The Case of the Extra 40ms by Toutouxc on Tuesday December 15, 2020 @03:19AM (#25428171)
I'm not a native speaker and the sentence is honestly absolutely unparseable for me and reads like a contradiction. Is it even... correct?
Re:The Case of the Extra 40ms by saghm on Tuesday December 15, 2020 @01:01PM (#25432921)
I think it's grammatically correct, yes! But being grammatically correct isn't always the same as being easy to understand; some correct things can be hard to understand, and some incorrect things can be pretty easy to understand!