You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.5KB

  1. /*
  2. * DVD subtitle decoding for ffmpeg
  3. * Copyright (c) 2005 Fabrice Bellard.
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "avcodec.h"
  22. /* parser definition */
  23. typedef struct DVDSubParseContext {
  24. uint8_t *packet;
  25. int packet_len;
  26. int packet_index;
  27. } DVDSubParseContext;
  28. static int dvdsub_parse_init(AVCodecParserContext *s)
  29. {
  30. return 0;
  31. }
  32. static int dvdsub_parse(AVCodecParserContext *s,
  33. AVCodecContext *avctx,
  34. const uint8_t **poutbuf, int *poutbuf_size,
  35. const uint8_t *buf, int buf_size)
  36. {
  37. DVDSubParseContext *pc = s->priv_data;
  38. if (pc->packet_index == 0) {
  39. if (buf_size < 2)
  40. return 0;
  41. pc->packet_len = AV_RB16(buf);
  42. if (pc->packet_len == 0) /* HD-DVD subpicture packet */
  43. pc->packet_len = AV_RB32(buf+2);
  44. av_freep(&pc->packet);
  45. pc->packet = av_malloc(pc->packet_len);
  46. }
  47. if (pc->packet) {
  48. if (pc->packet_index + buf_size <= pc->packet_len) {
  49. memcpy(pc->packet + pc->packet_index, buf, buf_size);
  50. pc->packet_index += buf_size;
  51. if (pc->packet_index >= pc->packet_len) {
  52. *poutbuf = pc->packet;
  53. *poutbuf_size = pc->packet_len;
  54. pc->packet_index = 0;
  55. return buf_size;
  56. }
  57. } else {
  58. /* erroneous size */
  59. pc->packet_index = 0;
  60. }
  61. }
  62. *poutbuf = NULL;
  63. *poutbuf_size = 0;
  64. return buf_size;
  65. }
  66. static void dvdsub_parse_close(AVCodecParserContext *s)
  67. {
  68. DVDSubParseContext *pc = s->priv_data;
  69. av_freep(&pc->packet);
  70. }
  71. AVCodecParser dvdsub_parser = {
  72. { CODEC_ID_DVD_SUBTITLE },
  73. sizeof(DVDSubParseContext),
  74. dvdsub_parse_init,
  75. dvdsub_parse,
  76. dvdsub_parse_close,
  77. };