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.

63 lines
1.9KB

  1. /*
  2. * SSA/ASS decoder
  3. * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; 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. #include "ass.h"
  23. static av_cold int ass_decode_init(AVCodecContext *avctx)
  24. {
  25. avctx->subtitle_header = av_malloc(avctx->extradata_size);
  26. if (!avctx->extradata)
  27. return AVERROR(ENOMEM);
  28. memcpy(avctx->subtitle_header, avctx->extradata, avctx->extradata_size);
  29. avctx->subtitle_header_size = avctx->extradata_size;
  30. return 0;
  31. }
  32. static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
  33. AVPacket *avpkt)
  34. {
  35. const char *ptr = avpkt->data;
  36. int len, size = avpkt->size;
  37. ff_ass_init(data);
  38. while (size > 0) {
  39. len = ff_ass_add_rect(data, ptr, 0, 0/* FIXME: duration */, 1);
  40. if (len < 0)
  41. return len;
  42. ptr += len;
  43. size -= len;
  44. }
  45. *got_sub_ptr = avpkt->size > 0;
  46. return avpkt->size;
  47. }
  48. AVCodec ff_ass_decoder = {
  49. .name = "ass",
  50. .long_name = NULL_IF_CONFIG_SMALL("Advanced SubStation Alpha subtitle"),
  51. .type = AVMEDIA_TYPE_SUBTITLE,
  52. .id = CODEC_ID_SSA,
  53. .init = ass_decode_init,
  54. .decode = ass_decode_frame,
  55. };