New gstreamer 1.0 code.

This commit is contained in:
Armin Novak 2014-05-23 13:46:37 +02:00
parent 309405592e
commit 7b455448f2
4 changed files with 980 additions and 1401 deletions

View File

@ -7,7 +7,7 @@
# 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
# 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,
@ -17,8 +17,36 @@
define_channel_client_subsystem("tsmf" "gstreamer" "decoder")
set(${MODULE_PREFIX}_SRCS
tsmf_gstreamer.c)
if(NOT GSTREAMER_FOUND)
message(FATAL_ERROR "GStreamer library not found, but required for TSMF module.")
endif()
set(SRC "tsmf_gstreamer.c")
set(LIBS ${GSTREAMER_LIBRARIES})
if(ANDROID)
set(SRC ${SRC}
tsmf_android.c)
set(LIBS ${LIBS})
else()
set(XEXT_FEATURE_TYPE "RECOMMENDED")
set(XEXT_FEATURE_PURPOSE "X11 extension")
set(XEXT_FEATURE_DESCRIPTION "X11 core extensions")
find_feature(Xext ${XEXT_FEATURE_TYPE} ${XEXT_FEATURE_PURPOSE} ${XEXT_FEATURE_DESCRIPTION})
set(SRC ${SRC}
tsmf_X11.c)
set(LIBS ${LIBS} ${X11_LIBRARIES} ${XEXT_LIBRARIES})
if(NOT XEXT_FOUND)
message(FATAL_ERROR "Xext library not found, but required for TSMF module.")
else()
add_definitions(-DWITH_XEXT=1)
endif()
endif()
set(${MODULE_PREFIX}_SRCS "${SRC}")
include_directories(..)
include_directories(${GSTREAMER_INCLUDE_DIRS})
@ -28,15 +56,12 @@ add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_N
set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "")
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
MONOLITHIC ${MONOLITHIC_BUILD}
MODULE freerdp
MODULES freerdp-utils)
MONOLITHIC ${MONOLITHIC_BUILD}
MODULE freerdp
MODULES freerdp-utils)
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS}
${GSTREAMER_LIBRARIES}
gstapp-0.10
gstinterfaces-0.10
Xrandr X11 Xext)
${LIBS})
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})

View File

