• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/mp3_header_compress_bsf.c

Go to the documentation of this file.
00001 /*
00002  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #include "avcodec.h"
00022 #include "mpegaudio.h"
00023 
00024 
00025 static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
00026                      uint8_t **poutbuf, int *poutbuf_size,
00027                      const uint8_t *buf, int buf_size, int keyframe){
00028     uint32_t header, extraheader;
00029     int mode_extension, header_size;
00030 
00031     if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
00032         av_log(avctx, AV_LOG_ERROR, "not standards compliant\n");
00033         return -1;
00034     }
00035 
00036     header = AV_RB32(buf);
00037     mode_extension= (header>>4)&3;
00038 
00039     if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){
00040 output_unchanged:
00041         *poutbuf= (uint8_t *) buf;
00042         *poutbuf_size= buf_size;
00043 
00044         av_log(avctx, AV_LOG_INFO, "cannot compress %08X\n", header);
00045         return 0;
00046     }
00047 
00048     if(avctx->extradata_size == 0){
00049         avctx->extradata_size=15;
00050         avctx->extradata= av_malloc(avctx->extradata_size);
00051         strcpy(avctx->extradata, "FFCMP3 0.0");
00052         memcpy(avctx->extradata+11, buf, 4);
00053     }
00054     if(avctx->extradata_size != 15){
00055         av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n");
00056         return -1;
00057     }
00058     extraheader = AV_RB32(avctx->extradata+11);
00059     if((extraheader&MP3_MASK) != (header&MP3_MASK))
00060         goto output_unchanged;
00061 
00062     header_size= (header&0x10000) ? 4 : 6;
00063 
00064     *poutbuf_size= buf_size - header_size;
00065     *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
00066     memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
00067 
00068     if(avctx->channels==2){
00069         if((header & (3<<19)) != 3<<19){
00070             (*poutbuf)[1] &= 0x3F;
00071             (*poutbuf)[1] |= mode_extension<<6;
00072             FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]);
00073         }else{
00074             (*poutbuf)[1] &= 0x8F;
00075             (*poutbuf)[1] |= mode_extension<<4;
00076         }
00077     }
00078 
00079     return 1;
00080 }
00081 
00082 AVBitStreamFilter mp3_header_compress_bsf={
00083     "mp3comp",
00084     0,
00085     mp3_header_compress,
00086 };

Generated on Fri Sep 16 2011 17:17:39 for FFmpeg by  doxygen 1.7.1