-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathBackEndTransport.cpp
More file actions
executable file
·74 lines (59 loc) · 2.41 KB
/
Copy pathBackEndTransport.cpp
File metadata and controls
executable file
·74 lines (59 loc) · 2.41 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// This is the source code of Telegram for Windows Phone v. 3.x.x.
// It is licensed under GNU GPL v. 2 or later.
// You should have received a copy of the license in this archive (see LICENSE).
//
// Copyright Evgeny Nadymov, 2013-present.
//
#include "BackEndTransport.h"
#include "BackEndNativeBuffer.h"
#include <ppltasks.h>
using namespace PhoneVoIPApp::BackEnd;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Storage::Streams;
using namespace Windows::System::Threading;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Details;
BackEndTransport::BackEndTransport()
{
}
void BackEndTransport::WriteAudio(BYTE* bytes, int byteCount)
{
Write(bytes, byteCount, TransportMessageType::Audio, 0, 0);
}
void BackEndTransport::WriteVideo(BYTE* bytes, int byteCount, UINT64 hnsPresenationTime, UINT64 hnsSampleDuration)
{
Write(bytes, byteCount, TransportMessageType::Video, hnsPresenationTime, hnsSampleDuration);
}
void BackEndTransport::Write(BYTE* bytes, int byteCount, TransportMessageType::Value dataType, UINT64 hnsPresenationTime, UINT64 hnsSampleDuration)
{
static const int MaxPacketSize = 10*1024*1024;
int bytesToSend = byteCount;
while (bytesToSend)
{
int chunkSize = bytesToSend > MaxPacketSize ? MaxPacketSize : bytesToSend;
ComPtr<NativeBuffer> spNativeBuffer = NULL;
if (dataType == TransportMessageType::Audio)
{
MakeAndInitialize<NativeBuffer>(&spNativeBuffer, bytes, chunkSize, FALSE);
AudioMessageReceived(NativeBuffer::GetIBufferFromNativeBuffer(spNativeBuffer), hnsPresenationTime, hnsSampleDuration);
}
else
{
// Temporarily duplicating this for sample so that MSS can own this
// buffer, and will be released when the stream itself is released
BYTE* pMem = new BYTE[chunkSize];
memcpy((void*) pMem, (void*) bytes, chunkSize);
MakeAndInitialize<NativeBuffer>(&spNativeBuffer, pMem, chunkSize, TRUE);
VideoMessageReceived(NativeBuffer::GetIBufferFromNativeBuffer(spNativeBuffer), hnsPresenationTime, hnsSampleDuration);
}
// Increment byte position
bytes += chunkSize;
bytesToSend -= chunkSize;
}
return;
}
BackEndTransport::~BackEndTransport()
{
}