@ -0,0 +1,240 @@
#include <assert.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <fcntl.h>
#include <winpr/thread.h>
#include <gst/video/videooverlay.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#include <X11/extensions/shape.h>
#include <freerdp/channels/tsmf.h>
#include "tsmf_platform.h"
#include "tsmf_constants.h"
#include "tsmf_decoder.h"
#if !defined(WITH_XEXT)
#warning "Building TSMF without shape extension support"
#endif
struct X11Handle
{
int shmid;
int *xfwin;
#if defined(WITH_XEXT)
BOOL has_shape;
#endif
Display *disp;
Window subwin;
};
static const char *get_shm_id()
{
static char shm_id[64];
snprintf(shm_id, sizeof(shm_id), "com.freerdp.xfreerpd.tsmf_%016X", GetCurrentProcessId());
return shm_id;
}
const char *tsmf_platform_get_video_sink(void)
{
return "xvimagesink";
}
const char *tsmf_platform_get_audio_sink(void)
{
return "autoaudiosink";
}
int tsmf_platform_create(TSMFGstreamerDecoder *decoder)
{
struct X11Handle *hdl;
assert(decoder);
assert(!decoder->platform);
hdl = malloc(sizeof(struct X11Handle));
if(!hdl)
{
DEBUG_WARN("%s: Could not allocate handle.", __func__);
return -1;
}
memset(hdl, 0, sizeof(struct X11Handle));
decoder->platform = hdl;
hdl->shmid = shm_open(get_shm_id(), O_RDWR, PROT_READ | PROT_WRITE);;
if(hdl->shmid < 0)
{
DEBUG_WARN("%s: failed to get access to shared memory - shmget()",
__func__);
return -2;
}
else
hdl->xfwin = mmap(0, sizeof(void *), PROT_READ | PROT_WRITE, MAP_SHARED, hdl->shmid, 0);
if(hdl->xfwin == (int *)-1)
{
DEBUG_WARN("%s: shmat failed!", __func__);
return -3;
}
hdl->disp = XOpenDisplay(NULL);
if(!hdl->disp)
{
DEBUG_WARN("Failed to open display");
return -4;
}
return 0;
}
int tsmf_platform_set_format(TSMFGstreamerDecoder *decoder)
{
assert(decoder);
if(decoder->media_type == TSMF_MAJOR_TYPE_VIDEO)
{
}
return 0;
}
int tsmf_platform_register_handler(TSMFGstreamerDecoder *decoder)
{
assert(decoder);
assert(decoder->pipe);
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(decoder->pipe));
if(!bus)
{
DEBUG_WARN("gst_pipeline_get_bus failed!");
return 1;
}
return 0;
}
int tsmf_platform_free(TSMFGstreamerDecoder *decoder)
{
struct X11Handle *hdl = decoder->platform;
if(!hdl)
return -1;
if(hdl->disp)
XCloseDisplay(hdl->disp);
if(hdl->xfwin)
munmap(0, sizeof(void *));
if(hdl->shmid >= 0)
close(hdl->shmid);
free(hdl);
decoder->platform = NULL;
return 0;
}
int tsmf_window_create(TSMFGstreamerDecoder *decoder)
{
if(decoder->media_type != TSMF_MAJOR_TYPE_VIDEO)
{
decoder->ready = TRUE;
return -3;
}
else
{
int shmid;
GstVideoOverlay *overlay = GST_VIDEO_OVERLAY(decoder->outsink);
struct X11Handle *hdl = (struct X11Handle *)decoder->platform;
assert(decoder);
assert(hdl);
if(!hdl->subwin)
{
int event, error;
hdl->subwin = XCreateSimpleWindow(hdl->disp, *(int *)hdl->xfwin, 0, 0, 1, 1, 0, 0, 0);
if(!hdl->subwin)
{
DEBUG_WARN("Could not create subwindow!");
}
XSetWindowBackgroundPixmap(hdl->disp, hdl->subwin, None);
XMapWindow(hdl->disp, hdl->subwin);
XSync(hdl->disp, FALSE);
gst_video_overlay_set_window_handle(overlay, hdl->subwin);
decoder->ready = TRUE;
#if defined(WITH_XEXT)
hdl->has_shape = XShapeQueryExtension(hdl->disp, &event, &error);
#endif
}
gst_video_overlay_handle_events(overlay, TRUE);
return 0;
}
}
int tsmf_window_resize(TSMFGstreamerDecoder *decoder, int x, int y, int width,
int height, int nr_rects, RDP_RECT *rects)
{
if(decoder->media_type != TSMF_MAJOR_TYPE_VIDEO)
return -3;
else
{
GstVideoOverlay *overlay = GST_VIDEO_OVERLAY(decoder->outsink);
struct X11Handle *hdl = (struct X11Handle *)decoder->platform;
DEBUG_TSMF("resize: x=%d, y=%d, w=%d, h=%d", x, y, width, height);
assert(decoder);
assert(hdl);
if(!gst_video_overlay_set_render_rectangle(overlay, 0, 0, width, height))
{
DEBUG_WARN("Could not resize overlay!");
}
gst_video_overlay_expose(overlay);
if(hdl->subwin)
{
XMoveResizeWindow(hdl->disp, hdl->subwin, x, y, width, height);
#if defined(WITH_XEXT)
if(hdl->has_shape)
{
int i;
XRectangle *xrects = calloc(nr_rects, sizeof(XRectangle));
for(i=0; i<nr_rects; i++)
{
xrects[i].x = rects[i].x - x;
xrects[i].y = rects[i].y - y;
xrects[i].width = rects[i].width;
xrects[i].height = rects[i].height;
}
XShapeCombineRectangles(hdl->disp, hdl->subwin, ShapeBounding, x, y, xrects, nr_rects, ShapeSet, 0);
free(xrects);
}
#endif
XSync(hdl->disp, FALSE);
}
return 0;
}
}
int tsmf_window_pause(TSMFGstreamerDecoder *decoder)
{
struct X11Handle *hdl = (struct X11Handle *)decoder->platform;
assert(decoder);
assert(hdl);
return 0;
}
int tsmf_window_resume(TSMFGstreamerDecoder *decoder)
{
struct X11Handle *hdl = (struct X11Handle *)decoder->platform;
assert(decoder);
assert(hdl);
return 0;
}
int tsmf_window_destroy(TSMFGstreamerDecoder *decoder)
{
struct X11Handle *hdl = (struct X11Handle *)decoder->platform;
decoder->ready = FALSE;
if(decoder->media_type != TSMF_MAJOR_TYPE_VIDEO)
return -3;
assert(decoder);
assert(hdl);
if(hdl->subwin)
{
XDestroyWindow(hdl->disp, hdl->subwin);
XSync(hdl->disp, FALSE);
}
hdl->subwin = 0;
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,68 @@
#ifndef _TSMF_PLATFORM_H_
#define _TSMF_PLATFORM_H_
#include <gst/gst.h>
#include <tsmf_decoder.h>
typedef struct _TSMFGstreamerDecoder
{
ITSMFDecoder iface;
int media_type; /* TSMF_MAJOR_TYPE_AUDIO or TSMF_MAJOR_TYPE_VIDEO */
gint64 duration;
GstState state;
GstCaps *gst_caps;
GstElement *pipe;
GstElement *src;
GstElement *queue;
GstElement *decbin;
GstElement *outbin;
GstElement *outconv;
GstElement *outresample;
GstElement *outsink;
GstElement *volume;
GstPad *ghost_pad;
BOOL ready;
BOOL paused;
UINT64 last_sample_end_time;
double gstVolume;
BOOL gstMuted;
int pipeline_start_time_valid; /* We've set the start time and have not reset the pipeline */
int shutdown; /* The decoder stream is shutting down */
void *platform;
BOOL (*ack_cb)(void *,BOOL);
void (*sync_cb)(void *);
void *stream;
} TSMFGstreamerDecoder;
const char *get_type(TSMFGstreamerDecoder *mdecoder);
const char *tsmf_platform_get_video_sink(void);
const char *tsmf_platform_get_audio_sink(void);
int tsmf_platform_create(TSMFGstreamerDecoder *decoder);
int tsmf_platform_set_format(TSMFGstreamerDecoder *decoder);
int tsmf_platform_register_handler(TSMFGstreamerDecoder *decoder);
int tsmf_platform_free(TSMFGstreamerDecoder *decoder);
int tsmf_window_create(TSMFGstreamerDecoder *decoder);
int tsmf_window_resize(TSMFGstreamerDecoder *decoder, int x, int y,
int width, int height, int nr_rect, RDP_RECT *visible);
int tsmf_window_destroy(TSMFGstreamerDecoder *decoder);
int tsmf_window_pause(TSMFGstreamerDecoder *decoder);
int tsmf_window_resume(TSMFGstreamerDecoder *decoder);
BOOL tsmf_gstreamer_add_pad(TSMFGstreamerDecoder *mdecoder);
void tsmf_gstreamer_remove_pad(TSMFGstreamerDecoder *mdecoder);
#endif