InstanceCX.cpp 5.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*****************************************************************************
* InstanceCX.cpp: Instance API
*****************************************************************************
* Copyright  2014 the VideoLAN team
*
* Authors: Hugo Beauze-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/

#include "InstanceCX.hpp"
#include "Helpers.h"
#include <collection.h>

//HACK HACK HACK
28
#include "MMDeviceLocator.h"
29 30 31 32 33 34 35
using namespace Windows::Graphics::Display;

namespace libVLCX
{
    Instance::Instance(Windows::Foundation::Collections::IVector<Platform::String^>^ argv, SwapChainPanel^ panel)
        : m_chainPanel(panel)
    {
36
        int extraArgs = 5;
37 38 39 40 41 42 43 44 45 46 47 48 49
        auto c_argv = new char*[argv->Size + extraArgs];
        unsigned int i = 0;
        for (auto arg : argv)
        {
            c_argv[i++] = _strdup((const char*) VLCString(arg));
        }
        InitializeHack(c_argv, i);
        m_instance = VLC::Instance::create(argv->Size + extraArgs, c_argv);
        for (i = 0; i < argv->Size + extraArgs; ++i)
            free(c_argv[i]);
        delete [] c_argv;
    }

50 51 52 53 54
    void Instance::Trim()
    {
        m_dxManager->Trim();
    }

55 56 57 58 59 60
    void Instance::InitializeHack(char** argv, unsigned int nbArgs)
    {
        m_dxManager.reset(new DirectXManger);
        m_dxManager->CreateSwapPanel(m_chainPanel);
        UpdateSize(m_chainPanel->ActualWidth, m_chainPanel->ActualHeight);

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        ComPtr<MMDeviceLocator> audioReg = Make<MMDeviceLocator>();

        audioReg->m_AudioClient = NULL;
        audioReg->m_audioClientReady = CreateEventEx(NULL, TEXT("AudioClientReady"), 0, EVENT_ALL_ACCESS);
        audioReg->RegisterForWASAPI();

        void *addr = NULL;
        DWORD res;
        while ((res = WaitForSingleObjectEx(audioReg->m_audioClientReady, 1000, TRUE)) == WAIT_TIMEOUT) {
            OutputDebugStringW(L"Waiting for audio\n");
        }
        CloseHandle(audioReg->m_audioClientReady);
        if (res != WAIT_OBJECT_0) {
            OutputDebugString(TEXT("Failure while waiting for audio client"));
            return;
        }

        char ptr_astring[40];
        sprintf_s(ptr_astring, "--winstore-audioclient=0x%p", audioReg->m_AudioClient);
        argv[nbArgs++] = _strdup(ptr_astring);

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
        char ptr_d2dstring[40];
        sprintf_s(ptr_d2dstring, "--winrt-d2dcontext=0x%p", m_dxManager->cp_d2dContext);
        argv[nbArgs++] = _strdup(ptr_d2dstring);

        char ptr_scstring[40];
        sprintf_s(ptr_scstring, "--winrt-swapchain=0x%p", m_dxManager->cp_swapChain);
        argv[nbArgs++] = _strdup(ptr_scstring);

        char widthstring[40];
        sprintf_s(widthstring, "--winrt-width=0x%p", &m_width);
        argv[nbArgs++] = _strdup(widthstring);

        char heightstring[40];
        sprintf_s(heightstring, "--winrt-height=0x%p", &m_height);
        argv[nbArgs++] = _strdup(heightstring);
    }

    void Instance::UpdateSize(float x, float y)
    {
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
        const float scaleFactor = Windows::Graphics::Display::DisplayInformation::GetForCurrentView()->RawPixelsPerViewPixel;
#else
        const float scaleFactor = (float) DisplayProperties::ResolutionScale / 100.f;
#endif

107 108
        m_width = (uint32_t)(x * scaleFactor);
        m_height = (uint32_t)(y * scaleFactor);
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    }

    int Instance::addIntf(Platform::String^ name)
    {
        return m_instance.addIntf(VLCString(name));
    }

    void Instance::setUserAgent(Platform::String^ name, Platform::String^ http)
    {
        m_instance.setUserAgent(VLCString(name), VLCString(http));
    }

    void Instance::setAppId(Platform::String^ id, Platform::String^ version, Platform::String^ icon)
    {
        m_instance.setAppId(VLCString(id), VLCString(version), VLCString(icon));
    }

    Windows::Foundation::Collections::IVector<ModuleDescription^>^ Instance::audioFilterList()
    {
        return MarshallVector<ModuleDescription, VLC::ModuleDescription>(m_instance.audioFilterList());
    }

    Windows::Foundation::Collections::IVector<ModuleDescription^>^ Instance::videoFilterList()
    {
        return MarshallVector<ModuleDescription, VLC::ModuleDescription>(m_instance.videoFilterList());
    }

    Windows::Foundation::Collections::IVector<AudioOutputDescription^>^ Instance::audioOutputList()
    {
        return MarshallVector<AudioOutputDescription, VLC::AudioOutputDescription>(m_instance.audioOutputList());
    }

    Windows::Foundation::Collections::IVector<AudioOutputDeviceDescription^>^ Instance::audioOutputDeviceList(Platform::String^ aout)
    {
        return MarshallVector<AudioOutputDeviceDescription, VLC::AudioOutputDeviceDescription>(m_instance.audioOutputDeviceList(VLCString(aout)));
    }

    Instance::~Instance()
    {
    }

} // namespace VLC