Replace LDLATEFLAGS hackery by proper LDFLAGS tests.
[FFMpeg-mirror/ffmpeg-vdpau.git] / libavcodec / mp3_header_compress_bsf.c
blobf5c513834aa80bc2a435445d8348e32fd6163de2
1 /*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "avcodec.h"
22 #include "mpegaudio.h"
25 static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
26 uint8_t **poutbuf, int *poutbuf_size,
27 const uint8_t *buf, int buf_size, int keyframe){
28 uint32_t header, extraheader;
29 int mode_extension, header_size;
31 if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
32 av_log(avctx, AV_LOG_ERROR, "not standards compliant\n");
33 return -1;
36 header = AV_RB32(buf);
37 mode_extension= (header>>4)&3;
39 if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){
40 output_unchanged:
41 *poutbuf= (uint8_t *) buf;
42 *poutbuf_size= buf_size;
44 av_log(avctx, AV_LOG_INFO, "cannot compress %08X\n", header);
45 return 0;
48 if(avctx->extradata_size == 0){
49 avctx->extradata_size=15;
50 avctx->extradata= av_malloc(avctx->extradata_size);
51 strcpy(avctx->extradata, "FFCMP3 0.0");
52 memcpy(avctx->extradata+11, buf, 4);
54 if(avctx->extradata_size != 15){
55 av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n");
56 return -1;
58 extraheader = AV_RB32(avctx->extradata+11);
59 if((extraheader&MP3_MASK) != (header&MP3_MASK))
60 goto output_unchanged;
62 header_size= (header&0x10000) ? 4 : 6;
64 *poutbuf_size= buf_size - header_size;
65 *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
66 memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
68 if(avctx->channels==2){
69 if((header & (3<<19)) != 3<<19){
70 (*poutbuf)[1] &= 0x3F;
71 (*poutbuf)[1] |= mode_extension<<6;
72 FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]);
73 }else{
74 (*poutbuf)[1] &= 0x8F;
75 (*poutbuf)[1] |= mode_extension<<4;
79 return 1;
82 AVBitStreamFilter mp3_header_compress_bsf={
83 "mp3comp",
85 mp3_header_compress,