gst_plugins_base/gst-libs/gst/rtsp/gstrtsprange.c
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
    67  * npt-ss       =   1*2DIGIT    ; 0-59
    67  * npt-ss       =   1*2DIGIT    ; 0-59
    68  */
    68  */
    69 static GstRTSPResult
    69 static GstRTSPResult
    70 parse_npt_time (const gchar * str, GstRTSPTime * time)
    70 parse_npt_time (const gchar * str, GstRTSPTime * time)
    71 {
    71 {
    72   if (strncmp (str, "now", 3) == 0) {
    72   if (strcmp (str, "now") == 0) {
    73     time->type = GST_RTSP_TIME_NOW;
    73     time->type = GST_RTSP_TIME_NOW;
    74   } else if (str[0] == '\0') {
    74   } else if (str[0] == '\0') {
    75     time->type = GST_RTSP_TIME_END;
    75     time->type = GST_RTSP_TIME_END;
    76   } else if (strstr (str, ":")) {
    76   } else if (strstr (str, ":")) {
    77     gfloat seconds;
    77     gfloat seconds;
   165     res->unit = GST_RTSP_RANGE_SMPTE_25;
   165     res->unit = GST_RTSP_RANGE_SMPTE_25;
   166     ret = parse_smpte_range (p + 9, res);
   166     ret = parse_smpte_range (p + 9, res);
   167   } else
   167   } else
   168     goto invalid;
   168     goto invalid;
   169 
   169 
   170   if (ret != GST_RTSP_OK)
   170   if (ret == GST_RTSP_OK)
   171     goto invalid;
   171     *range = res;
   172 
   172 
   173   *range = res;
       
   174   return ret;
   173   return ret;
   175 
   174 
   176   /* ERRORS */
   175   /* ERRORS */
   177 invalid:
   176 invalid:
   178   {
   177   {
   179     gst_rtsp_range_free (res);
   178     gst_rtsp_range_free (res);
   180     return GST_RTSP_EINVAL;
   179     return GST_RTSP_EINVAL;
   181   }
   180   }
   182 }
       
   183 
       
   184 static gboolean
       
   185 npt_time_string (const GstRTSPTime * time, GString * string)
       
   186 {
       
   187   gboolean res = TRUE;;
       
   188 
       
   189   switch (time->type) {
       
   190     case GST_RTSP_TIME_SECONDS:
       
   191       g_string_append_printf (string, "%f", time->seconds);
       
   192       break;
       
   193     case GST_RTSP_TIME_NOW:
       
   194       g_string_append (string, "now");
       
   195       break;
       
   196     case GST_RTSP_TIME_END:
       
   197       break;
       
   198     default:
       
   199       res = FALSE;
       
   200       break;
       
   201   }
       
   202   return res;
       
   203 }
       
   204 
       
   205 static gboolean
       
   206 npt_range_string (const GstRTSPTimeRange * range, GString * string)
       
   207 {
       
   208   gboolean res;
       
   209 
       
   210   if (!(res = npt_time_string (&range->min, string)))
       
   211     goto done;
       
   212 
       
   213   g_string_append (string, "-");
       
   214 
       
   215   if (!(res = npt_time_string (&range->max, string)))
       
   216     goto done;
       
   217 
       
   218 done:
       
   219   return res;
       
   220 }
       
   221 
       
   222 /**
       
   223  * gst_rtsp_range_to_string:
       
   224  * @range: a #GstRTSPTimeRange
       
   225  *
       
   226  * Convert @range into a string representation.
       
   227  *
       
   228  * Returns: The string representation of @range. g_free() after usage.
       
   229  *
       
   230  * Since: 0.10.23
       
   231  */
       
   232 gchar *
       
   233 gst_rtsp_range_to_string (const GstRTSPTimeRange * range)
       
   234 {
       
   235   gchar *result = NULL;
       
   236   GString *string;
       
   237 
       
   238   g_return_val_if_fail (range != NULL, NULL);
       
   239 
       
   240   string = g_string_new ("");
       
   241 
       
   242   switch (range->unit) {
       
   243     case GST_RTSP_RANGE_NPT:
       
   244       g_string_append (string, "npt=");
       
   245       if (!npt_range_string (range, string)) {
       
   246         g_string_free (string, TRUE);
       
   247         string = NULL;
       
   248       }
       
   249       break;
       
   250     case GST_RTSP_RANGE_SMPTE:
       
   251     case GST_RTSP_RANGE_SMPTE_30_DROP:
       
   252     case GST_RTSP_RANGE_SMPTE_25:
       
   253     case GST_RTSP_RANGE_CLOCK:
       
   254     default:
       
   255       g_warning ("time range unit not yet implemented");
       
   256       g_string_free (string, TRUE);
       
   257       string = NULL;
       
   258       break;
       
   259   }
       
   260   if (string)
       
   261     result = g_string_free (string, FALSE);
       
   262 
       
   263   return result;
       
   264 }
   181 }
   265 
   182 
   266 /**
   183 /**
   267  * gst_rtsp_range_free:
   184  * gst_rtsp_range_free:
   268  * @range: a #GstRTSPTimeRange
   185  * @range: a #GstRTSPTimeRange
   270  * Free the memory alocated by @range.
   187  * Free the memory alocated by @range.
   271  */
   188  */
   272 void
   189 void
   273 gst_rtsp_range_free (GstRTSPTimeRange * range)
   190 gst_rtsp_range_free (GstRTSPTimeRange * range)
   274 {
   191 {
       
   192   if (range == NULL)
       
   193     return;
       
   194 
   275   g_free (range);
   195   g_free (range);
   276 }
   196 }