1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-15 14:13:16 +02:00

dv: K&R formatting cosmetics

Signed-off-by: Diego Biurrun <diego@biurrun.de>
This commit is contained in:
Gabriel Dume
2014-09-08 13:40:28 -04:00
committed by Diego Biurrun
parent f629705b02
commit ee0ebd3c14
7 changed files with 1017 additions and 977 deletions

View File

@@ -40,19 +40,20 @@
#include "libavutil/internal.h" #include "libavutil/internal.h"
#include "libavutil/pixdesc.h" #include "libavutil/pixdesc.h"
#include "avcodec.h" #include "avcodec.h"
#include "dv.h"
#include "dvdata.h"
#include "get_bits.h" #include "get_bits.h"
#include "internal.h" #include "internal.h"
#include "put_bits.h" #include "put_bits.h"
#include "simple_idct.h" #include "simple_idct.h"
#include "dvdata.h"
#include "dv.h"
/* XXX: also include quantization */ /* XXX: also include quantization */
RL_VLC_ELEM ff_dv_rl_vlc[1184]; RL_VLC_ELEM ff_dv_rl_vlc[1184];
static inline void dv_calc_mb_coordinates(const AVDVProfile *d, int chan, int seq, int slot, static inline void dv_calc_mb_coordinates(const AVDVProfile *d, int chan,
uint16_t *tbl) int seq, int slot, uint16_t *tbl)
{ {
static const uint8_t off[] = { 2, 6, 8, 0, 4 }; static const uint8_t off[] = { 2, 6, 8, 0, 4 };
static const uint8_t shuf1[] = { 36, 18, 54, 0, 72 }; static const uint8_t shuf1[] = { 36, 18, 54, 0, 72 };
@@ -62,16 +63,21 @@ static inline void dv_calc_mb_coordinates(const AVDVProfile *d, int chan, int se
static const uint8_t l_start[] = { 0, 4, 9, 13, 18, 22, 27, 31, 36, 40 }; static const uint8_t l_start[] = { 0, 4, 9, 13, 18, 22, 27, 31, 36, 40 };
static const uint8_t l_start_shuffled[] = { 9, 4, 13, 0, 18 }; static const uint8_t l_start_shuffled[] = { 9, 4, 13, 0, 18 };
static const uint8_t serpent1[] = {0, 1, 2, 2, 1, 0, static const uint8_t serpent1[] = {
0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0,
0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0,
0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0,
0, 1, 2}; 0, 1, 2, 2, 1, 0,
static const uint8_t serpent2[] = {0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 0, 1, 2
};
static const uint8_t serpent2[] = {
0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0,
0, 1, 2, 3, 4, 5}; 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0,
0, 1, 2, 3, 4, 5
};
static const uint8_t remap[][2] = {{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, /* dummy */ static const uint8_t remap[][2] = {
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, /* dummy */
{ 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 }, { 10, 0 }, { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 }, { 10, 0 },
{ 10, 1 }, { 10, 2 }, { 10, 3 }, { 20, 0 }, { 20, 1 }, { 10, 1 }, { 10, 2 }, { 10, 3 }, { 20, 0 }, { 20, 1 },
{ 20, 2 }, { 20, 3 }, { 30, 0 }, { 30, 1 }, { 30, 2 }, { 20, 2 }, { 20, 3 }, { 30, 0 }, { 30, 1 }, { 30, 2 },
@@ -83,7 +89,8 @@ static inline void dv_calc_mb_coordinates(const AVDVProfile *d, int chan, int se
{ 20, 66 }, { 30, 64 }, { 30, 65 }, { 30, 66 }, { 40, 64 }, { 20, 66 }, { 30, 64 }, { 30, 65 }, { 30, 66 }, { 40, 64 },
{ 40, 65 }, { 40, 66 }, { 50, 64 }, { 50, 65 }, { 50, 66 }, { 40, 65 }, { 40, 66 }, { 50, 64 }, { 50, 65 }, { 50, 66 },
{ 60, 64 }, { 60, 65 }, { 60, 66 }, { 70, 64 }, { 70, 65 }, { 60, 64 }, { 60, 65 }, { 60, 66 }, { 70, 64 }, { 70, 65 },
{70,66}, { 0,67}, {20,67}, {40,67}, {60,67}}; { 70, 66 }, { 0, 67 }, { 20, 67 }, { 40, 67 }, { 60, 67 }
};
int i, k, m; int i, k, m;
int x, y, blk; int x, y, blk;
@@ -267,9 +274,9 @@ av_cold int ff_dvvideo_init(AVCodecContext *avctx)
} }
/* NOTE: as a trick, we use the fact the no codes are unused /* NOTE: as a trick, we use the fact the no codes are unused
to accelerate the parsing of partial codes */ * to accelerate the parsing of partial codes */
init_vlc(&dv_vlc, TEX_VLC_BITS, j, init_vlc(&dv_vlc, TEX_VLC_BITS, j, new_dv_vlc_len,
new_dv_vlc_len, 1, 1, new_dv_vlc_bits, 2, 2, 0); 1, 1, new_dv_vlc_bits, 2, 2, 0);
assert(dv_vlc.table_size == 1184); assert(dv_vlc.table_size == 1184);
for (i = 0; i < dv_vlc.table_size; i++) { for (i = 0; i < dv_vlc.table_size; i++) {

View File

@@ -28,9 +28,9 @@
#define AVCODEC_DV_H #define AVCODEC_DV_H
#include "avcodec.h" #include "avcodec.h"
#include "me_cmp.h"
#include "get_bits.h"
#include "dv_profile.h" #include "dv_profile.h"
#include "get_bits.h"
#include "me_cmp.h"
typedef struct DVwork_chunk { typedef struct DVwork_chunk {
uint16_t buf_offset; uint16_t buf_offset;
@@ -81,7 +81,7 @@ enum dv_pack_type {
#define DV_PROFILE_IS_720p50(p) (((p)->video_stype == 0x18) && ((p)->dsf == 1)) #define DV_PROFILE_IS_720p50(p) (((p)->video_stype == 0x18) && ((p)->dsf == 1))
/* minimum number of bytes to read from a DV stream in order to /* minimum number of bytes to read from a DV stream in order to
determine the profile */ * determine the profile */
#define DV_PROFILE_BYTES (6 * 80) /* 6 DIF blocks */ #define DV_PROFILE_BYTES (6 * 80) /* 6 DIF blocks */
/** /**
@@ -111,15 +111,18 @@ static inline int dv_work_pool_size(const AVDVProfile *d)
return size; return size;
} }
static inline void dv_calculate_mb_xy(DVVideoContext *s, DVwork_chunk *work_chunk, int m, int *mb_x, int *mb_y) static inline void dv_calculate_mb_xy(DVVideoContext *s,
DVwork_chunk *work_chunk,
int m, int *mb_x, int *mb_y)
{ {
*mb_x = work_chunk->mb_coordinates[m] & 0xff; *mb_x = work_chunk->mb_coordinates[m] & 0xff;
*mb_y = work_chunk->mb_coordinates[m] >> 8; *mb_y = work_chunk->mb_coordinates[m] >> 8;
/* We work with 720p frames split in half. The odd half-frame (chan==2,3) is displaced :-( */ /* We work with 720p frames split in half.
if (s->sys->height == 720 && !(s->buf[1]&0x0C)) { * The odd half-frame (chan == 2,3) is displaced :-( */
*mb_y -= (*mb_y>17)?18:-72; /* shifting the Y coordinate down by 72/2 macro blocks */ if (s->sys->height == 720 && !(s->buf[1] & 0x0C))
} /* shifting the Y coordinate down by 72/2 macro blocks */
*mb_y -= (*mb_y > 17) ? 18 : -72;
} }
#endif /* AVCODEC_DV_H */ #endif /* AVCODEC_DV_H */

View File

@@ -16,13 +16,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <stdint.h>
#include "config.h" #include "config.h"
#include <stdint.h>
#include "libavutil/common.h" #include "libavutil/common.h"
#include "libavutil/log.h" #include "libavutil/log.h"
#include "libavutil/pixdesc.h" #include "libavutil/pixdesc.h"
#include "avcodec.h" #include "avcodec.h"
#include "dv_profile.h" #include "dv_profile.h"
#include "dv_profile_internal.h" #include "dv_profile_internal.h"
@@ -85,8 +86,7 @@ static const AVDVProfile dv_profiles[] = {
.audio_stride = 90, .audio_stride = 90,
.audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */ .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */ .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
.audio_shuffle = dv_audio_shuffle525, .audio_shuffle = dv_audio_shuffle525, },
},
{ .dsf = 1, { .dsf = 1,
.video_stype = 0x0, .video_stype = 0x0,
.frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */ .frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */
@@ -103,8 +103,7 @@ static const AVDVProfile dv_profiles[] = {
.audio_stride = 108, .audio_stride = 108,
.audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
.audio_shuffle = dv_audio_shuffle625, .audio_shuffle = dv_audio_shuffle625, },
},
{ .dsf = 1, { .dsf = 1,
.video_stype = 0x0, .video_stype = 0x0,
.frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */ .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */
@@ -121,8 +120,7 @@ static const AVDVProfile dv_profiles[] = {
.audio_stride = 108, .audio_stride = 108,
.audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
.audio_shuffle = dv_audio_shuffle625, .audio_shuffle = dv_audio_shuffle625, },
},
{ .dsf = 0, { .dsf = 0,
.video_stype = 0x4, .video_stype = 0x4,
.frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */ .frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
@@ -139,8 +137,7 @@ static const AVDVProfile dv_profiles[] = {
.audio_stride = 90, .audio_stride = 90,
.audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */ .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */ .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
.audio_shuffle = dv_audio_shuffle525, .audio_shuffle = dv_audio_shuffle525, },
},
{ .dsf = 1, { .dsf = 1,
.video_stype = 0x4, .video_stype = 0x4,
.frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */ .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
@@ -157,8 +154,7 @@ static const AVDVProfile dv_profiles[] = {
.audio_stride = 108, .audio_stride = 108,
.audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
.audio_shuffle = dv_audio_shuffle625, .audio_shuffle = dv_audio_shuffle625, },
},
{ .dsf = 0, { .dsf = 0,
.video_stype = 0x14, .video_stype = 0x14,
.frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */ .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */
@@ -175,8 +171,7 @@ static const AVDVProfile dv_profiles[] = {
.audio_stride = 90, .audio_stride = 90,
.audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */ .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */ .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
.audio_shuffle = dv_audio_shuffle525, .audio_shuffle = dv_audio_shuffle525, },
},
{ .dsf = 1, { .dsf = 1,
.video_stype = 0x14, .video_stype = 0x14,
.frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */ .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */
@@ -193,8 +188,7 @@ static const AVDVProfile dv_profiles[] = {
.audio_stride = 108, .audio_stride = 108,
.audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
.audio_shuffle = dv_audio_shuffle625, .audio_shuffle = dv_audio_shuffle625, },
},
{ .dsf = 0, { .dsf = 0,
.video_stype = 0x18, .video_stype = 0x18,
.frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */ .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */
@@ -211,8 +205,7 @@ static const AVDVProfile dv_profiles[] = {
.audio_stride = 90, .audio_stride = 90,
.audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */ .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */ .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
.audio_shuffle = dv_audio_shuffle525, .audio_shuffle = dv_audio_shuffle525, },
},
{ .dsf = 1, { .dsf = 1,
.video_stype = 0x18, .video_stype = 0x18,
.frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */ .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */
@@ -229,8 +222,7 @@ static const AVDVProfile dv_profiles[] = {
.audio_stride = 90, .audio_stride = 90,
.audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
.audio_shuffle = dv_audio_shuffle625, .audio_shuffle = dv_audio_shuffle625, },
},
{ .dsf = 1, { .dsf = 1,
.video_stype = 0x1, .video_stype = 0x1,
.frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */ .frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */
@@ -247,8 +239,7 @@ static const AVDVProfile dv_profiles[] = {
.audio_stride = 108, .audio_stride = 108,
.audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
.audio_shuffle = dv_audio_shuffle625, .audio_shuffle = dv_audio_shuffle625, }
}
}; };
void ff_dv_print_profiles(void *logctx, int loglevel) void ff_dv_print_profiles(void *logctx, int loglevel)
@@ -256,8 +247,9 @@ void ff_dv_print_profiles(void *logctx, int loglevel)
int i; int i;
for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++) { for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++) {
const AVDVProfile *p = &dv_profiles[i]; const AVDVProfile *p = &dv_profiles[i];
av_log(logctx, loglevel, "Frame size: %dx%d; pixel format: %s, " av_log(logctx, loglevel,
"framerate: %d/%d\n", p->width, p->height, av_get_pix_fmt_name(p->pix_fmt), "Frame size: %dx%d; pixel format: %s, framerate: %d/%d\n",
p->width, p->height, av_get_pix_fmt_name(p->pix_fmt),
p->time_base.den, p->time_base.num); p->time_base.den, p->time_base.num);
} }
} }
@@ -277,9 +269,8 @@ const AVDVProfile *av_dv_frame_profile(const AVDVProfile *sys,
stype = frame[80 * 5 + 48 + 3] & 0x1f; stype = frame[80 * 5 + 48 + 3] & 0x1f;
/* 576i50 25Mbps 4:1:1 is a special case */ /* 576i50 25Mbps 4:1:1 is a special case */
if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) { if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */)
return &dv_profiles[2]; return &dv_profiles[2];
}
for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++) for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++)
if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype) if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)

View File

@@ -71,7 +71,8 @@ static void dv_vlc_map_tableinit(void)
for (j = 1; j < DV_VLC_MAP_LEV_SIZE; j++) { for (j = 1; j < DV_VLC_MAP_LEV_SIZE; j++) {
if (dv_vlc_map[i][j].size == 0) { if (dv_vlc_map[i][j].size == 0) {
dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc | dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc |
(dv_vlc_map[i-1][0].vlc << (dv_vlc_map[0][j].size)); (dv_vlc_map[i - 1][0].vlc <<
dv_vlc_map[0][j].size);
dv_vlc_map[i][j].size = dv_vlc_map[i - 1][0].size + dv_vlc_map[i][j].size = dv_vlc_map[i - 1][0].size +
dv_vlc_map[0][j].size; dv_vlc_map[0][j].size;
} }
@@ -80,14 +81,13 @@ static void dv_vlc_map_tableinit(void)
for (j = 1; j < DV_VLC_MAP_LEV_SIZE / 2; j++) { for (j = 1; j < DV_VLC_MAP_LEV_SIZE / 2; j++) {
if (dv_vlc_map[i][j].size == 0) { if (dv_vlc_map[i][j].size == 0) {
dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc | dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc |
(dv_vlc_map[i-1][0].vlc << (dv_vlc_map[0][j].size)); (dv_vlc_map[i - 1][0].vlc <<
dv_vlc_map[0][j].size);
dv_vlc_map[i][j].size = dv_vlc_map[i - 1][0].size + dv_vlc_map[i][j].size = dv_vlc_map[i - 1][0].size +
dv_vlc_map[0][j].size; dv_vlc_map[0][j].size;
} }
dv_vlc_map[i][((uint16_t)(-j))&0x1ff].vlc = dv_vlc_map[i][((uint16_t) (-j)) & 0x1ff].vlc = dv_vlc_map[i][j].vlc | 1;
dv_vlc_map[i][j].vlc | 1; dv_vlc_map[i][((uint16_t) (-j)) & 0x1ff].size = dv_vlc_map[i][j].size;
dv_vlc_map[i][((uint16_t)(-j))&0x1ff].size =
dv_vlc_map[i][j].size;
} }
#endif #endif
} }

View File

@@ -35,17 +35,18 @@
* DV decoder * DV decoder
*/ */
#include "libavutil/internal.h"
#include "libavutil/imgutils.h" #include "libavutil/imgutils.h"
#include "libavutil/internal.h"
#include "libavutil/pixdesc.h" #include "libavutil/pixdesc.h"
#include "avcodec.h" #include "avcodec.h"
#include "dv.h"
#include "dvdata.h"
#include "get_bits.h"
#include "idctdsp.h" #include "idctdsp.h"
#include "internal.h" #include "internal.h"
#include "get_bits.h"
#include "put_bits.h" #include "put_bits.h"
#include "simple_idct.h" #include "simple_idct.h"
#include "dvdata.h"
#include "dv.h"
typedef struct BlockInfo { typedef struct BlockInfo {
const uint32_t *factor_table; const uint32_t *factor_table;
@@ -93,7 +94,8 @@ static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, int16_t *block)
/* if we must parse a partial VLC, we do it here */ /* if we must parse a partial VLC, we do it here */
if (partial_bit_count > 0) { if (partial_bit_count > 0) {
re_cache = re_cache >> partial_bit_count | mb->partial_bit_buffer; re_cache = re_cache >> partial_bit_count |
mb->partial_bit_buffer;
re_index -= partial_bit_count; re_index -= partial_bit_count;
mb->partial_bit_count = 0; mb->partial_bit_count = 0;
} }
@@ -128,7 +130,8 @@ static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, int16_t *block)
if (pos >= 64) if (pos >= 64)
break; break;
level = (level * factor_table[pos] + (1 << (dv_iweight_bits - 1))) >> dv_iweight_bits; level = (level * factor_table[pos] + (1 << (dv_iweight_bits - 1))) >>
dv_iweight_bits;
block[scan_table[pos]] = level; block[scan_table[pos]] = level;
UPDATE_CACHE(re, gb); UPDATE_CACHE(re, gb);
@@ -144,10 +147,9 @@ static inline void bit_copy(PutBitContext *pb, GetBitContext *gb)
put_bits(pb, MIN_CACHE_BITS, get_bits(gb, MIN_CACHE_BITS)); put_bits(pb, MIN_CACHE_BITS, get_bits(gb, MIN_CACHE_BITS));
bits_left -= MIN_CACHE_BITS; bits_left -= MIN_CACHE_BITS;
} }
if (bits_left > 0) { if (bits_left > 0)
put_bits(pb, bits_left, get_bits(gb, bits_left)); put_bits(pb, bits_left, get_bits(gb, bits_left));
} }
}
/* mb_x and mb_y are in units of 8 pixels */ /* mb_x and mb_y are in units of 8 pixels */
static int dv_decode_video_segment(AVCodecContext *avctx, void *arg) static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
@@ -166,7 +168,7 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
BlockInfo mb_data[5 * DV_MAX_BPM], *mb, *mb1; BlockInfo mb_data[5 * DV_MAX_BPM], *mb, *mb1;
LOCAL_ALIGNED_16(int16_t, sblock, [5 * DV_MAX_BPM], [64]); LOCAL_ALIGNED_16(int16_t, sblock, [5 * DV_MAX_BPM], [64]);
LOCAL_ALIGNED_16(uint8_t, mb_bit_buffer, [80 + FF_INPUT_BUFFER_PADDING_SIZE]); /* allow some slack */ LOCAL_ALIGNED_16(uint8_t, mb_bit_buffer, [80 + FF_INPUT_BUFFER_PADDING_SIZE]); /* allow some slack */
LOCAL_ALIGNED_16(uint8_t, vs_bit_buffer, [5*80 + FF_INPUT_BUFFER_PADDING_SIZE]); /* allow some slack */ LOCAL_ALIGNED_16(uint8_t, vs_bit_buffer, [80 * 5 + FF_INPUT_BUFFER_PADDING_SIZE]); /* allow some slack */
const int log2_blocksize = 3; const int log2_blocksize = 3;
int is_field_mode[5]; int is_field_mode[5];
@@ -199,17 +201,21 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
if (DV_PROFILE_IS_HD(s->sys)) { if (DV_PROFILE_IS_HD(s->sys)) {
mb->idct_put = s->idct_put[0]; mb->idct_put = s->idct_put[0];
mb->scan_table = s->dv_zigzag[0]; mb->scan_table = s->dv_zigzag[0];
mb->factor_table = &s->idct_factor[(j >= 4)*4*16*64 + class1*16*64 + quant*64]; mb->factor_table = &s->idct_factor[(j >= 4) * 4 * 16 * 64 +
class1 * 16 * 64 +
quant * 64];
is_field_mode[mb_index] |= !j && dct_mode; is_field_mode[mb_index] |= !j && dct_mode;
} else { } else {
mb->idct_put = s->idct_put[dct_mode && log2_blocksize == 3]; mb->idct_put = s->idct_put[dct_mode && log2_blocksize == 3];
mb->scan_table = s->dv_zigzag[dct_mode]; mb->scan_table = s->dv_zigzag[dct_mode];
mb->factor_table = &s->idct_factor[(class1 == 3)*2*22*64 + dct_mode*22*64 + mb->factor_table =
&s->idct_factor[(class1 == 3) * 2 * 22 * 64 +
dct_mode * 22 * 64 +
(quant + ff_dv_quant_offset[class1]) * 64]; (quant + ff_dv_quant_offset[class1]) * 64];
} }
dc = dc << 2; dc = dc << 2;
/* convert to unsigned because 128 is not added in the /* convert to unsigned because 128 is not added in the
standard IDCT */ * standard IDCT */
dc += 1024; dc += 1024;
block[0] = dc; block[0] = dc;
buf_ptr += last_index >> 3; buf_ptr += last_index >> 3;
@@ -220,7 +226,7 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
dv_decode_ac(&gb, mb, block); dv_decode_ac(&gb, mb, block);
/* write the remaining bits in a new buffer only if the /* write the remaining bits in a new buffer only if the
block is finished */ * block is finished */
if (mb->pos >= 64) if (mb->pos >= 64)
bit_copy(&pb, &gb); bit_copy(&pb, &gb);
@@ -244,7 +250,7 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
} }
} }
/* all blocks are finished, so the extra bytes can be used at /* all blocks are finished, so the extra bytes can be used at
the video segment level */ * the video segment level */
if (j >= s->sys->bpm) if (j >= s->sys->bpm)
bit_copy(&vs_pb, &gb); bit_copy(&vs_pb, &gb);
} }
@@ -263,7 +269,8 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
dv_decode_ac(&gb, mb, block); dv_decode_ac(&gb, mb, block);
} }
if (mb->pos >= 64 && mb->pos < 127) if (mb->pos >= 64 && mb->pos < 127)
av_log(avctx, AV_LOG_ERROR, "AC EOB marker is absent pos=%d\n", mb->pos); av_log(avctx, AV_LOG_ERROR,
"AC EOB marker is absent pos=%d\n", mb->pos);
block += 64; block += 64;
mb++; mb++;
} }
@@ -279,11 +286,13 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
if ((s->sys->pix_fmt == AV_PIX_FMT_YUV420P) || if ((s->sys->pix_fmt == AV_PIX_FMT_YUV420P) ||
(s->sys->pix_fmt == AV_PIX_FMT_YUV411P && mb_x >= (704 / 8)) || (s->sys->pix_fmt == AV_PIX_FMT_YUV411P && mb_x >= (704 / 8)) ||
(s->sys->height >= 720 && mb_y != 134)) { (s->sys->height >= 720 && mb_y != 134)) {
y_stride = (s->frame->linesize[0] << ((!is_field_mode[mb_index]) * log2_blocksize)); y_stride = (s->frame->linesize[0] <<
((!is_field_mode[mb_index]) * log2_blocksize));
} else { } else {
y_stride = (2 << log2_blocksize); y_stride = (2 << log2_blocksize);
} }
y_ptr = s->frame->data[0] + ((mb_y * s->frame->linesize[0] + mb_x) << log2_blocksize); y_ptr = s->frame->data[0] +
((mb_y * s->frame->linesize[0] + mb_x) << log2_blocksize);
linesize = s->frame->linesize[0] << is_field_mode[mb_index]; linesize = s->frame->linesize[0] << is_field_mode[mb_index];
mb[0].idct_put(y_ptr, linesize, block + 0 * 64); mb[0].idct_put(y_ptr, linesize, block + 0 * 64);
if (s->sys->video_stype == 4) { /* SD 422 */ if (s->sys->video_stype == 4) { /* SD 422 */
@@ -315,14 +324,17 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
c_ptr1[x] = ptr1[x]; c_ptr1[x] = ptr1[x];
} }
} }
block += 64; mb++; block += 64;
mb++;
} else { } else {
y_stride = (mb_y == 134) ? (1 << log2_blocksize) : y_stride = (mb_y == 134) ? (1 << log2_blocksize) :
s->frame->linesize[j] << ((!is_field_mode[mb_index]) * log2_blocksize); s->frame->linesize[j] << ((!is_field_mode[mb_index]) * log2_blocksize);
linesize = s->frame->linesize[j] << is_field_mode[mb_index]; linesize = s->frame->linesize[j] << is_field_mode[mb_index];
(mb++)-> idct_put(c_ptr , linesize, block); block += 64; (mb++)->idct_put(c_ptr, linesize, block);
block += 64;
if (s->sys->bpm == 8) { if (s->sys->bpm == 8) {
(mb++)->idct_put(c_ptr + y_stride, linesize, block); block += 64; (mb++)->idct_put(c_ptr + y_stride, linesize, block);
block += 64;
} }
} }
} }
@@ -331,10 +343,9 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
} }
/* NOTE: exactly one frame must be given (120000 bytes for NTSC, /* NOTE: exactly one frame must be given (120000 bytes for NTSC,
144000 bytes for PAL - or twice those for 50Mbps) */ * 144000 bytes for PAL - or twice those for 50Mbps) */
static int dvvideo_decode_frame(AVCodecContext *avctx, static int dvvideo_decode_frame(AVCodecContext *avctx, void *data,
void *data, int *got_frame, int *got_frame, AVPacket *avpkt)
AVPacket *avpkt)
{ {
uint8_t *buf = avpkt->data; uint8_t *buf = avpkt->data;
int buf_size = avpkt->size; int buf_size = avpkt->size;
@@ -372,7 +383,8 @@ static int dvvideo_decode_frame(AVCodecContext *avctx,
vsc_pack = buf + 80 * 5 + 48 + 5; vsc_pack = buf + 80 * 5 + 48 + 5;
if (*vsc_pack == dv_video_control) { if (*vsc_pack == dv_video_control) {
apt = buf[4] & 0x07; apt = buf[4] & 0x07;
is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 || (!apt && (vsc_pack[2] & 0x07) == 0x07))); is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 ||
(!apt && (vsc_pack[2] & 0x07) == 0x07)));
ff_set_sar(avctx, s->sys->sar[is16_9]); ff_set_sar(avctx, s->sys->sar[is16_9]);
} }

