PageRenderTime 61ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/dvb/si/desc_5b.h

http://github.com/gfto/bitstream
C Header | 148 lines | 97 code | 17 blank | 34 comment | 9 complexity | 9feb9e3f1eecdeca7e61c040e0a9a9e1 MD5 | raw file
  1. /*****************************************************************************
  2. * desc_5b.h: ETSI EN 300 468 Descriptor 0x5b: Multilingual network name
  3. *****************************************************************************
  4. * Copyright (C) 2009-2010 VideoLAN
  5. *
  6. * Authors: Christophe Massiot <massiot@via.ecp.fr>
  7. * Georgi Chorbadzhiyski <georgi@unixsol.org>
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining
  10. * a copy of this software and associated documentation files (the
  11. * "Software"), to deal in the Software without restriction, including
  12. * without limitation the rights to use, copy, modify, merge, publish,
  13. * distribute, sublicense, and/or sell copies of the Software, and to
  14. * permit persons to whom the Software is furnished to do so, subject
  15. * to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be
  18. * included in all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  23. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  24. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. *****************************************************************************/
  28. /*
  29. * Normative references:
  30. * - ETSI EN 300 468 V1.11.1 (2010-04) (SI in DVB systems)
  31. */
  32. #ifndef __BITSTREAM_DVB_DESC_5B_H__
  33. #define __BITSTREAM_DVB_DESC_5B_H__
  34. #include <bitstream/common.h>
  35. #include <bitstream/mpeg/psi/descriptors.h>
  36. #include <bitstream/mpeg/psi/desc_0a.h>
  37. #include <bitstream/dvb/si/strings.h>
  38. #ifdef __cplusplus
  39. extern "C"
  40. {
  41. #endif
  42. /*****************************************************************************
  43. * Descriptor 0x5b: Multilingual network name
  44. *****************************************************************************/
  45. #define DESC5B_HEADER_SIZE DESC_HEADER_SIZE
  46. #define DESC5B_DATA_SIZE 4
  47. static inline void desc5b_init(uint8_t *p_desc)
  48. {
  49. desc_set_tag(p_desc, 0x5b);
  50. }
  51. #define desc5bn_set_code desc0an_set_code
  52. #define desc5bn_get_code desc0an_get_code
  53. static inline uint8_t desc5bn_get_networkname_length(const uint8_t *p_desc_n)
  54. {
  55. return p_desc_n[3];
  56. }
  57. static inline const uint8_t *desc5bn_get_networkname(const uint8_t *p_desc_n, uint8_t *pi_length)
  58. {
  59. *pi_length = desc5bn_get_networkname_length(p_desc_n);
  60. return p_desc_n + 4;
  61. }
  62. static inline void desc5bn_set_networkname(uint8_t *p_desc_n, const uint8_t *p_network_name, uint8_t i_length)
  63. {
  64. p_desc_n[3] = i_length;
  65. memcpy(p_desc_n + 4, p_network_name, i_length);
  66. }
  67. static inline uint8_t *desc5b_get_data(const uint8_t *p_desc, uint8_t n)
  68. {
  69. const uint8_t *p_desc_n = p_desc + DESC5B_HEADER_SIZE;
  70. uint8_t i_desc_size = desc_get_length(p_desc);
  71. while (n) {
  72. if (p_desc_n + DESC5B_DATA_SIZE - p_desc > i_desc_size)
  73. return NULL;
  74. p_desc_n += DESC5B_DATA_SIZE + desc5bn_get_networkname_length(p_desc_n);
  75. n--;
  76. }
  77. if (p_desc_n - p_desc > i_desc_size)
  78. return NULL;
  79. return (uint8_t *)p_desc_n;
  80. }
  81. static inline bool desc5b_validate(const uint8_t *p_desc)
  82. {
  83. const uint8_t *p_desc_n = p_desc + DESC5B_HEADER_SIZE;
  84. int i_desc_size = desc_get_length(p_desc);
  85. while (i_desc_size > 0)
  86. {
  87. uint8_t i_data_sz = DESC5B_DATA_SIZE + desc5bn_get_networkname_length(p_desc_n);
  88. i_desc_size -= i_data_sz;
  89. p_desc_n += i_data_sz;
  90. }
  91. return i_desc_size == 0;
  92. }
  93. static inline void desc5b_print(const uint8_t *p_desc,
  94. f_print pf_print, void *print_opaque,
  95. f_iconv pf_iconv, void *iconv_opaque,
  96. print_type_t i_print_type)
  97. {
  98. const uint8_t *p_desc_n;
  99. bool b_bouquet = desc_get_tag(p_desc) == 0x5c;
  100. uint8_t j = 0;
  101. while ((p_desc_n = desc5b_get_data(p_desc, j++)) != NULL) {
  102. uint8_t i_network_name_length;
  103. const uint8_t *p_network_name = desc5bn_get_networkname(p_desc_n, &i_network_name_length);
  104. char *psz_network_name = dvb_string_get(p_network_name, i_network_name_length, pf_iconv, iconv_opaque);
  105. switch (i_print_type) {
  106. case PRINT_XML:
  107. psz_network_name = dvb_string_xml_escape(psz_network_name);
  108. pf_print(print_opaque,
  109. !b_bouquet
  110. ? "<MULTILINGUAL_NETWORK_NAME_DESC code=\"%3.3s\" networkname=\"%s\"/>"
  111. : "<MULTILINGUAL_BOUQUET_NAME_DESC code=\"%3.3s\" bouquetname=\"%s\"/>",
  112. desc5bn_get_code(p_desc_n),
  113. psz_network_name
  114. );
  115. break;
  116. default:
  117. pf_print(print_opaque,
  118. !b_bouquet
  119. ? " - desc 5b multilingual_network_name code=\"%3.3s\" networkname=\"%s\""
  120. : " - desc 5c multilingual_bouquet_name code=\"%3.3s\" bouquetname=\"%s\"",
  121. desc5bn_get_code(p_desc_n),
  122. psz_network_name
  123. );
  124. }
  125. free(psz_network_name);
  126. }
  127. }
  128. #ifdef __cplusplus
  129. }
  130. #endif
  131. #endif