cea708.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**********************************************************************************************/
  2. /* The MIT License */
  3. /* */
  4. /* Copyright 2016-2017 Twitch Interactive, Inc. or its affiliates. All Rights Reserved. */
  5. /* */
  6. /* Permission is hereby granted, free of charge, to any person obtaining a copy */
  7. /* of this software and associated documentation files (the "Software"), to deal */
  8. /* in the Software without restriction, including without limitation the rights */
  9. /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
  10. /* copies of the Software, and to permit persons to whom the Software is */
  11. /* furnished to do so, subject to the following conditions: */
  12. /* */
  13. /* The above copyright notice and this permission notice shall be included in */
  14. /* all copies or substantial portions of the Software. */
  15. /* */
  16. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
  17. /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
  18. /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
  19. /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
  20. /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
  21. /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
  22. /* THE SOFTWARE. */
  23. /**********************************************************************************************/
  24. #ifndef LIBCAPTION_CEA708_H
  25. #define LIBCAPTION_CEA708_H
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #include "caption.h"
  30. #define CEA608_MAX_SIZE (255)
  31. ////////////////////////////////////////////////////////////////////////////////
  32. typedef enum {
  33. cc_type_ntsc_cc_field_1 = 0,
  34. cc_type_ntsc_cc_field_2 = 1,
  35. cc_type_dtvcc_packet_data = 2,
  36. cc_type_dtvcc_packet_start = 3,
  37. } cea708_cc_type_t;
  38. typedef struct {
  39. unsigned int marker_bits : 5;
  40. unsigned int cc_valid : 1;
  41. unsigned int cc_type : 2; // castable to cea708_cc_type_t
  42. unsigned int cc_data : 16;
  43. } cc_data_t;
  44. typedef struct {
  45. unsigned int process_em_data_flag : 1;
  46. unsigned int process_cc_data_flag : 1;
  47. unsigned int additional_data_flag : 1;
  48. unsigned int cc_count : 5;
  49. unsigned int em_data : 8;
  50. cc_data_t cc_data[32];
  51. } user_data_t;
  52. /*! \brief
  53. \param
  54. */
  55. cc_data_t cea708_encode_cc_data(int cc_valid, cea708_cc_type_t type, uint16_t cc_data);
  56. /*! \brief
  57. \param
  58. */
  59. int cea708_cc_count(user_data_t* data);
  60. /*! \brief
  61. \param
  62. */
  63. uint16_t cea708_cc_data(user_data_t* data, int index, int* valid, cea708_cc_type_t* type);
  64. ////////////////////////////////////////////////////////////////////////////////
  65. typedef enum {
  66. country_united_states = 181,
  67. } itu_t_t35_country_code_t;
  68. typedef enum {
  69. t35_provider_direct_tv = 47,
  70. t35_provider_atsc = 49,
  71. } itu_t_t35_provider_code_t;
  72. typedef struct {
  73. itu_t_t35_country_code_t country;
  74. itu_t_t35_provider_code_t provider;
  75. uint32_t user_identifier;
  76. uint8_t user_data_type_code;
  77. uint8_t directv_user_data_length;
  78. user_data_t user_data;
  79. double timestamp;
  80. } cea708_t;
  81. static const uint32_t GA94 = (('G' << 24) | ('A' << 16) | ('9' << 8) | '4');
  82. static const uint32_t DTG1 = (('D' << 24) | ('T' << 16) | ('G' << 8) | '1');
  83. /*! \brief
  84. \param
  85. */
  86. int cea708_init(cea708_t* cea708, double timestamp); // will confgure using HLS compatiable defaults
  87. /*! \brief
  88. \param
  89. */
  90. libcaption_stauts_t cea708_parse_h264(const uint8_t* data, size_t size, cea708_t* cea708);
  91. /*! \brief
  92. \param
  93. */
  94. libcaption_stauts_t cea708_parse_h262(const uint8_t* data, size_t size, cea708_t* cea708);
  95. /*! \brief
  96. \param
  97. */
  98. libcaption_stauts_t cea708_to_caption_frame(caption_frame_t* frame, cea708_t* cea708);
  99. /*! \brief
  100. \param
  101. */
  102. int cea708_add_cc_data(cea708_t* cea708, int valid, cea708_cc_type_t type, uint16_t cc_data);
  103. /*! \brief
  104. \param
  105. */
  106. int cea708_render(cea708_t* cea708, uint8_t* data, size_t size);
  107. /*! \brief
  108. \param
  109. */
  110. void cea708_dump(cea708_t* cea708);
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. #endif