oggparseskeleton.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2010 David Conrad
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavcodec/bytestream.h"
  21. #include "avformat.h"
  22. #include "internal.h"
  23. #include "oggdec.h"
  24. static int skeleton_header(AVFormatContext *s, int idx)
  25. {
  26. struct ogg *ogg = s->priv_data;
  27. struct ogg_stream *os = ogg->streams + idx;
  28. AVStream *st = s->streams[idx];
  29. uint8_t *buf = os->buf + os->pstart;
  30. int version_major, version_minor;
  31. int64_t start_num, start_den;
  32. uint64_t start_granule;
  33. int target_idx, start_time;
  34. strcpy(st->codec->codec_name, "skeleton");
  35. st->codec->codec_type = AVMEDIA_TYPE_DATA;
  36. if ((os->flags & OGG_FLAG_EOS) && os->psize == 0)
  37. return 1;
  38. if (os->psize < 8)
  39. return -1;
  40. if (!strncmp(buf, "fishead", 8)) {
  41. if (os->psize < 64)
  42. return -1;
  43. version_major = AV_RL16(buf+8);
  44. version_minor = AV_RL16(buf+10);
  45. if (version_major != 3 && version_major != 4) {
  46. av_log(s, AV_LOG_WARNING, "Unknown skeleton version %d.%d\n",
  47. version_major, version_minor);
  48. return -1;
  49. }
  50. // This is the overall start time. We use it for the start time of
  51. // of the skeleton stream since if left unset lavf assumes 0,
  52. // which we don't want since skeleton is timeless
  53. // FIXME: the real meaning of this field is "start playback at
  54. // this time which can be in the middle of a packet
  55. start_num = AV_RL64(buf+12);
  56. start_den = AV_RL64(buf+20);
  57. if (start_den) {
  58. int base_den;
  59. av_reduce(&start_time, &base_den, start_num, start_den, INT_MAX);
  60. avpriv_set_pts_info(st, 64, 1, base_den);
  61. os->lastpts =
  62. st->start_time = start_time;
  63. }
  64. } else if (!strncmp(buf, "fisbone", 8)) {
  65. if (os->psize < 52)
  66. return -1;
  67. target_idx = ogg_find_stream(ogg, AV_RL32(buf+12));
  68. start_granule = AV_RL64(buf+36);
  69. if (target_idx < 0) {
  70. av_log(s, AV_LOG_WARNING, "Serial number in fisbone doesn't match any stream\n");
  71. return 1;
  72. }
  73. os = ogg->streams + target_idx;
  74. if (os->start_granule != OGG_NOGRANULE_VALUE) {
  75. av_log(s, AV_LOG_WARNING, "Multiple fisbone for the same stream\n");
  76. return 1;
  77. }
  78. if (start_granule != OGG_NOGRANULE_VALUE) {
  79. os->start_granule = start_granule;
  80. }
  81. }
  82. return 1;
  83. }
  84. const struct ogg_codec ff_skeleton_codec = {
  85. .magic = "fishead",
  86. .magicsize = 8,
  87. .header = skeleton_header,
  88. .nb_header = 0,
  89. };