Merge remote-tracking branch 'qatar/master'

* qatar/master:
  swscale: convert yuv2yuvX() to using named arguments.
  swscale: rename "dstw" to "w" to prevent name collisions.
  swscale: use named registers in yuv2yuv1_plane() place.
  lavf: fix aspect ratio mismatch message.
  avconv: set AVFormatContext.duration from '-t'
  cljr: implement encode2.
  cljr: set the properties of the coded_frame, not input frame.
  dnxhdenc: switch to encode2.
  bmpenc: switch to encode2().

Conflicts:
	libavcodec/bmpenc.c
	libavcodec/cljr.c
	libavformat/utils.c
	tests/ref/vsynth1/cljr
	tests/ref/vsynth2/cljr

Merged-by: Michael Niedermayer <michaelni@gmx.at>
pull/3/merge
Michael Niedermayer 13 years ago
commit 4e04e1b81e
  1. 2
      ffmpeg.c
  2. 27
      libavcodec/bmpenc.c
  3. 26
      libavcodec/cljr.c
  4. 19
      libavcodec/dnxhdenc.c
  5. 68
      libswscale/x86/output.asm

@ -4420,6 +4420,8 @@ static void opt_output_file(void *optctx, const char *filename)
output_files[nb_output_files - 1].ctx = oc; output_files[nb_output_files - 1].ctx = oc;
output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams; output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams;
output_files[nb_output_files - 1].recording_time = o->recording_time; output_files[nb_output_files - 1].recording_time = o->recording_time;
if (o->recording_time != INT64_MAX)
oc->duration = o->recording_time;
output_files[nb_output_files - 1].start_time = o->start_time; output_files[nb_output_files - 1].start_time = o->start_time;
output_files[nb_output_files - 1].limit_filesize = o->limit_filesize; output_files[nb_output_files - 1].limit_filesize = o->limit_filesize;
av_dict_copy(&output_files[nb_output_files - 1].opts, format_opts, 0); av_dict_copy(&output_files[nb_output_files - 1].opts, format_opts, 0);

@ -25,6 +25,7 @@
#include "bytestream.h" #include "bytestream.h"
#include "bmp.h" #include "bmp.h"
#include <assert.h> #include <assert.h>
#include "internal.h"
static const uint32_t monoblack_pal[] = { 0x000000, 0xFFFFFF }; static const uint32_t monoblack_pal[] = { 0x000000, 0xFFFFFF };
static const uint32_t rgb565_masks[] = { 0xF800, 0x07E0, 0x001F }; static const uint32_t rgb565_masks[] = { 0xF800, 0x07E0, 0x001F };
@ -67,17 +68,17 @@ static av_cold int bmp_encode_init(AVCodecContext *avctx){
return 0; return 0;
} }
static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ static int bmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet)
{
BMPContext *s = avctx->priv_data; BMPContext *s = avctx->priv_data;
AVFrame *pict = data;
AVFrame * const p= (AVFrame*)&s->picture; AVFrame * const p= (AVFrame*)&s->picture;
int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize; int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize, ret;
const uint32_t *pal = NULL; const uint32_t *pal = NULL;
uint32_t palette256[256]; uint32_t palette256[256];
int pad_bytes_per_row, pal_entries = 0, compression = BMP_RGB; int pad_bytes_per_row, pal_entries = 0, compression = BMP_RGB;
int bit_count = avctx->bits_per_coded_sample; int bit_count = avctx->bits_per_coded_sample;
uint8_t *ptr; uint8_t *ptr, *buf;
unsigned char* buf0 = buf;
*p = *pict; *p = *pict;
p->pict_type= AV_PICTURE_TYPE_I; p->pict_type= AV_PICTURE_TYPE_I;
p->key_frame= 1; p->key_frame= 1;
@ -119,10 +120,11 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s
#define SIZE_BITMAPINFOHEADER 40 #define SIZE_BITMAPINFOHEADER 40
hsize = SIZE_BITMAPFILEHEADER + SIZE_BITMAPINFOHEADER + (pal_entries << 2); hsize = SIZE_BITMAPFILEHEADER + SIZE_BITMAPINFOHEADER + (pal_entries << 2);
n_bytes = n_bytes_image + hsize; n_bytes = n_bytes_image + hsize;
if(n_bytes>buf_size) { if ((ret = ff_alloc_packet(pkt, n_bytes)) < 0) {
av_log(avctx, AV_LOG_ERROR, "buf size too small (need %d, got %d)\n", n_bytes, buf_size); av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
return -1; return ret;
} }
buf = pkt->data;
bytestream_put_byte(&buf, 'B'); // BITMAPFILEHEADER.bfType bytestream_put_byte(&buf, 'B'); // BITMAPFILEHEADER.bfType
bytestream_put_byte(&buf, 'M'); // do. bytestream_put_byte(&buf, 'M'); // do.
bytestream_put_le32(&buf, n_bytes); // BITMAPFILEHEADER.bfSize bytestream_put_le32(&buf, n_bytes); // BITMAPFILEHEADER.bfSize
@ -144,7 +146,7 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s
bytestream_put_le32(&buf, pal[i] & 0xFFFFFF); bytestream_put_le32(&buf, pal[i] & 0xFFFFFF);
// BMP files are bottom-to-top so we start from the end... // BMP files are bottom-to-top so we start from the end...
ptr = p->data[0] + (avctx->height - 1) * p->linesize[0]; ptr = p->data[0] + (avctx->height - 1) * p->linesize[0];
buf = buf0 + hsize; buf = pkt->data + hsize;
for(i = 0; i < avctx->height; i++) { for(i = 0; i < avctx->height; i++) {
if (bit_count == 16) { if (bit_count == 16) {
const uint16_t *src = (const uint16_t *) ptr; const uint16_t *src = (const uint16_t *) ptr;
@ -159,7 +161,10 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s
buf += pad_bytes_per_row; buf += pad_bytes_per_row;
ptr -= p->linesize[0]; // ... and go back ptr -= p->linesize[0]; // ... and go back
} }
return n_bytes;
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
return 0;
} }
AVCodec ff_bmp_encoder = { AVCodec ff_bmp_encoder = {
@ -168,7 +173,7 @@ AVCodec ff_bmp_encoder = {
.id = CODEC_ID_BMP, .id = CODEC_ID_BMP,
.priv_data_size = sizeof(BMPContext), .priv_data_size = sizeof(BMPContext),
.init = bmp_encode_init, .init = bmp_encode_init,
.encode = bmp_encode_frame, .encode2 = bmp_encode_frame,
.pix_fmts = (const enum PixelFormat[]){ .pix_fmts = (const enum PixelFormat[]){
PIX_FMT_BGRA, PIX_FMT_BGR24, PIX_FMT_BGRA, PIX_FMT_BGR24,
PIX_FMT_RGB565, PIX_FMT_RGB555, PIX_FMT_RGB444, PIX_FMT_RGB565, PIX_FMT_RGB555, PIX_FMT_RGB444,

@ -27,6 +27,7 @@
#include "avcodec.h" #include "avcodec.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "get_bits.h" #include "get_bits.h"
#include "internal.h"
#include "put_bits.h" #include "put_bits.h"
typedef struct CLJRContext { typedef struct CLJRContext {
@ -132,13 +133,12 @@ AVCodec ff_cljr_decoder = {
#endif #endif
#if CONFIG_CLJR_ENCODER #if CONFIG_CLJR_ENCODER
static int encode_frame(AVCodecContext *avctx, unsigned char *buf, static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
int buf_size, void *data) const AVFrame *p, int *got_packet)
{ {
CLJRContext *a = avctx->priv_data; CLJRContext *a = avctx->priv_data;
PutBitContext pb; PutBitContext pb;
AVFrame *p = data; int x, y, ret;
int x, y;
uint32_t dither= avctx->frame_number; uint32_t dither= avctx->frame_number;
static const uint32_t ordered_dither[2][2] = static const uint32_t ordered_dither[2][2] =
{ {
@ -146,10 +146,15 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
{ 0xCB2A0000, 0xCB250000 }, { 0xCB2A0000, 0xCB250000 },
}; };
p->pict_type = AV_PICTURE_TYPE_I; if ((ret = ff_alloc_packet(pkt, 32*avctx->height*avctx->width/4)) < 0) {
p->key_frame = 1; av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
return ret;
}
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
avctx->coded_frame->key_frame = 1;
init_put_bits(&pb, buf, buf_size / 8); init_put_bits(&pb, pkt->data, pkt->size);
for (y = 0; y < avctx->height; y++) { for (y = 0; y < avctx->height; y++) {
uint8_t *luma = &p->data[0][y * p->linesize[0]]; uint8_t *luma = &p->data[0][y * p->linesize[0]];
@ -173,7 +178,10 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
flush_put_bits(&pb); flush_put_bits(&pb);
return put_bits_count(&pb) / 8; pkt->size = put_bits_count(&pb) / 8;
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
return 0;
} }
#define OFFSET(x) offsetof(CLJRContext, x) #define OFFSET(x) offsetof(CLJRContext, x)
@ -196,7 +204,7 @@ AVCodec ff_cljr_encoder = {
.id = CODEC_ID_CLJR, .id = CODEC_ID_CLJR,
.priv_data_size = sizeof(CLJRContext), .priv_data_size = sizeof(CLJRContext),
.init = common_init, .init = common_init,
.encode = encode_frame, .encode2 = encode_frame,
.pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV411P, .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV411P,
PIX_FMT_NONE }, PIX_FMT_NONE },
.long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"),

@ -29,6 +29,7 @@
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "avcodec.h" #include "avcodec.h"
#include "dsputil.h" #include "dsputil.h"
#include "internal.h"
#include "mpegvideo.h" #include "mpegvideo.h"
#include "mpegvideo_common.h" #include "mpegvideo_common.h"
#include "dnxhdenc.h" #include "dnxhdenc.h"
@ -901,18 +902,21 @@ static void dnxhd_load_picture(DNXHDEncContext *ctx, const AVFrame *frame)
ctx->cur_field = frame->interlaced_frame && !frame->top_field_first; ctx->cur_field = frame->interlaced_frame && !frame->top_field_first;
} }
static int dnxhd_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data) static int dnxhd_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *frame, int *got_packet)
{ {
DNXHDEncContext *ctx = avctx->priv_data; DNXHDEncContext *ctx = avctx->priv_data;
int first_field = 1; int first_field = 1;
int offset, i, ret; int offset, i, ret;
uint8_t *buf;
if (buf_size < ctx->cid_table->frame_size) { if ((ret = ff_alloc_packet(pkt, ctx->cid_table->frame_size)) < 0) {
av_log(avctx, AV_LOG_ERROR, "output buffer is too small to compress picture\n"); av_log(avctx, AV_LOG_ERROR, "output buffer is too small to compress picture\n");
return -1; return ret;
} }
buf = pkt->data;
dnxhd_load_picture(ctx, data); dnxhd_load_picture(ctx, frame);
encode_coding_unit: encode_coding_unit:
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
@ -953,13 +957,14 @@ static int dnxhd_encode_picture(AVCodecContext *avctx, unsigned char *buf, int b
first_field = 0; first_field = 0;
ctx->cur_field ^= 1; ctx->cur_field ^= 1;
buf += ctx->cid_table->coding_unit_size; buf += ctx->cid_table->coding_unit_size;
buf_size -= ctx->cid_table->coding_unit_size;
goto encode_coding_unit; goto encode_coding_unit;
} }
ctx->frame.quality = ctx->qscale*FF_QP2LAMBDA; ctx->frame.quality = ctx->qscale*FF_QP2LAMBDA;
return ctx->cid_table->frame_size; pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
return 0;
} }
static int dnxhd_encode_end(AVCodecContext *avctx) static int dnxhd_encode_end(AVCodecContext *avctx)
@ -1002,7 +1007,7 @@ AVCodec ff_dnxhd_encoder = {
.id = CODEC_ID_DNXHD, .id = CODEC_ID_DNXHD,
.priv_data_size = sizeof(DNXHDEncContext), .priv_data_size = sizeof(DNXHDEncContext),
.init = dnxhd_encode_init, .init = dnxhd_encode_init,
.encode = dnxhd_encode_picture, .encode2 = dnxhd_encode_picture,
.close = dnxhd_encode_end, .close = dnxhd_encode_end,
.capabilities = CODEC_CAP_SLICE_THREADS, .capabilities = CODEC_CAP_SLICE_THREADS,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_YUV422P10, PIX_FMT_NONE}, .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_YUV422P10, PIX_FMT_NONE},

@ -59,14 +59,14 @@ SECTION .text
%macro yuv2planeX_fn 3 %macro yuv2planeX_fn 3
%if ARCH_X86_32 %if ARCH_X86_32
%define cntr_reg r1 %define cntr_reg filterq
%define movsx mov %define movsx mov
%else %else
%define cntr_reg r11 %define cntr_reg r11
%define movsx movsxd %define movsx movsxd
%endif %endif
cglobal yuv2planeX_%1, %3, 7, %2 cglobal yuv2planeX_%1, %3, 7, %2, filter, fltsize, src, dst, w, dither, offset
%if %1 == 8 || %1 == 9 || %1 == 10 %if %1 == 8 || %1 == 9 || %1 == 10
pxor m6, m6 pxor m6, m6
%endif ; %1 == 8/9/10 %endif ; %1 == 8/9/10
@ -81,8 +81,8 @@ cglobal yuv2planeX_%1, %3, 7, %2
%endif ; x86-32 %endif ; x86-32
; create registers holding dither ; create registers holding dither
movq m_dith, [r5] ; dither movq m_dith, [ditherq] ; dither
test r6d, r6d test offsetd, offsetd
jz .no_rot jz .no_rot
%if mmsize == 16 %if mmsize == 16
punpcklqdq m_dith, m_dith punpcklqdq m_dith, m_dith
@ -146,17 +146,17 @@ cglobal yuv2planeX_%1, %3, 7, %2
mova m1, [yuv2yuvX_%1_start] mova m1, [yuv2yuvX_%1_start]
mova m2, m1 mova m2, m1
%endif ; %1 == 8/9/10/16 %endif ; %1 == 8/9/10/16
movsx cntr_reg, r1m movsx cntr_reg, fltsizem
.filterloop_ %+ %%i: .filterloop_ %+ %%i:
; input pixels ; input pixels
mov r6, [r2+gprsize*cntr_reg-2*gprsize] mov r6, [srcq+gprsize*cntr_reg-2*gprsize]
%if %1 == 16 %if %1 == 16
mova m3, [r6+r5*4] mova m3, [r6+r5*4]
mova m5, [r6+r5*4+mmsize] mova m5, [r6+r5*4+mmsize]
%else ; %1 == 8/9/10 %else ; %1 == 8/9/10
mova m3, [r6+r5*2] mova m3, [r6+r5*2]
%endif ; %1 == 8/9/10/16 %endif ; %1 == 8/9/10/16
mov r6, [r2+gprsize*cntr_reg-gprsize] mov r6, [srcq+gprsize*cntr_reg-gprsize]
%if %1 == 16 %if %1 == 16
mova m4, [r6+r5*4] mova m4, [r6+r5*4]
mova m6, [r6+r5*4+mmsize] mova m6, [r6+r5*4+mmsize]
@ -165,7 +165,7 @@ cglobal yuv2planeX_%1, %3, 7, %2
%endif ; %1 == 8/9/10/16 %endif ; %1 == 8/9/10/16
; coefficients ; coefficients
movd m0, [r0+2*cntr_reg-4]; coeff[0], coeff[1] movd m0, [filterq+2*cntr_reg-4] ; coeff[0], coeff[1]
%if %1 == 16 %if %1 == 16
pshuflw m7, m0, 0 ; coeff[0] pshuflw m7, m0, 0 ; coeff[0]
pshuflw m0, m0, 0x55 ; coeff[1] pshuflw m0, m0, 0x55 ; coeff[1]
@ -207,7 +207,7 @@ cglobal yuv2planeX_%1, %3, 7, %2
%if %1 == 8 %if %1 == 8
packssdw m2, m1 packssdw m2, m1
packuswb m2, m2 packuswb m2, m2
movh [r3+r5*1], m2 movh [dstq+r5*1], m2
%else ; %1 == 9/10/16 %else ; %1 == 9/10/16
%if %1 == 16 %if %1 == 16
packssdw m2, m1 packssdw m2, m1
@ -221,11 +221,11 @@ cglobal yuv2planeX_%1, %3, 7, %2
%endif ; mmx2/sse2/sse4/avx %endif ; mmx2/sse2/sse4/avx
pminsw m2, [yuv2yuvX_%1_upper] pminsw m2, [yuv2yuvX_%1_upper]
%endif ; %1 == 9/10/16 %endif ; %1 == 9/10/16
mova [r3+r5*2], m2 mova [dstq+r5*2], m2
%endif ; %1 == 8/9/10/16 %endif ; %1 == 8/9/10/16
add r5, mmsize/2 add r5, mmsize/2
sub r4d, mmsize/2 sub wd, mmsize/2
%if %1 == 8 %if %1 == 8
%assign %%i %%i+2 %assign %%i %%i+2
%endrep %endrep
@ -275,17 +275,17 @@ yuv2planeX_fn 10, 7, 5
%macro yuv2plane1_mainloop 2 %macro yuv2plane1_mainloop 2
.loop_%2: .loop_%2:
%if %1 == 8 %if %1 == 8
paddsw m0, m2, [srcq+dstwq*2+mmsize*0] paddsw m0, m2, [srcq+wq*2+mmsize*0]
paddsw m1, m3, [srcq+dstwq*2+mmsize*1] paddsw m1, m3, [srcq+wq*2+mmsize*1]
psraw m0, 7 psraw m0, 7
psraw m1, 7 psraw m1, 7
packuswb m0, m1 packuswb m0, m1
mov%2 [r1+r2], m0 mov%2 [dstq+wq], m0
%elif %1 == 16 %elif %1 == 16
paddd m0, m4, [srcq+dstwq*4+mmsize*0] paddd m0, m4, [srcq+wq*4+mmsize*0]
paddd m1, m4, [srcq+dstwq*4+mmsize*1] paddd m1, m4, [srcq+wq*4+mmsize*1]
paddd m2, m4, [srcq+dstwq*4+mmsize*2] paddd m2, m4, [srcq+wq*4+mmsize*2]
paddd m3, m4, [srcq+dstwq*4+mmsize*3] paddd m3, m4, [srcq+wq*4+mmsize*3]
psrad m0, 3 psrad m0, 3
psrad m1, 3 psrad m1, 3
psrad m2, 3 psrad m2, 3
@ -299,40 +299,40 @@ yuv2planeX_fn 10, 7, 5
paddw m0, m5 paddw m0, m5
paddw m2, m5 paddw m2, m5
%endif ; mmx/sse2/sse4/avx %endif ; mmx/sse2/sse4/avx
mov%2 [dstq+dstwq*2+mmsize*0], m0 mov%2 [dstq+wq*2+mmsize*0], m0
mov%2 [dstq+dstwq*2+mmsize*1], m2 mov%2 [dstq+wq*2+mmsize*1], m2
%else ; %1 == 9/10 %else ; %1 == 9/10
paddsw m0, m2, [srcq+dstwq*2+mmsize*0] paddsw m0, m2, [srcq+wq*2+mmsize*0]
paddsw m1, m2, [srcq+dstwq*2+mmsize*1] paddsw m1, m2, [srcq+wq*2+mmsize*1]
psraw m0, 15 - %1 psraw m0, 15 - %1
psraw m1, 15 - %1 psraw m1, 15 - %1
pmaxsw m0, m4 pmaxsw m0, m4
pmaxsw m1, m4 pmaxsw m1, m4
pminsw m0, m3 pminsw m0, m3
pminsw m1, m3 pminsw m1, m3
mov%2 [dstq+dstwq*2+mmsize*0], m0 mov%2 [dstq+wq*2+mmsize*0], m0
mov%2 [dstq+dstwq*2+mmsize*1], m1 mov%2 [dstq+wq*2+mmsize*1], m1
%endif %endif
add dstwq, mmsize add wq, mmsize
jl .loop_%2 jl .loop_%2
%endmacro %endmacro
%macro yuv2plane1_fn 3 %macro yuv2plane1_fn 3
cglobal yuv2plane1_%1, %3, %3, %2, src, dst, dstw, dither, offset cglobal yuv2plane1_%1, %3, %3, %2, src, dst, w, dither, offset
movsxdifnidn dstwq, dstwd movsxdifnidn wq, wd
add dstwq, mmsize - 1 add wq, mmsize - 1
and dstwq, ~(mmsize - 1) and wq, ~(mmsize - 1)
%if %1 == 8 %if %1 == 8
add dstq, dstwq add dstq, wq
%else ; %1 != 8 %else ; %1 != 8
lea dstq, [dstq+dstwq*2] lea dstq, [dstq+wq*2]
%endif ; %1 == 8 %endif ; %1 == 8
%if %1 == 16 %if %1 == 16
lea srcq, [srcq+dstwq*4] lea srcq, [srcq+wq*4]
%else ; %1 != 16 %else ; %1 != 16
lea srcq, [srcq+dstwq*2] lea srcq, [srcq+wq*2]
%endif ; %1 == 16 %endif ; %1 == 16
neg dstwq neg wq
%if %1 == 8 %if %1 == 8
pxor m4, m4 ; zero pxor m4, m4 ; zero

Loading…
Cancel
Save