FreeRDP
Loading...
Searching...
No Matches
tsmf_ifman.c
1
22
23#include <freerdp/config.h>
24
25#include <math.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29
30#include <winpr/crt.h>
31
32#include <winpr/stream.h>
33
34#include "tsmf_types.h"
35#include "tsmf_constants.h"
36#include "tsmf_media.h"
37#include "tsmf_codec.h"
38
39#include "tsmf_ifman.h"
40#include "tsmf_main.h"
41
47UINT tsmf_ifman_rim_exchange_capability_request(TSMF_IFMAN* ifman)
48{
49 UINT32 CapabilityValue = 0;
50
51 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 4))
52 return ERROR_INVALID_DATA;
53
54 Stream_Read_UINT32(ifman->input, CapabilityValue);
55 DEBUG_TSMF("server CapabilityValue %" PRIu32 "", CapabilityValue);
56
57 if (!Stream_EnsureRemainingCapacity(ifman->output, 8))
58 return ERROR_INVALID_DATA;
59
60 Stream_Write_UINT32(ifman->output, 1); /* CapabilityValue */
61 Stream_Write_UINT32(ifman->output, 0); /* Result */
62 return CHANNEL_RC_OK;
63}
64
70UINT tsmf_ifman_exchange_capability_request(TSMF_IFMAN* ifman)
71{
72 UINT32 CapabilityType = 0;
73 UINT32 cbCapabilityLength = 0;
74 UINT32 numHostCapabilities = 0;
75
76 WINPR_ASSERT(ifman);
77 if (!Stream_EnsureRemainingCapacity(ifman->output, ifman->input_size + 4))
78 return ERROR_OUTOFMEMORY;
79
80 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, ifman->input_size))
81 return ERROR_INVALID_DATA;
82
83 const size_t xpos = Stream_GetPosition(ifman->output);
84 Stream_Copy(ifman->input, ifman->output, ifman->input_size);
85 if (!Stream_SetPosition(ifman->output, xpos))
86 return ERROR_INVALID_DATA;
87
88 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->output, 4))
89 return ERROR_INVALID_DATA;
90
91 Stream_Read_UINT32(ifman->output, numHostCapabilities);
92
93 for (UINT32 i = 0; i < numHostCapabilities; i++)
94 {
95 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->output, 8))
96 return ERROR_INVALID_DATA;
97
98 Stream_Read_UINT32(ifman->output, CapabilityType);
99 Stream_Read_UINT32(ifman->output, cbCapabilityLength);
100
101 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->output, cbCapabilityLength))
102 return ERROR_INVALID_DATA;
103
104 const size_t pos = Stream_GetPosition(ifman->output);
105
106 switch (CapabilityType)
107 {
108 case 1: /* Protocol version request */
109 {
110 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->output, 4))
111 return ERROR_INVALID_DATA;
112
113 const UINT32 v = Stream_Get_UINT32(ifman->output);
114 WINPR_UNUSED(v);
115 DEBUG_TSMF("server protocol version %" PRIu32 "", v);
116 }
117 break;
118
119 case 2: /* Supported platform */
120 {
121 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->output, 4))
122 return ERROR_INVALID_DATA;
123
124 const UINT32 v = Stream_Get_UINT32(ifman->output);
125 WINPR_UNUSED(v);
126 DEBUG_TSMF("server supported platform %" PRIu32 "", v);
127 /* Claim that we support both MF and DShow platforms. */
128 Stream_Write_UINT32(ifman->output, MMREDIR_CAPABILITY_PLATFORM_MF |
129 MMREDIR_CAPABILITY_PLATFORM_DSHOW);
130 }
131 break;
132
133 default:
134 WLog_ERR(TAG, "skipping unknown capability type %" PRIu32 "", CapabilityType);
135 break;
136 }
137
138 if (!Stream_SetPosition(ifman->output, pos + cbCapabilityLength))
139 return ERROR_INVALID_DATA;
140 }
141
142 Stream_Write_UINT32(ifman->output, 0); /* Result */
143 ifman->output_interface_id = TSMF_INTERFACE_DEFAULT | STREAM_ID_STUB;
144 return CHANNEL_RC_OK;
145}
146
152UINT tsmf_ifman_check_format_support_request(TSMF_IFMAN* ifman)
153{
154 UINT32 numMediaType = 0;
155 UINT32 PlatformCookie = 0;
156 UINT32 FormatSupported = 1;
157
158 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 12))
159 return ERROR_INVALID_DATA;
160
161 Stream_Read_UINT32(ifman->input, PlatformCookie);
162 Stream_Seek_UINT32(ifman->input); /* NoRolloverFlags (4 bytes) */
163 Stream_Read_UINT32(ifman->input, numMediaType);
164 DEBUG_TSMF("PlatformCookie %" PRIu32 " numMediaType %" PRIu32 "", PlatformCookie, numMediaType);
165
166 if (!tsmf_codec_check_media_type(ifman->decoder_name, ifman->input))
167 FormatSupported = 0;
168
169 if (FormatSupported)
170 DEBUG_TSMF("format ok.");
171
172 if (!Stream_EnsureRemainingCapacity(ifman->output, 12))
173 return -1;
174
175 Stream_Write_UINT32(ifman->output, FormatSupported);
176 Stream_Write_UINT32(ifman->output, PlatformCookie);
177 Stream_Write_UINT32(ifman->output, 0); /* Result */
178 ifman->output_interface_id = TSMF_INTERFACE_DEFAULT | STREAM_ID_STUB;
179 return CHANNEL_RC_OK;
180}
181
187UINT tsmf_ifman_on_new_presentation(TSMF_IFMAN* ifman)
188{
189 UINT status = CHANNEL_RC_OK;
190 TSMF_PRESENTATION* presentation = nullptr;
191 DEBUG_TSMF("");
192
193 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, GUID_SIZE))
194 return ERROR_INVALID_DATA;
195
196 presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
197
198 if (presentation)
199 {
200 DEBUG_TSMF("Presentation already exists");
201 ifman->output_pending = FALSE;
202 return CHANNEL_RC_OK;
203 }
204
205 presentation = tsmf_presentation_new(Stream_Pointer(ifman->input), ifman->channel_callback);
206
207 if (!presentation)
208 status = ERROR_OUTOFMEMORY;
209 else
210 tsmf_presentation_set_audio_device(presentation, ifman->audio_name, ifman->audio_device);
211
212 ifman->output_pending = TRUE;
213 return status;
214}
215
221UINT tsmf_ifman_add_stream(TSMF_IFMAN* ifman, rdpContext* rdpcontext)
222{
223 UINT32 StreamId = 0;
224 UINT status = CHANNEL_RC_OK;
225
226 DEBUG_TSMF("");
227
228 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, GUID_SIZE + 8))
229 return ERROR_INVALID_DATA;
230
231 TSMF_PRESENTATION* presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
232 Stream_Seek(ifman->input, GUID_SIZE);
233
234 if (!presentation)
235 {
236 WLog_ERR(TAG, "unknown presentation id");
237 status = ERROR_NOT_FOUND;
238 }
239 else
240 {
241 const IWTSVirtualChannelCallback* pcb = tsmf_presentation_get_callback(presentation);
242 const TSMF_CHANNEL_CALLBACK* cb = (const TSMF_CHANNEL_CALLBACK*)ifman->channel_callback;
243
244 if (!pcb || (ifman->channel_callback != pcb))
245 {
246 WLog_ERR(TAG, "Presentation not set up for this callback.");
247 return ERROR_INVALID_DATA;
248 }
249 Stream_Read_UINT32(ifman->input, StreamId);
250 Stream_Seek_UINT32(ifman->input); /* numMediaType */
251 if (cb->stream_id != StreamId)
252 {
253 WLog_ERR(TAG,
254 "StreamId=0x%08" PRIx32
255 " does not match callback configuration for StreamId=0x%08" PRIx32,
256 StreamId, cb->stream_id);
257 return ERROR_INVALID_DATA;
258 }
259
260 TSMF_STREAM* stream = tsmf_stream_new(presentation, StreamId, rdpcontext);
261
262 if (!stream)
263 {
264 WLog_ERR(TAG, "failed to create stream");
265 return ERROR_OUTOFMEMORY;
266 }
267
268 if (!tsmf_stream_set_format(stream, ifman->decoder_name, ifman->input))
269 {
270 WLog_ERR(TAG, "failed to set stream format");
271 return ERROR_OUTOFMEMORY;
272 }
273
274 tsmf_stream_start_threads(stream);
275 }
276
277 ifman->output_pending = TRUE;
278 return status;
279}
280
286UINT tsmf_ifman_set_topology_request(TSMF_IFMAN* ifman)
287{
288 DEBUG_TSMF("");
289
290 if (!Stream_EnsureRemainingCapacity(ifman->output, 8))
291 return ERROR_OUTOFMEMORY;
292
293 Stream_Write_UINT32(ifman->output, 1); /* TopologyReady */
294 Stream_Write_UINT32(ifman->output, 0); /* Result */
295 ifman->output_interface_id = TSMF_INTERFACE_DEFAULT | STREAM_ID_STUB;
296 return CHANNEL_RC_OK;
297}
298
304UINT tsmf_ifman_remove_stream(TSMF_IFMAN* ifman)
305{
306 int status = CHANNEL_RC_OK;
307 UINT32 StreamId = 0;
308 TSMF_STREAM* stream = nullptr;
309 TSMF_PRESENTATION* presentation = nullptr;
310 DEBUG_TSMF("");
311
312 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 20))
313 return ERROR_INVALID_DATA;
314
315 presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
316 Stream_Seek(ifman->input, GUID_SIZE);
317
318 if (!presentation)
319 {
320 status = ERROR_NOT_FOUND;
321 }
322 else
323 {
324 Stream_Read_UINT32(ifman->input, StreamId);
325 stream = tsmf_stream_find_by_id(presentation, StreamId);
326
327 if (stream)
328 tsmf_stream_free(stream);
329 else
330 status = ERROR_NOT_FOUND;
331 }
332
333 ifman->output_pending = TRUE;
334 return status;
335}
336
337static float tsmf_stream_read_float(wStream* s)
338{
339 float fValue = NAN;
340 UINT32 iValue = 0;
341 Stream_Read_UINT32(s, iValue);
342 CopyMemory(&fValue, &iValue, 4);
343 return fValue;
344}
345
351UINT tsmf_ifman_set_source_video_rect(TSMF_IFMAN* ifman)
352{
353 UINT status = CHANNEL_RC_OK;
354 TSMF_PRESENTATION* presentation = nullptr;
355 DEBUG_TSMF("");
356
357 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 32))
358 return ERROR_INVALID_DATA;
359
360 presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
361 Stream_Seek(ifman->input, GUID_SIZE);
362
363 if (!presentation)
364 {
365 status = ERROR_NOT_FOUND;
366 }
367 else
368 {
369#ifdef WITH_DEBUG_TSMF
370 const float Left = tsmf_stream_read_float(ifman->input); /* Left (4 bytes) */
371 const float Top = tsmf_stream_read_float(ifman->input); /* Top (4 bytes) */
372 const float Right = tsmf_stream_read_float(ifman->input); /* Right (4 bytes) */
373 const float Bottom = tsmf_stream_read_float(ifman->input); /* Bottom (4 bytes) */
374 DEBUG_TSMF("SetSourceVideoRect: Left: %f Top: %f Right: %f Bottom: %f", Left, Top, Right,
375 Bottom);
376#endif
377 }
378
379 ifman->output_pending = TRUE;
380 return status;
381}
382
388UINT tsmf_ifman_shutdown_presentation(TSMF_IFMAN* ifman)
389{
390 TSMF_PRESENTATION* presentation = nullptr;
391 DEBUG_TSMF("");
392
393 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, GUID_SIZE))
394 return ERROR_INVALID_DATA;
395
396 presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
397
398 if (presentation)
399 tsmf_presentation_free(presentation);
400 else
401 {
402 WLog_ERR(TAG, "unknown presentation id");
403 return ERROR_NOT_FOUND;
404 }
405
406 if (!Stream_EnsureRemainingCapacity(ifman->output, 4))
407 return ERROR_OUTOFMEMORY;
408
409 Stream_Write_UINT32(ifman->output, 0); /* Result */
410 ifman->output_interface_id = TSMF_INTERFACE_DEFAULT | STREAM_ID_STUB;
411 return CHANNEL_RC_OK;
412}
413
419UINT tsmf_ifman_on_stream_volume(TSMF_IFMAN* ifman)
420{
421 TSMF_PRESENTATION* presentation = nullptr;
422 UINT32 newVolume = 0;
423 UINT32 muted = 0;
424 DEBUG_TSMF("on stream volume");
425
426 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, GUID_SIZE + 8))
427 return ERROR_INVALID_DATA;
428
429 presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
430
431 if (!presentation)
432 {
433 WLog_ERR(TAG, "unknown presentation id");
434 return ERROR_NOT_FOUND;
435 }
436
437 Stream_Seek(ifman->input, 16);
438 Stream_Read_UINT32(ifman->input, newVolume);
439 DEBUG_TSMF("on stream volume: new volume=[%" PRIu32 "]", newVolume);
440 Stream_Read_UINT32(ifman->input, muted);
441 DEBUG_TSMF("on stream volume: muted=[%" PRIu32 "]", muted);
442
443 if (!tsmf_presentation_volume_changed(presentation, newVolume, muted))
444 return ERROR_INVALID_OPERATION;
445
446 ifman->output_pending = TRUE;
447 return 0;
448}
449
455UINT tsmf_ifman_on_channel_volume(TSMF_IFMAN* ifman)
456{
457 TSMF_PRESENTATION* presentation = nullptr;
458 DEBUG_TSMF("on channel volume");
459
460 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, GUID_SIZE + 8))
461 return ERROR_INVALID_DATA;
462
463 presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
464
465 if (presentation)
466 {
467 UINT32 channelVolume = 0;
468 UINT32 changedChannel = 0;
469 Stream_Seek(ifman->input, 16);
470 Stream_Read_UINT32(ifman->input, channelVolume);
471 DEBUG_TSMF("on channel volume: channel volume=[%" PRIu32 "]", channelVolume);
472 Stream_Read_UINT32(ifman->input, changedChannel);
473 DEBUG_TSMF("on stream volume: changed channel=[%" PRIu32 "]", changedChannel);
474 }
475
476 ifman->output_pending = TRUE;
477 return CHANNEL_RC_OK;
478}
479
485UINT tsmf_ifman_set_video_window(TSMF_IFMAN* ifman)
486{
487 DEBUG_TSMF("");
488 ifman->output_pending = TRUE;
489 return CHANNEL_RC_OK;
490}
491
497UINT tsmf_ifman_update_geometry_info(TSMF_IFMAN* ifman)
498{
499 TSMF_PRESENTATION* presentation = nullptr;
500 UINT32 numGeometryInfo = 0;
501 UINT32 Left = 0;
502 UINT32 Top = 0;
503 UINT32 Width = 0;
504 UINT32 Height = 0;
505 UINT32 cbVisibleRect = 0;
506 RECTANGLE_32* rects = nullptr;
507 UINT error = CHANNEL_RC_OK;
508 size_t pos = 0;
509
510 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, GUID_SIZE + 32))
511 return ERROR_INVALID_DATA;
512
513 presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
514
515 if (!presentation)
516 return ERROR_NOT_FOUND;
517
518 Stream_Seek(ifman->input, 16);
519 Stream_Read_UINT32(ifman->input, numGeometryInfo);
520 pos = Stream_GetPosition(ifman->input);
521 Stream_Seek(ifman->input, 12); /* VideoWindowId (8 bytes), VideoWindowState (4 bytes) */
522 Stream_Read_UINT32(ifman->input, Width);
523 Stream_Read_UINT32(ifman->input, Height);
524 Stream_Read_UINT32(ifman->input, Left);
525 Stream_Read_UINT32(ifman->input, Top);
526 if (!Stream_SetPosition(ifman->input, pos + numGeometryInfo))
527 return ERROR_INVALID_DATA;
528 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 4))
529 return ERROR_INVALID_DATA;
530 Stream_Read_UINT32(ifman->input, cbVisibleRect);
531 const UINT32 num_rects = cbVisibleRect / 16;
532 DEBUG_TSMF("numGeometryInfo %" PRIu32 " Width %" PRIu32 " Height %" PRIu32 " Left %" PRIu32
533 " Top %" PRIu32 " cbVisibleRect %" PRIu32 " num_rects %d",
534 numGeometryInfo, Width, Height, Left, Top, cbVisibleRect, num_rects);
535
536 if (num_rects > 0)
537 {
538 if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, ifman->input, num_rects, 16ull))
539 return ERROR_INVALID_DATA;
540
541 rects = (RECTANGLE_32*)calloc(num_rects, sizeof(RECTANGLE_32));
542 if (!rects)
543 return ERROR_OUTOFMEMORY;
544
545 for (size_t i = 0; i < num_rects; i++)
546 {
547 Stream_Read_UINT32(ifman->input, rects[i].top); /* Top */
548 Stream_Read_UINT32(ifman->input, rects[i].left); /* Left */
549 Stream_Read_UINT32(ifman->input, rects[i].height); /* Bottom */
550 Stream_Read_UINT32(ifman->input, rects[i].width); /* Right */
551 rects[i].width -= rects[i].left;
552 rects[i].height -= rects[i].top;
553 DEBUG_TSMF("rect %d: %" PRId16 " %" PRId16 " %" PRId16 " %" PRId16 "", i, rects[i].x,
554 rects[i].y, rects[i].width, rects[i].height);
555 }
556 }
557
558 const BOOL rc = tsmf_presentation_set_geometry_info(presentation, Left, Top, Width, Height,
559 num_rects, rects);
560 free(rects);
561 if (!rc)
562 return ERROR_INVALID_OPERATION;
563
564 ifman->output_pending = TRUE;
565 return error;
566}
567
573UINT tsmf_ifman_set_allocator(TSMF_IFMAN* ifman)
574{
575 DEBUG_TSMF("");
576 ifman->output_pending = TRUE;
577 return CHANNEL_RC_OK;
578}
579
585UINT tsmf_ifman_notify_preroll(TSMF_IFMAN* ifman)
586{
587 DEBUG_TSMF("");
588 tsmf_ifman_on_playback_paused(ifman);
589 ifman->output_pending = TRUE;
590 return CHANNEL_RC_OK;
591}
592
598UINT tsmf_ifman_on_sample(TSMF_IFMAN* ifman)
599{
600 TSMF_PRESENTATION* presentation = nullptr;
601 TSMF_STREAM* stream = nullptr;
602 UINT32 StreamId = 0;
603 UINT64 SampleStartTime = 0;
604 UINT64 SampleEndTime = 0;
605 UINT64 ThrottleDuration = 0;
606 UINT32 SampleExtensions = 0;
607 UINT32 cbData = 0;
608 UINT error = 0;
609
610 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 60))
611 return ERROR_INVALID_DATA;
612
613 Stream_Seek(ifman->input, 16);
614 Stream_Read_UINT32(ifman->input, StreamId);
615 Stream_Seek_UINT32(ifman->input); /* numSample */
616 Stream_Read_UINT64(ifman->input, SampleStartTime);
617 Stream_Read_UINT64(ifman->input, SampleEndTime);
618 Stream_Read_UINT64(ifman->input, ThrottleDuration);
619 Stream_Seek_UINT32(ifman->input); /* SampleFlags */
620 Stream_Read_UINT32(ifman->input, SampleExtensions);
621 Stream_Read_UINT32(ifman->input, cbData);
622
623 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, cbData))
624 return ERROR_INVALID_DATA;
625
626 DEBUG_TSMF("MessageId %" PRIu32 " StreamId %" PRIu32 " SampleStartTime %" PRIu64
627 " SampleEndTime %" PRIu64 " "
628 "ThrottleDuration %" PRIu64 " SampleExtensions %" PRIu32 " cbData %" PRIu32 "",
629 ifman->message_id, StreamId, SampleStartTime, SampleEndTime, ThrottleDuration,
630 SampleExtensions, cbData);
631 presentation = tsmf_presentation_find_by_id(ifman->presentation_id);
632
633 if (!presentation || (tsmf_presentation_get_callback(presentation) != ifman->channel_callback))
634 {
635 WLog_ERR(TAG, "unknown presentation id");
636 return ERROR_NOT_FOUND;
637 }
638
639 stream = tsmf_stream_find_by_id(presentation, StreamId);
640
641 if (!stream)
642 {
643 WLog_ERR(TAG, "unknown stream id");
644 return ERROR_NOT_FOUND;
645 }
646
647 if (!tsmf_stream_push_sample(stream, ifman->message_id, SampleStartTime, SampleEndTime,
648 ThrottleDuration, SampleExtensions, cbData,
649 Stream_Pointer(ifman->input)))
650 {
651 WLog_ERR(TAG, "unable to push sample");
652 return ERROR_OUTOFMEMORY;
653 }
654
655 if ((error = tsmf_presentation_sync(presentation)))
656 {
657 WLog_ERR(TAG, "tsmf_presentation_sync failed with error %" PRIu32 "", error);
658 return error;
659 }
660
661 ifman->output_pending = TRUE;
662 return CHANNEL_RC_OK;
663}
664
670UINT tsmf_ifman_on_flush(TSMF_IFMAN* ifman)
671{
672 UINT32 StreamId = 0;
673 TSMF_PRESENTATION* presentation = nullptr;
674 TSMF_STREAM* stream = nullptr;
675
676 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 20))
677 return ERROR_INVALID_DATA;
678
679 Stream_Seek(ifman->input, 16);
680 Stream_Read_UINT32(ifman->input, StreamId);
681 DEBUG_TSMF("StreamId %" PRIu32 "", StreamId);
682 presentation = tsmf_presentation_find_by_id(ifman->presentation_id);
683
684 if (!presentation)
685 {
686 WLog_ERR(TAG, "unknown presentation id");
687 return ERROR_NOT_FOUND;
688 }
689
690 /* Flush message is for a stream, not the entire presentation
691 * therefore we only flush the stream as intended per the MS-RDPEV spec
692 */
693 stream = tsmf_stream_find_by_id(presentation, StreamId);
694
695 if (stream)
696 {
697 if (!tsmf_stream_flush(stream))
698 return ERROR_INVALID_OPERATION;
699 }
700 else
701 WLog_ERR(TAG, "unknown stream id");
702
703 ifman->output_pending = TRUE;
704 return CHANNEL_RC_OK;
705}
706
712UINT tsmf_ifman_on_end_of_stream(TSMF_IFMAN* ifman)
713{
714 UINT32 StreamId = 0;
715
716 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 20))
717 return ERROR_INVALID_DATA;
718
719 TSMF_PRESENTATION* presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
720 if (!presentation)
721 return ERROR_INVALID_DATA;
722
723 Stream_Seek(ifman->input, 16);
724 Stream_Read_UINT32(ifman->input, StreamId);
725
726 if (presentation && (ifman->channel_callback == tsmf_presentation_get_callback(presentation)))
727 {
728 TSMF_STREAM* stream = tsmf_stream_find_by_id(presentation, StreamId);
729
730 if (stream)
731 tsmf_stream_end(stream, ifman->message_id);
732 }
733
734 DEBUG_TSMF("StreamId %" PRIu32 "", StreamId);
735 ifman->output_pending = TRUE;
736 ifman->output_interface_id = TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY;
737 return CHANNEL_RC_OK;
738}
739
745UINT tsmf_ifman_on_playback_started(TSMF_IFMAN* ifman)
746{
747 TSMF_PRESENTATION* presentation = nullptr;
748 DEBUG_TSMF("");
749
750 if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 16))
751 return ERROR_INVALID_DATA;
752
753 presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
754
755 if (presentation)
756 tsmf_presentation_start(presentation);
757 else
758 WLog_ERR(TAG, "unknown presentation id");
759
760 if (!Stream_EnsureRemainingCapacity(ifman->output, 16))
761 return ERROR_OUTOFMEMORY;
762
763 Stream_Write_UINT32(ifman->output, CLIENT_EVENT_NOTIFICATION); /* FunctionId */
764 Stream_Write_UINT32(ifman->output, 0); /* StreamId */
765 Stream_Write_UINT32(ifman->output, TSMM_CLIENT_EVENT_START_COMPLETED); /* EventId */
766 Stream_Write_UINT32(ifman->output, 0); /* cbData */
767 ifman->output_interface_id = TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY;
768 return CHANNEL_RC_OK;
769}
770
776UINT tsmf_ifman_on_playback_paused(TSMF_IFMAN* ifman)
777{
778 TSMF_PRESENTATION* presentation = nullptr;
779 DEBUG_TSMF("");
780 ifman->output_pending = TRUE;
781 /* Added pause control so gstreamer pipeline can be paused accordingly */
782 presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
783
784 if (presentation)
785 {
786 if (!tsmf_presentation_paused(presentation))
787 return ERROR_INVALID_OPERATION;
788 }
789 else
790 WLog_ERR(TAG, "unknown presentation id");
791
792 return CHANNEL_RC_OK;
793}
794
800UINT tsmf_ifman_on_playback_restarted(TSMF_IFMAN* ifman)
801{
802 TSMF_PRESENTATION* presentation = nullptr;
803 DEBUG_TSMF("");
804 ifman->output_pending = TRUE;
805 /* Added restart control so gstreamer pipeline can be resumed accordingly */
806 presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
807
808 if (presentation)
809 {
810 if (!tsmf_presentation_restarted(presentation))
811 return ERROR_INVALID_OPERATION;
812 }
813 else
814 WLog_ERR(TAG, "unknown presentation id");
815
816 return CHANNEL_RC_OK;
817}
818
824UINT tsmf_ifman_on_playback_stopped(TSMF_IFMAN* ifman)
825{
826 TSMF_PRESENTATION* presentation = nullptr;
827 DEBUG_TSMF("");
828 presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input));
829
830 if (presentation)
831 {
832 if (!tsmf_presentation_stop(presentation))
833 return ERROR_INVALID_OPERATION;
834 }
835 else
836 WLog_ERR(TAG, "unknown presentation id");
837
838 if (!Stream_EnsureRemainingCapacity(ifman->output, 16))
839 return ERROR_OUTOFMEMORY;
840
841 Stream_Write_UINT32(ifman->output, CLIENT_EVENT_NOTIFICATION); /* FunctionId */
842 Stream_Write_UINT32(ifman->output, 0); /* StreamId */
843 Stream_Write_UINT32(ifman->output, TSMM_CLIENT_EVENT_STOP_COMPLETED); /* EventId */
844 Stream_Write_UINT32(ifman->output, 0); /* cbData */
845 ifman->output_interface_id = TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY;
846 return CHANNEL_RC_OK;
847}
848
854UINT tsmf_ifman_on_playback_rate_changed(TSMF_IFMAN* ifman)
855{
856 DEBUG_TSMF("");
857
858 if (!Stream_EnsureRemainingCapacity(ifman->output, 16))
859 return ERROR_OUTOFMEMORY;
860
861 Stream_Write_UINT32(ifman->output, CLIENT_EVENT_NOTIFICATION); /* FunctionId */
862 Stream_Write_UINT32(ifman->output, 0); /* StreamId */
863 Stream_Write_UINT32(ifman->output, TSMM_CLIENT_EVENT_MONITORCHANGED); /* EventId */
864 Stream_Write_UINT32(ifman->output, 0); /* cbData */
865 ifman->output_interface_id = TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY;
866 return CHANNEL_RC_OK;
867}