[FFmpeg-devel] [PATCH] lavc: remove libschroedinger encoding and decoding wrappers
wm4
nfxjfg at googlemail.com
Mon May 29 12:28:28 EEST 2017
On Sun, 28 May 2017 22:04:41 +0100
Rostislav Pehlivanov <atomnuker at gmail.com> wrote:
> The library has stopped being developed and Debian has removed it
> from its repositories citing security issues.
> The native Dirac decoder supports everything the library has and encoding
> support is still provided via the native vc2 (Dirac Pro) encoder. Hence,
> there's no reason to still support linking to the library and potentially
> leading users into security issues.
> ---
> MAINTAINERS | 1 -
> configure | 5 -
> doc/general.texi | 2 +-
> doc/platform.texi | 2 +-
> libavcodec/Makefile | 5 -
> libavcodec/allcodecs.c | 1 -
> libavcodec/libschroedinger.c | 221 ------------------
> libavcodec/libschroedinger.h | 133 -----------
> libavcodec/libschroedingerdec.c | 395 --------------------------------
> libavcodec/libschroedingerenc.c | 485 ----------------------------------------
> 10 files changed, 2 insertions(+), 1248 deletions(-)
> delete mode 100644 libavcodec/libschroedinger.c
> delete mode 100644 libavcodec/libschroedinger.h
> delete mode 100644 libavcodec/libschroedingerdec.c
> delete mode 100644 libavcodec/libschroedingerenc.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 5e5c6886df..32408e605d 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -192,7 +192,6 @@ Codecs:
> libkvazaar.c Arttu Ylä-Outinen
> libopenjpeg.c Jaikrishnan Menon
> libopenjpegenc.c Michael Bradshaw
> - libschroedinger* David Conrad
> libtheoraenc.c David Conrad
> libvorbis.c David Conrad
> libvpx* James Zern
> diff --git a/configure b/configure
> index 70b47fb95b..18464b3967 100755
> --- a/configure
> +++ b/configure
> @@ -245,7 +245,6 @@ External library support:
> --enable-librsvg enable SVG rasterization via librsvg [no]
> --enable-librubberband enable rubberband needed for rubberband filter [no]
> --enable-librtmp enable RTMP[E] support via librtmp [no]
> - --enable-libschroedinger enable Dirac de/encoding via libschroedinger [no]
> --enable-libshine enable fixed-point MP3 encoding via libshine [no]
> --enable-libsmbclient enable Samba protocol via libsmbclient [no]
> --enable-libsnappy enable Snappy compression, needed for hap encoding [no]
> @@ -1559,7 +1558,6 @@ EXTERNAL_LIBRARY_LIST="
> libpulse
> librsvg
> librtmp
> - libschroedinger
> libshine
> libsmbclient
> libsnappy
> @@ -2874,8 +2872,6 @@ libopus_decoder_deps="libopus"
> libopus_encoder_deps="libopus"
> libopus_encoder_select="audio_frame_queue"
> librsvg_decoder_deps="librsvg"
> -libschroedinger_decoder_deps="libschroedinger"
> -libschroedinger_encoder_deps="libschroedinger"
> libshine_encoder_deps="libshine"
> libshine_encoder_select="audio_frame_queue"
> libspeex_decoder_deps="libspeex"
> @@ -5847,7 +5843,6 @@ enabled libpulse && require_pkg_config libpulse pulse/pulseaudio.h pa_c
> enabled librsvg && require_pkg_config librsvg-2.0 librsvg-2.0/librsvg/rsvg.h rsvg_handle_render_cairo
> enabled librtmp && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
> enabled librubberband && require_pkg_config "rubberband >= 1.8.1" rubberband/rubberband-c.h rubberband_new
> -enabled libschroedinger && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
> enabled libshine && require_pkg_config shine shine/layer3.h shine_encode_buffer
> enabled libsmbclient && { use_pkg_config smbclient libsmbclient.h smbc_init ||
> require smbclient libsmbclient.h smbc_init -lsmbclient; }
> diff --git a/doc/general.texi b/doc/general.texi
> index 065374e3f2..8f582d586f 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -711,7 +711,7 @@ following image formats are supported:
> @item DFA @tab @tab X
> @tab Codec used in Chronomaster game.
> @item Dirac @tab E @tab X
> - @tab supported through external library libschroedinger
> + @tab supported though the native vc2 (Dirac Pro) encoder
> @item Deluxe Paint Animation @tab @tab X
> @item DNxHD @tab X @tab X
> @tab aka SMPTE VC3
> diff --git a/doc/platform.texi b/doc/platform.texi
> index 576c295313..32d97cc58b 100644
> --- a/doc/platform.texi
> +++ b/doc/platform.texi
> @@ -315,7 +315,7 @@ These library packages are only available from
>
> @example
> yasm, libSDL-devel, libgsm-devel, libmp3lame-devel,
> -libschroedinger1.0-devel, speex-devel, libtheora-devel, libxvidcore-devel
> +speex-devel, libtheora-devel, libxvidcore-devel
> @end example
>
> The recommendation for x264 is to build it from source, as it evolves too
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 3d93c05ff8..0818950ad9 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -902,10 +902,6 @@ OBJS-$(CONFIG_LIBOPUS_DECODER) += libopusdec.o libopus.o \
> vorbis_data.o
> OBJS-$(CONFIG_LIBOPUS_ENCODER) += libopusenc.o libopus.o \
> vorbis_data.o
> -OBJS-$(CONFIG_LIBSCHROEDINGER_DECODER) += libschroedingerdec.o \
> - libschroedinger.o
> -OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER) += libschroedingerenc.o \
> - libschroedinger.o
> OBJS-$(CONFIG_LIBSHINE_ENCODER) += libshine.o
> OBJS-$(CONFIG_LIBSPEEX_DECODER) += libspeexdec.o
> OBJS-$(CONFIG_LIBSPEEX_ENCODER) += libspeexenc.o
> @@ -1025,7 +1021,6 @@ SKIPHEADERS += %_tablegen.h \
> SKIPHEADERS-$(CONFIG_D3D11VA) += d3d11va.h dxva2_internal.h
> SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h
> SKIPHEADERS-$(CONFIG_JNI) += ffjni.h
> -SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h
> SKIPHEADERS-$(CONFIG_LIBVPX) += libvpx.h
> SKIPHEADERS-$(CONFIG_LIBWEBP_ENCODER) += libwebpenc_common.h
> SKIPHEADERS-$(CONFIG_MEDIACODEC) += mediacodecdec_common.h mediacodec_surface.h mediacodec_wrapper.h mediacodec_sw_buffer.h
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 40468a6d6d..89fadcd2fa 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -617,7 +617,6 @@ static void register_all(void)
> REGISTER_ENCDEC (LIBOPENJPEG, libopenjpeg);
> REGISTER_ENCDEC (LIBOPUS, libopus);
> REGISTER_DECODER(LIBRSVG, librsvg);
> - REGISTER_ENCDEC (LIBSCHROEDINGER, libschroedinger);
> REGISTER_ENCODER(LIBSHINE, libshine);
> REGISTER_ENCDEC (LIBSPEEX, libspeex);
> REGISTER_ENCODER(LIBTHEORA, libtheora);
> diff --git a/libavcodec/libschroedinger.c b/libavcodec/libschroedinger.c
> deleted file mode 100644
> index 4bb0f12d89..0000000000
> --- a/libavcodec/libschroedinger.c
> +++ /dev/null
> @@ -1,221 +0,0 @@
> -/*
> - * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
> - *
> - * This file is part of FFmpeg.
> - *
> - * FFmpeg is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU Lesser General Public
> - * License as published by the Free Software Foundation; either
> - * version 2.1 of the License, or (at your option) any later version.
> - *
> - * FFmpeg is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> - * Lesser General Public License for more details.
> - *
> - * You should have received a copy of the GNU Lesser General Public
> - * License along with FFmpeg; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> - */
> -
> -/**
> -* @file
> -* function definitions common to libschroedinger decoder and encoder
> -*/
> -
> -#include "libavutil/attributes.h"
> -#include "libavutil/mem.h"
> -#include "libschroedinger.h"
> -#include "internal.h"
> -
> -static const SchroVideoFormatInfo ff_schro_video_format_info[] = {
> - { 640, 480, 24000, 1001},
> - { 176, 120, 15000, 1001},
> - { 176, 144, 25, 2 },
> - { 352, 240, 15000, 1001},
> - { 352, 288, 25, 2 },
> - { 704, 480, 15000, 1001},
> - { 704, 576, 25, 2 },
> - { 720, 480, 30000, 1001},
> - { 720, 576, 25, 1 },
> - { 1280, 720, 60000, 1001},
> - { 1280, 720, 50, 1 },
> - { 1920, 1080, 30000, 1001},
> - { 1920, 1080, 25, 1 },
> - { 1920, 1080, 60000, 1001},
> - { 1920, 1080, 50, 1 },
> - { 2048, 1080, 24, 1 },
> - { 4096, 2160, 24, 1 },
> -};
> -
> -static unsigned int get_video_format_idx(AVCodecContext *avctx)
> -{
> - unsigned int ret_idx = 0;
> - unsigned int idx;
> - unsigned int num_formats = sizeof(ff_schro_video_format_info) /
> - sizeof(ff_schro_video_format_info[0]);
> -
> - for (idx = 1; idx < num_formats; ++idx) {
> - const SchroVideoFormatInfo *vf = &ff_schro_video_format_info[idx];
> - if (avctx->width == vf->width &&
> - avctx->height == vf->height) {
> - ret_idx = idx;
> - if (avctx->time_base.den == vf->frame_rate_num &&
> - avctx->time_base.num == vf->frame_rate_denom)
> - return idx;
> - }
> - }
> - return ret_idx;
> -}
> -
> -av_cold void ff_schro_queue_init(FFSchroQueue *queue)
> -{
> - queue->p_head = queue->p_tail = NULL;
> - queue->size = 0;
> -}
> -
> -void ff_schro_queue_free(FFSchroQueue *queue, void (*free_func)(void *))
> -{
> - while (queue->p_head)
> - free_func(ff_schro_queue_pop(queue));
> -}
> -
> -int ff_schro_queue_push_back(FFSchroQueue *queue, void *p_data)
> -{
> - FFSchroQueueElement *p_new = av_mallocz(sizeof(FFSchroQueueElement));
> -
> - if (!p_new)
> - return -1;
> -
> - p_new->data = p_data;
> -
> - if (!queue->p_head)
> - queue->p_head = p_new;
> - else
> - queue->p_tail->next = p_new;
> - queue->p_tail = p_new;
> -
> - ++queue->size;
> - return 0;
> -}
> -
> -void *ff_schro_queue_pop(FFSchroQueue *queue)
> -{
> - FFSchroQueueElement *top = queue->p_head;
> -
> - if (top) {
> - void *data = top->data;
> - queue->p_head = queue->p_head->next;
> - --queue->size;
> - av_freep(&top);
> - return data;
> - }
> -
> - return NULL;
> -}
> -
> -/**
> -* Schroedinger video preset table. Ensure that this tables matches up correctly
> -* with the ff_schro_video_format_info table.
> -*/
> -static const SchroVideoFormatEnum ff_schro_video_formats[]={
> - SCHRO_VIDEO_FORMAT_CUSTOM ,
> - SCHRO_VIDEO_FORMAT_QSIF ,
> - SCHRO_VIDEO_FORMAT_QCIF ,
> - SCHRO_VIDEO_FORMAT_SIF ,
> - SCHRO_VIDEO_FORMAT_CIF ,
> - SCHRO_VIDEO_FORMAT_4SIF ,
> - SCHRO_VIDEO_FORMAT_4CIF ,
> - SCHRO_VIDEO_FORMAT_SD480I_60 ,
> - SCHRO_VIDEO_FORMAT_SD576I_50 ,
> - SCHRO_VIDEO_FORMAT_HD720P_60 ,
> - SCHRO_VIDEO_FORMAT_HD720P_50 ,
> - SCHRO_VIDEO_FORMAT_HD1080I_60 ,
> - SCHRO_VIDEO_FORMAT_HD1080I_50 ,
> - SCHRO_VIDEO_FORMAT_HD1080P_60 ,
> - SCHRO_VIDEO_FORMAT_HD1080P_50 ,
> - SCHRO_VIDEO_FORMAT_DC2K_24 ,
> - SCHRO_VIDEO_FORMAT_DC4K_24 ,
> -};
> -
> -SchroVideoFormatEnum ff_get_schro_video_format_preset(AVCodecContext *avctx)
> -{
> - unsigned int num_formats = sizeof(ff_schro_video_formats) /
> - sizeof(ff_schro_video_formats[0]);
> -
> - unsigned int idx = get_video_format_idx(avctx);
> -
> - return (idx < num_formats) ? ff_schro_video_formats[idx] :
> - SCHRO_VIDEO_FORMAT_CUSTOM;
> -}
> -
> -int ff_get_schro_frame_format (SchroChromaFormat schro_pix_fmt,
> - SchroFrameFormat *schro_frame_fmt)
> -{
> - unsigned int num_formats = sizeof(schro_pixel_format_map) /
> - sizeof(schro_pixel_format_map[0]);
> -
> - int idx;
> -
> - for (idx = 0; idx < num_formats; ++idx) {
> - if (schro_pixel_format_map[idx].schro_pix_fmt == schro_pix_fmt) {
> - *schro_frame_fmt = schro_pixel_format_map[idx].schro_frame_fmt;
> - return 0;
> - }
> - }
> - return -1;
> -}
> -
> -static void free_schro_frame(SchroFrame *frame, void *priv)
> -{
> - AVFrame *p_pic = priv;
> - av_frame_free(&p_pic);
> -}
> -
> -SchroFrame *ff_create_schro_frame(AVCodecContext *avctx,
> - SchroFrameFormat schro_frame_fmt)
> -{
> - AVFrame *p_pic;
> - SchroFrame *p_frame;
> - int y_width, uv_width;
> - int y_height, uv_height;
> - int i;
> -
> - y_width = avctx->width;
> - y_height = avctx->height;
> - uv_width = y_width >> (SCHRO_FRAME_FORMAT_H_SHIFT(schro_frame_fmt));
> - uv_height = y_height >> (SCHRO_FRAME_FORMAT_V_SHIFT(schro_frame_fmt));
> -
> - p_pic = av_frame_alloc();
> - if (!p_pic)
> - return NULL;
> -
> - if (ff_get_buffer(avctx, p_pic, AV_GET_BUFFER_FLAG_REF) < 0) {
> - av_frame_free(&p_pic);
> - return NULL;
> - }
> -
> - p_frame = schro_frame_new();
> - p_frame->format = schro_frame_fmt;
> - p_frame->width = y_width;
> - p_frame->height = y_height;
> - schro_frame_set_free_callback(p_frame, free_schro_frame, p_pic);
> -
> - for (i = 0; i < 3; ++i) {
> - p_frame->components[i].width = i ? uv_width : y_width;
> - p_frame->components[i].stride = p_pic->linesize[i];
> - p_frame->components[i].height = i ? uv_height : y_height;
> - p_frame->components[i].length =
> - p_frame->components[i].stride * p_frame->components[i].height;
> - p_frame->components[i].data = p_pic->data[i];
> -
> - if (i) {
> - p_frame->components[i].v_shift =
> - SCHRO_FRAME_FORMAT_V_SHIFT(p_frame->format);
> - p_frame->components[i].h_shift =
> - SCHRO_FRAME_FORMAT_H_SHIFT(p_frame->format);
> - }
> - }
> -
> - return p_frame;
> -}
> diff --git a/libavcodec/libschroedinger.h b/libavcodec/libschroedinger.h
> deleted file mode 100644
> index 12fe57c7f1..0000000000
> --- a/libavcodec/libschroedinger.h
> +++ /dev/null
> @@ -1,133 +0,0 @@
> -/*
> - * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
> - *
> - * This file is part of FFmpeg.
> - *
> - * FFmpeg is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU Lesser General Public
> - * License as published by the Free Software Foundation; either
> - * version 2.1 of the License, or (at your option) any later version.
> - *
> - * FFmpeg is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> - * Lesser General Public License for more details.
> - *
> - * You should have received a copy of the GNU Lesser General Public
> - * License along with FFmpeg; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> - */
> -
> -/**
> -* @file
> -* data structures common to libschroedinger decoder and encoder
> -*/
> -
> -#ifndef AVCODEC_LIBSCHROEDINGER_H
> -#define AVCODEC_LIBSCHROEDINGER_H
> -
> -#include <schroedinger/schrobitstream.h>
> -#include <schroedinger/schroframe.h>
> -
> -#include "avcodec.h"
> -
> -typedef struct SchroVideoFormatInfo {
> - uint16_t width;
> - uint16_t height;
> - uint16_t frame_rate_num;
> - uint16_t frame_rate_denom;
> -} SchroVideoFormatInfo;
> -
> -/**
> -* contains a single encoded frame returned from Dirac or Schroedinger
> -*/
> -typedef struct FFSchroEncodedFrame {
> - /** encoded frame data */
> - uint8_t *p_encbuf;
> -
> - /** encoded frame size */
> - uint32_t size;
> -
> - /** encoded frame number. Will be used as pts */
> - uint32_t frame_num;
> -
> - /** key frame flag. 1 : is key frame , 0 : in not key frame */
> - uint16_t key_frame;
> -} FFSchroEncodedFrame;
> -
> -/**
> -* queue element
> -*/
> -typedef struct FFSchroQueueElement {
> - /** Data to be stored in queue*/
> - void *data;
> - /** Pointer to next element queue */
> - struct FFSchroQueueElement *next;
> -} FFSchroQueueElement;
> -
> -
> -/**
> -* A simple queue implementation used in libschroedinger
> -*/
> -typedef struct FFSchroQueue {
> - /** Pointer to head of queue */
> - FFSchroQueueElement *p_head;
> - /** Pointer to tail of queue */
> - FFSchroQueueElement *p_tail;
> - /** Queue size*/
> - int size;
> -} FFSchroQueue;
> -
> -/**
> -* Initialise the queue
> -*/
> -void ff_schro_queue_init(FFSchroQueue *queue);
> -
> -/**
> -* Add an element to the end of the queue
> -*/
> -int ff_schro_queue_push_back(FFSchroQueue *queue, void *p_data);
> -
> -/**
> -* Return the first element in the queue
> -*/
> -void *ff_schro_queue_pop(FFSchroQueue *queue);
> -
> -/**
> -* Free the queue resources. free_func is a function supplied by the caller to
> -* free any resources allocated by the caller. The data field of the queue
> -* element is passed to it.
> -*/
> -void ff_schro_queue_free(FFSchroQueue *queue, void (*free_func)(void *));
> -
> -static const struct {
> - enum AVPixelFormat ff_pix_fmt;
> - SchroChromaFormat schro_pix_fmt;
> - SchroFrameFormat schro_frame_fmt;
> -} schro_pixel_format_map[] = {
> - { AV_PIX_FMT_YUV420P, SCHRO_CHROMA_420, SCHRO_FRAME_FORMAT_U8_420 },
> - { AV_PIX_FMT_YUV422P, SCHRO_CHROMA_422, SCHRO_FRAME_FORMAT_U8_422 },
> - { AV_PIX_FMT_YUV444P, SCHRO_CHROMA_444, SCHRO_FRAME_FORMAT_U8_444 },
> -};
> -
> -/**
> -* Returns the video format preset matching the input video dimensions and
> -* time base.
> -*/
> -SchroVideoFormatEnum ff_get_schro_video_format_preset (AVCodecContext *avctx);
> -
> -/**
> -* Sets the Schroedinger frame format corresponding to the Schro chroma format
> -* passed. Returns 0 on success, -1 on failure.
> -*/
> -int ff_get_schro_frame_format(SchroChromaFormat schro_chroma_fmt,
> - SchroFrameFormat *schro_frame_fmt);
> -
> -/**
> -* Create a Schro frame based on the dimensions and frame format
> -* passed. Returns a pointer to a frame on success, NULL on failure.
> -*/
> -SchroFrame *ff_create_schro_frame(AVCodecContext *avctx,
> - SchroFrameFormat schro_frame_fmt);
> -
> -#endif /* AVCODEC_LIBSCHROEDINGER_H */
> diff --git a/libavcodec/libschroedingerdec.c b/libavcodec/libschroedingerdec.c
> deleted file mode 100644
> index 148a9b6098..0000000000
> --- a/libavcodec/libschroedingerdec.c
> +++ /dev/null
> @@ -1,395 +0,0 @@
> -/*
> - * Dirac decoder support via Schroedinger libraries
> - * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
> - *
> - * This file is part of FFmpeg.
> - *
> - * FFmpeg is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU Lesser General Public
> - * License as published by the Free Software Foundation; either
> - * version 2.1 of the License, or (at your option) any later version.
> - *
> - * FFmpeg is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> - * Lesser General Public License for more details.
> - *
> - * You should have received a copy of the GNU Lesser General Public
> - * License along with FFmpeg; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> - */
> -
> -/**
> -* @file
> -* Dirac decoder support via libschroedinger-1.0 libraries. More details about
> -* the Schroedinger project can be found at http://www.diracvideo.org/.
> -* The library implements Dirac Specification Version 2.2.
> -* (http://dirac.sourceforge.net/specification.html).
> -*/
> -
> -#include <string.h>
> -
> -#include "libavutil/imgutils.h"
> -#include "libavutil/internal.h"
> -#include "libavutil/intreadwrite.h"
> -#include "libavutil/mem.h"
> -#include "avcodec.h"
> -#include "internal.h"
> -#include "libschroedinger.h"
> -
> -#include <schroedinger/schro.h>
> -#include <schroedinger/schrodebug.h>
> -#include <schroedinger/schrovideoformat.h>
> -
> -/** SchroFrame and Pts relation */
> -typedef struct LibSchroFrameContext {
> - SchroFrame *frame;
> - int64_t pts;
> -} LibSchroFrameContext;
> -
> -/** libschroedinger decoder private data */
> -typedef struct SchroDecoderParams {
> - /** Schroedinger video format */
> - SchroVideoFormat *format;
> -
> - /** Schroedinger frame format */
> - SchroFrameFormat frame_format;
> -
> - /** decoder handle */
> - SchroDecoder* decoder;
> -
> - /** queue storing decoded frames */
> - FFSchroQueue dec_frame_queue;
> -
> - /** end of sequence signalled */
> - int eos_signalled;
> -
> - /** end of sequence pulled */
> - int eos_pulled;
> -} SchroDecoderParams;
> -
> -typedef struct SchroParseUnitContext {
> - const uint8_t *buf;
> - int buf_size;
> -} SchroParseUnitContext;
> -
> -
> -static void libschroedinger_decode_buffer_free(SchroBuffer *schro_buf,
> - void *priv)
> -{
> - av_freep(&priv);
> -}
> -
> -static void parse_context_init(SchroParseUnitContext *parse_ctx,
> - const uint8_t *buf, int buf_size)
> -{
> - parse_ctx->buf = buf;
> - parse_ctx->buf_size = buf_size;
> -}
> -
> -static SchroBuffer *find_next_parse_unit(SchroParseUnitContext *parse_ctx)
> -{
> - SchroBuffer *enc_buf = NULL;
> - int next_pu_offset = 0;
> - unsigned char *in_buf;
> -
> - if (parse_ctx->buf_size < 13 ||
> - parse_ctx->buf[0] != 'B' ||
> - parse_ctx->buf[1] != 'B' ||
> - parse_ctx->buf[2] != 'C' ||
> - parse_ctx->buf[3] != 'D')
> - return NULL;
> -
> - next_pu_offset = (parse_ctx->buf[5] << 24) +
> - (parse_ctx->buf[6] << 16) +
> - (parse_ctx->buf[7] << 8) +
> - parse_ctx->buf[8];
> -
> - if (next_pu_offset == 0 &&
> - SCHRO_PARSE_CODE_IS_END_OF_SEQUENCE(parse_ctx->buf[4]))
> - next_pu_offset = 13;
> -
> - if (next_pu_offset <= 0 || parse_ctx->buf_size < next_pu_offset)
> - return NULL;
> -
> - in_buf = av_malloc(next_pu_offset);
> - if (!in_buf) {
> - av_log(parse_ctx, AV_LOG_ERROR, "Unable to allocate input buffer\n");
> - return NULL;
> - }
> -
> - memcpy(in_buf, parse_ctx->buf, next_pu_offset);
> - enc_buf = schro_buffer_new_with_data(in_buf, next_pu_offset);
> - enc_buf->free = libschroedinger_decode_buffer_free;
> - enc_buf->priv = in_buf;
> -
> - parse_ctx->buf += next_pu_offset;
> - parse_ctx->buf_size -= next_pu_offset;
> -
> - return enc_buf;
> -}
> -
> -/**
> -* Returns FFmpeg chroma format.
> -*/
> -static enum AVPixelFormat get_chroma_format(SchroChromaFormat schro_pix_fmt)
> -{
> - int num_formats = sizeof(schro_pixel_format_map) /
> - sizeof(schro_pixel_format_map[0]);
> - int idx;
> -
> - for (idx = 0; idx < num_formats; ++idx)
> - if (schro_pixel_format_map[idx].schro_pix_fmt == schro_pix_fmt)
> - return schro_pixel_format_map[idx].ff_pix_fmt;
> - return AV_PIX_FMT_NONE;
> -}
> -
> -static av_cold int libschroedinger_decode_init(AVCodecContext *avctx)
> -{
> -
> - SchroDecoderParams *p_schro_params = avctx->priv_data;
> - /* First of all, initialize our supporting libraries. */
> - schro_init();
> -
> - schro_debug_set_level(avctx->debug);
> - p_schro_params->decoder = schro_decoder_new();
> - schro_decoder_set_skip_ratio(p_schro_params->decoder, 1);
> -
> - if (!p_schro_params->decoder)
> - return -1;
> -
> - /* Initialize the decoded frame queue. */
> - ff_schro_queue_init(&p_schro_params->dec_frame_queue);
> - return 0;
> -}
> -
> -static void libschroedinger_decode_frame_free(void *frame)
> -{
> - schro_frame_unref(frame);
> -}
> -
> -static void libschroedinger_handle_first_access_unit(AVCodecContext *avctx)
> -{
> - SchroDecoderParams *p_schro_params = avctx->priv_data;
> - SchroDecoder *decoder = p_schro_params->decoder;
> -
> - p_schro_params->format = schro_decoder_get_video_format(decoder);
> -
> - /* Tell FFmpeg about sequence details. */
> - if (av_image_check_size(p_schro_params->format->width,
> - p_schro_params->format->height, 0, avctx) < 0) {
> - av_log(avctx, AV_LOG_ERROR, "invalid dimensions (%dx%d)\n",
> - p_schro_params->format->width, p_schro_params->format->height);
> - avctx->height = avctx->width = 0;
> - return;
> - }
> - avctx->height = p_schro_params->format->height;
> - avctx->width = p_schro_params->format->width;
> - avctx->pix_fmt = get_chroma_format(p_schro_params->format->chroma_format);
> -
> - if (ff_get_schro_frame_format(p_schro_params->format->chroma_format,
> - &p_schro_params->frame_format) == -1) {
> - av_log(avctx, AV_LOG_ERROR,
> - "This codec currently only supports planar YUV 4:2:0, 4:2:2 "
> - "and 4:4:4 formats.\n");
> - return;
> - }
> -
> - avctx->framerate.num = p_schro_params->format->frame_rate_numerator;
> - avctx->framerate.den = p_schro_params->format->frame_rate_denominator;
> -}
> -
> -static int libschroedinger_decode_frame(AVCodecContext *avctx,
> - void *data, int *got_frame,
> - AVPacket *avpkt)
> -{
> - const uint8_t *buf = avpkt->data;
> - int buf_size = avpkt->size;
> - int64_t pts = avpkt->pts;
> - SchroTag *tag;
> -
> - SchroDecoderParams *p_schro_params = avctx->priv_data;
> - SchroDecoder *decoder = p_schro_params->decoder;
> - SchroBuffer *enc_buf;
> - SchroFrame* frame;
> - AVFrame *avframe = data;
> - int state;
> - int go = 1;
> - int outer = 1;
> - SchroParseUnitContext parse_ctx;
> - LibSchroFrameContext *framewithpts = NULL;
> - int ret;
> -
> - *got_frame = 0;
> -
> - parse_context_init(&parse_ctx, buf, buf_size);
> - if (!buf_size) {
> - if (!p_schro_params->eos_signalled) {
> - state = schro_decoder_push_end_of_stream(decoder);
> - p_schro_params->eos_signalled = 1;
> - }
> - }
> -
> - /* Loop through all the individual parse units in the input buffer */
> - do {
> - if ((enc_buf = find_next_parse_unit(&parse_ctx))) {
> - /* Set Schrotag with the pts to be recovered after decoding*/
> - enc_buf->tag = schro_tag_new(av_malloc(sizeof(int64_t)), av_free);
> - if (!enc_buf->tag->value) {
> - av_log(avctx, AV_LOG_ERROR, "Unable to allocate SchroTag\n");
> - return AVERROR(ENOMEM);
> - }
> - AV_WN(64, enc_buf->tag->value, pts);
> - /* Push buffer into decoder. */
> - if (SCHRO_PARSE_CODE_IS_PICTURE(enc_buf->data[4]) &&
> - SCHRO_PARSE_CODE_NUM_REFS(enc_buf->data[4]) > 0)
> - avctx->has_b_frames = 1;
> - state = schro_decoder_push(decoder, enc_buf);
> - if (state == SCHRO_DECODER_FIRST_ACCESS_UNIT)
> - libschroedinger_handle_first_access_unit(avctx);
> - go = 1;
> - } else
> - outer = 0;
> -
> - while (go) {
> - /* Parse data and process result. */
> - state = schro_decoder_wait(decoder);
> - switch (state) {
> - case SCHRO_DECODER_FIRST_ACCESS_UNIT:
> - libschroedinger_handle_first_access_unit(avctx);
> - break;
> -
> - case SCHRO_DECODER_NEED_BITS:
> - /* Need more input data - stop iterating over what we have. */
> - go = 0;
> - break;
> -
> - case SCHRO_DECODER_NEED_FRAME:
> - /* Decoder needs a frame - create one and push it in. */
> - frame = ff_create_schro_frame(avctx,
> - p_schro_params->frame_format);
> - if (!frame)
> - return AVERROR(ENOMEM);
> - schro_decoder_add_output_picture(decoder, frame);
> - break;
> -
> - case SCHRO_DECODER_OK:
> - /* Pull a frame out of the decoder. */
> - tag = schro_decoder_get_picture_tag(decoder);
> - frame = schro_decoder_pull(decoder);
> -
> - if (frame) {
> - /* Add relation between schroframe and pts. */
> - framewithpts = av_malloc(sizeof(LibSchroFrameContext));
> - if (!framewithpts) {
> - av_log(avctx, AV_LOG_ERROR, "Unable to allocate FrameWithPts\n");
> - return AVERROR(ENOMEM);
> - }
> - framewithpts->frame = frame;
> - framewithpts->pts = AV_RN64(tag->value);
> - ff_schro_queue_push_back(&p_schro_params->dec_frame_queue,
> - framewithpts);
> - }
> - break;
> - case SCHRO_DECODER_EOS:
> - go = 0;
> - p_schro_params->eos_pulled = 1;
> - schro_decoder_reset(decoder);
> - outer = 0;
> - break;
> -
> - case SCHRO_DECODER_ERROR:
> - return -1;
> - break;
> - }
> - }
> - } while (outer);
> -
> - /* Grab next frame to be returned from the top of the queue. */
> - framewithpts = ff_schro_queue_pop(&p_schro_params->dec_frame_queue);
> -
> - if (framewithpts && framewithpts->frame && framewithpts->frame->components[0].stride) {
> - if ((ret = ff_get_buffer(avctx, avframe, 0)) < 0) {
> - goto end;
> - }
> -
> - memcpy(avframe->data[0],
> - framewithpts->frame->components[0].data,
> - framewithpts->frame->components[0].length);
> -
> - memcpy(avframe->data[1],
> - framewithpts->frame->components[1].data,
> - framewithpts->frame->components[1].length);
> -
> - memcpy(avframe->data[2],
> - framewithpts->frame->components[2].data,
> - framewithpts->frame->components[2].length);
> -
> - /* Fill frame with current buffer data from Schroedinger. */
> - avframe->pts = framewithpts->pts;
> -#if FF_API_PKT_PTS
> -FF_DISABLE_DEPRECATION_WARNINGS
> - avframe->pkt_pts = avframe->pts;
> -FF_ENABLE_DEPRECATION_WARNINGS
> -#endif
> - avframe->linesize[0] = framewithpts->frame->components[0].stride;
> - avframe->linesize[1] = framewithpts->frame->components[1].stride;
> - avframe->linesize[2] = framewithpts->frame->components[2].stride;
> -
> - *got_frame = 1;
> - } else {
> - data = NULL;
> - *got_frame = 0;
> - }
> - ret = buf_size;
> -end:
> - /* Now free the frame resources. */
> - if (framewithpts && framewithpts->frame)
> - libschroedinger_decode_frame_free(framewithpts->frame);
> - av_freep(&framewithpts);
> - return ret;
> -}
> -
> -
> -static av_cold int libschroedinger_decode_close(AVCodecContext *avctx)
> -{
> - SchroDecoderParams *p_schro_params = avctx->priv_data;
> - /* Free the decoder. */
> - schro_decoder_free(p_schro_params->decoder);
> - av_freep(&p_schro_params->format);
> -
> - /* Free data in the output frame queue. */
> - ff_schro_queue_free(&p_schro_params->dec_frame_queue,
> - libschroedinger_decode_frame_free);
> -
> - return 0;
> -}
> -
> -static void libschroedinger_flush(AVCodecContext *avctx)
> -{
> - /* Got a seek request. Free the decoded frames queue and then reset
> - * the decoder */
> - SchroDecoderParams *p_schro_params = avctx->priv_data;
> -
> - /* Free data in the output frame queue. */
> - ff_schro_queue_free(&p_schro_params->dec_frame_queue,
> - libschroedinger_decode_frame_free);
> -
> - ff_schro_queue_init(&p_schro_params->dec_frame_queue);
> - schro_decoder_reset(p_schro_params->decoder);
> - p_schro_params->eos_pulled = 0;
> - p_schro_params->eos_signalled = 0;
> -}
> -
> -AVCodec ff_libschroedinger_decoder = {
> - .name = "libschroedinger",
> - .long_name = NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"),
> - .type = AVMEDIA_TYPE_VIDEO,
> - .id = AV_CODEC_ID_DIRAC,
> - .priv_data_size = sizeof(SchroDecoderParams),
> - .init = libschroedinger_decode_init,
> - .close = libschroedinger_decode_close,
> - .decode = libschroedinger_decode_frame,
> - .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1,
> - .flush = libschroedinger_flush,
> -};
> diff --git a/libavcodec/libschroedingerenc.c b/libavcodec/libschroedingerenc.c
> deleted file mode 100644
> index cf4baa1d82..0000000000
> --- a/libavcodec/libschroedingerenc.c
> +++ /dev/null
> @@ -1,485 +0,0 @@
> -/*
> - * Dirac encoder support via Schroedinger libraries
> - * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
> - *
> - * This file is part of FFmpeg.
> - *
> - * FFmpeg is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU Lesser General Public
> - * License as published by the Free Software Foundation; either
> - * version 2.1 of the License, or (at your option) any later version.
> - *
> - * FFmpeg is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> - * Lesser General Public License for more details.
> - *
> - * You should have received a copy of the GNU Lesser General Public
> - * License along with FFmpeg; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> - */
> -
> -/**
> -* @file
> -* Dirac encoder support via libschroedinger-1.0 libraries. More details about
> -* the Schroedinger project can be found at http://www.diracvideo.org/.
> -* The library implements Dirac Specification Version 2.2
> -* (http://dirac.sourceforge.net/specification.html).
> -*/
> -
> -#include <schroedinger/schro.h>
> -#include <schroedinger/schrodebug.h>
> -#include <schroedinger/schrovideoformat.h>
> -
> -#include "libavutil/attributes.h"
> -#include "libavutil/avassert.h"
> -#include "libavutil/imgutils.h"
> -#include "libavutil/opt.h"
> -
> -#include "avcodec.h"
> -#include "internal.h"
> -#include "libschroedinger.h"
> -#include "bytestream.h"
> -
> -
> -/** libschroedinger encoder private data */
> -typedef struct SchroEncoderParams {
> - AVClass *class;
> -
> - /** Schroedinger video format */
> - SchroVideoFormat *format;
> -
> - /** Schroedinger frame format */
> - SchroFrameFormat frame_format;
> -
> - /** frame size */
> - int frame_size;
> -
> - /** Schroedinger encoder handle*/
> - SchroEncoder* encoder;
> -
> - /** buffer to store encoder output before writing it to the frame queue*/
> - unsigned char *enc_buf;
> -
> - /** Size of encoder buffer*/
> - int enc_buf_size;
> -
> - /** queue storing encoded frames */
> - FFSchroQueue enc_frame_queue;
> -
> - /** end of sequence signalled */
> - int eos_signalled;
> -
> - /** end of sequence pulled */
> - int eos_pulled;
> -
> - /* counter for frames submitted to encoder, used as dts */
> - int64_t dts;
> -
> - /** enable noarith */
> - int noarith;
> -} SchroEncoderParams;
> -
> -/**
> -* Works out Schro-compatible chroma format.
> -*/
> -static int set_chroma_format(AVCodecContext *avctx)
> -{
> - int num_formats = sizeof(schro_pixel_format_map) /
> - sizeof(schro_pixel_format_map[0]);
> - int idx;
> -
> - SchroEncoderParams *p_schro_params = avctx->priv_data;
> -
> - for (idx = 0; idx < num_formats; ++idx) {
> - if (schro_pixel_format_map[idx].ff_pix_fmt == avctx->pix_fmt) {
> - p_schro_params->format->chroma_format =
> - schro_pixel_format_map[idx].schro_pix_fmt;
> - return 0;
> - }
> - }
> -
> - av_log(avctx, AV_LOG_ERROR,
> - "This codec currently only supports planar YUV 4:2:0, 4:2:2"
> - " and 4:4:4 formats.\n");
> -
> - return -1;
> -}
> -
> -static av_cold int libschroedinger_encode_init(AVCodecContext *avctx)
> -{
> - SchroEncoderParams *p_schro_params = avctx->priv_data;
> - SchroVideoFormatEnum preset;
> -
> - /* Initialize the libraries that libschroedinger depends on. */
> - schro_init();
> -
> - /* Create an encoder object. */
> - p_schro_params->encoder = schro_encoder_new();
> -
> - if (!p_schro_params->encoder) {
> - av_log(avctx, AV_LOG_ERROR,
> - "Unrecoverable Error: schro_encoder_new failed. ");
> - return -1;
> - }
> -
> - /* Initialize the format. */
> - preset = ff_get_schro_video_format_preset(avctx);
> - p_schro_params->format =
> - schro_encoder_get_video_format(p_schro_params->encoder);
> - schro_video_format_set_std_video_format(p_schro_params->format, preset);
> - p_schro_params->format->width = avctx->width;
> - p_schro_params->format->height = avctx->height;
> -
> - if (set_chroma_format(avctx) == -1)
> - return -1;
> -
> - if (avctx->color_primaries == AVCOL_PRI_BT709) {
> - p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_HDTV;
> - } else if (avctx->color_primaries == AVCOL_PRI_BT470BG) {
> - p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_625;
> - } else if (avctx->color_primaries == AVCOL_PRI_SMPTE170M) {
> - p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_525;
> - }
> -
> - if (avctx->colorspace == AVCOL_SPC_BT709) {
> - p_schro_params->format->colour_matrix = SCHRO_COLOUR_MATRIX_HDTV;
> - } else if (avctx->colorspace == AVCOL_SPC_BT470BG) {
> - p_schro_params->format->colour_matrix = SCHRO_COLOUR_MATRIX_SDTV;
> - }
> -
> - if (avctx->color_trc == AVCOL_TRC_BT709) {
> - p_schro_params->format->transfer_function = SCHRO_TRANSFER_CHAR_TV_GAMMA;
> - }
> -
> - if (ff_get_schro_frame_format(p_schro_params->format->chroma_format,
> - &p_schro_params->frame_format) == -1) {
> - av_log(avctx, AV_LOG_ERROR,
> - "This codec currently supports only planar YUV 4:2:0, 4:2:2"
> - " and 4:4:4 formats.\n");
> - return -1;
> - }
> -
> - p_schro_params->format->frame_rate_numerator = avctx->time_base.den;
> - p_schro_params->format->frame_rate_denominator = avctx->time_base.num;
> -
> - p_schro_params->frame_size = av_image_get_buffer_size(avctx->pix_fmt,
> - avctx->width,
> - avctx->height, 1);
> -
> - if (!avctx->gop_size) {
> - schro_encoder_setting_set_double(p_schro_params->encoder,
> - "gop_structure",
> - SCHRO_ENCODER_GOP_INTRA_ONLY);
> -
> -#if FF_API_CODER_TYPE
> -FF_DISABLE_DEPRECATION_WARNINGS
> - if (avctx->coder_type != FF_CODER_TYPE_VLC)
> - p_schro_params->noarith = 0;
> -FF_ENABLE_DEPRECATION_WARNINGS
> -#endif
> - schro_encoder_setting_set_double(p_schro_params->encoder,
> - "enable_noarith",
> - p_schro_params->noarith);
> - } else {
> - schro_encoder_setting_set_double(p_schro_params->encoder,
> - "au_distance", avctx->gop_size);
> - avctx->has_b_frames = 1;
> - p_schro_params->dts = -1;
> - }
> -
> - /* FIXME - Need to handle SCHRO_ENCODER_RATE_CONTROL_LOW_DELAY. */
> - if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
> - if (!avctx->global_quality) {
> - /* lossless coding */
> - schro_encoder_setting_set_double(p_schro_params->encoder,
> - "rate_control",
> - SCHRO_ENCODER_RATE_CONTROL_LOSSLESS);
> - } else {
> - int quality;
> - schro_encoder_setting_set_double(p_schro_params->encoder,
> - "rate_control",
> - SCHRO_ENCODER_RATE_CONTROL_CONSTANT_QUALITY);
> -
> - quality = avctx->global_quality / FF_QP2LAMBDA;
> - if (quality > 10)
> - quality = 10;
> - schro_encoder_setting_set_double(p_schro_params->encoder,
> - "quality", quality);
> - }
> - } else {
> - schro_encoder_setting_set_double(p_schro_params->encoder,
> - "rate_control",
> - SCHRO_ENCODER_RATE_CONTROL_CONSTANT_BITRATE);
> -
> - schro_encoder_setting_set_double(p_schro_params->encoder,
> - "bitrate", avctx->bit_rate);
> - }
> -
> - if (avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)
> - /* All material can be coded as interlaced or progressive
> - irrespective of the type of source material. */
> - schro_encoder_setting_set_double(p_schro_params->encoder,
> - "interlaced_coding", 1);
> -
> - schro_encoder_setting_set_double(p_schro_params->encoder, "open_gop",
> - !(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP));
> -
> - /* FIXME: Signal range hardcoded to 8-bit data until both libschroedinger
> - * and libdirac support other bit-depth data. */
> - schro_video_format_set_std_signal_range(p_schro_params->format,
> - SCHRO_SIGNAL_RANGE_8BIT_VIDEO);
> -
> - /* Set the encoder format. */
> - schro_encoder_set_video_format(p_schro_params->encoder,
> - p_schro_params->format);
> -
> - /* Set the debug level. */
> - schro_debug_set_level(avctx->debug);
> -
> - schro_encoder_start(p_schro_params->encoder);
> -
> - /* Initialize the encoded frame queue. */
> - ff_schro_queue_init(&p_schro_params->enc_frame_queue);
> - return 0;
> -}
> -
> -static SchroFrame *libschroedinger_frame_from_data(AVCodecContext *avctx,
> - const AVFrame *frame)
> -{
> - SchroEncoderParams *p_schro_params = avctx->priv_data;
> - SchroFrame *in_frame = ff_create_schro_frame(avctx,
> - p_schro_params->frame_format);
> -
> - if (in_frame) {
> - /* Copy input data to SchroFrame buffers (they match the ones
> - * referenced by the AVFrame stored in priv) */
> - if (av_frame_copy(in_frame->priv, frame) < 0) {
> - av_log(avctx, AV_LOG_ERROR, "Failed to copy input data\n");
> - return NULL;
> - }
> - }
> -
> - return in_frame;
> -}
> -
> -static void libschroedinger_free_frame(void *data)
> -{
> - FFSchroEncodedFrame *enc_frame = data;
> -
> - av_freep(&enc_frame->p_encbuf);
> - av_free(enc_frame);
> -}
> -
> -static int libschroedinger_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
> - const AVFrame *frame, int *got_packet)
> -{
> - int enc_size = 0;
> - SchroEncoderParams *p_schro_params = avctx->priv_data;
> - SchroEncoder *encoder = p_schro_params->encoder;
> - struct FFSchroEncodedFrame *p_frame_output = NULL;
> - int go = 1;
> - SchroBuffer *enc_buf;
> - int presentation_frame;
> - int parse_code;
> - int last_frame_in_sequence = 0;
> - int pkt_size, ret;
> -
> - if (!frame) {
> - /* Push end of sequence if not already signalled. */
> - if (!p_schro_params->eos_signalled) {
> - schro_encoder_end_of_stream(encoder);
> - p_schro_params->eos_signalled = 1;
> - }
> - } else {
> - /* Allocate frame data to schro input buffer. */
> - SchroFrame *in_frame = libschroedinger_frame_from_data(avctx, frame);
> - if (!in_frame)
> - return AVERROR(ENOMEM);
> - /* Load next frame. */
> - schro_encoder_push_frame(encoder, in_frame);
> - }
> -
> - if (p_schro_params->eos_pulled)
> - go = 0;
> -
> - /* Now check to see if we have any output from the encoder. */
> - while (go) {
> - int err;
> - SchroStateEnum state;
> - state = schro_encoder_wait(encoder);
> - switch (state) {
> - case SCHRO_STATE_HAVE_BUFFER:
> - case SCHRO_STATE_END_OF_STREAM:
> - enc_buf = schro_encoder_pull(encoder, &presentation_frame);
> - if (enc_buf->length <= 0)
> - return AVERROR_BUG;
> - parse_code = enc_buf->data[4];
> -
> - /* All non-frame data is prepended to actual frame data to
> - * be able to set the pts correctly. So we don't write data
> - * to the frame output queue until we actually have a frame
> - */
> - if ((err = av_reallocp(&p_schro_params->enc_buf,
> - p_schro_params->enc_buf_size +
> - enc_buf->length)) < 0) {
> - p_schro_params->enc_buf_size = 0;
> - return err;
> - }
> -
> - memcpy(p_schro_params->enc_buf + p_schro_params->enc_buf_size,
> - enc_buf->data, enc_buf->length);
> - p_schro_params->enc_buf_size += enc_buf->length;
> -
> -
> - if (state == SCHRO_STATE_END_OF_STREAM) {
> - p_schro_params->eos_pulled = 1;
> - go = 0;
> - }
> -
> - if (!SCHRO_PARSE_CODE_IS_PICTURE(parse_code)) {
> - schro_buffer_unref(enc_buf);
> - break;
> - }
> -
> - /* Create output frame. */
> - p_frame_output = av_mallocz(sizeof(FFSchroEncodedFrame));
> - if (!p_frame_output)
> - return AVERROR(ENOMEM);
> - /* Set output data. */
> - p_frame_output->size = p_schro_params->enc_buf_size;
> - p_frame_output->p_encbuf = p_schro_params->enc_buf;
> - if (SCHRO_PARSE_CODE_IS_INTRA(parse_code) &&
> - SCHRO_PARSE_CODE_IS_REFERENCE(parse_code))
> - p_frame_output->key_frame = 1;
> -
> - /* Parse the coded frame number from the bitstream. Bytes 14
> - * through 17 represent the frame number. */
> - p_frame_output->frame_num = AV_RB32(enc_buf->data + 13);
> -
> - ff_schro_queue_push_back(&p_schro_params->enc_frame_queue,
> - p_frame_output);
> - p_schro_params->enc_buf_size = 0;
> - p_schro_params->enc_buf = NULL;
> -
> - schro_buffer_unref(enc_buf);
> -
> - break;
> -
> - case SCHRO_STATE_NEED_FRAME:
> - go = 0;
> - break;
> -
> - case SCHRO_STATE_AGAIN:
> - break;
> -
> - default:
> - av_log(avctx, AV_LOG_ERROR, "Unknown Schro Encoder state\n");
> - return -1;
> - }
> - }
> -
> - /* Copy 'next' frame in queue. */
> -
> - if (p_schro_params->enc_frame_queue.size == 1 &&
> - p_schro_params->eos_pulled)
> - last_frame_in_sequence = 1;
> -
> - p_frame_output = ff_schro_queue_pop(&p_schro_params->enc_frame_queue);
> -
> - if (!p_frame_output)
> - return 0;
> -
> - pkt_size = p_frame_output->size;
> - if (last_frame_in_sequence && p_schro_params->enc_buf_size > 0)
> - pkt_size += p_schro_params->enc_buf_size;
> - if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size, 0)) < 0)
> - goto error;
> -
> - memcpy(pkt->data, p_frame_output->p_encbuf, p_frame_output->size);
> -#if FF_API_CODED_FRAME
> -FF_DISABLE_DEPRECATION_WARNINGS
> - avctx->coded_frame->key_frame = p_frame_output->key_frame;
> - avctx->coded_frame->pts = p_frame_output->frame_num;
> -FF_ENABLE_DEPRECATION_WARNINGS
> -#endif
> - /* Use the frame number of the encoded frame as the pts. It is OK to
> - * do so since Dirac is a constant frame rate codec. It expects input
> - * to be of constant frame rate. */
> - pkt->pts = p_frame_output->frame_num;
> - pkt->dts = p_schro_params->dts++;
> - enc_size = p_frame_output->size;
> -
> - /* Append the end of sequence information to the last frame in the
> - * sequence. */
> - if (last_frame_in_sequence && p_schro_params->enc_buf_size > 0) {
> - memcpy(pkt->data + enc_size, p_schro_params->enc_buf,
> - p_schro_params->enc_buf_size);
> - enc_size += p_schro_params->enc_buf_size;
> - av_freep(&p_schro_params->enc_buf);
> - p_schro_params->enc_buf_size = 0;
> - }
> -
> - if (p_frame_output->key_frame)
> - pkt->flags |= AV_PKT_FLAG_KEY;
> - *got_packet = 1;
> -
> -error:
> - /* free frame */
> - libschroedinger_free_frame(p_frame_output);
> - return ret;
> -}
> -
> -
> -static int libschroedinger_encode_close(AVCodecContext *avctx)
> -{
> - SchroEncoderParams *p_schro_params = avctx->priv_data;
> -
> - /* Close the encoder. */
> - schro_encoder_free(p_schro_params->encoder);
> -
> - /* Free data in the output frame queue. */
> - ff_schro_queue_free(&p_schro_params->enc_frame_queue,
> - libschroedinger_free_frame);
> -
> -
> - /* Free the encoder buffer. */
> - if (p_schro_params->enc_buf_size)
> - av_freep(&p_schro_params->enc_buf);
> -
> - /* Free the video format structure. */
> - av_freep(&p_schro_params->format);
> -
> - return 0;
> -}
> -
> -#define OFFSET(x) offsetof(SchroEncoderParams, x)
> -#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> -static const AVOption options[] = {
> - { "noarith", "Enable noarith", OFFSET(noarith), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
> -
> - { NULL },
> -};
> -
> -static const AVClass libschroedinger_class = {
> - .class_name = "libschroedinger",
> - .item_name = av_default_item_name,
> - .option = options,
> - .version = LIBAVUTIL_VERSION_INT,
> -};
> -
> -AVCodec ff_libschroedinger_encoder = {
> - .name = "libschroedinger",
> - .long_name = NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"),
> - .type = AVMEDIA_TYPE_VIDEO,
> - .id = AV_CODEC_ID_DIRAC,
> - .priv_data_size = sizeof(SchroEncoderParams),
> - .priv_class = &libschroedinger_class,
> - .init = libschroedinger_encode_init,
> - .encode2 = libschroedinger_encode_frame,
> - .close = libschroedinger_encode_close,
> - .capabilities = AV_CODEC_CAP_DELAY,
> - .pix_fmts = (const enum AVPixelFormat[]){
> - AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_NONE
> - },
> -};
LGTM
A few security bugs less!
More information about the ffmpeg-devel
mailing list