annotate mp3_header_compress_bsf.c @ 7295:f3923fea3a8c libavcodec

Simplify
author vitor
date Thu, 17 Jul 2008 22:42:21 +0000
parents b955154b7ca9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
1 /*
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
3 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
4 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
5 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
8 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
10 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
14 * Lesser General Public License for more details.
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
15 *
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3422
diff changeset
19 */
3421
b7826511f7b6 AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff changeset
20
b7826511f7b6 AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff changeset
21 #include "avcodec.h"
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
22 #include "mpegaudio.h"
3421
b7826511f7b6 AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff changeset
23
3422
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
24
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
25 static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
26 uint8_t **poutbuf, int *poutbuf_size,
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
27 const uint8_t *buf, int buf_size, int keyframe){
4167
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
28 uint32_t header, extraheader;
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
29 int mode_extension, header_size;
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
30
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
31 if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
32 av_log(avctx, AV_LOG_ERROR, "not standards compliant\n");
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
33 return -1;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
34 }
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
35
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4168
diff changeset
36 header = AV_RB32(buf);
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
37 mode_extension= (header>>4)&3;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
38
4167
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
39 if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
40 output_unchanged:
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
41 *poutbuf= (uint8_t *) buf;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
42 *poutbuf_size= buf_size;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
43
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
44 av_log(avctx, AV_LOG_INFO, "cannot compress %08X\n", header);
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
45 return 0;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
46 }
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
47
4167
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
48 if(avctx->extradata_size == 0){
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
49 avctx->extradata_size=15;
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
50 avctx->extradata= av_malloc(avctx->extradata_size);
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
51 strcpy(avctx->extradata, "FFCMP3 0.0");
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
52 memcpy(avctx->extradata+11, buf, 4);
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
53 }
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
54 if(avctx->extradata_size != 15){
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
55 av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n");
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
56 return -1;
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
57 }
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4168
diff changeset
58 extraheader = AV_RB32(avctx->extradata+11);
4167
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
59 if((extraheader&MP3_MASK) != (header&MP3_MASK))
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
60 goto output_unchanged;
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
61
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
62 header_size= (header&0x10000) ? 4 : 6;
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
63
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
64 *poutbuf_size= buf_size - header_size;
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
65 *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
66 memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
67
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
68 if(avctx->channels==2){
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
69 if((header & (3<<19)) != 3<<19){
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
70 (*poutbuf)[1] &= 0x3F;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
71 (*poutbuf)[1] |= mode_extension<<6;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
72 FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]);
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
73 }else{
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
74 (*poutbuf)[1] &= 0x8F;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
75 (*poutbuf)[1] |= mode_extension<<4;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
76 }
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
77 }
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
78
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
79 return 1;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
80 }
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
81
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
82 AVBitStreamFilter mp3_header_compress_bsf={
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
83 "mp3comp",
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
84 0,
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
85 mp3_header_compress,
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
86 };