xiph.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (C) 2007 FFmpeg Project
  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 "xiph.h"
  21. int ff_split_xiph_headers(uint8_t *extradata, int extradata_size,
  22. int first_header_size, uint8_t *header_start[3],
  23. int header_len[3])
  24. {
  25. int i, j;
  26. if (AV_RB16(extradata) == first_header_size) {
  27. for (i=0; i<3; i++) {
  28. header_len[i] = AV_RB16(extradata);
  29. extradata += 2;
  30. header_start[i] = extradata;
  31. extradata += header_len[i];
  32. }
  33. } else if (extradata[0] == 2) {
  34. for (i=0,j=1; i<2; i++,j++) {
  35. header_len[i] = 0;
  36. for (; j<extradata_size && extradata[j]==0xff; j++) {
  37. header_len[i] += 0xff;
  38. }
  39. if (j >= extradata_size)
  40. return -1;
  41. header_len[i] += extradata[j];
  42. }
  43. header_len[2] = extradata_size - header_len[0] - header_len[1] - j;
  44. extradata += j;
  45. header_start[0] = extradata;
  46. header_start[1] = header_start[0] + header_len[0];
  47. header_start[2] = header_start[1] + header_len[1];
  48. } else {
  49. return -1;
  50. }
  51. return 0;
  52. }