How to instantiate H264 Encoder on WinRT Store App - windows-runtime

I want to be able to encode video frames using Media Foundation IMFTransform for H264 Video Encoding. That's easily doable in Win32, where you can use MFTEnumEx to enumerate the transforms and find the H264 encoder.
However, on WinRT (Store Apps), I can't find a way to instantiate.
I've noticed there's a class CMSH264EncoderMFT, but there's no definition for the CLSID to use on CoCreateInstance.
With:
CoCreateInstance(CLSID_CMSH264EncoderMFT, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IUnknown), (void **)&pUnknown);
CLSID_CMSH264EncoderMFT is undefined for WinRT apps.
And tried:
ComPtr<CMSH264EncoderMFT> encoder = Make<CMSH264EncoderMFT>();
It says the class CMSH264EncoderMFT is incomplete, and says "use of undefined type 'CMSH264EncoderMFT'". Don't even know if the syntax for Make is correct or appropriate...
Does anyone have a clue on how to do this for WinRT?

Use MFCreateSinkWriterFromURL to create a file writer first. Then, use MFCreateMediaType to create an IMFMediaType. Set up its properties, one of which will be the output format: use SetGUID method on the media type with MF_MT_SUBTYPE guid and specify MFVideoFormat_H264 as the argument. Finally, use AddStream method on the sink writer to set the media type to it.
There's an example here (you'll need to modify it a bit when it sets MF_MT_SUBTYPE).

you cannot instantiate object via CMSH264EncoderMFT because it DOES NOT have some interfaces which MUST have object in WinRT for example IInspectable - Provides functionality required for all Windows Runtime classes. CMSH264EncoderMFT IS NOT WinRT class. You can try resolve your task by function MFCreateSinkWriterFromMediaSink - this function takes an object with interface IMFMediaSink. It is possible write code for object with IMFMediaSink interface and receive samples from IMFTransform::ProcessOutput. I just point your attention - you cannot instantiate in WindowsStore code objects which IS NOT Windows Runtime classes.
Regards,
Evgeny Pereguda

Related

How do I avoid conflicts between haxe Type class and C# Type class?

I am developing Haxe code that I convert in C# and insert into a Unity project.
The conversion works fine and I am able to use the generated class when I import it alone in Unity.
To make it work, I have to bring in Unity the whole generated src folder, including the Type.cs file.
However, when I import the "Post Processing Stack" (a basic Unity extension) I get errors due to name Conflicts. The Type class is also a basic C# class and It is used by the Post Processing scripts.
The haxe-Type takes priority and breaks the compilation:
Assets/PostProcessing/Runtime/PostProcessingBehaviour.cs(406,30): error CS1502: The best overloaded method match for `System.Collections.Generic.Dictionary<Type,System.Collections.Generic.KeyValuePair<UnityEngine.Rendering.CameraEvent,UnityEngine.Rendering.CommandBuffer>>.Add(Type, System.Collections.Generic.KeyValuePair<UnityEngine.Rendering.CameraEvent,UnityEngine.Rendering.CommandBuffer>)' has some invalid arguments
Assets/PostProcessing/Runtime/PostProcessingBehaviour.cs(406,34): error CS1503: Argument `#1' cannot convert `System.Type' expression to type `Type'
I don't know if it is possible to solve this issue by playing around with C#/Unity/Mono search paths.
I as wondering wether it is more appropriate to (optionally) wrap all haxe top-level classes into the haxe namespace, or a special haxe-defaultnamespace, or prefix them for example to class HType.
Name conflicts for this basic types are likely to emerge in many other contexts, not only in Unity.
I found the solution in the Haxe documentation for C#:
https://github.com/HaxeFoundation/HaxeManual/wiki/Haxe-C%23
-D no-root generate package-less haxe types in the haxe.root namespace to avoid conflicts with other types in the root namespace
This way, all the classes that were at global level will be generated under namespace haxe.root.

getDefinitionByName "Variable Not defined" workaround

