Play an MP3 with Media Foundation

An under 100 lines of C++ code sample that plays an MP3 file with Microsoft Media Foundation.

https://github.com/roman380/MediaFoundationMinimalAudioPlayback

Comes from this StackOverflow question, however unlike Microsoft’s sample it does not spread simple code among multiple source code files, gives a quick way to build & run, shows modern C++ practices (including Microsoft Windows Implementation Library in wil branch – the library I recommend to use).

The sample quickly goes over main concepts: topology, nodes, session, events, asynchronous processing. Media Foundation’s “Intelligent Connect” automatically & transparently supplying two Media Foundation Transforms to decode MP3 audio and to fit audio format to acceptable by audio playback device.

Event: MESessionTopologySet
  Node Count: 4
  Node 0: MF_TOPOLOGY_SOURCESTREAM_NODE
    MF_TOPONODE_MEDIASTART
    MF_TOPONODE_SOURCE
    MF_TOPONODE_PRESENTATION_DESCRIPTOR
    MF_TOPONODE_STREAM_DESCRIPTOR
  Node 1: MF_TOPOLOGY_OUTPUT_NODE
    MF_TOPONODE_STREAMID
    MF_TOPONODE_TRANSFORM_OBJECTID {D23E6476-B104-4707-81CB-E1CA19A07016}
  Node 2: MF_TOPOLOGY_TRANSFORM_NODE
    MF_TOPONODE_MARKIN_HERE
    MF_TOPONODE_MARKOUT_HERE
    MF_TOPONODE_DECODER
    MF_TOPONODE_TRANSFORM_OBJECTID {BBEEA841-0A63-4F52-A7AB-A9B3A84ED38A}
  Node 3: MF_TOPOLOGY_TRANSFORM_NODE
    MF_TOPONODE_TRANSFORM_OBJECTID {F447B69E-1884-4A7E-8055-346F74D6EDB3}
Event: MESessionNotifyPresentationTime
Event: MESessionCapabilitiesChanged
  Capabilities: MFSESSIONCAP_START MFSESSIONCAP_SEEK MFSESSIONCAP_RATE_FORWARD MFSESSIONCAP_DOES_NOT_USE_NETWORK
  Change: MFSESSIONCAP_START MFSESSIONCAP_SEEK MFSESSIONCAP_RATE_FORWARD MFSESSIONCAP_DOES_NOT_USE_NETWORK
Event: MESessionTopologyStatus MF_TOPOSTATUS_READY
Event: MESessionTopologyStatus MF_TOPOSTATUS_STARTED_SOURCE
Event: MEExtendedType
Event: MESessionCapabilitiesChanged
  Capabilities: MFSESSIONCAP_START MFSESSIONCAP_SEEK MFSESSIONCAP_PAUSE MFSESSIONCAP_RATE_FORWARD MFSESSIONCAP_DOES_NOT_USE_NETWORK
  Change: MFSESSIONCAP_PAUSE
Event: MESessionStarted
...
Event: MEEndOfPresentation
Event: MESessionTopologyStatus MF_TOPOSTATUS_ENDED
Event: MESessionCapabilitiesChanged
  Capabilities: MFSESSIONCAP_START MFSESSIONCAP_SEEK MFSESSIONCAP_RATE_FORWARD MFSESSIONCAP_DOES_NOT_USE_NETWORK
  Change: MFSESSIONCAP_PAUSE
Event: MESessionEnded

Have fun!

Getting married in Ukraine under martial law

TLDR: You will have hard time marrying a disabled girl in Ukraine 2022/2023.

As you might have heard, Ukraine does not allow its men citizen aged 18 through 60 to leave the country. You might want to think it’s a smart idea but let’s have a dive into the implementation.

According to current legislation in Ukraine there are a few scenarios when the country prohibit border crossing to its citizens on their outbound travel. And those, surprisingly, do NOT include the case of martial law and those who can potentially be drafted. So what the hell is going on?

Ukraine has a legislative branch, a judicial branch, and an executive branch. The highest level normative act, the Constitution of Ukraine, defines that it is the legislative branch who has to define the exception for border crossing. Did legislative branch banned men leave? NO. Executive branch, represented by antisocial gang with the president as a frontman actor, issued its own leave ban and instructed the border service to refer to it and ignore the norms of the Constitution of Ukraine. The judicial branch is suppressed and threatened and so things have remained as this for some time. There are a few collisions that make it hard for legislative branch to issue the ban accurately too, and – no matter what – legislative branch after almost a year of martial law did not even make an attempt to legalize the ban in a nicer way.

