vc1_common.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * VC-1 and WMV3 decoder
  3. * Copyright (c) 2006-2007 Konstantin Shishkov
  4. * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVCODEC_VC1_COMMON_H
  23. #define AVCODEC_VC1_COMMON_H
  24. #include <stdint.h>
  25. #include "libavutil/attributes.h"
  26. #include "internal.h"
  27. /** Markers used in VC-1 AP frame data */
  28. //@{
  29. enum VC1Code {
  30. VC1_CODE_RES0 = 0x00000100,
  31. VC1_CODE_ENDOFSEQ = 0x0000010A,
  32. VC1_CODE_SLICE,
  33. VC1_CODE_FIELD,
  34. VC1_CODE_FRAME,
  35. VC1_CODE_ENTRYPOINT,
  36. VC1_CODE_SEQHDR,
  37. };
  38. //@}
  39. #define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0)
  40. /** Available Profiles */
  41. //@{
  42. enum Profile {
  43. PROFILE_SIMPLE,
  44. PROFILE_MAIN,
  45. PROFILE_COMPLEX, ///< TODO: WMV9 specific
  46. PROFILE_ADVANCED
  47. };
  48. //@}
  49. /** Find VC-1 marker in buffer
  50. * @return position where next marker starts or end of buffer if no marker found
  51. */
  52. static av_always_inline const uint8_t* find_next_marker(const uint8_t *src, const uint8_t *end)
  53. {
  54. if (end - src >= 4) {
  55. uint32_t mrk = 0xFFFFFFFF;
  56. src = avpriv_find_start_code(src, end, &mrk);
  57. if (IS_MARKER(mrk))
  58. return src - 4;
  59. }
  60. return end;
  61. }
  62. static av_always_inline int vc1_unescape_buffer(const uint8_t *src, int size, uint8_t *dst)
  63. {
  64. int dsize = 0, i;
  65. if (size < 4) {
  66. for (dsize = 0; dsize < size; dsize++)
  67. *dst++ = *src++;
  68. return size;
  69. }
  70. for (i = 0; i < size; i++, src++) {
  71. if (src[0] == 3 && i >= 2 && !src[-1] && !src[-2] && i < size-1 && src[1] < 4) {
  72. dst[dsize++] = src[1];
  73. src++;
  74. i++;
  75. } else
  76. dst[dsize++] = *src;
  77. }
  78. return dsize;
  79. }
  80. #endif /* AVCODEC_VC1_COMMON_H */