Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

video upload support #197

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions winsdkfb/winsdkfb/winsdkfb.Shared/FBVideo.cpp.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<#@ template debug="false" hostspecific="false" language="C#" #>
<# string classDefFile = "..\\winsdkfb.Shared\\FBVideo.xml"; #>
<#@ include file="FBGraphObjectImplementation.ttinclude" #>
3 changes: 3 additions & 0 deletions winsdkfb/winsdkfb/winsdkfb.Shared/FBVideo.h.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<#@ template debug="false" hostspecific="false" language="C#" #>
<# string classDefFile = "..\\winsdkfb.Shared\\FBVideo.xml"; #>
<#@ include file="FBGraphObjectHeader.ttinclude" #>
10 changes: 10 additions & 0 deletions winsdkfb/winsdkfb/winsdkfb.Shared/FBVideo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<class name="FBVideo" bindable="no">
<property name="id" type="string" />
<property name="post_id" type="string" />
<property name="upload_session_id" type="string" />
<property name="video_id" type="string" />
<property name="start_offset" type="string" />
<property name="end_offset" type="string" />
<property name="success" type="bool" />
</class>
126 changes: 126 additions & 0 deletions winsdkfb/winsdkfb/winsdkfb.Shared/FBVideoContentStream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//******************************************************************************
//
// Copyright (c) 2016 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//******************************************************************************

#include "pch.h"
#include "FBVideoContentStream.h"

using namespace concurrency;
using namespace Windows::Storage::Streams;
using namespace Windows::Foundation;

FBVideoContentStream::FBVideoContentStream(
IRandomAccessStream^ stream,
Platform::String^ contentType
) :
_contentType{contentType},
_stream{stream}
{
}

IAsyncOperationWithProgress<IBuffer^, unsigned int>^ FBVideoContentStream::ReadAsync(
Windows::Storage::Streams::IBuffer^ buffer,
unsigned int count,
Windows::Storage::Streams::InputStreamOptions options
)
{
return _stream->ReadAsync(buffer, count, options);
}

IAsyncOperationWithProgress<unsigned int, unsigned int>^ FBVideoContentStream::WriteAsync(Windows::Storage::Streams::IBuffer^ buffer)
{
return _stream->WriteAsync(buffer);
}

IAsyncOperation<bool>^ FBVideoContentStream::FlushAsync()
{
return _stream->FlushAsync();
}

bool FBVideoContentStream::CanRead::get()
{
return _stream->CanRead;
}

bool FBVideoContentStream::CanWrite::get()
{
return _stream->CanWrite;
}

unsigned long long FBVideoContentStream::Position::get()
{
return _stream->Position;
}

unsigned long long FBVideoContentStream::Size::get()
{
return _stream->Size;
}

void FBVideoContentStream::Size::set(unsigned long long value)
{
_stream->Size = value;
}

IInputStream^ FBVideoContentStream::GetInputStreamAt(unsigned long long position)
{
return _stream->GetInputStreamAt(position);
}

IOutputStream^ FBVideoContentStream::GetOutputStreamAt(unsigned long long position)
{
return _stream->GetOutputStreamAt(position);
}

void FBVideoContentStream::Seek(unsigned long long position)
{
_stream->Seek(position);
}

IRandomAccessStream^ FBVideoContentStream::CloneStream()
{
return ref new FBVideoContentStream(_stream->CloneStream(), _contentType);
}

Platform::String^ FBVideoContentStream::ContentType::get()
{
return _contentType;
}

FBVideoContentStream::~FBVideoContentStream()
{
}

IAsyncOperation<FBVideoContentStream^>^ FBVideoContentStream::TruncateCloneStreamAsync(unsigned long long position, unsigned int size)
{
unsigned long long oldPosition = _stream->Position;
_stream->Seek(position);
IBuffer^ buffer = ref new Buffer(size);

task<FBVideoContentStream^> workTask = create_task(_stream->ReadAsync(buffer, size, InputStreamOptions::None)).then([=](IBuffer^ filledBuffer)
{
_stream->Seek(oldPosition);
InMemoryRandomAccessStream^ memoryStream = ref new InMemoryRandomAccessStream();
return create_task(memoryStream->WriteAsync(filledBuffer)).then([=](unsigned int count)
{
memoryStream->Seek(0);
return ref new FBVideoContentStream(memoryStream, _contentType);
});
});
return create_async([=]()
{
return workTask;
});
}
101 changes: 101 additions & 0 deletions winsdkfb/winsdkfb/winsdkfb.Shared/FBVideoContentStream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//******************************************************************************
//
// Copyright (c) 2016 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//******************************************************************************

#pragma once

using namespace Windows::Storage::Streams;

ref class FBVideoContentStream sealed : IRandomAccessStreamWithContentType
{
public:

FBVideoContentStream(
IRandomAccessStream^ stream,
Platform::String^ contentType
);

// Inherited via IRandomAccessStream
virtual Windows::Foundation::IAsyncOperationWithProgress<Windows::Storage::Streams::IBuffer^, unsigned int>^
ReadAsync(
Windows::Storage::Streams::IBuffer^buffer,
unsigned int count,
Windows::Storage::Streams::InputStreamOptions options
);

virtual Windows::Foundation::IAsyncOperationWithProgress<unsigned int, unsigned int>^
WriteAsync(
Windows::Storage::Streams::IBuffer^buffer
);

virtual Windows::Foundation::IAsyncOperation<bool>^ FlushAsync();

virtual property bool CanRead
{
bool get();
}

virtual property bool CanWrite
{
bool get();
}

virtual property unsigned long long Position
{
unsigned long long get();
}

virtual property unsigned long long Size
{
unsigned long long get();
void set(unsigned long long);
}

virtual Windows::Storage::Streams::IInputStream^ GetInputStreamAt(
unsigned long long position
);

virtual Windows::Storage::Streams::IOutputStream^ GetOutputStreamAt(
unsigned long long position
);

virtual void Seek(
unsigned long long position
);

virtual Windows::Storage::Streams::IRandomAccessStream^ CloneStream();

// Inherited via IContentTypeProvider
virtual property Platform::String^ ContentType
{
Platform::String^ get();
}

virtual ~FBVideoContentStream();

/**
* Clones a portion of the stream into another object.
* @param position The position in the stream to start the clone at
* @param size The amount of bytes to clone
* @return The cloned, truncated FBVideoContentStream
*/
Windows::Foundation::IAsyncOperation<FBVideoContentStream^>^ TruncateCloneStreamAsync(
unsigned long long position,
unsigned int size
);
private:
Platform::String^ _contentType;
IRandomAccessStream^ _stream;
};
Loading