You've already forked FFmpeg
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:
committed by
Diego Biurrun
parent
f629705b02
commit
ee0ebd3c14
143
libavcodec/dv.c
143
libavcodec/dv.c
@@ -40,124 +40,131 @@
|
|||||||
|
|
||||||
#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 };
|
||||||
static const uint8_t shuf2[] = { 24, 12, 36, 0, 48 };
|
static const uint8_t shuf2[] = { 24, 12, 36, 0, 48 };
|
||||||
static const uint8_t shuf3[] = { 18, 9, 27, 0, 36 };
|
static const uint8_t shuf3[] = { 18, 9, 27, 0, 36 };
|
||||||
|
|
||||||
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, 1}, { 0, 2}, { 0, 3}, {10, 0},
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, /* dummy */
|
||||||
{10, 1}, {10, 2}, {10, 3}, {20, 0}, {20, 1},
|
{ 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 }, { 10, 0 },
|
||||||
{20, 2}, {20, 3}, {30, 0}, {30, 1}, {30, 2},
|
{ 10, 1 }, { 10, 2 }, { 10, 3 }, { 20, 0 }, { 20, 1 },
|
||||||
{30, 3}, {40, 0}, {40, 1}, {40, 2}, {40, 3},
|
{ 20, 2 }, { 20, 3 }, { 30, 0 }, { 30, 1 }, { 30, 2 },
|
||||||
{50, 0}, {50, 1}, {50, 2}, {50, 3}, {60, 0},
|
{ 30, 3 }, { 40, 0 }, { 40, 1 }, { 40, 2 }, { 40, 3 },
|
||||||
{60, 1}, {60, 2}, {60, 3}, {70, 0}, {70, 1},
|
{ 50, 0 }, { 50, 1 }, { 50, 2 }, { 50, 3 }, { 60, 0 },
|
||||||
{70, 2}, {70, 3}, { 0,64}, { 0,65}, { 0,66},
|
{ 60, 1 }, { 60, 2 }, { 60, 3 }, { 70, 0 }, { 70, 1 },
|
||||||
{10,64}, {10,65}, {10,66}, {20,64}, {20,65},
|
{ 70, 2 }, { 70, 3 }, { 0, 64 }, { 0, 65 }, { 0, 66 },
|
||||||
{20,66}, {30,64}, {30,65}, {30,66}, {40,64},
|
{ 10, 64 }, { 10, 65 }, { 10, 66 }, { 20, 64 }, { 20, 65 },
|
||||||
{40,65}, {40,66}, {50,64}, {50,65}, {50,66},
|
{ 20, 66 }, { 30, 64 }, { 30, 65 }, { 30, 66 }, { 40, 64 },
|
||||||
{60,64}, {60,65}, {60,66}, {70,64}, {70,65},
|
{ 40, 65 }, { 40, 66 }, { 50, 64 }, { 50, 65 }, { 50, 66 },
|
||||||
{70,66}, { 0,67}, {20,67}, {40,67}, {60,67}};
|
{ 60, 64 }, { 60, 65 }, { 60, 66 }, { 70, 64 }, { 70, 65 },
|
||||||
|
{ 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;
|
||||||
|
|
||||||
for (m=0; m<5; m++) {
|
for (m = 0; m < 5; m++) {
|
||||||
switch (d->width) {
|
switch (d->width) {
|
||||||
case 1440:
|
case 1440:
|
||||||
blk = (chan*11+seq)*27+slot;
|
blk = (chan * 11 + seq) * 27 + slot;
|
||||||
|
|
||||||
if (chan == 0 && seq == 11) {
|
if (chan == 0 && seq == 11) {
|
||||||
x = m*27+slot;
|
x = m * 27 + slot;
|
||||||
if (x<90) {
|
if (x < 90) {
|
||||||
y = 0;
|
y = 0;
|
||||||
} else {
|
} else {
|
||||||
x = (x - 90)*2;
|
x = (x - 90) * 2;
|
||||||
y = 67;
|
y = 67;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
i = (4*chan + blk + off[m])%11;
|
i = (4 * chan + blk + off[m]) % 11;
|
||||||
k = (blk/11)%27;
|
k = (blk / 11) % 27;
|
||||||
|
|
||||||
x = shuf1[m] + (chan&1)*9 + k%9;
|
x = shuf1[m] + (chan & 1) * 9 + k % 9;
|
||||||
y = (i*3+k/9)*2 + (chan>>1) + 1;
|
y = (i * 3 + k / 9) * 2 + (chan >> 1) + 1;
|
||||||
}
|
}
|
||||||
tbl[m] = (x<<1)|(y<<9);
|
tbl[m] = (x << 1) | (y << 9);
|
||||||
break;
|
break;
|
||||||
case 1280:
|
case 1280:
|
||||||
blk = (chan*10+seq)*27+slot;
|
blk = (chan * 10 + seq) * 27 + slot;
|
||||||
|
|
||||||
i = (4*chan + (seq/5) + 2*blk + off[m])%10;
|
i = (4 * chan + (seq / 5) + 2 * blk + off[m]) % 10;
|
||||||
k = (blk/5)%27;
|
k = (blk / 5) % 27;
|
||||||
|
|
||||||
x = shuf1[m]+(chan&1)*9 + k%9;
|
x = shuf1[m] + (chan & 1) * 9 + k % 9;
|
||||||
y = (i*3+k/9)*2 + (chan>>1) + 4;
|
y = (i * 3 + k / 9) * 2 + (chan >> 1) + 4;
|
||||||
|
|
||||||
if (x >= 80) {
|
if (x >= 80) {
|
||||||
x = remap[y][0]+((x-80)<<(y>59));
|
x = remap[y][0] + ((x - 80) << (y > 59));
|
||||||
y = remap[y][1];
|
y = remap[y][1];
|
||||||
}
|
}
|
||||||
tbl[m] = (x<<1)|(y<<9);
|
tbl[m] = (x << 1) | (y << 9);
|
||||||
break;
|
break;
|
||||||
case 960:
|
case 960:
|
||||||
blk = (chan*10+seq)*27+slot;
|
blk = (chan * 10 + seq) * 27 + slot;
|
||||||
|
|
||||||
i = (4*chan + (seq/5) + 2*blk + off[m])%10;
|
i = (4 * chan + (seq / 5) + 2 * blk + off[m]) % 10;
|
||||||
k = (blk/5)%27 + (i&1)*3;
|
k = (blk / 5) % 27 + (i & 1) * 3;
|
||||||
|
|
||||||
x = shuf2[m] + k%6 + 6*(chan&1);
|
x = shuf2[m] + k % 6 + 6 * (chan & 1);
|
||||||
y = l_start[i] + k/6 + 45*(chan>>1);
|
y = l_start[i] + k / 6 + 45 * (chan >> 1);
|
||||||
tbl[m] = (x<<1)|(y<<9);
|
tbl[m] = (x << 1) | (y << 9);
|
||||||
break;
|
break;
|
||||||
case 720:
|
case 720:
|
||||||
switch (d->pix_fmt) {
|
switch (d->pix_fmt) {
|
||||||
case AV_PIX_FMT_YUV422P:
|
case AV_PIX_FMT_YUV422P:
|
||||||
x = shuf3[m] + slot/3;
|
x = shuf3[m] + slot / 3;
|
||||||
y = serpent1[slot] +
|
y = serpent1[slot] +
|
||||||
((((seq + off[m]) % d->difseg_size)<<1) + chan)*3;
|
((((seq + off[m]) % d->difseg_size) << 1) + chan) * 3;
|
||||||
tbl[m] = (x<<1)|(y<<8);
|
tbl[m] = (x << 1) | (y << 8);
|
||||||
break;
|
break;
|
||||||
case AV_PIX_FMT_YUV420P:
|
case AV_PIX_FMT_YUV420P:
|
||||||
x = shuf3[m] + slot/3;
|
x = shuf3[m] + slot / 3;
|
||||||
y = serpent1[slot] +
|
y = serpent1[slot] +
|
||||||
((seq + off[m]) % d->difseg_size)*3;
|
((seq + off[m]) % d->difseg_size) * 3;
|
||||||
tbl[m] = (x<<1)|(y<<9);
|
tbl[m] = (x << 1) | (y << 9);
|
||||||
break;
|
break;
|
||||||
case AV_PIX_FMT_YUV411P:
|
case AV_PIX_FMT_YUV411P:
|
||||||
i = (seq + off[m]) % d->difseg_size;
|
i = (seq + off[m]) % d->difseg_size;
|
||||||
k = slot + ((m==1||m==2)?3:0);
|
k = slot + ((m == 1 || m == 2) ? 3 : 0);
|
||||||
|
|
||||||
x = l_start_shuffled[m] + k/6;
|
x = l_start_shuffled[m] + k / 6;
|
||||||
y = serpent2[k] + i*6;
|
y = serpent2[k] + i * 6;
|
||||||
if (x>21)
|
if (x > 21)
|
||||||
y = y*2 - i*6;
|
y = y * 2 - i * 6;
|
||||||
tbl[m] = (x<<2)|(y<<8);
|
tbl[m] = (x << 2) | (y << 8);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -177,7 +184,7 @@ static const uint8_t dv_quant_areas[4] = { 6, 21, 43, 64 };
|
|||||||
|
|
||||||
int ff_dv_init_dynamic_tables(DVVideoContext *ctx, const AVDVProfile *d)
|
int ff_dv_init_dynamic_tables(DVVideoContext *ctx, const AVDVProfile *d)
|
||||||
{
|
{
|
||||||
int j,i,c,s,p;
|
int j, i, c, s, p;
|
||||||
uint32_t *factor1, *factor2;
|
uint32_t *factor1, *factor2;
|
||||||
const int *iweight1, *iweight2;
|
const int *iweight1, *iweight2;
|
||||||
|
|
||||||
@@ -240,10 +247,10 @@ av_cold int ff_dvvideo_init(AVCodecContext *avctx)
|
|||||||
|
|
||||||
if (!done) {
|
if (!done) {
|
||||||
VLC dv_vlc;
|
VLC dv_vlc;
|
||||||
uint16_t new_dv_vlc_bits[NB_DV_VLC*2];
|
uint16_t new_dv_vlc_bits[NB_DV_VLC * 2];
|
||||||
uint8_t new_dv_vlc_len[NB_DV_VLC*2];
|
uint8_t new_dv_vlc_len[NB_DV_VLC * 2];
|
||||||
uint8_t new_dv_vlc_run[NB_DV_VLC*2];
|
uint8_t new_dv_vlc_run[NB_DV_VLC * 2];
|
||||||
int16_t new_dv_vlc_level[NB_DV_VLC*2];
|
int16_t new_dv_vlc_level[NB_DV_VLC * 2];
|
||||||
|
|
||||||
done = 1;
|
done = 1;
|
||||||
|
|
||||||
@@ -267,21 +274,21 @@ 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++) {
|
||||||
int code = dv_vlc.table[i][0];
|
int code = dv_vlc.table[i][0];
|
||||||
int len = dv_vlc.table[i][1];
|
int len = dv_vlc.table[i][1];
|
||||||
int level, run;
|
int level, run;
|
||||||
|
|
||||||
if (len < 0){ //more bits needed
|
if (len < 0) { // more bits needed
|
||||||
run = 0;
|
run = 0;
|
||||||
level = code;
|
level = code;
|
||||||
} else {
|
} else {
|
||||||
run = new_dv_vlc_run [code] + 1;
|
run = new_dv_vlc_run[code] + 1;
|
||||||
level = new_dv_vlc_level[code];
|
level = new_dv_vlc_level[code];
|
||||||
}
|
}
|
||||||
ff_dv_rl_vlc[i].len = len;
|
ff_dv_rl_vlc[i].len = len;
|
||||||
|
@@ -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,8 +81,8 @@ 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 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* largest possible DV frame, in bytes (1080i50)
|
* largest possible DV frame, in bytes (1080i50)
|
||||||
@@ -103,23 +103,26 @@ int ff_dvvideo_init(AVCodecContext *avctx);
|
|||||||
|
|
||||||
static inline int dv_work_pool_size(const AVDVProfile *d)
|
static inline int dv_work_pool_size(const AVDVProfile *d)
|
||||||
{
|
{
|
||||||
int size = d->n_difchan*d->difseg_size*27;
|
int size = d->n_difchan * d->difseg_size * 27;
|
||||||
if (DV_PROFILE_IS_1080i50(d))
|
if (DV_PROFILE_IS_1080i50(d))
|
||||||
size -= 3*27;
|
size -= 3 * 27;
|
||||||
if (DV_PROFILE_IS_720p50(d))
|
if (DV_PROFILE_IS_720p50(d))
|
||||||
size -= 4*27;
|
size -= 4 * 27;
|
||||||
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 */
|
||||||
|
@@ -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"
|
||||||
@@ -44,19 +45,19 @@ static const uint8_t dv_audio_shuffle525[10][9] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t dv_audio_shuffle625[12][9] = {
|
static const uint8_t dv_audio_shuffle625[12][9] = {
|
||||||
{ 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */
|
{ 0, 36, 72, 26, 62, 98, 16, 52, 88 }, /* 1st channel */
|
||||||
{ 6, 42, 78, 32, 68, 104, 22, 58, 94},
|
{ 6, 42, 78, 32, 68, 104, 22, 58, 94 },
|
||||||
{ 12, 48, 84, 2, 38, 74, 28, 64, 100},
|
{ 12, 48, 84, 2, 38, 74, 28, 64, 100 },
|
||||||
{ 18, 54, 90, 8, 44, 80, 34, 70, 106},
|
{ 18, 54, 90, 8, 44, 80, 34, 70, 106 },
|
||||||
{ 24, 60, 96, 14, 50, 86, 4, 40, 76},
|
{ 24, 60, 96, 14, 50, 86, 4, 40, 76 },
|
||||||
{ 30, 66, 102, 20, 56, 92, 10, 46, 82},
|
{ 30, 66, 102, 20, 56, 92, 10, 46, 82 },
|
||||||
|
|
||||||
{ 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */
|
{ 1, 37, 73, 27, 63, 99, 17, 53, 89 }, /* 2nd channel */
|
||||||
{ 7, 43, 79, 33, 69, 105, 23, 59, 95},
|
{ 7, 43, 79, 33, 69, 105, 23, 59, 95 },
|
||||||
{ 13, 49, 85, 3, 39, 75, 29, 65, 101},
|
{ 13, 49, 85, 3, 39, 75, 29, 65, 101 },
|
||||||
{ 19, 55, 91, 9, 45, 81, 35, 71, 107},
|
{ 19, 55, 91, 9, 45, 81, 35, 71, 107 },
|
||||||
{ 25, 61, 97, 15, 51, 87, 5, 41, 77},
|
{ 25, 61, 97, 15, 51, 87, 5, 41, 77 },
|
||||||
{ 31, 67, 103, 21, 57, 93, 11, 47, 83},
|
{ 31, 67, 103, 21, 57, 93, 11, 47, 83 },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* macroblock bit budgets */
|
/* macroblock bit budgets */
|
||||||
@@ -78,15 +79,14 @@ static const AVDVProfile dv_profiles[] = {
|
|||||||
.ltc_divisor = 30,
|
.ltc_divisor = 30,
|
||||||
.height = 480,
|
.height = 480,
|
||||||
.width = 720,
|
.width = 720,
|
||||||
.sar = {{8, 9}, {32, 27}},
|
.sar = { { 8, 9 }, { 32, 27 } },
|
||||||
.pix_fmt = AV_PIX_FMT_YUV411P,
|
.pix_fmt = AV_PIX_FMT_YUV411P,
|
||||||
.bpm = 6,
|
.bpm = 6,
|
||||||
.block_sizes = block_sizes_dv2550,
|
.block_sizes = block_sizes_dv2550,
|
||||||
.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) */
|
||||||
@@ -96,15 +96,14 @@ static const AVDVProfile dv_profiles[] = {
|
|||||||
.ltc_divisor = 25,
|
.ltc_divisor = 25,
|
||||||
.height = 576,
|
.height = 576,
|
||||||
.width = 720,
|
.width = 720,
|
||||||
.sar = {{16, 15}, {64, 45}},
|
.sar = { { 16, 15 }, { 64, 45 } },
|
||||||
.pix_fmt = AV_PIX_FMT_YUV420P,
|
.pix_fmt = AV_PIX_FMT_YUV420P,
|
||||||
.bpm = 6,
|
.bpm = 6,
|
||||||
.block_sizes = block_sizes_dv2550,
|
.block_sizes = block_sizes_dv2550,
|
||||||
.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) */
|
||||||
@@ -114,15 +113,14 @@ static const AVDVProfile dv_profiles[] = {
|
|||||||
.ltc_divisor = 25,
|
.ltc_divisor = 25,
|
||||||
.height = 576,
|
.height = 576,
|
||||||
.width = 720,
|
.width = 720,
|
||||||
.sar = {{16, 15}, {64, 45}},
|
.sar = { { 16, 15 }, { 64, 45 } },
|
||||||
.pix_fmt = AV_PIX_FMT_YUV411P,
|
.pix_fmt = AV_PIX_FMT_YUV411P,
|
||||||
.bpm = 6,
|
.bpm = 6,
|
||||||
.block_sizes = block_sizes_dv2550,
|
.block_sizes = block_sizes_dv2550,
|
||||||
.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 */
|
||||||
@@ -132,15 +130,14 @@ static const AVDVProfile dv_profiles[] = {
|
|||||||
.ltc_divisor = 30,
|
.ltc_divisor = 30,
|
||||||
.height = 480,
|
.height = 480,
|
||||||
.width = 720,
|
.width = 720,
|
||||||
.sar = {{8, 9}, {32, 27}},
|
.sar = { { 8, 9 }, { 32, 27 } },
|
||||||
.pix_fmt = AV_PIX_FMT_YUV422P,
|
.pix_fmt = AV_PIX_FMT_YUV422P,
|
||||||
.bpm = 6,
|
.bpm = 6,
|
||||||
.block_sizes = block_sizes_dv2550,
|
.block_sizes = block_sizes_dv2550,
|
||||||
.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 */
|
||||||
@@ -150,15 +147,14 @@ static const AVDVProfile dv_profiles[] = {
|
|||||||
.ltc_divisor = 25,
|
.ltc_divisor = 25,
|
||||||
.height = 576,
|
.height = 576,
|
||||||
.width = 720,
|
.width = 720,
|
||||||
.sar = {{16, 15}, {64, 45}},
|
.sar = { { 16, 15 }, { 64, 45 } },
|
||||||
.pix_fmt = AV_PIX_FMT_YUV422P,
|
.pix_fmt = AV_PIX_FMT_YUV422P,
|
||||||
.bpm = 6,
|
.bpm = 6,
|
||||||
.block_sizes = block_sizes_dv2550,
|
.block_sizes = block_sizes_dv2550,
|
||||||
.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 */
|
||||||
@@ -168,15 +164,14 @@ static const AVDVProfile dv_profiles[] = {
|
|||||||
.ltc_divisor = 30,
|
.ltc_divisor = 30,
|
||||||
.height = 1080,
|
.height = 1080,
|
||||||
.width = 1280,
|
.width = 1280,
|
||||||
.sar = {{1, 1}, {3, 2}},
|
.sar = { { 1, 1 }, { 3, 2 } },
|
||||||
.pix_fmt = AV_PIX_FMT_YUV422P,
|
.pix_fmt = AV_PIX_FMT_YUV422P,
|
||||||
.bpm = 8,
|
.bpm = 8,
|
||||||
.block_sizes = block_sizes_dv100,
|
.block_sizes = block_sizes_dv100,
|
||||||
.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 */
|
||||||
@@ -186,15 +181,14 @@ static const AVDVProfile dv_profiles[] = {
|
|||||||
.ltc_divisor = 25,
|
.ltc_divisor = 25,
|
||||||
.height = 1080,
|
.height = 1080,
|
||||||
.width = 1440,
|
.width = 1440,
|
||||||
.sar = {{1, 1}, {4, 3}},
|
.sar = { { 1, 1 }, { 4, 3 } },
|
||||||
.pix_fmt = AV_PIX_FMT_YUV422P,
|
.pix_fmt = AV_PIX_FMT_YUV422P,
|
||||||
.bpm = 8,
|
.bpm = 8,
|
||||||
.block_sizes = block_sizes_dv100,
|
.block_sizes = block_sizes_dv100,
|
||||||
.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 */
|
||||||
@@ -204,15 +198,14 @@ static const AVDVProfile dv_profiles[] = {
|
|||||||
.ltc_divisor = 60,
|
.ltc_divisor = 60,
|
||||||
.height = 720,
|
.height = 720,
|
||||||
.width = 960,
|
.width = 960,
|
||||||
.sar = {{1, 1}, {4, 3}},
|
.sar = { { 1, 1 }, { 4, 3 } },
|
||||||
.pix_fmt = AV_PIX_FMT_YUV422P,
|
.pix_fmt = AV_PIX_FMT_YUV422P,
|
||||||
.bpm = 8,
|
.bpm = 8,
|
||||||
.block_sizes = block_sizes_dv100,
|
.block_sizes = block_sizes_dv100,
|
||||||
.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 */
|
||||||
@@ -222,15 +215,14 @@ static const AVDVProfile dv_profiles[] = {
|
|||||||
.ltc_divisor = 50,
|
.ltc_divisor = 50,
|
||||||
.height = 720,
|
.height = 720,
|
||||||
.width = 960,
|
.width = 960,
|
||||||
.sar = {{1, 1}, {4, 3}},
|
.sar = { { 1, 1 }, { 4, 3 } },
|
||||||
.pix_fmt = AV_PIX_FMT_YUV422P,
|
.pix_fmt = AV_PIX_FMT_YUV422P,
|
||||||
.bpm = 8,
|
.bpm = 8,
|
||||||
.block_sizes = block_sizes_dv100,
|
.block_sizes = block_sizes_dv100,
|
||||||
.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) */
|
||||||
@@ -240,15 +232,14 @@ static const AVDVProfile dv_profiles[] = {
|
|||||||
.ltc_divisor = 25,
|
.ltc_divisor = 25,
|
||||||
.height = 576,
|
.height = 576,
|
||||||
.width = 720,
|
.width = 720,
|
||||||
.sar = {{16, 15}, {64, 45}},
|
.sar = { { 16, 15 }, { 64, 45 } },
|
||||||
.pix_fmt = AV_PIX_FMT_YUV420P,
|
.pix_fmt = AV_PIX_FMT_YUV420P,
|
||||||
.bpm = 6,
|
.bpm = 6,
|
||||||
.block_sizes = block_sizes_dv2550,
|
.block_sizes = block_sizes_dv2550,
|
||||||
.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,7 +257,7 @@ void ff_dv_print_profiles(void *logctx, int loglevel)
|
|||||||
#endif /* CONFIG_DVPROFILE */
|
#endif /* CONFIG_DVPROFILE */
|
||||||
|
|
||||||
const AVDVProfile *av_dv_frame_profile(const AVDVProfile *sys,
|
const AVDVProfile *av_dv_frame_profile(const AVDVProfile *sys,
|
||||||
const uint8_t* frame, unsigned buf_size)
|
const uint8_t *frame, unsigned buf_size)
|
||||||
{
|
{
|
||||||
#if CONFIG_DVPROFILE
|
#if CONFIG_DVPROFILE
|
||||||
int i, dsf, stype;
|
int i, dsf, stype;
|
||||||
@@ -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)
|
||||||
@@ -299,7 +290,7 @@ const AVDVProfile *av_dv_codec_profile(int width, int height,
|
|||||||
#if CONFIG_DVPROFILE
|
#if CONFIG_DVPROFILE
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
|
for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++)
|
||||||
if (height == dv_profiles[i].height &&
|
if (height == dv_profiles[i].height &&
|
||||||
pix_fmt == dv_profiles[i].pix_fmt &&
|
pix_fmt == dv_profiles[i].pix_fmt &&
|
||||||
width == dv_profiles[i].width)
|
width == dv_profiles[i].width)
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
#define DV_VLC_MAP_LEV_SIZE 23
|
#define DV_VLC_MAP_LEV_SIZE 23
|
||||||
#else
|
#else
|
||||||
#define DV_VLC_MAP_RUN_SIZE 64
|
#define DV_VLC_MAP_RUN_SIZE 64
|
||||||
#define DV_VLC_MAP_LEV_SIZE 512 //FIXME sign was removed so this should be /2 but needs check
|
#define DV_VLC_MAP_LEV_SIZE 512 // FIXME sign was removed so this should be /2 but needs check
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* VLC encoding lookup table */
|
/* VLC encoding lookup table */
|
||||||
@@ -71,23 +71,23 @@ 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[i][j].size = dv_vlc_map[i-1][0].size +
|
dv_vlc_map[0][j].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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
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[i][j].size = dv_vlc_map[i-1][0].size +
|
dv_vlc_map[0][j].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
|
||||||
}
|
}
|
||||||
|
@@ -43,28 +43,28 @@ const uint8_t ff_dv_zigzag248_direct[64] = {
|
|||||||
|
|
||||||
/* unquant tables (not used directly) */
|
/* unquant tables (not used directly) */
|
||||||
const uint8_t ff_dv_quant_shifts[22][4] = {
|
const uint8_t ff_dv_quant_shifts[22][4] = {
|
||||||
{ 3,3,4,4 },
|
{ 3, 3, 4, 4 },
|
||||||
{ 3,3,4,4 },
|
{ 3, 3, 4, 4 },
|
||||||
{ 2,3,3,4 },
|
{ 2, 3, 3, 4 },
|
||||||
{ 2,3,3,4 },
|
{ 2, 3, 3, 4 },
|
||||||
{ 2,2,3,3 },
|
{ 2, 2, 3, 3 },
|
||||||
{ 2,2,3,3 },
|
{ 2, 2, 3, 3 },
|
||||||
{ 1,2,2,3 },
|
{ 1, 2, 2, 3 },
|
||||||
{ 1,2,2,3 },
|
{ 1, 2, 2, 3 },
|
||||||
{ 1,1,2,2 },
|
{ 1, 1, 2, 2 },
|
||||||
{ 1,1,2,2 },
|
{ 1, 1, 2, 2 },
|
||||||
{ 0,1,1,2 },
|
{ 0, 1, 1, 2 },
|
||||||
{ 0,1,1,2 },
|
{ 0, 1, 1, 2 },
|
||||||
{ 0,0,1,1 },
|
{ 0, 0, 1, 1 },
|
||||||
{ 0,0,1,1 },
|
{ 0, 0, 1, 1 },
|
||||||
{ 0,0,0,1 },
|
{ 0, 0, 0, 1 },
|
||||||
{ 0,0,0,0 },
|
{ 0, 0, 0, 0 },
|
||||||
{ 0,0,0,0 },
|
{ 0, 0, 0, 0 },
|
||||||
{ 0,0,0,0 },
|
{ 0, 0, 0, 0 },
|
||||||
{ 0,0,0,0 },
|
{ 0, 0, 0, 0 },
|
||||||
{ 0,0,0,0 },
|
{ 0, 0, 0, 0 },
|
||||||
{ 0,0,0,0 },
|
{ 0, 0, 0, 0 },
|
||||||
{ 0,0,0,0 },
|
{ 0, 0, 0, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint8_t ff_dv_quant_offset[4] = { 6, 3, 0, 1 };
|
const uint8_t ff_dv_quant_offset[4] = { 6, 3, 0, 1 };
|
||||||
@@ -301,7 +301,7 @@ const uint8_t ff_dv_vlc_run[NB_DV_VLC] = {
|
|||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
127,
|
127,
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint8_t ff_dv_vlc_level[NB_DV_VLC] = {
|
const uint8_t ff_dv_vlc_level[NB_DV_VLC] = {
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
@@ -106,7 +108,7 @@ static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, int16_t *block)
|
|||||||
index = NEG_USR32(re_cache, TEX_VLC_BITS);
|
index = NEG_USR32(re_cache, TEX_VLC_BITS);
|
||||||
vlc_len = ff_dv_rl_vlc[index].len;
|
vlc_len = ff_dv_rl_vlc[index].len;
|
||||||
if (vlc_len < 0) {
|
if (vlc_len < 0) {
|
||||||
index = NEG_USR32((unsigned)re_cache << TEX_VLC_BITS, -vlc_len) +
|
index = NEG_USR32((unsigned) re_cache << TEX_VLC_BITS, -vlc_len) +
|
||||||
ff_dv_rl_vlc[index].level;
|
ff_dv_rl_vlc[index].level;
|
||||||
vlc_len = TEX_VLC_BITS - vlc_len;
|
vlc_len = TEX_VLC_BITS - vlc_len;
|
||||||
}
|
}
|
||||||
@@ -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,9 +147,8 @@ 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 */
|
||||||
@@ -164,19 +166,19 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
|
|||||||
PutBitContext pb, vs_pb;
|
PutBitContext pb, vs_pb;
|
||||||
GetBitContext gb;
|
GetBitContext gb;
|
||||||
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];
|
||||||
|
|
||||||
assert((((int)mb_bit_buffer) & 7) == 0);
|
assert((((int) mb_bit_buffer) & 7) == 0);
|
||||||
assert((((int)vs_bit_buffer) & 7) == 0);
|
assert((((int) vs_bit_buffer) & 7) == 0);
|
||||||
|
|
||||||
memset(sblock, 0, 5*DV_MAX_BPM*sizeof(*sblock));
|
memset(sblock, 0, 5 * DV_MAX_BPM * sizeof(*sblock));
|
||||||
|
|
||||||
/* pass 1: read DC and AC coefficients in blocks */
|
/* pass 1: read DC and AC coefficients in blocks */
|
||||||
buf_ptr = &s->buf[work_chunk->buf_offset*80];
|
buf_ptr = &s->buf[work_chunk->buf_offset * 80];
|
||||||
block1 = &sblock[0][0];
|
block1 = &sblock[0][0];
|
||||||
mb1 = mb_data;
|
mb1 = mb_data;
|
||||||
init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80);
|
init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80);
|
||||||
@@ -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 =
|
||||||
(quant + ff_dv_quant_offset[class1])*64];
|
&s->idct_factor[(class1 == 3) * 2 * 22 * 64 +
|
||||||
|
dct_mode * 22 * 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,22 +286,24 @@ 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 */
|
||||||
mb[2].idct_put(y_ptr + (1 << log2_blocksize) , linesize, block + 2*64);
|
mb[2].idct_put(y_ptr + (1 << log2_blocksize), linesize, block + 2 * 64);
|
||||||
} else {
|
} else {
|
||||||
mb[1].idct_put(y_ptr + (1 << log2_blocksize) , linesize, block + 1*64);
|
mb[1].idct_put(y_ptr + (1 << log2_blocksize), linesize, block + 1 * 64);
|
||||||
mb[2].idct_put(y_ptr + y_stride, linesize, block + 2*64);
|
mb[2].idct_put(y_ptr + y_stride, linesize, block + 2 * 64);
|
||||||
mb[3].idct_put(y_ptr + (1 << log2_blocksize) + y_stride, linesize, block + 3*64);
|
mb[3].idct_put(y_ptr + (1 << log2_blocksize) + y_stride, linesize, block + 3 * 64);
|
||||||
}
|
}
|
||||||
mb += 4;
|
mb += 4;
|
||||||
block += 4*64;
|
block += 4 * 64;
|
||||||
|
|
||||||
/* idct_put'ting chrominance */
|
/* idct_put'ting chrominance */
|
||||||
c_offset = (((mb_y >> (s->sys->pix_fmt == AV_PIX_FMT_YUV420P)) * s->frame->linesize[1] +
|
c_offset = (((mb_y >> (s->sys->pix_fmt == AV_PIX_FMT_YUV420P)) * s->frame->linesize[1] +
|
||||||
@@ -302,8 +311,8 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
|
|||||||
for (j = 2; j; j--) {
|
for (j = 2; j; j--) {
|
||||||
uint8_t *c_ptr = s->frame->data[j] + c_offset;
|
uint8_t *c_ptr = s->frame->data[j] + c_offset;
|
||||||
if (s->sys->pix_fmt == AV_PIX_FMT_YUV411P && mb_x >= (704 / 8)) {
|
if (s->sys->pix_fmt == AV_PIX_FMT_YUV411P && mb_x >= (704 / 8)) {
|
||||||
uint64_t aligned_pixels[64/8];
|
uint64_t aligned_pixels[64 / 8];
|
||||||
uint8_t *pixels = (uint8_t*)aligned_pixels;
|
uint8_t *pixels = (uint8_t *) aligned_pixels;
|
||||||
uint8_t *c_ptr1, *ptr1;
|
uint8_t *c_ptr1, *ptr1;
|
||||||
int x, y;
|
int x, y;
|
||||||
mb->idct_put(pixels, 8, block);
|
mb->idct_put(pixels, 8, block);
|
||||||
@@ -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,15 +343,14 @@ 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;
|
||||||
DVVideoContext *s = avctx->priv_data;
|
DVVideoContext *s = avctx->priv_data;
|
||||||
const uint8_t* vsc_pack;
|
const uint8_t *vsc_pack;
|
||||||
int apt, is16_9, ret;
|
int apt, is16_9, ret;
|
||||||
const AVDVProfile *sys;
|
const AVDVProfile *sys;
|
||||||
|
|
||||||
@@ -369,10 +380,11 @@ static int dvvideo_decode_frame(AVCodecContext *avctx,
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Determine the codec's sample_aspect ratio from the packet */
|
/* Determine the codec's sample_aspect ratio from the packet */
|
||||||
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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -80,19 +82,19 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* bit budget for AC only in 5 MBs */
|
/* bit budget for AC only in 5 MBs */
|
||||||
static const int vs_total_ac_bits = (100 * 4 + 68*2) * 5;
|
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;
|
||||||
@@ -101,9 +103,9 @@ static av_always_inline int dv_rl2vlc(int run, int level, int sign, uint32_t* vl
|
|||||||
size = 16;
|
size = 16;
|
||||||
}
|
}
|
||||||
if (run) {
|
if (run) {
|
||||||
*vlc |= ((run < 16) ? dv_vlc_map[run-1][0].vlc :
|
*vlc |= ((run < 16) ? dv_vlc_map[run - 1][0].vlc :
|
||||||
(0x1f80 | (run - 1))) << size;
|
(0x1f80 | (run - 1))) << size;
|
||||||
size += (run < 16) ? dv_vlc_map[run-1][0].size : 13;
|
size += (run < 16) ? dv_vlc_map[run - 1][0].size : 13;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,17 +118,15 @@ 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
|
||||||
static av_always_inline int dv_rl2vlc(int run, int l, int sign, uint32_t* vlc)
|
static av_always_inline int dv_rl2vlc(int run, int l, int sign, uint32_t *vlc)
|
||||||
{
|
{
|
||||||
*vlc = dv_vlc_map[run][l].vlc | sign;
|
*vlc = dv_vlc_map[run][l].vlc | sign;
|
||||||
return dv_vlc_map[run][l].size;
|
return dv_vlc_map[run][l].size;
|
||||||
@@ -152,17 +152,18 @@ typedef struct EncBlockInfo {
|
|||||||
uint32_t partial_bit_buffer; /* we can't use uint16_t here */
|
uint32_t partial_bit_buffer; /* we can't use uint16_t here */
|
||||||
} EncBlockInfo;
|
} EncBlockInfo;
|
||||||
|
|
||||||
static av_always_inline PutBitContext* dv_encode_ac(EncBlockInfo* bi,
|
static av_always_inline PutBitContext *dv_encode_ac(EncBlockInfo *bi,
|
||||||
PutBitContext* pb_pool,
|
PutBitContext *pb_pool,
|
||||||
PutBitContext* pb_end)
|
PutBitContext *pb_end)
|
||||||
{
|
{
|
||||||
int prev, bits_left;
|
int prev, bits_left;
|
||||||
PutBitContext* pb = pb_pool;
|
PutBitContext *pb = pb_pool;
|
||||||
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 =
|
||||||
for (;;){
|
bi->partial_bit_buffer = 0;
|
||||||
|
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++) {
|
||||||
if (bits_left) {
|
if (bits_left) {
|
||||||
@@ -186,21 +187,25 @@ static av_always_inline PutBitContext* dv_encode_ac(EncBlockInfo* bi,
|
|||||||
/* Construct the next VLC */
|
/* Construct the next VLC */
|
||||||
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) {
|
||||||
int is = s->ildct_cmp(NULL, data , NULL, linesize<<1, 4) +
|
int is = s->ildct_cmp(NULL, data, NULL, linesize << 1, 4) +
|
||||||
s->ildct_cmp(NULL, data + linesize, NULL, linesize<<1, 4);
|
s->ildct_cmp(NULL, data + linesize, NULL, linesize << 1, 4);
|
||||||
return ps > is;
|
return ps > is;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,33 +235,38 @@ 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 };
|
||||||
#else /* improved Libav method */
|
#else /* improved Libav method */
|
||||||
static const int classes[] = {-1, -1, 255, 0xffff};
|
static const int classes[] = { -1, -1, 255, 0xffff };
|
||||||
#endif
|
#endif
|
||||||
int max = classes[0];
|
int max = classes[0];
|
||||||
int prev = 0;
|
int prev = 0;
|
||||||
|
|
||||||
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,9 +275,10 @@ 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"
|
||||||
memset(blk, 0, 64*sizeof(*blk));
|
* blocks. */
|
||||||
|
memset(blk, 0, 64 * sizeof(*blk));
|
||||||
bi->dct_mode = 0;
|
bi->dct_mode = 0;
|
||||||
}
|
}
|
||||||
bi->mb[0] = blk[0];
|
bi->mb[0] = blk[0];
|
||||||
@@ -278,26 +289,28 @@ static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, i
|
|||||||
for (area = 0; area < 4; area++) {
|
for (area = 0; area < 4; area++) {
|
||||||
bi->prev[area] = prev;
|
bi->prev[area] = prev;
|
||||||
bi->bit_size[area] = 1; // 4 areas 4 bits for EOB :)
|
bi->bit_size[area] = 1; // 4 areas 4 bits for EOB :)
|
||||||
for (i = mb_area_start[area]; i < mb_area_start[area+1]; i++) {
|
for (i = mb_area_start[area]; i < mb_area_start[area + 1]; i++) {
|
||||||
int level = blk[zigzag_scan[i]];
|
int level = blk[zigzag_scan[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;
|
||||||
bi->bit_size[area] += dv_rl2vlc_size(i - prev - 1, level);
|
bi->bit_size[area] += dv_rl2vlc_size(i - prev - 1, level);
|
||||||
bi->next[prev]= i;
|
bi->next[prev] = i;
|
||||||
prev = i;
|
prev = 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;
|
||||||
|
|
||||||
@@ -308,29 +321,34 @@ static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, i
|
|||||||
for (area = 0; area < 4; area++) {
|
for (area = 0; area < 4; area++) {
|
||||||
bi->prev[area] = prev;
|
bi->prev[area] = prev;
|
||||||
bi->bit_size[area] = 1; // 4 areas 4 bits for EOB :)
|
bi->bit_size[area] = 1; // 4 areas 4 bits for EOB :)
|
||||||
for (; i < mb_area_start[area+1]; i = bi->next[i]) {
|
for (; i < mb_area_start[area + 1]; i = bi->next[i]) {
|
||||||
bi->mb[i] >>= 1;
|
bi->mb[i] >>= 1;
|
||||||
|
|
||||||
if (bi->mb[i]) {
|
if (bi->mb[i]) {
|
||||||
bi->bit_size[area] += dv_rl2vlc_size(i - prev - 1, bi->mb[i]);
|
bi->bit_size[area] += dv_rl2vlc_size(i - prev - 1, bi->mb[i]);
|
||||||
bi->next[prev]= i;
|
bi->next[prev] = i;
|
||||||
prev = i;
|
prev = 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)
|
||||||
{
|
{
|
||||||
int size[5];
|
int size[5];
|
||||||
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++) {
|
||||||
@@ -345,27 +363,27 @@ static inline void dv_guess_qnos(EncBlockInfo* blks, int* qnos)
|
|||||||
b->bit_size[a] = 1; // 4 areas 4 bits for EOB :)
|
b->bit_size[a] = 1; // 4 areas 4 bits for EOB :)
|
||||||
b->area_q[a]++;
|
b->area_q[a]++;
|
||||||
prev = b->prev[a];
|
prev = b->prev[a];
|
||||||
assert(b->next[prev] >= mb_area_start[a+1] || b->mb[prev]);
|
assert(b->next[prev] >= mb_area_start[a + 1] || b->mb[prev]);
|
||||||
for (k = b->next[prev] ; k < mb_area_start[a+1]; k = b->next[k]) {
|
for (k = b->next[prev]; k < mb_area_start[a + 1]; k = b->next[k]) {
|
||||||
b->mb[k] >>= 1;
|
b->mb[k] >>= 1;
|
||||||
if (b->mb[k]) {
|
if (b->mb[k]) {
|
||||||
b->bit_size[a] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);
|
b->bit_size[a] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);
|
||||||
prev = k;
|
prev = k;
|
||||||
} else {
|
} else {
|
||||||
if (b->next[k] >= mb_area_start[a+1] && b->next[k]<64){
|
if (b->next[k] >= mb_area_start[a + 1] && b->next[k] < 64) {
|
||||||
for (a2 = a + 1; b->next[k] >= mb_area_start[a2+1]; a2++)
|
for (a2 = a + 1; b->next[k] >= mb_area_start[a2 + 1]; a2++)
|
||||||
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;
|
||||||
}
|
}
|
||||||
b->next[prev] = b->next[k];
|
b->next[prev] = b->next[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b->prev[a+1]= prev;
|
b->prev[a + 1] = prev;
|
||||||
}
|
}
|
||||||
size[i] += b->bit_size[a];
|
size[i] += b->bit_size[a];
|
||||||
}
|
}
|
||||||
@@ -373,18 +391,17 @@ static inline void dv_guess_qnos(EncBlockInfo* blks, int* qnos)
|
|||||||
if (vs_total_ac_bits >= size[0] + size[1] + size[2] + size[3] + size[4])
|
if (vs_total_ac_bits >= size[0] + size[1] + size[2] + size[3] + size[4])
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} 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
|
||||||
for (j = 0; j < 6 *5; j++, b++) {
|
for (j = 0; j < 6 * 5; j++, b++) {
|
||||||
prev = b->prev[0];
|
prev = b->prev[0];
|
||||||
for (k = b->next[prev]; k < 64; k = b->next[k]) {
|
for (k = b->next[prev]; k < 64; k = b->next[k]) {
|
||||||
if (b->mb[k] < a && b->mb[k] > -a){
|
if (b->mb[k] < a && b->mb[k] > -a) {
|
||||||
b->next[prev] = b->next[k];
|
b->next[prev] = b->next[k];
|
||||||
}else{
|
} else {
|
||||||
size[0] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);
|
size[0] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);
|
||||||
prev = k;
|
prev = k;
|
||||||
}
|
}
|
||||||
@@ -399,18 +416,18 @@ static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
|
|||||||
DVwork_chunk *work_chunk = arg;
|
DVwork_chunk *work_chunk = arg;
|
||||||
int mb_index, i, j;
|
int mb_index, i, j;
|
||||||
int mb_x, mb_y, c_offset, linesize, y_stride;
|
int mb_x, mb_y, c_offset, linesize, y_stride;
|
||||||
uint8_t* y_ptr;
|
uint8_t *y_ptr;
|
||||||
uint8_t* dif;
|
uint8_t *dif;
|
||||||
LOCAL_ALIGNED_8(uint8_t, scratch, [128]);
|
LOCAL_ALIGNED_8(uint8_t, scratch, [128]);
|
||||||
EncBlockInfo enc_blks[5*DV_MAX_BPM];
|
EncBlockInfo enc_blks[5 * DV_MAX_BPM];
|
||||||
PutBitContext pbs[5*DV_MAX_BPM];
|
PutBitContext pbs[5 * DV_MAX_BPM];
|
||||||
PutBitContext* pb;
|
PutBitContext *pb;
|
||||||
EncBlockInfo* enc_blk;
|
EncBlockInfo *enc_blk;
|
||||||
int vs_bit_size = 0;
|
int vs_bit_size = 0;
|
||||||
int qnos[5] = {15, 15, 15, 15, 15}; /* No quantization */
|
int qnos[5] = { 15, 15, 15, 15, 15 }; /* No quantization */
|
||||||
int* qnosp = &qnos[0];
|
int *qnosp = &qnos[0];
|
||||||
|
|
||||||
dif = &s->buf[work_chunk->buf_offset*80];
|
dif = &s->buf[work_chunk->buf_offset * 80];
|
||||||
enc_blk = &enc_blks[0];
|
enc_blk = &enc_blks[0];
|
||||||
for (mb_index = 0; mb_index < 5; mb_index++) {
|
for (mb_index = 0; mb_index < 5; mb_index++) {
|
||||||
dv_calculate_mb_xy(s, work_chunk, mb_index, &mb_x, &mb_y);
|
dv_calculate_mb_xy(s, work_chunk, mb_index, &mb_x, &mb_y);
|
||||||
@@ -423,21 +440,22 @@ 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 */
|
||||||
vs_bit_size +=
|
vs_bit_size +=
|
||||||
dv_init_enc_block(enc_blk+0, y_ptr , linesize, s, 0) +
|
dv_init_enc_block(enc_blk + 0, y_ptr, linesize, s, 0) +
|
||||||
dv_init_enc_block(enc_blk+1, NULL , linesize, s, 0) +
|
dv_init_enc_block(enc_blk + 1, NULL, linesize, s, 0) +
|
||||||
dv_init_enc_block(enc_blk+2, y_ptr + 8 , linesize, s, 0) +
|
dv_init_enc_block(enc_blk + 2, y_ptr + 8, linesize, s, 0) +
|
||||||
dv_init_enc_block(enc_blk+3, NULL , linesize, s, 0);
|
dv_init_enc_block(enc_blk + 3, NULL, linesize, s, 0);
|
||||||
} else {
|
} else {
|
||||||
vs_bit_size +=
|
vs_bit_size +=
|
||||||
dv_init_enc_block(enc_blk+0, y_ptr , linesize, s, 0) +
|
dv_init_enc_block(enc_blk + 0, y_ptr, linesize, s, 0) +
|
||||||
dv_init_enc_block(enc_blk+1, y_ptr + 8 , linesize, s, 0) +
|
dv_init_enc_block(enc_blk + 1, y_ptr + 8, linesize, s, 0) +
|
||||||
dv_init_enc_block(enc_blk+2, y_ptr + y_stride, linesize, s, 0) +
|
dv_init_enc_block(enc_blk + 2, y_ptr + y_stride, linesize, s, 0) +
|
||||||
dv_init_enc_block(enc_blk+3, y_ptr + 8 + y_stride, linesize, s, 0);
|
dv_init_enc_block(enc_blk + 3, y_ptr + 8 + y_stride, linesize, s, 0);
|
||||||
}
|
}
|
||||||
enc_blk += 4;
|
enc_blk += 4;
|
||||||
|
|
||||||
@@ -449,12 +467,18 @@ static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
|
|||||||
linesize = s->frame->linesize[j];
|
linesize = s->frame->linesize[j];
|
||||||
y_stride = (mb_y == 134) ? 8 : (s->frame->linesize[j] << 3);
|
y_stride = (mb_y == 134) ? 8 : (s->frame->linesize[j] << 3);
|
||||||
if (s->sys->pix_fmt == AV_PIX_FMT_YUV411P && mb_x >= (704 / 8)) {
|
if (s->sys->pix_fmt == AV_PIX_FMT_YUV411P && mb_x >= (704 / 8)) {
|
||||||
uint8_t* d;
|
uint8_t *d;
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -462,10 +486,10 @@ static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
|
|||||||
linesize = 16;
|
linesize = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,49 +497,50 @@ static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
|
|||||||
dv_guess_qnos(&enc_blks[0], qnosp);
|
dv_guess_qnos(&enc_blks[0], qnosp);
|
||||||
|
|
||||||
/* DIF encoding process */
|
/* DIF encoding process */
|
||||||
for (j=0; j<5*s->sys->bpm;) {
|
for (j = 0; j < 5 * s->sys->bpm;) {
|
||||||
int start_mb = j;
|
int start_mb = j;
|
||||||
|
|
||||||
dif[3] = *qnosp++;
|
dif[3] = *qnosp++;
|
||||||
dif += 4;
|
dif += 4;
|
||||||
|
|
||||||
/* First pass over individual cells only */
|
/* First pass over individual cells only */
|
||||||
for (i=0; i<s->sys->bpm; i++, j++) {
|
for (i = 0; i < s->sys->bpm; i++, j++) {
|
||||||
int sz = s->sys->block_sizes[i]>>3;
|
int sz = s->sys->block_sizes[i] >> 3;
|
||||||
|
|
||||||
init_put_bits(&pbs[j], dif, sz);
|
init_put_bits(&pbs[j], dif, sz);
|
||||||
put_sbits(&pbs[j], 9, ((enc_blks[j].mb[0] >> 3) - 1024 + 2) >> 2);
|
put_sbits(&pbs[j], 9, ((enc_blks[j].mb[0] >> 3) - 1024 + 2) >> 2);
|
||||||
put_bits(&pbs[j], 1, enc_blks[j].dct_mode);
|
put_bits(&pbs[j], 1, enc_blks[j].dct_mode);
|
||||||
put_bits(&pbs[j], 2, enc_blks[j].cno);
|
put_bits(&pbs[j], 2, enc_blks[j].cno);
|
||||||
|
|
||||||
dv_encode_ac(&enc_blks[j], &pbs[j], &pbs[j+1]);
|
dv_encode_ac(&enc_blks[j], &pbs[j], &pbs[j + 1]);
|
||||||
dif += sz;
|
dif += sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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 */
|
||||||
pb = &pbs[0];
|
pb = &pbs[0];
|
||||||
for (j=0; j<5*s->sys->bpm; j++) {
|
for (j = 0; j < 5 * s->sys->bpm; j++) {
|
||||||
if (enc_blks[j].partial_bit_count)
|
if (enc_blks[j].partial_bit_count)
|
||||||
pb = dv_encode_ac(&enc_blks[j], pb, &pbs[s->sys->bpm*5]);
|
pb = dv_encode_ac(&enc_blks[j], pb, &pbs[s->sys->bpm * 5]);
|
||||||
if (enc_blks[j].partial_bit_count)
|
if (enc_blks[j].partial_bit_count)
|
||||||
av_log(avctx, AV_LOG_ERROR, "ac bitstream overflow\n");
|
av_log(avctx, AV_LOG_ERROR, "ac bitstream overflow\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j=0; j<5*s->sys->bpm; j++) {
|
for (j = 0; j < 5 * s->sys->bpm; j++) {
|
||||||
int pos;
|
int pos;
|
||||||
int size = pbs[j].size_in_bits >> 3;
|
int size = pbs[j].size_in_bits >> 3;
|
||||||
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);
|
||||||
@@ -525,7 +550,7 @@ static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c,
|
static inline int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c,
|
||||||
uint8_t* buf)
|
uint8_t *buf)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Here's what SMPTE314M says about these two:
|
* Here's what SMPTE314M says about these two:
|
||||||
@@ -548,10 +573,11 @@ 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;
|
||||||
switch (pack_id) {
|
switch (pack_id) {
|
||||||
case dv_header525: /* I can't imagine why these two weren't defined as real */
|
case dv_header525: /* I can't imagine why these two weren't defined as real */
|
||||||
case dv_header625: /* packs in SMPTE314M -- they definitely look like ones */
|
case dv_header625: /* packs in SMPTE314M -- they definitely look like ones */
|
||||||
@@ -591,16 +617,19 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num,
|
static inline int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num,
|
||||||
uint8_t seq_num, uint8_t dif_num,
|
uint8_t seq_num, uint8_t dif_num,
|
||||||
uint8_t* buf)
|
uint8_t *buf)
|
||||||
{
|
{
|
||||||
buf[0] = (uint8_t)t; /* Section type */
|
buf[0] = (uint8_t) t; /* Section type */
|
||||||
buf[1] = (seq_num << 4) | /* DIF seq number 0-9 for 525/60; 0-11 for 625/50 */
|
buf[1] = (seq_num << 4) | /* DIF seq number 0-9 for 525/60; 0-11 for 625/50 */
|
||||||
(chan_num << 3) | /* FSC: for 50Mb/s 0 - first channel; 1 - second */
|
(chan_num << 3) | /* FSC: for 50Mb/s 0 - first channel; 1 - second */
|
||||||
7; /* reserved -- always 1 */
|
7; /* reserved -- always 1 */
|
||||||
@@ -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 */
|
||||||
@@ -631,7 +657,7 @@ static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t* buf)
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dv_format_frame(DVVideoContext* c, uint8_t* buf)
|
static void dv_format_frame(DVVideoContext *c, uint8_t *buf)
|
||||||
{
|
{
|
||||||
int chan, i, j, k;
|
int chan, i, j, k;
|
||||||
|
|
||||||
@@ -641,14 +667,15 @@ 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 */
|
||||||
for (j = 0; j < 2; j++) {
|
for (j = 0; j < 2; j++) {
|
||||||
buf += dv_write_dif_id(dv_sect_subcode, chan, i, j, buf);
|
buf += dv_write_dif_id(dv_sect_subcode, chan, i, j, buf);
|
||||||
for (k = 0; k < 6; k++)
|
for (k = 0; k < 6; k++)
|
||||||
buf += dv_write_ssyb_id(k, (i < c->sys->difseg_size/2), buf) + 5;
|
buf += dv_write_ssyb_id(k, (i < c->sys->difseg_size / 2), buf) + 5;
|
||||||
buf += 29; /* unused bytes */
|
buf += 29; /* unused bytes */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -657,30 +684,29 @@ static void dv_format_frame(DVVideoContext* c, uint8_t* buf)
|
|||||||
buf += dv_write_dif_id(dv_sect_vaux, chan, i, j, buf);
|
buf += dv_write_dif_id(dv_sect_vaux, chan, i, j, buf);
|
||||||
buf += dv_write_pack(dv_video_source, c, buf);
|
buf += dv_write_pack(dv_video_source, c, buf);
|
||||||
buf += dv_write_pack(dv_video_control, c, buf);
|
buf += dv_write_pack(dv_video_control, c, buf);
|
||||||
buf += 7*5;
|
buf += 7 * 5;
|
||||||
buf += dv_write_pack(dv_video_source, c, buf);
|
buf += dv_write_pack(dv_video_source, c, buf);
|
||||||
buf += dv_write_pack(dv_video_control, c, buf);
|
buf += dv_write_pack(dv_video_control, c, buf);
|
||||||
buf += 4*5 + 2; /* unused bytes */
|
buf += 4 * 5 + 2; /* unused bytes */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DV Audio/Video: 135 Video DIFs + 9 Audio DIFs */
|
/* DV Audio/Video: 135 Video DIFs + 9 Audio DIFs */
|
||||||
for (j = 0; j < 135; j++) {
|
for (j = 0; j < 135; j++) {
|
||||||
if (j%15 == 0) {
|
if (j % 15 == 0) {
|
||||||
memset(buf, 0xff, 80);
|
memset(buf, 0xff, 80);
|
||||||
buf += dv_write_dif_id(dv_sect_audio, chan, i, j/15, buf);
|
buf += dv_write_dif_id(dv_sect_audio, chan, i, j / 15, buf);
|
||||||
buf += 77; /* audio control & shuffled PCM audio */
|
buf += 77; /* audio control & shuffled PCM audio */
|
||||||
}
|
}
|
||||||
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
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user