2012-06-13 23:45:58 +04:00
|
|
|
/*
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-06-13 23:45:58 +04:00
|
|
|
* Video Redirection Virtual Channel - GStreamer Decoder
|
|
|
|
*
|
2014-05-23 15:46:37 +04:00
|
|
|
* (C) Copyright 2012 HP Development Company, LLC
|
|
|
|
* (C) Copyright 2014 Thincast Technologies GmbH
|
|
|
|
* (C) Copyright 2014 Armin Novak <armin.novak@thincast.com>
|
|
|
|
*
|
2012-06-13 23:45:58 +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.
|
2019-11-06 17:24:51 +03:00
|
|
|
*/
|
2012-06-13 23:45:58 +04:00
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2021-06-09 15:03:34 +03:00
|
|
|
#include <winpr/assert.h>
|
2012-10-09 22:26:07 +04:00
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2012-10-09 22:26:07 +04:00
|
|
|
|
2015-07-03 14:26:15 +03:00
|
|
|
#include <winpr/string.h>
|
|
|
|
|
2017-08-29 10:09:38 +03:00
|
|
|
#if __clang__
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wparentheses-equality"
|
|
|
|
#endif /* __clang__ */
|
2012-06-13 23:45:58 +04:00
|
|
|
#include <gst/gst.h>
|
2017-08-29 10:09:38 +03:00
|
|
|
#if __clang__
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif /* __clang__ */
|
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
#include <gst/app/gstappsrc.h>
|
|
|
|
#include <gst/app/gstappsink.h>
|
|
|
|
|
|
|
|
#include "tsmf_constants.h"
|
|
|
|
#include "tsmf_decoder.h"
|
2014-05-23 15:46:37 +04:00
|
|
|
#include "tsmf_platform.h"
|
2012-06-13 23:45:58 +04:00
|
|
|
|
2012-10-09 22:52:07 +04:00
|
|
|
#ifdef HAVE_INTTYPES_H
|
|
|
|
#include <inttypes.h>
|
|
|
|
#endif
|
|
|
|
|
2015-07-08 21:10:21 +03:00
|
|
|
/* 1 second = 10,000,000 100ns units*/
|
2019-11-06 17:24:51 +03:00
|
|
|
#define SEEK_TOLERANCE 10 * 1000 * 1000
|
2015-07-08 00:39:29 +03:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder);
|
|
|
|
static void tsmf_gstreamer_clean_up(TSMFGstreamerDecoder* mdecoder);
|
|
|
|
static int tsmf_gstreamer_pipeline_set_state(TSMFGstreamerDecoder* mdecoder,
|
2019-11-06 17:24:51 +03:00
|
|
|
GstState desired_state);
|
2015-07-08 00:39:29 +03:00
|
|
|
static BOOL tsmf_gstreamer_buffer_level(ITSMFDecoder* decoder);
|
2012-06-13 23:45:58 +04:00
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
static const char* get_type(TSMFGstreamerDecoder* mdecoder)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
if (!mdecoder)
|
|
|
|
return NULL;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 21:10:21 +03:00
|
|
|
switch (mdecoder->media_type)
|
|
|
|
{
|
|
|
|
case TSMF_MAJOR_TYPE_VIDEO:
|
|
|
|
return "VIDEO";
|
|
|
|
case TSMF_MAJOR_TYPE_AUDIO:
|
|
|
|
return "AUDIO";
|
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
2015-07-08 00:39:29 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void cb_child_added(GstChildProxy* child_proxy, GObject* object,
|
|
|
|
TSMFGstreamerDecoder* mdecoder)
|
2015-07-08 00:39:29 +03:00
|
|
|
{
|
|
|
|
DEBUG_TSMF("NAME: %s", G_OBJECT_TYPE_NAME(object));
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstXvImageSink") ||
|
|
|
|
!g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstXImageSink") ||
|
|
|
|
!g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstFluVAAutoSink"))
|
2015-07-08 00:39:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
gst_base_sink_set_max_lateness((GstBaseSink*)object, 10000000); /* nanoseconds */
|
|
|
|
g_object_set(G_OBJECT(object), "sync", TRUE, NULL); /* synchronize on the clock */
|
2015-07-08 21:10:21 +03:00
|
|
|
g_object_set(G_OBJECT(object), "async", TRUE, NULL); /* no async state changes */
|
2015-07-08 00:39:29 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
else if (!g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstAlsaSink") ||
|
|
|
|
!g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstPulseSink"))
|
2015-07-08 00:39:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
gst_base_sink_set_max_lateness((GstBaseSink*)object, 10000000); /* nanoseconds */
|
2015-07-08 21:10:21 +03:00
|
|
|
g_object_set(G_OBJECT(object), "slave-method", 1, NULL);
|
2019-11-06 17:24:51 +03:00
|
|
|
g_object_set(G_OBJECT(object), "buffer-time", (gint64)20000, NULL); /* microseconds */
|
|
|
|
g_object_set(G_OBJECT(object), "drift-tolerance", (gint64)20000, NULL); /* microseconds */
|
|
|
|
g_object_set(G_OBJECT(object), "latency-time", (gint64)10000, NULL); /* microseconds */
|
|
|
|
g_object_set(G_OBJECT(object), "sync", TRUE, NULL); /* synchronize on the clock */
|
2015-07-08 21:10:21 +03:00
|
|
|
g_object_set(G_OBJECT(object), "async", TRUE, NULL); /* no async state changes */
|
2015-07-08 00:39:29 +03:00
|
|
|
}
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void tsmf_gstreamer_enough_data(GstAppSrc* src, gpointer user_data)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMFGstreamerDecoder* mdecoder = user_data;
|
2019-11-06 17:24:51 +03:00
|
|
|
(void)mdecoder;
|
2014-05-23 15:46:37 +04:00
|
|
|
DEBUG_TSMF("%s", get_type(mdecoder));
|
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void tsmf_gstreamer_need_data(GstAppSrc* src, guint length, gpointer user_data)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMFGstreamerDecoder* mdecoder = user_data;
|
2019-11-06 17:24:51 +03:00
|
|
|
(void)mdecoder;
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_TSMF("%s length=%u", get_type(mdecoder), length);
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static gboolean tsmf_gstreamer_seek_data(GstAppSrc* src, guint64 offset, gpointer user_data)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
TSMFGstreamerDecoder* mdecoder = user_data;
|
2019-11-06 17:24:51 +03:00
|
|
|
(void)mdecoder;
|
|
|
|
DEBUG_TSMF("%s offset=%" PRIu64 "", get_type(mdecoder), offset);
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-09-03 20:58:16 +03:00
|
|
|
static BOOL tsmf_gstreamer_change_volume(ITSMFDecoder* decoder, UINT32 newVolume, UINT32 muted)
|
2015-07-08 00:39:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder*)decoder;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
if (!mdecoder || !mdecoder->pipe)
|
2015-09-03 20:58:16 +03:00
|
|
|
return TRUE;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO)
|
2015-09-03 20:58:16 +03:00
|
|
|
return TRUE;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gstMuted = (BOOL)muted;
|
|
|
|
DEBUG_TSMF("mute=[%" PRId32 "]", mdecoder->gstMuted);
|
|
|
|
mdecoder->gstVolume = (double)newVolume / (double)10000;
|
2015-07-08 00:39:29 +03:00
|
|
|
DEBUG_TSMF("gst_new_vol=[%f]", mdecoder->gstVolume);
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
if (!mdecoder->volume)
|
2015-09-03 20:58:16 +03:00
|
|
|
return TRUE;
|
2015-07-08 00:39:29 +03:00
|
|
|
|
|
|
|
if (!G_IS_OBJECT(mdecoder->volume))
|
2015-09-03 20:58:16 +03:00
|
|
|
return TRUE;
|
2015-07-08 00:39:29 +03:00
|
|
|
|
|
|
|
g_object_set(mdecoder->volume, "mute", mdecoder->gstMuted, NULL);
|
|
|
|
g_object_set(mdecoder->volume, "volume", mdecoder->gstVolume, NULL);
|
2015-09-03 20:58:16 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
|
2015-05-05 19:33:44 +03:00
|
|
|
static inline GstClockTime tsmf_gstreamer_timestamp_ms_to_gst(UINT64 ms_timestamp)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:46:37 +04:00
|
|
|
/*
|
2012-06-13 23:45:58 +04:00
|
|
|
* Convert Microsoft 100ns timestamps to Gstreamer 1ns units.
|
|
|
|
*/
|
|
|
|
return (GstClockTime)(ms_timestamp * 100);
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
int tsmf_gstreamer_pipeline_set_state(TSMFGstreamerDecoder* mdecoder, GstState desired_state)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
|
|
|
GstStateChangeReturn state_change;
|
2014-11-10 22:02:54 +03:00
|
|
|
const char* name;
|
|
|
|
const char* sname = get_type(mdecoder);
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (!mdecoder)
|
2014-05-23 15:46:37 +04:00
|
|
|
return 0;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (!mdecoder->pipe)
|
2019-11-06 17:24:51 +03:00
|
|
|
return 0; /* Just in case this is called during startup or shutdown when we don't expect it
|
|
|
|
*/
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (desired_state == mdecoder->state)
|
2019-11-06 17:24:51 +03:00
|
|
|
return 0; /* Redundant request - Nothing to do */
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-05-25 00:22:33 +04:00
|
|
|
name = gst_element_state_get_name(desired_state); /* For debug */
|
2014-05-25 12:08:50 +04:00
|
|
|
DEBUG_TSMF("%s to %s", sname, name);
|
2014-05-23 15:46:37 +04:00
|
|
|
state_change = gst_element_set_state(mdecoder->pipe, desired_state);
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (state_change == GST_STATE_CHANGE_FAILURE)
|
2014-11-10 22:02:54 +03:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "%s: (%s) GST_STATE_CHANGE_FAILURE.", sname, name);
|
2014-11-10 22:02:54 +03:00
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
else if (state_change == GST_STATE_CHANGE_ASYNC)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "%s: (%s) GST_STATE_CHANGE_ASYNC.", sname, name);
|
2014-05-23 17:35:25 +04:00
|
|
|
mdecoder->state = desired_state;
|
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
else
|
2014-11-10 22:02:54 +03:00
|
|
|
{
|
2014-05-23 17:35:25 +04:00
|
|
|
mdecoder->state = desired_state;
|
2014-11-10 22:02:54 +03:00
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static GstBuffer* tsmf_get_buffer_from_data(const void* raw_data, gsize size)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
GstBuffer* buffer;
|
2014-05-23 15:46:37 +04:00
|
|
|
gpointer data;
|
2014-11-10 22:02:54 +03:00
|
|
|
|
|
|
|
if (!raw_data)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (size < 1)
|
|
|
|
return NULL;
|
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
data = g_malloc(size);
|
2014-05-25 00:22:33 +04:00
|
|
|
|
|
|
|
if (!data)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Could not allocate %" G_GSIZE_FORMAT " bytes of data.", size);
|
2014-05-25 00:22:33 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
CopyMemory(data, raw_data, size);
|
|
|
|
|
2014-05-25 00:22:33 +04:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
|
|
|
buffer = gst_buffer_new_wrapped(data, size);
|
|
|
|
#else
|
|
|
|
buffer = gst_buffer_new();
|
2012-06-13 23:45:58 +04:00
|
|
|
|
2014-05-25 00:22:33 +04:00
|
|
|
if (!buffer)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Could not create GstBuffer");
|
2014-05-25 00:22:33 +04:00
|
|
|
free(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_BUFFER_MALLOCDATA(buffer) = data;
|
|
|
|
GST_BUFFER_SIZE(buffer) = size;
|
|
|
|
GST_BUFFER_DATA(buffer) = GST_BUFFER_MALLOCDATA(buffer);
|
|
|
|
#endif
|
2014-11-10 22:02:54 +03:00
|
|
|
|
2014-05-25 00:22:33 +04:00
|
|
|
return buffer;
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* media_type)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder*)decoder;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (!mdecoder)
|
2014-05-23 15:46:37 +04:00
|
|
|
return FALSE;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
DEBUG_TSMF("");
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
switch (media_type->MajorType)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
|
|
|
case TSMF_MAJOR_TYPE_VIDEO:
|
|
|
|
mdecoder->media_type = TSMF_MAJOR_TYPE_VIDEO;
|
|
|
|
break;
|
|
|
|
case TSMF_MAJOR_TYPE_AUDIO:
|
|
|
|
mdecoder->media_type = TSMF_MAJOR_TYPE_AUDIO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
switch (media_type->SubType)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
|
|
|
case TSMF_SUB_TYPE_WVC1:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"video/x-wmv", "bitrate", G_TYPE_UINT, media_type->BitRate, "width", G_TYPE_INT,
|
|
|
|
media_type->Width, "height", G_TYPE_INT, media_type->Height, "wmvversion",
|
|
|
|
G_TYPE_INT, 3,
|
2015-07-08 21:10:21 +03:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
2019-11-06 17:24:51 +03:00
|
|
|
"format", G_TYPE_STRING, "WVC1",
|
2015-07-08 21:10:21 +03:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('W', 'V', 'C', '1'),
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2019-11-06 17:24:51 +03:00
|
|
|
"framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator,
|
|
|
|
media_type->SamplesPerSecond.Denominator, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
1, 1, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_MP4S:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"video/x-divx", "divxversion", G_TYPE_INT, 5, "bitrate", G_TYPE_UINT,
|
|
|
|
media_type->BitRate, "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT,
|
|
|
|
media_type->Height,
|
2015-07-08 21:10:21 +03:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
2019-11-06 17:24:51 +03:00
|
|
|
"format", G_TYPE_STRING, "MP42",
|
|
|
|
#else
|
|
|
|
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('M', 'P', '4', '2'),
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2019-11-06 17:24:51 +03:00
|
|
|
"framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator,
|
|
|
|
media_type->SamplesPerSecond.Denominator, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_MP42:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"video/x-msmpeg", "msmpegversion", G_TYPE_INT, 42, "bitrate", G_TYPE_UINT,
|
|
|
|
media_type->BitRate, "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT,
|
|
|
|
media_type->Height,
|
|
|
|
#if GST_VERSION_MAJOR > 0
|
|
|
|
"format", G_TYPE_STRING, "MP42",
|
2015-07-08 21:10:21 +03:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('M', 'P', '4', '2'),
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2019-11-06 17:24:51 +03:00
|
|
|
"framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator,
|
|
|
|
media_type->SamplesPerSecond.Denominator, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_MP43:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"video/x-msmpeg", "msmpegversion", G_TYPE_INT, 43, "bitrate", G_TYPE_UINT,
|
|
|
|
media_type->BitRate, "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT,
|
|
|
|
media_type->Height,
|
|
|
|
#if GST_VERSION_MAJOR > 0
|
|
|
|
"format", G_TYPE_STRING, "MP43",
|
|
|
|
#else
|
|
|
|
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('M', 'P', '4', '3'),
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2019-11-06 17:24:51 +03:00
|
|
|
"framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator,
|
|
|
|
media_type->SamplesPerSecond.Denominator, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
2015-07-08 00:39:29 +03:00
|
|
|
case TSMF_SUB_TYPE_M4S2:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"video/mpeg", "mpegversion", G_TYPE_INT, 4, "width", G_TYPE_INT, media_type->Width,
|
|
|
|
"height", G_TYPE_INT, media_type->Height,
|
|
|
|
#if GST_VERSION_MAJOR > 0
|
|
|
|
"format", G_TYPE_STRING, "M4S2",
|
|
|
|
#else
|
|
|
|
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('M', '4', 'S', '2'),
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2019-11-06 17:24:51 +03:00
|
|
|
"framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator,
|
|
|
|
media_type->SamplesPerSecond.Denominator, NULL);
|
2015-07-08 00:39:29 +03:00
|
|
|
break;
|
2012-06-13 23:45:58 +04:00
|
|
|
case TSMF_SUB_TYPE_WMA9:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"audio/x-wma", "wmaversion", G_TYPE_INT, 3, "rate", G_TYPE_INT,
|
|
|
|
media_type->SamplesPerSecond.Numerator, "channels", G_TYPE_INT,
|
|
|
|
media_type->Channels, "bitrate", G_TYPE_INT, media_type->BitRate, "depth",
|
|
|
|
G_TYPE_INT, media_type->BitsPerSample, "width", G_TYPE_INT,
|
|
|
|
media_type->BitsPerSample, "block_align", G_TYPE_INT, media_type->BlockAlign, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
2015-07-08 00:39:29 +03:00
|
|
|
case TSMF_SUB_TYPE_WMA1:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"audio/x-wma", "wmaversion", G_TYPE_INT, 1, "rate", G_TYPE_INT,
|
|
|
|
media_type->SamplesPerSecond.Numerator, "channels", G_TYPE_INT,
|
|
|
|
media_type->Channels, "bitrate", G_TYPE_INT, media_type->BitRate, "depth",
|
|
|
|
G_TYPE_INT, media_type->BitsPerSample, "width", G_TYPE_INT,
|
|
|
|
media_type->BitsPerSample, "block_align", G_TYPE_INT, media_type->BlockAlign, NULL);
|
2015-07-08 00:39:29 +03:00
|
|
|
break;
|
2012-06-13 23:45:58 +04:00
|
|
|
case TSMF_SUB_TYPE_WMA2:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"audio/x-wma", "wmaversion", G_TYPE_INT, 2, "rate", G_TYPE_INT,
|
|
|
|
media_type->SamplesPerSecond.Numerator, "channels", G_TYPE_INT,
|
|
|
|
media_type->Channels, "bitrate", G_TYPE_INT, media_type->BitRate, "depth",
|
|
|
|
G_TYPE_INT, media_type->BitsPerSample, "width", G_TYPE_INT,
|
|
|
|
media_type->BitsPerSample, "block_align", G_TYPE_INT, media_type->BlockAlign, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_MP3:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps =
|
|
|
|
gst_caps_new_simple("audio/mpeg", "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT,
|
|
|
|
3, "rate", G_TYPE_INT, media_type->SamplesPerSecond.Numerator,
|
|
|
|
"channels", G_TYPE_INT, media_type->Channels, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_WMV1:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"video/x-wmv", "bitrate", G_TYPE_UINT, media_type->BitRate, "width", G_TYPE_INT,
|
|
|
|
media_type->Width, "height", G_TYPE_INT, media_type->Height, "wmvversion",
|
|
|
|
G_TYPE_INT, 1,
|
|
|
|
#if GST_VERSION_MAJOR > 0
|
|
|
|
"format", G_TYPE_STRING, "WMV1",
|
|
|
|
#else
|
|
|
|
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('W', 'M', 'V', '1'),
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2019-11-06 17:24:51 +03:00
|
|
|
"framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator,
|
|
|
|
media_type->SamplesPerSecond.Denominator, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_WMV2:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"video/x-wmv", "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT,
|
|
|
|
media_type->Height, "wmvversion", G_TYPE_INT, 2,
|
|
|
|
#if GST_VERSION_MAJOR > 0
|
|
|
|
"format", G_TYPE_STRING, "WMV2",
|
2015-07-08 21:10:21 +03:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('W', 'M', 'V', '2'),
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2019-11-06 17:24:51 +03:00
|
|
|
"framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator,
|
|
|
|
media_type->SamplesPerSecond.Denominator, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
1, 1, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_WMV3:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"video/x-wmv", "bitrate", G_TYPE_UINT, media_type->BitRate, "width", G_TYPE_INT,
|
|
|
|
media_type->Width, "height", G_TYPE_INT, media_type->Height, "wmvversion",
|
|
|
|
G_TYPE_INT, 3,
|
|
|
|
#if GST_VERSION_MAJOR > 0
|
|
|
|
"format", G_TYPE_STRING, "WMV3",
|
2015-07-08 21:10:21 +03:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('W', 'M', 'V', '3'),
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2019-11-06 17:24:51 +03:00
|
|
|
"framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator,
|
|
|
|
media_type->SamplesPerSecond.Denominator, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
1, 1, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_AVC1:
|
|
|
|
case TSMF_SUB_TYPE_H264:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"video/x-h264", "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT,
|
|
|
|
media_type->Height, "framerate", GST_TYPE_FRACTION,
|
|
|
|
media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator,
|
|
|
|
"pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, "stream-format", G_TYPE_STRING,
|
|
|
|
"byte-stream", "alignment", G_TYPE_STRING, "nal", NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_AC3:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"audio/x-ac3", "rate", G_TYPE_INT, media_type->SamplesPerSecond.Numerator,
|
|
|
|
"channels", G_TYPE_INT, media_type->Channels, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_AAC:
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
/* For AAC the pFormat is a HEAACWAVEINFO struct, and the codec data
|
|
|
|
is at the end of it. See
|
|
|
|
http://msdn.microsoft.com/en-us/library/dd757806.aspx */
|
2014-05-23 17:35:25 +04:00
|
|
|
if (media_type->ExtraData)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
|
|
|
media_type->ExtraData += 12;
|
|
|
|
media_type->ExtraDataSize -= 12;
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"audio/mpeg", "rate", G_TYPE_INT, media_type->SamplesPerSecond.Numerator,
|
|
|
|
"channels", G_TYPE_INT, media_type->Channels, "mpegversion", G_TYPE_INT, 4,
|
|
|
|
"framed", G_TYPE_BOOLEAN, TRUE, "stream-format", G_TYPE_STRING, "raw", NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_MP1A:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps =
|
|
|
|
gst_caps_new_simple("audio/mpeg", "mpegversion", G_TYPE_INT, 1, "channels",
|
|
|
|
G_TYPE_INT, media_type->Channels, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_MP1V:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps =
|
|
|
|
gst_caps_new_simple("video/mpeg", "mpegversion", G_TYPE_INT, 1, "width", G_TYPE_INT,
|
|
|
|
media_type->Width, "height", G_TYPE_INT, media_type->Height,
|
|
|
|
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_YUY2:
|
2014-05-26 09:46:11 +04:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"video/x-raw", "format", G_TYPE_STRING, "YUY2", "width", G_TYPE_INT,
|
|
|
|
media_type->Width, "height", G_TYPE_INT, media_type->Height, NULL);
|
2014-05-26 09:46:11 +04:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple(
|
|
|
|
"video/x-raw-yuv", "format", G_TYPE_STRING, "YUY2", "width", G_TYPE_INT,
|
|
|
|
media_type->Width, "height", G_TYPE_INT, media_type->Height, "framerate",
|
|
|
|
GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator,
|
|
|
|
media_type->SamplesPerSecond.Denominator, NULL);
|
2014-05-26 09:46:11 +04:00
|
|
|
#endif
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_MP2V:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple("video/mpeg", "mpegversion", G_TYPE_INT, 2,
|
|
|
|
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
|
|
|
case TSMF_SUB_TYPE_MP2A:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps =
|
|
|
|
gst_caps_new_simple("audio/mpeg", "mpegversion", G_TYPE_INT, 1, "rate", G_TYPE_INT,
|
|
|
|
media_type->SamplesPerSecond.Numerator, "channels", G_TYPE_INT,
|
|
|
|
media_type->Channels, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
break;
|
2015-07-08 00:39:29 +03:00
|
|
|
case TSMF_SUB_TYPE_FLAC:
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->gst_caps = gst_caps_new_simple("audio/x-flac", "", NULL);
|
2015-07-08 00:39:29 +03:00
|
|
|
break;
|
2012-06-13 23:45:58 +04:00
|
|
|
default:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "unknown format:(%d).", media_type->SubType);
|
2012-06-13 23:45:58 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (media_type->ExtraDataSize > 0)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
GstBuffer* buffer;
|
|
|
|
DEBUG_TSMF("Extra data available (%" PRIu32 ")", media_type->ExtraDataSize);
|
2014-05-25 00:22:33 +04:00
|
|
|
buffer = tsmf_get_buffer_from_data(media_type->ExtraData, media_type->ExtraDataSize);
|
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "could not allocate GstBuffer!");
|
2014-05-25 00:22:33 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_set_simple(mdecoder->gst_caps, "codec_data", GST_TYPE_BUFFER, buffer, NULL);
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_TSMF("%p format '%s'", (void*)mdecoder, gst_caps_to_string(mdecoder->gst_caps));
|
2014-05-23 15:46:37 +04:00
|
|
|
tsmf_platform_set_format(mdecoder);
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
/* Create the pipeline... */
|
2014-05-23 17:35:25 +04:00
|
|
|
if (!tsmf_gstreamer_pipeline_build(mdecoder))
|
2014-05-23 15:46:37 +04:00
|
|
|
return FALSE;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-09-12 18:19:32 +04:00
|
|
|
void tsmf_gstreamer_clean_up(TSMFGstreamerDecoder* mdecoder)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 17:35:25 +04:00
|
|
|
if (!mdecoder || !mdecoder->pipe)
|
2014-05-23 15:46:37 +04:00
|
|
|
return;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (mdecoder->pipe && GST_OBJECT_REFCOUNT_VALUE(mdecoder->pipe) > 0)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-05-25 01:32:47 +04:00
|
|
|
tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_NULL);
|
2014-05-23 15:46:37 +04:00
|
|
|
gst_object_unref(mdecoder->pipe);
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
mdecoder->ready = FALSE;
|
2015-07-08 00:39:29 +03:00
|
|
|
mdecoder->paused = FALSE;
|
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
mdecoder->pipe = NULL;
|
|
|
|
mdecoder->src = NULL;
|
2015-07-08 00:39:29 +03:00
|
|
|
mdecoder->queue = NULL;
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2015-07-08 21:10:21 +03:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
2019-11-06 17:24:51 +03:00
|
|
|
const char* video =
|
|
|
|
"appsrc name=videosource ! queue2 name=videoqueue ! decodebin name=videodecoder !";
|
|
|
|
const char* audio =
|
|
|
|
"appsrc name=audiosource ! queue2 name=audioqueue ! decodebin name=audiodecoder ! "
|
|
|
|
"audioconvert ! audiorate ! audioresample ! volume name=audiovolume !";
|
2015-07-08 21:10:21 +03:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
const char* video =
|
|
|
|
"appsrc name=videosource ! queue2 name=videoqueue ! decodebin2 name=videodecoder !";
|
|
|
|
const char* audio =
|
|
|
|
"appsrc name=audiosource ! queue2 name=audioqueue ! decodebin2 name=audiodecoder ! "
|
|
|
|
"audioconvert ! audiorate ! audioresample ! volume name=audiovolume !";
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2014-05-25 12:08:50 +04:00
|
|
|
char pipeline[1024];
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-05-25 12:08:50 +04:00
|
|
|
if (!mdecoder)
|
|
|
|
return FALSE;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-05-26 09:46:11 +04:00
|
|
|
/* TODO: Construction of the pipeline from a string allows easy overwrite with arguments.
|
|
|
|
* The only fixed elements necessary are appsrc and the volume element for audio streams.
|
|
|
|
* The rest could easily be provided in gstreamer pipeline notation from command line. */
|
2014-05-25 12:08:50 +04:00
|
|
|
if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO)
|
2019-11-06 17:24:51 +03:00
|
|
|
sprintf_s(pipeline, sizeof(pipeline), "%s %s name=videosink", video,
|
|
|
|
tsmf_platform_get_video_sink());
|
2014-05-25 12:08:50 +04:00
|
|
|
else
|
2019-11-06 17:24:51 +03:00
|
|
|
sprintf_s(pipeline, sizeof(pipeline), "%s %s name=audiosink", audio,
|
|
|
|
tsmf_platform_get_audio_sink());
|
2014-05-26 09:46:11 +04:00
|
|
|
|
|
|
|
DEBUG_TSMF("pipeline=%s", pipeline);
|
2014-05-25 12:08:50 +04:00
|
|
|
mdecoder->pipe = gst_parse_launch(pipeline, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
|
2014-05-25 12:08:50 +04:00
|
|
|
if (!mdecoder->pipe)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Failed to create new pipe");
|
2014-05-25 12:08:50 +04:00
|
|
|
return FALSE;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO)
|
|
|
|
mdecoder->src = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "videosource");
|
|
|
|
else
|
|
|
|
mdecoder->src = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "audiosource");
|
2014-05-26 09:46:11 +04:00
|
|
|
|
2014-05-25 12:08:50 +04:00
|
|
|
if (!mdecoder->src)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Failed to get appsrc");
|
2014-05-25 12:08:50 +04:00
|
|
|
return FALSE;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO)
|
|
|
|
mdecoder->queue = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "videoqueue");
|
|
|
|
else
|
|
|
|
mdecoder->queue = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "audioqueue");
|
|
|
|
|
|
|
|
if (!mdecoder->queue)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to get queue");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO)
|
|
|
|
mdecoder->outsink = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "videosink");
|
|
|
|
else
|
|
|
|
mdecoder->outsink = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "audiosink");
|
2014-05-26 09:46:11 +04:00
|
|
|
|
2014-05-25 12:08:50 +04:00
|
|
|
if (!mdecoder->outsink)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Failed to get sink");
|
2012-06-13 23:45:58 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
g_signal_connect(mdecoder->outsink, "child-added", G_CALLBACK(cb_child_added), mdecoder);
|
|
|
|
|
|
|
|
if (mdecoder->media_type == TSMF_MAJOR_TYPE_AUDIO)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-25 12:08:50 +04:00
|
|
|
mdecoder->volume = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "audiovolume");
|
2014-05-26 09:46:11 +04:00
|
|
|
|
2014-05-23 17:35:25 +04:00
|
|
|
if (!mdecoder->volume)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Failed to get volume");
|
2014-05-23 15:46:37 +04:00
|
|
|
return FALSE;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2015-07-08 00:39:29 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
tsmf_gstreamer_change_volume((ITSMFDecoder*)mdecoder, mdecoder->gstVolume * ((double)10000),
|
|
|
|
mdecoder->gstMuted);
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
tsmf_platform_register_handler(mdecoder);
|
|
|
|
/* AppSrc settings */
|
2019-11-06 17:24:51 +03:00
|
|
|
GstAppSrcCallbacks callbacks = {
|
|
|
|
tsmf_gstreamer_need_data, tsmf_gstreamer_enough_data, tsmf_gstreamer_seek_data, { NULL }
|
2014-05-23 15:46:37 +04:00
|
|
|
};
|
|
|
|
g_object_set(mdecoder->src, "format", GST_FORMAT_TIME, NULL);
|
2015-07-08 00:39:29 +03:00
|
|
|
g_object_set(mdecoder->src, "is-live", FALSE, NULL);
|
|
|
|
g_object_set(mdecoder->src, "block", FALSE, NULL);
|
|
|
|
g_object_set(mdecoder->src, "blocksize", 1024, NULL);
|
2019-11-06 17:24:51 +03:00
|
|
|
gst_app_src_set_caps((GstAppSrc*)mdecoder->src, mdecoder->gst_caps);
|
|
|
|
gst_app_src_set_callbacks((GstAppSrc*)mdecoder->src, &callbacks, mdecoder, NULL);
|
|
|
|
gst_app_src_set_stream_type((GstAppSrc*)mdecoder->src, GST_APP_STREAM_TYPE_SEEKABLE);
|
|
|
|
gst_app_src_set_latency((GstAppSrc*)mdecoder->src, 0, -1);
|
|
|
|
gst_app_src_set_max_bytes((GstAppSrc*)mdecoder->src, (guint64)0); // unlimited
|
2015-07-08 00:39:29 +03:00
|
|
|
g_object_set(G_OBJECT(mdecoder->queue), "use-buffering", FALSE, NULL);
|
|
|
|
g_object_set(G_OBJECT(mdecoder->queue), "use-rate-estimate", FALSE, NULL);
|
|
|
|
g_object_set(G_OBJECT(mdecoder->queue), "max-size-buffers", 0, NULL);
|
|
|
|
g_object_set(G_OBJECT(mdecoder->queue), "max-size-bytes", 0, NULL);
|
2019-11-06 17:24:51 +03:00
|
|
|
g_object_set(G_OBJECT(mdecoder->queue), "max-size-time", (guint64)0, NULL);
|
2015-07-08 00:39:29 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
/* Only set these properties if not an autosink, otherwise we will set properties when real
|
|
|
|
* sinks are added */
|
|
|
|
if (!g_strcmp0(G_OBJECT_TYPE_NAME(mdecoder->outsink), "GstAutoVideoSink") &&
|
|
|
|
!g_strcmp0(G_OBJECT_TYPE_NAME(mdecoder->outsink), "GstAutoAudioSink"))
|
2015-07-08 00:39:29 +03:00
|
|
|
{
|
|
|
|
if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
gst_base_sink_set_max_lateness((GstBaseSink*)mdecoder->outsink,
|
|
|
|
10000000); /* nanoseconds */
|
2015-07-08 00:39:29 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
gst_base_sink_set_max_lateness((GstBaseSink*)mdecoder->outsink,
|
|
|
|
10000000); /* nanoseconds */
|
|
|
|
g_object_set(G_OBJECT(mdecoder->outsink), "buffer-time", (gint64)20000,
|
|
|
|
NULL); /* microseconds */
|
|
|
|
g_object_set(G_OBJECT(mdecoder->outsink), "drift-tolerance", (gint64)20000,
|
|
|
|
NULL); /* microseconds */
|
|
|
|
g_object_set(G_OBJECT(mdecoder->outsink), "latency-time", (gint64)10000,
|
|
|
|
NULL); /* microseconds */
|
2015-07-08 00:39:29 +03:00
|
|
|
g_object_set(G_OBJECT(mdecoder->outsink), "slave-method", 1, NULL);
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
g_object_set(G_OBJECT(mdecoder->outsink), "sync", TRUE,
|
|
|
|
NULL); /* synchronize on the clock */
|
2015-07-08 21:10:21 +03:00
|
|
|
g_object_set(G_OBJECT(mdecoder->outsink), "async", TRUE, NULL); /* no async state changes */
|
2015-07-08 00:39:29 +03:00
|
|
|
}
|
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
tsmf_window_create(mdecoder);
|
|
|
|
tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_READY);
|
|
|
|
tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PLAYING);
|
|
|
|
mdecoder->pipeline_start_time_valid = 0;
|
|
|
|
mdecoder->shutdown = 0;
|
2015-07-08 00:39:29 +03:00
|
|
|
mdecoder->paused = FALSE;
|
2014-05-26 10:25:01 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(mdecoder->pipe), GST_DEBUG_GRAPH_SHOW_ALL,
|
|
|
|
get_type(mdecoder));
|
2014-05-26 10:25:01 +04:00
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE* data, UINT32 data_size,
|
|
|
|
UINT32 extensions, UINT64 start_time, UINT64 end_time,
|
|
|
|
UINT64 duration)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
GstBuffer* gst_buf;
|
|
|
|
TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder*)decoder;
|
2014-05-23 15:46:37 +04:00
|
|
|
UINT64 sample_time = tsmf_gstreamer_timestamp_ms_to_gst(start_time);
|
2015-07-08 00:39:29 +03:00
|
|
|
BOOL useTimestamps = TRUE;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (!mdecoder)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Decoder not initialized!");
|
2012-06-13 23:45:58 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
/*
|
|
|
|
* This function is always called from a stream-specific thread.
|
|
|
|
* It should be alright to block here if necessary.
|
|
|
|
* We don't expect to block here often, since the pipeline should
|
2012-06-13 23:45:58 +04:00
|
|
|
* have more than enough buffering.
|
2014-05-23 15:46:37 +04:00
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_TSMF(
|
|
|
|
"%s. Start:(%" PRIu64 ") End:(%" PRIu64 ") Duration:(%" PRIu64 ") Last Start:(%" PRIu64 ")",
|
|
|
|
get_type(mdecoder), start_time, end_time, duration, mdecoder->last_sample_start_time);
|
2015-07-08 00:39:29 +03:00
|
|
|
|
|
|
|
if (mdecoder->shutdown)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "decodeEx called on shutdown decoder");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (mdecoder->gst_caps == NULL)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "tsmf_gstreamer_set_format not called or invalid format.");
|
2012-06-13 23:45:58 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
if (!mdecoder->pipe)
|
|
|
|
tsmf_gstreamer_pipeline_build(mdecoder);
|
|
|
|
|
2014-05-23 17:35:25 +04:00
|
|
|
if (!mdecoder->src)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(
|
|
|
|
TAG,
|
|
|
|
"failed to construct pipeline correctly. Unable to push buffer to source element.");
|
2014-05-23 15:46:37 +04:00
|
|
|
return FALSE;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
gst_buf = tsmf_get_buffer_from_data(data, data_size);
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (gst_buf == NULL)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "tsmf_get_buffer_from_data(%p, %" PRIu32 ") failed.", (void*)data, data_size);
|
2012-06-13 23:45:58 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 21:10:21 +03:00
|
|
|
/* Relative timestamping will sometimes be set to 0
|
|
|
|
* so we ignore these timestamps just to be safe(bit 8)
|
|
|
|
*/
|
2015-07-08 00:39:29 +03:00
|
|
|
if (extensions & 0x00000080)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2015-07-08 00:39:29 +03:00
|
|
|
DEBUG_TSMF("Ignoring the timestamps - relative - bit 8");
|
|
|
|
useTimestamps = FALSE;
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 21:10:21 +03:00
|
|
|
/* If no timestamps exist then we dont want to look at the timestamp values (bit 7) */
|
2015-07-08 00:39:29 +03:00
|
|
|
if (extensions & 0x00000040)
|
|
|
|
{
|
|
|
|
DEBUG_TSMF("Ignoring the timestamps - none - bit 7");
|
|
|
|
useTimestamps = FALSE;
|
|
|
|
}
|
|
|
|
|
2015-07-08 21:10:21 +03:00
|
|
|
/* If performing a seek */
|
2015-07-08 00:39:29 +03:00
|
|
|
if (mdecoder->seeking)
|
|
|
|
{
|
|
|
|
mdecoder->seeking = FALSE;
|
|
|
|
tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PAUSED);
|
2019-11-06 17:24:51 +03:00
|
|
|
mdecoder->pipeline_start_time_valid = 0;
|
2015-07-08 00:39:29 +03:00
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
if (mdecoder->pipeline_start_time_valid)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_TSMF("%s start time %" PRIu64 "", get_type(mdecoder), start_time);
|
2015-09-18 00:19:55 +03:00
|
|
|
|
2015-07-08 21:10:21 +03:00
|
|
|
/* Adjusted the condition for a seek to be based on start time only
|
|
|
|
* WMV1 and WMV2 files in particular have bad end time and duration values
|
|
|
|
* there seems to be no real side effects of just using the start time instead
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT64 minTime = mdecoder->last_sample_start_time - (UINT64)SEEK_TOLERANCE;
|
|
|
|
UINT64 maxTime = mdecoder->last_sample_start_time + (UINT64)SEEK_TOLERANCE;
|
2015-07-08 00:39:29 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
/* Make sure the minTime stops at 0 , should we be at the beginning of the stream */
|
|
|
|
if (mdecoder->last_sample_start_time < (UINT64)SEEK_TOLERANCE)
|
|
|
|
minTime = 0;
|
2015-07-08 00:39:29 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
/* If the start_time is valid and different from the previous start time by more than the
|
|
|
|
* seek tolerance, then we have a seek condition */
|
2015-07-08 00:39:29 +03:00
|
|
|
if (((start_time > maxTime) || (start_time < minTime)) && useTimestamps)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_TSMF("tsmf_gstreamer_decodeEx: start_time=[%" PRIu64
|
|
|
|
"] > last_sample_start_time=[%" PRIu64 "] OR ",
|
|
|
|
start_time, mdecoder->last_sample_start_time);
|
|
|
|
DEBUG_TSMF("tsmf_gstreamer_decodeEx: start_time=[%" PRIu64
|
|
|
|
"] < last_sample_start_time=[%" PRIu64 "] with",
|
|
|
|
start_time, mdecoder->last_sample_start_time);
|
|
|
|
DEBUG_TSMF(
|
|
|
|
"tsmf_gstreamer_decodeEX: a tolerance of more than [%lu] from the last sample",
|
|
|
|
SEEK_TOLERANCE);
|
|
|
|
DEBUG_TSMF("tsmf_gstreamer_decodeEX: minTime=[%" PRIu64 "] maxTime=[%" PRIu64 "]",
|
|
|
|
minTime, maxTime);
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
mdecoder->seeking = TRUE;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
/* since we cant make the gstreamer pipeline jump to the new start time after a seek -
|
|
|
|
* we just maintain a offset between realtime and gstreamer time
|
2015-07-08 21:10:21 +03:00
|
|
|
*/
|
2015-07-08 00:39:29 +03:00
|
|
|
mdecoder->seek_offset = start_time;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
}
|
2014-05-23 15:46:37 +04:00
|
|
|
else
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_TSMF("%s start time %" PRIu64 "", get_type(mdecoder), start_time);
|
2015-07-08 21:10:21 +03:00
|
|
|
/* Always set base/start time to 0. Will use seek offset to translate real buffer times
|
2019-11-06 17:24:51 +03:00
|
|
|
* back to 0. This allows the video to be started from anywhere and the ability to handle
|
|
|
|
* seeks without rebuilding the pipeline, etc. since that is costly
|
2015-07-08 21:10:21 +03:00
|
|
|
*/
|
2015-07-08 00:39:29 +03:00
|
|
|
gst_element_set_base_time(mdecoder->pipe, tsmf_gstreamer_timestamp_ms_to_gst(0));
|
|
|
|
gst_element_set_start_time(mdecoder->pipe, tsmf_gstreamer_timestamp_ms_to_gst(0));
|
2014-05-23 15:46:37 +04:00
|
|
|
mdecoder->pipeline_start_time_valid = 1;
|
2015-07-08 00:39:29 +03:00
|
|
|
|
2015-07-08 21:10:21 +03:00
|
|
|
/* Set the seek offset if buffer has valid timestamps. */
|
2015-07-08 00:39:29 +03:00
|
|
|
if (useTimestamps)
|
|
|
|
mdecoder->seek_offset = start_time;
|
|
|
|
|
|
|
|
if (!gst_element_seek(mdecoder->pipe, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
|
2019-11-06 17:24:51 +03:00
|
|
|
GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
|
2015-07-08 00:39:29 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "seek failed");
|
|
|
|
}
|
2013-06-19 20:33:46 +04:00
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-05-25 00:22:33 +04:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
2015-07-08 00:39:29 +03:00
|
|
|
if (useTimestamps)
|
2019-11-06 17:24:51 +03:00
|
|
|
GST_BUFFER_PTS(gst_buf) =
|
|
|
|
sample_time - tsmf_gstreamer_timestamp_ms_to_gst(mdecoder->seek_offset);
|
2015-07-08 00:39:29 +03:00
|
|
|
else
|
|
|
|
GST_BUFFER_PTS(gst_buf) = GST_CLOCK_TIME_NONE;
|
2014-05-25 00:22:33 +04:00
|
|
|
#else
|
2015-07-08 00:39:29 +03:00
|
|
|
if (useTimestamps)
|
2019-11-06 17:24:51 +03:00
|
|
|
GST_BUFFER_TIMESTAMP(gst_buf) =
|
|
|
|
sample_time - tsmf_gstreamer_timestamp_ms_to_gst(mdecoder->seek_offset);
|
2015-07-08 00:39:29 +03:00
|
|
|
else
|
|
|
|
GST_BUFFER_TIMESTAMP(gst_buf) = GST_CLOCK_TIME_NONE;
|
2014-05-25 00:22:33 +04:00
|
|
|
#endif
|
2015-07-08 00:39:29 +03:00
|
|
|
GST_BUFFER_DURATION(gst_buf) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_OFFSET(gst_buf) = GST_BUFFER_OFFSET_NONE;
|
2015-07-08 21:10:21 +03:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
|
|
|
#else
|
2015-07-08 00:39:29 +03:00
|
|
|
gst_buffer_set_caps(gst_buf, mdecoder->gst_caps);
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2012-06-13 23:45:58 +04:00
|
|
|
gst_app_src_push_buffer(GST_APP_SRC(mdecoder->src), gst_buf);
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 21:10:21 +03:00
|
|
|
/* Should only update the last timestamps if the current ones are valid */
|
2015-07-08 00:39:29 +03:00
|
|
|
if (useTimestamps)
|
|
|
|
{
|
|
|
|
mdecoder->last_sample_start_time = start_time;
|
|
|
|
mdecoder->last_sample_end_time = end_time;
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
if (mdecoder->pipe && (GST_STATE(mdecoder->pipe) != GST_STATE_PLAYING))
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_TSMF("%s: state=%s", get_type(mdecoder),
|
|
|
|
gst_element_state_get_name(GST_STATE(mdecoder->pipe)));
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_TSMF("%s Paused: %" PRIi32 " Shutdown: %i Ready: %" PRIi32 "", get_type(mdecoder),
|
|
|
|
mdecoder->paused, mdecoder->shutdown, mdecoder->ready);
|
2014-05-23 17:35:25 +04:00
|
|
|
if (!mdecoder->paused && !mdecoder->shutdown && mdecoder->ready)
|
2012-06-13 23:45:58 +04:00
|
|
|
tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PLAYING);
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL tsmf_gstreamer_control(ITSMFDecoder* decoder, ITSMFControlMsg control_msg, UINT32* arg)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder*)decoder;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (!mdecoder)
|
2015-09-03 20:58:16 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Control called with no decoder!");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (control_msg == Control_Pause)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:46:37 +04:00
|
|
|
DEBUG_TSMF("Control_Pause %s", get_type(mdecoder));
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (mdecoder->paused)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2015-07-08 00:39:29 +03:00
|
|
|
WLog_ERR(TAG, "%s: Ignoring Control_Pause, already received!", get_type(mdecoder));
|
2015-06-29 16:21:53 +03:00
|
|
|
return TRUE;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PAUSED);
|
2015-07-08 00:39:29 +03:00
|
|
|
mdecoder->shutdown = 0;
|
2014-05-23 15:46:37 +04:00
|
|
|
mdecoder->paused = TRUE;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
else if (control_msg == Control_Resume)
|
|
|
|
{
|
|
|
|
DEBUG_TSMF("Control_Resume %s", get_type(mdecoder));
|
|
|
|
|
|
|
|
if (!mdecoder->paused && !mdecoder->shutdown)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2015-07-08 00:39:29 +03:00
|
|
|
WLog_ERR(TAG, "%s: Ignoring Control_Resume, already received!", get_type(mdecoder));
|
2015-06-29 16:21:53 +03:00
|
|
|
return TRUE;
|
2014-05-23 17:35:25 +04:00
|
|
|
}
|
2014-05-23 15:46:37 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
mdecoder->shutdown = 0;
|
2014-05-23 17:35:25 +04:00
|
|
|
mdecoder->paused = FALSE;
|
|
|
|
}
|
|
|
|
else if (control_msg == Control_Stop)
|
|
|
|
{
|
2014-05-26 09:46:11 +04:00
|
|
|
DEBUG_TSMF("Control_Stop %s", get_type(mdecoder));
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (mdecoder->shutdown)
|
|
|
|
{
|
2015-07-08 00:39:29 +03:00
|
|
|
WLog_ERR(TAG, "%s: Ignoring Control_Stop, already received!", get_type(mdecoder));
|
2015-06-29 16:21:53 +03:00
|
|
|
return TRUE;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
/* Reset stamps, flush buffers, etc */
|
2015-07-08 00:39:29 +03:00
|
|
|
if (mdecoder->pipe)
|
|
|
|
{
|
|
|
|
tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_NULL);
|
|
|
|
tsmf_window_destroy(mdecoder);
|
|
|
|
tsmf_gstreamer_clean_up(mdecoder);
|
|
|
|
}
|
|
|
|
mdecoder->seek_offset = 0;
|
|
|
|
mdecoder->pipeline_start_time_valid = 0;
|
|
|
|
mdecoder->shutdown = 1;
|
|
|
|
}
|
|
|
|
else if (control_msg == Control_Restart)
|
|
|
|
{
|
|
|
|
DEBUG_TSMF("Control_Restart %s", get_type(mdecoder));
|
|
|
|
mdecoder->shutdown = 0;
|
|
|
|
mdecoder->paused = FALSE;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
if (mdecoder->pipeline_start_time_valid)
|
|
|
|
tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PLAYING);
|
2014-05-23 17:35:25 +04:00
|
|
|
}
|
|
|
|
else
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Unknown control message %08x", control_msg);
|
2015-06-29 16:21:53 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
static BOOL tsmf_gstreamer_buffer_level(ITSMFDecoder* decoder)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder*)decoder;
|
2014-05-23 15:46:37 +04:00
|
|
|
DEBUG_TSMF("");
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (!mdecoder)
|
2014-05-23 15:46:37 +04:00
|
|
|
return FALSE;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
guint clbuff = 0;
|
2015-07-08 00:39:29 +03:00
|
|
|
|
|
|
|
if (G_IS_OBJECT(mdecoder->queue))
|
|
|
|
g_object_get(mdecoder->queue, "current-level-buffers", &clbuff, NULL);
|
|
|
|
|
|
|
|
DEBUG_TSMF("%s buffer level %u", get_type(mdecoder), clbuff);
|
|
|
|
return clbuff;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static void tsmf_gstreamer_free(ITSMFDecoder* decoder)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder*)decoder;
|
2014-05-26 09:46:11 +04:00
|
|
|
DEBUG_TSMF("%s", get_type(mdecoder));
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (mdecoder)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2015-07-08 00:39:29 +03:00
|
|
|
tsmf_window_destroy(mdecoder);
|
2014-05-23 15:46:37 +04:00
|
|
|
tsmf_gstreamer_clean_up(mdecoder);
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (mdecoder->gst_caps)
|
2012-06-13 23:45:58 +04:00
|
|
|
gst_caps_unref(mdecoder->gst_caps);
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
tsmf_platform_free(mdecoder);
|
2014-11-10 22:02:54 +03:00
|
|
|
ZeroMemory(mdecoder, sizeof(TSMFGstreamerDecoder));
|
2012-06-13 23:45:58 +04:00
|
|
|
free(mdecoder);
|
2014-05-23 15:46:37 +04:00
|
|
|
mdecoder = NULL;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static UINT64 tsmf_gstreamer_get_running_time(ITSMFDecoder* decoder)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder*)decoder;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (!mdecoder)
|
2012-06-13 23:45:58 +04:00
|
|
|
return 0;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (!mdecoder->outsink)
|
2015-07-08 00:39:29 +03:00
|
|
|
return mdecoder->last_sample_start_time;
|
|
|
|
|
|
|
|
if (!mdecoder->pipe)
|
|
|
|
return 0;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
GstFormat fmt = GST_FORMAT_TIME;
|
|
|
|
gint64 pos = 0;
|
2014-05-25 00:22:33 +04:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
2015-07-08 00:39:29 +03:00
|
|
|
gst_element_query_position(mdecoder->pipe, fmt, &pos);
|
2014-05-25 00:22:33 +04:00
|
|
|
#else
|
2015-07-08 00:39:29 +03:00
|
|
|
gst_element_query_position(mdecoder->pipe, &fmt, &pos);
|
2014-05-25 00:22:33 +04:00
|
|
|
#endif
|
2019-11-06 17:24:51 +03:00
|
|
|
return (UINT64)(pos / 100 + mdecoder->seek_offset);
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL tsmf_gstreamer_update_rendering_area(ITSMFDecoder* decoder, int newX, int newY,
|
|
|
|
int newWidth, int newHeight, int numRectangles,
|
|
|
|
RDP_RECT* rectangles)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder*)decoder;
|
|
|
|
DEBUG_TSMF("x=%d, y=%d, w=%d, h=%d, rect=%d", newX, newY, newWidth, newHeight, numRectangles);
|
2014-05-23 17:35:25 +04:00
|
|
|
|
|
|
|
if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO)
|
2014-11-10 22:02:54 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
return tsmf_window_resize(mdecoder, newX, newY, newWidth, newHeight, numRectangles,
|
|
|
|
rectangles) == 0;
|
2014-11-10 22:02:54 +03:00
|
|
|
}
|
2015-06-29 16:21:53 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
2013-06-19 20:33:46 +04:00
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
static BOOL tsmf_gstreamer_ack(ITSMFDecoder* decoder, BOOL (*cb)(void*, BOOL), void* stream)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder*)decoder;
|
2014-05-23 15:46:37 +04:00
|
|
|
DEBUG_TSMF("");
|
2015-07-08 21:10:21 +03:00
|
|
|
mdecoder->ack_cb = NULL;
|
2014-05-23 15:46:37 +04:00
|
|
|
mdecoder->stream = stream;
|
|
|
|
return TRUE;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
static BOOL tsmf_gstreamer_sync(ITSMFDecoder* decoder, void (*cb)(void*), void* stream)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder*)decoder;
|
2014-05-23 15:46:37 +04:00
|
|
|
DEBUG_TSMF("");
|
|
|
|
mdecoder->sync_cb = NULL;
|
|
|
|
mdecoder->stream = stream;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2012-06-13 23:45:58 +04:00
|
|
|
|
2016-06-15 14:36:27 +03:00
|
|
|
#ifdef BUILTIN_CHANNELS
|
2019-11-06 17:24:51 +03:00
|
|
|
#define freerdp_tsmf_client_subsystem_entry gstreamer_freerdp_tsmf_client_decoder_subsystem_entry
|
2016-03-03 19:11:26 +03:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
#define freerdp_tsmf_client_subsystem_entry FREERDP_API freerdp_tsmf_client_decoder_subsystem_entry
|
2012-11-20 07:31:15 +04:00
|
|
|
#endif
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
ITSMFDecoder* freerdp_tsmf_client_subsystem_entry(void)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
TSMFGstreamerDecoder* decoder;
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
#if GST_CHECK_VERSION(0, 10, 31)
|
2014-05-23 17:35:25 +04:00
|
|
|
if (!gst_is_initialized())
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2014-05-23 15:46:37 +04:00
|
|
|
gst_init(NULL, NULL);
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2017-06-27 18:12:23 +03:00
|
|
|
#else
|
|
|
|
gst_init(NULL, NULL);
|
|
|
|
#endif
|
2014-05-23 17:35:25 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
decoder = calloc(1, sizeof(TSMFGstreamerDecoder));
|
|
|
|
|
|
|
|
if (!decoder)
|
|
|
|
return NULL;
|
|
|
|
|
2012-06-13 23:45:58 +04:00
|
|
|
decoder->iface.SetFormat = tsmf_gstreamer_set_format;
|
|
|
|
decoder->iface.Decode = NULL;
|
|
|
|
decoder->iface.GetDecodedData = NULL;
|
|
|
|
decoder->iface.GetDecodedFormat = NULL;
|
|
|
|
decoder->iface.GetDecodedDimension = NULL;
|
|
|
|
decoder->iface.GetRunningTime = tsmf_gstreamer_get_running_time;
|
|
|
|
decoder->iface.UpdateRenderingArea = tsmf_gstreamer_update_rendering_area;
|
|
|
|
decoder->iface.Free = tsmf_gstreamer_free;
|
|
|
|
decoder->iface.Control = tsmf_gstreamer_control;
|
|
|
|
decoder->iface.DecodeEx = tsmf_gstreamer_decodeEx;
|
|
|
|
decoder->iface.ChangeVolume = tsmf_gstreamer_change_volume;
|
2015-07-08 00:39:29 +03:00
|
|
|
decoder->iface.BufferLevel = tsmf_gstreamer_buffer_level;
|
2014-05-23 15:46:37 +04:00
|
|
|
decoder->iface.SetAckFunc = tsmf_gstreamer_ack;
|
|
|
|
decoder->iface.SetSyncFunc = tsmf_gstreamer_sync;
|
2012-06-13 23:45:58 +04:00
|
|
|
decoder->paused = FALSE;
|
2013-06-19 20:33:46 +04:00
|
|
|
decoder->gstVolume = 0.5;
|
2012-06-13 23:45:58 +04:00
|
|
|
decoder->gstMuted = FALSE;
|
2019-11-06 17:24:51 +03:00
|
|
|
decoder->state = GST_STATE_VOID_PENDING; /* No real state yet */
|
2015-07-08 00:39:29 +03:00
|
|
|
decoder->last_sample_start_time = 0;
|
|
|
|
decoder->last_sample_end_time = 0;
|
|
|
|
decoder->seek_offset = 0;
|
|
|
|
decoder->seeking = FALSE;
|
2014-11-10 22:02:54 +03:00
|
|
|
|
2015-06-29 16:21:53 +03:00
|
|
|
if (tsmf_platform_create(decoder) < 0)
|
|
|
|
{
|
|
|
|
free(decoder);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-11-10 22:02:54 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return (ITSMFDecoder*)decoder;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|