View File

@@ -24,18 +24,20 @@
* DV encoder * DV encoder
*/ */
#include "config.h"
#include "libavutil/attributes.h" #include "libavutil/attributes.h"
#include "libavutil/pixdesc.h" #include "libavutil/pixdesc.h"
#include "config.h"
#include "avcodec.h" #include "avcodec.h"
#include "dv.h"
#include "dv_profile_internal.h"
#include "dv_tablegen.h"
#include "fdctdsp.h" #include "fdctdsp.h"
#include "internal.h" #include "internal.h"
#include "me_cmp.h" #include "me_cmp.h"
#include "pixblockdsp.h" #include "pixblockdsp.h"
#include "put_bits.h" #include "put_bits.h"
#include "dv.h"
#include "dv_tablegen.h"
#include "dv_profile_internal.h"
static av_cold int dvvideo_encode_init(AVCodecContext *avctx) static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
{ {
@@ -84,15 +86,15 @@ static const int vs_total_ac_bits = (100 * 4 + 68*2) * 5;
static const int mb_area_start[5] = { 1, 6, 21, 43, 64 }; static const int mb_area_start[5] = { 1, 6, 21, 43, 64 };
#if CONFIG_SMALL #if CONFIG_SMALL
/* Converts run and level (where level != 0) pair into VLC, returning bit size */ /* Convert run and level (where level != 0) pair into VLC, returning bit size */
static av_always_inline int dv_rl2vlc(int run, int level, int sign, uint32_t* vlc) static av_always_inline int dv_rl2vlc(int run, int level, int sign,
uint32_t *vlc)
{ {
int size; int size;
if (run < DV_VLC_MAP_RUN_SIZE && level < DV_VLC_MAP_LEV_SIZE) { if (run < DV_VLC_MAP_RUN_SIZE && level < DV_VLC_MAP_LEV_SIZE) {
*vlc = dv_vlc_map[run][level].vlc | sign; *vlc = dv_vlc_map[run][level].vlc | sign;
size = dv_vlc_map[run][level].size; size = dv_vlc_map[run][level].size;
} } else {
else {
if (level < DV_VLC_MAP_LEV_SIZE) { if (level < DV_VLC_MAP_LEV_SIZE) {
*vlc = dv_vlc_map[0][level].vlc | sign; *vlc = dv_vlc_map[0][level].vlc | sign;
size = dv_vlc_map[0][level].size; size = dv_vlc_map[0][level].size;
@@ -116,13 +118,11 @@ static av_always_inline int dv_rl2vlc_size(int run, int level)
if (run < DV_VLC_MAP_RUN_SIZE && level < DV_VLC_MAP_LEV_SIZE) { if (run < DV_VLC_MAP_RUN_SIZE && level < DV_VLC_MAP_LEV_SIZE) {
size = dv_vlc_map[run][level].size; size = dv_vlc_map[run][level].size;
} } else {
else {
size = (level < DV_VLC_MAP_LEV_SIZE) ? dv_vlc_map[0][level].size : 16; size = (level < DV_VLC_MAP_LEV_SIZE) ? dv_vlc_map[0][level].size : 16;
if (run) { if (run)
size += (run < 16) ? dv_vlc_map[run - 1][0].size : 13; size += (run < 16) ? dv_vlc_map[run - 1][0].size : 13;
} }
}
return size; return size;
} }
#else #else
@@ -161,7 +161,8 @@ static av_always_inline PutBitContext* dv_encode_ac(EncBlockInfo* bi,
int size = bi->partial_bit_count; int size = bi->partial_bit_count;
uint32_t vlc = bi->partial_bit_buffer; uint32_t vlc = bi->partial_bit_buffer;
bi->partial_bit_count = bi->partial_bit_buffer = 0; bi->partial_bit_count =
bi->partial_bit_buffer = 0;
for (;;) { for (;;) {
/* Find suitable storage space */ /* Find suitable storage space */
for (; size > (bits_left = put_bits_left(pb)); pb++) { for (; size > (bits_left = put_bits_left(pb)); pb++) {
@@ -187,15 +188,19 @@ static av_always_inline PutBitContext* dv_encode_ac(EncBlockInfo* bi,
prev = bi->cur_ac; prev = bi->cur_ac;
bi->cur_ac = bi->next[prev]; bi->cur_ac = bi->next[prev];
if (bi->cur_ac < 64) { if (bi->cur_ac < 64) {
size = dv_rl2vlc(bi->cur_ac - prev - 1, bi->mb[bi->cur_ac], bi->sign[bi->cur_ac], &vlc); size = dv_rl2vlc(bi->cur_ac - prev - 1, bi->mb[bi->cur_ac],
bi->sign[bi->cur_ac], &vlc);
} else { } else {
size = 4; vlc = 6; /* End Of Block stamp */ size = 4;
vlc = 6; /* End Of Block stamp */
} }
} }
return pb; return pb;
} }
static av_always_inline int dv_guess_dct_mode(DVVideoContext *s, uint8_t *data, int linesize) { static av_always_inline int dv_guess_dct_mode(DVVideoContext *s, uint8_t *data,
int linesize)
{
if (s->avctx->flags & CODEC_FLAG_INTERLACED_DCT) { if (s->avctx->flags & CODEC_FLAG_INTERLACED_DCT) {
int ps = s->ildct_cmp(NULL, data, NULL, linesize, 8) - 400; int ps = s->ildct_cmp(NULL, data, NULL, linesize, 8) - 400;
if (ps > 0) { if (ps > 0) {
@@ -230,21 +235,23 @@ static const int dv_weight_248[64] = {
195068, 170627, 175557, 153560, 188995, 174609, 165371, 144651, 195068, 170627, 175557, 153560, 188995, 174609, 165371, 144651,
}; };
static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, int linesize, DVVideoContext *s, int bias) static av_always_inline int dv_init_enc_block(EncBlockInfo *bi, uint8_t *data,
int linesize, DVVideoContext *s,
int bias)
{ {
const int *weight; const int *weight;
const uint8_t *zigzag_scan; const uint8_t *zigzag_scan;
LOCAL_ALIGNED_16(int16_t, blk, [64]); LOCAL_ALIGNED_16(int16_t, blk, [64]);
int i, area; int i, area;
/* We offer two different methods for class number assignment: the /* We offer two different methods for class number assignment: the
method suggested in SMPTE 314M Table 22, and an improved * method suggested in SMPTE 314M Table 22, and an improved
method. The SMPTE method is very conservative; it assigns class * method. The SMPTE method is very conservative; it assigns class
3 (i.e. severe quantization) to any block where the largest AC * 3 (i.e. severe quantization) to any block where the largest AC
component is greater than 36. Libav's DV encoder tracks AC bit * component is greater than 36. Libav's DV encoder tracks AC bit
consumption precisely, so there is no need to bias most blocks * consumption precisely, so there is no need to bias most blocks
towards strongly lossy compression. Instead, we assign class 2 * towards strongly lossy compression. Instead, we assign class 2
to most blocks, and use class 3 only when strictly necessary * to most blocks, and use class 3 only when strictly necessary
(for blocks whose largest AC component exceeds 255). */ * (for blocks whose largest AC component exceeds 255). */
#if 0 /* SMPTE spec method */ #if 0 /* SMPTE spec method */
static const int classes[] = { 12, 24, 36, 0xffff }; static const int classes[] = { 12, 24, 36, 0xffff };
@@ -256,7 +263,10 @@ static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, i
assert((((int) blk) & 15) == 0); assert((((int) blk) & 15) == 0);
bi->area_q[0] = bi->area_q[1] = bi->area_q[2] = bi->area_q[3] = 0; bi->area_q[0] =
bi->area_q[1] =
bi->area_q[2] =
bi->area_q[3] = 0;
bi->partial_bit_count = 0; bi->partial_bit_count = 0;
bi->partial_bit_buffer = 0; bi->partial_bit_buffer = 0;
bi->cur_ac = 0; bi->cur_ac = 0;
@@ -265,8 +275,9 @@ static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, i
s->get_pixels(blk, data, linesize); s->get_pixels(blk, data, linesize);
s->fdct[bi->dct_mode](blk); s->fdct[bi->dct_mode](blk);
} else { } else {
/* We rely on the fact that encoding all zeros leads to an immediate EOB, /* We rely on the fact that encoding all zeros leads to an immediate
which is precisely what the spec calls for in the "dummy" blocks. */ * EOB, which is precisely what the spec calls for in the "dummy"
* blocks. */
memset(blk, 0, 64 * sizeof(*blk)); memset(blk, 0, 64 * sizeof(*blk));
bi->dct_mode = 0; bi->dct_mode = 0;
} }
@@ -283,10 +294,11 @@ static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, i
if (level + 15 > 30U) { if (level + 15 > 30U) {
bi->sign[i] = (level >> 31) & 1; bi->sign[i] = (level >> 31) & 1;
/* weight it and and shift down into range, adding for rounding */ /* Weight it and and shift down into range, adding for rounding.
/* the extra division by a factor of 2^4 reverses the 8x expansion of the DCT * The extra division by a factor of 2^4 reverses the 8x
AND the 2x doubling of the weights */ * expansion of the DCT AND the 2x doubling of the weights. */
level = (FFABS(level) * weight[i] + (1 << (dv_weight_bits+3))) >> (dv_weight_bits+4); level = (FFABS(level) * weight[i] + (1 << (dv_weight_bits + 3))) >>
(dv_weight_bits + 4);
bi->mb[i] = level; bi->mb[i] = level;
if (level > max) if (level > max)
max = level; max = level;
@@ -297,7 +309,8 @@ static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, i
} }
} }
bi->next[prev] = i; bi->next[prev] = i;
for (bi->cno = 0; max > classes[bi->cno]; bi->cno++); for (bi->cno = 0; max > classes[bi->cno]; bi->cno++)
;
bi->cno += bias; bi->cno += bias;
@@ -321,7 +334,8 @@ static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, i
bi->next[prev] = i; bi->next[prev] = i;
} }
return bi->bit_size[0] + bi->bit_size[1] + bi->bit_size[2] + bi->bit_size[3]; return bi->bit_size[0] + bi->bit_size[1] +
bi->bit_size[2] + bi->bit_size[3];
} }
static inline void dv_guess_qnos(EncBlockInfo *blks, int *qnos) static inline void dv_guess_qnos(EncBlockInfo *blks, int *qnos)
@@ -330,7 +344,11 @@ static inline void dv_guess_qnos(EncBlockInfo* blks, int* qnos)
int i, j, k, a, prev, a2; int i, j, k, a, prev, a2;
EncBlockInfo *b; EncBlockInfo *b;
size[0] = size[1] = size[2] = size[3] = size[4] = 1 << 24; size[0] =
size[1] =
size[2] =
size[3] =
size[4] = 1 << 24;
do { do {
b = blks; b = blks;
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
@@ -357,8 +375,8 @@ static inline void dv_guess_qnos(EncBlockInfo* blks, int* qnos)
b->prev[a2] = prev; b->prev[a2] = prev;
assert(a2 < 4); assert(a2 < 4);
assert(b->mb[b->next[k]]); assert(b->mb[b->next[k]]);
b->bit_size[a2] += dv_rl2vlc_size(b->next[k] - prev - 1, b->mb[b->next[k]]) b->bit_size[a2] += dv_rl2vlc_size(b->next[k] - prev - 1, b->mb[b->next[k]]) -
-dv_rl2vlc_size(b->next[k] - k - 1, b->mb[b->next[k]]); dv_rl2vlc_size(b->next[k] - k - 1, b->mb[b->next[k]]);
assert(b->prev[a2] == k && (a2 + 1 >= 4 || b->prev[a2 + 1] != k)); assert(b->prev[a2] == k && (a2 + 1 >= 4 || b->prev[a2 + 1] != k));
b->prev[a2] = prev; b->prev[a2] = prev;
} }
@@ -375,7 +393,6 @@ static inline void dv_guess_qnos(EncBlockInfo* blks, int* qnos)
} }
} while (qnos[0] | qnos[1] | qnos[2] | qnos[3] | qnos[4]); } while (qnos[0] | qnos[1] | qnos[2] | qnos[3] | qnos[4]);
for (a = 2; a == 2 || vs_total_ac_bits < size[0]; a += a) { for (a = 2; a == 2 || vs_total_ac_bits < size[0]; a += a) {
b = blks; b = blks;
size[0] = 5 * 6 * 4; // EOB size[0] = 5 * 6 * 4; // EOB
@@ -423,7 +440,8 @@ static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
} else { } else {
y_stride = 16; y_stride = 16;
} }
y_ptr = s->frame->data[0] + ((mb_y * s->frame->linesize[0] + mb_x) << 3); y_ptr = s->frame->data[0] +
((mb_y * s->frame->linesize[0] + mb_x) << 3);
linesize = s->frame->linesize[0]; linesize = s->frame->linesize[0];
if (s->sys->video_stype == 4) { /* SD 422 */ if (s->sys->video_stype == 4) { /* SD 422 */
@@ -453,8 +471,14 @@ static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
uint8_t *b = scratch; uint8_t *b = scratch;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
d = c_ptr + (linesize << 3); d = c_ptr + (linesize << 3);
b[0] = c_ptr[0]; b[1] = c_ptr[1]; b[2] = c_ptr[2]; b[3] = c_ptr[3]; b[0] = c_ptr[0];
b[4] = d[0]; b[5] = d[1]; b[6] = d[2]; b[7] = d[3]; b[1] = c_ptr[1];
b[2] = c_ptr[2];
b[3] = c_ptr[3];
b[4] = d[0];
b[5] = d[1];
b[6] = d[2];
b[7] = d[3];
c_ptr += linesize; c_ptr += linesize;
b += 16; b += 16;
} }
@@ -463,9 +487,9 @@ static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
} }
vs_bit_size += dv_init_enc_block(enc_blk++, c_ptr, linesize, s, 1); vs_bit_size += dv_init_enc_block(enc_blk++, c_ptr, linesize, s, 1);
if (s->sys->bpm == 8) { if (s->sys->bpm == 8)
vs_bit_size += dv_init_enc_block(enc_blk++, c_ptr + y_stride, linesize, s, 1); vs_bit_size += dv_init_enc_block(enc_blk++, c_ptr + y_stride,
} linesize, s, 1);
} }
} }
@@ -494,10 +518,10 @@ static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
/* Second pass over each MB space */ /* Second pass over each MB space */
pb = &pbs[start_mb]; pb = &pbs[start_mb];
for (i=0; i<s->sys->bpm; i++) { for (i = 0; i < s->sys->bpm; i++)
if (enc_blks[start_mb + i].partial_bit_count) if (enc_blks[start_mb + i].partial_bit_count)
pb = dv_encode_ac(&enc_blks[start_mb+i], pb, &pbs[start_mb+s->sys->bpm]); pb = dv_encode_ac(&enc_blks[start_mb + i], pb,
} &pbs[start_mb + s->sys->bpm]);
} }
/* Third and final pass over the whole video segment space */ /* Third and final pass over the whole video segment space */
@@ -515,7 +539,8 @@ static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
flush_put_bits(&pbs[j]); flush_put_bits(&pbs[j]);
pos = put_bits_count(&pbs[j]) >> 3; pos = put_bits_count(&pbs[j]) >> 3;
if (pos > size) { if (pos > size) {
av_log(avctx, AV_LOG_ERROR, "bitstream written beyond buffer size\n"); av_log(avctx, AV_LOG_ERROR,
"bitstream written beyond buffer size\n");
return -1; return -1;
} }
memset(pbs[j].buf + pos, 0xff, size - pos); memset(pbs[j].buf + pos, 0xff, size - pos);
@@ -548,7 +573,8 @@ static inline int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c,
int apt = (c->sys->pix_fmt == AV_PIX_FMT_YUV420P ? 0 : 1); int apt = (c->sys->pix_fmt == AV_PIX_FMT_YUV420P ? 0 : 1);
uint8_t aspect = 0; uint8_t aspect = 0;
if ((int)(av_q2d(c->avctx->sample_aspect_ratio) * c->avctx->width / c->avctx->height * 10) >= 17) /* 16:9 */ if ((int) (av_q2d(c->avctx->sample_aspect_ratio) *
c->avctx->width / c->avctx->height * 10) >= 17) /* 16:9 */
aspect = 0x02; aspect = 0x02;
buf[0] = (uint8_t) pack_id; buf[0] = (uint8_t) pack_id;
@@ -591,7 +617,10 @@ static inline int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c,
buf[4] = 0xff; /* reserved -- always 1 */ buf[4] = 0xff; /* reserved -- always 1 */
break; break;
default: default:
buf[1] = buf[2] = buf[3] = buf[4] = 0xff; buf[1] =
buf[2] =
buf[3] =
buf[4] = 0xff;
} }
return 5; return 5;
} }
@@ -608,19 +637,16 @@ static inline int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num,
return 3; return 3;
} }
static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t *buf) static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t *buf)
{ {
if (syb_num == 0 || syb_num == 6) { if (syb_num == 0 || syb_num == 6) {
buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */ buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */
(0 << 4) | /* AP3 (Subcode application ID) */ (0 << 4) | /* AP3 (Subcode application ID) */
0x0f; /* reserved -- always 1 */ 0x0f; /* reserved -- always 1 */
} } else if (syb_num == 11) {
else if (syb_num == 11) {
buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */ buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */
0x7f; /* reserved -- always 1 */ 0x7f; /* reserved -- always 1 */
} } else {
else {
buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */ buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */
(0 << 4) | /* APT (Track application ID) */ (0 << 4) | /* APT (Track application ID) */
0x0f; /* reserved -- always 1 */ 0x0f; /* reserved -- always 1 */
@@ -641,7 +667,8 @@ static void dv_format_frame(DVVideoContext* c, uint8_t* buf)
/* DV header: 1DIF */ /* DV header: 1DIF */
buf += dv_write_dif_id(dv_sect_header, chan, i, 0, buf); buf += dv_write_dif_id(dv_sect_header, chan, i, 0, buf);
buf += dv_write_pack((c->sys->dsf ? dv_header625 : dv_header525), c, buf); buf += dv_write_pack((c->sys->dsf ? dv_header625 : dv_header525),
c, buf);
buf += 72; /* unused bytes */ buf += 72; /* unused bytes */
/* DV subcode: 2DIFs */ /* DV subcode: 2DIFs */
@@ -672,15 +699,14 @@ static void dv_format_frame(DVVideoContext* c, uint8_t* buf)
} }
buf += dv_write_dif_id(dv_sect_video, chan, i, j, buf); buf += dv_write_dif_id(dv_sect_video, chan, i, j, buf);
buf += 77; /* 1 video macroblock: 1 bytes control buf += 77; /* 1 video macroblock: 1 bytes control
4 * 14 bytes Y 8x8 data * 4 * 14 bytes Y 8x8 data
10 bytes Cr 8x8 data * 10 bytes Cr 8x8 data
10 bytes Cb 8x8 data */ * 10 bytes Cb 8x8 data */
} }
} }
} }
} }
static int dvvideo_encode_frame(AVCodecContext *c, AVPacket *pkt, static int dvvideo_encode_frame(AVCodecContext *c, AVPacket *pkt,
const AVFrame *frame, int *got_packet) const AVFrame *frame, int *got_packet)
{ {
@@ -728,6 +754,7 @@ AVCodec ff_dvvideo_encoder = {
.close = dvvideo_encode_close, .close = dvvideo_encode_close,
.capabilities = CODEC_CAP_SLICE_THREADS, .capabilities = CODEC_CAP_SLICE_THREADS,
.pix_fmts = (const enum AVPixelFormat[]) { .pix_fmts = (const enum AVPixelFormat[]) {
AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV422P,
AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE
}, },
}; };