Men in Ukraine are in a sort of a trap: explosions, no jobs, the usurpers of power are treating men as resource for fights where men are thrown and those who want to stay alive are supposed to purchase equipment at their own expense. And, of course, no leave from Ukraine. Many look for loopholes and exceptions, and one of the stories I recently heard encouraged me to share and write this post.

One person from my home city Kharkov, Ukraine complained that he had troubles with his plan. In frustration of being locked in Ukraine, he decided to find and marry disabled girl because this sort of disability and care needs opens an opportunity to cross border for a men who is a carer of such disabled person and is also a first degree relative. He found a woman and they got into agreement.

They went to register their marriage in Lvov, Ukraine in the Western part of the country assumed to be safer (not really for men) and what they heard was this: “We will not register your marriage because you’re trying to escape the draft and you want to flee. Your mutual consent to get married? We don’t give a fuck.”. They drove to another neighboring region to make another attempt and they found that they are already sort of banned by name across the offices, and new office refused immediately because “you already tried to do it yesterday in Lvov”.

On helping Ukraine (update)

Recently I explained why you should not express your support of Ukraine by sending money to various disgusting organizations even if they have fancy looking names, such as, including, and maybe even first of all those with labels “initiative of the president of Ukraine”.

The organization I recommended has been gradually shifting to forwarding the donations to military support, so I no longer recommend even them.

Seriously, consider better ways of wasting your money.

You might think you are expressing support of Ukraine by tearing your own penny from you, but the only thing you are really showing is that you were fooled and you couldn’t even figure out what happened.

If you are curious about the level of the lawlessness in Ukraine and what men aged 18 through 60 have to deal with, please ask your Russian speaking friends to re-tell the details of these clips below.

Continue reading →

On helping Ukraine

I have been asked a few times about helping Ukraine in connection with the happening on the East of Ukraine.

The first thing however, is to have clear understanding about who is fighting with whom and for what exactly. The mainstream media story about Russian president going nuts and attack of Ukraine, and then all this denazification, and that Ukrainian army is so well prepared that it defends successfully against the second army of the world… This is bullshit is literally every word of it. However after a few attempts to put this all together nicely in a compact way, I failed.

Back to helping Ukraine.

Ukraine as a state wants this war. In fact, the administrations of Ukraine and Russian Federation are much closer to one another than to their own population. They arranged this fight cooperatively and keep it running, neglecting the needs of people and the damage caused. For this reason, nearly each and every centralized way to support Ukraine will end up being fueling the war.

For example, United24 the initiative of the President of Ukraine… First, remember that it is a professional artist looking at you from the webpage. They created a way to collect donations in an easy way, for those who want to help it is the way to easily release the intent to help, and also to feel involvement that they are on the “right” side of the story. This money will not help real people and I would not recommend giving a single penny to the scoundrels.

The reality is this. Ukraine has no its own economy, it is all destroyed, and Ukraine is living now on external funding, like a seriously ill patient on a ventilator, it will crash the next second after the device is turned off. A dollar you spend to crooks like mentioned in the previous paragraph means that they will need a dollar less from external source (the funding which is generously given them anyway) without absolutely any effect. Regional authorities in Ukraine are fully dependent on the government and are not only spending funds to keep their positions, they even monopolized the helping activities and are pushing away competing volunteers.

The second important part is the definition of help. In Ukraine the government throws people into combat without training, without equipment. They force you into trenches “because of constitutional obligation” even though they trampled on the constitution. Same time you buy armor, drones, collimators, thermal visors… yourselves. Or you fundraise to get these purchases funded, and those “volunteers” who shop for this stuff abroad take their cut off the supply chain. So it is literally making war at expense of people you are throwing into this war. Donations given to random volunteers, if they pass the hands of government and militaries in which case they are simply stolen, will most likely end up in some buying a used all-wheel driving car in Europe for the needs of subdivision X. That is, what starts in helping Ukraine will just fuel the war further.

If, however, the understanding of help is to help to those who suffered, which I hope is the case, then finding people who stay away from military rage is really difficult. Only small unknown groups of people can perform this activity in first place because otherwise they would be absorbed my local authorities who eradicates competition in the field of helping.

I personally know just one group of people who sticks to suffered. I mentioned them before and my trust in them is because I know a few of them in person. These people have accounts on Facebook and Telegram, however they are not the best in arranging collection of donations: in Ukraine people are sending money instantly by card number and SWIFT is an option for foreigners even though it’s not something those foreigners are comfortable with. This is the best I know, and I am aware of one another who helps those who have problems with animals (dogs, horses, relocation of those etc.). If you decided to donate and you don’t know whom exactly, the best I can suggest is to get in touch with these people and talk to them.