annotate libdiracenc.c @ 9386:a673af90ed8f libavcodec

Loop up to MAX_THREADS instead of h->s.avctx->thread_count to free the thread contexts, this avoids a crash when freeing the H.264 parser context introduced in r18406, since h->s.avctx is NULL there.
author reimar
date Fri, 10 Apr 2009 14:30:04 +0000
parents 043574c5c153
children fdb318d12314
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
1 /*
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
2 * Dirac encoding support via libdirac library
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
3 * Copyright (c) 2005 BBC, Andrew Kennedy <dirac at rd dot bbc dot co dot uk>
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
4 * Copyright (c) 2006-2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
5 *
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
6 * This file is part of FFmpeg.
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
7 *
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
12 *
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
16 * Lesser General Public License for more details.
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
17 *
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
21 */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
22
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
23 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8021
diff changeset
24 * @file libavcodec/libdiracenc.c
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
25 * Dirac encoding support via libdirac library; more details about the
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
26 * Dirac project can be found at http://dirac.sourceforge.net/.
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
27 * The libdirac_encoder library implements Dirac specification version 2.2
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
28 * (http://dirac.sourceforge.net/specification.html).
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
29 */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
30
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
31 #include "libdirac_libschro.h"
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
32 #include "libdirac.h"
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
33
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
34 #undef NDEBUG
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
35 #include <assert.h>
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
36
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
37
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
38 #include <libdirac_encoder/dirac_encoder.h>
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
39
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
40 /** Dirac encoder private data */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
41 typedef struct FfmpegDiracEncoderParams
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
42 {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
43 /** Dirac encoder context */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
44 dirac_encoder_context_t enc_ctx;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
45
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
46 /** frame being encoded */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
47 AVFrame picture;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
48
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
49 /** frame size */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
50 int frame_size;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
51
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
52 /** Dirac encoder handle */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
53 dirac_encoder_t* p_encoder;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
54
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
55 /** input frame buffer */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
56 unsigned char *p_in_frame_buf;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
57
7252
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
58 /** buffer to store encoder output before writing it to the frame queue */
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
59 unsigned char *enc_buf;
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
60
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
61 /** size of encoder buffer */
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
62 int enc_buf_size;
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
63
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
64 /** queue storing encoded frames */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
65 FfmpegDiracSchroQueue enc_frame_queue;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
66
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
67 /** end of sequence signalled by user, 0 - false, 1 - true */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
68 int eos_signalled;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
69
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
70 /** end of sequence returned by encoder, 0 - false, 1 - true */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
71 int eos_pulled;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
72 } FfmpegDiracEncoderParams;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
73
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
74 /**
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
75 * Works out Dirac-compatible chroma format.
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
76 */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
77 static dirac_chroma_t GetDiracChromaFormat(enum PixelFormat ff_pix_fmt)
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
78 {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
79 int num_formats = sizeof(ffmpeg_dirac_pixel_format_map) /
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
80 sizeof(ffmpeg_dirac_pixel_format_map[0]);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
81 int idx;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
82
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
83 for (idx = 0; idx < num_formats; ++idx) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
84 if (ffmpeg_dirac_pixel_format_map[idx].ff_pix_fmt == ff_pix_fmt) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
85 return ffmpeg_dirac_pixel_format_map[idx].dirac_pix_fmt;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
86 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
87 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
88 return formatNK;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
89 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
90
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
91 /**
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
92 * Dirac video preset table. Ensure that this tables matches up correctly
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
93 * with the ff_dirac_schro_video_format_info table in libdirac_libschro.c.
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
94 */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
95 static const VideoFormat ff_dirac_video_formats[]={
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
96 VIDEO_FORMAT_CUSTOM ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
97 VIDEO_FORMAT_QSIF525 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
98 VIDEO_FORMAT_QCIF ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
99 VIDEO_FORMAT_SIF525 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
100 VIDEO_FORMAT_CIF ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
101 VIDEO_FORMAT_4SIF525 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
102 VIDEO_FORMAT_4CIF ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
103 VIDEO_FORMAT_SD_480I60 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
104 VIDEO_FORMAT_SD_576I50 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
105 VIDEO_FORMAT_HD_720P60 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
106 VIDEO_FORMAT_HD_720P50 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
107 VIDEO_FORMAT_HD_1080I60 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
108 VIDEO_FORMAT_HD_1080I50 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
109 VIDEO_FORMAT_HD_1080P60 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
110 VIDEO_FORMAT_HD_1080P50 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
111 VIDEO_FORMAT_DIGI_CINEMA_2K24 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
112 VIDEO_FORMAT_DIGI_CINEMA_4K24 ,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
113 };
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
114
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
115 /**
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
116 * Returns the video format preset matching the input video dimensions and
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
117 * time base.
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
118 */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
119 static VideoFormat GetDiracVideoFormatPreset (AVCodecContext *avccontext)
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
120 {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
121 unsigned int num_formats = sizeof(ff_dirac_video_formats) /
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
122 sizeof(ff_dirac_video_formats[0]);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
123
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
124 unsigned int idx = ff_dirac_schro_get_video_format_idx (avccontext);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
125
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
126 return (idx < num_formats) ?
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
127 ff_dirac_video_formats[idx] : VIDEO_FORMAT_CUSTOM;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
128 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
129
9007
043574c5c153 Add missing av_cold in static init/close functions.
stefano
parents: 8718
diff changeset
130 static av_cold int libdirac_encode_init(AVCodecContext *avccontext)
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
131 {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
132
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
133 FfmpegDiracEncoderParams* p_dirac_params = avccontext->priv_data;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
134 int no_local = 1;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
135 int verbose = avccontext->debug;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
136 VideoFormat preset;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
137
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
138 /* get Dirac preset */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
139 preset = GetDiracVideoFormatPreset(avccontext);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
140
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
141 /* initialize the encoder context */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
142 dirac_encoder_context_init (&(p_dirac_params->enc_ctx), preset);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
143
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
144 p_dirac_params->enc_ctx.src_params.chroma =
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
145 GetDiracChromaFormat(avccontext->pix_fmt);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
146
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
147 if (p_dirac_params->enc_ctx.src_params.chroma == formatNK) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
148 av_log (avccontext, AV_LOG_ERROR,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
149 "Unsupported pixel format %d. This codec supports only "
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
150 "Planar YUV formats (yuv420p, yuv422p, yuv444p\n",
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
151 avccontext->pix_fmt);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
152 return -1;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
153 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
154
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
155 p_dirac_params->enc_ctx.src_params.frame_rate.numerator =
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
156 avccontext->time_base.den;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
157 p_dirac_params->enc_ctx.src_params.frame_rate.denominator =
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
158 avccontext->time_base.num;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
159
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
160 p_dirac_params->enc_ctx.src_params.width = avccontext->width;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
161 p_dirac_params->enc_ctx.src_params.height = avccontext->height;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
162
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
163 p_dirac_params->frame_size = avpicture_get_size(avccontext->pix_fmt,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
164 avccontext->width,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
165 avccontext->height);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
166
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
167 avccontext->coded_frame = &p_dirac_params->picture;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
168
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
169 if (no_local) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
170 p_dirac_params->enc_ctx.decode_flag = 0;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
171 p_dirac_params->enc_ctx.instr_flag = 0;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
172 } else {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
173 p_dirac_params->enc_ctx.decode_flag = 1;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
174 p_dirac_params->enc_ctx.instr_flag = 1;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
175 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
176
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
177 /* Intra-only sequence */
7839
e6348a5656e0 Add support for creating Simple Profile (I-frame only, no arithmetic coding)
diego
parents: 7252
diff changeset
178 if (avccontext->gop_size == 0 ) {
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
179 p_dirac_params->enc_ctx.enc_params.num_L1 = 0;
7839
e6348a5656e0 Add support for creating Simple Profile (I-frame only, no arithmetic coding)
diego
parents: 7252
diff changeset
180 if (avccontext->coder_type == FF_CODER_TYPE_VLC)
e6348a5656e0 Add support for creating Simple Profile (I-frame only, no arithmetic coding)
diego
parents: 7252
diff changeset
181 p_dirac_params->enc_ctx.enc_params.using_ac = 0;
e6348a5656e0 Add support for creating Simple Profile (I-frame only, no arithmetic coding)
diego
parents: 7252
diff changeset
182 } else
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
183 avccontext->has_b_frames = 1;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
184
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
185 if (avccontext->flags & CODEC_FLAG_QSCALE) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
186 if (avccontext->global_quality != 0) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
187 p_dirac_params->enc_ctx.enc_params.qf =
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
188 avccontext->global_quality / (FF_QP2LAMBDA*10.0);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
189 /* if it is not default bitrate then send target rate. */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
190 if (avccontext->bit_rate >= 1000 &&
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
191 avccontext->bit_rate != 200000) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
192 p_dirac_params->enc_ctx.enc_params.trate =
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
193 avccontext->bit_rate / 1000;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
194 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
195 } else
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
196 p_dirac_params->enc_ctx.enc_params.lossless = 1;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
197 } else if (avccontext->bit_rate >= 1000)
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
198 p_dirac_params->enc_ctx.enc_params.trate = avccontext->bit_rate / 1000;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
199
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
200 if ((preset > VIDEO_FORMAT_QCIF || preset < VIDEO_FORMAT_QSIF525) &&
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
201 avccontext->bit_rate == 200000) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
202 p_dirac_params->enc_ctx.enc_params.trate = 0;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
203 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
204
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
205 if (avccontext->flags & CODEC_FLAG_INTERLACED_ME) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
206 /* all material can be coded as interlaced or progressive
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
207 * irrespective of the type of source material */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
208 p_dirac_params->enc_ctx.enc_params.picture_coding_mode = 1;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
209 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
210
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
211 p_dirac_params->p_encoder = dirac_encoder_init (&(p_dirac_params->enc_ctx),
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
212 verbose );
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
213
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
214 if (!p_dirac_params->p_encoder) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
215 av_log(avccontext, AV_LOG_ERROR,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
216 "Unrecoverable Error: dirac_encoder_init failed. ");
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
217 return EXIT_FAILURE;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
218 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
219
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
220 /* allocate enough memory for the incoming data */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
221 p_dirac_params->p_in_frame_buf = av_malloc(p_dirac_params->frame_size);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
222
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
223 /* initialize the encoded frame queue */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
224 ff_dirac_schro_queue_init(&p_dirac_params->enc_frame_queue);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
225
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
226 return 0 ;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
227 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
228
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
229 static void DiracFreeFrame (void *data)
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
230 {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
231 FfmpegDiracSchroEncodedFrame *enc_frame = data;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
232
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
233 av_freep (&(enc_frame->p_encbuf));
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
234 av_free(enc_frame);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
235 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
236
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
237 static int libdirac_encode_frame(AVCodecContext *avccontext,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
238 unsigned char *frame,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
239 int buf_size, void *data)
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
240 {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
241 int enc_size = 0;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
242 dirac_encoder_state_t state;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
243 FfmpegDiracEncoderParams* p_dirac_params = avccontext->priv_data;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
244 FfmpegDiracSchroEncodedFrame* p_frame_output = NULL;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
245 FfmpegDiracSchroEncodedFrame* p_next_output_frame = NULL;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
246 int go = 1;
7252
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
247 int last_frame_in_sequence = 0;
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
248
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
249 if (data == NULL) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
250 /* push end of sequence if not already signalled */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
251 if (!p_dirac_params->eos_signalled) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
252 dirac_encoder_end_sequence( p_dirac_params->p_encoder );
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
253 p_dirac_params->eos_signalled = 1;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
254 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
255 } else {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
256
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
257 /* Allocate frame data to Dirac input buffer.
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
258 * Input line size may differ from what the codec supports,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
259 * especially when transcoding from one format to another.
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
260 * So use avpicture_layout to copy the frame. */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
261 avpicture_layout ((AVPicture *)data, avccontext->pix_fmt,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
262 avccontext->width, avccontext->height,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
263 p_dirac_params->p_in_frame_buf,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
264 p_dirac_params->frame_size);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
265
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
266 /* load next frame */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
267 if (dirac_encoder_load (p_dirac_params->p_encoder,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
268 p_dirac_params->p_in_frame_buf,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
269 p_dirac_params->frame_size ) < 0) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
270 av_log(avccontext, AV_LOG_ERROR, "Unrecoverable Encoder Error."
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
271 " dirac_encoder_load failed...\n");
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
272 return -1;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
273 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
274 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
275
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
276 if (p_dirac_params->eos_pulled)
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
277 go = 0;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
278
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
279 while(go) {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
280 p_dirac_params->p_encoder->enc_buf.buffer = frame;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
281 p_dirac_params->p_encoder->enc_buf.size = buf_size;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
282 /* process frame */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
283 state = dirac_encoder_output ( p_dirac_params->p_encoder );
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
284
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
285 switch (state)
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
286 {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
287 case ENC_STATE_AVAIL:
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
288 case ENC_STATE_EOS:
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
289 assert (p_dirac_params->p_encoder->enc_buf.size > 0);
7252
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
290
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
291 /* All non-frame data is prepended to actual frame data to
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
292 * be able to set the pts correctly. So we don't write data
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
293 * to the frame output queue until we actually have a frame
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
294 */
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
295
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
296 p_dirac_params->enc_buf = av_realloc (
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
297 p_dirac_params->enc_buf,
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
298 p_dirac_params->enc_buf_size +
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
299 p_dirac_params->p_encoder->enc_buf.size
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
300 );
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
301 memcpy(p_dirac_params->enc_buf + p_dirac_params->enc_buf_size,
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
302 p_dirac_params->p_encoder->enc_buf.buffer,
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
303 p_dirac_params->p_encoder->enc_buf.size);
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
304
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
305 p_dirac_params->enc_buf_size +=
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
306 p_dirac_params->p_encoder->enc_buf.size;
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
307
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
308 if (state == ENC_STATE_EOS) {
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
309 p_dirac_params->eos_pulled = 1;
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
310 go = 0;
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
311 }
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
312
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
313 /* If non-frame data, don't output it until it we get an
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
314 * encoded frame back from the encoder. */
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
315 if (p_dirac_params->p_encoder->enc_pparams.pnum == -1)
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
316 break;
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
317
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
318 /* create output frame */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
319 p_frame_output = av_mallocz(sizeof(FfmpegDiracSchroEncodedFrame));
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
320 /* set output data */
7252
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
321 p_frame_output->size = p_dirac_params->enc_buf_size;
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
322 p_frame_output->p_encbuf = p_dirac_params->enc_buf;
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
323 p_frame_output->frame_num =
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
324 p_dirac_params->p_encoder->enc_pparams.pnum;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
325
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
326 if (p_dirac_params->p_encoder->enc_pparams.ptype == INTRA_PICTURE &&
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
327 p_dirac_params->p_encoder->enc_pparams.rtype == REFERENCE_PICTURE)
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
328 p_frame_output->key_frame = 1;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
329
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
330 ff_dirac_schro_queue_push_back (&p_dirac_params->enc_frame_queue,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
331 p_frame_output);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
332
7252
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
333 p_dirac_params->enc_buf_size = 0;
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
334 p_dirac_params->enc_buf = NULL;
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
335 break;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
336
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
337 case ENC_STATE_BUFFER:
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
338 go = 0;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
339 break;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
340
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
341 case ENC_STATE_INVALID:
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
342 av_log(avccontext, AV_LOG_ERROR,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
343 "Unrecoverable Dirac Encoder Error. Quitting...\n");
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
344 return -1;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
345
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
346 default:
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
347 av_log(avccontext, AV_LOG_ERROR, "Unknown Dirac Encoder state\n");
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
348 return -1;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
349 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
350 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
351
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
352 /* copy 'next' frame in queue */
7252
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
353
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
354 if (p_dirac_params->enc_frame_queue.size == 1 &&
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
355 p_dirac_params->eos_pulled)
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
356 last_frame_in_sequence = 1;
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
357
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
358 p_next_output_frame =
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
359 ff_dirac_schro_queue_pop(&p_dirac_params->enc_frame_queue);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
360
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
361 if (p_next_output_frame == NULL)
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
362 return 0;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
363
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
364 memcpy(frame, p_next_output_frame->p_encbuf, p_next_output_frame->size);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
365 avccontext->coded_frame->key_frame = p_next_output_frame->key_frame;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
366 /* Use the frame number of the encoded frame as the pts. It is OK to do
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
367 * so since Dirac is a constant framerate codec. It expects input to be
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
368 * of constant framerate. */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
369 avccontext->coded_frame->pts = p_next_output_frame->frame_num;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
370 enc_size = p_next_output_frame->size;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
371
7252
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
372 /* Append the end of sequence information to the last frame in the
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
373 * sequence. */
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
374 if (last_frame_in_sequence && p_dirac_params->enc_buf_size > 0)
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
375 {
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
376 memcpy (frame + enc_size, p_dirac_params->enc_buf,
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
377 p_dirac_params->enc_buf_size);
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
378 enc_size += p_dirac_params->enc_buf_size;
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
379 av_freep (&p_dirac_params->enc_buf);
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
380 p_dirac_params->enc_buf_size = 0;
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
381 }
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
382
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
383 /* free frame */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
384 DiracFreeFrame(p_next_output_frame);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
385
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
386 return enc_size;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
387 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
388
9007
043574c5c153 Add missing av_cold in static init/close functions.
stefano
parents: 8718
diff changeset
389 static av_cold int libdirac_encode_close(AVCodecContext *avccontext)
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
390 {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
391 FfmpegDiracEncoderParams* p_dirac_params = avccontext->priv_data;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
392
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
393 /* close the encoder */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
394 dirac_encoder_close(p_dirac_params->p_encoder );
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
395
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
396 /* free data in the output frame queue */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
397 ff_dirac_schro_queue_free(&p_dirac_params->enc_frame_queue,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
398 DiracFreeFrame);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
399
7252
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
400 /* free the encoder buffer */
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
401 if (p_dirac_params->enc_buf_size)
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
402 av_freep(&p_dirac_params->enc_buf);
e674db16f1c6 Fix pts handling when encoding with libdirac.
diego
parents: 7040
diff changeset
403
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
404 /* free the input frame buffer */
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
405 av_freep(&p_dirac_params->p_in_frame_buf);
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
406
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
407 return 0 ;
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
408 }
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
409
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
410
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
411 AVCodec libdirac_encoder = {
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
412 "libdirac",
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
413 CODEC_TYPE_VIDEO,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
414 CODEC_ID_DIRAC,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
415 sizeof(FfmpegDiracEncoderParams),
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
416 libdirac_encode_init,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
417 libdirac_encode_frame,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
418 libdirac_encode_close,
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
419 .capabilities= CODEC_CAP_DELAY,
8021
00fca5d6f0d9 Use PIX_FMT_NONE instead of -1 in AVCodec.pix_fmts.
cehoyos
parents: 7839
diff changeset
420 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_NONE},
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6819
diff changeset
421 .long_name= NULL_IF_CONFIG_SMALL("libdirac Dirac 2.2"),
6734
df467cebd0d3 Dirac decoding/encoding support via libdirac.
diego
parents:
diff changeset
422 } ;