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.

129 lines
3.7KB

  1. /*
  2. * Constants for DV codec
  3. * Copyright (c) 2002 Fabrice Bellard
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * Constants for DV codec.
  24. */
  25. #ifndef AVCODEC_DV_H
  26. #define AVCODEC_DV_H
  27. #include "avcodec.h"
  28. #include "dv_profile.h"
  29. #include "me_cmp.h"
  30. #include "vlc.h"
  31. typedef struct DVwork_chunk {
  32. uint16_t buf_offset;
  33. uint16_t mb_coordinates[5];
  34. } DVwork_chunk;
  35. typedef struct DVVideoContext {
  36. const AVDVProfile *sys;
  37. const AVFrame *frame;
  38. AVCodecContext *avctx;
  39. uint8_t *buf;
  40. uint8_t dv_zigzag[2][64];
  41. void (*get_pixels)(int16_t *block, const uint8_t *pixels, ptrdiff_t linesize);
  42. void (*fdct[2])(int16_t *block);
  43. void (*idct_put[2])(uint8_t *dest, ptrdiff_t stride, int16_t *block);
  44. me_cmp_func ildct_cmp;
  45. DVwork_chunk work_chunks[4 * 12 * 27];
  46. uint32_t idct_factor[2 * 4 * 16 * 64];
  47. } DVVideoContext;
  48. enum dv_section_type {
  49. dv_sect_header = 0x1f,
  50. dv_sect_subcode = 0x3f,
  51. dv_sect_vaux = 0x56,
  52. dv_sect_audio = 0x76,
  53. dv_sect_video = 0x96,
  54. };
  55. enum dv_pack_type {
  56. dv_header525 = 0x3f, /* see dv_write_pack for important details on */
  57. dv_header625 = 0xbf, /* these two packs */
  58. dv_timecode = 0x13,
  59. dv_audio_source = 0x50,
  60. dv_audio_control = 0x51,
  61. dv_audio_recdate = 0x52,
  62. dv_audio_rectime = 0x53,
  63. dv_video_source = 0x60,
  64. dv_video_control = 0x61,
  65. dv_video_recdate = 0x62,
  66. dv_video_rectime = 0x63,
  67. dv_unknown_pack = 0xff,
  68. };
  69. #define DV_PROFILE_IS_HD(p) ((p)->video_stype & 0x10)
  70. #define DV_PROFILE_IS_1080i50(p) (((p)->video_stype == 0x14) && ((p)->dsf == 1))
  71. #define DV_PROFILE_IS_720p50(p) (((p)->video_stype == 0x18) && ((p)->dsf == 1))
  72. /* minimum number of bytes to read from a DV stream in order to
  73. * determine the profile */
  74. #define DV_PROFILE_BYTES (6 * 80) /* 6 DIF blocks */
  75. /**
  76. * largest possible DV frame, in bytes (1080i50)
  77. */
  78. #define DV_MAX_FRAME_SIZE 576000
  79. /**
  80. * maximum number of blocks per macroblock in any DV format
  81. */
  82. #define DV_MAX_BPM 8
  83. #define TEX_VLC_BITS 9
  84. extern RL_VLC_ELEM ff_dv_rl_vlc[1184];
  85. int ff_dv_init_dynamic_tables(DVVideoContext *s, const AVDVProfile *d);
  86. int ff_dvvideo_init(AVCodecContext *avctx);
  87. static inline int dv_work_pool_size(const AVDVProfile *d)
  88. {
  89. int size = d->n_difchan * d->difseg_size * 27;
  90. if (DV_PROFILE_IS_1080i50(d))
  91. size -= 3 * 27;
  92. if (DV_PROFILE_IS_720p50(d))
  93. size -= 4 * 27;
  94. return size;
  95. }
  96. static inline void dv_calculate_mb_xy(DVVideoContext *s,
  97. DVwork_chunk *work_chunk,
  98. int m, int *mb_x, int *mb_y)
  99. {
  100. *mb_x = work_chunk->mb_coordinates[m] & 0xff;
  101. *mb_y = work_chunk->mb_coordinates[m] >> 8;
  102. /* We work with 720p frames split in half.
  103. * The odd half-frame (chan == 2,3) is displaced :-( */
  104. if (s->sys->height == 720 && !(s->buf[1] & 0x0C))
  105. /* shifting the Y coordinate down by 72/2 macro blocks */
  106. *mb_y -= (*mb_y > 17) ? 18 : -72;
  107. }
  108. #endif /* AVCODEC_DV_H */