Libav
mjpegenc.c
Go to the documentation of this file.
1 /*
2  * MJPEG encoder
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  * Copyright (c) 2003 Alex Beregszaszi
5  * Copyright (c) 2003-2004 Michael Niedermayer
6  *
7  * Support for external huffman table, various fixes (AVID workaround),
8  * aspecting, new decode_frame mechanism and apple mjpeg-b support
9  * by Alex Beregszaszi
10  *
11  * This file is part of Libav.
12  *
13  * Libav is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * Libav is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with Libav; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26  */
27 
33 #include <assert.h>
34 
35 #include "libavutil/pixdesc.h"
36 
37 #include "avcodec.h"
38 #include "mpegvideo.h"
39 #include "mjpeg.h"
40 #include "mjpegenc.h"
41 
43 {
44  MJpegContext *m;
45 
46  m = av_malloc(sizeof(MJpegContext));
47  if (!m)
48  return -1;
49 
50  s->min_qcoeff=-1023;
51  s->max_qcoeff= 1023;
52 
53  /* build all the huffman tables */
70 
71  s->mjpeg_ctx = m;
72  return 0;
73 }
74 
76 {
77  av_free(s->mjpeg_ctx);
78 }
79 
80 /* table_class: 0 = DC coef, 1 = AC coefs */
81 static int put_huffman_table(PutBitContext *p, int table_class, int table_id,
82  const uint8_t *bits_table, const uint8_t *value_table)
83 {
84  int n, i;
85 
86  put_bits(p, 4, table_class);
87  put_bits(p, 4, table_id);
88 
89  n = 0;
90  for(i=1;i<=16;i++) {
91  n += bits_table[i];
92  put_bits(p, 8, bits_table[i]);
93  }
94 
95  for(i=0;i<n;i++)
96  put_bits(p, 8, value_table[i]);
97 
98  return n + 17;
99 }
100 
101 static void jpeg_table_header(PutBitContext *p, ScanTable *intra_scantable,
102  uint16_t intra_matrix[64])
103 {
104  int i, j, size;
105  uint8_t *ptr;
106 
107  /* quant matrixes */
108  put_marker(p, DQT);
109  put_bits(p, 16, 2 + 1 * (1 + 64));
110  put_bits(p, 4, 0); /* 8 bit precision */
111  put_bits(p, 4, 0); /* table 0 */
112  for(i=0;i<64;i++) {
113  j = intra_scantable->permutated[i];
114  put_bits(p, 8, intra_matrix[j]);
115  }
116 
117  /* huffman table */
118  put_marker(p, DHT);
119  flush_put_bits(p);
120  ptr = put_bits_ptr(p);
121  put_bits(p, 16, 0); /* patched later */
122  size = 2;
127 
132  AV_WB16(ptr, size);
133 }
134 
136 {
137  int size;
138  uint8_t *ptr;
139 
140  if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) {
141  /* JFIF header */
142  put_marker(p, APP0);
143  put_bits(p, 16, 16);
144  avpriv_put_string(p, "JFIF", 1); /* this puts the trailing zero-byte too */
145  /* The most significant byte is used for major revisions, the least
146  * significant byte for minor revisions. Version 1.02 is the current
147  * released revision. */
148  put_bits(p, 16, 0x0102);
149  put_bits(p, 8, 0); /* units type: 0 - aspect ratio */
150  put_bits(p, 16, avctx->sample_aspect_ratio.num);
151  put_bits(p, 16, avctx->sample_aspect_ratio.den);
152  put_bits(p, 8, 0); /* thumbnail width */
153  put_bits(p, 8, 0); /* thumbnail height */
154  }
155 
156  /* comment */
157  if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
158  put_marker(p, COM);
159  flush_put_bits(p);
160  ptr = put_bits_ptr(p);
161  put_bits(p, 16, 0); /* patched later */
163  size = strlen(LIBAVCODEC_IDENT)+3;
164  AV_WB16(ptr, size);
165  }
166 
167  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
168  avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
169  avctx->pix_fmt == AV_PIX_FMT_YUV444P) {
170  put_marker(p, COM);
171  flush_put_bits(p);
172  ptr = put_bits_ptr(p);
173  put_bits(p, 16, 0); /* patched later */
174  avpriv_put_string(p, "CS=ITU601", 1);
175  size = strlen("CS=ITU601")+3;
176  AV_WB16(ptr, size);
177  }
178 }
179 
181  ScanTable *intra_scantable,
182  uint16_t intra_matrix[64])
183 {
184  int chroma_h_shift, chroma_v_shift;
185  const int lossless = avctx->codec_id != AV_CODEC_ID_MJPEG;
186  int hsample[3], vsample[3];
187 
188  av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift,
189  &chroma_v_shift);
190 
191  if (avctx->codec->id == AV_CODEC_ID_LJPEG &&
192  avctx->pix_fmt == AV_PIX_FMT_BGR24) {
193  vsample[0] = hsample[0] =
194  vsample[1] = hsample[1] =
195  vsample[2] = hsample[2] = 1;
196  } else {
197  vsample[0] = 2;
198  vsample[1] = 2 >> chroma_v_shift;
199  vsample[2] = 2 >> chroma_v_shift;
200  hsample[0] = 2;
201  hsample[1] = 2 >> chroma_h_shift;
202  hsample[2] = 2 >> chroma_h_shift;
203  }
204 
205  put_marker(pb, SOI);
206 
207  jpeg_put_comments(avctx, pb);
208 
209  jpeg_table_header(pb, intra_scantable, intra_matrix);
210 
211  switch (avctx->codec_id) {
212  case AV_CODEC_ID_MJPEG: put_marker(pb, SOF0 ); break;
213  case AV_CODEC_ID_LJPEG: put_marker(pb, SOF3 ); break;
214  default: assert(0);
215  }
216 
217  put_bits(pb, 16, 17);
218  if (lossless && avctx->pix_fmt == AV_PIX_FMT_BGR24)
219  put_bits(pb, 8, 9); /* 9 bits/component RCT */
220  else
221  put_bits(pb, 8, 8); /* 8 bits/component */
222  put_bits(pb, 16, avctx->height);
223  put_bits(pb, 16, avctx->width);
224  put_bits(pb, 8, 3); /* 3 components */
225 
226  /* Y component */
227  put_bits(pb, 8, 1); /* component number */
228  put_bits(pb, 4, hsample[0]); /* H factor */
229  put_bits(pb, 4, vsample[0]); /* V factor */
230  put_bits(pb, 8, 0); /* select matrix */
231 
232  /* Cb component */
233  put_bits(pb, 8, 2); /* component number */
234  put_bits(pb, 4, hsample[1]); /* H factor */
235  put_bits(pb, 4, vsample[1]); /* V factor */
236  put_bits(pb, 8, 0); /* select matrix */
237 
238  /* Cr component */
239  put_bits(pb, 8, 3); /* component number */
240  put_bits(pb, 4, hsample[2]); /* H factor */
241  put_bits(pb, 4, vsample[2]); /* V factor */
242  put_bits(pb, 8, 0); /* select matrix */
243 
244  /* scan header */
245  put_marker(pb, SOS);
246  put_bits(pb, 16, 12); /* length */
247  put_bits(pb, 8, 3); /* 3 components */
248 
249  /* Y component */
250  put_bits(pb, 8, 1); /* index */
251  put_bits(pb, 4, 0); /* DC huffman table index */
252  put_bits(pb, 4, 0); /* AC huffman table index */
253 
254  /* Cb component */
255  put_bits(pb, 8, 2); /* index */
256  put_bits(pb, 4, 1); /* DC huffman table index */
257  put_bits(pb, 4, lossless ? 0 : 1); /* AC huffman table index */
258 
259  /* Cr component */
260  put_bits(pb, 8, 3); /* index */
261  put_bits(pb, 4, 1); /* DC huffman table index */
262  put_bits(pb, 4, lossless ? 0 : 1); /* AC huffman table index */
263 
264  put_bits(pb, 8, lossless ? avctx->prediction_method + 1 : 0); /* Ss (not used) */
265 
266  switch (avctx->codec_id) {
267  case AV_CODEC_ID_MJPEG: put_bits(pb, 8, 63); break; /* Se (not used) */
268  case AV_CODEC_ID_LJPEG: put_bits(pb, 8, 0); break; /* not used */
269  default: assert(0);
270  }
271 
272  put_bits(pb, 8, 0); /* Ah/Al (not used) */
273 }
274 
275 static void escape_FF(PutBitContext *pb, int start)
276 {
277  int size = put_bits_count(pb) - start * 8;
278  int i, ff_count;
279  uint8_t *buf = pb->buf + start;
280  int align= (-(size_t)(buf))&3;
281 
282  assert((size&7) == 0);
283  size >>= 3;
284 
285  ff_count=0;
286  for(i=0; i<size && i<align; i++){
287  if(buf[i]==0xFF) ff_count++;
288  }
289  for(; i<size-15; i+=16){
290  int acc, v;
291 
292  v= *(uint32_t*)(&buf[i]);
293  acc= (((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
294  v= *(uint32_t*)(&buf[i+4]);
295  acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
296  v= *(uint32_t*)(&buf[i+8]);
297  acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
298  v= *(uint32_t*)(&buf[i+12]);
299  acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
300 
301  acc>>=4;
302  acc+= (acc>>16);
303  acc+= (acc>>8);
304  ff_count+= acc&0xFF;
305  }
306  for(; i<size; i++){
307  if(buf[i]==0xFF) ff_count++;
308  }
309 
310  if(ff_count==0) return;
311 
312  flush_put_bits(pb);
313  skip_put_bytes(pb, ff_count);
314 
315  for(i=size-1; ff_count; i--){
316  int v= buf[i];
317 
318  if(v==0xFF){
319  buf[i+ff_count]= 0;
320  ff_count--;
321  }
322 
323  buf[i+ff_count]= v;
324  }
325 }
326 
328 {
329  int length;
330  length= (-put_bits_count(pbc))&7;
331  if(length) put_bits(pbc, length, (1<<length)-1);
332 }
333 
335 {
337  flush_put_bits(pb);
338 
339  assert((header_bits & 7) == 0);
340 
341  escape_FF(pb, header_bits >> 3);
342 
343  put_marker(pb, EOI);
344 }
345 
347  uint8_t *huff_size, uint16_t *huff_code)
348 {
349  int mant, nbits;
350 
351  if (val == 0) {
352  put_bits(pb, huff_size[0], huff_code[0]);
353  } else {
354  mant = val;
355  if (val < 0) {
356  val = -val;
357  mant--;
358  }
359 
360  nbits= av_log2_16bit(val) + 1;
361 
362  put_bits(pb, huff_size[nbits], huff_code[nbits]);
363 
364  put_sbits(pb, nbits, mant);
365  }
366 }
367 
368 static void encode_block(MpegEncContext *s, int16_t *block, int n)
369 {
370  int mant, nbits, code, i, j;
371  int component, dc, run, last_index, val;
372  MJpegContext *m = s->mjpeg_ctx;
373  uint8_t *huff_size_ac;
374  uint16_t *huff_code_ac;
375 
376  /* DC coef */
377  component = (n <= 3 ? 0 : (n&1) + 1);
378  dc = block[0]; /* overflow is impossible */
379  val = dc - s->last_dc[component];
380  if (n < 4) {
382  huff_size_ac = m->huff_size_ac_luminance;
383  huff_code_ac = m->huff_code_ac_luminance;
384  } else {
386  huff_size_ac = m->huff_size_ac_chrominance;
387  huff_code_ac = m->huff_code_ac_chrominance;
388  }
389  s->last_dc[component] = dc;
390 
391  /* AC coefs */
392 
393  run = 0;
394  last_index = s->block_last_index[n];
395  for(i=1;i<=last_index;i++) {
396  j = s->intra_scantable.permutated[i];
397  val = block[j];
398  if (val == 0) {
399  run++;
400  } else {
401  while (run >= 16) {
402  put_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]);
403  run -= 16;
404  }
405  mant = val;
406  if (val < 0) {
407  val = -val;
408  mant--;
409  }
410 
411  nbits= av_log2(val) + 1;
412  code = (run << 4) | nbits;
413 
414  put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]);
415 
416  put_sbits(&s->pb, nbits, mant);
417  run = 0;
418  }
419  }
420 
421  /* output EOB only if not already 64 values */
422  if (last_index < 63 || run != 0)
423  put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]);
424 }
425 
426 void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[6][64])
427 {
428  int i;
429  for(i=0;i<5;i++) {
430  encode_block(s, block[i], i);
431  }
432  if (s->chroma_format == CHROMA_420) {
433  encode_block(s, block[5], 5);
434  } else {
435  encode_block(s, block[6], 6);
436  encode_block(s, block[5], 5);
437  encode_block(s, block[7], 7);
438  }
439 
440  s->i_tex_bits += get_bits_diff(s);
441 }
442 
444  .name = "mjpeg",
445  .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"),
446  .type = AVMEDIA_TYPE_VIDEO,
447  .id = AV_CODEC_ID_MJPEG,
448  .priv_data_size = sizeof(MpegEncContext),
450  .encode2 = ff_MPV_encode_picture,
452  .pix_fmts = (const enum AVPixelFormat[]){
454  },
455 };
Definition: mjpeg.h:115
const struct AVCodec * codec
Definition: avcodec.h:1063
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: mjpegenc.c:426
int size
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:177
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:70
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
Definition: mjpeg.c:73
int acc
Definition: yuv2rgb.c:471
MJPEG encoder.
int ff_MPV_encode_end(AVCodecContext *avctx)
Scantable.
Definition: dsputil.h:111
int num
numerator
Definition: rational.h:44
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1422
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1247
Definition: mjpeg.h:74
int min_qcoeff
minimum encodable coefficient
Definition: mpegvideo.h:499
const uint8_t avpriv_mjpeg_bits_dc_chrominance[17]
Definition: mjpeg.c:70
mpegvideo header.
const uint8_t avpriv_mjpeg_bits_ac_chrominance[17]
Definition: mjpeg.c:99
av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
Definition: mjpegenc.c:42
uint8_t permutated[64]
Definition: dsputil.h:113
uint8_t run
Definition: svq3.c:142
AVCodec.
Definition: avcodec.h:2755
MJPEG encoder and decoder.
uint16_t huff_code_dc_chrominance[12]
Definition: mjpegenc.h:44
uint16_t huff_code_ac_luminance[256]
Definition: mjpegenc.h:47
uint8_t
#define av_cold
Definition: attributes.h:66
static void encode_block(MpegEncContext *s, int16_t *block, int n)
Definition: mjpegenc.c:368
#define CHROMA_420
Definition: mpegvideo.h:658
static void escape_FF(PutBitContext *pb, int start)
Definition: mjpegenc.c:275
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
Definition: mjpeg.c:127
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: pixfmt.h:78
uint8_t huff_size_dc_chrominance[12]
Definition: mjpegenc.h:43
static void jpeg_table_header(PutBitContext *p, ScanTable *intra_scantable, uint16_t intra_matrix[64])
Definition: mjpegenc.c:101
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:685
Definition: mjpeg.h:77
int max_qcoeff
maximum encodable coefficient
Definition: mpegvideo.h:500
Definition: mjpeg.h:83
int ff_MPV_encode_init(AVCodecContext *avctx)
static int get_bits_diff(MpegEncContext *s)
Definition: mpegvideo.h:846
uint16_t huff_code_ac_chrominance[256]
Definition: mjpegenc.h:49
enum AVCodecID id
Definition: avcodec.h:2769
AVCodec ff_mjpeg_encoder
Definition: mjpegenc.c:443
uint8_t huff_size_ac_luminance[256]
Definition: mjpegenc.h:46
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
Definition: put_bits.h:204
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
int last_dc[3]
last DC values for MPEG1
Definition: mpegvideo.h:371
Definition: mjpeg.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:142
void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits)
Definition: mjpegenc.c:334
Definition: mjpeg.h:60
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1142
uint8_t * buf
Definition: put_bits.h:43
uint8_t huff_size_ac_chrominance[256]
Definition: mjpegenc.h:48
const char * name
Name of the codec implementation.
Definition: avcodec.h:2762
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
Definition: put_bits.h:139
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:72
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:69
void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, ScanTable *intra_scantable, uint16_t intra_matrix[64])
Definition: mjpegenc.c:180
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
Definition: put_bits.h:213
Definition: mjpeg.h:76
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: pixfmt.h:77
int width
picture width / height.
Definition: avcodec.h:1217
void ff_mjpeg_encode_dc(PutBitContext *pb, int val, uint8_t *huff_size, uint16_t *huff_code)
Definition: mjpegenc.c:346
const uint8_t avpriv_mjpeg_bits_dc_luminance[17]
Definition: mjpeg.c:65
const uint8_t avpriv_mjpeg_val_dc[12]
Definition: mjpeg.c:67
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:314
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:68
Definition: mjpeg.h:46
Definition: mjpeg.h:75
struct MJpegContext * mjpeg_ctx
Definition: mpegvideo.h:611
Libavcodec external API header.
enum AVCodecID codec_id
Definition: avcodec.h:1065
void ff_mjpeg_encode_close(MpegEncContext *s)
Definition: mjpegenc.c:75
main external API structure.
Definition: avcodec.h:1054
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:489
ScanTable intra_scantable
Definition: mpegvideo.h:319
void ff_mjpeg_encode_stuffing(PutBitContext *pbc)
Definition: mjpegenc.c:327
#define AV_WB16(p, d)
Definition: intreadwrite.h:213
int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
MpegEncContext.
Definition: mpegvideo.h:264
const uint8_t avpriv_mjpeg_val_ac_luminance[]
Definition: mjpeg.c:75
uint16_t huff_code_dc_luminance[12]
Definition: mjpegenc.h:42
PutBitContext pb
bit output
Definition: mpegvideo.h:337
uint8_t huff_size_dc_luminance[12]
Definition: mjpegenc.h:41
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:88
int prediction_method
prediction method (needed for huffyuv)
Definition: avcodec.h:1403
FF_ENABLE_DEPRECATION_WARNINGS int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:1533
int den
denominator
Definition: rational.h:45
static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p)
Definition: mjpegenc.c:135
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:498
static void put_marker(PutBitContext *p, int code)
Definition: mjpeg.h:122
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
Definition: mjpeg.c:102
#define av_log2_16bit
Definition: intmath.h:86
#define av_log2
Definition: intmath.h:85
#define LIBAVCODEC_IDENT
Definition: version.h:43
void avpriv_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
Definition: bitstream.c:50
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> dc
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
static int put_huffman_table(PutBitContext *p, int table_class, int table_id, const uint8_t *bits_table, const uint8_t *value_table)
Definition: mjpegenc.c:81
static int16_t block[64]
Definition: dct-test.c:170