Ok so I have game data parser that creates a game out of data file basically, it is using extensively getDefinitionByName which has one problem if the class is not loading somewhere else it throw variable not defined error information=ReferenceError: Error #1065: Variable {MyClass} is not defined. to workaround it I am using a class that holds all the list of components and instantiate it to make these classes available to the compiler.
Ok the question part is there any more efficient way to do that or playing with compiler argument or something ?
Is there something like export in first frame in flash professional as a compiler argument ?
I think what you want is to have a library project with all those "callable" classes, and then reference that library project in your game.
In flash builder, for a library project, you can check which classes are compiled (and so available to getDefinitionByName). (info here)

What is __AS3__?

Sometimes in debug mode with Flash Builder, I see something like
__AS3__.vec.Vector.<Object> (#909e219)
but when I try to store this variable in another as3 variable, Flash duplicate this variable. Concretly, I'm trying to exclude some values on dragInitiator.selectedItems property before adding them to a List but when I use splice method on it, values aren't deleted from this vector.
So how can I acces variable with __AS3__ namespace please ?
According to a Tamarin developer:
The namespace "__AS3__.vec" is an artifact of a time when we did not have good API
versioning and could not introduce new top-level names without the risk of breaking
existing code. Today we would probably have made "Vector" public & versioned.
Source: http://hg.mozilla.org/tamarin-redux/rev/817f3e019ba2#l2.30
In other words, __AS3__ is the package where are defined Flash internal classes into Tamarin VM.
To access such variables, you don't need to specify the namespace. You only have to use the FQN declared in playerglobals.swc.

SharedObject and Dictionary problems in Flash Builder

I'm usin Flash Builder to create some actionscript code that uses SharedObjects.
First question: how can I delete my local SharedObject in Flash Builder? I am debugging my program and the SharedObject sems to persist between runs. I want to start fresh and clean with no SharedObject storing my data. How do I get rid of it?
Also, in my SharedObject, I used mySharedObject.data["mykey"] to store a Dictionary. This Dictionary will have String keys and values of MyCustomClass. The problem is that when I later try to loop over the values of this Dictionary, I get error #1034 cannot convert object to type MyCustomClass. It seems like I can put an item of type MyCustomClass into this dictionary, but I can't get the item back out as anything other than an object.
Any idea what is going wrong?
Those are essentially two questions, so should have been asked as two questions. Anyway, I'd answer them here but still prefer that you break them up in two parts (possibly leave a link to the other one here for reference sake):
Local shared object, are useful exactly for persistence across runs. And then there's SharedObject.clear() to clear the state as required.
For you second issue, Shared Object's serialize your object into AMF, so that it can be written to disk or sent over network using RTMP. Now, your custom class can't really be serialized in AMF. What actually happens is that the public properties (and dynamic ones, if the class is declared dynamic) are serialized into the structure. So, the public data is stored... but it's essentially a general Object.
To work around that, you can have a public static readFrom(object:Object):MyCustomClass type function, which would read the properties from the passed object to construct a new MyCustomClass representing that information.
There are ways to register your class with the player to be stored in SharedObject (see here)... but you need to make sure that the code that de-serializes that data is aware of the class as well.
To make a class available for conversion, in your global initialization use registerClassAlias() call with MyCustomClass and its fully qualified name as parameters. The manual. Say your custom class is foo.bar.TheClass, you write:
registerClassAlias('foo.bar.TheClass',foo.bar.TheClass);
In order to drop old SO use delete call against so.data["mykey"] and do so.flush(). Edit: SharedObject.clear() is way better.
1/ Being persistent is one of the particularity of a SharedObject. To cleanup all its content, you need to call the clear method.
var shareObject:SharedObject = SharedObject.getLocal('justatest');
shareObject.data.test = 'test';
trace(shareObject.data.test)
shareObject.clear();
trace(shareObject.data.test)
output
test
undefined
2/ To store complex data types in SO, you need to use flash.net.registerClassAlias (example here)

Saving application state AIR

Is there a way to save an application state for save files in AIR for the desktop (Flex /AS3)?
Thanks
You need to make sure all your classes are serializable, then serialize them and save them to a file when exiting the application.
On starting the application again, you deserialize the objects - in effect instantiating all objects and assigning all their previous properties again.
This can be rather hard to retro-fit to an existing application since your code must adhere to a few rules. For instance, your class constructors cannot accept any arguments and your objects must have public properties or they will not be serialized.
This article should get you up to speed on object serializaion in as3: http://jacksondunstan.com/articles/1642