<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 4, 2018 at 2:06 PM, Jean-Baptiste Kempf <span dir="ltr"><<a href="mailto:jb@videolan.org" target="_blank">jb@videolan.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>





<div><div style="font-family:helvetica,arial,sans-serif">Hello,<br></div><span class="">
<div><br></div>
<div>On Sun, 4 Mar 2018, at 11:53, Teemu Ikonen wrote:<br></div>
<blockquote type="cite"><div dir="ltr"><div>Adds support in Media Foundation (MFT) module to use decoders whose FCC is not found from the hardcoded list. Improves compatibility and adds support for common uncompressed formats decoders might prefer. <br></div>
</div>
</blockquote><div style="font-family:helvetica,arial,sans-serif"><br></div>
</span><div style="font-family:helvetica,arial,sans-serif">This looks cool, but how do you have examples of such things?<br></div></div></blockquote><div><br></div><div>

<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Typical use case for them is to allow Windows Media Player to play videos with custom vendor codecs (camera and instrument manufacturers, research, ..).</span> <br></div><div>I've done few decoders to support Windows Media Player to play formats (e.g. Y800) and noticed it would be easy to extend VLC mft module to use any MFT compatible decoder instead of only ones in the hardcoded list. (H264, WM9, ..).<br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:helvetica,arial,sans-serif"></div><span class="">
<div style="font-family:helvetica,arial,sans-serif"><br></div>
<blockquote type="cite"><div dir="ltr"><div>Internal formats (like MFVideoFormat_RGB32) are bottom up (negative stride). Code just changes the to <span class="m_8346319416216312287highlight" style="background-color:rgb(255,255,255)"><span class="m_8346319416216312287colour" style="color:rgb(34,34,34)"><span class="m_8346319416216312287font" style="font-family:arial,sans-serif"><span class="m_8346319416216312287size" style="font-size:small">ORIENT_BOTTOM_LEFT in this case and it works, but is this the right thing do?</span></span></span></span><br></div>
</div>
</blockquote><div style="font-family:helvetica,arial,sans-serif"><br></div>
</span><div style="font-family:helvetica,arial,sans-serif">Did you look at the avi code?<br></div></div></blockquote><div><br></div><div>No. I know that the bitmapinfo header member biHeight in AVI stream format can define the orientation but not sure how it applies. AFAIK it's ignored if payload FCC is anything else than 'DIB '. </div><div>This is more a problem of mapping raw RGB format of MF decoder to VLC RGB format. <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Microsoft recommends that MFT Decoders support NV12 as common format but it's optional and custom decoder probably outputs just raw RGB that works fine and all the example code does that.</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Thank you for the interest!</span></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:helvetica,arial,sans-serif"></div>
<div style="font-family:helvetica,arial,sans-serif"><br></div>
<div style="font-family:helvetica,arial,sans-serif">Best,<br></div>
<blockquote type="cite"><div><div class="h5"><div dir="ltr"><div><br></div>
<div>---<br></div>
<div> modules/codec/mft.c | 66 ++++++++++++++++++++++++++++++<wbr>+++++++++++++++++++----<br></div>
<div> 1 file changed, 62 insertions(+), 4 deletions(-)<br></div>
<div><br></div>
<div>diff --git a/modules/codec/mft.c b/modules/codec/mft.c<br></div>
<div>index 24eaaa55cb..3cf6aa494d 100644<br></div>
<div>--- a/modules/codec/mft.c<br></div>
<div>+++ b/modules/codec/mft.c<br></div>
<div>@@ -92,6 +92,8 @@ struct decoder_sys_t<br></div>
<div> <br></div>
<div>     const GUID* major_type;<br></div>
<div>     const GUID* subtype;<br></div>
<div>+    /* Container for a dynamically constructed subtype */<br></div>
<div>+    GUID custom_subtype;<br></div>
<div> <br></div>
<div>     /* For asynchronous MFT */<br></div>
<div>     bool is_async;<br></div>
<div>@@ -183,6 +185,20 @@ static const pair_format_guid video_format_table[] =<br></div>
<div>     { 0, NULL }<br></div>
<div> };<br></div>
<div> <br></div>
<div>+// 8-bit luminance only<br></div>
<div>+DEFINE_MEDIATYPE_GUID (MFVideoFormat_L8, 50);<br></div>
<div>+<br></div>
<div>+/*<br></div>
<div>+ * Table to map MF Transform raw 3D3 output formats to native VLC FourCC<br></div>
<div>+ */<br></div>
<div>+static const pair_format_guid d3d_format_table[] = {<br></div>
<div>+    { VLC_CODEC_RGB32, &MFVideoFormat_RGB32  },<br></div>
<div>+    { VLC_CODEC_RGB24, &MFVideoFormat_RGB24  },<br></div>
<div>+    { VLC_CODEC_RGBA,  &MFVideoFormat_ARGB32 },<br></div>
<div>+    { VLC_CODEC_GREY,  &MFVideoFormat_L8     },<br></div>
<div>+    { 0, NULL }<br></div>
<div>+};<br></div>
<div>+<br></div>
<div> #if defined(__MINGW64_VERSION_<wbr>MAJOR) && __MINGW64_VERSION_MAJOR < 4<br></div>
<div> DEFINE_GUID(MFAudioFormat_<wbr>Dolby_AC3, 0xe06d802c, 0xdb46, 0x11cf, 0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea);<br></div>
<div> #endif<br></div>
<div>@@ -210,6 +226,15 @@ static const GUID *FormatToGUID(const pair_format_guid table[], vlc_fourcc_t fou<br></div>
<div>     return NULL;<br></div>
<div> }<br></div>
<div> <br></div>
<div>+static vlc_fourcc_t GUIDToFormat(const pair_format_guid table[], const GUID* guid)<br></div>
<div>+{<br></div>
<div>+    for (int i = 0; table[i].fourcc; ++i)<br></div>
<div>+        if (IsEqualGUID(table[i].guid, guid))<br></div>
<div>+            return table[i].fourcc;<br></div>
<div>+<br></div>
<div>+    return 0;<br></div>
<div>+}<br></div>
<div>+<br></div>
<div> /*<br></div>
<div>  * Low latency mode for Windows 8. Without this option, the H264<br></div>
<div>  * decoder will fill *all* its internal buffers before returning a<br></div>
<div>@@ -272,6 +297,16 @@ static int SetInputType(decoder_t *p_dec, DWORD stream_id, IMFMediaType **result<br></div>
<div>         hr = IMFMediaType_SetUINT64(input_<wbr>media_type, &MF_MT_FRAME_SIZE, frame_size);<br></div>
<div>         if (FAILED(hr))<br></div>
<div>             goto error;<br></div>
<div>+<br></div>
<div>+        /* Some transforms like to know the frame rate and may reject the input type otherwise. */<br></div>
<div>+        UINT64 frame_ratio_num = p_dec->fmt_in.video.i_frame_<wbr>rate;<br></div>
<div>+        UINT64 frame_ratio_dem = p_dec->fmt_in.video.i_frame_<wbr>rate_base;<br></div>
<div>+        if(frame_ratio_num && frame_ratio_dem) {<br></div>
<div>+            UINT64 frame_rate = (frame_ratio_num << 32) | frame_ratio_dem;<br></div>
<div>+            hr = IMFMediaType_SetUINT64(input_<wbr>media_type, &MF_MT_FRAME_RATE, frame_rate);<br></div>
<div>+            if(FAILED(hr))<br></div>
<div>+                goto error;<br></div>
<div>+        }<br></div>
<div>     }<br></div>
<div>     else<br></div>
<div>     {<br></div>
<div>@@ -356,7 +391,7 @@ static int SetOutputType(decoder_t *p_dec, DWORD stream_id, IMFMediaType **resul<br></div>
<div>      * preference thus we will use the first one unless YV12/I420 is<br></div>
<div>      * available for video or float32 for audio.<br></div>
<div>      */<br></div>
<div>-    int output_type_index = 0;<br></div>
<div>+    int output_type_index = -1;<br></div>
<div>     bool found = false;<br></div>
<div>     for (int i = 0; !found; ++i)<br></div>
<div>     {<br></div>
<div>@@ -380,6 +415,10 @@ static int SetOutputType(decoder_t *p_dec, DWORD stream_id, IMFMediaType **resul<br></div>
<div>         {<br></div>
<div>             if (IsEqualGUID(&subtype, &MFVideoFormat_YV12) || IsEqualGUID(&subtype, &MFVideoFormat_I420))<br></div>
<div>                 found = true;<br></div>
<div>+            /* Transform might offer output in a D3DFMT propietary FCC. If we can<br></div>
<div>+             * use it, fall back to it in case we do not find YV12 or I420 */<br></div>
<div>+            else if(output_type_index < 0 && GUIDToFormat(d3d_format_table, &subtype) > 0)<br></div>
<div>+                    output_type_index = i;<br></div>
<div>         }<br></div>
<div>         else<br></div>
<div>         {<br></div>
<div>@@ -399,9 +438,12 @@ static int SetOutputType(decoder_t *p_dec, DWORD stream_id, IMFMediaType **resul<br></div>
<div>     }<br></div>
<div>     /*<br></div>
<div>      * It's not an error if we don't find the output type we were<br></div>
<div>-     * looking for, in this case we use the first available type which<br></div>
<div>-     * is the "preferred" output type for this MFT.<br></div>
<div>+     * looking for, in this case we use the first available type.<br></div>
<div>      */<br></div>
<div>+    if(output_type_index < 0)<br></div>
<div>+        /* No output format found we prefer, just pick the first one preferred<br></div>
<div>+         * by the MFT */<br></div>
<div>+        output_type_index = 0;<br></div>
<div> <br></div>
<div>     hr = IMFTransform_<wbr>GetOutputAvailableType(p_sys-><wbr>mft, stream_id, output_type_index, &output_media_type);<br></div>
<div>     if (FAILED(hr))<br></div>
<div>@@ -419,7 +461,17 @@ static int SetOutputType(decoder_t *p_dec, DWORD stream_id, IMFMediaType **resul<br></div>
<div>     if (p_dec->fmt_in.i_cat == VIDEO_ES)<br></div>
<div>     {<br></div>
<div>         video_format_Copy( &p_dec->fmt_out.video, &p_dec->fmt_in.video );<br></div>
<div>-        p_dec->fmt_out.i_codec = vlc_fourcc_GetCodec(p_dec-><wbr>fmt_in.i_cat, subtype.Data1);<br></div>
<div>+<br></div>
<div>+        /* Transform might offer output in a D3DFMT propietary FCC */<br></div>
<div>+        vlc_fourcc_t fcc = GUIDToFormat(d3d_format_table, &subtype);<br></div>
<div>+        if(fcc) {<br></div>
<div>+            /* D3D formats are upside down */<br></div>
<div>+            p_dec->fmt_out.video.<wbr>orientation = ORIENT_BOTTOM_LEFT;<br></div>
<div>+        } else {<br></div>
<div>+            fcc = vlc_fourcc_GetCodec(p_dec-><wbr>fmt_in.i_cat, subtype.Data1);<br></div>
<div>+        }<br></div>
<div>+<br></div>
<div>+        p_dec->fmt_out.i_codec = fcc;<br></div>
<div>     }<br></div>
<div>     else<br></div>
<div>     {<br></div>
<div>@@ -1046,6 +1098,12 @@ static int FindMFT(decoder_t *p_dec)<br></div>
<div>         category = MFT_CATEGORY_VIDEO_DECODER;<br></div>
<div>         p_sys->major_type = &MFMediaType_Video;<br></div>
<div>         p_sys->subtype = FormatToGUID(video_format_<wbr>table, p_dec->fmt_in.i_codec);<br></div>
<div>+        if(!p_sys->subtype) {<br></div>
<div>+            /* Codec is not well known. Construct a MF transform subtype from the fourcc */<br></div>
<div>+            p_sys->custom_subtype = MFVideoFormat_Base;<br></div>
<div>+            p_sys->custom_subtype.Data1 = p_dec->fmt_in.i_codec;<br></div>
<div>+            p_sys->subtype = &p_sys->custom_subtype;<br></div>
<div>+        }<br></div>
<div>     }<br></div>
<div>     else<br></div>
<div>     {<br></div>
<div>-- <br></div>
<div>2.14.1<br></div>
<div><br></div>
</div>
</div></div><div><u>______________________________<wbr>_________________</u><br></div>
<div>vlc-devel mailing list<br></div>
<div>To unsubscribe or modify your subscription options:<br></div>
<div><a href="https://mailman.videolan.org/listinfo/vlc-devel" target="_blank">https://mailman.videolan.org/<wbr>listinfo/vlc-devel</a><br></div>
</blockquote><div style="font-family:helvetica,arial,sans-serif"><br></div>
<div id="m_8346319416216312287sig60240713"><div class="m_8346319416216312287signature">--<br></div>
<div class="m_8346319416216312287signature">Jean-Baptiste Kempf -  President<br></div>
<div class="m_8346319416216312287signature">+33 672 704 734<br></div>
<div class="m_8346319416216312287signature"> <br></div>
<div class="m_8346319416216312287signature"><br></div>
</div>
<div style="font-family:helvetica,arial,sans-serif"><br></div>
</div>

</blockquote></div><br></div></div>