mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
gst/rtsp/: Add code to parse time ranges.
Original commit message from CVS: * gst/rtsp/Makefile.am: * gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_handle_src_query), (gst_rtspsrc_send_keep_alive), (gst_rtspsrc_open): * gst/rtsp/rtsprange.c: (parse_npt_time), (parse_npt_range), (parse_clock_range), (parse_smpte_range), (rtsp_range_parse), (rtsp_range_free): * gst/rtsp/rtsprange.h: Add code to parse time ranges. Report DURATION on the stream when possible.
This commit is contained in:
parent
e38b5e7590
commit
d29215b257
5 changed files with 314 additions and 3 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2007-05-09 Wim Taymans <wim@fluendo.com>
|
||||
|
||||
* gst/rtsp/Makefile.am:
|
||||
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_handle_src_query),
|
||||
(gst_rtspsrc_send_keep_alive), (gst_rtspsrc_open):
|
||||
* gst/rtsp/rtsprange.c: (parse_npt_time), (parse_npt_range),
|
||||
(parse_clock_range), (parse_smpte_range), (rtsp_range_parse),
|
||||
(rtsp_range_free):
|
||||
* gst/rtsp/rtsprange.h:
|
||||
Add code to parse time ranges.
|
||||
Report DURATION on the stream when possible.
|
||||
|
||||
2007-05-08 Tim-Philipp Müller <tim at centricular dot net>
|
||||
|
||||
* gst/videomixer/videomixer.c: (gst_videomixer_blend_ayuv_ayuv),
|
||||
|
|
|
@ -7,6 +7,7 @@ libgstrtsp_la_SOURCES = gstrtsp.c gstrtspsrc.c \
|
|||
rtspextwms.c \
|
||||
rtspmessage.c \
|
||||
rtsptransport.c \
|
||||
rtsprange.c \
|
||||
rtspurl.c \
|
||||
sdpmessage.c \
|
||||
base64.c
|
||||
|
@ -23,4 +24,18 @@ test_SOURCES = test.c rtspdefs.c rtspurl.c rtspconnection.c rtspmessage.c rtsptr
|
|||
test_CFLAGS = $(GST_CFLAGS)
|
||||
test_LDFLAGS = $(GST_LIBS) $(WIN32_LIBS)
|
||||
|
||||
noinst_HEADERS = gstrtspsrc.h gstrtsp.h gstrtpdec.h rtsptransport.h rtsp.h rtspurl.h rtspconnection.h rtspdefs.h rtspmessage.h sdp.h sdpmessage.h rtspextwms.h rtspext.h base64.h
|
||||
noinst_HEADERS = gstrtspsrc.h \
|
||||
gstrtsp.h \
|
||||
gstrtpdec.h \
|
||||
rtsptransport.h \
|
||||
rtsp.h \
|
||||
rtspurl.h \
|
||||
rtsprange.h \
|
||||
rtspconnection.h \
|
||||
rtspdefs.h \
|
||||
rtspmessage.h \
|
||||
sdp.h \
|
||||
sdpmessage.h \
|
||||
rtspextwms.h \
|
||||
rtspext.h \
|
||||
base64.h
|
||||
|
|
|
@ -94,6 +94,7 @@
|
|||
|
||||
#include "gstrtspsrc.h"
|
||||
#include "sdp.h"
|
||||
#include "rtsprange.h"
|
||||
|
||||
/* define for experimental real support */
|
||||
#undef WITH_EXT_REAL
|
||||
|
@ -1068,6 +1069,7 @@ gst_rtspsrc_handle_src_query (GstPad * pad, GstQuery * query)
|
|||
|
||||
switch (format) {
|
||||
case GST_FORMAT_TIME:
|
||||
gst_query_set_duration (query, format, src->segment.duration);
|
||||
break;
|
||||
default:
|
||||
res = FALSE;
|
||||
|
@ -3087,13 +3089,22 @@ gst_rtspsrc_open (GstRTSPSrc * src)
|
|||
if (src->extension && src->extension->parse_sdp)
|
||||
src->extension->parse_sdp (src->extension, &sdp);
|
||||
|
||||
/* parse range */
|
||||
/* parse range for duration reporting. */
|
||||
{
|
||||
gchar *range;
|
||||
RTSPTimeRange *therange;
|
||||
|
||||
range = sdp_message_get_attribute_val (&sdp, "range");
|
||||
|
||||
GST_DEBUG_OBJECT (src, "got range: %s", GST_STR_NULL (range));
|
||||
rtsp_range_parse (range, &therange);
|
||||
|
||||
GST_DEBUG_OBJECT (src, "range: '%s', min %f - max %f ",
|
||||
GST_STR_NULL (range), therange->min.seconds, therange->max.seconds);
|
||||
|
||||
gst_segment_set_duration (&src->segment, GST_FORMAT_TIME,
|
||||
therange->max.seconds * GST_SECOND);
|
||||
gst_segment_set_last_stop (&src->segment, GST_FORMAT_TIME,
|
||||
therange->min.seconds * GST_SECOND);
|
||||
}
|
||||
|
||||
/* create streams */
|
||||
|
|
176
gst/rtsp/rtsprange.c
Normal file
176
gst/rtsp/rtsprange.c
Normal file
|
@ -0,0 +1,176 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2005,2006> Wim Taymans <wim@fluendo.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
/*
|
||||
* Unless otherwise indicated, Source Code is licensed under MIT license.
|
||||
* See further explanation attached in License Statement (distributed in the file
|
||||
* LICENSE).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rtsprange.h"
|
||||
|
||||
/* npt-time = "now" | npt-sec | npt-hhmmss
|
||||
* npt-sec = 1*DIGIT [ "." *DIGIT ]
|
||||
* npt-hhmmss = npt-hh ":" npt-mm ":" npt-ss [ "." *DIGIT ]
|
||||
* npt-hh = 1*DIGIT ; any positive number
|
||||
* npt-mm = 1*2DIGIT ; 0-59
|
||||
* npt-ss = 1*2DIGIT ; 0-59
|
||||
*/
|
||||
static RTSPResult
|
||||
parse_npt_time (const gchar * str, RTSPTime * time)
|
||||
{
|
||||
if (strcmp (str, "now") == 0) {
|
||||
time->type = RTSP_TIME_NOW;
|
||||
} else if (str[0] == '\0') {
|
||||
time->type = RTSP_TIME_END;
|
||||
} else if (strstr (str, ":")) {
|
||||
gfloat seconds;
|
||||
gint hours, mins;
|
||||
|
||||
sscanf (str, "%2d:%2d:%f", &hours, &mins, &seconds);
|
||||
|
||||
time->type = RTSP_TIME_SECONDS;
|
||||
time->seconds = ((hours * 60) + mins) * 60 + seconds;
|
||||
} else {
|
||||
gfloat seconds;
|
||||
|
||||
sscanf (str, "%f", &seconds);
|
||||
|
||||
time->type = RTSP_TIME_SECONDS;
|
||||
time->seconds = seconds;
|
||||
}
|
||||
return RTSP_OK;
|
||||
}
|
||||
|
||||
/* npt-range = ( npt-time "-" [ npt-time ] ) | ( "-" npt-time )
|
||||
*/
|
||||
static RTSPResult
|
||||
parse_npt_range (const gchar * str, RTSPTimeRange * range)
|
||||
{
|
||||
RTSPResult res;
|
||||
gchar *p;
|
||||
|
||||
range->unit = RTSP_RANGE_NPT;
|
||||
|
||||
/* find '-' separator */
|
||||
p = strstr (str, "-");
|
||||
if (p == NULL)
|
||||
return RTSP_EINVAL;
|
||||
|
||||
if ((res = parse_npt_time (str, &range->min)) != RTSP_OK)
|
||||
goto done;
|
||||
|
||||
res = parse_npt_time (p + 1, &range->max);
|
||||
|
||||
done:
|
||||
return res;
|
||||
}
|
||||
|
||||
static RTSPResult
|
||||
parse_clock_range (const gchar * str, RTSPTimeRange * range)
|
||||
{
|
||||
return RTSP_ENOTIMPL;
|
||||
}
|
||||
|
||||
static RTSPResult
|
||||
parse_smpte_range (const gchar * str, RTSPTimeRange * range)
|
||||
{
|
||||
return RTSP_ENOTIMPL;
|
||||
}
|
||||
|
||||
/**
|
||||
* rtsp_range_parse:
|
||||
* @rangestr: a range string to parse
|
||||
* @range: location to hold the #RTSPTimeRange result
|
||||
*
|
||||
* Parse @rangestr to a #RTSPTimeRange.
|
||||
*
|
||||
* Returns: #RTSP_OK on success.
|
||||
*/
|
||||
RTSPResult
|
||||
rtsp_range_parse (const gchar * rangestr, RTSPTimeRange ** range)
|
||||
{
|
||||
RTSPResult ret;
|
||||
RTSPTimeRange *res;
|
||||
gchar *p;
|
||||
|
||||
g_return_val_if_fail (rangestr != NULL, RTSP_EINVAL);
|
||||
g_return_val_if_fail (range != NULL, RTSP_EINVAL);
|
||||
|
||||
res = g_new0 (RTSPTimeRange, 1);
|
||||
|
||||
p = (gchar *) rangestr;
|
||||
/* first figure out the units of the range */
|
||||
if (g_str_has_prefix (p, "npt=")) {
|
||||
ret = parse_npt_range (p + 4, res);
|
||||
} else if (g_str_has_prefix (p, "clock=")) {
|
||||
ret = parse_clock_range (p + 6, res);
|
||||
} else if (g_str_has_prefix (p, "smpte=")) {
|
||||
res->unit = RTSP_RANGE_SMPTE;
|
||||
ret = parse_smpte_range (p + 6, res);
|
||||
} else if (g_str_has_prefix (p, "smpte-30-drop=")) {
|
||||
res->unit = RTSP_RANGE_SMPTE_30_DROP;
|
||||
ret = parse_smpte_range (p + 14, res);
|
||||
} else if (g_str_has_prefix (p, "smpte-25=")) {
|
||||
res->unit = RTSP_RANGE_SMPTE_25;
|
||||
ret = parse_smpte_range (p + 9, res);
|
||||
} else
|
||||
goto invalid;
|
||||
|
||||
if (ret == RTSP_OK)
|
||||
*range = res;
|
||||
|
||||
return ret;
|
||||
|
||||
/* ERRORS */
|
||||
invalid:
|
||||
{
|
||||
rtsp_range_free (res);
|
||||
return RTSP_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rtsp_range_free (RTSPTimeRange * range)
|
||||
{
|
||||
if (range == NULL)
|
||||
return;
|
||||
|
||||
g_free (range);
|
||||
}
|
97
gst/rtsp/rtsprange.h
Normal file
97
gst/rtsp/rtsprange.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2005,2006> Wim Taymans <wim@fluendo.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
/*
|
||||
* Unless otherwise indicated, Source Code is licensed under MIT license.
|
||||
* See further explanation attached in License Statement (distributed in the file
|
||||
* LICENSE).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __RTSP_RANGE_H__
|
||||
#define __RTSP_RANGE_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <rtspdefs.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* RTSPRangeUnit:
|
||||
* @RTSP_RANGE_SMPTE:
|
||||
* @RTSP_RANGE_SMPTE_30_DROP:
|
||||
* @RTSP_RANGE_SMPTE_25:
|
||||
* @RTSP_RANGE_NPT:
|
||||
* @RTSP_RANGE_CLOCK:
|
||||
*
|
||||
* Different possible time range units.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
RTSP_RANGE_SMPTE,
|
||||
RTSP_RANGE_SMPTE_30_DROP,
|
||||
RTSP_RANGE_SMPTE_25,
|
||||
RTSP_RANGE_NPT,
|
||||
RTSP_RANGE_CLOCK
|
||||
} RTSPRangeUnit;
|
||||
|
||||
typedef struct _RTSPTimeRange RTSPTimeRange;
|
||||
typedef struct _RTSPTime RTSPTime;
|
||||
|
||||
typedef enum {
|
||||
RTSP_TIME_SECONDS,
|
||||
RTSP_TIME_NOW,
|
||||
RTSP_TIME_END
|
||||
} RTSPTimeType;
|
||||
|
||||
struct _RTSPTime {
|
||||
RTSPTimeType type;
|
||||
gdouble seconds;
|
||||
};
|
||||
|
||||
struct _RTSPTimeRange {
|
||||
RTSPRangeUnit unit;
|
||||
|
||||
RTSPTime min;
|
||||
RTSPTime max;
|
||||
};
|
||||
|
||||
RTSPResult rtsp_range_parse (const gchar *rangestr, RTSPTimeRange **range);
|
||||
void rtsp_range_free (RTSPTimeRange *range);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __RTSP_RANGE_H__ */
|
Loading…
Reference in a new issue