From 87eae4a49bd0e31eba3299f2a3ad0bebae195381 Mon Sep 17 00:00:00 2001 From: Maxim Date: Wed, 15 Apr 2015 11:29:27 +0300 Subject: [PATCH 1/7] fixed crash at mediaplayer closing, fixed tsmf event parameters-no video freerdp crashed at media player closing windows 2008R2 no tsmf video output at test video sample about bunny. all this fixed. --- channels/tsmf/client/tsmf_media.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index d460c0105..5d81bd0ba 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -375,6 +375,18 @@ static void tsmf_sample_playback_video(TSMF_SAMPLE* sample) event.frameWidth = sample->stream->width; event.frameHeight = sample->stream->height; + event.x = presentation->x; + event.y = presentation->y; + event.width = presentation->width; + event.height = presentation->height; + + if (presentation->nr_rects > 0) + { + event.numVisibleRects = presentation->nr_rects; + event.visibleRects = (RECTANGLE_16*) calloc(1, event.numVisibleRects * sizeof(RECTANGLE_16)); + memcpy(event.visibleRects, presentation->rects, presentation->nr_rects * sizeof(RDP_RECT)); + } + #if 0 /* Dump a .ppm image for every 30 frames. Assuming the frame is in YUV format, we extract the Y values to create a grayscale image. */ @@ -406,6 +418,8 @@ static void tsmf_sample_playback_video(TSMF_SAMPLE* sample) tsmf->FrameEvent(tsmf, &event); free(event.frameData); + + if(event.visibleRects!=NULL) free(event.visibleRects); } } @@ -840,11 +854,13 @@ void tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, presentation->height = height; tmp_rects = realloc(presentation->rects, sizeof(RDP_RECT) * num_rects); - if (!tmp_rects) - return; + presentation->nr_rects = num_rects; presentation->rects = tmp_rects; + if (!tmp_rects) + return; + CopyMemory(presentation->rects, rects, sizeof(RDP_RECT) * num_rects); ArrayList_Lock(presentation->stream_list); From f3a1fe544e5efef3279106bd6d4c35d813a4d437 Mon Sep 17 00:00:00 2001 From: Maxim Date: Wed, 15 Apr 2015 14:08:51 +0300 Subject: [PATCH 2/7] fixed-check for calloc return memory --- channels/tsmf/client/tsmf_media.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index 5d81bd0ba..82d86c65a 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -384,7 +384,13 @@ static void tsmf_sample_playback_video(TSMF_SAMPLE* sample) { event.numVisibleRects = presentation->nr_rects; event.visibleRects = (RECTANGLE_16*) calloc(1, event.numVisibleRects * sizeof(RECTANGLE_16)); - memcpy(event.visibleRects, presentation->rects, presentation->nr_rects * sizeof(RDP_RECT)); + if (event.visibleRects) + memcpy(event.visibleRects, presentation->rects, presentation->nr_rects * sizeof(RDP_RECT)); + else + { + presentation->nr_rects=0; + WLog_ERR(TAG, "can't allocate memory for copy rectangles"); + } } #if 0 From 26c054d7a4429c0727c1471a523757dcb5d193e4 Mon Sep 17 00:00:00 2001 From: Maxim Date: Wed, 15 Apr 2015 17:42:54 +0300 Subject: [PATCH 3/7] fixed - detect realloc failed and return if calloc failed --- channels/tsmf/client/tsmf_media.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index 82d86c65a..30a1aad58 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -384,13 +384,13 @@ static void tsmf_sample_playback_video(TSMF_SAMPLE* sample) { event.numVisibleRects = presentation->nr_rects; event.visibleRects = (RECTANGLE_16*) calloc(1, event.numVisibleRects * sizeof(RECTANGLE_16)); - if (event.visibleRects) - memcpy(event.visibleRects, presentation->rects, presentation->nr_rects * sizeof(RDP_RECT)); - else + if (!event.visibleRects) { - presentation->nr_rects=0; WLog_ERR(TAG, "can't allocate memory for copy rectangles"); + return; } + memcpy(event.visibleRects, presentation->rects, presentation->nr_rects * sizeof(RDP_RECT)); + presentation->nr_rects=0; } #if 0 @@ -861,12 +861,12 @@ void tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, tmp_rects = realloc(presentation->rects, sizeof(RDP_RECT) * num_rects); + if (!tmp_rects&&num_rects) + return; + presentation->nr_rects = num_rects; presentation->rects = tmp_rects; - if (!tmp_rects) - return; - CopyMemory(presentation->rects, rects, sizeof(RDP_RECT) * num_rects); ArrayList_Lock(presentation->stream_list); From be7ff45a52a25beb3291f46ff2180751e0764e4d Mon Sep 17 00:00:00 2001 From: Maxim Date: Fri, 17 Apr 2015 12:14:30 +0300 Subject: [PATCH 4/7] fixed crash at mediaplayer closing, fixed tsmf event parameters-no video, fixed tsmf no audio. --- channels/tsmf/client/tsmf_media.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index 30a1aad58..7f1864f4c 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -108,6 +108,8 @@ struct _TSMF_STREAM HANDLE stopEvent; HANDLE ready; + BOOL started; + wQueue *sample_list; wQueue *sample_ack_list; }; @@ -675,6 +677,13 @@ static void tsmf_stream_start(TSMF_STREAM* stream) if (!stream || !stream->presentation || !stream->decoder) return; + if (!stream->started) + { + ResumeThread(stream->play_thread); + ResumeThread(stream->ack_thread); + stream->started = TRUE; + } + if (stream->decoder->Control) { stream->decoder->Control(stream->decoder, Control_Resume, NULL); @@ -690,6 +699,12 @@ static void tsmf_stream_stop(TSMF_STREAM* stream) { stream->decoder->Control(stream->decoder, Control_Stop, NULL); } + + if (stream->started) + { + //SetEvent(stream->stopEvent); + stream->started = FALSE; + } } static void tsmf_stream_pause(TSMF_STREAM* stream) @@ -977,8 +992,10 @@ TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id) stream->sample_list->object.fnObjectFree = tsmf_sample_free; stream->sample_ack_list = Queue_New(TRUE, -1, -1); stream->sample_ack_list->object.fnObjectFree = tsmf_sample_free; - stream->play_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) tsmf_stream_playback_func, stream, 0, NULL); - stream->ack_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)tsmf_stream_ack_func, stream, 0, NULL); + + stream->started = FALSE; + stream->play_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) tsmf_stream_playback_func, stream, CREATE_SUSPENDED, NULL); + stream->ack_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)tsmf_stream_ack_func, stream, CREATE_SUSPENDED, NULL); ArrayList_Add(presentation->stream_list, stream); From ed89fc7861afb7eeaa7ec16cdeae5dbc4aafda94 Mon Sep 17 00:00:00 2001 From: Maxim Date: Thu, 14 May 2015 16:57:37 +0300 Subject: [PATCH 5/7] coding style update --- channels/tsmf/client/tsmf_media.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index 7f1864f4c..24ca30b81 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -108,8 +108,6 @@ struct _TSMF_STREAM HANDLE stopEvent; HANDLE ready; - BOOL started; - wQueue *sample_list; wQueue *sample_ack_list; }; @@ -392,7 +390,7 @@ static void tsmf_sample_playback_video(TSMF_SAMPLE* sample) return; } memcpy(event.visibleRects, presentation->rects, presentation->nr_rects * sizeof(RDP_RECT)); - presentation->nr_rects=0; + presentation->nr_rects = 0; } #if 0 @@ -427,7 +425,8 @@ static void tsmf_sample_playback_video(TSMF_SAMPLE* sample) free(event.frameData); - if(event.visibleRects!=NULL) free(event.visibleRects); + if(event.visibleRects != NULL) + free(event.visibleRects); } } @@ -677,13 +676,6 @@ static void tsmf_stream_start(TSMF_STREAM* stream) if (!stream || !stream->presentation || !stream->decoder) return; - if (!stream->started) - { - ResumeThread(stream->play_thread); - ResumeThread(stream->ack_thread); - stream->started = TRUE; - } - if (stream->decoder->Control) { stream->decoder->Control(stream->decoder, Control_Resume, NULL); @@ -699,12 +691,6 @@ static void tsmf_stream_stop(TSMF_STREAM* stream) { stream->decoder->Control(stream->decoder, Control_Stop, NULL); } - - if (stream->started) - { - //SetEvent(stream->stopEvent); - stream->started = FALSE; - } } static void tsmf_stream_pause(TSMF_STREAM* stream) @@ -876,6 +862,9 @@ void tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, tmp_rects = realloc(presentation->rects, sizeof(RDP_RECT) * num_rects); + if(!num_rects) + presentation->rects=NULL; + if (!tmp_rects&&num_rects) return; @@ -993,7 +982,6 @@ TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id) stream->sample_ack_list = Queue_New(TRUE, -1, -1); stream->sample_ack_list->object.fnObjectFree = tsmf_sample_free; - stream->started = FALSE; stream->play_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) tsmf_stream_playback_func, stream, CREATE_SUSPENDED, NULL); stream->ack_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)tsmf_stream_ack_func, stream, CREATE_SUSPENDED, NULL); @@ -1002,6 +990,12 @@ TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id) return stream; } +void tsmf_stream_start_threads (TSMF_STREAM* stream) +{ + ResumeThread(stream->play_thread); + ResumeThread(stream->ack_thread); +} + TSMF_STREAM *tsmf_stream_find_by_id(TSMF_PRESENTATION* presentation, UINT32 stream_id) { UINT32 index; From c9d6611170e5105fc576d6a5d480f9a54d7b1fd2 Mon Sep 17 00:00:00 2001 From: Maxim Date: Thu, 14 May 2015 17:06:34 +0300 Subject: [PATCH 6/7] added start for suspended threads was issue - if all threads start before tsmf_stream_set_format - unknown format of threads, not remember exactly gstreamer or ffmpeg problem was. --- channels/tsmf/client/tsmf_ifman.c | 1 + 1 file changed, 1 insertion(+) diff --git a/channels/tsmf/client/tsmf_ifman.c b/channels/tsmf/client/tsmf_ifman.c index a5c65fe2f..6518bcabf 100644 --- a/channels/tsmf/client/tsmf_ifman.c +++ b/channels/tsmf/client/tsmf_ifman.c @@ -179,6 +179,7 @@ int tsmf_ifman_add_stream(TSMF_IFMAN* ifman) stream = tsmf_stream_new(presentation, StreamId); if (stream) tsmf_stream_set_format(stream, ifman->decoder_name, ifman->input); + tsmf_stream_start_threads(stream); } ifman->output_pending = TRUE; return status; From 99420423cf96270a90ec9bccd81bc2ec90f9c882 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 18 Jan 2017 12:39:40 +0100 Subject: [PATCH 7/7] Fixed warnings due to API changes. --- channels/tsmf/client/tsmf_media.c | 7 ++--- channels/tsmf/client/tsmf_media.h | 49 +++++++++++++++++-------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index 9c89becf2..9b93cace2 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -468,7 +468,7 @@ static BOOL tsmf_sample_playback_video(TSMF_SAMPLE* sample) if (!event.visibleRects) { WLog_ERR(TAG, "can't allocate memory for copy rectangles"); - return; + return FALSE; } memcpy(event.visibleRects, presentation->rects, presentation->nr_rects * sizeof(RDP_RECT)); @@ -1132,11 +1132,8 @@ BOOL tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, presentation->height = height; tmp_rects = realloc(presentation->rects, sizeof(RDP_RECT) * num_rects); - if (!num_rects) - presentation->rects = NULL; - if (!tmp_rects && num_rects) - return; + return FALSE; presentation->nr_rects = num_rects; presentation->rects = tmp_rects; diff --git a/channels/tsmf/client/tsmf_media.h b/channels/tsmf/client/tsmf_media.h index 1760fe05a..3a08b1c6a 100644 --- a/channels/tsmf/client/tsmf_media.h +++ b/channels/tsmf/client/tsmf_media.h @@ -36,33 +36,38 @@ typedef struct _TSMF_STREAM TSMF_STREAM; typedef struct _TSMF_SAMPLE TSMF_SAMPLE; -TSMF_PRESENTATION *tsmf_presentation_new(const BYTE *guid, IWTSVirtualChannelCallback *pChannelCallback); -TSMF_PRESENTATION *tsmf_presentation_find_by_id(const BYTE *guid); -BOOL tsmf_presentation_start(TSMF_PRESENTATION *presentation); -BOOL tsmf_presentation_stop(TSMF_PRESENTATION *presentation); -UINT tsmf_presentation_sync(TSMF_PRESENTATION *presentation); -BOOL tsmf_presentation_paused(TSMF_PRESENTATION *presentation); -BOOL tsmf_presentation_restarted(TSMF_PRESENTATION *presentation); -BOOL tsmf_presentation_volume_changed(TSMF_PRESENTATION *presentation, UINT32 newVolume, UINT32 muted); -BOOL tsmf_presentation_set_geometry_info(TSMF_PRESENTATION *presentation, - UINT32 x, UINT32 y, UINT32 width, UINT32 height, - int num_rects, RDP_RECT *rects); -void tsmf_presentation_set_audio_device(TSMF_PRESENTATION *presentation, - const char *name, const char *device); -void tsmf_presentation_free(TSMF_PRESENTATION *presentation); +TSMF_PRESENTATION* tsmf_presentation_new(const BYTE* guid, + IWTSVirtualChannelCallback* pChannelCallback); +TSMF_PRESENTATION* tsmf_presentation_find_by_id(const BYTE* guid); +BOOL tsmf_presentation_start(TSMF_PRESENTATION* presentation); +BOOL tsmf_presentation_stop(TSMF_PRESENTATION* presentation); +UINT tsmf_presentation_sync(TSMF_PRESENTATION* presentation); +BOOL tsmf_presentation_paused(TSMF_PRESENTATION* presentation); +BOOL tsmf_presentation_restarted(TSMF_PRESENTATION* presentation); +BOOL tsmf_presentation_volume_changed(TSMF_PRESENTATION* presentation, UINT32 newVolume, + UINT32 muted); +BOOL tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, + UINT32 x, UINT32 y, UINT32 width, UINT32 height, + int num_rects, RDP_RECT* rects); +void tsmf_presentation_set_audio_device(TSMF_PRESENTATION* presentation, + const char* name, const char* device); +void tsmf_presentation_free(TSMF_PRESENTATION* presentation); -TSMF_STREAM *tsmf_stream_new(TSMF_PRESENTATION *presentation, UINT32 stream_id, rdpContext* rdpcontext); -TSMF_STREAM *tsmf_stream_find_by_id(TSMF_PRESENTATION *presentation, UINT32 stream_id); -BOOL tsmf_stream_set_format(TSMF_STREAM *stream, const char *name, wStream *s); -void tsmf_stream_end(TSMF_STREAM *stream, UINT32 message_id, IWTSVirtualChannelCallback* pChannelCallback); -void tsmf_stream_free(TSMF_STREAM *stream); +TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id, + rdpContext* rdpcontext); +TSMF_STREAM* tsmf_stream_find_by_id(TSMF_PRESENTATION* presentation, UINT32 stream_id); +BOOL tsmf_stream_set_format(TSMF_STREAM* stream, const char* name, wStream* s); +void tsmf_stream_end(TSMF_STREAM* stream, UINT32 message_id, + IWTSVirtualChannelCallback* pChannelCallback); +void tsmf_stream_free(TSMF_STREAM* stream); BOOL tsmf_stream_flush(TSMF_STREAM* stream); -BOOL tsmf_stream_push_sample(TSMF_STREAM *stream, IWTSVirtualChannelCallback *pChannelCallback, - UINT32 sample_id, UINT64 start_time, UINT64 end_time, UINT64 duration, UINT32 extensions, - UINT32 data_size, BYTE *data); +BOOL tsmf_stream_push_sample(TSMF_STREAM* stream, IWTSVirtualChannelCallback* pChannelCallback, + UINT32 sample_id, UINT64 start_time, UINT64 end_time, UINT64 duration, UINT32 extensions, + UINT32 data_size, BYTE* data); BOOL tsmf_media_init(void); +void tsmf_stream_start_threads(TSMF_STREAM* stream); #endif