Home Reference Source

src/types/cmcd.ts

  1. /**
  2. * CMCD spec version
  3. */
  4. export const CMCDVersion = 1;
  5.  
  6. /**
  7. * CMCD Object Type
  8. */
  9. export enum CMCDObjectType {
  10. MANIFEST = 'm',
  11. AUDIO = 'a',
  12. VIDEO = 'v',
  13. MUXED = 'av',
  14. INIT = 'i',
  15. CAPTION = 'c',
  16. TIMED_TEXT = 'tt',
  17. KEY = 'k',
  18. OTHER = 'o',
  19. }
  20.  
  21. /**
  22. * CMCD Streaming Format
  23. */
  24. export enum CMCDStreamingFormat {
  25. DASH = 'd',
  26. HLS = 'h',
  27. SMOOTH = 's',
  28. OTHER = 'o',
  29. }
  30.  
  31. /**
  32. * CMCD Streaming Type
  33. */
  34. export enum CMCDStreamType {
  35. VOD = 'v',
  36. LIVE = 'l',
  37. }
  38.  
  39. /**
  40. * CMCD Headers
  41. */
  42. export interface CMCDHeaders {
  43. 'CMCD-Object': string;
  44. 'CMCD-Request': string;
  45. 'CMCD-Session': string;
  46. 'CMCD-Status': string;
  47. }
  48.  
  49. /**
  50. * CMCD
  51. */
  52. export interface CMCD {
  53. /////////////////
  54. // CMCD Object //
  55. /////////////////
  56.  
  57. /**
  58. * Encoded bitrate
  59. *
  60. * The encoded bitrate of the audio or video object being requested. This may not be known precisely by the player; however,
  61. * it MAY be estimated based upon playlist/manifest declarations. If the playlist declares both peak and average bitrate values,
  62. * the peak value should be transmitted.
  63. *
  64. * Integer kbps
  65. */
  66. br?: number;
  67.  
  68. /**
  69. * Object duration
  70. *
  71. * The playback duration in milliseconds of the object being requested. If a partial segment is being requested, then this value
  72. * MUST indicate the playback duration of that part and not that of its parent segment. This value can be an approximation of the
  73. * estimated duration if the explicit value is not known.
  74. *
  75. * Integer milliseconds
  76. */
  77. d?: number;
  78.  
  79. /**
  80. * Object type
  81. *
  82. * The media type of the current object being requested:
  83. * - `m` = text file, such as a manifest or playlist
  84. * - `a` = audio only
  85. * - `v` = video only
  86. * - `av` = muxed audio and video
  87. * - `i` = init segment
  88. * - `c` = caption or subtitle
  89. * - `tt` = ISOBMFF timed text track
  90. * - `k` = cryptographic key, license or certificate.
  91. * - `o` = other
  92. *
  93. * If the object type being requested is unknown, then this key MUST NOT be used.
  94. */
  95. ot?: CMCDObjectType;
  96.  
  97. /**
  98. * Top bitrate
  99. *
  100. * The highest bitrate rendition in the manifest or playlist that the client is allowed to play, given current codec, licensing and
  101. * sizing constraints.
  102. *
  103. * Integer Kbps
  104. */
  105. tb?: number;
  106.  
  107. //////////////////
  108. // CMCD Request //
  109. //////////////////
  110. /**
  111. * Buffer length
  112. *
  113. * The buffer length associated with the media object being requested. This value MUST be rounded to the nearest 100 ms. This key SHOULD only be
  114. * sent with an object type of ‘a’, ‘v’ or ‘av’.
  115. *
  116. * Integer milliseconds
  117. */
  118. bl?: number;
  119.  
  120. /**
  121. * Deadline
  122. *
  123. * Deadline from the request time until the first sample of this Segment/Object needs to be available in order to not create a buffer underrun or
  124. * any other playback problems. This value MUST be rounded to the nearest 100ms. For a playback rate of 1, this may be equivalent to the player’s
  125. * remaining buffer length.
  126. *
  127. * Integer milliseconds
  128. */
  129. dl?: number;
  130.  
  131. /**
  132. * Measured mtp CMCD throughput
  133. *
  134. * The throughput between client and server, as measured by the client and MUST be rounded to the nearest 100 kbps. This value, however derived,
  135. * SHOULD be the value that the client is using to make its next Adaptive Bitrate switching decision. If the client is connected to multiple
  136. * servers concurrently, it must take care to report only the throughput measured against the receiving server. If the client has multiple concurrent
  137. * connections to the server, then the intent is that this value communicates the aggregate throughput the client sees across all those connections.
  138. *
  139. * Integer kbps
  140. */
  141. mtp?: number;
  142.  
  143. /**
  144. * Next object request
  145. *
  146. * Relative path of the next object to be requested. This can be used to trigger pre-fetching by the CDN. This MUST be a path relative to the current
  147. * request. This string MUST be URLEncoded. The client SHOULD NOT depend upon any pre-fetch action being taken - it is merely a request for such a
  148. * pre-fetch to take place.
  149. *
  150. * String
  151. */
  152. nor?: string;
  153.  
  154. /**
  155. * Next range request
  156. *
  157. * If the next request will be a partial object request, then this string denotes the byte range to be requested. If the ‘nor’ field is not set, then the
  158. * object is assumed to match the object currently being requested. The client SHOULD NOT depend upon any pre-fetch action being taken – it is merely a
  159. * request for such a pre-fetch to take place. Formatting is similar to the HTTP Range header, except that the unit MUST be ‘byte’, the ‘Range:’ prefix is
  160. * NOT required and specifying multiple ranges is NOT allowed. Valid combinations are:
  161. *
  162. * - `"\<range-start\>-"`
  163. * - `"\<range-start\>-\<range-end\>"`
  164. * - `"-\<suffix-length\>"`
  165. *
  166. * String
  167. */
  168. nrr?: string;
  169.  
  170. /**
  171. * Startup
  172. *
  173. * Key is included without a value if the object is needed urgently due to startup, seeking or recovery after a buffer-empty event. The media SHOULD not be
  174. * rendering when this request is made. This key MUST not be sent if it is FALSE.
  175. *
  176. * Boolean
  177. */
  178. su?: boolean;
  179.  
  180. //////////////////
  181. // CMCD Session //
  182. //////////////////
  183.  
  184. /**
  185. * Content ID
  186. *
  187. * A unique string identifying the current content. Maximum length is 64 characters. This value is consistent across multiple different
  188. * sessions and devices and is defined and updated at the discretion of the service provider.
  189. *
  190. * String
  191. */
  192. cid?: string;
  193.  
  194. /**
  195. * Playback rate
  196. *
  197. * `1` if real-time, `2` if double speed, `0` if not playing. SHOULD only be sent if not equal to `1`.
  198. *
  199. * Decimal
  200. */
  201. pr?: number;
  202.  
  203. /**
  204. * Streaming format
  205. *
  206. * The streaming format that defines the current request.
  207. *
  208. * - `d` = MPEG DASH
  209. * - `h` = HTTP Live Streaming (HLS)
  210. * - `s` = Smooth Streaming
  211. * - `o` = other
  212. *
  213. * If the streaming format being requested is unknown, then this key MUST NOT be used.
  214. */
  215. sf?: CMCDStreamingFormat;
  216.  
  217. /**
  218. * Session ID
  219. *
  220. * A GUID identifying the current playback session. A playback session typically ties together segments belonging to a single media asset.
  221. * Maximum length is 64 characters. It is RECOMMENDED to conform to the UUID specification.
  222. *
  223. * String
  224. */
  225. sid?: string;
  226.  
  227. /**
  228. * Stream type
  229. * - `v` = all segments are available – e.g., VOD
  230. * - `l` = segments become available over time – e.g., LIVE
  231. */
  232. st?: CMCDStreamType;
  233.  
  234. /**
  235. * CMCD version
  236. *
  237. * The version of this specification used for interpreting the defined key names and values. If this key is omitted, the client and server MUST
  238. * interpret the values as being defined by version 1. Client SHOULD omit this field if the version is 1.
  239. *
  240. * Integer
  241. */
  242. v?: number;
  243.  
  244. /////////////////
  245. // CMCD Status //
  246. /////////////////
  247.  
  248. /**
  249. * Buffer starvation
  250. *
  251. * Key is included without a value if the buffer was starved at some point between the prior request and this object request,
  252. * resulting in the player being in a rebuffering state and the video or audio playback being stalled. This key MUST NOT be
  253. * sent if the buffer was not starved since the prior request.
  254. *
  255. * If the object type `ot` key is sent along with this key, then the `bs` key refers to the buffer associated with the particular
  256. * object type. If no object type is communicated, then the buffer state applies to the current session.
  257. *
  258. * Boolean
  259. */
  260. bs?: boolean;
  261.  
  262. /**
  263. * Requested maximum throughput
  264. *
  265. * The requested maximum throughput that the client considers sufficient for delivery of the asset. Values MUST be rounded to the
  266. * nearest 100kbps. For example, a client would indicate that the current segment, encoded at 2Mbps, is to be delivered at no more
  267. * than 10Mbps, by using rtp=10000.
  268. *
  269. * Note: This can benefit clients by preventing buffer saturation through over-delivery and can also deliver a community benefit
  270. * through fair-share delivery. The concept is that each client receives the throughput necessary for great performance, but no more.
  271. * The CDN may not support the rtp feature.
  272. *
  273. * Integer kbps
  274. */
  275. rtp?: number;
  276. }