Browse code

lavc: remove libschroedinger encoding and decoding wrappers

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 basic
encoding support is still provided via the native vc2 (Dirac Pro, intra
only version of Dirac) encoder. Hence, there's no reason to still support
linking to the library and potentially leading users into security issues.

Rostislav Pehlivanov authored on 2017/05/29 06:01:40
Showing 11 changed files
... ...
@@ -15,6 +15,7 @@ version <next>:
15 15
 - crossfeed audio filter
16 16
 - spec compliant VP9 muxing support in MP4
17 17
 - remove the libnut muxer/demuxer wrappers
18
+- remove the libschroedinger encoder/decoder wrappers
18 19
 
19 20
 version 3.3:
20 21
 - CrystalHD decoder moved to new decode API
... ...
@@ -192,7 +192,6 @@ Codecs:
192 192
   libkvazaar.c                          Arttu Ylä-Outinen
193 193
   libopenjpeg.c                         Jaikrishnan Menon
194 194
   libopenjpegenc.c                      Michael Bradshaw
195
-  libschroedinger*                      David Conrad
196 195
   libtheoraenc.c                        David Conrad
197 196
   libvorbis.c                           David Conrad
198 197
   libvpx*                               James Zern
... ...
@@ -245,7 +245,6 @@ External library support:
245 245
   --enable-librsvg         enable SVG rasterization via librsvg [no]
246 246
   --enable-librubberband   enable rubberband needed for rubberband filter [no]
247 247
   --enable-librtmp         enable RTMP[E] support via librtmp [no]
248
-  --enable-libschroedinger enable Dirac de/encoding via libschroedinger [no]
249 248
   --enable-libshine        enable fixed-point MP3 encoding via libshine [no]
250 249
   --enable-libsmbclient    enable Samba protocol via libsmbclient [no]
251 250
   --enable-libsnappy       enable Snappy compression, needed for hap encoding [no]
... ...
@@ -1559,7 +1558,6 @@ EXTERNAL_LIBRARY_LIST="
1559 1559
     libpulse
1560 1560
     librsvg
1561 1561
     librtmp
1562
-    libschroedinger
1563 1562
     libshine
1564 1563
     libsmbclient
1565 1564
     libsnappy
... ...
@@ -2874,8 +2872,6 @@ libopus_decoder_deps="libopus"
2874 2874
 libopus_encoder_deps="libopus"
2875 2875
 libopus_encoder_select="audio_frame_queue"
2876 2876
 librsvg_decoder_deps="librsvg"
2877
-libschroedinger_decoder_deps="libschroedinger"
2878
-libschroedinger_encoder_deps="libschroedinger"
2879 2877
 libshine_encoder_deps="libshine"
2880 2878
 libshine_encoder_select="audio_frame_queue"
2881 2879
 libspeex_decoder_deps="libspeex"
... ...
@@ -5847,7 +5843,6 @@ enabled libpulse          && require_pkg_config libpulse pulse/pulseaudio.h pa_c
5847 5847
 enabled librsvg           && require_pkg_config librsvg-2.0 librsvg-2.0/librsvg/rsvg.h rsvg_handle_render_cairo
5848 5848
 enabled librtmp           && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
5849 5849
 enabled librubberband     && require_pkg_config "rubberband >= 1.8.1" rubberband/rubberband-c.h rubberband_new
5850
-enabled libschroedinger   && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
5851 5850
 enabled libshine          && require_pkg_config shine shine/layer3.h shine_encode_buffer
5852 5851
 enabled libsmbclient      && { use_pkg_config smbclient libsmbclient.h smbc_init ||
5853 5852
                                require smbclient libsmbclient.h smbc_init -lsmbclient; }
... ...
@@ -711,7 +711,7 @@ following image formats are supported:
711 711
 @item DFA                    @tab     @tab  X
712 712
     @tab Codec used in Chronomaster game.
713 713
 @item Dirac                  @tab  E  @tab  X
714
-    @tab supported through external library libschroedinger
714
+    @tab supported though the native vc2 (Dirac Pro) encoder
715 715
 @item Deluxe Paint Animation @tab     @tab  X
716 716
 @item DNxHD                  @tab   X @tab  X
717 717
     @tab aka SMPTE VC3
... ...
@@ -315,7 +315,7 @@ These library packages are only available from
315 315
 
316 316
 @example
317 317
 yasm, libSDL-devel, libgsm-devel, libmp3lame-devel,
318
-libschroedinger1.0-devel, speex-devel, libtheora-devel, libxvidcore-devel
318
+speex-devel, libtheora-devel, libxvidcore-devel
319 319
 @end example
320 320
 
321 321
 The recommendation for x264 is to build it from source, as it evolves too
... ...
@@ -902,10 +902,6 @@ OBJS-$(CONFIG_LIBOPUS_DECODER)            += libopusdec.o libopus.o     \
902 902
                                              vorbis_data.o
903 903
 OBJS-$(CONFIG_LIBOPUS_ENCODER)            += libopusenc.o libopus.o     \
904 904
                                              vorbis_data.o
905
-OBJS-$(CONFIG_LIBSCHROEDINGER_DECODER)    += libschroedingerdec.o \
906
-                                             libschroedinger.o
907
-OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER)    += libschroedingerenc.o \
908
-                                             libschroedinger.o
909 905
 OBJS-$(CONFIG_LIBSHINE_ENCODER)           += libshine.o
910 906
 OBJS-$(CONFIG_LIBSPEEX_DECODER)           += libspeexdec.o
911 907
 OBJS-$(CONFIG_LIBSPEEX_ENCODER)           += libspeexenc.o
... ...
@@ -1025,7 +1021,6 @@ SKIPHEADERS                            += %_tablegen.h                  \
1025 1025
 SKIPHEADERS-$(CONFIG_D3D11VA)          += d3d11va.h dxva2_internal.h
1026 1026
 SKIPHEADERS-$(CONFIG_DXVA2)            += dxva2.h dxva2_internal.h
1027 1027
 SKIPHEADERS-$(CONFIG_JNI)              += ffjni.h
1028
-SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER)  += libschroedinger.h
1029 1028
 SKIPHEADERS-$(CONFIG_LIBVPX)           += libvpx.h
1030 1029
 SKIPHEADERS-$(CONFIG_LIBWEBP_ENCODER)  += libwebpenc_common.h
1031 1030
 SKIPHEADERS-$(CONFIG_MEDIACODEC)       += mediacodecdec_common.h mediacodec_surface.h mediacodec_wrapper.h mediacodec_sw_buffer.h
... ...
@@ -617,7 +617,6 @@ static void register_all(void)
617 617
     REGISTER_ENCDEC (LIBOPENJPEG,       libopenjpeg);
618 618
     REGISTER_ENCDEC (LIBOPUS,           libopus);
619 619
     REGISTER_DECODER(LIBRSVG,           librsvg);
620
-    REGISTER_ENCDEC (LIBSCHROEDINGER,   libschroedinger);
621 620
     REGISTER_ENCODER(LIBSHINE,          libshine);
622 621
     REGISTER_ENCDEC (LIBSPEEX,          libspeex);
