Bug 1731430 Comment 26 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

Here are more details why I said the problem is in MFT decoder. The following are some debug log, `ProcessDecode ...` means we feed the input to MFTDecoder [here](https://searchfox.org/mozilla-central/rev/0ec81de2037cb0a0701d5d316f42763230b3a142/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp#81-82). `Decoded audio ...` means we get the audio output from MFT decoder [here](https://searchfox.org/mozilla-central/rev/0ec81de2037cb0a0701d5d316f42763230b3a142/dom/media/platforms/wmf/WMFAudioMFTManager.cpp#305-306) (but I added one more check for [discontinuity](https://searchfox.org/mozilla-central/rev/0ec81de2037cb0a0701d5d316f42763230b3a142/dom/media/platforms/wmf/WMFAudioMFTManager.cpp#253) in my build). Some new log I added are, `Ask MFT to drain` [here](https://searchfox.org/mozilla-central/rev/0ec81de2037cb0a0701d5d316f42763230b3a142/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp#200) and ` MFT tell us ...` [here](https://searchfox.org/mozilla-central/rev/0ec81de2037cb0a0701d5d316f42763230b3a142/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp#208).

```
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17786915
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17763695 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17810135
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=17786915 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Ask MFT to drain
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17810135 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=17833355 duration=14988 currentLength=5288 discontinuity=0
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule MFT tell us MF_E_TRANSFORM_NEED_MORE_INPUT, drain ended
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessFlush, type=Audio
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17740475
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17763695
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Unable to retrieve channel layout. Ignoring
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=0 duration=8231 currentLength=2904 discontinuity=1
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17786915
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17763695 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17810135
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=17786915 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.558000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17833355
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17810135 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17856575
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=17833355 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17879794
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17856575 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17903014
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=17879794 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Ask MFT to drain
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17903014 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=17926234 duration=14988 currentLength=5288 discontinuity=0
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule MFT tell us MF_E_TRANSFORM_NEED_MORE_INPUT, drain ended
2021-10-14 18:45:40.578000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessFlush, type=Audio
2021-10-14 18:45:40.578000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17833355
2021-10-14 18:45:40.583000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17856575
2021-10-14 18:45:40.583000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=0 duration=8231 currentLength=2904 discontinuity=1
2021-10-14 18:45:40.583000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17879794
2021-10-14 18:45:40.583000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17856575 duration=23219 currentLength=8192 discontinuity=0
```
So you can see, before we called draining, the last input we sent to MFT decoder is `17810135`. But it returns two (`17810135` with correct duration `23219` and another is `17833355` with incorrect duration `14988`)

According to MS's [documentation](https://docs.microsoft.com/en-us/windows/win32/medfound/mft-message-command-drain), draining should not return an incompleted partial sample, but it's apparently not true on Windows 11, the second sample MFT decoder returned was wrong!

In addition, another interesting thing is that, their document said `The first sample after the drain operation must have the discontinuity attribute`, and you can see the sample with discontinuity attribute is also a wrong one. It has timestamp 0 and incorrect duration 8231. The previous incorrect one is `14988` and the sum of these two incorrect duration is exactly `14988+8231=23219`!

So it seems that MFT decoder splits an empty sample to two, and return them BEFORE AND AFTER draining. We also encounter a similar issue for video in bug 1718709 where the first video sample MFT decoder gave us is wrong!
Here are more details why I said the problem is in MFT decoder. The following are some debug log, `ProcessDecode ...` means we feed the input to MFTDecoder [here](https://searchfox.org/mozilla-central/rev/0ec81de2037cb0a0701d5d316f42763230b3a142/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp#81-82). `Decoded audio ...` means we get the audio output from MFT decoder [here](https://searchfox.org/mozilla-central/rev/0ec81de2037cb0a0701d5d316f42763230b3a142/dom/media/platforms/wmf/WMFAudioMFTManager.cpp#305-306) (but I added one more check for [discontinuity](https://searchfox.org/mozilla-central/rev/0ec81de2037cb0a0701d5d316f42763230b3a142/dom/media/platforms/wmf/WMFAudioMFTManager.cpp#253) in my build). Some new log I added are, `Ask MFT to drain` [here](https://searchfox.org/mozilla-central/rev/0ec81de2037cb0a0701d5d316f42763230b3a142/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp#200) and ` MFT tell us ...` [here](https://searchfox.org/mozilla-central/rev/0ec81de2037cb0a0701d5d316f42763230b3a142/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp#208).

```
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17786915
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17763695 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17810135
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=17786915 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Ask MFT to drain
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17810135 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.471000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=17833355 duration=14988 currentLength=5288 discontinuity=0
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule MFT tell us MF_E_TRANSFORM_NEED_MORE_INPUT, drain ended
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessFlush, type=Audio
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17740475
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17763695
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Unable to retrieve channel layout. Ignoring
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=0 duration=8231 currentLength=2904 discontinuity=1
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17786915
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17763695 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17810135
2021-10-14 18:45:40.478000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=17786915 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.558000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17833355
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17810135 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17856575
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=17833355 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17879794
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17856575 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17903014
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=17879794 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Ask MFT to drain
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17903014 duration=23219 currentLength=8192 discontinuity=0
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=17926234 duration=14988 currentLength=5288 discontinuity=0
2021-10-14 18:45:40.567000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule MFT tell us MF_E_TRANSFORM_NEED_MORE_INPUT, drain ended
2021-10-14 18:45:40.578000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessFlush, type=Audio
2021-10-14 18:45:40.578000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17833355
2021-10-14 18:45:40.583000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17856575
2021-10-14 18:45:40.583000 UTC - [RDD 27332: MediaPDecoder #1]: D/PlatformDecoderModule Decoded audio sample! timestamp=0 duration=8231 currentLength=2904 discontinuity=1
2021-10-14 18:45:40.583000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule ProcessDecode, type=Audio, sample=17879794
2021-10-14 18:45:40.583000 UTC - [RDD 27332: MediaPDecoder #2]: D/PlatformDecoderModule Decoded audio sample! timestamp=17856575 duration=23219 currentLength=8192 discontinuity=0
```
So you can see, before we called draining, the last input we sent to MFT decoder is `17810135`. But it returns two (`17810135` with correct duration `23219` and another is `17833355` with incorrect duration `14988`)

According to MS's [documentation](https://docs.microsoft.com/en-us/windows/win32/medfound/mft-message-command-drain), draining should not return an incompleted partial sample, but it's apparently not true on Windows 11, the second sample MFT decoder returned was wrong!

In addition, another interesting thing is that, their document said `The first sample after the drain operation must have the discontinuity attribute`, and you can see the sample with discontinuity attribute is also a wrong one. It has timestamp 0 and incorrect duration 8231. The previous incorrect one is `14988` and the sum of these two incorrect duration is exactly `14988+8231=23219`!

So it seems that MFT decoder splits an empty sample to two, and return them **BEFORE AND AFTER** draining. We also encounter a similar issue for video in bug 1718709 where the first video sample MFT decoder gave us is wrong!

Back to Bug 1731430 Comment 26