summaryrefslogtreecommitdiffstats
path: root/xrdpapi
diff options
context:
space:
mode:
Diffstat (limited to 'xrdpapi')
-rw-r--r--xrdpapi/simple.c15
-rw-r--r--xrdpapi/vrplayer.c95
-rw-r--r--xrdpapi/vrplayer.mk5
-rw-r--r--xrdpapi/xrdpapi.c59
-rw-r--r--xrdpapi/xrdpapi.h29
5 files changed, 155 insertions, 48 deletions
diff --git a/xrdpapi/simple.c b/xrdpapi/simple.c
index e6f5bd16..afe1a22c 100644
--- a/xrdpapi/simple.c
+++ b/xrdpapi/simple.c
@@ -101,6 +101,7 @@ run_echo_test()
/* open a virtual channel named ECHO */
channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "ECHO", WTS_CHANNEL_OPTION_DYNAMIC_PRI_LOW);
+
if (channel == NULL)
{
printf("### WTSVirtualChannelOpenEx() failed!\n");
@@ -117,6 +118,7 @@ run_echo_test()
/* write data to virtual channel */
count = (bytes_left > 1700) ? 1700 : bytes_left;
rv = WTSVirtualChannelWrite(channel, wr_ptr, count, &bytes_written);
+
if ((rv == 0) || (bytes_written == 0))
{
printf("### WTSVirtualChannelWrite() failed\n");
@@ -129,6 +131,7 @@ run_echo_test()
{
/* read back the echo */
rv = WTSVirtualChannelRead(channel, 5000, in_buf, count, &bytes_read);
+
if ((rv == 0) || (bytes_read == 0))
{
printf("### WTSVirtualChannelRead() failed\n");
@@ -145,6 +148,7 @@ run_echo_test()
return -1;
}
}
+
count -= bytes_read;
}
@@ -153,26 +157,27 @@ run_echo_test()
printf("### pkt %d passed echo test\n", pkt_count++);
}
- WTSVirtualChannelClose(channel);
- return 0;
+ WTSVirtualChannelClose(channel);
+ return 0;
}
int
run_tsmf_test()
{
- void *channel;
+ void *channel;
printf("this test not yet implemented!\n");
return 1;
/* open virtual channel */
channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "TSMF", WTS_CHANNEL_OPTION_DYNAMIC_PRI_LOW);
+
if (channel == NULL)
{
printf("### WTSVirtualChannelOpenEx() failed!\n");
return 1;
}
- WTSVirtualChannelClose(channel);
- return 0;
+ WTSVirtualChannelClose(channel);
+ return 0;
}
diff --git a/xrdpapi/vrplayer.c b/xrdpapi/vrplayer.c
new file mode 100644
index 00000000..442ef35e
--- /dev/null
+++ b/xrdpapi/vrplayer.c
@@ -0,0 +1,95 @@
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Laxmikant Rashinkar 2012 LK.Rashinkar@gmail.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * a program that uses xrdpapi and ffmpeg to redirect media streams
+ * to a FreeRDP client where it is decompressed and played locally
+ *
+ */
+
+/******************************************************************************
+ * build instructions: make -f vrplayer.mk
+ * setup environment: export LD_LIBRARY_PATH=".libs:../xrdpvr/.libs"
+ * run vrplayer: vrplayer <media file>
+ *****************************************************************************/
+
+#ifdef __WIN32__
+#include <mstsapi.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h>
+
+#include "xrdpapi.h"
+#include "xrdpvr.h"
+
+void
+extract_32(uint32_t *value, char *buf)
+{
+ *value = ((buf[3] << 24) & 0xff000000)
+ | ((buf[2] << 16) & 0x00ff0000)
+ | ((buf[1] << 8) & 0x0000ff00)
+ | (buf[0] & 0x000000ff);
+}
+
+int
+main(int argc, char **argv)
+{
+ char *data;
+ char *data1;
+ void *channel;
+ int written = 0;
+ int rv;
+ int first_time = 1;
+ int length;
+ int bytes_read;
+
+ if (argc < 2)
+ {
+ printf("usage: vrplayer <media filename> >\n");
+ return 1;
+ }
+
+ /* open a virtual channel and connect to remote client */
+ channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "xrdpvr", 0);
+
+ if (channel == NULL)
+ {
+ fprintf(stderr, "WTSVirtualChannelOpenEx() failed\n");
+ return 1;
+ }
+
+ /* initialize the player */
+ if (xrdpvr_init_player(channel, 101, argv[1]))
+ {
+ fprintf(stderr, "failed to initialize the player\n");
+ return 1;
+ }
+
+ /* send compressed media data to client; client will decompress */
+ /* the media and play it locally */
+ xrdpvr_play_media(channel, 101, argv[1]);
+
+ /* perform clean up */
+ xrdpvr_deinit_player(channel, 101);
+
+ WTSVirtualChannelClose(channel);
+ return 0;
+}
diff --git a/xrdpapi/vrplayer.mk b/xrdpapi/vrplayer.mk
new file mode 100644
index 00000000..15daf0f6
--- /dev/null
+++ b/xrdpapi/vrplayer.mk
@@ -0,0 +1,5 @@
+CFLAGS = -I../xrdpvr
+LIBS = -L./.libs -L../xrdpvr/.libs -lxrdpapi -lxrdpvr -lavformat
+
+vrplayer: vrplayer.o
+ gcc $(CFLAGS) vrplayer.c -o vrplayer $(LIBS)
diff --git a/xrdpapi/xrdpapi.c b/xrdpapi/xrdpapi.c
index e320ef5d..973deb48 100644
--- a/xrdpapi/xrdpapi.c
+++ b/xrdpapi/xrdpapi.c
@@ -152,57 +152,57 @@ WTSVirtualChannelOpenEx(unsigned int SessionId, const char *pVirtualName,
return wts;
}
+/*
+ * write data to client connection
+ *
+ * @return 0 on success, -1 on error
/*****************************************************************************/
int
WTSVirtualChannelWrite(void *hChannelHandle, const char *Buffer,
unsigned int Length, unsigned int *pBytesWritten)
{
struct wts_obj *wts;
- int error;
- int lerrno;
+ int rv;
- wts = (struct wts_obj *)hChannelHandle;
+ wts = (struct wts_obj *) hChannelHandle;
+
+ *pBytesWritten = 0;
if (wts == 0)
{
- return 0;
+ LLOGLN(10, ("WTSVirtualChannelWrite: wts is NULL"));
+ return -1;
}
if (wts->status != 1)
{
- return 0;
+ LLOGLN(10, ("WTSVirtualChannelWrite: wts->status != 1"));
+ return -1;
}
- if (can_send(wts->fd, 0))
+ if (!can_send(wts->fd, 0))
{
- error = send(wts->fd, Buffer, Length, 0);
+ return 0; /* can't write now, ok to try again */
+ }
- if (error == -1)
- {
- lerrno = errno;
+ rv = send(wts->fd, Buffer, Length, 0);
+ LLOGLN(10, ("WTSVirtualChannelWrite: send() reted %d", rv));
- if ((lerrno == EWOULDBLOCK) || (lerrno == EAGAIN) ||
- (lerrno == EINPROGRESS))
- {
- *pBytesWritten = 0;
- return 1;
- }
+ if (rv >= 0)
+ {
+ /* success, but zero bytes may have been written */
+ *pBytesWritten = rv;
+ return 0;
+ }
- return 0;
- }
- else if (error == 0)
- {
- return 0;
- }
- else if (error > 0)
- {
- *pBytesWritten = error;
- return 1;
- }
+ /* error, but is it ok to try again? */
+ if ((rv == EWOULDBLOCK) || (rv == EAGAIN) || (rv == EINPROGRESS))
+ {
+ return 0; /* failed to send, but should try again */
}
- *pBytesWritten = 0;
- return 1;
+ /* fatal error */
+ return -1;
}
/*****************************************************************************/
@@ -241,6 +241,7 @@ WTSVirtualChannelRead(void *hChannelHandle, unsigned int TimeOut,
*pBytesRead = 0;
return 1;
}
+
return 0;
}
else if (rv == 0)
diff --git a/xrdpapi/xrdpapi.h b/xrdpapi/xrdpapi.h
index fdb998cf..81e5acd5 100644
--- a/xrdpapi/xrdpapi.h
+++ b/xrdpapi/xrdpapi.h
@@ -45,32 +45,33 @@ typedef enum _WTS_VIRTUAL_CLASS
{
WTSVirtualClientData,
WTSVirtualFileHandle
-} WTS_VIRTUAL_CLASS;
+}
+WTS_VIRTUAL_CLASS;
/*
* Reference:
* http://msdn.microsoft.com/en-us/library/windows/desktop/aa383464(v=vs.85).aspx
*/
-void* WTSVirtualChannelOpen(void* hServer, unsigned int SessionId,
- const char* pVirtualName);
+void *WTSVirtualChannelOpen(void *hServer, unsigned int SessionId,
+ const char *pVirtualName);
-void* WTSVirtualChannelOpenEx(unsigned int SessionId,
- const char* pVirtualName, unsigned int flags);
+void *WTSVirtualChannelOpenEx(unsigned int SessionId,
+ const char *pVirtualName, unsigned int flags);
-int WTSVirtualChannelWrite(void* hChannelHandle, const char* Buffer,
- unsigned int Length, unsigned int* pBytesWritten);
+int WTSVirtualChannelWrite(void *hChannelHandle, const char *Buffer,
+ unsigned int Length, unsigned int *pBytesWritten);
-int WTSVirtualChannelRead(void* hChannelHandle, unsigned int TimeOut,
- char* Buffer, unsigned int BufferSize,
- unsigned int* pBytesRead);
+int WTSVirtualChannelRead(void *hChannelHandle, unsigned int TimeOut,
+ char *Buffer, unsigned int BufferSize,
+ unsigned int *pBytesRead);
-int WTSVirtualChannelClose(void* hChannelHandle);
+int WTSVirtualChannelClose(void *hChannelHandle);
-int WTSVirtualChannelQuery(void* hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
- void** ppBuffer, unsigned int* pBytesReturned);
+int WTSVirtualChannelQuery(void *hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
+ void **ppBuffer, unsigned int *pBytesReturned);
-void WTSFreeMemory(void* pMemory);
+void WTSFreeMemory(void *pMemory);
#ifdef __cplusplus
}