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.

165 lines
5.9KB

  1. /*
  2. * Constants for DV codec
  3. * Copyright (c) 2002 Fabrice Bellard
  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. /**
  22. * @file
  23. * Constants for DV codec.
  24. */
  25. #ifndef AVCODEC_DVDATA_H
  26. #define AVCODEC_DVDATA_H
  27. #include "libavutil/rational.h"
  28. #include "avcodec.h"
  29. #include "dsputil.h"
  30. #include "get_bits.h"
  31. typedef struct DVwork_chunk {
  32. uint16_t buf_offset;
  33. uint16_t mb_coordinates[5];
  34. } DVwork_chunk;
  35. /*
  36. * DVprofile is used to express the differences between various
  37. * DV flavors. For now it's primarily used for differentiating
  38. * 525/60 and 625/50, but the plans are to use it for various
  39. * DV specs as well (e.g. SMPTE314M vs. IEC 61834).
  40. */
  41. typedef struct DVprofile {
  42. int dsf; /* value of the dsf in the DV header */
  43. int video_stype; /* stype for VAUX source pack */
  44. int frame_size; /* total size of one frame in bytes */
  45. int difseg_size; /* number of DIF segments per DIF channel */
  46. int n_difchan; /* number of DIF channels per frame */
  47. AVRational time_base; /* 1/framerate */
  48. int ltc_divisor; /* FPS from the LTS standpoint */
  49. int height; /* picture height in pixels */
  50. int width; /* picture width in pixels */
  51. AVRational sar[2]; /* sample aspect ratios for 4:3 and 16:9 */
  52. DVwork_chunk *work_chunks; /* each thread gets its own chunk of frame to work on */
  53. uint32_t *idct_factor; /* set of iDCT factor tables */
  54. enum PixelFormat pix_fmt; /* picture pixel format */
  55. int bpm; /* blocks per macroblock */
  56. const uint8_t *block_sizes; /* AC block sizes, in bits */
  57. int audio_stride; /* size of audio_shuffle table */
  58. int audio_min_samples[3]; /* min amount of audio samples */
  59. /* for 48kHz, 44.1kHz and 32kHz */
  60. int audio_samples_dist[5]; /* how many samples are supposed to be */
  61. /* in each frame in a 5 frames window */
  62. const uint8_t (*audio_shuffle)[9]; /* PCM shuffling table */
  63. } DVprofile;
  64. typedef struct DVVideoContext {
  65. const DVprofile *sys;
  66. AVFrame picture;
  67. AVCodecContext *avctx;
  68. uint8_t *buf;
  69. uint8_t dv_zigzag[2][64];
  70. void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size);
  71. void (*fdct[2])(DCTELEM *block);
  72. void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block);
  73. me_cmp_func ildct_cmp;
  74. } DVVideoContext;
  75. enum dv_section_type {
  76. dv_sect_header = 0x1f,
  77. dv_sect_subcode = 0x3f,
  78. dv_sect_vaux = 0x56,
  79. dv_sect_audio = 0x76,
  80. dv_sect_video = 0x96,
  81. };
  82. enum dv_pack_type {
  83. dv_header525 = 0x3f, /* see dv_write_pack for important details on */
  84. dv_header625 = 0xbf, /* these two packs */
  85. dv_timecode = 0x13,
  86. dv_audio_source = 0x50,
  87. dv_audio_control = 0x51,
  88. dv_audio_recdate = 0x52,
  89. dv_audio_rectime = 0x53,
  90. dv_video_source = 0x60,
  91. dv_video_control = 0x61,
  92. dv_video_recdate = 0x62,
  93. dv_video_rectime = 0x63,
  94. dv_unknown_pack = 0xff,
  95. };
  96. #define DV_PROFILE_IS_HD(p) ((p)->video_stype & 0x10)
  97. #define DV_PROFILE_IS_1080i50(p) (((p)->video_stype == 0x14) && ((p)->dsf == 1))
  98. #define DV_PROFILE_IS_720p50(p) (((p)->video_stype == 0x18) && ((p)->dsf == 1))
  99. /* minimum number of bytes to read from a DV stream in order to
  100. determine the profile */
  101. #define DV_PROFILE_BYTES (6*80) /* 6 DIF blocks */
  102. /**
  103. * largest possible DV frame, in bytes (1080i50)
  104. */
  105. #define DV_MAX_FRAME_SIZE 576000
  106. /**
  107. * maximum number of blocks per macroblock in any DV format
  108. */
  109. #define DV_MAX_BPM 8
  110. #define TEX_VLC_BITS 9
  111. extern RL_VLC_ELEM ff_dv_rl_vlc[1184];
  112. const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
  113. const uint8_t* frame, unsigned buf_size);
  114. const DVprofile* avpriv_dv_frame_profile2(AVCodecContext* codec, const DVprofile *sys,
  115. const uint8_t* frame, unsigned buf_size);
  116. const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec);
  117. int ff_dv_init_dynamic_tables(const DVprofile *d);
  118. int ff_dvvideo_init(AVCodecContext *avctx);
  119. static inline int dv_work_pool_size(const DVprofile *d)
  120. {
  121. int size = d->n_difchan*d->difseg_size*27;
  122. if (DV_PROFILE_IS_1080i50(d))
  123. size -= 3*27;
  124. if (DV_PROFILE_IS_720p50(d))
  125. size -= 4*27;
  126. return size;
  127. }
  128. static inline void dv_calculate_mb_xy(DVVideoContext *s, DVwork_chunk *work_chunk, int m, int *mb_x, int *mb_y)
  129. {
  130. *mb_x = work_chunk->mb_coordinates[m] & 0xff;
  131. *mb_y = work_chunk->mb_coordinates[m] >> 8;
  132. /* We work with 720p frames split in half. The odd half-frame (chan==2,3) is displaced :-( */
  133. if (s->sys->height == 720 && !(s->buf[1]&0x0C)) {
  134. *mb_y -= (*mb_y>17)?18:-72; /* shifting the Y coordinate down by 72/2 macro blocks */
  135. }
  136. }
  137. /**
  138. * Print all allowed DV profiles into logctx at specified logging level.
  139. */
  140. void ff_dv_print_profiles(void *logctx, int loglevel);
  141. #endif /* AVCODEC_DVDATA_H */