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.

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