time_description.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package sdp
  2. import (
  3. "strconv"
  4. "strings"
  5. )
  6. // TimeDescription describes "t=", "r=" fields of the session description
  7. // which are used to specify the start and stop times for a session as well as
  8. // repeat intervals and durations for the scheduled session.
  9. type TimeDescription struct {
  10. // t=<start-time> <stop-time>
  11. // https://tools.ietf.org/html/rfc4566#section-5.9
  12. Timing Timing
  13. // r=<repeat interval> <active duration> <offsets from start-time>
  14. // https://tools.ietf.org/html/rfc4566#section-5.10
  15. RepeatTimes []RepeatTime
  16. }
  17. // Timing defines the "t=" field's structured representation for the start and
  18. // stop times.
  19. type Timing struct {
  20. StartTime uint64
  21. StopTime uint64
  22. }
  23. func (t Timing) String() string {
  24. output := strconv.FormatUint(t.StartTime, 10)
  25. output += " " + strconv.FormatUint(t.StopTime, 10)
  26. return output
  27. }
  28. // RepeatTime describes the "r=" fields of the session description which
  29. // represents the intervals and durations for repeated scheduled sessions.
  30. type RepeatTime struct {
  31. Interval int64
  32. Duration int64
  33. Offsets []int64
  34. }
  35. func (r RepeatTime) String() string {
  36. fields := make([]string, 0)
  37. fields = append(fields, strconv.FormatInt(r.Interval, 10))
  38. fields = append(fields, strconv.FormatInt(r.Duration, 10))
  39. for _, value := range r.Offsets {
  40. fields = append(fields, strconv.FormatInt(value, 10))
  41. }
  42. return strings.Join(fields, " ")
  43. }