annotate libschroedingerenc.c @ 10111:ebe5812b39a7 libavcodec

Use the output data type to determine the maximum number of samples that can be decoded.
author jbr
date Fri, 28 Aug 2009 00:57:00 +0000
parents 09f2db2d7c90
children 38cfe222e1a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
1 /*
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
2 * Dirac encoder support via Schroedinger libraries
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
3 * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
4 *
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
5 * This file is part of FFmpeg.
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
6 *
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
11 *
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
15 * Lesser General Public License for more details.
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
16 *
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
20 */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
21
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
22 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 7839
diff changeset
23 * @file libavcodec/libschroedingerenc.c
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
24 * Dirac encoder support via libschroedinger-1.0 libraries. More details about
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
25 * the Schroedinger project can be found at http://www.diracvideo.org/.
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
26 * The library implements Dirac Specification Version 2.2
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
27 * (http://dirac.sourceforge.net/specification.html).
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
28 */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
29
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
30 #undef NDEBUG
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
31 #include <assert.h>
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
32
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
33 #include <schroedinger/schro.h>
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
34 #include <schroedinger/schrodebug.h>
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
35 #include <schroedinger/schrovideoformat.h>
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
36
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
37 #include "avcodec.h"
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
38 #include "libdirac_libschro.h"
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
39 #include "libschroedinger.h"
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
40
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
41
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
42 /** libschroedinger encoder private data */
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
43 typedef struct FfmpegSchroEncoderParams {
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
44 /** Schroedinger video format */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
45 SchroVideoFormat *format;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
46
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
47 /** Schroedinger frame format */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
48 SchroFrameFormat frame_format;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
49
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
50 /** frame being encoded */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
51 AVFrame picture;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
52
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
53 /** frame size */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
54 int frame_size;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
55
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
56 /** Schroedinger encoder handle*/
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
57 SchroEncoder* encoder;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
58
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
59 /** buffer to store encoder output before writing it to the frame queue*/
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
60 unsigned char *enc_buf;
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
61
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
62 /** Size of encoder buffer*/
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
63 int enc_buf_size;
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
64
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
65 /** queue storing encoded frames */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
66 FfmpegDiracSchroQueue enc_frame_queue;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
67
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
68 /** end of sequence signalled */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
69 int eos_signalled;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
70
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
71 /** end of sequence pulled */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
72 int eos_pulled;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
73 } FfmpegSchroEncoderParams;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
74
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
75 /**
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
76 * Works out Schro-compatible chroma format.
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
77 */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
78 static int SetSchroChromaFormat(AVCodecContext *avccontext)
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
79 {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
80 int num_formats = sizeof(ffmpeg_schro_pixel_format_map) /
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
81 sizeof(ffmpeg_schro_pixel_format_map[0]);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
82 int idx;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
83
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
84 FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
85
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
86 for (idx = 0; idx < num_formats; ++idx) {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
87 if (ffmpeg_schro_pixel_format_map[idx].ff_pix_fmt ==
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
88 avccontext->pix_fmt) {
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
89 p_schro_params->format->chroma_format =
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
90 ffmpeg_schro_pixel_format_map[idx].schro_pix_fmt;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
91 return 0;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
92 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
93 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
94
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
95 av_log(avccontext, AV_LOG_ERROR,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
96 "This codec currently only supports planar YUV 4:2:0, 4:2:2"
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
97 " and 4:4:4 formats.\n");
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
98
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
99 return -1;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
100 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
101
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
102 static int libschroedinger_encode_init(AVCodecContext *avccontext)
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
103 {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
104 FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
105 SchroVideoFormatEnum preset;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
106
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
107 /* Initialize the libraries that libschroedinger depends on. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
108 schro_init();
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
109
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
110 /* Create an encoder object. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
111 p_schro_params->encoder = schro_encoder_new();
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
112
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
113 if (!p_schro_params->encoder) {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
114 av_log(avccontext, AV_LOG_ERROR,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
115 "Unrecoverable Error: schro_encoder_new failed. ");
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
116 return -1;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
117 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
118
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
119 /* Initialize the format. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
120 preset = ff_get_schro_video_format_preset(avccontext);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
121 p_schro_params->format =
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
122 schro_encoder_get_video_format(p_schro_params->encoder);
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
123 schro_video_format_set_std_video_format(p_schro_params->format, preset);
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
124 p_schro_params->format->width = avccontext->width;
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
125 p_schro_params->format->height = avccontext->height;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
126
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
127 if (SetSchroChromaFormat(avccontext) == -1)
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
128 return -1;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
129
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
130 if (ff_get_schro_frame_format(p_schro_params->format->chroma_format,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
131 &p_schro_params->frame_format) == -1) {
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
132 av_log(avccontext, AV_LOG_ERROR,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
133 "This codec currently supports only planar YUV 4:2:0, 4:2:2"
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
134 " and 4:4:4 formats.\n");
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
135 return -1;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
136 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
137
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
138 p_schro_params->format->frame_rate_numerator = avccontext->time_base.den;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
139 p_schro_params->format->frame_rate_denominator = avccontext->time_base.num;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
140
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
141 p_schro_params->frame_size = avpicture_get_size(avccontext->pix_fmt,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
142 avccontext->width,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
143 avccontext->height);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
144
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
145 avccontext->coded_frame = &p_schro_params->picture;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
146
10055
fdb318d12314 Simplify 'if' condition statements.
diego
parents: 8790
diff changeset
147 if (!avccontext->gop_size) {
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
148 schro_encoder_setting_set_double(p_schro_params->encoder,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
149 "gop_structure",
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
150 SCHRO_ENCODER_GOP_INTRA_ONLY);
7839
e6348a5656e0 Add support for creating Simple Profile (I-frame only, no arithmetic coding)
diego
parents: 7253
diff changeset
151
10056
646065f63290 Remove useless braces around if/for/while expressions.
diego
parents: 10055
diff changeset
152 if (avccontext->coder_type == FF_CODER_TYPE_VLC)
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
153 schro_encoder_setting_set_double(p_schro_params->encoder,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
154 "enable_noarith", 1);
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
155 } else {
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
156 schro_encoder_setting_set_double(p_schro_params->encoder,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
157 "gop_structure",
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
158 SCHRO_ENCODER_GOP_BIREF);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
159 avccontext->has_b_frames = 1;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
160 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
161
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
162 /* FIXME - Need to handle SCHRO_ENCODER_RATE_CONTROL_LOW_DELAY. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
163 if (avccontext->flags & CODEC_FLAG_QSCALE) {
10055
fdb318d12314 Simplify 'if' condition statements.
diego
parents: 8790
diff changeset
164 if (!avccontext->global_quality) {
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
165 /* lossless coding */
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
166 schro_encoder_setting_set_double(p_schro_params->encoder,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
167 "rate_control",
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
168 SCHRO_ENCODER_RATE_CONTROL_LOSSLESS);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
169 } else {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
170 int noise_threshold;
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
171 schro_encoder_setting_set_double(p_schro_params->encoder,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
172 "rate_control",
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
173 SCHRO_ENCODER_RATE_CONTROL_CONSTANT_NOISE_THRESHOLD);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
174
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
175 noise_threshold = avccontext->global_quality / FF_QP2LAMBDA;
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
176 if (noise_threshold > 100)
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
177 noise_threshold = 100;
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
178 schro_encoder_setting_set_double(p_schro_params->encoder,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
179 "noise_threshold",
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
180 noise_threshold);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
181 }
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
182 } else {
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
183 schro_encoder_setting_set_double(p_schro_params->encoder,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
184 "rate_control",
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
185 SCHRO_ENCODER_RATE_CONTROL_CONSTANT_BITRATE);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
186
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
187 schro_encoder_setting_set_double(p_schro_params->encoder,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
188 "bitrate",
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
189 avccontext->bit_rate);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
190
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
191 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
192
10056
646065f63290 Remove useless braces around if/for/while expressions.
diego
parents: 10055
diff changeset
193 if (avccontext->flags & CODEC_FLAG_INTERLACED_ME)
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
194 /* All material can be coded as interlaced or progressive
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
195 irrespective of the type of source material. */
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
196 schro_encoder_setting_set_double(p_schro_params->encoder,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
197 "interlaced_coding", 1);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
198
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
199 /* FIXME: Signal range hardcoded to 8-bit data until both libschroedinger
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
200 * and libdirac support other bit-depth data. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
201 schro_video_format_set_std_signal_range(p_schro_params->format,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
202 SCHRO_SIGNAL_RANGE_8BIT_VIDEO);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
203
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
204 /* Set the encoder format. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
205 schro_encoder_set_video_format(p_schro_params->encoder,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
206 p_schro_params->format);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
207
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
208 /* Set the debug level. */
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
209 schro_debug_set_level(avccontext->debug);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
210
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
211 schro_encoder_start(p_schro_params->encoder);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
212
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
213 /* Initialize the encoded frame queue. */
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
214 ff_dirac_schro_queue_init(&p_schro_params->enc_frame_queue);
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
215 return 0;
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
216 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
217
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
218 static SchroFrame *libschroedinger_frame_from_data(AVCodecContext *avccontext,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
219 void *in_data)
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
220 {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
221 FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
222 SchroFrame *in_frame;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
223 /* Input line size may differ from what the codec supports. Especially
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
224 * when transcoding from one format to another. So use avpicture_layout
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
225 * to copy the frame. */
10061
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
226 in_frame = ff_create_schro_frame(avccontext, p_schro_params->frame_format);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
227
10061
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
228 if (in_frame)
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
229 avpicture_layout((AVPicture *)in_data, avccontext->pix_fmt,
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
230 avccontext->width, avccontext->height,
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
231 in_frame->components[0].data,
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
232 p_schro_params->frame_size);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
233
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
234 return in_frame;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
235 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
236
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
237 static void SchroedingerFreeFrame(void *data)
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
238 {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
239 FfmpegDiracSchroEncodedFrame *enc_frame = data;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
240
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
241 av_freep(&(enc_frame->p_encbuf));
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
242 av_free(enc_frame);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
243 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
244
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
245 static int libschroedinger_encode_frame(AVCodecContext *avccontext,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
246 unsigned char *frame,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
247 int buf_size, void *data)
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
248 {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
249 int enc_size = 0;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
250 FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
251 SchroEncoder *encoder = p_schro_params->encoder;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
252 struct FfmpegDiracSchroEncodedFrame* p_frame_output = NULL;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
253 int go = 1;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
254 SchroBuffer *enc_buf;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
255 int presentation_frame;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
256 int parse_code;
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
257 int last_frame_in_sequence = 0;
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
258
10058
d18468c5fee0 Simplify another 'if' condition: Replace 'exp == 0' by '!exp'.
diego
parents: 10056
diff changeset
259 if (!data) {
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
260 /* Push end of sequence if not already signalled. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
261 if (!p_schro_params->eos_signalled) {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
262 schro_encoder_end_of_stream(encoder);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
263 p_schro_params->eos_signalled = 1;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
264 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
265 } else {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
266 /* Allocate frame data to schro input buffer. */
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
267 SchroFrame *in_frame = libschroedinger_frame_from_data(avccontext,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
268 data);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
269 /* Load next frame. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
270 schro_encoder_push_frame(encoder, in_frame);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
271 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
272
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
273 if (p_schro_params->eos_pulled)
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
274 go = 0;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
275
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
276 /* Now check to see if we have any output from the encoder. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
277 while (go) {
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
278 SchroStateEnum state;
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
279 state = schro_encoder_wait(encoder);
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
280 switch (state) {
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
281 case SCHRO_STATE_HAVE_BUFFER:
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
282 case SCHRO_STATE_END_OF_STREAM:
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
283 enc_buf = schro_encoder_pull(encoder, &presentation_frame);
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
284 assert(enc_buf->length > 0);
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
285 assert(enc_buf->length <= buf_size);
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
286 parse_code = enc_buf->data[4];
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
287
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
288 /* All non-frame data is prepended to actual frame data to
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
289 * be able to set the pts correctly. So we don't write data
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
290 * to the frame output queue until we actually have a frame
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
291 */
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
292 p_schro_params->enc_buf = av_realloc(p_schro_params->enc_buf,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
293 p_schro_params->enc_buf_size + enc_buf->length);
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
294
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
295 memcpy(p_schro_params->enc_buf + p_schro_params->enc_buf_size,
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
296 enc_buf->data, enc_buf->length);
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
297 p_schro_params->enc_buf_size += enc_buf->length;
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
298
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
299
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
300 if (state == SCHRO_STATE_END_OF_STREAM) {
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
301 p_schro_params->eos_pulled = 1;
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
302 go = 0;
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
303 }
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
304
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
305 if (!SCHRO_PARSE_CODE_IS_PICTURE(parse_code)) {
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
306 schro_buffer_unref(enc_buf);
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
307 break;
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
308 }
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
309
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
310 /* Create output frame. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
311 p_frame_output = av_mallocz(sizeof(FfmpegDiracSchroEncodedFrame));
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
312 /* Set output data. */
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
313 p_frame_output->size = p_schro_params->enc_buf_size;
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
314 p_frame_output->p_encbuf = p_schro_params->enc_buf;
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
315 if (SCHRO_PARSE_CODE_IS_INTRA(parse_code) &&
10056
646065f63290 Remove useless braces around if/for/while expressions.
diego
parents: 10055
diff changeset
316 SCHRO_PARSE_CODE_IS_REFERENCE(parse_code))
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
317 p_frame_output->key_frame = 1;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
318
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
319 /* Parse the coded frame number from the bitstream. Bytes 14
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
320 * through 17 represesent the frame number. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
321 p_frame_output->frame_num = (enc_buf->data[13] << 24) +
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
322 (enc_buf->data[14] << 16) +
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
323 (enc_buf->data[15] << 8) +
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
324 enc_buf->data[16];
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
325
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
326 ff_dirac_schro_queue_push_back(&p_schro_params->enc_frame_queue,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
327 p_frame_output);
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
328 p_schro_params->enc_buf_size = 0;
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
329 p_schro_params->enc_buf = NULL;
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
330
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
331 schro_buffer_unref(enc_buf);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
332
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
333 break;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
334
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
335 case SCHRO_STATE_NEED_FRAME:
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
336 go = 0;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
337 break;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
338
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
339 case SCHRO_STATE_AGAIN:
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
340 break;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
341
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
342 default:
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
343 av_log(avccontext, AV_LOG_ERROR, "Unknown Schro Encoder state\n");
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
344 return -1;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
345 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
346 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
347
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
348 /* Copy 'next' frame in queue. */
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
349
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
350 if (p_schro_params->enc_frame_queue.size == 1 &&
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
351 p_schro_params->eos_pulled)
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
352 last_frame_in_sequence = 1;
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
353
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
354 p_frame_output = ff_dirac_schro_queue_pop(&p_schro_params->enc_frame_queue);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
355
10055
fdb318d12314 Simplify 'if' condition statements.
diego
parents: 8790
diff changeset
356 if (!p_frame_output)
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
357 return 0;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
358
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
359 memcpy(frame, p_frame_output->p_encbuf, p_frame_output->size);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
360 avccontext->coded_frame->key_frame = p_frame_output->key_frame;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
361 /* Use the frame number of the encoded frame as the pts. It is OK to
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
362 * do so since Dirac is a constant frame rate codec. It expects input
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
363 * to be of constant frame rate. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
364 avccontext->coded_frame->pts = p_frame_output->frame_num;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
365 enc_size = p_frame_output->size;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
366
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
367 /* Append the end of sequence information to the last frame in the
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
368 * sequence. */
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
369 if (last_frame_in_sequence && p_schro_params->enc_buf_size > 0) {
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
370 memcpy(frame + enc_size, p_schro_params->enc_buf,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
371 p_schro_params->enc_buf_size);
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
372 enc_size += p_schro_params->enc_buf_size;
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
373 av_freep(&p_schro_params->enc_buf);
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
374 p_schro_params->enc_buf_size = 0;
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
375 }
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
376
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
377 /* free frame */
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
378 SchroedingerFreeFrame(p_frame_output);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
379
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
380 return enc_size;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
381 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
382
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
383
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
384 static int libschroedinger_encode_close(AVCodecContext *avccontext)
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
385 {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
386
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
387 FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
388
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
389 /* Close the encoder. */
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
390 schro_encoder_free(p_schro_params->encoder);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
391
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
392 /* Free data in the output frame queue. */
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
393 ff_dirac_schro_queue_free(&p_schro_params->enc_frame_queue,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
394 SchroedingerFreeFrame);
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
395
7253
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
396
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
397 /* Free the encoder buffer. */
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
398 if (p_schro_params->enc_buf_size)
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
399 av_freep(&p_schro_params->enc_buf);
2f5b98d0aa13 Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents: 7040
diff changeset
400
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
401 /* Free the video format structure. */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
402 av_freep(&p_schro_params->format);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
403
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
404 return 0;
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
405 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
406
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
407
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
408 AVCodec libschroedinger_encoder = {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
409 "libschroedinger",
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
410 CODEC_TYPE_VIDEO,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
411 CODEC_ID_DIRAC,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
412 sizeof(FfmpegSchroEncoderParams),
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
413 libschroedinger_encode_init,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
414 libschroedinger_encode_frame,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
415 libschroedinger_encode_close,
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
416 .capabilities = CODEC_CAP_DELAY,
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
417 .pix_fmts = (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_NONE},
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 10058
diff changeset
418 .long_name = NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"),
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
419 };