cvct_section.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * section and descriptor parser
  3. *
  4. * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
  5. * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  20. */
  21. #include <libucsi/atsc/cvct_section.h>
  22. struct atsc_cvct_section *atsc_cvct_section_codec(struct atsc_section_psip *psip)
  23. {
  24. uint8_t * buf = (uint8_t *) psip;
  25. size_t pos = sizeof(struct atsc_section_psip);
  26. size_t len = section_ext_length(&(psip->ext_head));
  27. int idx;
  28. if (len < sizeof(struct atsc_cvct_section))
  29. return NULL;
  30. struct atsc_cvct_section *cvct = (struct atsc_cvct_section *) psip;
  31. pos++;
  32. for(idx =0; idx < cvct->num_channels_in_section; idx++) {
  33. if ((pos + sizeof(struct atsc_cvct_channel)) > len)
  34. return NULL;
  35. struct atsc_cvct_channel *channel = (struct atsc_cvct_channel *) (buf+pos);
  36. pos += 7*2;
  37. bswap32(buf+pos);
  38. bswap32(buf+pos+4);
  39. bswap16(buf+pos+8);
  40. bswap16(buf+pos+10);
  41. bswap16(buf+pos+12);
  42. bswap16(buf+pos+14);
  43. bswap16(buf+pos+16);
  44. pos+=18;
  45. if ((pos + channel->descriptors_length) > len)
  46. return NULL;
  47. if (verify_descriptors(buf + pos, channel->descriptors_length))
  48. return NULL;
  49. pos += channel->descriptors_length;
  50. }
  51. if ((pos + sizeof(struct atsc_cvct_section_part2)) > len)
  52. return NULL;
  53. struct atsc_cvct_section_part2 *part2 = (struct atsc_cvct_section_part2 *) (buf+pos);
  54. bswap16(buf+pos);
  55. pos+=2;
  56. if ((pos + part2->descriptors_length) > len)
  57. return NULL;
  58. if (verify_descriptors(buf + pos, part2->descriptors_length))
  59. return NULL;
  60. pos += part2->descriptors_length;
  61. if (pos != len)
  62. return NULL;
  63. return (struct atsc_cvct_section *) psip;
  64. }