00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 };