00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "libavutil/common.h"
00022 #include "libavutil/intreadwrite.h"
00023 #include "avcodec.h"
00024 #include "mpegaudiodecheader.h"
00025
00026
00027 static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
00028 uint8_t **poutbuf, int *poutbuf_size,
00029 const uint8_t *buf, int buf_size, int keyframe){
00030 uint32_t header, extraheader;
00031 int mode_extension, header_size;
00032
00033 if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
00034 av_log(avctx, AV_LOG_ERROR, "not standards compliant\n");
00035 return -1;
00036 }
00037
00038 header = AV_RB32(buf);
00039 mode_extension= (header>>4)&3;
00040
00041 if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){
00042 output_unchanged:
00043 *poutbuf= (uint8_t *) buf;
00044 *poutbuf_size= buf_size;
00045
00046 av_log(avctx, AV_LOG_INFO, "cannot compress %08X\n", header);
00047 return 0;
00048 }
00049
00050 if(avctx->extradata_size == 0){
00051 avctx->extradata_size=15;
00052 avctx->extradata= av_malloc(avctx->extradata_size);
00053 strcpy(avctx->extradata, "FFCMP3 0.0");
00054 memcpy(avctx->extradata+11, buf, 4);
00055 }
00056 if(avctx->extradata_size != 15){
00057 av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n");
00058 return -1;
00059 }
00060 extraheader = AV_RB32(avctx->extradata+11);
00061 if((extraheader&MP3_MASK) != (header&MP3_MASK))
00062 goto output_unchanged;
00063
00064 header_size= (header&0x10000) ? 4 : 6;
00065
00066 *poutbuf_size= buf_size - header_size;
00067 *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
00068 memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
00069
00070 if(avctx->channels==2){
00071 if((header & (3<<19)) != 3<<19){
00072 (*poutbuf)[1] &= 0x3F;
00073 (*poutbuf)[1] |= mode_extension<<6;
00074 FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]);
00075 }else{
00076 (*poutbuf)[1] &= 0x8F;
00077 (*poutbuf)[1] |= mode_extension<<4;
00078 }
00079 }
00080
00081 return 1;
00082 }
00083
00084 AVBitStreamFilter ff_mp3_header_compress_bsf={
00085 "mp3comp",
00086 0,
00087 mp3_header_compress,
00088 };