2011-09-19 18:54:09 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-09-19 18:54:09 +04:00
|
|
|
* Video Redirection Virtual Channel - Media Container
|
|
|
|
*
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
2012-06-13 23:45:58 +04:00
|
|
|
* Copyright 2012 Hewlett-Packard Development Company, L.P.
|
2011-09-19 18:54:09 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-06-13 23:45:58 +04:00
|
|
|
#include <signal.h>
|
2012-07-29 06:24:14 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2012-06-13 23:45:58 +04:00
|
|
|
#include <unistd.h>
|
2012-07-29 06:24:14 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
2011-09-19 18:54:09 +04:00
|
|
|
#include <sys/time.h>
|
2012-07-29 06:24:14 +04:00
|
|
|
#endif
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2013-03-21 05:42:52 +04:00
|
|
|
#include <winpr/synch.h>
|
|
|
|
#include <winpr/thread.h>
|
2014-04-26 20:31:24 +04:00
|
|
|
#include <winpr/stream.h>
|
2013-03-21 05:42:52 +04:00
|
|
|
#include <winpr/collections.h>
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2012-10-09 04:33:58 +04:00
|
|
|
#include <freerdp/client/tsmf.h>
|
2011-09-19 18:54:09 +04:00
|
|
|
|
|
|
|
#include "tsmf_constants.h"
|
|
|
|
#include "tsmf_types.h"
|
|
|
|
#include "tsmf_decoder.h"
|
|
|
|
#include "tsmf_audio.h"
|
|
|
|
#include "tsmf_main.h"
|
|
|
|
#include "tsmf_codec.h"
|
|
|
|
#include "tsmf_media.h"
|
|
|
|
|
|
|
|
#define AUDIO_TOLERANCE 10000000LL
|
|
|
|
|
|
|
|
struct _TSMF_PRESENTATION
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE presentation_id[GUID_SIZE];
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
const char *audio_name;
|
|
|
|
const char *audio_device;
|
2011-09-19 18:54:09 +04:00
|
|
|
int eos;
|
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
IWTSVirtualChannelCallback *channel_callback;
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT64 audio_start_time;
|
|
|
|
UINT64 audio_end_time;
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2013-06-19 20:33:46 +04:00
|
|
|
UINT32 volume;
|
|
|
|
UINT32 muted;
|
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
wArrayList *stream_list;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
|
|
|
|
int nr_rects;
|
|
|
|
void *rects;
|
2011-09-19 18:54:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _TSMF_STREAM
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 stream_id;
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_PRESENTATION* presentation;
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
ITSMFDecoder *decoder;
|
2011-09-19 18:54:09 +04:00
|
|
|
|
|
|
|
int major_type;
|
|
|
|
int eos;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 width;
|
|
|
|
UINT32 height;
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
ITSMFAudioDevice *audio;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 sample_rate;
|
|
|
|
UINT32 channels;
|
|
|
|
UINT32 bits_per_sample;
|
2011-09-19 18:54:09 +04:00
|
|
|
|
|
|
|
/* The end_time of last played sample */
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT64 last_end_time;
|
2011-09-19 18:54:09 +04:00
|
|
|
/* Next sample should not start before this system time. */
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT64 next_start_time;
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
HANDLE play_thread;
|
|
|
|
HANDLE ack_thread;
|
2013-03-21 05:42:52 +04:00
|
|
|
HANDLE stopEvent;
|
2014-05-23 15:50:52 +04:00
|
|
|
HANDLE ready;
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
wQueue *sample_list;
|
|
|
|
wQueue *sample_ack_list;
|
2011-09-19 18:54:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _TSMF_SAMPLE
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 sample_id;
|
|
|
|
UINT64 start_time;
|
|
|
|
UINT64 end_time;
|
|
|
|
UINT64 duration;
|
|
|
|
UINT32 extensions;
|
|
|
|
UINT32 data_size;
|
2014-05-23 15:50:52 +04:00
|
|
|
BYTE *data;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 decoded_size;
|
|
|
|
UINT32 pixfmt;
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream;
|
2014-05-23 15:50:52 +04:00
|
|
|
IWTSVirtualChannelCallback *channel_callback;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT64 ack_time;
|
2011-09-19 18:54:09 +04:00
|
|
|
};
|
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
static wArrayList *presentation_list = NULL;
|
2012-06-13 23:45:58 +04:00
|
|
|
static int TERMINATING = 0;
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static void _tsmf_presentation_free(TSMF_PRESENTATION* presentation);
|
|
|
|
static void _tsmf_stream_free(TSMF_STREAM* stream);
|
2014-05-23 15:50:52 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
static UINT64 get_current_time(void)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
|
|
|
struct timeval tp;
|
|
|
|
gettimeofday(&tp, 0);
|
2012-10-09 11:26:39 +04:00
|
|
|
return ((UINT64)tp.tv_sec) * 10000000LL + ((UINT64)tp.tv_usec) * 10LL;
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-04-26 20:31:24 +04:00
|
|
|
UINT32 index;
|
|
|
|
UINT32 count;
|
2014-05-23 15:50:52 +04:00
|
|
|
TSMF_STREAM *s;
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_SAMPLE* sample;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL pending = FALSE;
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_PRESENTATION* presentation = stream->presentation;
|
|
|
|
|
|
|
|
if (!stream)
|
|
|
|
return NULL;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (Queue_Count(stream->sample_list) < 1)
|
2011-09-19 18:54:09 +04:00
|
|
|
return NULL;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (sync)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (stream->decoder)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (stream->decoder->GetDecodedData)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2012-06-13 23:45:58 +04:00
|
|
|
/* Check if some other stream has earlier sample that needs to be played first */
|
2014-05-25 00:58:54 +04:00
|
|
|
if (stream->last_end_time > AUDIO_TOLERANCE)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Lock(presentation->stream_list);
|
|
|
|
count = ArrayList_Count(presentation->stream_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
s = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (s != stream && !s->eos && s->last_end_time &&
|
2014-05-23 15:50:52 +04:00
|
|
|
s->last_end_time < stream->last_end_time - AUDIO_TOLERANCE)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
pending = TRUE;
|
|
|
|
break;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Unlock(presentation->stream_list);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
else
|
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (stream->last_end_time > presentation->audio_end_time)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
pending = TRUE;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
}
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (pending)
|
2011-09-19 18:54:09 +04:00
|
|
|
return NULL;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
sample = (TSMF_SAMPLE *) Queue_Dequeue(stream->sample_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (sample && (sample->end_time > stream->last_end_time))
|
2011-09-19 18:54:09 +04:00
|
|
|
stream->last_end_time = sample->end_time;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
return sample;
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
static void tsmf_sample_free(void *arg)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_SAMPLE* sample = arg;
|
|
|
|
|
|
|
|
if (!sample)
|
|
|
|
return;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (sample->data)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(sample->data);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(sample);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-11-08 02:33:45 +03:00
|
|
|
static void tsmf_sample_ack(TSMF_SAMPLE* sample)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
if (!sample)
|
|
|
|
return;
|
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
tsmf_playback_ack(sample->channel_callback, sample->sample_id, sample->duration, sample->data_size);
|
|
|
|
}
|
|
|
|
|
2014-11-08 02:33:45 +03:00
|
|
|
static void tsmf_sample_queue_ack(TSMF_SAMPLE* sample)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
if (!sample)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sample->stream)
|
|
|
|
return;
|
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
Queue_Enqueue(sample->stream->sample_ack_list, sample);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static BOOL tsmf_stream_process_ack(void* arg, BOOL force)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream = arg;
|
|
|
|
TSMF_SAMPLE* sample;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT64 ack_time;
|
2014-05-23 15:50:52 +04:00
|
|
|
BOOL rc = FALSE;
|
2014-11-10 22:02:54 +03:00
|
|
|
|
|
|
|
if (!stream)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
Queue_Lock(stream->sample_ack_list);
|
2014-11-10 22:02:54 +03:00
|
|
|
sample = (TSMF_SAMPLE*) Queue_Peek(stream->sample_ack_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (!sample)
|
2014-05-23 15:50:52 +04:00
|
|
|
goto finally;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (!force)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
|
|
|
ack_time = get_current_time();
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (sample->ack_time > ack_time)
|
2014-05-23 15:50:52 +04:00
|
|
|
goto finally;
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
sample = Queue_Dequeue(stream->sample_ack_list);
|
|
|
|
tsmf_sample_ack(sample);
|
|
|
|
tsmf_sample_free(sample);
|
2014-11-10 22:02:54 +03:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
finally:
|
|
|
|
Queue_Unlock(stream->sample_ack_list);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_PRESENTATION* tsmf_presentation_new(const BYTE* guid, IWTSVirtualChannelCallback* pChannelCallback)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_PRESENTATION* presentation;
|
|
|
|
|
|
|
|
if (!guid || !pChannelCallback)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
presentation = (TSMF_PRESENTATION*) calloc(1, sizeof(TSMF_PRESENTATION));
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (!presentation)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "calloc failed");
|
2014-05-25 00:58:54 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
CopyMemory(presentation->presentation_id, guid, GUID_SIZE);
|
2011-09-19 18:54:09 +04:00
|
|
|
presentation->channel_callback = pChannelCallback;
|
2013-06-19 20:33:46 +04:00
|
|
|
presentation->volume = 5000; /* 50% */
|
2014-04-26 20:31:24 +04:00
|
|
|
presentation->stream_list = ArrayList_New(TRUE);
|
2014-05-23 15:50:52 +04:00
|
|
|
ArrayList_Object(presentation->stream_list)->fnObjectFree = (OBJECT_FREE_FN) _tsmf_stream_free;
|
2014-11-10 22:02:54 +03:00
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Add(presentation_list, presentation);
|
2014-11-10 22:02:54 +03:00
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
return presentation;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static char* guid_to_string(const BYTE* guid, char* str, size_t len)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
int i;
|
2014-11-10 22:02:54 +03:00
|
|
|
|
|
|
|
if (!guid || !str)
|
|
|
|
return NULL;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
for (i=0; i<GUID_SIZE && len > 2*i; i++)
|
2014-05-23 15:50:52 +04:00
|
|
|
snprintf(str + (2*i), len - 2*i, "%02X", guid[i]);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_PRESENTATION* tsmf_presentation_find_by_id(const BYTE *guid)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
2014-04-26 20:31:24 +04:00
|
|
|
UINT32 index;
|
|
|
|
UINT32 count;
|
|
|
|
BOOL found = FALSE;
|
2014-11-10 22:02:54 +03:00
|
|
|
char guid_str[GUID_SIZE * 2 + 1];
|
|
|
|
TSMF_PRESENTATION* presentation;
|
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Lock(presentation_list);
|
|
|
|
count = ArrayList_Count(presentation_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
presentation = (TSMF_PRESENTATION*) ArrayList_GetItem(presentation_list, index);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (memcmp(presentation->presentation_id, guid, GUID_SIZE) == 0)
|
2014-04-26 20:31:24 +04:00
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Unlock(presentation_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (!found)
|
2014-09-16 11:45:48 +04:00
|
|
|
WLog_WARN(TAG, "presentation id %s not found", guid_to_string(guid, guid_str, sizeof(guid_str)));
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
return (found) ? presentation : NULL;
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-11-08 02:33:45 +03:00
|
|
|
static void tsmf_sample_playback_video(TSMF_SAMPLE* sample)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT64 t;
|
2014-11-11 00:33:34 +03:00
|
|
|
TSMF_VIDEO_FRAME_EVENT event;
|
2014-11-08 02:33:45 +03:00
|
|
|
TSMF_STREAM* stream = sample->stream;
|
|
|
|
TSMF_PRESENTATION* presentation = stream->presentation;
|
|
|
|
TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*) sample->channel_callback;
|
|
|
|
TsmfClientContext* tsmf = (TsmfClientContext*) callback->plugin->pInterface;
|
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
DEBUG_TSMF("MessageId %d EndTime %d data_size %d consumed.",
|
2014-11-11 00:23:04 +03:00
|
|
|
sample->sample_id, (int) sample->end_time, sample->data_size);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (sample->data)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
|
|
|
t = get_current_time();
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->next_start_time > t &&
|
2014-05-23 15:50:52 +04:00
|
|
|
(sample->end_time >= presentation->audio_start_time ||
|
|
|
|
sample->end_time < stream->last_end_time))
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2012-12-14 09:58:48 +04:00
|
|
|
USleep((stream->next_start_time - t) / 10);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
stream->next_start_time = t + sample->duration - 50000;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-11-11 00:33:34 +03:00
|
|
|
ZeroMemory(&event, sizeof(TSMF_VIDEO_FRAME_EVENT));
|
2014-11-08 02:33:45 +03:00
|
|
|
|
2014-11-11 00:33:34 +03:00
|
|
|
event.frameData = sample->data;
|
|
|
|
event.frameSize = sample->decoded_size;
|
|
|
|
event.framePixFmt = sample->pixfmt;
|
|
|
|
event.frameWidth = sample->stream->width;
|
|
|
|
event.frameHeight = sample->stream->height;
|
2014-11-08 02:33:45 +03:00
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
#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. */
|
|
|
|
static int frame_id = 0;
|
|
|
|
char buf[100];
|
2014-05-23 15:50:52 +04:00
|
|
|
FILE *fp;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if ((frame_id % 30) == 0)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "/tmp/FreeRDP_Frame_%d.ppm", frame_id);
|
|
|
|
fp = fopen(buf, "wb");
|
|
|
|
fwrite("P5\n", 1, 3, fp);
|
|
|
|
snprintf(buf, sizeof(buf), "%d %d\n", sample->stream->width, sample->stream->height);
|
|
|
|
fwrite(buf, 1, strlen(buf), fp);
|
|
|
|
fwrite("255\n", 1, 4, fp);
|
|
|
|
fwrite(sample->data, 1, sample->stream->width * sample->stream->height, fp);
|
|
|
|
fflush(fp);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
frame_id++;
|
|
|
|
#endif
|
2015-03-26 13:38:09 +03:00
|
|
|
|
|
|
|
/* The frame data ownership is passed to the event object, and is freed after the event is processed. */
|
|
|
|
sample->data = NULL;
|
|
|
|
sample->decoded_size = 0;
|
|
|
|
|
|
|
|
if (tsmf->FrameEvent)
|
|
|
|
tsmf->FrameEvent(tsmf, &event);
|
|
|
|
|
|
|
|
free(event.frameData);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static void tsmf_sample_playback_audio(TSMF_SAMPLE* sample)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT64 latency = 0;
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream = sample->stream;
|
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
DEBUG_TSMF("MessageId %d EndTime %d consumed.",
|
|
|
|
sample->sample_id, (int)sample->end_time);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (sample->stream->audio && sample->data)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-08 02:33:45 +03:00
|
|
|
sample->stream->audio->Play(sample->stream->audio, sample->data, sample->decoded_size);
|
2011-09-19 18:54:09 +04:00
|
|
|
sample->data = NULL;
|
|
|
|
sample->decoded_size = 0;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->audio && stream->audio->GetLatency)
|
2011-09-19 18:54:09 +04:00
|
|
|
latency = stream->audio->GetLatency(stream->audio);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
latency = 0;
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
sample->ack_time = latency + get_current_time();
|
|
|
|
stream->last_end_time = sample->end_time + latency;
|
|
|
|
stream->presentation->audio_start_time = sample->start_time + latency;
|
|
|
|
stream->presentation->audio_end_time = sample->end_time + latency;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static void tsmf_sample_playback(TSMF_SAMPLE* sample)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL ret = FALSE;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 width;
|
|
|
|
UINT32 height;
|
|
|
|
UINT32 pixfmt = 0;
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream = sample->stream;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (stream->decoder->DecodeEx)
|
2014-11-10 22:02:54 +03:00
|
|
|
{
|
2012-06-13 23:45:58 +04:00
|
|
|
ret = stream->decoder->DecodeEx(stream->decoder, sample->data, sample->data_size, sample->extensions,
|
2014-11-10 22:02:54 +03:00
|
|
|
sample->start_time, sample->end_time, sample->duration);
|
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
else
|
2014-11-10 22:02:54 +03:00
|
|
|
{
|
2012-06-13 23:45:58 +04:00
|
|
|
ret = stream->decoder->Decode(stream->decoder, sample->data, sample->data_size, sample->extensions);
|
2014-11-10 22:02:54 +03:00
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (!ret)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
tsmf_sample_queue_ack(sample);
|
2011-09-19 18:54:09 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(sample->data);
|
2011-09-19 18:54:09 +04:00
|
|
|
sample->data = NULL;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->major_type == TSMF_MAJOR_TYPE_VIDEO)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (stream->decoder->GetDecodedFormat)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
|
|
|
pixfmt = stream->decoder->GetDecodedFormat(stream->decoder);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (pixfmt == ((UINT32) -1))
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
tsmf_sample_queue_ack(sample);
|
2011-09-19 18:54:09 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
sample->pixfmt = pixfmt;
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
ret = FALSE;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder->GetDecodedDimension)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2012-06-13 23:45:58 +04:00
|
|
|
ret = stream->decoder->GetDecodedDimension(stream->decoder, &width, &height);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (ret && (width != stream->width || height != stream->height))
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
DEBUG_TSMF("video dimension changed to %d x %d", width, height);
|
2012-06-13 23:45:58 +04:00
|
|
|
stream->width = width;
|
|
|
|
stream->height = height;
|
|
|
|
}
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder->GetDecodedData)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
|
|
|
sample->data = stream->decoder->GetDecodedData(stream->decoder, &sample->decoded_size);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
switch (sample->stream->major_type)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
|
|
|
case TSMF_MAJOR_TYPE_VIDEO:
|
|
|
|
tsmf_sample_playback_video(sample);
|
2014-05-23 15:50:52 +04:00
|
|
|
tsmf_sample_queue_ack(sample);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
case TSMF_MAJOR_TYPE_AUDIO:
|
|
|
|
tsmf_sample_playback_audio(sample);
|
|
|
|
tsmf_sample_queue_ack(sample);
|
|
|
|
break;
|
|
|
|
}
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
else
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream = sample->stream;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT64 ack_anticipation_time = get_current_time();
|
|
|
|
UINT64 currentRunningTime = sample->start_time;
|
2014-05-23 15:50:52 +04:00
|
|
|
BOOL buffer_filled = TRUE;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder->GetRunningTime)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
|
|
|
currentRunningTime = stream->decoder->GetRunningTime(stream->decoder);
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder->BufferFilled)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
buffer_filled = stream->decoder->BufferFilled(stream->decoder);
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (buffer_filled)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (currentRunningTime > sample->start_time)
|
|
|
|
{
|
|
|
|
ack_anticipation_time += sample->duration;
|
|
|
|
}
|
|
|
|
else if (currentRunningTime == 0)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
ack_anticipation_time += sample->duration;
|
|
|
|
}
|
|
|
|
else
|
2014-05-25 00:58:54 +04:00
|
|
|
{
|
|
|
|
ack_anticipation_time += (sample->start_time - currentRunningTime);
|
|
|
|
}
|
2014-05-23 15:50:52 +04:00
|
|
|
}
|
|
|
|
else
|
2014-11-10 22:02:54 +03:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
ack_anticipation_time += sample->duration / 2;
|
2014-11-10 22:02:54 +03:00
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
switch (sample->stream->major_type)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
|
|
|
case TSMF_MAJOR_TYPE_VIDEO:
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
break;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
case TSMF_MAJOR_TYPE_AUDIO:
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
break;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
sample->ack_time = ack_anticipation_time;
|
|
|
|
tsmf_sample_queue_ack(sample);
|
2014-05-23 15:50:52 +04:00
|
|
|
}
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static void* tsmf_stream_ack_func(void *arg)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
HANDLE hdl[2];
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream = (TSMF_STREAM*) arg;
|
2014-05-23 15:50:52 +04:00
|
|
|
DEBUG_TSMF("in %d", stream->stream_id);
|
2014-11-10 22:02:54 +03:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
hdl[0] = stream->stopEvent;
|
|
|
|
hdl[1] = Queue_Event(stream->sample_ack_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
while (1)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
|
|
|
DWORD ev = WaitForMultipleObjects(2, hdl, FALSE, INFINITE);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (ev == WAIT_OBJECT_0)
|
2014-05-23 15:50:52 +04:00
|
|
|
break;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (!stream->decoder)
|
2014-05-23 15:50:52 +04:00
|
|
|
continue;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder->SetAckFunc)
|
2014-05-23 15:50:52 +04:00
|
|
|
continue;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (tsmf_stream_process_ack(stream, FALSE))
|
2014-05-23 15:50:52 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
DEBUG_TSMF("out %d", stream->stream_id);
|
|
|
|
ExitThread(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static void* tsmf_stream_playback_func(void *arg)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
2014-05-24 17:55:55 +04:00
|
|
|
HANDLE hdl[2];
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_SAMPLE* sample;
|
|
|
|
TSMF_STREAM* stream = (TSMF_STREAM *) arg;
|
|
|
|
TSMF_PRESENTATION* presentation = stream->presentation;
|
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
DEBUG_TSMF("in %d", stream->stream_id);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO &&
|
2014-05-23 15:50:52 +04:00
|
|
|
stream->sample_rate && stream->channels && stream->bits_per_sample)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (stream->decoder)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (stream->decoder->GetDecodedData)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
|
|
|
stream->audio = tsmf_load_audio_device(
|
2014-11-10 22:02:54 +03:00
|
|
|
presentation->audio_name && presentation->audio_name[0] ? presentation->audio_name : NULL,
|
|
|
|
presentation->audio_device && presentation->audio_device[0] ? presentation->audio_device : NULL);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->audio)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
stream->audio->SetFormat(stream->audio, stream->sample_rate, stream->channels, stream->bits_per_sample);
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
}
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
}
|
2014-05-24 17:55:55 +04:00
|
|
|
|
|
|
|
hdl[0] = stream->stopEvent;
|
|
|
|
hdl[1] = Queue_Event(stream->sample_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
while (!(WaitForMultipleObjects(2, hdl, FALSE, INFINITE) == WAIT_OBJECT_0))
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
sample = tsmf_stream_pop_sample(stream, 0);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (sample)
|
2011-09-19 18:54:09 +04:00
|
|
|
tsmf_sample_playback(sample);
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->audio)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
|
|
|
stream->audio->Free(stream->audio);
|
|
|
|
stream->audio = NULL;
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
DEBUG_TSMF("out %d", stream->stream_id);
|
|
|
|
ExitThread(0);
|
2011-09-19 18:54:09 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static void tsmf_stream_start(TSMF_STREAM* stream)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (!stream || !stream->presentation || !stream->decoder)
|
2014-05-23 15:50:52 +04:00
|
|
|
return;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder->Control)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
stream->decoder->Control(stream->decoder, Control_Resume, NULL);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static void tsmf_stream_stop(TSMF_STREAM* stream)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (!stream || !stream->decoder)
|
2012-06-13 23:45:58 +04:00
|
|
|
return;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder->Control)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
stream->decoder->Control(stream->decoder, Control_Stop, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static void tsmf_stream_pause(TSMF_STREAM* stream)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (!stream || !stream->decoder)
|
2012-06-13 23:45:58 +04:00
|
|
|
return;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder->Control)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
|
|
|
stream->decoder->Control(stream->decoder, Control_Pause, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static void tsmf_stream_restart(TSMF_STREAM* stream)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (!stream || !stream->decoder)
|
2012-06-13 23:45:58 +04:00
|
|
|
return;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder->Control)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
stream->decoder->Control(stream->decoder, Control_Resume, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static void tsmf_stream_change_volume(TSMF_STREAM* stream, UINT32 newVolume, UINT32 muted)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-25 00:58:54 +04:00
|
|
|
if (!stream || !stream->decoder)
|
2012-06-13 23:45:58 +04:00
|
|
|
return;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder != NULL && stream->decoder->ChangeVolume)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
|
|
|
stream->decoder->ChangeVolume(stream->decoder, newVolume, muted);
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
else if (stream->audio != NULL && stream->audio->ChangeVolume)
|
|
|
|
{
|
|
|
|
stream->audio->ChangeVolume(stream->audio, newVolume, muted);
|
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_presentation_volume_changed(TSMF_PRESENTATION* presentation, UINT32 newVolume, UINT32 muted)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-04-26 20:31:24 +04:00
|
|
|
UINT32 index;
|
|
|
|
UINT32 count;
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream;
|
2013-06-19 20:33:46 +04:00
|
|
|
presentation->volume = newVolume;
|
|
|
|
presentation->muted = muted;
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Lock(presentation->stream_list);
|
|
|
|
count = ArrayList_Count(presentation->stream_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
|
2012-06-13 23:45:58 +04:00
|
|
|
tsmf_stream_change_volume(stream, newVolume, muted);
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Unlock(presentation->stream_list);
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_presentation_paused(TSMF_PRESENTATION* presentation)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-04-26 20:31:24 +04:00
|
|
|
UINT32 index;
|
|
|
|
UINT32 count;
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream;
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Lock(presentation->stream_list);
|
|
|
|
count = ArrayList_Count(presentation->stream_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
|
2012-06-13 23:45:58 +04:00
|
|
|
tsmf_stream_pause(stream);
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Unlock(presentation->stream_list);
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_presentation_restarted(TSMF_PRESENTATION* presentation)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-04-26 20:31:24 +04:00
|
|
|
UINT32 index;
|
|
|
|
UINT32 count;
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream;
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Lock(presentation->stream_list);
|
|
|
|
count = ArrayList_Count(presentation->stream_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
|
2012-06-13 23:45:58 +04:00
|
|
|
tsmf_stream_restart(stream);
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Unlock(presentation->stream_list);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_presentation_start(TSMF_PRESENTATION* presentation)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-04-26 20:31:24 +04:00
|
|
|
UINT32 index;
|
|
|
|
UINT32 count;
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream;
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Lock(presentation->stream_list);
|
|
|
|
count = ArrayList_Count(presentation->stream_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
|
2011-09-19 18:54:09 +04:00
|
|
|
tsmf_stream_start(stream);
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Unlock(presentation->stream_list);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_presentation_sync(TSMF_PRESENTATION* presentation)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-04-26 20:31:24 +04:00
|
|
|
UINT32 index;
|
|
|
|
UINT32 count;
|
|
|
|
ArrayList_Lock(presentation->stream_list);
|
|
|
|
count = ArrayList_Count(presentation->stream_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
|
2014-05-23 15:50:52 +04:00
|
|
|
WaitForSingleObject(stream->ready, 500);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Unlock(presentation->stream_list);
|
2014-05-23 15:50:52 +04:00
|
|
|
}
|
2014-04-26 20:31:24 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_presentation_stop(TSMF_PRESENTATION* presentation)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
|
|
|
UINT32 index;
|
|
|
|
UINT32 count;
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream;
|
2014-05-23 15:50:52 +04:00
|
|
|
tsmf_presentation_flush(presentation);
|
|
|
|
ArrayList_Lock(presentation->stream_list);
|
|
|
|
count = ArrayList_Count(presentation->stream_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
|
|
|
|
tsmf_stream_stop(stream);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
ArrayList_Unlock(presentation->stream_list);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation,
|
2014-05-23 15:50:52 +04:00
|
|
|
UINT32 x, UINT32 y, UINT32 width, UINT32 height, int num_rects, RDP_RECT *rects)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
UINT32 index;
|
|
|
|
UINT32 count;
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream;
|
2015-03-11 06:04:36 +03:00
|
|
|
void *tmp_rects;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
/* The server may send messages with invalid width / height.
|
|
|
|
* Ignore those messages. */
|
2014-05-25 00:58:54 +04:00
|
|
|
if (!width || !height)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((width == presentation->width) && (height == presentation->height) &&
|
|
|
|
(x == presentation->x) && (y == presentation->y) &&
|
|
|
|
(num_rects == presentation->nr_rects) &&
|
|
|
|
(0 == memcmp(rects, presentation->rects, num_rects * sizeof(RDP_RECT))))
|
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
return;
|
2014-05-25 00:58:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
presentation->x = x;
|
|
|
|
presentation->y = y;
|
|
|
|
presentation->width = width;
|
|
|
|
presentation->height = height;
|
2015-03-11 06:04:36 +03:00
|
|
|
|
|
|
|
tmp_rects = realloc(presentation->rects, sizeof(RDP_RECT) * num_rects);
|
|
|
|
if (!tmp_rects)
|
|
|
|
return;
|
2014-05-25 00:58:54 +04:00
|
|
|
presentation->nr_rects = num_rects;
|
2015-03-11 06:04:36 +03:00
|
|
|
presentation->rects = tmp_rects;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2015-03-11 06:04:36 +03:00
|
|
|
CopyMemory(presentation->rects, rects, sizeof(RDP_RECT) * num_rects);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
ArrayList_Lock(presentation->stream_list);
|
|
|
|
count = ArrayList_Count(presentation->stream_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
|
|
|
stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (!stream->decoder)
|
2014-05-23 15:50:52 +04:00
|
|
|
continue;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder->UpdateRenderingArea)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
|
|
|
stream->decoder->UpdateRenderingArea(stream->decoder, x, y, width, height, num_rects, rects);
|
|
|
|
}
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
ArrayList_Unlock(presentation->stream_list);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_presentation_set_audio_device(TSMF_PRESENTATION* presentation, const char *name, const char *device)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
|
|
|
presentation->audio_name = name;
|
|
|
|
presentation->audio_device = device;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static void tsmf_stream_flush(TSMF_STREAM* stream)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2013-03-22 00:45:25 +04:00
|
|
|
//TSMF_SAMPLE* sample;
|
2013-03-21 05:42:52 +04:00
|
|
|
/* TODO: free lists */
|
2014-05-25 00:58:54 +04:00
|
|
|
if (stream->audio)
|
2011-09-19 18:54:09 +04:00
|
|
|
stream->audio->Flush(stream->audio);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
stream->eos = 0;
|
|
|
|
stream->last_end_time = 0;
|
|
|
|
stream->next_start_time = 0;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
|
|
|
stream->presentation->audio_start_time = 0;
|
|
|
|
stream->presentation->audio_end_time = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_presentation_flush(TSMF_PRESENTATION* presentation)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-04-26 20:31:24 +04:00
|
|
|
UINT32 index;
|
|
|
|
UINT32 count;
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream;
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Lock(presentation->stream_list);
|
|
|
|
count = ArrayList_Count(presentation->stream_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
stream = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list, index);
|
2011-09-19 18:54:09 +04:00
|
|
|
tsmf_stream_flush(stream);
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Unlock(presentation->stream_list);
|
2011-09-19 18:54:09 +04:00
|
|
|
presentation->eos = 0;
|
|
|
|
presentation->audio_start_time = 0;
|
|
|
|
presentation->audio_end_time = 0;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void _tsmf_presentation_free(TSMF_PRESENTATION* presentation)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
|
|
|
tsmf_presentation_stop(presentation);
|
2014-05-23 15:50:52 +04:00
|
|
|
ArrayList_Clear(presentation->stream_list);
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Free(presentation->stream_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (presentation->rects)
|
|
|
|
free(presentation->rects);
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
ZeroMemory(presentation, sizeof(TSMF_PRESENTATION));
|
2012-10-09 07:21:26 +04:00
|
|
|
free(presentation);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_presentation_free(TSMF_PRESENTATION* presentation)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
ArrayList_Remove(presentation_list, presentation);
|
|
|
|
}
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream;
|
2011-09-19 18:54:09 +04:00
|
|
|
stream = tsmf_stream_find_by_id(presentation, stream_id);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "duplicated stream id %d!", stream_id);
|
2011-09-19 18:54:09 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
stream = (TSMF_STREAM*) calloc(1, sizeof(TSMF_STREAM));
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (!stream)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Calloc failed");
|
2014-05-25 00:58:54 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
stream->stream_id = stream_id;
|
|
|
|
stream->presentation = presentation;
|
2013-03-21 05:42:52 +04:00
|
|
|
stream->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
2014-05-23 15:50:52 +04:00
|
|
|
stream->ready = CreateEvent(NULL, TRUE, TRUE, NULL);
|
2013-03-21 05:42:52 +04:00
|
|
|
stream->sample_list = Queue_New(TRUE, -1, -1);
|
2014-05-23 15:50:52 +04:00
|
|
|
stream->sample_list->object.fnObjectFree = tsmf_sample_free;
|
2013-03-21 05:42:52 +04:00
|
|
|
stream->sample_ack_list = Queue_New(TRUE, -1, -1);
|
2014-05-23 15:50:52 +04:00
|
|
|
stream->sample_ack_list->object.fnObjectFree = tsmf_sample_free;
|
2014-11-10 22:02:54 +03:00
|
|
|
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);
|
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Add(presentation->stream_list, stream);
|
2014-11-10 22:02:54 +03:00
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM *tsmf_stream_find_by_id(TSMF_PRESENTATION* presentation, UINT32 stream_id)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-04-26 20:31:24 +04:00
|
|
|
UINT32 index;
|
|
|
|
UINT32 count;
|
|
|
|
BOOL found = FALSE;
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream;
|
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Lock(presentation->stream_list);
|
|
|
|
count = ArrayList_Count(presentation->stream_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
stream = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list, index);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->stream_id == stream_id)
|
2014-04-26 20:31:24 +04:00
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Unlock(presentation->stream_list);
|
|
|
|
return (found) ? stream : NULL;
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
static void tsmf_stream_resync(void *arg)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_STREAM* stream = arg;
|
2014-05-23 15:50:52 +04:00
|
|
|
ResetEvent(stream->ready);
|
|
|
|
}
|
2011-09-19 18:54:09 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_stream_set_format(TSMF_STREAM* stream, const char *name, wStream *s)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
|
|
|
TS_AM_MEDIA_TYPE mediatype;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "duplicated call");
|
2011-09-19 18:54:09 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
tsmf_codec_parse_media_type(&mediatype, s);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (mediatype.MajorType == TSMF_MAJOR_TYPE_VIDEO)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-05-23 15:50:52 +04:00
|
|
|
DEBUG_TSMF("video width %d height %d bit_rate %d frame_rate %f codec_data %d",
|
|
|
|
mediatype.Width, mediatype.Height, mediatype.BitRate,
|
|
|
|
(double) mediatype.SamplesPerSecond.Numerator / (double) mediatype.SamplesPerSecond.Denominator,
|
|
|
|
mediatype.ExtraDataSize);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
else if (mediatype.MajorType == TSMF_MAJOR_TYPE_AUDIO)
|
|
|
|
{
|
|
|
|
DEBUG_TSMF("audio channel %d sample_rate %d bits_per_sample %d codec_data %d",
|
|
|
|
mediatype.Channels, mediatype.SamplesPerSecond.Numerator, mediatype.BitsPerSample,
|
|
|
|
mediatype.ExtraDataSize);
|
|
|
|
stream->sample_rate = mediatype.SamplesPerSecond.Numerator;
|
|
|
|
stream->channels = mediatype.Channels;
|
|
|
|
stream->bits_per_sample = mediatype.BitsPerSample;
|
|
|
|
|
|
|
|
if (stream->bits_per_sample == 0)
|
|
|
|
stream->bits_per_sample = 16;
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
stream->major_type = mediatype.MajorType;
|
|
|
|
stream->width = mediatype.Width;
|
|
|
|
stream->height = mediatype.Height;
|
|
|
|
stream->decoder = tsmf_load_decoder(name, &mediatype);
|
2013-06-19 20:33:46 +04:00
|
|
|
tsmf_stream_change_volume(stream, stream->presentation->volume, stream->presentation->muted);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (!stream->decoder)
|
2014-05-23 15:50:52 +04:00
|
|
|
return;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder->SetAckFunc)
|
2014-05-23 15:50:52 +04:00
|
|
|
stream->decoder->SetAckFunc(stream->decoder, tsmf_stream_process_ack, stream);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder->SetSyncFunc)
|
2014-05-23 15:50:52 +04:00
|
|
|
stream->decoder->SetSyncFunc(stream->decoder, tsmf_stream_resync, stream);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_stream_end(TSMF_STREAM* stream)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
if (!stream)
|
|
|
|
return;
|
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
stream->eos = 1;
|
|
|
|
stream->presentation->eos = 1;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void _tsmf_stream_free(TSMF_STREAM* stream)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
if (!stream)
|
|
|
|
return;
|
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
tsmf_stream_stop(stream);
|
|
|
|
tsmf_stream_flush(stream);
|
2014-05-23 15:50:52 +04:00
|
|
|
SetEvent(stream->stopEvent);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->play_thread)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
|
|
|
WaitForSingleObject(stream->play_thread, INFINITE);
|
|
|
|
CloseHandle(stream->play_thread);
|
|
|
|
stream->play_thread = NULL;
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->ack_thread)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
|
|
|
WaitForSingleObject(stream->ack_thread, INFINITE);
|
|
|
|
CloseHandle(stream->ack_thread);
|
|
|
|
stream->ack_thread = NULL;
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2013-03-21 05:42:52 +04:00
|
|
|
Queue_Free(stream->sample_list);
|
|
|
|
Queue_Free(stream->sample_ack_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (stream->decoder && stream->decoder->Free)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2011-09-19 18:54:09 +04:00
|
|
|
stream->decoder->Free(stream->decoder);
|
2014-05-23 15:50:52 +04:00
|
|
|
stream->decoder = NULL;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-05-23 15:50:52 +04:00
|
|
|
CloseHandle(stream->stopEvent);
|
|
|
|
CloseHandle(stream->ready);
|
2014-11-10 22:02:54 +03:00
|
|
|
ZeroMemory(stream, sizeof(TSMF_STREAM));
|
2012-10-09 07:21:26 +04:00
|
|
|
free(stream);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void tsmf_stream_free(TSMF_STREAM* stream)
|
2011-09-19 18:54:09 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_PRESENTATION* presentation = stream->presentation;
|
2014-05-23 15:50:52 +04:00
|
|
|
ArrayList_Remove(presentation->stream_list, stream);
|
|
|
|
}
|
2012-07-29 06:24:14 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
void 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)
|
2014-05-23 15:50:52 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMF_SAMPLE* sample;
|
2014-05-23 15:50:52 +04:00
|
|
|
SetEvent(stream->ready);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (TERMINATING)
|
2012-06-13 23:45:58 +04:00
|
|
|
return;
|
2014-05-25 00:58:54 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
sample = (TSMF_SAMPLE*) calloc(1, sizeof(TSMF_SAMPLE));
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (!sample)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
2014-05-25 00:58:54 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
sample->sample_id = sample_id;
|
|
|
|
sample->start_time = start_time;
|
|
|
|
sample->end_time = end_time;
|
|
|
|
sample->duration = duration;
|
|
|
|
sample->extensions = extensions;
|
|
|
|
sample->stream = stream;
|
|
|
|
sample->channel_callback = pChannelCallback;
|
|
|
|
sample->data_size = data_size;
|
2014-05-25 00:58:54 +04:00
|
|
|
sample->data = calloc(1, data_size + TSMF_BUFFER_PADDING_SIZE);
|
|
|
|
|
|
|
|
if (!sample->data)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
2014-05-25 00:58:54 +04:00
|
|
|
free(sample);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-21 05:42:52 +04:00
|
|
|
CopyMemory(sample->data, data, data_size);
|
|
|
|
Queue_Enqueue(stream->sample_list, sample);
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|
|
|
|
|
2012-07-29 06:24:14 +04:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
static void tsmf_signal_handler(int s)
|
|
|
|
{
|
2012-09-19 01:33:52 +04:00
|
|
|
TERMINATING = 1;
|
2014-04-26 20:31:24 +04:00
|
|
|
ArrayList_Free(presentation_list);
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (s == SIGINT)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
|
|
|
signal(s, SIG_DFL);
|
|
|
|
kill(getpid(), s);
|
|
|
|
}
|
2014-05-25 00:58:54 +04:00
|
|
|
else if (s == SIGUSR1)
|
|
|
|
{
|
|
|
|
signal(s, SIG_DFL);
|
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
|
2012-07-29 06:24:14 +04:00
|
|
|
#endif
|
|
|
|
|
2011-09-19 18:54:09 +04:00
|
|
|
void tsmf_media_init(void)
|
|
|
|
{
|
2012-07-29 06:24:14 +04:00
|
|
|
#ifndef _WIN32
|
2012-06-13 23:45:58 +04:00
|
|
|
struct sigaction sigtrap;
|
|
|
|
sigtrap.sa_handler = tsmf_signal_handler;
|
|
|
|
sigemptyset(&sigtrap.sa_mask);
|
|
|
|
sigtrap.sa_flags = 0;
|
|
|
|
sigaction(SIGINT, &sigtrap, 0);
|
|
|
|
sigaction(SIGUSR1, &sigtrap, 0);
|
2012-07-29 06:24:14 +04:00
|
|
|
#endif
|
2014-05-25 00:58:54 +04:00
|
|
|
|
|
|
|
if (!presentation_list)
|
2014-04-26 20:31:24 +04:00
|
|
|
{
|
|
|
|
presentation_list = ArrayList_New(TRUE);
|
2014-05-23 15:50:52 +04:00
|
|
|
ArrayList_Object(presentation_list)->fnObjectFree = (OBJECT_FREE_FN) _tsmf_presentation_free;
|
2014-04-26 20:31:24 +04:00
|
|
|
}
|
2011-09-19 18:54:09 +04:00
|
|
|
}
|