(Note: I originally posted this question in the Windows Apps with C++ forum about 3 weeks ago, but received no replies. I realized quickly that this might be a better forum for this, but wanted to let that question run its course before posting again here. So any help you all could provide would be VERY much appreciated.)
I am using a C++/CX component to encode video using IMFSinkWriter, and everything works fine when I encode using the WMV3 codec, but when I try to use the H.264 codec I get E_CHANGED_STATE (0x8000000c: "A concurrent or interleaved operation changed the state of the object, invalidating this operation.") errors. I can't find any reason to believe this is a threading issue, which was my first thought: the component is being called from an async/await C# method, but everything awaitable is being awaited, as far as I can see, and there's no other threading-like behavior going on in the app.
My second thought was that somehow the sink writer's throttling (on by default) was being turned off. But this doesn't seem to be the case. In fact, I tried to explicitly enable throttling, but this didn't have any effect:
spAttr->SetUINT32(MF_SINK_WRITER_DISABLE_THROTTLING, false);
The encoding source is an RGB32 stream, and I am encoding at a 1.5Mbps bitrate, 25 FPS.
The error happens every time I try to encode a video of any real-world length: it'll usually pop up before it gets about 10% of the way through a 5 minute output file. However, it isn't entirely deterministic: sometimes it will get partway through the third (of 58) segments, while other times it will happened on the first.
None of these problems affect WMV encoding. Can anyone offer any suggestions for things to try?
Additional note: I have seen some references that I might need to supply some metadata (a sample description box) with the video, but I can't find any documentation on this that I can understand. As indicated I can encode WMV without getting this error (usually-- I think I've seen it once or twice in the long history of testing this component), and all I would like to do is provide an alternative format for my users. Could the lack of this metadata be causing this, and if so are there any accessible tutorials on constructing it?