623 622
     REGISTER_ENCODER(LIBTHEORA,         libtheora);
624 623
deleted file mode 100644
... ...
@@ -1,221 +0,0 @@
1
-/*
2
- * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
3
- *
4
- * This file is part of FFmpeg.
5
- *
6
- * FFmpeg is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * FFmpeg is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with FFmpeg; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
-/**
22
-* @file
23
-* function definitions common to libschroedinger decoder and encoder
24
-*/
25
-
26
-#include "libavutil/attributes.h"
27
-#include "libavutil/mem.h"
28
-#include "libschroedinger.h"
29
-#include "internal.h"
30
-
31
-static const SchroVideoFormatInfo ff_schro_video_format_info[] = {
32
-    { 640,  480,  24000, 1001},
33
-    { 176,  120,  15000, 1001},
34
-    { 176,  144,  25,    2   },
35
-    { 352,  240,  15000, 1001},
36
-    { 352,  288,  25,    2   },
37
-    { 704,  480,  15000, 1001},
38
-    { 704,  576,  25,    2   },
39
-    { 720,  480,  30000, 1001},
40
-    { 720,  576,  25,    1   },
41
-    { 1280, 720,  60000, 1001},
42
-    { 1280, 720,  50,    1   },
43
-    { 1920, 1080, 30000, 1001},
44
-    { 1920, 1080, 25,    1   },
45
-    { 1920, 1080, 60000, 1001},
46
-    { 1920, 1080, 50,    1   },
47
-    { 2048, 1080, 24,    1   },
48
-    { 4096, 2160, 24,    1   },
49
-};
50
-
51
-static unsigned int get_video_format_idx(AVCodecContext *avctx)
52
-{
53
-    unsigned int ret_idx = 0;
54
-    unsigned int idx;
55
-    unsigned int num_formats = sizeof(ff_schro_video_format_info) /
56
-                               sizeof(ff_schro_video_format_info[0]);
57
-
58
-    for (idx = 1; idx < num_formats; ++idx) {
59
-        const SchroVideoFormatInfo *vf = &ff_schro_video_format_info[idx];
60
-        if (avctx->width  == vf->width &&
61
-            avctx->height == vf->height) {
62
-            ret_idx = idx;
63
-            if (avctx->time_base.den == vf->frame_rate_num &&
64
-                avctx->time_base.num == vf->frame_rate_denom)
65
-                return idx;
66
-        }
67
-    }
68
-    return ret_idx;
69
-}
70
-
71
-av_cold void ff_schro_queue_init(FFSchroQueue *queue)
72
-{
73
-    queue->p_head = queue->p_tail = NULL;
74
-    queue->size = 0;
75
-}
76
-
77
-void ff_schro_queue_free(FFSchroQueue *queue, void (*free_func)(void *))
78
-{
79
-    while (queue->p_head)
80
-        free_func(ff_schro_queue_pop(queue));
81
-}
82
-
83
-int ff_schro_queue_push_back(FFSchroQueue *queue, void *p_data)
84
-{
85
-    FFSchroQueueElement *p_new = av_mallocz(sizeof(FFSchroQueueElement));
86
-
87
-    if (!p_new)
88
-        return -1;
89
-
90
-    p_new->data = p_data;
91
-
92
-    if (!queue->p_head)
93
-        queue->p_head = p_new;
94
-    else
95
-        queue->p_tail->next = p_new;
96
-    queue->p_tail = p_new;
97
-
98
-    ++queue->size;
99
-    return 0;
100
-}
101
-
102
-void *ff_schro_queue_pop(FFSchroQueue *queue)
103
-{
104
-    FFSchroQueueElement *top = queue->p_head;
105
-
106
-    if (top) {
107
-        void *data = top->data;
108
-        queue->p_head = queue->p_head->next;
109
-        --queue->size;
110
-        av_freep(&top);
111
-        return data;
112
-    }
113
-
114
-    return NULL;
115
-}
116
-
117
-/**
118
-* Schroedinger video preset table. Ensure that this tables matches up correctly
119
-* with the ff_schro_video_format_info table.
120
-*/
121
-static const SchroVideoFormatEnum ff_schro_video_formats[]={
122
-    SCHRO_VIDEO_FORMAT_CUSTOM     ,
123
-    SCHRO_VIDEO_FORMAT_QSIF       ,
124
-    SCHRO_VIDEO_FORMAT_QCIF       ,
125
-    SCHRO_VIDEO_FORMAT_SIF        ,
126
-    SCHRO_VIDEO_FORMAT_CIF        ,
127
-    SCHRO_VIDEO_FORMAT_4SIF       ,
128
-    SCHRO_VIDEO_FORMAT_4CIF       ,
129
-    SCHRO_VIDEO_FORMAT_SD480I_60  ,
130
-    SCHRO_VIDEO_FORMAT_SD576I_50  ,
131
-    SCHRO_VIDEO_FORMAT_HD720P_60  ,
132
-    SCHRO_VIDEO_FORMAT_HD720P_50  ,
133
-    SCHRO_VIDEO_FORMAT_HD1080I_60 ,
134
-    SCHRO_VIDEO_FORMAT_HD1080I_50 ,
135
-    SCHRO_VIDEO_FORMAT_HD1080P_60 ,
136
-    SCHRO_VIDEO_FORMAT_HD1080P_50 ,
137
-    SCHRO_VIDEO_FORMAT_DC2K_24    ,
138
-    SCHRO_VIDEO_FORMAT_DC4K_24    ,
139
-};
140
-
141
-SchroVideoFormatEnum ff_get_schro_video_format_preset(AVCodecContext *avctx)
142
-{
143
-    unsigned int num_formats = sizeof(ff_schro_video_formats) /
144
-                               sizeof(ff_schro_video_formats[0]);
145
-
146
-    unsigned int idx = get_video_format_idx(avctx);
147
-
148
-    return (idx < num_formats) ? ff_schro_video_formats[idx] :
149
-                                 SCHRO_VIDEO_FORMAT_CUSTOM;
150
-}
151
-
152
-int ff_get_schro_frame_format (SchroChromaFormat schro_pix_fmt,
153
-                               SchroFrameFormat  *schro_frame_fmt)
154
-{
155
-    unsigned int num_formats = sizeof(schro_pixel_format_map) /
156
-                               sizeof(schro_pixel_format_map[0]);
157
-
158
-    int idx;
159
-
160
-    for (idx = 0; idx < num_formats; ++idx) {
161
-        if (schro_pixel_format_map[idx].schro_pix_fmt == schro_pix_fmt) {
162
-            *schro_frame_fmt = schro_pixel_format_map[idx].schro_frame_fmt;
163
-            return 0;
164
-        }
165
-    }
166
-    return -1;
167
-}
168
-
169
-static void free_schro_frame(SchroFrame *frame, void *priv)
170
-{
171
-    AVFrame *p_pic = priv;
172
-    av_frame_free(&p_pic);
173
-}
174
-
175
-SchroFrame *ff_create_schro_frame(AVCodecContext *avctx,
176
-                                  SchroFrameFormat schro_frame_fmt)
177
-{
178
-    AVFrame *p_pic;
179
-    SchroFrame *p_frame;
180
-    int y_width, uv_width;
181
-    int y_height, uv_height;
182
-    int i;
183
-
184
-    y_width   = avctx->width;
185
-    y_height  = avctx->height;
186
-    uv_width  = y_width  >> (SCHRO_FRAME_FORMAT_H_SHIFT(schro_frame_fmt));
187
-    uv_height = y_height >> (SCHRO_FRAME_FORMAT_V_SHIFT(schro_frame_fmt));
188
-
189
-    p_pic = av_frame_alloc();
190
-    if (!p_pic)
191
-        return NULL;
192
-
193
-    if (ff_get_buffer(avctx, p_pic, AV_GET_BUFFER_FLAG_REF) < 0) {
194
-        av_frame_free(&p_pic);
195
-        return NULL;
196
-    }
197
-
198
-    p_frame         = schro_frame_new();
199
-    p_frame->format = schro_frame_fmt;
200
-    p_frame->width  = y_width;
201
-    p_frame->height = y_height;
202
-    schro_frame_set_free_callback(p_frame, free_schro_frame, p_pic);
203
-
204
-    for (i = 0; i < 3; ++i) {
205
-        p_frame->components[i].width  = i ? uv_width : y_width;
206
-        p_frame->components[i].stride = p_pic->linesize[i];
207
-        p_frame->components[i].height = i ? uv_height : y_height;
208
-        p_frame->components[i].length =
209
-                 p_frame->components[i].stride * p_frame->components[i].height;
210
-        p_frame->components[i].data   = p_pic->data[i];
211
-
212
-        if (i) {
213
-            p_frame->components[i].v_shift =
214
-                SCHRO_FRAME_FORMAT_V_SHIFT(p_frame->format);
215
-            p_frame->components[i].h_shift =
216
-                SCHRO_FRAME_FORMAT_H_SHIFT(p_frame->format);
217
-        }
218
-    }
219
-
220
-    return p_frame;
221
-}
222 1
deleted file mode 100644
... ...
@@ -1,133 +0,0 @@
1
-/*
2
- * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
3
- *
4
- * This file is part of FFmpeg.
5
- *
6
- * FFmpeg is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * FFmpeg is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with FFmpeg; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
-/**
22
-* @file
23
-* data structures common to libschroedinger decoder and encoder
24
-*/
25
-
26
-#ifndef AVCODEC_LIBSCHROEDINGER_H
27
-#define AVCODEC_LIBSCHROEDINGER_H
28
-
29
-#include <schroedinger/schrobitstream.h>
30
-#include <schroedinger/schroframe.h>
31
-
32
-#include "avcodec.h"
33
-
34
-typedef struct SchroVideoFormatInfo {
35
-    uint16_t width;
36
-    uint16_t height;
37
-    uint16_t frame_rate_num;
38
-    uint16_t frame_rate_denom;
39
-} SchroVideoFormatInfo;
40
-
41
-/**
42
-* contains a single encoded frame returned from Dirac or Schroedinger
43
-*/
44
-typedef struct FFSchroEncodedFrame {
45
-    /** encoded frame data */
46
-    uint8_t *p_encbuf;
47
-
48
-    /** encoded frame size */
49
-    uint32_t size;
50
-
51
-    /** encoded frame number. Will be used as pts */
52
-    uint32_t frame_num;
53
-
54
-    /** key frame flag. 1 : is key frame , 0 : in not key frame */
55
-    uint16_t key_frame;
56
-} FFSchroEncodedFrame;
57
-
58
-/**
59
-* queue element
60
-*/
61
-typedef struct FFSchroQueueElement {
62
-    /** Data to be stored in queue*/
63
-    void *data;
64
-    /** Pointer to next element queue */
65
-    struct FFSchroQueueElement *next;
66
-} FFSchroQueueElement;
67
-
68
-
69
-/**
70
-* A simple queue implementation used in libschroedinger
71
-*/
72
-typedef struct FFSchroQueue {
73
-    /** Pointer to head of queue */
74
-    FFSchroQueueElement *p_head;
75
-    /** Pointer to tail of queue */
76
-    FFSchroQueueElement *p_tail;
77
-    /** Queue size*/
78
-    int size;
79
-} FFSchroQueue;
80
-
81
-/**
82
-* Initialise the queue
83
-*/
84
-void ff_schro_queue_init(FFSchroQueue *queue);
85
-
86
-/**
87
-* Add an element to the end of the queue
88
-*/
89
-int ff_schro_queue_push_back(FFSchroQueue *queue, void *p_data);
90
-
91
-/**
92
-* Return the first element in the queue
93
-*/
94
-void *ff_schro_queue_pop(FFSchroQueue *queue);
95
-
96
-/**
97
-* Free the queue resources. free_func is a function supplied by the caller to
98
-* free any resources allocated by the caller. The data field of the queue
99
-* element is passed to it.
100
-*/
101
-void ff_schro_queue_free(FFSchroQueue *queue, void (*free_func)(void *));
102
-
103
-static const struct {
104
-    enum AVPixelFormat  ff_pix_fmt;
105
-    SchroChromaFormat schro_pix_fmt;
106
-    SchroFrameFormat  schro_frame_fmt;
107
-} schro_pixel_format_map[] = {
108
-    { AV_PIX_FMT_YUV420P, SCHRO_CHROMA_420, SCHRO_FRAME_FORMAT_U8_420 },
109
-    { AV_PIX_FMT_YUV422P, SCHRO_CHROMA_422, SCHRO_FRAME_FORMAT_U8_422 },
110
-    { AV_PIX_FMT_YUV444P, SCHRO_CHROMA_444, SCHRO_FRAME_FORMAT_U8_444 },
111
-};
112
-
113
-/**
114
-* Returns the video format preset matching the input video dimensions and
115
-* time base.
116
-*/
117
-SchroVideoFormatEnum ff_get_schro_video_format_preset (AVCodecContext *avctx);
118
-
119
-/**
120
-* Sets the Schroedinger frame format corresponding to the Schro chroma format
121
-* passed. Returns 0 on success, -1 on failure.
122
-*/
123
-int ff_get_schro_frame_format(SchroChromaFormat schro_chroma_fmt,
124
-                              SchroFrameFormat  *schro_frame_fmt);
125
-
126
-/**
127
-* Create a Schro frame based on the dimensions and frame format
128
-* passed. Returns a pointer to a frame on success, NULL on failure.
129
-*/
130
-SchroFrame *ff_create_schro_frame(AVCodecContext *avctx,
131
-                                  SchroFrameFormat schro_frame_fmt);
132
-
133
-#endif /* AVCODEC_LIBSCHROEDINGER_H */
134 1
deleted file mode 100644
... ...
@@ -1,395 +0,0 @@
1
-/*
2
- * Dirac decoder support via Schroedinger libraries
3
- * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
4
- *
5
- * This file is part of FFmpeg.
6
- *
7
- * FFmpeg is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * FFmpeg is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with FFmpeg; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- */
21
-
22
-/**
23
-* @file
24
-* Dirac decoder support via libschroedinger-1.0 libraries. More details about
25
-* the Schroedinger project can be found at http://www.diracvideo.org/.
26
-* The library implements Dirac Specification Version 2.2.
27
-* (http://dirac.sourceforge.net/specification.html).
28
-*/
29
-
30
-#include <string.h>
31
-
32
-#include "libavutil/imgutils.h"
33
-#include "libavutil/internal.h"
34
-#include "libavutil/intreadwrite.h"
35
-#include "libavutil/mem.h"
36
-#include "avcodec.h"
37
-#include "internal.h"
38
-#include "libschroedinger.h"
39
-
40
-#include <schroedinger/schro.h>
41
-#include <schroedinger/schrodebug.h>
42
-#include <schroedinger/schrovideoformat.h>
43
-
44
-/** SchroFrame and Pts relation */
45
-typedef struct LibSchroFrameContext {
46
-     SchroFrame *frame;
47
-     int64_t pts;
48
-} LibSchroFrameContext;
49
-
50
-/** libschroedinger decoder private data */
51
-typedef struct SchroDecoderParams {
52
-    /** Schroedinger video format */
53
-    SchroVideoFormat *format;
54
-
55
-    /** Schroedinger frame format */
56
-    SchroFrameFormat frame_format;
57
-
58
-    /** decoder handle */
59
-    SchroDecoder* decoder;
60
-
61
-    /** queue storing decoded frames */
62
-    FFSchroQueue dec_frame_queue;
63
-
64
-    /** end of sequence signalled */
65
-    int eos_signalled;
66
-
67
-    /** end of sequence pulled */
68
-    int eos_pulled;
69
-} SchroDecoderParams;
70
-
71
-typedef struct SchroParseUnitContext {
72
-    const uint8_t *buf;
73
-    int           buf_size;
74
-} SchroParseUnitContext;
75
-
76
-
77
-static void libschroedinger_decode_buffer_free(SchroBuffer *schro_buf,
78
-                                               void *priv)
79
-{
80
-    av_freep(&priv);
81
-}
82
-
83
-static void parse_context_init(SchroParseUnitContext *parse_ctx,
84
-                               const uint8_t *buf, int buf_size)
85
-{
86
-    parse_ctx->buf           = buf;
87
-    parse_ctx->buf_size      = buf_size;
88
-}
89
-
90
-static SchroBuffer *find_next_parse_unit(SchroParseUnitContext *parse_ctx)
91
-{
92
-    SchroBuffer *enc_buf = NULL;
93
-    int next_pu_offset = 0;
94
-    unsigned char *in_buf;
95
-
96
-    if (parse_ctx->buf_size < 13 ||
97
-        parse_ctx->buf[0] != 'B' ||
98
-        parse_ctx->buf[1] != 'B' ||
99
-        parse_ctx->buf[2] != 'C' ||
100
-        parse_ctx->buf[3] != 'D')
101
-        return NULL;
102
-
103
-    next_pu_offset = (parse_ctx->buf[5] << 24) +
104
-                     (parse_ctx->buf[6] << 16) +
105
-                     (parse_ctx->buf[7] <<  8) +
106
-                      parse_ctx->buf[8];
107
-
108
-    if (next_pu_offset == 0 &&
109
-        SCHRO_PARSE_CODE_IS_END_OF_SEQUENCE(parse_ctx->buf[4]))
110
-        next_pu_offset = 13;
111
-
112
-    if (next_pu_offset <= 0 || parse_ctx->buf_size < next_pu_offset)
113
-        return NULL;
114
-
115
-    in_buf = av_malloc(next_pu_offset);
116
-    if (!in_buf) {
117
-        av_log(parse_ctx, AV_LOG_ERROR, "Unable to allocate input buffer\n");
118
-        return NULL;
119
-    }
120
-
121
-    memcpy(in_buf, parse_ctx->buf, next_pu_offset);
122
-    enc_buf       = schro_buffer_new_with_data(in_buf, next_pu_offset);
123
-    enc_buf->free = libschroedinger_decode_buffer_free;
124
-    enc_buf->priv = in_buf;
125
-
126
-    parse_ctx->buf      += next_pu_offset;
127
-    parse_ctx->buf_size -= next_pu_offset;
128
-
129
-    return enc_buf;
130
-}
131
-
132
-/**
133
-* Returns FFmpeg chroma format.
134
-*/
135
-static enum AVPixelFormat get_chroma_format(SchroChromaFormat schro_pix_fmt)
136
-{
137
-    int num_formats = sizeof(schro_pixel_format_map) /
138
-                      sizeof(schro_pixel_format_map[0]);
139
-    int idx;
140
-
141
-    for (idx = 0; idx < num_formats; ++idx)
142
-        if (schro_pixel_format_map[idx].schro_pix_fmt == schro_pix_fmt)
143
-            return schro_pixel_format_map[idx].ff_pix_fmt;
144
-    return AV_PIX_FMT_NONE;
145
-}
146
-
147
-static av_cold int libschroedinger_decode_init(AVCodecContext *avctx)
148
-{
149
-
150
-    SchroDecoderParams *p_schro_params = avctx->priv_data;
151
-    /* First of all, initialize our supporting libraries. */
152
-    schro_init();
153
-
154
-    schro_debug_set_level(avctx->debug);
155
-    p_schro_params->decoder = schro_decoder_new();
156
-    schro_decoder_set_skip_ratio(p_schro_params->decoder, 1);
157
-
158
-    if (!p_schro_params->decoder)
159
-        return -1;
160
-
161
-    /* Initialize the decoded frame queue. */
162
-    ff_schro_queue_init(&p_schro_params->dec_frame_queue);
163
-    return 0;
164
-}
165
-
166
-static void libschroedinger_decode_frame_free(void *frame)
167
-{
168
-    schro_frame_unref(frame);
169
-}
170
-
171
-static void libschroedinger_handle_first_access_unit(AVCodecContext *avctx)
172
-{
173
-    SchroDecoderParams *p_schro_params = avctx->priv_data;
174
-    SchroDecoder *decoder = p_schro_params->decoder;
175
-
176
-    p_schro_params->format = schro_decoder_get_video_format(decoder);
177
-
178
-    /* Tell FFmpeg about sequence details. */
179
-    if (av_image_check_size(p_schro_params->format->width,
180
-                            p_schro_params->format->height, 0, avctx) < 0) {
181
-        av_log(avctx, AV_LOG_ERROR, "invalid dimensions (%dx%d)\n",
182
-               p_schro_params->format->width, p_schro_params->format->height);
183
-        avctx->height = avctx->width = 0;
184
-        return;
185
-    }
186
-    avctx->height  = p_schro_params->format->height;
187
-    avctx->width   = p_schro_params->format->width;
188
-    avctx->pix_fmt = get_chroma_format(p_schro_params->format->chroma_format);
189
-
190
-    if (ff_get_schro_frame_format(p_schro_params->format->chroma_format,
191
-                                  &p_schro_params->frame_format) == -1) {
192
-        av_log(avctx, AV_LOG_ERROR,
193
-               "This codec currently only supports planar YUV 4:2:0, 4:2:2 "
194
-               "and 4:4:4 formats.\n");
195
-        return;
196
-    }
197
-
198
-    avctx->framerate.num = p_schro_params->format->frame_rate_numerator;
199
-    avctx->framerate.den = p_schro_params->format->frame_rate_denominator;
200
-}
201
-
202
-static int libschroedinger_decode_frame(AVCodecContext *avctx,
203
-                                        void *data, int *got_frame,
204
-                                        AVPacket *avpkt)
205
-{
206
-    const uint8_t *buf = avpkt->data;
207
-    int buf_size = avpkt->size;
208
-    int64_t pts  = avpkt->pts;
209
-    SchroTag *tag;
210
-
211
-    SchroDecoderParams *p_schro_params = avctx->priv_data;
212
-    SchroDecoder *decoder = p_schro_params->decoder;
213
-    SchroBuffer *enc_buf;
214
-    SchroFrame* frame;
215
-    AVFrame *avframe = data;
216
-    int state;
217
-    int go = 1;
218
-    int outer = 1;
219
-    SchroParseUnitContext parse_ctx;
220
-    LibSchroFrameContext *framewithpts = NULL;
221
-    int ret;
222
-
223
-    *got_frame = 0;
224
-
225
-    parse_context_init(&parse_ctx, buf, buf_size);
226
-    if (!buf_size) {
227
-        if (!p_schro_params->eos_signalled) {
228
-            state = schro_decoder_push_end_of_stream(decoder);
229
-            p_schro_params->eos_signalled = 1;
230
-        }
231
-    }
232
-
233
-    /* Loop through all the individual parse units in the input buffer */
234
-    do {
235
-        if ((enc_buf = find_next_parse_unit(&parse_ctx))) {
236
-            /* Set Schrotag with the pts to be recovered after decoding*/
237
-            enc_buf->tag = schro_tag_new(av_malloc(sizeof(int64_t)), av_free);
238
-            if (!enc_buf->tag->value) {
239
-                av_log(avctx, AV_LOG_ERROR, "Unable to allocate SchroTag\n");
240
-                return AVERROR(ENOMEM);
241
-            }
242
-            AV_WN(64, enc_buf->tag->value, pts);
243
-            /* Push buffer into decoder. */
244
-            if (SCHRO_PARSE_CODE_IS_PICTURE(enc_buf->data[4]) &&
245
-                SCHRO_PARSE_CODE_NUM_REFS(enc_buf->data[4]) > 0)
246
-                avctx->has_b_frames = 1;
247
-            state = schro_decoder_push(decoder, enc_buf);
248
-            if (state == SCHRO_DECODER_FIRST_ACCESS_UNIT)
249
-                libschroedinger_handle_first_access_unit(avctx);
250
-            go = 1;
251
-        } else
252
-            outer = 0;
253
-
254
-        while (go) {
255
-            /* Parse data and process result. */
256
-            state = schro_decoder_wait(decoder);
257
-            switch (state) {
258
-            case SCHRO_DECODER_FIRST_ACCESS_UNIT:
259
-                libschroedinger_handle_first_access_unit(avctx);
260
-                break;
261
-
262
-            case SCHRO_DECODER_NEED_BITS:
263
-                /* Need more input data - stop iterating over what we have. */
264
-                go = 0;
265
-                break;
266
-
267
-            case SCHRO_DECODER_NEED_FRAME:
268
-                /* Decoder needs a frame - create one and push it in. */
269
-                frame = ff_create_schro_frame(avctx,
270
-                                              p_schro_params->frame_format);
271
-                if (!frame)
272
-                    return AVERROR(ENOMEM);
273
-                schro_decoder_add_output_picture(decoder, frame);
274
-                break;
275
-
276
-            case SCHRO_DECODER_OK:
277
-                /* Pull a frame out of the decoder. */
278
-                tag   = schro_decoder_get_picture_tag(decoder);
279
-                frame = schro_decoder_pull(decoder);
280
-
281
-                if (frame) {
282
-                    /* Add relation between schroframe and pts. */
283
-                    framewithpts = av_malloc(sizeof(LibSchroFrameContext));
284
-                    if (!framewithpts) {
285
-                        av_log(avctx, AV_LOG_ERROR, "Unable to allocate FrameWithPts\n");
286
-                        return AVERROR(ENOMEM);
287
-                    }
288
-                    framewithpts->frame = frame;
289
-                    framewithpts->pts   = AV_RN64(tag->value);
290
-                    ff_schro_queue_push_back(&p_schro_params->dec_frame_queue,
291
-                                             framewithpts);
292
-                }
293
-                break;
294
-            case SCHRO_DECODER_EOS:
295
-                go = 0;
296
-                p_schro_params->eos_pulled = 1;
297
-                schro_decoder_reset(decoder);
298
-                outer = 0;
299
-                break;
300
-
301
-            case SCHRO_DECODER_ERROR:
302
-                return -1;
303
-                break;
304
-            }
305
-        }
306
-    } while (outer);
307
-
308
-    /* Grab next frame to be returned from the top of the queue. */
309
-    framewithpts = ff_schro_queue_pop(&p_schro_params->dec_frame_queue);
310
-
311
-    if (framewithpts && framewithpts->frame && framewithpts->frame->components[0].stride) {
312
-        if ((ret = ff_get_buffer(avctx, avframe, 0)) < 0) {
313
-            goto end;
314
-        }
315
-
316
-        memcpy(avframe->data[0],
317
-               framewithpts->frame->components[0].data,
318
-               framewithpts->frame->components[0].length);
319
-
320
-        memcpy(avframe->data[1],
321
-               framewithpts->frame->components[1].data,
322
-               framewithpts->frame->components[1].length);
323
-
324
-        memcpy(avframe->data[2],
325
-               framewithpts->frame->components[2].data,
326
-               framewithpts->frame->components[2].length);
327
-
328
-        /* Fill frame with current buffer data from Schroedinger. */
329
-        avframe->pts = framewithpts->pts;
330
-#if FF_API_PKT_PTS
331
-FF_DISABLE_DEPRECATION_WARNINGS
332
-        avframe->pkt_pts = avframe->pts;
333
-FF_ENABLE_DEPRECATION_WARNINGS
334
-#endif
335
-        avframe->linesize[0] = framewithpts->frame->components[0].stride;
336
-        avframe->linesize[1] = framewithpts->frame->components[1].stride;
337
-        avframe->linesize[2] = framewithpts->frame->components[2].stride;
338
-
339
-        *got_frame      = 1;
340
-    } else {
341
-        data       = NULL;
342
-        *got_frame = 0;
343
-    }
344
-    ret = buf_size;
345
-end:
346
-    /* Now free the frame resources. */
347
-    if (framewithpts && framewithpts->frame)
348
-        libschroedinger_decode_frame_free(framewithpts->frame);
349
-    av_freep(&framewithpts);
350
-    return ret;
351
-}
352
-
353
-
354
-static av_cold int libschroedinger_decode_close(AVCodecContext *avctx)
355
-{
356
-    SchroDecoderParams *p_schro_params = avctx->priv_data;
357
-    /* Free the decoder. */
358
-    schro_decoder_free(p_schro_params->decoder);
359
-    av_freep(&p_schro_params->format);
360
-
361
-    /* Free data in the output frame queue. */
362
-    ff_schro_queue_free(&p_schro_params->dec_frame_queue,
363
-                        libschroedinger_decode_frame_free);
364
-
365
-    return 0;
366
-}
367
-
368
-static void libschroedinger_flush(AVCodecContext *avctx)
369
-{
370
-    /* Got a seek request. Free the decoded frames queue and then reset
371
-     * the decoder */
372
-    SchroDecoderParams *p_schro_params = avctx->priv_data;
373
-
374
-    /* Free data in the output frame queue. */
375
-    ff_schro_queue_free(&p_schro_params->dec_frame_queue,
376
-                        libschroedinger_decode_frame_free);
377
-
378
-    ff_schro_queue_init(&p_schro_params->dec_frame_queue);
379
-    schro_decoder_reset(p_schro_params->decoder);
380
-    p_schro_params->eos_pulled = 0;
381
-    p_schro_params->eos_signalled = 0;
382
-}
383
-
384
-AVCodec ff_libschroedinger_decoder = {
385
-    .name           = "libschroedinger",
386
-    .long_name      = NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"),
387
-    .type           = AVMEDIA_TYPE_VIDEO,
388
-    .id             = AV_CODEC_ID_DIRAC,
389
-    .priv_data_size = sizeof(SchroDecoderParams),
390
-    .init           = libschroedinger_decode_init,
391
-    .close          = libschroedinger_decode_close,
392
-    .decode         = libschroedinger_decode_frame,
393
-    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1,
394
-    .flush          = libschroedinger_flush,
395
-};
396 1
deleted file mode 100644
... ...
@@ -1,485 +0,0 @@
1
-/*
2
- * Dirac encoder support via Schroedinger libraries
3
- * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
4
- *
5
- * This file is part of FFmpeg.
6
- *
7
- * FFmpeg is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * FFmpeg is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with FFmpeg; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- */
21
-
22
-/**
23
-* @file
24
-* Dirac encoder support via libschroedinger-1.0 libraries. More details about
25
-* the Schroedinger project can be found at http://www.diracvideo.org/.
26
-* The library implements Dirac Specification Version 2.2
27
-* (http://dirac.sourceforge.net/specification.html).
28
-*/
29
-
30
-#include <schroedinger/schro.h>
31
-#include <schroedinger/schrodebug.h>
32
-#include <schroedinger/schrovideoformat.h>
33
-
34
-#include "libavutil/attributes.h"
35
-#include "libavutil/avassert.h"
36
-#include "libavutil/imgutils.h"
37
-#include "libavutil/opt.h"
38
-
39
-#include "avcodec.h"
40
-#include "internal.h"
41
-#include "libschroedinger.h"
42
-#include "bytestream.h"
43
-
44
-
45
-/** libschroedinger encoder private data */
46
-typedef struct SchroEncoderParams {
47
-    AVClass        *class;
48
-
49
-    /** Schroedinger video format */
50
-    SchroVideoFormat *format;
51
-
52
-    /** Schroedinger frame format */
53
-    SchroFrameFormat frame_format;
54
-
55
-    /** frame size */
56
-    int frame_size;
57
-
58
-    /** Schroedinger encoder handle*/
59
-    SchroEncoder* encoder;
60
-
61
-    /** buffer to store encoder output before writing it to the frame queue*/
62
-    unsigned char *enc_buf;
63
-
64
-    /** Size of encoder buffer*/
65
-    int enc_buf_size;
66
-
67
-    /** queue storing encoded frames */
68
-    FFSchroQueue enc_frame_queue;
69
-
70
-    /** end of sequence signalled */
71
-    int eos_signalled;
72
-
73
-    /** end of sequence pulled */
74
-    int eos_pulled;
75
-
76
-    /* counter for frames submitted to encoder, used as dts */
77
-    int64_t dts;
78
-
79
-    /** enable noarith */
80
-    int noarith;
81
-} SchroEncoderParams;
82
-
83
-/**
84
-* Works out Schro-compatible chroma format.
85
-*/
86
-static int set_chroma_format(AVCodecContext *avctx)
87
-{
88
-    int num_formats = sizeof(schro_pixel_format_map) /
89
-                      sizeof(schro_pixel_format_map[0]);
90
-    int idx;
91
-
92
-    SchroEncoderParams *p_schro_params = avctx->priv_data;
93
-
94
-    for (idx = 0; idx < num_formats; ++idx) {
95
-        if (schro_pixel_format_map[idx].ff_pix_fmt == avctx->pix_fmt) {
96
-            p_schro_params->format->chroma_format =
97
-                            schro_pixel_format_map[idx].schro_pix_fmt;
98
-            return 0;
99
-        }
100
-    }
101
-
102
-    av_log(avctx, AV_LOG_ERROR,
103
-           "This codec currently only supports planar YUV 4:2:0, 4:2:2"
104
-           " and 4:4:4 formats.\n");
105
-
106
-    return -1;
107
-}
108
-
109
-static av_cold int libschroedinger_encode_init(AVCodecContext *avctx)
110
-{
111
-    SchroEncoderParams *p_schro_params = avctx->priv_data;
112
-    SchroVideoFormatEnum preset;
113
-
114
-    /* Initialize the libraries that libschroedinger depends on. */
115
-    schro_init();
116
-
117
-    /* Create an encoder object. */
118
-    p_schro_params->encoder = schro_encoder_new();
119
-
120
-    if (!p_schro_params->encoder) {
121
-        av_log(avctx, AV_LOG_ERROR,
122
-               "Unrecoverable Error: schro_encoder_new failed. ");
123
-        return -1;
124
-    }
125
-
126
-    /* Initialize the format. */
127
-    preset = ff_get_schro_video_format_preset(avctx);
128
-    p_schro_params->format =
129
-                    schro_encoder_get_video_format(p_schro_params->encoder);
130
-    schro_video_format_set_std_video_format(p_schro_params->format, preset);
131
-    p_schro_params->format->width  = avctx->width;
132
-    p_schro_params->format->height = avctx->height;
133
-
134
-    if (set_chroma_format(avctx) == -1)
135
-        return -1;
136
-
137
-    if (avctx->color_primaries == AVCOL_PRI_BT709) {
138
-        p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_HDTV;
139
-    } else if (avctx->color_primaries == AVCOL_PRI_BT470BG) {
140
-        p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_625;
141
-    } else if (avctx->color_primaries == AVCOL_PRI_SMPTE170M) {
142
-        p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_525;
143
-    }
144
-
145
-    if (avctx->colorspace == AVCOL_SPC_BT709) {
146
-        p_schro_params->format->colour_matrix = SCHRO_COLOUR_MATRIX_HDTV;
147
-    } else if (avctx->colorspace == AVCOL_SPC_BT470BG) {
148
-        p_schro_params->format->colour_matrix = SCHRO_COLOUR_MATRIX_SDTV;
149
-    }
150
-
151
-    if (avctx->color_trc == AVCOL_TRC_BT709) {
152
-        p_schro_params->format->transfer_function = SCHRO_TRANSFER_CHAR_TV_GAMMA;
153
-    }
154
-
155
-    if (ff_get_schro_frame_format(p_schro_params->format->chroma_format,
156
-                                  &p_schro_params->frame_format) == -1) {
157
-        av_log(avctx, AV_LOG_ERROR,
158
-               "This codec currently supports only planar YUV 4:2:0, 4:2:2"
159
-               " and 4:4:4 formats.\n");
160
-        return -1;
161
-    }
162
-
163
-    p_schro_params->format->frame_rate_numerator   = avctx->time_base.den;
164
-    p_schro_params->format->frame_rate_denominator = avctx->time_base.num;
165
-
166
-    p_schro_params->frame_size = av_image_get_buffer_size(avctx->pix_fmt,
167
-                                                          avctx->width,
168
-                                                          avctx->height, 1);
169
-
170
-    if (!avctx->gop_size) {
171
-        schro_encoder_setting_set_double(p_schro_params->encoder,
172
-                                         "gop_structure",
173
-                                         SCHRO_ENCODER_GOP_INTRA_ONLY);
174
-
175
-#if FF_API_CODER_TYPE
176
-FF_DISABLE_DEPRECATION_WARNINGS
177
-        if (avctx->coder_type != FF_CODER_TYPE_VLC)
178
-            p_schro_params->noarith = 0;
179
-FF_ENABLE_DEPRECATION_WARNINGS
180
-#endif
181
-        schro_encoder_setting_set_double(p_schro_params->encoder,
182
-                                         "enable_noarith",
183
-                                         p_schro_params->noarith);
184
-    } else {
185
-        schro_encoder_setting_set_double(p_schro_params->encoder,
186
-                                         "au_distance", avctx->gop_size);
187
-        avctx->has_b_frames = 1;
188
-        p_schro_params->dts = -1;
189
-    }
190
-
191
-    /* FIXME - Need to handle SCHRO_ENCODER_RATE_CONTROL_LOW_DELAY. */
192
-    if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
193
-        if (!avctx->global_quality) {
194
-            /* lossless coding */
195
-            schro_encoder_setting_set_double(p_schro_params->encoder,
196
-                                             "rate_control",
197
-                                             SCHRO_ENCODER_RATE_CONTROL_LOSSLESS);
198
-        } else {
199
-            int quality;
200
-            schro_encoder_setting_set_double(p_schro_params->encoder,
201
-                                             "rate_control",
202
-                                             SCHRO_ENCODER_RATE_CONTROL_CONSTANT_QUALITY);
203
-
204
-            quality = avctx->global_quality / FF_QP2LAMBDA;
205
-            if (quality > 10)
206
-                quality = 10;
207
-            schro_encoder_setting_set_double(p_schro_params->encoder,
208
-                                             "quality", quality);
209
-        }
210
-    } else {
211
-        schro_encoder_setting_set_double(p_schro_params->encoder,
212
-                                         "rate_control",
213
-                                         SCHRO_ENCODER_RATE_CONTROL_CONSTANT_BITRATE);
214
-
215
-        schro_encoder_setting_set_double(p_schro_params->encoder,
216
-                                         "bitrate", avctx->bit_rate);
217
-    }
218
-
219
-    if (avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)
220
-        /* All material can be coded as interlaced or progressive
221
-           irrespective of the type of source material. */
222
-        schro_encoder_setting_set_double(p_schro_params->encoder,
223
-                                         "interlaced_coding", 1);
224
-
225
-    schro_encoder_setting_set_double(p_schro_params->encoder, "open_gop",
226
-                                     !(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP));
227
-
228
-    /* FIXME: Signal range hardcoded to 8-bit data until both libschroedinger
229
-     * and libdirac support other bit-depth data. */
230
-    schro_video_format_set_std_signal_range(p_schro_params->format,
231
-                                            SCHRO_SIGNAL_RANGE_8BIT_VIDEO);
232
-
233
-    /* Set the encoder format. */
234
-    schro_encoder_set_video_format(p_schro_params->encoder,
235
-                                   p_schro_params->format);
236
-
237
-    /* Set the debug level. */
238
-    schro_debug_set_level(avctx->debug);
239
-
240
-    schro_encoder_start(p_schro_params->encoder);
241
-
242
-    /* Initialize the encoded frame queue. */
243
-    ff_schro_queue_init(&p_schro_params->enc_frame_queue);
244
-    return 0;
245
-}
246
-
247
-static SchroFrame *libschroedinger_frame_from_data(AVCodecContext *avctx,
248
-                                                   const AVFrame *frame)
249
-{
250
-    SchroEncoderParams *p_schro_params = avctx->priv_data;
251
-    SchroFrame *in_frame = ff_create_schro_frame(avctx,
252
-                                                 p_schro_params->frame_format);
253
-
254
-    if (in_frame) {
255
-        /* Copy input data to SchroFrame buffers (they match the ones
256
-         * referenced by the AVFrame stored in priv) */
257
-        if (av_frame_copy(in_frame->priv, frame) < 0) {
258
-            av_log(avctx, AV_LOG_ERROR, "Failed to copy input data\n");
259
-            return NULL;
260
-        }
261
-    }
262
-
263
-    return in_frame;
264
-}
265
-
266
-static void libschroedinger_free_frame(void *data)
267
-{
268
-    FFSchroEncodedFrame *enc_frame = data;
269
-
270
-    av_freep(&enc_frame->p_encbuf);
271
-    av_free(enc_frame);
272
-}
273
-
274
-static int libschroedinger_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
275
-                                        const AVFrame *frame, int *got_packet)
276
-{
277
-    int enc_size = 0;
278
-    SchroEncoderParams *p_schro_params = avctx->priv_data;
279
-    SchroEncoder *encoder = p_schro_params->encoder;
280
-    struct FFSchroEncodedFrame *p_frame_output = NULL;
281
-    int go = 1;
282
-    SchroBuffer *enc_buf;
283
-    int presentation_frame;
284
-    int parse_code;
285
-    int last_frame_in_sequence = 0;
286
-    int pkt_size, ret;
287
-
288
-    if (!frame) {
289
-        /* Push end of sequence if not already signalled. */
290
-        if (!p_schro_params->eos_signalled) {
291
-            schro_encoder_end_of_stream(encoder);
292
-            p_schro_params->eos_signalled = 1;
293
-        }
294
-    } else {
295
-        /* Allocate frame data to schro input buffer. */
296
-        SchroFrame *in_frame = libschroedinger_frame_from_data(avctx, frame);
297
-        if (!in_frame)
298
-            return AVERROR(ENOMEM);
299
-        /* Load next frame. */
300
-        schro_encoder_push_frame(encoder, in_frame);
301
-    }
302
-
303
-    if (p_schro_params->eos_pulled)
304
-        go = 0;
305
-
306
-    /* Now check to see if we have any output from the encoder. */
307
-    while (go) {
308
-        int err;
309
-        SchroStateEnum state;
310
-        state = schro_encoder_wait(encoder);
311
-        switch (state) {
312
-        case SCHRO_STATE_HAVE_BUFFER:
313
-        case SCHRO_STATE_END_OF_STREAM:
314
-            enc_buf = schro_encoder_pull(encoder, &presentation_frame);
315
-            if (enc_buf->length <= 0)
316
-                return AVERROR_BUG;
317
-            parse_code = enc_buf->data[4];
318
-
319
-            /* All non-frame data is prepended to actual frame data to
320
-             * be able to set the pts correctly. So we don't write data
321
-             * to the frame output queue until we actually have a frame
322
-             */
323
-            if ((err = av_reallocp(&p_schro_params->enc_buf,
324
-                                   p_schro_params->enc_buf_size +
325
-                                   enc_buf->length)) < 0) {
326
-                p_schro_params->enc_buf_size = 0;
327
-                return err;
328
-            }
329
-
330
-            memcpy(p_schro_params->enc_buf + p_schro_params->enc_buf_size,
331
-                   enc_buf->data, enc_buf->length);
332
-            p_schro_params->enc_buf_size += enc_buf->length;
333
-
334
-
335
-            if (state == SCHRO_STATE_END_OF_STREAM) {
336
-                p_schro_params->eos_pulled = 1;
337
-                go = 0;
338
-            }
339
-
340
-            if (!SCHRO_PARSE_CODE_IS_PICTURE(parse_code)) {
341
-                schro_buffer_unref(enc_buf);
342
-                break;
343
-            }
344
-
345
-            /* Create output frame. */
346
-            p_frame_output = av_mallocz(sizeof(FFSchroEncodedFrame));
347
-            if (!p_frame_output)
348
-                return AVERROR(ENOMEM);
349
-            /* Set output data. */
350
-            p_frame_output->size     = p_schro_params->enc_buf_size;
351
-            p_frame_output->p_encbuf = p_schro_params->enc_buf;
352
-            if (SCHRO_PARSE_CODE_IS_INTRA(parse_code) &&
353
-                SCHRO_PARSE_CODE_IS_REFERENCE(parse_code))
354
-                p_frame_output->key_frame = 1;
355
-
356
-            /* Parse the coded frame number from the bitstream. Bytes 14
357
-             * through 17 represent the frame number. */
358
-            p_frame_output->frame_num = AV_RB32(enc_buf->data + 13);
359
-
360
-            ff_schro_queue_push_back(&p_schro_params->enc_frame_queue,
361
-                                     p_frame_output);
362
-            p_schro_params->enc_buf_size = 0;
363
-            p_schro_params->enc_buf      = NULL;
364
-
365
-            schro_buffer_unref(enc_buf);
366
-
367
-            break;
368
-
369
-        case SCHRO_STATE_NEED_FRAME:
370
-            go = 0;
371
-            break;
372
-
373
-        case SCHRO_STATE_AGAIN:
374
-            break;
375
-
376
-        default:
377
-            av_log(avctx, AV_LOG_ERROR, "Unknown Schro Encoder state\n");
378
-            return -1;
379
-        }
380
-    }
381
-
382
-    /* Copy 'next' frame in queue. */
383
-
384
-    if (p_schro_params->enc_frame_queue.size == 1 &&
385
-        p_schro_params->eos_pulled)
386
-        last_frame_in_sequence = 1;
387
-
388
-    p_frame_output = ff_schro_queue_pop(&p_schro_params->enc_frame_queue);
389
-
390
-    if (!p_frame_output)
391
-        return 0;
392
-
393
-    pkt_size = p_frame_output->size;
394
-    if (last_frame_in_sequence && p_schro_params->enc_buf_size > 0)
395
-        pkt_size += p_schro_params->enc_buf_size;
396
-    if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size, 0)) < 0)
397
-        goto error;
398
-
399
-    memcpy(pkt->data, p_frame_output->p_encbuf, p_frame_output->size);
400
-#if FF_API_CODED_FRAME
401
-FF_DISABLE_DEPRECATION_WARNINGS
402
-    avctx->coded_frame->key_frame = p_frame_output->key_frame;
403
-    avctx->coded_frame->pts = p_frame_output->frame_num;
404
-FF_ENABLE_DEPRECATION_WARNINGS
405
-#endif
406
-    /* Use the frame number of the encoded frame as the pts. It is OK to
407
-     * do so since Dirac is a constant frame rate codec. It expects input
408
-     * to be of constant frame rate. */
409
-    pkt->pts = p_frame_output->frame_num;
410
-    pkt->dts = p_schro_params->dts++;
411
-    enc_size = p_frame_output->size;
412
-
413
-    /* Append the end of sequence information to the last frame in the
414
-     * sequence. */
415
-    if (last_frame_in_sequence && p_schro_params->enc_buf_size > 0) {
416
-        memcpy(pkt->data + enc_size, p_schro_params->enc_buf,
417
-               p_schro_params->enc_buf_size);
418
-        enc_size += p_schro_params->enc_buf_size;
419
-        av_freep(&p_schro_params->enc_buf);
420
-        p_schro_params->enc_buf_size = 0;
421
-    }
422
-
423
-    if (p_frame_output->key_frame)
424
-        pkt->flags |= AV_PKT_FLAG_KEY;
425
-    *got_packet = 1;
426
-
427
-error:
428
-    /* free frame */
429
-    libschroedinger_free_frame(p_frame_output);
430
-    return ret;
431
-}
432
-
433
-
434
-static int libschroedinger_encode_close(AVCodecContext *avctx)
435
-{
436
-    SchroEncoderParams *p_schro_params = avctx->priv_data;
437
-
438
-    /* Close the encoder. */
439
-    schro_encoder_free(p_schro_params->encoder);
440
-
441
-    /* Free data in the output frame queue. */
442
-    ff_schro_queue_free(&p_schro_params->enc_frame_queue,
443
-                        libschroedinger_free_frame);
444
-
445
-
446
-    /* Free the encoder buffer. */
447
-    if (p_schro_params->enc_buf_size)
448
-        av_freep(&p_schro_params->enc_buf);
449
-
450
-    /* Free the video format structure. */
451
-    av_freep(&p_schro_params->format);
452
-
453
-    return 0;
454
-}
455
-
456
-#define OFFSET(x) offsetof(SchroEncoderParams, x)
457
-#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
458
-static const AVOption options[] = {
459
-    { "noarith", "Enable noarith", OFFSET(noarith), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
460
-
461
-    { NULL },
462
-};
463
-
464
-static const AVClass libschroedinger_class = {
465
-    .class_name = "libschroedinger",
466
-    .item_name  = av_default_item_name,
467
-    .option     = options,
468
-    .version    = LIBAVUTIL_VERSION_INT,
469
-};
470
-
471
-AVCodec ff_libschroedinger_encoder = {
472
-    .name           = "libschroedinger",
473
-    .long_name      = NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"),
474
-    .type           = AVMEDIA_TYPE_VIDEO,
475
-    .id             = AV_CODEC_ID_DIRAC,
476
-    .priv_data_size = sizeof(SchroEncoderParams),
477
-    .priv_class     = &libschroedinger_class,
478
-    .init           = libschroedinger_encode_init,
479
-    .encode2        = libschroedinger_encode_frame,
480
-    .close          = libschroedinger_encode_close,
481
-    .capabilities   = AV_CODEC_CAP_DELAY,
482
-    .pix_fmts       = (const enum AVPixelFormat[]){
483
-        AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_NONE
484
-    },
485
-};