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.

117 lines
3.4KB

  1. /*
  2. * DVD navigation block parser for FFmpeg
  3. * Copyright (c) 2013 The FFmpeg Project
  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. #include "dsputil.h"
  23. #include "get_bits.h"
  24. #include "parser.h"
  25. #define PCI_SIZE 980
  26. #define DSI_SIZE 1018
  27. /* parser definition */
  28. typedef struct DVDNavParseContext {
  29. uint32_t lba;
  30. uint8_t buffer[PCI_SIZE+DSI_SIZE];
  31. int copied;
  32. } DVDNavParseContext;
  33. static av_cold int dvd_nav_parse_init(AVCodecParserContext *s)
  34. {
  35. DVDNavParseContext *pc = s->priv_data;
  36. pc->lba = 0xFFFFFFFF;
  37. pc->copied = 0;
  38. return 0;
  39. }
  40. static int dvd_nav_parse(AVCodecParserContext *s,
  41. AVCodecContext *avctx,
  42. const uint8_t **poutbuf, int *poutbuf_size,
  43. const uint8_t *buf, int buf_size)
  44. {
  45. DVDNavParseContext *pc1 = s->priv_data;
  46. int lastPacket = 0;
  47. int valid = 0;
  48. s->pict_type = AV_PICTURE_TYPE_NONE;
  49. avctx->time_base.num = 1;
  50. avctx->time_base.den = 90000;
  51. if (buf && buf_size) {
  52. switch(buf[0]) {
  53. case 0x00:
  54. if (buf_size == PCI_SIZE) {
  55. /* PCI */
  56. uint32_t lba = AV_RB32(&buf[0x01]);
  57. uint32_t startpts = AV_RB32(&buf[0x0D]);
  58. uint32_t endpts = AV_RB32(&buf[0x11]);
  59. if (endpts > startpts) {
  60. pc1->lba = lba;
  61. s->pts = (int64_t)startpts;
  62. s->duration = endpts - startpts;
  63. memcpy(pc1->buffer, buf, PCI_SIZE);
  64. pc1->copied = PCI_SIZE;
  65. valid = 1;
  66. }
  67. }
  68. break;
  69. case 0x01:
  70. if ((buf_size == DSI_SIZE) && (pc1->copied == PCI_SIZE)) {
  71. /* DSI */
  72. uint32_t lba = AV_RB32(&buf[0x05]);
  73. if (lba == pc1->lba) {
  74. memcpy(pc1->buffer + pc1->copied, buf, DSI_SIZE);
  75. lastPacket = 1;
  76. valid = 1;
  77. }
  78. }
  79. break;
  80. }
  81. }
  82. if (!valid || lastPacket) {
  83. pc1->copied = 0;
  84. pc1->lba = 0xFFFFFFFF;
  85. }
  86. if (lastPacket) {
  87. *poutbuf = pc1->buffer;
  88. *poutbuf_size = sizeof(pc1->buffer);
  89. } else {
  90. *poutbuf = NULL;
  91. *poutbuf_size = 0;
  92. }
  93. return buf_size;
  94. }
  95. AVCodecParser ff_dvd_nav_parser = {
  96. .codec_ids = { AV_CODEC_ID_DVD_NAV },
  97. .priv_data_size = sizeof(DVDNavParseContext),
  98. .parser_init = dvd_nav_parse_init,
  99. .parser_parse = dvd_nav_parse,
  100. };