annotate libxavs.c @ 12492:58a960d6e34c libavcodec

Rename h264_idct_sse2.asm to h264_idct.asm; move inline IDCT asm from h264dsp_mmx.c to h264_idct.asm (as yasm code). Because the loops are now coded in asm instead of C, this is (depending on the function) up to 50% faster for cases where gcc didn't do a great job at looping. Since h264_idct_add8() is now faster than the manual loop setup in h264.c, in-asm idct calling can now be enabled for chroma as well (see r16207). For MMX, this is 5% faster. For SSE2 (which isn't done for chroma if h264.c does the looping), this makes it up to 50% faster. Speed gain overall is ~0.5-1.0%.
author rbultje
date Tue, 14 Sep 2010 13:36:26 +0000
parents bf51ca1aafb8
children 34beb0af8204
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12281
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
1 /*
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
2 * AVS encoding using the xavs library
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
3 * Copyright (C) 2010 Amanda, Y.N. Wu <amanda11192003@gmail.com>
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
4 *
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
5 * This file is part of FFmpeg.
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
6 *
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
11 *
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
15 * Lesser General Public License for more details.
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
16 *
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
20 */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
21
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
22 #include <stdio.h>
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
23 #include <stdlib.h>
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
24 #include <string.h>
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
25 #include <math.h>
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
26 #include <stdint.h>
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
27 #include <xavs.h>
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
28 #include "avcodec.h"
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
29
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
30 #define END_OF_STREAM 0x001
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
31
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
32 #define XAVS_PART_I8X8 0x002 /* Analyze i8x8 (requires 8x8 transform) */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
33 #define XAVS_PART_P8X8 0x010 /* Analyze p16x8, p8x16 and p8x8 */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
34 #define XAVS_PART_B8X8 0x100 /* Analyze b16x8, b*/
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
35
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
36 typedef struct XavsContext {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
37 xavs_param_t params;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
38 xavs_t *enc;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
39 xavs_picture_t pic;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
40 uint8_t *sei;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
41 int sei_size;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
42 AVFrame out_pic;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
43 int end_of_stream;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
44 } XavsContext;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
45
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
46 static void XAVS_log(void *p, int level, const char *fmt, va_list args)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
47 {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
48 static const int level_map[] = {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
49 [XAVS_LOG_ERROR] = AV_LOG_ERROR,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
50 [XAVS_LOG_WARNING] = AV_LOG_WARNING,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
51 [XAVS_LOG_INFO] = AV_LOG_INFO,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
52 [XAVS_LOG_DEBUG] = AV_LOG_DEBUG
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
53 };
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
54
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
55 if (level < 0 || level > XAVS_LOG_DEBUG)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
56 return;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
57
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
58 av_vlog(p, level_map[level], fmt, args);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
59 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
60
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
61 static int encode_nals(AVCodecContext *ctx, uint8_t *buf,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
62 int size, xavs_nal_t *nals,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
63 int nnal, int skip_sei)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
64 {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
65 XavsContext *x4 = ctx->priv_data;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
66 uint8_t *p = buf;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
67 int i, s;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
68
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
69 /* Write the SEI as part of the first frame. */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
70 if (x4->sei_size > 0 && nnal > 0) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
71 memcpy(p, x4->sei, x4->sei_size);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
72 p += x4->sei_size;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
73 x4->sei_size = 0;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
74 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
75
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
76 for (i = 0; i < nnal; i++) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
77 /* Don't put the SEI in extradata. */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
78 if (skip_sei && nals[i].i_type == NAL_SEI) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
79 x4->sei = av_malloc( 5 + nals[i].i_payload * 4 / 3 );
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
80 if (xavs_nal_encode(x4->sei, &x4->sei_size, 1, nals + i) < 0)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
81 return -1;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
82
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
83 continue;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
84 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
85 s = xavs_nal_encode(p, &size, 1, nals + i);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
86 if (s < 0)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
87 return -1;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
88 p += s;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
89 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
90
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
91 return p - buf;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
92 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
93
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
94 static int XAVS_frame(AVCodecContext *ctx, uint8_t *buf,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
95 int bufsize, void *data)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
96 {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
97 XavsContext *x4 = ctx->priv_data;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
98 AVFrame *frame = data;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
99 xavs_nal_t *nal;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
100 int nnal, i;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
101 xavs_picture_t pic_out;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
102
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
103 x4->pic.img.i_csp = XAVS_CSP_I420;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
104 x4->pic.img.i_plane = 3;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
105
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
106 if (frame) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
107 for (i = 0; i < 3; i++) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
108 x4->pic.img.plane[i] = frame->data[i];
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
109 x4->pic.img.i_stride[i] = frame->linesize[i];
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
110 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
111
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
112 x4->pic.i_pts = frame->pts;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
113 x4->pic.i_type = XAVS_TYPE_AUTO;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
114 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
115
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
116 if (xavs_encoder_encode(x4->enc, &nal, &nnal,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
117 frame? &x4->pic: NULL, &pic_out) < 0)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
118 return -1;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
119
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
120 bufsize = encode_nals(ctx, buf, bufsize, nal, nnal, 0);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
121
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
122 if (bufsize < 0)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
123 return -1;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
124
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
125 if (!bufsize && !frame && !(x4->end_of_stream)){
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
126 buf[bufsize] = 0x0;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
127 buf[bufsize+1] = 0x0;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
128 buf[bufsize+2] = 0x01;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
129 buf[bufsize+3] = 0xb1;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
130 bufsize += 4;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
131 x4->end_of_stream = END_OF_STREAM;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
132 return bufsize;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
133 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
134 /* FIXME: libxavs now provides DTS */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
135 /* but AVFrame doesn't have a field for it. */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
136 x4->out_pic.pts = pic_out.i_pts;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
137
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
138 switch (pic_out.i_type) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
139 case XAVS_TYPE_IDR:
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
140 case XAVS_TYPE_I:
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
141 x4->out_pic.pict_type = FF_I_TYPE;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
142 break;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
143 case XAVS_TYPE_P:
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
144 x4->out_pic.pict_type = FF_P_TYPE;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
145 break;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
146 case XAVS_TYPE_B:
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
147 case XAVS_TYPE_BREF:
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
148 x4->out_pic.pict_type = FF_B_TYPE;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
149 break;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
150 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
151
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
152 /* There is no IDR frame in AVS JiZhun */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
153 /* Sequence header is used as a flag */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
154 x4->out_pic.key_frame = pic_out.i_type == XAVS_TYPE_I;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
155
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
156 x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
157
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
158 return bufsize;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
159 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
160
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
161 static av_cold int XAVS_close(AVCodecContext *avctx)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
162 {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
163 XavsContext *x4 = avctx->priv_data;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
164
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
165 av_freep(&avctx->extradata);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
166 av_free(x4->sei);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
167
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
168 if (x4->enc)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
169 xavs_encoder_close(x4->enc);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
170
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
171 return 0;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
172 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
173
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
174 static av_cold int XAVS_init(AVCodecContext *avctx)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
175 {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
176 XavsContext *x4 = avctx->priv_data;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
177
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
178 x4->sei_size = 0;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
179 xavs_param_default(&x4->params);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
180
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
181 x4->params.pf_log = XAVS_log;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
182 x4->params.p_log_private = avctx;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
183 x4->params.i_keyint_max = avctx->gop_size;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
184 x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
185 x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
186 x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
187 x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
188 if (avctx->flags & CODEC_FLAG_PASS2) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
189 x4->params.rc.b_stat_read = 1;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
190 } else {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
191 if (avctx->crf) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
192 x4->params.rc.i_rc_method = XAVS_RC_CRF;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
193 x4->params.rc.f_rf_constant = avctx->crf;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
194 } else if (avctx->cqp > -1) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
195 x4->params.rc.i_rc_method = XAVS_RC_CQP;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
196 x4->params.rc.i_qp_constant = avctx->cqp;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
197 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
198 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
199
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
200 /* if neither crf nor cqp modes are selected we have to enable the RC */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
201 /* we do it this way because we cannot check if the bitrate has been set */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
202 if (!(avctx->crf || (avctx->cqp > -1)))
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
203 x4->params.rc.i_rc_method = XAVS_RC_ABR;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
204
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
205 x4->params.i_bframe = avctx->max_b_frames;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
206 /* cabac is not included in AVS JiZhun Profile */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
207 x4->params.b_cabac = 0;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
208
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
209 x4->params.i_bframe_adaptive = avctx->b_frame_strategy;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
210 x4->params.i_bframe_bias = avctx->bframebias;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
211
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
212 avctx->has_b_frames = !!avctx->max_b_frames;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
213
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
214 /* AVS doesn't allow B picture as reference */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
215 /* The max allowed reference frame number of B is 2 */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
216 x4->params.i_keyint_min = avctx->keyint_min;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
217 if (x4->params.i_keyint_min > x4->params.i_keyint_max)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
218 x4->params.i_keyint_min = x4->params.i_keyint_max;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
219
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
220 x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
221
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
222 // x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
223 x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
224 x4->params.i_deblocking_filter_beta = avctx->deblockbeta;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
225
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
226 x4->params.rc.i_qp_min = avctx->qmin;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
227 x4->params.rc.i_qp_max = avctx->qmax;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
228 x4->params.rc.i_qp_step = avctx->max_qdiff;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
229
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
230 x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
231 x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
232 x4->params.rc.f_complexity_blur = avctx->complexityblur;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
233
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
234 x4->params.i_frame_reference = avctx->refs;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
235
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
236 x4->params.i_width = avctx->width;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
237 x4->params.i_height = avctx->height;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
238 x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
239 x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
240 /* This is only used for counting the fps */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
241 x4->params.i_fps_num = avctx->time_base.den;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
242 x4->params.i_fps_den = avctx->time_base.num;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
243 x4->params.analyse.inter = XAVS_ANALYSE_I8x8 |XAVS_ANALYSE_PSUB16x16| XAVS_ANALYSE_BSUB16x16;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
244 if (avctx->partitions) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
245 if (avctx->partitions & XAVS_PART_I8X8)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
246 x4->params.analyse.inter |= XAVS_ANALYSE_I8x8;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
247
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
248 if (avctx->partitions & XAVS_PART_P8X8)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
249 x4->params.analyse.inter |= XAVS_ANALYSE_PSUB16x16;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
250
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
251 if (avctx->partitions & XAVS_PART_B8X8)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
252 x4->params.analyse.inter |= XAVS_ANALYSE_BSUB16x16;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
253 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
254
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
255 x4->params.analyse.i_direct_mv_pred = avctx->directpred;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
256
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
257 x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
258
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
259 switch (avctx->me_method) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
260 case ME_EPZS:
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
261 x4->params.analyse.i_me_method = XAVS_ME_DIA;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
262 break;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
263 case ME_HEX:
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
264 x4->params.analyse.i_me_method = XAVS_ME_HEX;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
265 break;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
266 case ME_UMH:
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
267 x4->params.analyse.i_me_method = XAVS_ME_UMH;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
268 break;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
269 case ME_FULL:
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
270 x4->params.analyse.i_me_method = XAVS_ME_ESA;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
271 break;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
272 case ME_TESA:
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
273 x4->params.analyse.i_me_method = XAVS_ME_TESA;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
274 break;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
275 default:
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
276 x4->params.analyse.i_me_method = XAVS_ME_HEX;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
277 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
278
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
279 x4->params.analyse.i_me_range = avctx->me_range;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
280 x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
281
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
282 x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
283 x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
284 /* AVS P2 only enables 8x8 transform */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
285 x4->params.analyse.b_transform_8x8 = 1; //avctx->flags2 & CODEC_FLAG2_8X8DCT;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
286 x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
287
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
288 x4->params.analyse.i_trellis = avctx->trellis;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
289 x4->params.analyse.i_noise_reduction = avctx->noise_reduction;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
290
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
291 if (avctx->level > 0)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
292 x4->params.i_level_idc = avctx->level;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
293
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
294 x4->params.rc.f_rate_tolerance =
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
295 (float)avctx->bit_rate_tolerance/avctx->bit_rate;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
296
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
297 if ((avctx->rc_buffer_size) &&
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
298 (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
299 x4->params.rc.f_vbv_buffer_init =
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
300 (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
301 } else
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
302 x4->params.rc.f_vbv_buffer_init = 0.9;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
303
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
304 /* TAG:do we have MB tree RC method */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
305 /* what is the RC method we are now using? Default NO */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
306 x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
307 x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
308 x4->params.rc.f_pb_factor = avctx->b_quant_factor;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
309 x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
310
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
311 x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
312 x4->params.i_log_level = XAVS_LOG_DEBUG;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
313 x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
314 x4->params.i_threads = avctx->thread_count;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
315 x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
316
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
317 if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
318 x4->params.b_repeat_headers = 0;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
319
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
320 x4->enc = xavs_encoder_open(&x4->params);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
321 if (!x4->enc)
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
322 return -1;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
323
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
324 avctx->coded_frame = &x4->out_pic;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
325 /* TAG: Do we have GLOBAL HEADER in AVS */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
326 /* We Have PPS and SPS in AVS */
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
327 if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
328 xavs_nal_t *nal;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
329 int nnal, s;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
330
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
331 s = xavs_encoder_headers(x4->enc, &nal, &nnal);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
332
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
333 avctx->extradata = av_malloc(s);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
334 avctx->extradata_size = encode_nals(avctx, avctx->extradata, s, nal, nnal, 1);
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
335 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
336 return 0;
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
337 }
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
338
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
339 AVCodec libxavs_encoder = {
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
340 .name = "libxavs",
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
341 .type = CODEC_TYPE_VIDEO,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
342 .id = CODEC_ID_CAVS,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
343 .priv_data_size = sizeof(XavsContext),
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
344 .init = XAVS_init,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
345 .encode = XAVS_frame,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
346 .close = XAVS_close,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
347 .capabilities = CODEC_CAP_DELAY,
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
348 .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_NONE },
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
349 .long_name = NULL_IF_CONFIG_SMALL("libxavs - the Chinese Audio Video Standard Encoder"),
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
350 };
bf51ca1aafb8 add Chinese AVS encoding via external library libxavs
stefang
parents:
diff changeset
351