Commit dcb7ba53 authored by Ghislain MARY's avatar Ghislain MARY

Display almost working.

parent 32b6326b
......@@ -32,65 +32,62 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <windows.storage.streams.h>
namespace Mediastreamer2
namespace libmswinrtvid
{
namespace WP8Video
/// <summary>
/// The purpose of this class is to transform byte buffers into an IBuffer
/// </summary>
class VideoBuffer : public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags< Microsoft::WRL::RuntimeClassType::WinRtClassicComMix >,
ABI::Windows::Storage::Streams::IBuffer,
Windows::Storage::Streams::IBufferByteAccess,
Microsoft::WRL::FtmBase>
{
/// <summary>
/// The purpose of this class is to transform byte buffers into an IBuffer
/// </summary>
class VideoBuffer : public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags< Microsoft::WRL::RuntimeClassType::WinRtClassicComMix >,
ABI::Windows::Storage::Streams::IBuffer,
Windows::Storage::Streams::IBufferByteAccess,
Microsoft::WRL::FtmBase>
{
public:
virtual ~VideoBuffer() {
if (mBuffer) {
delete[] mBuffer;
mBuffer = NULL;
}
public:
virtual ~VideoBuffer() {
if (mBuffer) {
delete[] mBuffer;
mBuffer = NULL;
}
STDMETHODIMP RuntimeClassInitialize(BYTE* pBuffer, UINT size) {
mSize = size;
mBuffer = new BYTE[size];
memcpy((void*)mBuffer, (void*)pBuffer, size);
return S_OK;
}
STDMETHODIMP Buffer(BYTE **value) {
*value = mBuffer;
return S_OK;
}
STDMETHODIMP get_Capacity(UINT32 *value) {
*value = mSize;
return S_OK;
}
STDMETHODIMP get_Length(UINT32 *value) {
*value = mSize;
return S_OK;
}
STDMETHODIMP put_Length(UINT32 value) {
if(value > mSize) {
return E_INVALIDARG;
}
mSize = value;
return S_OK;
}
STDMETHODIMP RuntimeClassInitialize(BYTE* pBuffer, UINT size) {
mSize = size;
mBuffer = new BYTE[size];
memcpy((void*)mBuffer, (void*)pBuffer, size);
return S_OK;
}
STDMETHODIMP Buffer(BYTE **value) {
*value = mBuffer;
return S_OK;
}
STDMETHODIMP get_Capacity(UINT32 *value) {
*value = mSize;
return S_OK;
}
STDMETHODIMP get_Length(UINT32 *value) {
*value = mSize;
return S_OK;
}
STDMETHODIMP put_Length(UINT32 value) {
if(value > mSize) {
return E_INVALIDARG;
}
static Windows::Storage::Streams::IBuffer^ GetIBuffer(Microsoft::WRL::ComPtr<VideoBuffer> spVideoBuffer) {
auto iinspectable = reinterpret_cast<IInspectable*>(spVideoBuffer.Get());
return reinterpret_cast<Windows::Storage::Streams::IBuffer^>(iinspectable);
}
private:
UINT32 mSize;
BYTE* mBuffer;
};
}
mSize = value;
return S_OK;
}
static Windows::Storage::Streams::IBuffer^ GetIBuffer(Microsoft::WRL::ComPtr<VideoBuffer> spVideoBuffer) {
auto iinspectable = reinterpret_cast<IInspectable*>(spVideoBuffer.Get());
return reinterpret_cast<Windows::Storage::Streams::IBuffer^>(iinspectable);
}
private:
UINT32 mSize;
BYTE* mBuffer;
};
}
......@@ -141,7 +141,7 @@ int MSWinRTCap::activate()
#if defined(MS2_WINDOWS_UNIVERSAL)
mCapture = ref new MediaCapture();
MediaCaptureInitializationSettings^ initSettings = ref new MediaCaptureInitializationSettings();
//initSettings->MediaCategory = MediaCategory::Communications;
initSettings->MediaCategory = MediaCategory::Communications;
initSettings->VideoDeviceId = mDeviceId;
initSettings->StreamingCaptureMode = StreamingCaptureMode::Video;
IAsyncAction^ initAction = mCapture->InitializeAsync(initSettings);
......@@ -660,6 +660,8 @@ bool MSWinRTCap::selectBestVideoSize()
void MSWinRTCap::configure()
{
#if defined(MS2_WINDOWS_UNIVERSAL)
mEncodingProfile = MediaEncodingProfile::CreateMp4(VideoEncodingQuality::Auto);
#if 0
mEncodingProfile = ref new MediaEncodingProfile();
if (mPixFmt == MS_H264) {
mEncodingProfile->Video = VideoEncodingProperties::CreateH264();
......@@ -669,6 +671,7 @@ void MSWinRTCap::configure()
} else {
mEncodingProfile->Video = VideoEncodingProperties::CreateUncompressed(MediaEncodingSubtypes::Nv12, mVConf.vsize.width, mVConf.vsize.height);
}
#endif
#elif defined(MS2_WINDOWS_PHONE)
bool unMuteAudio = true;
bool supportH264BaselineProfile = false;
......
This diff is collapsed.
......@@ -28,59 +28,136 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <mediastreamer2/rfc3984.h>
#ifdef MS2_WINDOWS_PHONE
#include <implements.h>
#endif
#include <collection.h>
#include <ppltasks.h>
#include <mutex>
#include <robuffer.h>
#include <windows.storage.streams.h>
#ifdef MS2_WINDOWS_PHONE
#include "IVideoRenderer.h"
#endif
class MSWinRTDis {
public:
MSWinRTDis();
virtual ~MSWinRTDis();
int activate();
int deactivate();
bool isStarted() { return mIsStarted; }
void start();
void stop();
int feed(MSFilter *f);
MSVideoSize getVideoSize();
void setVideoSize(MSVideoSize vs);
void setPixFmt(MSPixFmt pix_fmt) { mPixFmt = pix_fmt; }
#ifdef MS2_WINDOWS_PHONE
Mediastreamer2::WinRTVideo::IVideoRenderer^ getVideoRenderer();
void setVideoRenderer(Mediastreamer2::WinRTVideo::IVideoRenderer^ renderer);
namespace libmswinrtvid
{
class MSWinRTDis;
private ref class MSWinRTDisSample sealed
{
public:
MSWinRTDisSample(Windows::Storage::Streams::IBuffer^ pBuffer, UINT64 hnsPresentationTime)
{
this->Buffer = pBuffer;
this->PresentationTime = hnsPresentationTime;
}
property Windows::Storage::Streams::IBuffer^ Buffer
{
Windows::Storage::Streams::IBuffer^ get() { return mBuffer; };
void set(Windows::Storage::Streams::IBuffer^ value) { mBuffer = value; };
}
property UINT64 PresentationTime
{
UINT64 get() { return mPresentationTime; };
void set(UINT64 value) { mPresentationTime = value; };
}
private:
~MSWinRTDisSample() {};
Windows::Storage::Streams::IBuffer^ mBuffer;
UINT64 mPresentationTime;
};
private ref class MSWinRTDisSampleHandler sealed
{
public:
MSWinRTDisSampleHandler();
virtual ~MSWinRTDisSampleHandler();
void StartMediaElement();
void StopMediaElement();
void Feed(Windows::Storage::Streams::IBuffer^ pBuffer, UINT64 hnsPresentationTime);
void OnSampleRequested(Windows::Media::Core::MediaStreamSource ^sender, Windows::Media::Core::MediaStreamSourceSampleRequestedEventArgs ^args);
void RequestMediaElementRestart();
property unsigned int PixFmt
{
unsigned int get() { return mPixFmt; }
void set(unsigned int value) { mPixFmt = (MSPixFmt)value; }
}
property Windows::UI::Xaml::Controls::MediaElement^ MediaElement
{
Windows::UI::Xaml::Controls::MediaElement^ get() { return mMediaElement; }
void set(Windows::UI::Xaml::Controls::MediaElement^ value) { mMediaElement = value; }
}
property int Width
{
int get() { return mWidth; }
void set(int value) { mWidth = value; }
}
property int Height
{
int get() { return mHeight; }
void set(int value) { mHeight = value; }
}
private:
void AnswerSampleRequest(Windows::Media::Core::MediaStreamSourceSampleRequest^ sampleRequest);
Platform::Collections::Vector<MSWinRTDisSample^>^ mSampleQueue;
Windows::Media::Core::MediaStreamSourceSampleRequest^ mSampleRequest;
Windows::Media::Core::MediaStreamSourceSampleRequestDeferral^ mSampleRequestDeferral;
Windows::UI::Xaml::Controls::MediaElement^ mMediaElement;
std::mutex mMutex;
MSPixFmt mPixFmt;
int mWidth;
int mHeight;
};
class MSWinRTDis {
public:
MSWinRTDis();
virtual ~MSWinRTDis();
int activate();
int deactivate();
bool isStarted() { return mIsStarted; }
void start();
void stop();
int feed(MSFilter *f);
MSVideoSize getVideoSize();
void setVideoSize(MSVideoSize vs);
void setPixFmt(MSPixFmt pix_fmt) { mSampleHandler->PixFmt = pix_fmt; }
void enableAVPF(bool enable) { mAVPFEnabled = enable; }
void setMediaElement(Windows::UI::Xaml::Controls::MediaElement^ mediaElement) { mSampleHandler->MediaElement = mediaElement; }
private:
int nalusToFrame(MSQueue *nalus, bool *new_sps_pps);
void enlargeBitstream(int newSize);
bool checkSPSChange(mblk_t *sps);
bool checkPPSChange(mblk_t *pps);
void updateSPS(mblk_t *sps);
void updatePPS(mblk_t *pps);
void updateVideoSizeFromSPS();
#if 0
void startMediaElement();
void stopMediaElement();
#endif
private:
int nalusToFrame(MSQueue *nalus, bool *new_sps_pps);
void enlargeBitstream(int newSize);
bool checkSPSChange(mblk_t *sps);
bool checkPPSChange(mblk_t *pps);
void updateSPS(mblk_t *sps);
void updatePPS(mblk_t *pps);
void updateVideoSizeFromSPS();
static bool smInstantiated;
bool mIsInitialized;
bool mIsActivated;
bool mIsStarted;
int mWidth;
int mHeight;
Rfc3984Context *mRfc3984Unpacker;
MSPixFmt mPixFmt;
int mBitstreamSize;
uint8_t *mBitstream;
mblk_t *mSPS;
mblk_t *mPPS;
#ifdef MS2_WINDOWS_PHONE
Mediastreamer2::WinRTVideo::IVideoRenderer^ mRenderer;
#endif
bool mFirstFrameReceived;
};
static bool smInstantiated;
bool mIsInitialized;
bool mIsActivated;
bool mIsStarted;
Rfc3984Context *mRfc3984Unpacker;
int mBitstreamSize;
uint8_t *mBitstream;
mblk_t *mSPS;
mblk_t *mPPS;
bool mAVPFEnabled;
MSWinRTDisSampleHandler^ mSampleHandler;
Windows::Media::Core::MediaStreamSource^ mMediaStreamSource;
bool mFirstFrameReceived;
};
}
......@@ -32,7 +32,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
//using namespace Mediastreamer2::WinRTVideo;
using namespace libmswinrtvid;
#ifdef MS2_WINDOWS_PHONE
using namespace Mediastreamer2::WinRTVideo;
#endif
/******************************************************************************
......@@ -273,13 +276,18 @@ static void ms_winrtdis_init(MSFilter *f) {
static void ms_winrtdis_preprocess(MSFilter *f) {
MSWinRTDis *w = static_cast<MSWinRTDis *>(f->data);
w->activate();
#ifdef MS2_WINDOWS_UNIVERSAL
w->start();
#endif
}
static void ms_winrtdis_process(MSFilter *f) {
MSWinRTDis *w = static_cast<MSWinRTDis *>(f->data);
#ifdef MS2_WINDOWS_PHONE
if (!w->isStarted()) {
w->start();
}
#endif
if (w->isStarted()) {
w->feed(f);
}
......@@ -329,10 +337,20 @@ static int ms_winrtdis_support_rendering(MSFilter *f, void *arg) {
return 0;
}
static int ms_winrtdis_enable_avpf(MSFilter *f, void *arg) {
MSWinRTDis *w = static_cast<MSWinRTDis *>(f->data);
w->enableAVPF(*((bool_t *)arg) ? true : false);
return 0;
}
static int ms_winrtdis_set_native_window_id(MSFilter *f, void *arg) {
MSWinRTDis *w = static_cast<MSWinRTDis *>(f->data);
#if defined(MS2_WINDOWS_UNIVERSAL)
RefToPtrProxy<Platform::Object^> *proxy = static_cast<RefToPtrProxy<Platform::Object^>*>((void *)(*((PULONG_PTR)arg)));
Windows::UI::Xaml::Controls::MediaElement^ mediaElement = dynamic_cast<Windows::UI::Xaml::Controls::MediaElement^>(proxy->Ref());
w->setMediaElement(mediaElement);
#elif defined(MS2_WINDOWS_PHONE)
unsigned long *ptr = (unsigned long *)arg;
#ifdef MS2_WINDOWS_PHONE
RefToPtrProxy<IVideoRenderer^> *proxy = reinterpret_cast< RefToPtrProxy<IVideoRenderer^> *>(*ptr);
IVideoRenderer^ renderer = (proxy) ? proxy->Ref() : nullptr;
w->setVideoRenderer(renderer);
......@@ -345,6 +363,7 @@ static MSFilterMethod ms_winrtdis_methods[] = {
{ MS_FILTER_SET_VIDEO_SIZE, ms_winrtdis_set_vsize },
{ MS_FILTER_SET_PIX_FMT, ms_winrtdis_set_pix_fmt },
{ MS_VIDEO_DECODER_SUPPORT_RENDERING, ms_winrtdis_support_rendering },
{ MS_VIDEO_DECODER_ENABLE_AVPF, ms_winrtdis_enable_avpf },
{ MS_VIDEO_DISPLAY_SET_NATIVE_WINDOW_ID, ms_winrtdis_set_native_window_id },
{ 0, NULL }
};
......
......@@ -43,6 +43,7 @@
<ClInclude Include="..\..\mswinrtcap.h" />
<ClInclude Include="..\..\mswinrtdis.h" />
<ClInclude Include="..\..\mswinrtvid.h" />
<ClInclude Include="..\..\VideoBuffer.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{2d0e44c4-e51d-4911-b876-345d1e5e5209}</ProjectGuid>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment