Commit 7ae473e8 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge remote-tracking branch 'qatar/master'

* qatar/master:
  nuv: K&R formatting cosmetics
  build: generalise rules and variable settings for av* programs
  nuv: check RTjpeg header for validity
  Revert "nuv: check per-frame header for validity."
  imc: remove unused field IMCContext.one_div_log2
  imc: fix size of a memset()
  imc: remove empty if() block
  fate: simplify variable setting filter.mak
  lavf: Declare an AVRational struct without a struct literal

Conflicts:
	Makefile
	configure
	libavcodec/nuv.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents a80ce390 cf22705e
...@@ -17,7 +17,7 @@ PROGS-$(CONFIG_FFSERVER) += ffserver ...@@ -17,7 +17,7 @@ PROGS-$(CONFIG_FFSERVER) += ffserver
PROGS := $(PROGS-yes:%=%$(EXESUF)) PROGS := $(PROGS-yes:%=%$(EXESUF))
INSTPROGS = $(PROGS-yes:%=%$(PROGSSUF)$(EXESUF)) INSTPROGS = $(PROGS-yes:%=%$(PROGSSUF)$(EXESUF))
OBJS = $(PROGS-yes:%=%.o) cmdutils.o OBJS = cmdutils.o
TESTTOOLS = audiogen videogen rotozoom tiny_psnr base64 TESTTOOLS = audiogen videogen rotozoom tiny_psnr base64
HOSTPROGS := $(TESTTOOLS:%=tests/%) doc/print_options HOSTPROGS := $(TESTTOOLS:%=tests/%) doc/print_options
TOOLS = qt-faststart trasher TOOLS = qt-faststart trasher
...@@ -88,12 +88,19 @@ endef ...@@ -88,12 +88,19 @@ endef
$(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D)))) $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
ffplay.o: CFLAGS += $(SDL_CFLAGS) define DOPROG
ffplay_g$(EXESUF): FF_EXTRALIBS += $(SDL_LIBS) OBJS-$(1) += $(1).o
ffserver_g$(EXESUF): LDFLAGS += $(FFSERVERLDFLAGS) $(1)_g$(EXESUF): $(OBJS-$(1))
$$(OBJS-$(1)): CFLAGS += $(CFLAGS-$(1))
$(1)_g$(EXESUF): LDFLAGS += $(LDFLAGS-$(1))
$(1)_g$(EXESUF): FF_EXTRALIBS += $(LIBS-$(1))
-include $$(OBJS-$(1):.o=.d)
endef
$(foreach P,$(PROGS-yes),$(eval $(call DOPROG,$(P))))
%$(PROGSSUF)_g$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS) %$(PROGSSUF)_g$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS)
$(LD) $(LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS) $(LD) $(LDFLAGS) -o $@ $(OBJS-$*) cmdutils.o $(FF_EXTRALIBS)
OBJDIRS += tools OBJDIRS += tools
......
...@@ -3926,7 +3926,7 @@ CXX_O=$CXX_O ...@@ -3926,7 +3926,7 @@ CXX_O=$CXX_O
LD_O=$LD_O LD_O=$LD_O
DLLTOOL=$dlltool DLLTOOL=$dlltool
LDFLAGS=$LDFLAGS LDFLAGS=$LDFLAGS
FFSERVERLDFLAGS=$FFSERVERLDFLAGS LDFLAGS-ffserver=$FFSERVERLDFLAGS
SHFLAGS=$SHFLAGS SHFLAGS=$SHFLAGS
YASMFLAGS=$YASMFLAGS YASMFLAGS=$YASMFLAGS
BUILDSUF=$build_suffix BUILDSUF=$build_suffix
...@@ -3960,8 +3960,8 @@ HOSTCC_C=$HOSTCC_C ...@@ -3960,8 +3960,8 @@ HOSTCC_C=$HOSTCC_C
HOSTCC_O=$HOSTCC_O HOSTCC_O=$HOSTCC_O
TARGET_EXEC=$target_exec TARGET_EXEC=$target_exec
TARGET_PATH=$target_path TARGET_PATH=$target_path
SDL_LIBS=$sdl_libs LIBS-ffplay=$sdl_libs
SDL_CFLAGS=$sdl_cflags CFLAGS-ffplay=$sdl_cflags
LIB_INSTALL_EXTRA_CMD=$LIB_INSTALL_EXTRA_CMD LIB_INSTALL_EXTRA_CMD=$LIB_INSTALL_EXTRA_CMD
EXTRALIBS=$extralibs EXTRALIBS=$extralibs
INSTALL=$install INSTALL=$install
......
...@@ -92,7 +92,6 @@ typedef struct { ...@@ -92,7 +92,6 @@ typedef struct {
float sqrt_tab[30]; float sqrt_tab[30];
GetBitContext gb; GetBitContext gb;
float one_div_log2;
DSPContext dsp; DSPContext dsp;
FFTContext fft; FFTContext fft;
...@@ -227,10 +226,6 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) ...@@ -227,10 +226,6 @@ static av_cold int imc_decode_init(AVCodecContext *avctx)
imc_huffman_bits[i][j], 2, 2, INIT_VLC_USE_NEW_STATIC); imc_huffman_bits[i][j], 2, 2, INIT_VLC_USE_NEW_STATIC);
} }
} }
q->one_div_log2 = 1 / log(2);
if (avctx->codec_id == CODEC_ID_IAC) {
}
if (avctx->codec_id == CODEC_ID_IAC) { if (avctx->codec_id == CODEC_ID_IAC) {
iac_generate_tabs(q, avctx->sample_rate); iac_generate_tabs(q, avctx->sample_rate);
...@@ -792,7 +787,7 @@ static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch) ...@@ -792,7 +787,7 @@ static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
chctx->decoder_reset = 1; chctx->decoder_reset = 1;
if (chctx->decoder_reset) { if (chctx->decoder_reset) {
memset(q->out_samples, 0, sizeof(q->out_samples)); memset(q->out_samples, 0, COEFFS * sizeof(*q->out_samples));
for (i = 0; i < BANDS; i++) for (i = 0; i < BANDS; i++)
chctx->old_floor[i] = 1.0; chctx->old_floor[i] = 1.0;
for (i = 0; i < COEFFS; i++) for (i = 0; i < COEFFS; i++)
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* License along with FFmpeg; if not, write to the Free Software * License along with FFmpeg; if not, write to the Free Software
* 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 <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
...@@ -35,7 +36,7 @@ typedef struct { ...@@ -35,7 +36,7 @@ typedef struct {
int quality; int quality;
int width, height; int width, height;
unsigned int decomp_size; unsigned int decomp_size;
unsigned char* decomp_buf; unsigned char *decomp_buf;
uint32_t lq[64], cq[64]; uint32_t lq[64], cq[64];
RTJpegContext rtj; RTJpegContext rtj;
DSPContext dsp; DSPContext dsp;
...@@ -70,8 +71,8 @@ static const uint8_t fallback_cquant[] = { ...@@ -70,8 +71,8 @@ static const uint8_t fallback_cquant[] = {
* @param width width of the video frame * @param width width of the video frame
* @param height height of the video frame * @param height height of the video frame
*/ */
static void copy_frame(AVFrame *f, const uint8_t *src, static void copy_frame(AVFrame *f, const uint8_t *src, int width, int height)
int width, int height) { {
AVPicture pic; AVPicture pic;
avpicture_fill(&pic, src, PIX_FMT_YUV420P, width, height); avpicture_fill(&pic, src, PIX_FMT_YUV420P, width, height);
av_picture_copy((AVPicture *)f, &pic, PIX_FMT_YUV420P, width, height); av_picture_copy((AVPicture *)f, &pic, PIX_FMT_YUV420P, width, height);
...@@ -80,8 +81,9 @@ static void copy_frame(AVFrame *f, const uint8_t *src, ...@@ -80,8 +81,9 @@ static void copy_frame(AVFrame *f, const uint8_t *src,
/** /**
* @brief extract quantization tables from codec data into our context * @brief extract quantization tables from codec data into our context
*/ */
static int get_quant(AVCodecContext *avctx, NuvContext *c, static int get_quant(AVCodecContext *avctx, NuvContext *c, const uint8_t *buf,
const uint8_t *buf, int size) { int size)
{
int i; int i;
if (size < 2 * 64 * 4) { if (size < 2 * 64 * 4) {
av_log(avctx, AV_LOG_ERROR, "insufficient rtjpeg quant data\n"); av_log(avctx, AV_LOG_ERROR, "insufficient rtjpeg quant data\n");
...@@ -97,7 +99,8 @@ static int get_quant(AVCodecContext *avctx, NuvContext *c, ...@@ -97,7 +99,8 @@ static int get_quant(AVCodecContext *avctx, NuvContext *c,
/** /**
* @brief set quantization tables from a quality value * @brief set quantization tables from a quality value
*/ */
static void get_quant_quality(NuvContext *c, int quality) { static void get_quant_quality(NuvContext *c, int quality)
{
int i; int i;
quality = FFMAX(quality, 1); quality = FFMAX(quality, 1);
for (i = 0; i < 64; i++) { for (i = 0; i < 64; i++) {
...@@ -106,7 +109,9 @@ static void get_quant_quality(NuvContext *c, int quality) { ...@@ -106,7 +109,9 @@ static void get_quant_quality(NuvContext *c, int quality) {
} }
} }
static int codec_reinit(AVCodecContext *avctx, int width, int height, int quality) { static int codec_reinit(AVCodecContext *avctx, int width, int height,
int quality)
{
NuvContext *c = avctx->priv_data; NuvContext *c = avctx->priv_data;
width = FFALIGN(width, 2); width = FFALIGN(width, 2);
height = FFALIGN(height, 2); height = FFALIGN(height, 2);
...@@ -120,20 +125,26 @@ static int codec_reinit(AVCodecContext *avctx, int width, int height, int qualit ...@@ -120,20 +125,26 @@ static int codec_reinit(AVCodecContext *avctx, int width, int height, int qualit
return -1; return -1;
avctx->width = c->width = width; avctx->width = c->width = width;
avctx->height = c->height = height; avctx->height = c->height = height;
av_fast_malloc(&c->decomp_buf, &c->decomp_size, buf_size); av_fast_malloc(&c->decomp_buf, &c->decomp_size,
buf_size);
if (!c->decomp_buf) { if (!c->decomp_buf) {
av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); av_log(avctx, AV_LOG_ERROR,
"Can't allocate decompression buffer.\n");
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
ff_rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq); ff_rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height,
c->lq, c->cq);
return 1; return 1;
} else if (quality != c->quality) } else if (quality != c->quality)
ff_rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq); ff_rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height,
c->lq, c->cq);
return 0; return 0;
} }
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt) { AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data; const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size; int buf_size = avpkt->size;
NuvContext *c = avctx->priv_data; NuvContext *c = avctx->priv_data;
...@@ -142,9 +153,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, ...@@ -142,9 +153,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
int keyframe; int keyframe;
int size_change = 0; int size_change = 0;
int result; int result;
enum {NUV_UNCOMPRESSED = '0', NUV_RTJPEG = '1', enum {
NUV_RTJPEG_IN_LZO = '2', NUV_LZO = '3', NUV_UNCOMPRESSED = '0',
NUV_BLACK = 'N', NUV_COPY_LAST = 'L'} comptype; NUV_RTJPEG = '1',
NUV_RTJPEG_IN_LZO = '2',
NUV_LZO = '3',
NUV_BLACK = 'N',
NUV_COPY_LAST = 'L'
} comptype;
if (buf_size < 12) { if (buf_size < 12) {
av_log(avctx, AV_LOG_ERROR, "coded frame too small\n"); av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
...@@ -160,7 +176,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, ...@@ -160,7 +176,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
ret = get_quant(avctx, c, buf, buf_size); ret = get_quant(avctx, c, buf, buf_size);
if (ret < 0) if (ret < 0)
return ret; return ret;
ff_rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq); ff_rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq,
c->cq);
return orig_size; return orig_size;
} }
...@@ -172,11 +189,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, ...@@ -172,11 +189,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
switch (comptype) { switch (comptype) {
case NUV_RTJPEG_IN_LZO: case NUV_RTJPEG_IN_LZO:
case NUV_RTJPEG: case NUV_RTJPEG:
keyframe = !buf[2]; break; keyframe = !buf[2];
break;
case NUV_COPY_LAST: case NUV_COPY_LAST:
keyframe = 0; break; keyframe = 0;
break;
default: default:
keyframe = 1; break; keyframe = 1;
break;
} }
retry: retry:
// skip rest of the frameheader. // skip rest of the frameheader.
...@@ -190,8 +210,9 @@ retry: ...@@ -190,8 +210,9 @@ retry:
buf_size = c->decomp_size - AV_LZO_OUTPUT_PADDING - outlen; buf_size = c->decomp_size - AV_LZO_OUTPUT_PADDING - outlen;
} }
if (c->codec_frameheader) { if (c->codec_frameheader) {
int w, h, q, res; int w, h, q;
if (buf_size < 12) { int res;
if (buf_size < RTJPEG_HEADER_SIZE) {
av_log(avctx, AV_LOG_ERROR, "Too small NUV video frame\n"); av_log(avctx, AV_LOG_ERROR, "Too small NUV video frame\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
...@@ -214,8 +235,8 @@ retry: ...@@ -214,8 +235,8 @@ retry:
size_change = 1; size_change = 1;
goto retry; goto retry;
} }
buf = &buf[12]; buf = &buf[RTJPEG_HEADER_SIZE];
buf_size -= 12; buf_size -= RTJPEG_HEADER_SIZE;
} }
if ((size_change || keyframe) && c->pic.data[0]) if ((size_change || keyframe) && c->pic.data[0])
...@@ -244,20 +265,17 @@ retry: ...@@ -244,20 +265,17 @@ retry:
break; break;
} }
case NUV_RTJPEG_IN_LZO: case NUV_RTJPEG_IN_LZO:
case NUV_RTJPEG: { case NUV_RTJPEG:
ff_rtjpeg_decode_frame_yuv420(&c->rtj, &c->pic, buf, buf_size); ff_rtjpeg_decode_frame_yuv420(&c->rtj, &c->pic, buf, buf_size);
break; break;
} case NUV_BLACK:
case NUV_BLACK: {
memset(c->pic.data[0], 0, c->width * c->height); memset(c->pic.data[0], 0, c->width * c->height);
memset(c->pic.data[1], 128, c->width * c->height / 4); memset(c->pic.data[1], 128, c->width * c->height / 4);
memset(c->pic.data[2], 128, c->width * c->height / 4); memset(c->pic.data[2], 128, c->width * c->height / 4);
break; break;
} case NUV_COPY_LAST:
case NUV_COPY_LAST: {
/* nothing more to do here */ /* nothing more to do here */
break; break;
}
default: default:
av_log(avctx, AV_LOG_ERROR, "unknown compression\n"); av_log(avctx, AV_LOG_ERROR, "unknown compression\n");
return -1; return -1;
...@@ -268,7 +286,8 @@ retry: ...@@ -268,7 +286,8 @@ retry:
return orig_size; return orig_size;
} }
static av_cold int decode_init(AVCodecContext *avctx) { static av_cold int decode_init(AVCodecContext *avctx)
{
NuvContext *c = avctx->priv_data; NuvContext *c = avctx->priv_data;
avctx->pix_fmt = PIX_FMT_YUV420P; avctx->pix_fmt = PIX_FMT_YUV420P;
c->pic.data[0] = NULL; c->pic.data[0] = NULL;
...@@ -276,20 +295,28 @@ static av_cold int decode_init(AVCodecContext *avctx) { ...@@ -276,20 +295,28 @@ static av_cold int decode_init(AVCodecContext *avctx) {
c->quality = -1; c->quality = -1;
c->width = 0; c->width = 0;
c->height = 0; c->height = 0;
c->codec_frameheader = avctx->codec_tag == MKTAG('R', 'J', 'P', 'G'); c->codec_frameheader = avctx->codec_tag == MKTAG('R', 'J', 'P', 'G');
if (avctx->extradata_size) if (avctx->extradata_size)
get_quant(avctx, c, avctx->extradata, avctx->extradata_size); get_quant(avctx, c, avctx->extradata, avctx->extradata_size);
ff_dsputil_init(&c->dsp, avctx); ff_dsputil_init(&c->dsp, avctx);
if (codec_reinit(avctx, avctx->width, avctx->height, -1) < 0) if (codec_reinit(avctx, avctx->width, avctx->height, -1) < 0)
return 1; return 1;
return 0; return 0;
} }
static av_cold int decode_end(AVCodecContext *avctx) { static av_cold int decode_end(AVCodecContext *avctx)
{
NuvContext *c = avctx->priv_data; NuvContext *c = avctx->priv_data;
av_freep(&c->decomp_buf); av_freep(&c->decomp_buf);
if (c->pic.data[0]) if (c->pic.data[0])
avctx->release_buffer(avctx, &c->pic); avctx->release_buffer(avctx, &c->pic);
return 0; return 0;
} }
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
#include <stdint.h> #include <stdint.h>
#include "dsputil.h" #include "dsputil.h"
#define RTJPEG_FILE_VERSION 0
#define RTJPEG_HEADER_SIZE 12
typedef struct { typedef struct {
int w, h; int w, h;
DSPContext *dsp; DSPContext *dsp;
......
...@@ -2798,7 +2798,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ...@@ -2798,7 +2798,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
/* round guessed framerate to a "standard" framerate if it's /* round guessed framerate to a "standard" framerate if it's
* within 1% of the original estimate*/ * within 1% of the original estimate*/
for (j = 1; j < MAX_STD_TIMEBASES; j++) { for (j = 1; j < MAX_STD_TIMEBASES; j++) {
AVRational std_fps = (AVRational){get_std_framerate(j), 12*1001}; AVRational std_fps = { get_std_framerate(j), 12*1001 };
double error = fabs(av_q2d(st->avg_frame_rate) / av_q2d(std_fps) - 1); double error = fabs(av_q2d(st->avg_frame_rate) / av_q2d(std_fps) - 1);
if (error < best_error) { if (error < best_error) {
......
...@@ -19,21 +19,16 @@ $(FATE_AMIX): CMP = oneoff ...@@ -19,21 +19,16 @@ $(FATE_AMIX): CMP = oneoff
$(FATE_AMIX): CMP_UNIT = f32 $(FATE_AMIX): CMP_UNIT = f32
FATE_FILTER += $(FATE_AMIX) FATE_FILTER += $(FATE_AMIX)
FATE_SAMPLES_AVCONV += $(FATE_AMIX)
FATE_ASYNCTS += fate-filter-asyncts FATE_FILTER += fate-filter-asyncts
fate-filter-asyncts: SRC = $(SAMPLES)/nellymoser/nellymoser-discont.flv fate-filter-asyncts: SRC = $(SAMPLES)/nellymoser/nellymoser-discont.flv
fate-filter-asyncts: CMD = pcm -i $(SRC) -af aresample=min_comp=0.001:min_hard_comp=0.1 fate-filter-asyncts: CMD = pcm -i $(SRC) -af aresample=min_comp=0.001:min_hard_comp=0.1
fate-filter-asyncts: CMP = oneoff fate-filter-asyncts: CMP = oneoff
fate-filter-asyncts: REF = $(SAMPLES)/nellymoser/nellymoser-discont.pcm fate-filter-asyncts: REF = $(SAMPLES)/nellymoser/nellymoser-discont.pcm
FATE_FILTER += $(FATE_ASYNCTS)
FATE_SAMPLES_AVCONV += $(FATE_ASYNCTS)
fate-filter-delogo: CMD = framecrc -i $(SAMPLES)/real/rv30.rm -vf delogo=show=0:x=290:y=25:w=26:h=16 -an fate-filter-delogo: CMD = framecrc -i $(SAMPLES)/real/rv30.rm -vf delogo=show=0:x=290:y=25:w=26:h=16 -an
FATE_FILTER += fate-filter-delogo FATE_FILTER += fate-filter-delogo
FATE_SAMPLES_AVCONV += fate-filter-delogo
FATE_YADIF += fate-filter-yadif-mode0 FATE_YADIF += fate-filter-yadif-mode0
fate-filter-yadif-mode0: CMD = framecrc -flags bitexact -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -vf yadif=0 fate-filter-yadif-mode0: CMD = framecrc -flags bitexact -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -vf yadif=0
...@@ -42,6 +37,6 @@ FATE_YADIF += fate-filter-yadif-mode1 ...@@ -42,6 +37,6 @@ FATE_YADIF += fate-filter-yadif-mode1
fate-filter-yadif-mode1: CMD = framecrc -flags bitexact -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -vf yadif=1 fate-filter-yadif-mode1: CMD = framecrc -flags bitexact -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -vf yadif=1
FATE_FILTER += $(FATE_YADIF) FATE_FILTER += $(FATE_YADIF)
FATE_SAMPLES_AVCONV += $(FATE_YADIF)
FATE_SAMPLES_AVCONV += $(FATE_FILTER)
fate-filter: $(FATE_FILTER) fate-filter: $(FATE_FILTER)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment