Changes between Version 6 and Version 7 of CompilationGuide/WinRT


Ignore:
Timestamp:
Apr 2, 2015, 7:35:01 PM (4 years ago)
Author:
peter0302
Comment:

The compilation guide did not address certain practical details and I have not found any other online source addressing it, so I thought this addition would be helpful. Ideally the FFmpeg team will incorporate full WinRT support into the next version. A separate page dedicated to FFmpeg usage in Windows Store apps may be warranted.

Legend:

Unmodified
Added
Removed
Modified
  • CompilationGuide/WinRT

    v6 v7  
    1 = Compile FFmpeg Libraries for Windows Runtime (WinRT) = 
     1= Compile and Use FFmpeg Libraries for Windows Runtime (WinRT) = 
    22 
    33[[PageOutline(2)]] 
    44 
    5 FFmpeg libraries can be built for '''Windows Store 8.1''' and '''Windows Phone 8.1''' apps development using MSVC 2013 (Update 3 RTM or newer). The guide below provides build instruction for all supported target configurations (platform & architecture). Each configuration requires distinct set of tools, environment variables, and configure options outlined in each section below. 
     5FFmpeg libraries can be built for and used with '''Windows Store 8.1''' and '''Windows Phone 8.1''' apps development using MSVC 2013 (Update 3 RTM or newer). The guide below provides build instruction for all supported target configurations (platform & architecture). Each configuration requires distinct set of tools, environment variables, and configure options outlined in each section below. It concludes with some practical and potentially non-obvious information for consuming the FFmpeg DLLs from your app. 
    66 
    77---- 
     
    325325 
    326326---- 
     327== Windows Store Certification, File I/O, and Other Details == 
     328 
     329FFmpeg is an excellent alternative to Windows Media Foundation, which supports a small fraction of the codecs that FFmpeg has. Fortunately,  
     330FFmpeg does not use any prohibited Windows or CRT APIs, and apps linked to the DLLs built with this method pass the latest Windows App Certification Kit. However, there are important things to remember. 
     331 
     332First, don't forget to make sure your app package includes all the necessary FFmpeg DLLs in the root folder. In your Visual C++ project, you should include links to the FFmpeg DLLs in the root project folder, making sure to set "Build Action" to "Content" and "Copy to Output Directory" to "Copy Always". It is not enough just to link to the import libraries. You will fail certification if you require your users to install the FFmpeg DLLs separately. 
     333 
     334You will also need to supply a custom file I/O context to any `AVFormatContext` rather than relying on `avio_xxx` functions, because the standard I/O functions utilize CRT I/O that is not supported in WinRT. (You won't fail certification, but your app will be unable to access the file specified in the `AVFormatContext.filename` member, unless potentially it is located in the app's local storage). The file I/O context needs to be initialized to point to your `read`, `write`, and `seek` functions, with the `opaque` member pointing to a `struct` containing an `IRandomAccessStream^` that you obtain when opening a file using proper WinRT IO calls in the `Windows::Storage` namespace. (You need a `struct` to hold the `IRandomAccessStream^`, since you cannot cast a `void*` to a ref handle). Your `read`, `write`, and `seek` functions should cast the `void* opaque` argument to the `struct*` you define, and then use the `IRandomAccessStream^` for all I/O.  
     335 
     336Since FFmpeg I/O calls are synchronous, but the `IRandomAccessStream` members are all asynchronous, you will need to utilize `create_task` and `wait()` on all I/O calls in your IO context implementation functions. Note that this necessitates that any FFmpeg functions utilizing file I/O be executed on a WORKER thread, as WinRT will generate an exception if you use `wait()` in the UI thread. The best solution here is to create WinRT-friendly wrapper functions of the major FFmpeg functions you will utilize, by using the `concurrency::create_async` function, for example: 
     337 
     338{{{ 
     339IAsyncOperation<int>^ av_read_frame_async(AVFormatContext* s, AVPacket* pkt) 
     340{ 
     341        return create_async([s, pkt]()->int 
     342        { 
     343                return av_read_frame(s, pkt); 
     344        }); 
     345} 
     346}}} 
     347 
     348Alternatively, if you don't want to use Windows Runtime extensions, and don't mind COM, you can use the Windows 8-API function `CreateStreamOverRandomAccessStream`, which gives you an `IStream*` COM interface from an `IRandomAccessStream^`, utilizes synchronous I/O, and can be passed as the `void* opaque` member of the IO context. The `IStream` I/O calls are easier to use with C++ since they support direct pointer buffer access (you don't have to deal with `IBuffer`) and more closely correspond to the functions required in `AVIOContext`. However, you should still make sure to wrap any code that utilizes file I/O in a background thread, as excessive blocking of the UI does violate Windows Store guidelines and may cause your app to be terminated at runtime. 
     349